add_action()
add_action( string $tag, callable $function_to_add, int…
add_action( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )
将函数挂接到特定操作上。
Hooks a function on to a specific action.
目录锚点:#说明#参数#返回#源码#笔记
说明(Description)
Actions是WordPress核心在执行期间或发生特定事件时在特定点启动的钩子。插件可以使用Action API指定在这些点上执行一个或多个PHP函数。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$tag | (string) | 必需 | 要添加的$function的操作的名称。 |
$function_to_add | (callable) | 必需 | 要调用的函数的名称。 |
$priority | (int) | 可选 | 用于指定与特定操作关联的函数的执行顺序。较低的数字对应于先前的执行,具有相同优先级的函数按它们添加到操作中的顺序执行。 |
$accepted_args | (int) | 可选 | 函数接受的参数数。 |
返回(Return)
(true)将始终返回true。
源码(Source)
/** * Hooks a function on to a specific action. * * Actions are the hooks that the WordPress core launches at specific points * during execution, or when specific events occur. Plugins can specify that * one or more of its PHP functions are executed at these points, using the * Action API. * * @since 1.2.0 * * @param string $tag The name of the action to which the $function_to_add is hooked. * @param callback $function_to_add The name of the function you wish to be called. * @param int $priority Optional. Used to specify the order in which the functions * associated with a particular action are executed. Default 10. * Lower numbers correspond with earlier execution, * and functions with the same priority are executed * in the order in which they were added to the action. * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. * @return true Will always return true. */ function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { return add_filter($tag, $function_to_add, $priority, $accepted_args); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
1.2.0 | wp-includes/plugin.php:403 | 73 | 1 function |
笔记(Notes)
与类一起使用
与类中的静态函数一起使用
简单挂钩
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!