There is the following do_action

do_action( 'example', $this->nothing());

Where nothing() does exactly what it sounds like.

This logic is in a public function testFunction in a class called Test.

What I would like to do is hook into this function (I'm in a different plugin), and call a different function (looppages()) that is already in the same class as the above logic like this:

add_action( 'example', Test::looppages);

Can I do this?

1 Answer 1


No, you can't.

add_action( 'hook', array( [class], "method_name" ) ); is the right way to use a method as callback. Read about how to use methods as callback in the codex.

If you want to use a static method as callback, do it in this way:

add_action( 'hook', array( "ClassName", "method_name" ) );

  • I'm calling from one __construct to another though, so in my do_action do I need to pass this as a parameter or something?
    – Chris
    Nov 29, 2012 at 20:30
  • Any idea as to above question?
    – Chris
    Nov 29, 2012 at 20:55
  • Code examples are very helpfull. And if you post more than just one or two lines of code, others get a chance to understand what you are planning.
    – Ralf912
    Nov 29, 2012 at 21:35
  • @Ralf912 Any Idea how will affect it if the function is private? May 27, 2015 at 14:01
  • it works thanks for this post @Ralf912
    – bdalina
    May 10, 2019 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.