博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
wordpress自动发布_WordPress发布帖子挂钩
阅读量:2512 次
发布时间:2019-05-11

本文共 1565 字,大约阅读时间需要 5 分钟。

wordpress自动发布

One of the best parts of WordPress is its hook/action system; this special hook system is WordPress' way of assigning callbacks when certain events occur. One event that there seems to be a lot of confusion over is which hook to use to detect when a post is initially published. There's the publish_post hook but that fires when you click the "Update" button after a post has already been published; that's not ideal.

WordPress最好的部分之一是它的钩子/动作系统。 这种特殊的挂钩系统是WordPress在某些事件发生时分配回调的方式。 似乎有很多困惑的事件是用于检测帖子最初发布时间的钩子。 有publish_post钩子,但是在发布了一个帖子后单击“更新”按钮时会触发该钩子; 那不理想。

Scour the WordPress documentation and forums and you're sure to see a dozen other solutions but none work as well as the transition_post_status hook:

搜寻WordPress文档和论坛,您肯定会看到许多其他解决方案,但没有一个能像transition_post_status挂钩一样有效:

// Add the hook actionadd_action('transition_post_status', 'send_new_post', 10, 3);// Listen for publishing of a new postfunction send_new_post($new_status, $old_status, $post) {  if('publish' === $new_status && 'publish' !== $old_status && $post->post_type === 'post') {    // Do something!  }}

The transition_post_status occurs when a post goes from one status to another; you can check out the to see other possible values. I've also added a post_type check to ensure the post is a blog post and not a page.

当帖子从一种状态变为另一种状态时,会发生transition_post_status 。 您可以查看以查看其他可能的值。 我还添加了一个post_type检查,以确保该帖子是博客帖子而不是页面。

Whew, took me a while to find what I needed here -- hopefully this saves you a lot of searching and pain!

ew,花了我一段时间在这里找到我需要的东西-希望这可以节省您很多搜索和痛苦!

翻译自:

wordpress自动发布

转载地址:http://okpwd.baihongyu.com/

你可能感兴趣的文章
并查集
查看>>
sessionStorage
查看>>
代码示例_进程
查看>>
Java中关键词之this,super的使用
查看>>
学习进度
查看>>
“此人不存在”
查看>>
github.com加速节点
查看>>
解密zend-PHP凤凰源码程序
查看>>
python3 序列分片记录
查看>>
Atitit.git的存储结构and 追踪
查看>>
atitit 读书与获取知识资料的attilax的总结.docx
查看>>
B站 React教程笔记day2(3)React-Redux
查看>>
找了一个api管理工具
查看>>
Part 2 - Fundamentals(4-10)
查看>>
使用Postmark测试后端存储性能
查看>>
NSTextView 文字链接的定制化
查看>>
第五天站立会议内容
查看>>
(转))iOS App上架AppStore 会遇到的坑
查看>>
做好产品
查看>>
项目管理经验
查看>>