henrywright henrywright - 3 months ago 9
PHP Question

How to remove a WordPress action which uses the current object - $this?

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

Answer

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.

Comments