WordPress.org

Make WordPress Core

Changeset 37982


Ignore:
Timestamp:
07/06/2016 05:58:28 AM (4 years ago)
Author:
westonruter
Message:

Customize: Ensure that WP_Customize_Setting::value() can return a previewed value for aggregated multidimensionals.

Fixes #37294.

Location:
trunk
Files:
2 edited

Legend:

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

    r37491 r37982  
    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 );
  • trunk/tests/phpunit/tests/customize/setting.php

    r37476 r37982  
    641641        return $validity;
    642642    }
     643
     644    /**
     645     * Ensure that WP_Customize_Setting::value() can return a previewed value for aggregated multidimensionals.
     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
Note: See TracChangeset for help on using the changeset viewer.