Why do filters/actions require an argument count?

Because of backwards compatibility. You can use the same callback for multiple filters. Inside of that callback you should use current_filter() to determine the context. But some plugins use the number of passed arguments instead. Changing that would break these plugins. That’s why you should always use the API (here: current_filter()) and not some made-up … Read more

Exclude trash from save_post

save_post gets fired, once the post is saved. We get the current post object as the second parameter. So we can check, if the current post status is trash: <?php add_action( ‘save_post’, function( $post_ID, $post, $update ) { if ( ‘trash’ === $post->post_status ) { return; } /** do your stuff **/ }, 10, 3 … Read more

Disable email field on WooCommerce customer account details

You can do it by adding this code to functions.php: function custom_override_checkout_fields( $fields ) { unset($fields[‘billing’][‘billing_email’]); return $fields; } add_filter( ‘woocommerce_checkout_fields’ , ‘custom_override_checkout_fields’, 1000, 1 ); But it is wrong approach, since WooCommerce uses email to notify user about status of the order.

How does WordPress call functions attached to a certain action hook before calling functions attached to other hooks

WordPress doesn’t execute all the actions and filters (i.e. hooks) at the same time using some sort of priority, instead, execution order of these action and filter hooks are hard coded within WordPress core PHP files. Within WordPress source CODE, search for the following four function calls (using any text editor’s find in files feature): … Read more

Modify query in pre_get_posts action is messing up my nav menu

pre_get_posts runs for every query. That includes the main query, secondary queries, and menus. The problem is that is_post_type_archive(array(‘provider’)) is checking if the main query is the post type archive, not a specific query going through pre_get_posts. So when you check for that and then modify the current query going through pre_get_posts you’re going to … Read more

Find variables available at a given hook

In general the best solution would be to refer to the documentation for the hook – or the source for the action call within WordPress core’s codebase if the documentation proves insufficient. You can search the documentation for the relevant action or filter here. Many pages actually include the source of the filter/action call which … Read more

add_action for saving a custom menu

At least in 3.4.1, there is an action for that: wp_update_nav_menu See here. Then you can get the items in your menu with something like: add_action(‘wp_update_nav_menu’, ‘my_get_menu_items’); function my_get_menu_items($nav_menu_selected_id) { $items = wp_get_nav_menu_items($nav_menu_selected_id); }

Woocommerce Change placement with wrapper

Okay I solved this but don’t know it is right way or wrong way. Hope you expert will give some better guideline. What I did just added two function into my add_action function and use those as a wrapper. // adding and re arranging placement function q2a_product_summary() { function wrapstart () { echo ‘<div class=”buy-box”>’; … Read more