From 953cf28ac601099ce92829e780046020a041fe6e Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 10 Mar 2015 23:05:27 +0000 Subject: [PATCH] Customizer: Return the original value when filtering theme mods/options and the current blog has changed. props westonruter. fixes #31428. Built from https://develop.svn.wordpress.org/trunk@31707 git-svn-id: http://core.svn.wordpress.org/trunk@31688 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-customize-setting.php | 39 ++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-customize-setting.php b/wp-includes/class-wp-customize-setting.php index 8bb3e9438b..1541253492 100644 --- a/wp-includes/class-wp-customize-setting.php +++ b/wp-includes/class-wp-customize-setting.php @@ -114,6 +114,34 @@ class WP_Customize_Setting { add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 ); } + /** + * The ID for the current blog when the preview() method was called. + * + * @since 4.2.0 + * @var int + */ + protected $_previewed_blog_id; + + /** + * Return true if the current blog is not the same as the previewed blog. + * + * @since 4.2.0 + * @return bool|null Returns null if preview() has not been called yet. + */ + public function is_current_blog_previewed() { + if ( ! isset( $this->_previewed_blog_id ) ) { + return null; + } + return ( get_current_blog_id() === $this->_previewed_blog_id ); + } + + /** + * Original non-previewed value stored by the preview method. + * + * @see WP_Customize_Setting::preview() + * @since 4.1.1 + * @var mixed + */ protected $_original_value; /** @@ -125,6 +153,9 @@ class WP_Customize_Setting { if ( ! isset( $this->_original_value ) ) { $this->_original_value = $this->value(); } + if ( ! isset( $this->_previewed_blog_id ) ) { + $this->_previewed_blog_id = get_current_blog_id(); + } switch( $this->type ) { case 'theme_mod' : @@ -169,6 +200,10 @@ class WP_Customize_Setting { /** * Callback function to filter the theme mods and options. * + * If switch_to_blog() was called after the preview() method, and the current + * blog is now not the same blog, then this method does a no-op and returns + * the original value. + * * @since 3.4.0 * @uses WP_Customize_Setting::multidimensional_replace() * @@ -176,6 +211,10 @@ class WP_Customize_Setting { * @return mixed New or old value. */ public function _preview_filter( $original ) { + if ( ! $this->is_current_blog_previewed() ) { + return $original; + } + $undefined = new stdClass(); // symbol hack $post_value = $this->post_value( $undefined ); if ( $undefined === $post_value ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 380275bed2..02a6601c2c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31706'; +$wp_version = '4.2-alpha-31707'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.