wordpress发布内容时常用到的钩子函数

164 阅读1分钟

publish_post

参数一个($post_ID),点击发布文章时就会被触发;

save_post

参数一个($post_ID),发布或更新文章时就会被触发;

edit_post

参数两个(postID,post_ID, post),只要编辑已经存在的文章就会被触发;

publish_future_post

参数一个($post_ID),到定时发布文章设定的时间点就会被触发,如果设定的时间早于发布时间,不会被触发;

transition_post_status

参数三个(newstatus,new_status, old_status, $post),实现功能比较强大,可以根据文章发布状态的变化实现一些功能。

{old_status}_to_{new_status}

参数一个($post),比如 draft_to_publish 是通常的文章发布事件

future_to_publish

则可以用来处理定时文章发布事件。

post_updated

参数三个(postID,post_ID, post_after, $post_before),已存在文章更新了就会被触发。

其中 post为文章对象;post 为文章对象; post_ID 为文章 ID; poststatus为文章对象的发布状态(包括newpublishfuturedraftpendingprivatetrashautodraft等);post_status 为文章对象的发布状态(包括 new,publish,future,draft,pending,private,trash,auto-draft 等); post_type 为文章对象的发布类型(包括 post,page,attachment,revision 等)。

对比上面的函数说明可以发现,post_updated 事件是最强大的,可以获取到文章修改前后的所有内容,参数较多;其次是 transition_post_status 事件,功能也比较强;接着是 {old_status}_to_{new_status} 事件,针对性较强,可以对特定情况进行事件抓取;而 publish_post、save_post、edit_post 和 publish_future_post 这四个事件就相对比较简单,可以视情况而用。

欢迎关注我的公众号“xx主题网”,原创技术文章第一时间推送。

文章来源:www.xxzhuti.com/775.html