Make WordPress Core

Ticket #30988: 30988.diff

File 30988.diff, 2.9 KB (added by westonruter, 10 years ago)

https://github.com/xwp/wordpress-develop/pull/62

  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index c9dc52d..9030964 100644
    final class WP_Customize_Manager { 
    399399        }
    400400
    401401        /**
    402          * Decode the $_POST['customized'] values for a specific Customize Setting.
     402         * Decode the $_POST['customized'] values, and cache in _post_values array.
    403403         *
    404          * @since 3.4.0
    405          *
    406          * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object
    407          * @return string $post_value Sanitized value
     404         * @since 4.1.1
    408405         */
    409         public function post_value( $setting ) {
     406        protected function parse_post_data() {
    410407                if ( ! isset( $this->_post_values ) ) {
    411                         if ( isset( $_POST['customized'] ) )
     408                        if ( isset( $_POST['customized'] ) ) {
    412409                                $this->_post_values = json_decode( wp_unslash( $_POST['customized'] ), true );
    413                         else
     410                        } else {
    414411                                $this->_post_values = false;
     412                        }
    415413                }
     414        }
    416415
    417                 if ( isset( $this->_post_values[ $setting->id ] ) )
     416        /**
     417         * Get the post data value for a specific Customize Setting.
     418         *
     419         * @since 3.4.0
     420         *
     421         * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object
     422         * @param mixed $default Value to return when setting value is posted
     423         * @return mixed $post_value Sanitized value
     424         */
     425        public function post_value( $setting, $default = null ) {
     426                $this->parse_post_data();
     427                if ( is_array( $this->_post_values ) && array_key_exists( $setting->id, $this->_post_values ) ) {
    418428                        return $setting->sanitize( $this->_post_values[ $setting->id ] );
     429                } else {
     430                        return $default;
     431                }
    419432        }
    420433
    421434        /**
  • src/wp-includes/class-wp-customize-setting.php

    diff --git src/wp-includes/class-wp-customize-setting.php src/wp-includes/class-wp-customize-setting.php
    index 7a7be45..5eeb41a 100644
    class WP_Customize_Setting { 
    151151         *
    152152         * @since 3.4.0
    153153         * @uses WP_Customize_Setting::multidimensional_replace()
     154         * @uses WP_Customize_Setting::multidimensional_isset()
    154155         *
    155156         * @param mixed $original Old value.
    156157         * @return mixed New or old value.
    157158         */
    158159        public function _preview_filter( $original ) {
    159                 return $this->multidimensional_replace( $original, $this->id_data[ 'keys' ], $this->post_value() );
     160                $undefined = new stdClass();
     161                $value = $this->manager->post_value( $this, $undefined );
     162                if ( $undefined === $value ) {
     163                        $is_default_option_filter = ( 'option' === $this->type && 'default_option_' . $this->id_data['base'] === current_filter() );
     164                        if ( $is_default_option_filter || ! $this->multidimensional_isset( $original, $this->id_data['keys'] ) ) {
     165                                $replaced = $this->multidimensional_replace( $original, $this->id_data['keys'], $this->default );
     166                        } else {
     167                                $replaced = $original;
     168                        }
     169                } else {
     170                        $replaced = $this->multidimensional_replace( $original, $this->id_data['keys'], $value );
     171                }
     172                return $replaced;
    160173        }
    161174
    162175        /**