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
This commit is contained in:
Dominik Schilling 2015-03-10 23:05:27 +00:00
parent 9250d59e6a
commit 953cf28ac6
2 changed files with 40 additions and 1 deletions

View File

@ -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 ) {

View File

@ -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.