admin管理员组文章数量:1326636
Is there an action i can hook into when a post is set from published back to draft? I have tried both transition_post_status
and publish_to_draft
but they don't seem to work when I set the post back to draft. I am doing something like:
add_action('publish_to_draft', 'doStuff')
function doStuff() {
// do stuff here
}
Maybe there is something I am missing, but I wanted to check that these are the correct hooks to use.
Is there an action i can hook into when a post is set from published back to draft? I have tried both transition_post_status
and publish_to_draft
but they don't seem to work when I set the post back to draft. I am doing something like:
add_action('publish_to_draft', 'doStuff')
function doStuff() {
// do stuff here
}
Maybe there is something I am missing, but I wanted to check that these are the correct hooks to use.
Share Improve this question asked Aug 7, 2020 at 23:19 Anton EmeryAnton Emery 32 bronze badges1 Answer
Reset to default 0Yes, these are probably the right calls to use for what you want.
I just checked this by adding this to my functions.php:
add_action('publish_to_draft', 'doStuff');
function doStuff() {
update_option('foo', 'bar1');
}
Then using the quick edit in the posts list to change a published post to draft, and this hook definitely ran at that point and set this option in the database.
Note that if you echo something from this hook, or expect to see something output to your browser you likely won't see it, and you might cause an error as this might be being called via an ajax type call.
本文标签: Hook when post is set from published to draft
版权声明:本文标题:Hook when post is set from published to draft? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742204197a2432509.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论