So is it possible to do something like this with add_action
?
class class{}
$my_class = new class;
add_action('init', 'my_class');
So is it possible to do something like this with add_action
?
class class{}
$my_class = new class;
add_action('init', 'my_class');
You must be logged in to post a comment.
You can do this:
Or this:
It doesn’t work like…
.. but I am not sure what you are trying to accomplish by using that pattern. You’ve already instantiated the class so the constructor, if present, has already ran. Without a callback method, I don’t know what you expect to happen.
check in Using Add Action In Your Class in WordPress Codex
In the (accepted) answer the first example is incorrect:
It is incorrect because method
test
is not static.The correct use for the static call in the action would be:
you could also write it then as: