Make WordPress Core


Ignore:
Timestamp:
02/03/2015 10:14:28 AM (10 years ago)
Author:
ocean90
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.
fixes #30988.

File:
1 edited

Legend:

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

    r31126 r31329  
    101101    }
    102102
     103    protected $_original_value;
     104
    103105    /**
    104106     * Handle previewing the setting.
     
    107109     */
    108110    public function preview() {
     111        if ( ! isset( $this->_original_value ) ) {
     112            $this->_original_value = $this->value();
     113        }
     114
    109115        switch( $this->type ) {
    110116            case 'theme_mod' :
     
    157163     */
    158164    public function _preview_filter( $original ) {
    159         return $this->multidimensional_replace( $original, $this->id_data[ 'keys' ], $this->post_value() );
     165        $undefined = new stdClass(); // symbol hack
     166        $post_value = $this->manager->post_value( $this, $undefined );
     167        if ( $undefined === $post_value ) {
     168            $value = $this->_original_value;
     169        } else {
     170            $value = $post_value;
     171        }
     172
     173        return $this->multidimensional_replace( $original, $this->id_data['keys'], $value );
    160174    }
    161175
     
    423437        }
    424438
    425         if ( $create && ! isset( $node[ $last ] ) )
    426             $node[ $last ] = array();
     439        if ( $create ) {
     440            if ( ! is_array( $node ) ) {
     441                // account for an array overriding a string or object value
     442                $node = array();
     443            }
     444            if ( ! isset( $node[ $last ] ) ) {
     445                $node[ $last ] = array();
     446            }
     447        }
    427448
    428449        if ( ! isset( $node[ $last ] ) )
Note: See TracChangeset for help on using the changeset viewer.