views:

27

answers:

2

well im learning to create a wordpress plugin i downloaded one and read the codes, and i saw this i assume 'foo' is the tag where it will add action to..

but what does the array() exactly do?

add_action('foo', array('foo1', 'foo2'));

i looked at http://codex.wordpress.org/Function_Reference/add_action and there is no clear definition about it ..

A: 

The second argument of the add_action function is the function to be called with the hook.

function hello_header() {
 echo "I'm in the header!"; 
}

add_action('wp_head', 'hello_header');

The usage of an array as the second argument is to pass a objects method rather than just a regular function.

Have a read up on the how the call_user_func works. Should provide some more insight.

http://us2.php.net/manual/en/language.pseudo-types.php#language.types.callback

Stoosh
A: 

Right, the first argument is the tag (to which you'll be adding the action), and the second argument specifies the function to call (i.e. your callback).

The second argument takes in a PHP callback, and as such, accepts a number of valid forms. Check this out for all of them :

PHP Callback Pseudo-Types

The type you've shown above is of type 2. The first element of the array specifies a class, and the second element specifies which function of the class you'd like to call.

So with the example you've given above, what that will do is that, whenever the foo() action is called, it will eventually call foo1->foo2() as well.

Richard Neil Ilagan
Note that foo2() has to be static for this to work. :)
Richard Neil Ilagan
thank you richard, i understand it (almost) xDso you mean foo1 is the class and foo2 is the method within the class right?hell, i need to learn oop in php xDthanks guys sorry for such a dumb question :P
kapitanluffy
yup, that's basically right. :) ok lang yan. :p
Richard Neil Ilagan
@kapitanluffy - can you please mark this question as answered
Stoosh