问题描述
我正在写一个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的挂钩前发布更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!