WordPress 4.1.1
[autoinstalls/wordpress.git] / wp-includes / class-wp-customize-setting.php
index 0207b709fd6668a701bf86b4a1b710f3752469be..d8bf1e2371c076299f0ea619f3f6574986c78cb9 100644 (file)
@@ -103,12 +103,18 @@ class WP_Customize_Setting {
                return $this;
        }
 
+       protected $_original_value;
+
        /**
         * Handle previewing the setting.
         *
         * @since 3.4.0
         */
        public function preview() {
+               if ( ! isset( $this->_original_value ) ) {
+                       $this->_original_value = $this->value();
+               }
+
                switch( $this->type ) {
                        case 'theme_mod' :
                                add_filter( 'theme_mod_' . $this->id_data[ 'base' ], array( $this, '_preview_filter' ) );
@@ -159,7 +165,15 @@ class WP_Customize_Setting {
         * @return mixed New or old value.
         */
        public function _preview_filter( $original ) {
-               return $this->multidimensional_replace( $original, $this->id_data[ 'keys' ], $this->post_value() );
+               $undefined = new stdClass(); // symbol hack
+               $post_value = $this->manager->post_value( $this, $undefined );
+               if ( $undefined === $post_value ) {
+                       $value = $this->_original_value;
+               } else {
+                       $value = $post_value;
+               }
+
+               return $this->multidimensional_replace( $original, $this->id_data['keys'], $value );
        }
 
        /**
@@ -425,8 +439,15 @@ class WP_Customize_Setting {
                        $node = &$node[ $key ];
                }
 
-               if ( $create && ! isset( $node[ $last ] ) )
-                       $node[ $last ] = array();
+               if ( $create ) {
+                       if ( ! is_array( $node ) ) {
+                               // account for an array overriding a string or object value
+                               $node = array();
+                       }
+                       if ( ! isset( $node[ $last ] ) ) {
+                               $node[ $last ] = array();
+                       }
+               }
 
                if ( ! isset( $node[ $last ] ) )
                        return;