返回介绍

_transition_post_status()

发布于 2017-09-11 13:37:25 字数 3158 浏览 973 评论 0 收藏 0

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use wp_clear_scheduled_hook() instead.

_transition_post_status( string $new_status,  string $old_status,  WP_Post $post )

Hook for managing future post transitions to published.


description


参数

$new_status

(string) (Required) New post status.

$old_status

(string) (Required) Previous post status.

$post

(WP_Post) (Required) Post object.


源代码

File: wp-includes/post.php

function _transition_post_status( $new_status, $old_status, $post ) {
	global $wpdb;

	if ( $old_status != 'publish' && $new_status == 'publish' ) {
		// Reset GUID if transitioning to publish and it is empty.
		if ( '' == get_the_guid($post->ID) )
			$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) );

		/**
		 * Fires when a post's status is transitioned from private to published.
		 *
		 * @since 1.5.0
		 * @deprecated 2.3.0 Use 'private_to_publish' instead.
		 *
		 * @param int $post_id Post ID.
		 */
		do_action('private_to_published', $post->ID);
	}

	// If published posts changed clear the lastpostmodified cache.
	if ( 'publish' == $new_status || 'publish' == $old_status) {
		foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) {
			wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' );
			wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' );
			wp_cache_delete( "lastpostdate:$timezone:{$post->post_type}", 'timeinfo' );
		}
	}

	if ( $new_status !== $old_status ) {
		wp_cache_delete( _count_posts_cache_key( $post->post_type ), 'counts' );
		wp_cache_delete( _count_posts_cache_key( $post->post_type, 'readable' ), 'counts' );
	}

	// Always clears the hook in case the post status bounced from future to draft.
	wp_clear_scheduled_hook('publish_future_post', array( $post->ID ) );
}

更新日志

Versiondescription
2.3.0Introduced.

相关函数

Uses

  • wp-includes/cron.php: wp_clear_scheduled_hook()
  • wp-includes/cache.php: wp_cache_delete()
  • wp-includes/link-template.php: get_permalink()
  • wp-includes/plugin.php: do_action()
  • wp-includes/post-template.php: get_the_guid()
  • wp-includes/post.php: private_to_published
  • wp-includes/post.php: _count_posts_cache_key()
  • wp-includes/wp-db.php: wpdb::update()
  • Show 3 more uses Hide more uses

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文