WordPress——add_action()详解

2019年10月5日13:30:29 发表评论 2,101 views

add_action() 是 WordPress 核心代码执行期间或特定事件发生时启动的钩子函数。 插件可以指定使用 Action API 在这些特定点上执行其一个或多个PHP函数。简单来说就是通过 add_action() 将函数连接到指定 action 上。add_action() 的调用方法如下:

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/

 

 

 

 

历史上的今天:


欢迎来到菜鸟头头的个人博客
本文章百度已收录,若发现本站有任何侵犯您利益的内容,请及时邮件或留言联系,我会第一时间删除所有相关内容。

  • A+
所属分类:PHP

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: