add_action reference a class

No, you cannot ‘initialise’ or instantiate the class through a hook, not directly. Some additional code is always required ( and it is not a desirable thing to be able to do that, as you’re opening a can of worms for yourself. Here is a better way of doing it: class MyClass { function __construct() … Read more

remove_action or remove_filter with external classes?

The best thing to do here is to use a static class. The following code should be instructional: 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 … Read more