_update_posts_count_on_transition_post_status

函数


_update_posts_count_on_transition_post_status ( $new_status, $old_status, $post = null )
参数
  • (string)
    $new_status
    The status the post is changing to.
    Required:
  • (string)
    $old_status
    The status the post is changing from.
    Required:
  • (WP_Post)
    $post
    Post object
    Required:
    Default: null
定义位置
  • wp-includes/ms-blogs.php
    , line 903
引入
4.0.0
弃用

Handler for updating the current site’s posts count when a post status changes.

function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) {
	if ( $new_status === $old_status ) {
		return;
	}

	if ( 'post' !== get_post_type( $post ) ) {
		return;
	}

	if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
		return;
	}

	update_posts_count();
}