企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**常用函数-add_action()** **说明** 将函数连接到指定action(动作)。 在Plugin API/Action Reference 上查看动作hook列表。wordpress核心调用do_action() 时触发动作。 **用法** ~~~ <?php add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1); ?> ~~~ **示例** 博客发表新内容时用电子邮件通知朋友: ~~~ function email_friends($post_ID) { $friends = 'bob@example.org, susie@example.org'; mail($friends, "sally's blog updated" , 'I just put something on my blog: http://blog.example.com'); return $post_ID; } add_action('publish_post', 'email_friends'); ~~~ **参数** **$tag** (字符串)希望连接到的动作名称(在Plugin API/Action Reference 上查看动作hook列表) **$function_to_add** (回调)希望调用的函数名称。注意: the PHP documentation for the 'callback' type中解释的语法均可用。 **$priority** 函数的重要程度。改变此参数以决定函数与其他函数的调用顺序。默认值为10,因此(例如)将值设为5时函数运行较早,设为12时运行则较晚。 **$accepted_args** 函数所接受参数的数量。在WordPress 1.5.1及之后版本中,连接的函数可吸收其它在调用do_action() 或 apply_filters()时设置的参数。例如,comment_id_not_found动作将传递任何函数,若该函数将所请求的评论编号连接到该动作。