wordpress 内容发布时涉及的钩子

在写百度熊掌号相关的代码时,用到了 publish_future_post 这个钩子,索性把所有相关的参数找齐,自己作一个备份记录。

wordpress 图标
wordpress
publish_post //参数一个($post_ID),点击发布文章时就会被触发;
save_post //参数一个($post_ID),发布或更新文章时就会被触发;
edit_post //参数两个($post_ID, $post),只要编辑已经存在的文章就会被触发;
publish_future_post //参数一个($post_ID),到定时发布文章设定的时间点就会被触发,如果设定的时间早于发布时间,不会被触发;
transition_post_status //参数三个($new_status, $old_status, $post),实现功能比较强大,可以根据文章发布状态的变化实现一些功能。
{$old_status}_to_{$new_status} //参数一个($post),比如 draft_to_publish 是通常的文章发布事件
future_to_publish 则可以用来处理定时文章发布事件。
post_updated //参数三个($post_ID, $post_after, $post_before),已存在文章更新了就会被触发。

其中 $post 为文章对象;$post_ID 为文章 ID;$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 这四个事件就相对比较简单,可以视情况而用。

© 版权声明
THE END
打赏一根烟,继续保持。
点赞0打赏作者 分享
评论 抢沙发
头像
友好交流,请勿发纯表情,请勿灌水,违者封号喔
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容