The best thing to do here is to use a static class. The following code should be instructional:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | class MyClass { function __construct() { add_action( 'wp_footer', array( $this, 'my_action' ) ); } function my_action() { print '<h1>' . __class__ . ' - ' . __function__ . '</h1>'; } } new MyClass(); class MyStaticClass { public static function init() { add_action( 'wp_footer', array( __class__, 'my_action' ) ); } public static function my_action() { print '<h1>' . __class__ . ' - ' . __function__ . '</h1>'; } } MyStaticClass::init(); function my_wp_footer() { print '<h1>my_wp_footer()</h1>'; } add_action( 'wp_footer', 'my_wp_footer' ); function mfields_test_remove_actions() { remove_action( 'wp_footer', 'my_wp_footer' ); remove_action( 'wp_footer', array( 'MyClass', 'my_action' ), 10 ); remove_action( 'wp_footer', array( 'MyStaticClass', 'my_action' ), 10 ); } add_action( 'wp_head', 'mfields_test_remove_actions' ); |
If you run this code from a plugin you should notice that the method of the StaticClass as well as the function will removed from wp_footer.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.