WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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
@Ralf912 Any Idea how will affect it if the function is private? – g3ek1337 May 27 '15 at 14:01

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.