Make WordPress Core


Ignore:
Timestamp:
02/11/2015 06:24:01 AM (12 years ago)
Author:
dd32
Message:

Ensure that WP_Customize_Setting::value() returns default value for setting if not dirty.

There was regression introduced by #28580 where only changed (dirty) settings now are POST'ed to the Customizer preview.

  • Allow WP_Customize_Manager::post_value() to accept a second $default argument.
  • Introduce WP_Customize_Manager::unsanitized_post_values() for accessing previously-private member variable _post_values.
  • Do require_once instead of require for Customizer classes.
  • Add unit tests for WP_Customize_Manager and WP_Customize_Setting.

Props westonruter, boonebgorges.
Merges [31329] [31339] [31342] [31360] to the 4.1 branch.
Fixes #30988.

Location:
branches/4.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1

  • branches/4.1/src/wp-includes/class-wp-customize-setting.php

    r30676 r31410  
    104104        }
    105105
     106        protected $_original_value;
     107
    106108        /**
    107109         * Handle previewing the setting.
     
    110112         */
    111113        public function preview() {
     114                if ( ! isset( $this->_original_value ) ) {
     115                        $this->_original_value = $this->value();
     116                }
     117
    112118                switch( $this->type ) {
    113119                        case 'theme_mod' :
     
    160166         */
    161167        public function _preview_filter( $original ) {
    162                 return $this->multidimensional_replace( $original, $this->id_data[ 'keys' ], $this->post_value() );
     168                $undefined = new stdClass(); // symbol hack
     169                $post_value = $this->manager->post_value( $this, $undefined );
     170                if ( $undefined === $post_value ) {
     171                        $value = $this->_original_value;
     172                } else {
     173                        $value = $post_value;
     174                }
     175
     176                return $this->multidimensional_replace( $original, $this->id_data['keys'], $value );
    163177        }
    164178
     
    426440                }
    427441
    428                 if ( $create && ! isset( $node[ $last ] ) )
    429                         $node[ $last ] = array();
     442                if ( $create ) {
     443                        if ( ! is_array( $node ) ) {
     444                                // account for an array overriding a string or object value
     445                                $node = array();
     446                        }
     447                        if ( ! isset( $node[ $last ] ) ) {
     448                                $node[ $last ] = array();
     449                        }
     450                }
    430451
    431452                if ( ! isset( $node[ $last ] ) )
Note: See TracChangeset for help on using the changeset viewer.