Make WordPress Core


Ignore:
Timestamp:
03/10/2015 11:04:12 PM (11 years ago)
Author:
ocean90
Message:

Customizer: Return the original value when filtering theme mods/options and the current blog has changed.

props westonruter.
fixes #31428.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-setting.php

    r31705 r31707  
    115115        }
    116116
     117        /**
     118         * The ID for the current blog when the preview() method was called.
     119         *
     120         * @since 4.2.0
     121         * @var int
     122         */
     123        protected $_previewed_blog_id;
     124
     125        /**
     126         * Return true if the current blog is not the same as the previewed blog.
     127         *
     128         * @since 4.2.0
     129         * @return bool|null Returns null if preview() has not been called yet.
     130         */
     131        public function is_current_blog_previewed() {
     132                if ( ! isset( $this->_previewed_blog_id ) ) {
     133                        return null;
     134                }
     135                return ( get_current_blog_id() === $this->_previewed_blog_id );
     136        }
     137
     138        /**
     139         * Original non-previewed value stored by the preview method.
     140         *
     141         * @see WP_Customize_Setting::preview()
     142         * @since 4.1.1
     143         * @var mixed
     144         */
    117145        protected $_original_value;
    118146
     
    125153                if ( ! isset( $this->_original_value ) ) {
    126154                        $this->_original_value = $this->value();
     155                }
     156                if ( ! isset( $this->_previewed_blog_id ) ) {
     157                        $this->_previewed_blog_id = get_current_blog_id();
    127158                }
    128159
     
    170201         * Callback function to filter the theme mods and options.
    171202         *
     203         * If switch_to_blog() was called after the preview() method, and the current
     204         * blog is now not the same blog, then this method does a no-op and returns
     205         * the original value.
     206         *
    172207         * @since 3.4.0
    173208         * @uses WP_Customize_Setting::multidimensional_replace()
     
    177212         */
    178213        public function _preview_filter( $original ) {
     214                if ( ! $this->is_current_blog_previewed() ) {
     215                        return $original;
     216                }
     217
    179218                $undefined = new stdClass(); // symbol hack
    180219                $post_value = $this->post_value( $undefined );
Note: See TracChangeset for help on using the changeset viewer.