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 ..
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.
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.
(dead link)http://us2.php.net/manual/en/language.pseudo-types.php#language.types.callback
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With