WordPress的挂钩前发布更新 [英] Wordpress Hook Pre Post Update

查看:88
本文介绍了WordPress的挂钩前发布更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个wordpress插件.如果发布状态为将来,我想将发布状态设置为发布.

I am writing a wordpress plugin. I would like to to set the post status to publish if post status is future.

我知道要使用的一个钩子是pre_post_update.

I know one hook that is to be used that is pre_post_update.

但是,与帖子相关的详细信息数组存储在哪里,以便我可以更改post_status?

However where is the array of post related details stored so that I can change the post_status?

感谢您的帮助

推荐答案

调用pre_post_update挂钩的函数对我来说出现在wp-includes/posts.php的第1525行:

The function that calls the pre_post_update hook appears on line 1525 of wp-includes/posts.php for me:

do_action( 'pre_post_update', $post_ID );

如您所见,它在执行时传递要更新的帖子的ID.要从那里获取帖子,您只需致电get_post(),例如:

As you can see, it passes the ID of the post being updated when it is executed. To get the post from there, you would just call get_post(), e.g.:

function do_something_with_a_post($post_id, $post_data) {
     // now do something with $post_data
}
add_action('pre_post_update', 'do_something_with_a_post', 10, 2);

希望,上面的$post变量应该引用一个对象,该对象具有与您正在寻找的帖子有关的所有各种属性.

The $post variable above should reference an object with all of the various attributes about a post you are looking for, hopefully.

这篇关于WordPress的挂钩前发布更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆