How to use a custom hook

The problem is the order of execution. The order things run matters. For your code to function, it would require either add_action to implement time travel several microseconds into the past so that it can add the hook before it ran, or it would require do_action to implement precognition so that it knows about add_action … Read more

useSelect second parameter

Short Answer The second parameter for useSelect is the second parameter for useCallback, so check the React website and you’d understand what the heck that second parameter is.. 🙂 Long Answer useSelect is a custom React hook which uses the core useCallback hook in React which returns a memoized callback which can avoid expensive calculations … Read more

How to get user meta fields that have just been updated?

For anyone else with this issue, the fix was simple. I changed the hook and most importantly, I changed the priority so my action comes later. Default wordpress priority was 10, so I set priority to 11 and it works. add_action( ‘profile_update’, ‘BB_WP_SYNC_update_BB_profile’, 11, 2); And my function changed due to the different hook: function … Read more

Get rid of “trash can” for custom post type

If you wanted to do this for all post types, you’d simply do define(‘EMPTY_TRASH_DAYS’, 0); see https://codex.wordpress.org/Trash_status#EMPTY_TRASH_DAYS_option. But since you only want to do this for a custom post type, you will need to hook into ‘trashed_post’ like this: add_action(‘trashed_post’, function( $post_id ){ […] then check your trashed posts’ post type: if ( get_post_type($post_id) === … Read more

Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args

The error happens because the filter callback (shapeSpace_disable_sitemap_post_meta()) expects to receive two parameters ($args and $post_type) and yet you call add_filter() without setting the fourth parameter to 2. So to solve the problem: // Replace this: add_filter(‘wp_sitemaps_posts_query_args’, ‘shapeSpace_disable_sitemap_post_meta’); // with this one: add_filter(‘wp_sitemaps_posts_query_args’, ‘shapeSpace_disable_sitemap_post_meta’, 10, 2);

What exactly happens to function argument availability when using a filter?

The important thing to note is that action and filter hooks are mostly just standard PHP callback behaviour. The second argument passed to add_filter() should be a PHP Callable. When the filter is applied with apply_filters(), that callback is just run through the core PHP function call_user_func_array(). Any additional arguments to apply_filters() are then passed … Read more

It’s okay if I do not write add_action()

It is not always required technically but it is good practice to follow for multiple reasons: Code is more organized by keeping hook-related stuff together The more precise conditions when it runs – the better for performance It is easier to unhook function, that performs multiple add_, then unhook each add_ individually. The order of … Read more