add_action pre_term_description vs. pre_category_description

Categories and tags are both terms, which is why your code is running twice. What you need to is use the second argument passed to the callbacks for the pre_term_description hook, which tells you the taxonomy the filter is currently being applied for: function wpse_321166_default_term_description( $description, $taxonomy ) { if ( $description ) { return … Read more

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

how to Update 15k products on plugin activation with meta_option

Based on Paul’s original comment, we moved the code execution to a custom wp-cli command. Which also allowed us add arguments and change code behaviour based on arguments. Example code for anyone, including WPML language specification via global $sitepress; $sitepress->switch_lang(“en”); … ‘suppress_filters’ => false, <?php /** * Registers CLI command csa * * Allows to … Read more