Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

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" ) );

share|improve this answer
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 '12 at 20:30
Any idea as to above question? –  Chris Nov 29 '12 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 '12 at 21:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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