返回介绍

_wp_customize_publish_changeset()

发布于 2017-09-11 13:40:33 字数 5786 浏览 1009 评论 0 收藏 0

_wp_customize_publish_changeset( string $new_status,  string $old_status,  WP_Post $changeset_post )

Publish a snapshot’s changes.


description


参数

$new_status

(string) (Required) New post status.

$old_status

(string) (Required) Old post status.

$changeset_post

(WP_Post) (Required) Changeset post object.


源代码

File: wp-includes/theme.php

function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) {
	global $wp_customize, $wpdb;

	$is_publishing_changeset = (
		'customize_changeset' === $changeset_post->post_type
		&&
		'publish' === $new_status
		&&
		'publish' !== $old_status
	);
	if ( ! $is_publishing_changeset ) {
		return;
	}

	if ( empty( $wp_customize ) ) {
		require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
		$wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $changeset_post->post_name ) );
	}

	if ( ! did_action( 'customize_register' ) ) {
		/*
		 * When running from CLI or Cron, the customize_register action will need
		 * to be triggered in order for core, themes, and plugins to register their
		 * settings. Normally core will add_action( 'customize_register' ) at
		 * priority 10 to register the core settings, and if any themes/plugins
		 * also add_action( 'customize_register' ) at the same priority, they
		 * will have a $wp_customize with those settings registered since they
		 * call add_action() afterward, normally. However, when manually doing
		 * the customize_register action after the setup_theme, then the order
		 * will be reversed for two actions added at priority 10, resulting in
		 * the core settings no longer being available as expected to themes/plugins.
		 * So the following manually calls the method that registers the core
		 * settings up front before doing the action.
		 */
		remove_action( 'customize_register', array( $wp_customize, 'register_controls' ) );
		$wp_customize->register_controls();

		/** This filter is documented in /wp-includes/class-wp-customize-manager.php */
		do_action( 'customize_register', $wp_customize );
	}
	$wp_customize->_publish_changeset_values( $changeset_post->ID ) ;

	/*
	 * Trash the changeset post if revisions are not enabled. Unpublished
	 * changesets by default get garbage collected due to the auto-draft status.
	 * When a changeset post is published, however, it would no longer get cleaned
	 * out. Ths is a problem when the changeset posts are never displayed anywhere,
	 * since they would just be endlessly piling up. So here we use the revisions
	 * feature to indicate whether or not a published changeset should get trashed
	 * and thus garbage collected.
	 */
	if ( ! wp_revisions_enabled( $changeset_post ) ) {
		$post = $changeset_post;
		$post_id = $changeset_post->ID;

		/*
		 * The following re-formulates the logic from wp_trash_post() as done in
		 * wp_publish_post(). The reason for bypassing wp_trash_post() is that it
		 * will mutate the the post_content and the post_name when they should be
		 * untouched.
		 */
		if ( ! EMPTY_TRASH_DAYS ) {
			wp_delete_post( $post_id, true );
		} else {
			/** This action is documented in wp-includes/post.php */
			do_action( 'wp_trash_post', $post_id );

			add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
			add_post_meta( $post_id, '_wp_trash_meta_time', time() );

			$old_status = $post->post_status;
			$new_status = 'trash';
			$wpdb->update( $wpdb->posts, array( 'post_status' => $new_status ), array( 'ID' => $post->ID ) );
			clean_post_cache( $post->ID );

			$post->post_status = $new_status;
			wp_transition_post_status( $new_status, $old_status, $post );

			/** This action is documented in wp-includes/post.php */
			do_action( 'edit_post', $post->ID, $post );

			/** This action is documented in wp-includes/post.php */
			do_action( "save_post_{$post->post_type}", $post->ID, $post, true );

			/** This action is documented in wp-includes/post.php */
			do_action( 'save_post', $post->ID, $post, true );

			/** This action is documented in wp-includes/post.php */
			do_action( 'wp_insert_post', $post->ID, $post, true );

			/** This action is documented in wp-includes/post.php */
			do_action( 'trashed_post', $post_id );
		}
	}
}

Collapse full 源代码 code View on Trac


相关函数

Uses

  • wp-includes/class-wp-customize-manager.php: customize_register
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::__construct()
  • wp-includes/plugin.php: remove_action()
  • wp-includes/plugin.php: did_action()
  • wp-includes/plugin.php: do_action()
  • wp-includes/post.php: clean_post_cache()
  • wp-includes/post.php: wp_transition_post_status()
  • wp-includes/post.php: edit_post
  • wp-includes/post.php: save_post_{$post->post_type}
  • wp-includes/post.php: save_post
  • wp-includes/post.php: wp_insert_post
  • wp-includes/post.php: wp_delete_post()
  • wp-includes/post.php: wp_trash_post
  • wp-includes/post.php: trashed_post
  • wp-includes/post.php: add_post_meta()
  • wp-includes/revision.php: wp_revisions_enabled()
  • wp-includes/wp-db.php: wpdb::update()
  • Show 12 more uses Hide more uses

User Contributed Notes

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

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

发布评论

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