REST Endpoint API 404

There are few problems: you are using \WP_REST_Server::CREATABLE which is executed only when the request type is POST, if you are just opening the URL in the browser use \WP_REST_Server::READABLE instead (or \WP_REST_Server::ALLMETHODS to accept any request type). your callback is ‘callback’ => [$this, ‘import_csv’], but it should be ‘callback’ => [$this, ‘import_csv_file’], as the … Read more

Is it possible to load the css just on my plugin admin page?

To answer the question, from the codex, listed above in the comments. function load_custom_wp_admin_style($hook) { // Load only on ?page=mypluginname if($hook != ‘toplevel_page_mypluginname’) { return; } wp_enqueue_style( ‘custom_wp_admin_css’, plugins_url(‘admin-style.css’, __FILE__) ); } add_action( ‘admin_enqueue_scripts’, ‘load_custom_wp_admin_style’ ); Note: If you are unsure what your $hook name is .. use this to determine your hookname. Put the … Read more

How to call code when adding WooCommerce menu items via woocommerce_account_menu_items

One needs to create an action hook ‘woocommerce_account_[myendpoint]_endpoint’: add_action(‘woocommerce_account_’ . $endpoint . ‘_endpoint’, ‘my_endpoint_content’); function my_endpoint_content() { //content goes here echo ‘My content goes here’; } http://hookr.io/actions/woocommerce_account_key_endpoint/ So, putting a few different sources together, to add a new menu item to the Woocommerce My Account dashboard one needs something like: <?php add_filter(‘woocommerce_account_menu_items’, ‘add_my_menu_items’); function add_my_menu_items($items) … Read more

Plugin index page code executes multiple times

The code in the file itself can be executed multiple times. If you want to do something when the plugin is activated use register_activation_hook and wrap your email sending codes in it. function my_plugin_activation() { //Setting up the credential … } register_activation_hook( __FILE__, ‘my_plugin_activation’ );

Where to use nonce

Well actually, you just need to learn and understand what nonce is and is for, and then you would know when/where/whether you should use it. Excerpt from https://codex.wordpress.org/WordPress_Nonces: WordPress’s security tokens are called “nonces” (despite the above-noted differences from true nonces) because they serve much the same purpose as nonces do. They help protect against … Read more

How to create ShortCode

You need to use hooks to create custom columns and data for a custom post type are manage_{$post_type}posts_columns and manage{$post_type}_posts_custom_column respectively. {$post_type} is the name of the custom post type. I have created common function to add column and and their data. You can use below function to add column and it’s data. function cv_add_column_to_admin_dashboard($column_title, … Read more