函数原型
add_action( string $hook_name, callable $callback, int $priority = 10, int $accepted_args = 1 ): true
函数描述
Adds a callback function to an action hook.
是否弃用
未弃用
函数参数
-
$hook_name
string
Required - The name of the action to add the callback to.
-
$callback
callable
Required - The callback to be run when the action is called.
-
$priority
int
Optional - Used to specify the order in which the functions associated with a particular action are executed.
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.Default:
10 -
$accepted_args
int
Optional - The number of arguments the function accepts.
Default:
1
函数返回值
true Always returns true.
函数位置
File: wp-includes/plugin.php.
函数源码
add_action( $hook, $function_to_add, $priority, $accepted_args );源码链接
变更日志
| Version | Description |
|---|---|
| 1.2.0 | Introduced. |

