add_action( string $tag, callable $function_to_add, int $priority = 10,int $accepted_args = 1 )
$tag:必填(字符串)。$function_to_add 所挂载的动作(action)的名称。
$function_to_add:必填(回调)。你希望挂载的函数的名称。
$priority:可选(整型)。用于指定与特定的动作相关联的函数的执行顺序。数字越小,执行越早,默认值 10 。
$accepted_args:可选(整型)。挂钩函数所接受的参数数量。
该函数定义在 wp-includes/plugin.php 文件中:
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
return add_filter($tag, $function_to_add, $priority, $accepted_args);
}
通过源代码可知,其实际上还是调用了 add_filter() 函数,关于该函数请看这里>>> WordPress学习——add_filter()详解 。
参考文档:https://developer.wordpress.org/reference/functions/add_action/