有朋自远方来,不亦乐乎。
wordpress常见的action钩子大全(一)
原创 橘子书  发布于 8个月前 ( 05-02 ) 阅读: 862 次 评论: 8 条 A+

整理一些常见的),便于后期查询。

,页面,附件, 类别 Actions (Admin)

post_submitbox_misc_actions

原文:Runs when an editing page gets generated to add some content (eg. fields) to the submit box (where the publish button is shown). No function arguments.

翻译:在编辑页面生成提交按钮的内容,没有参数。

add_attachment

原文:Runs when an attached file is first added to the database. Action function arguments: attachment ID.

翻译:当一个附加的文件首先被添加到数据库中时运行。作用函数的参数:attachment ID.

add_category

原文:Same as create_category.

翻译:当有相同或类似的分类,立即新建?

category_add_form_fields

原文:Runs when category add form is cerated in admin. Useful to add a field in this form before the submit button

翻译:当分类的添加表单在后台被创建时,在提交按钮钱添加一个表单字段.也可以使用category_add_form

注意原代码为$taxonomy.’_add_form_fields’, $taxonomy除了可以为category外,也可以通过get_taxonomies()获取;

category_edit_form_fields

原文:Runs when category edit form is created in admin. Useful to add a new field to this form

翻译:当分类的编辑表单在后台被创建时,在提交按钮钱添加一个表单字段。也可以使用category_edit_form

注意原代码为$taxonomy.’_edit_form_fields’, $taxonomy除了可以为category外,也可以通过get_taxonomies()获取;

clean_post_cache

原文:Runs when post cache is cleaned. Action function arguments: post ID. See clean_post_cache().

翻译:当post缓存被清除时运行,参数:post ID

create_category

原文:Runs when a new category is created. Action function arguments: category ID.

翻译:当一个新的分类被创建时,参数:category ID.

delete_attachment

原文:Runs just before an attached file is deleted from the database. Action function arguments: attachment ID.

翻译:一个附加文件在被数据库删除前,参数:attachment ID,[在2.8版本前是在数据库删除后触发]

delete_category

原文:Runs just after a category is deleted from the database and its corresponding links/posts are updated to remove the category. Action function arguments: category ID.

翻译:一个分类被数据库删除,并且相应的 links/posts 在数据库中被移除,无关联后。参数:category ID

wp_trash_post

原文:Runs when a post or page is about to be trashed. Action function arguments: post or page ID.

翻译:当post或者page被移到回收站时。参数:post 或 page ID

trashed_post

原文:Runs just after a post or page is trashed. Action function arguments: post or page ID.

翻译:当post或者page被移到回收站后。参数:post 或 page ID

before_delete_post

原文:Runs when a post or page is about to be deleted. Comments, attachments and metadata are still available. Action function arguments: post or page ID.

翻译:当post或page将要被删除前,评论,附件,多媒体仍然可用。参数:post 或 page ID

delete_post

原文:Runs when a post or page is about to be deleted. Comments, attachments and metadata are already deleted. Action function arguments: post or page ID.

翻译:当post或page将要被删除时,评论,附件,多媒体已经被删除。参数:post 或 page ID

deleted_post

原文:Runs just after a post or page is deleted. Action function arguments: post or page ID.

翻译:当post或page被删除后。参数:post 或 page ID

edit_attachment

原文:Runs when an attached file is edited/updated to the database. Action function arguments: attachment ID.

翻译:当一个附件被 编辑/更新 在 数据库时。参数:attachment ID

edit_category

原文:Runs when a category is updated/edited, including when a post or blogroll link is added/deleted or its categories are updated (which causes the count for the category to update). Action function arguments: category ID.

翻译:当一个类别被更新,包括当文章或链接也被更新或者所有的类别被更新。参数:category ID.

edit_post

原文:Runs when a post or page is updated/edited, including when a comment is added or updated (which causes the comment count for the post to update). Action function arguments: post or page ID.

翻译:当post/page被更新,包括评论被更新。参数:post or page ID

pre_post_update

原文:Runs just before a post or page is updated. Action function arguments: post or page ID.

翻译:在post/page被更新前,参数:post or page ID

(old status)_to_(new status)

原文:(See also Post Status Transitions) Runs when a post status transition occurs. Action function arguments: old status, new status, post object. (Actions for all post status transitions are available: see wp_transition_post_status()).

翻译:当post状态改变时,参数:old status, new status, post object.

publish_page

原文:Runs when a page is published, or if it is edited and its status is “published”. Action function arguments: page ID. (WARNING: this hook seems to never fire on v2.3 and higher. The ‘transition_post_status’ hook does work though; UPDATE : publish_page hook appears to be working as of 2.6)

翻译:当page被发布,或者状态被改变为‘发布’时。参数:page ID.。

注意:该钩子在版本2.3以下使用,transition_post_status钩子仍然可以使用;更新publish_page钩子在2.6中可以使用。

publish_phone

原文:Runs just after a post is added via email. Action function argument: post ID.

翻译:当post添加email通过后,参数:post ID.

publish_post

原文:Runs when a post is published, or if it is edited and its status is “published”. Action function arguments: post ID.

翻译:当post被发布,后者状态改变为发布时,参数:post ID.

publish_future_post

原文:Runs when a future post or page is published. Action function arguments: post ID.

翻译:将要发布一个post/page时,参数:post ID.

save_post

原文:Runs whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email. Action function arguments: post ID and post object.

Runs after the data is saved to the database.

翻译:当post/page被创建或者被编辑,保持着数据库后触发,参数:post ID and post object.

原文:Note that post ID may reference a post revision and not the last saved post. Use wp_is_post_revision() to get the ID of the real post.

翻译:post ID 可以参考post版本,也可能不是最后一条记录,使用 wp_is_post_revision()获取真实的post ID .(注意!!!)

updated_postmeta

原文:Runs when a metadata has been updated.

翻译:当多媒体被更新后

wp_insert_post

原文:Same as save_post, runs immediately afterwards.

翻译:当相同或类似的save_post,立即运行?

xmlrpc_publish_post

原文:Runs when a post is published via XMLRPC request, or if it is edited via XMLRPC and its status is “published”. Action function arguments: post ID.

翻译:使用xmlrpc接口更改文章状态为发布时,参数:post ID

 

Principle Team
龙砚庭官方QQ群,一个坚持强怼的7P成员群!
10人已关注

目前评论:8   其中:访客  4   博主  4

发表评论

莫慌,小狮子正在努力加载评论...
  1. 品牌馆
    品牌馆1 ( 2018.05.03 16:13:35 )  4楼

    橘子兄,这是要搞大事了,期待橘子主题早日上线

  2. 西枫里博客
    西枫里博客3 ( 2018.05.03 0:45:59 )  地板

    主题应该就是需要通过这些钩子函数调用系统内置的功能吧?

    • 橘子书
      橘子书渣渣橘 ( 2018.05.04 9:37:54 )

      @西枫里博客 对对对,wordpress内置了很多函数,这些函数有些很鸡肋,有些超实用。但很多功能的实现离不开它们 :twisted: :lol:

  3. 懿古今
    懿古今3 ( 2018.05.02 17:16:50 )  板凳

    又开始研究WordPress钩子之类的,看来又准备有大动作啊

    • 橘子书
      橘子书渣渣橘 ( 2018.05.02 17:33:55 )

      @懿古今 没什么大动作,就是单纯觉得整理归纳一下,方便自己去官网(wordpress)查询开发文档。

  4. 明月登楼
    明月登楼3 ( 2018.05.02 16:40:09 )  沙发

    虽然大部分看不懂,但还是要感谢博主的分享!