开发者

add_action function in wordpress

开发者 https://www.devze.com 2023-01-14 14:44 出处:网络
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..

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.

http://us2.php.net/manual/en/language.pseudo-types.php#language.types.callback(dead link)

0

精彩评论

暂无评论...
验证码 换一张
取 消