WordPress.org

Make WordPress Core

Ticket #37294: 37294.0.diff

File 37294.0.diff, 1.8 KB (added by westonruter, 5 years ago)
  • 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 f5cb1bf..fc78d07 100644
    class WP_Customize_Setting { 
    711711                } elseif ( $this->is_multidimensional_aggregated ) {
    712712                        $root_value = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
    713713                        $value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default );
     714
     715                        // Ensure that the post value is used if the setting is previewed, since preview filters aren't applying on cached $root_value.
     716                        if ( $this->is_previewed ) {
     717                                $value = $this->post_value( $value );
     718                        }
    714719                } else {
    715720                        $value = $this->get_root_value( $this->default );
    716721                }
  • tests/phpunit/tests/customize/setting.php

    diff --git tests/phpunit/tests/customize/setting.php tests/phpunit/tests/customize/setting.php
    index 98990c5..6ed5ee4 100644
    class Tests_WP_Customize_Setting extends WP_UnitTestCase { 
    640640                }
    641641                return $validity;
    642642        }
     643
     644        /**
     645         * Ensure that WP_Customize_Setting::value() can return a previewed value.
     646         *
     647         * @ticket 37294
     648         */
     649        public function test_multidimensional_value_when_previewed() {
     650                WP_Customize_Setting::reset_aggregated_multidimensionals();
     651
     652                $initial_value = 456;
     653                set_theme_mod( 'nav_menu_locations', array(
     654                        'primary' => $initial_value,
     655                ) );
     656                $setting_id = 'nav_menu_locations[primary]';
     657
     658                $setting = new WP_Customize_Setting( $this->manager, $setting_id );
     659                $this->assertEquals( $initial_value, $setting->value() );
     660
     661                $override_value = -123456;
     662                $this->manager->set_post_value( $setting_id, $override_value );
     663                $setting->preview();
     664
     665                $this->assertEquals( $override_value, $setting->value() );
     666        }
    643667}
    644668