I'm familiar with remove_action
when removing an action in WordPress.
To create the action:
add_action( 'action_hook', 'function_name', 10, 3 );
To remove the action:
remove_action( 'action_hook', 'function_name', 10, 3 );
But how can I remove an action which uses the current object? e.g $this
add_action( 'some_action_hook', array( $this, 'some_function' ) );
Ref:
http://codex.wordpress.org/Function_Reference/add_action
http://codex.wordpress.org/Function_Reference/remove_action
WordPress is great for allowing developers to extend plugins and themes using action hooks and filters. Sometimes we need to remove an already declared action or filter in a plugin or theme. It's pretty easy to do this in functional programming using remove_action() and remove_filter().
If you are a WordPress developer, then you must have definitely used action and filter hooks. You might have also known that add_action() hook can be removed using remove_action() & add_filter() hook can be removed using remove_filter() functions.
By setting a lower priority, the action will be executed earlier. By setting a higher priority, the action will be executed later. Whether it is an add_action or remove_action the principal is the same. 2] So set the priority of remove_action and add_action to the same number, in this case, 10.
To remove a hook, the $callback and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.
Inside class
add_action( 'some_action_hook', array( $this, 'some_function' ) );
Outside class,
With use of global vairable:
global $my_class;
remove_action( 'some_action_hook', array( $my_class, 'some_function' ) );
Using class name:
remove_action( 'some_action_hook', array( 'MyClass', 'some_function' ) );
Reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With