函数原型
do_action( string $hook_name, mixed $arg )
函数描述
Calls the callback functions that have been added to an action hook.
是否弃用
未弃用
函数参数
-
$hook_name
string
Required - The name of the action to be executed.
-
$arg
mixed
Optional - Additional arguments which are passed on to the functions hooked to the action. Default empty.
函数返回值
无
函数位置
File: wp-includes/plugin.php.
函数源码
// The action callback function.
function example_callback( $arg1, $arg2 ) {
// (maybe) do something with the args.
}
add_action( 'example_action', 'example_callback', 10, 2 );
/*
* Trigger the actions by calling the 'example_callback()' function
* that's hooked onto `example_action` above.
*
* - 'example_action' is the action hook.
* - $arg1 and $arg2 are the additional arguments passed to the callback.
do_action( 'example_action', $arg1, $arg2 );源码链接
变更日志
| Version | Description |
|---|---|
| 5.3.0 | Formalized the existing and already documented ...$arg parameter by adding it to the function signature. |
| 1.2.0 | Introduced. |

