Why do some hooks not work inside class context?

Sometimes certain hooks need to be fired at certain times. Example, some hooks need to be fired upon init. Add this to your __construct() add_action(‘init’, array(&$this, ‘init’)); Then add this function, which will contain all hooks that need to be fired upon init. public function init(){ add_action(‘hook_name’, array(&$this, ‘your_method_name’)); add_action(‘hook_name’, array(&$this, ‘your_method_name’)); add_action(‘hook_name’, array(&$this, ‘your_method_name’)); … Read more

Is there a action hook for the “Empty Trash” button?

I don’t think there exist one, but you could create your own, wpse_empty_trash, with something like this: /** * Add a custom hook ‘wpse_empty_trash’ */ add_action( ‘load-edit.php’, function() { add_action( ‘before_delete_post’, function ( $post_id ) { if ( ‘trash’ === get_post_status( $post_id ) && filter_input( INPUT_GET, ‘delete_all’ ) && 1 === did_action( ‘before_delete_post ‘ ) … Read more

How to know what priority to use with add_action()?

range of priority values? range of priority values? Generally, speaking, you can’t know a priori what priority something is hooked with. The priority needed depends on how other callbacks where hooked in. Often that is the default value of 10 but it could be anywhere between PHP_INT_MIN (negative integers are still integers) and PHP_INT_MAX and … Read more

Remove parent theme action in child

For removing an action hook you should use the same action name, callback name and the priority that was used to add a action in parent theme. And register it on init add_action( ‘init’, ‘remove_my_action’); function remove_my_action() { remove_action( ‘woocommerce_before_shop_loop’,’storefront_sorting_wrapper’,9 ); } Read about remove_action