触发与过帐帖子状态相关的操作。
原型
wp_transition_post_status( string $new_status, string $old_status, WP_Post $post )
描述
保存帖子后,帖子状态将从一种状态“转换”到另一种状态,但这并不总是意味着状态在保存之前和之后实际已更改。此函数触发与该转换相关的许多动作挂钩:通用的“transition_post_status”动作,以及动态挂钩’$ old_status_to_ $ new_status’和’$ new_status_ $ post-> post_type’。请注意,该函数不会转换数据库中的post对象。
参数
$new_status
(string)
(Required)
过渡到此帖子状态。
$old_status
(string)
(Required)
以前的帖子状态。
$post
(WP_Post)
(Required)
发布数据。
源文件
路径:wp-includes/post.php
<?php
...
function wp_transition_post_status( $new_status, $old_status, $post ) {
/**
* Fires when a post is transitioned from one status to another.
*
* @since 2.3.0
*
* @param string $new_status New post status.
* @param string $old_status Old post status.
* @param WP_Post $post Post object.
*/
do_action( 'transition_post_status', $new_status, $old_status, $post );
/**
* Fires when a post is transitioned from one status to another.
*
* The dynamic portions of the hook name, `$new_status` and `$old status`,
* refer to the old and new post statuses, respectively.
*
* @since 2.3.0
*
* @param WP_Post $post Post object.
*/
do_action( "{$old_status}_to_{$new_status}", $post );
/**
* Fires when a post is transitioned from one status to another.
*
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
* refer to the new post status and post type, respectively.
*
* Please note: When this action is hooked using a particular post status (like
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
* first transitioned to that status from something else, as well as upon
* subsequent post updates (old and new status are both the same).
*
* Therefore, if you are looking to only fire a callback when a post is first
* transitioned to a status, use the {@see 'transition_post_status'} hook instead.
*
* @since 2.3.0
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_transition_post_status/