From 68b9b45548b34dc332c7ce6d7aa76a47a53d6c49 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sat, 19 Nov 2016 05:59:12 +0000 Subject: [PATCH] Customize: Ensure `WP_Customize_Setting::value()` returns previewed value for custom types utilizing the `customize_value_{$id_base}` filter. Fixes #38864. git-svn-id: https://develop.svn.wordpress.org/trunk@39318 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-customize-setting.php | 9 +++++++++ .../class-wp-customize-custom-css-setting.php | 9 ++++++--- tests/phpunit/tests/customize/setting.php | 12 ++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-customize-setting.php b/src/wp-includes/class-wp-customize-setting.php index a16b100795..7f1f98ac3b 100644 --- a/src/wp-includes/class-wp-customize-setting.php +++ b/src/wp-includes/class-wp-customize-setting.php @@ -696,6 +696,15 @@ class WP_Customize_Setting { $is_core_type = ( 'option' === $this->type || 'theme_mod' === $this->type ); if ( ! $is_core_type && ! $this->is_multidimensional_aggregated ) { + + // Use post value if previewed and a post value is present. + if ( $this->is_previewed ) { + $value = $this->post_value( null ); + if ( null !== $value ) { + return $value; + } + } + $value = $this->get_root_value( $this->default ); /** diff --git a/src/wp-includes/customize/class-wp-customize-custom-css-setting.php b/src/wp-includes/customize/class-wp-customize-custom-css-setting.php index eb9379e425..eadd47c581 100644 --- a/src/wp-includes/customize/class-wp-customize-custom-css-setting.php +++ b/src/wp-includes/customize/class-wp-customize-custom-css-setting.php @@ -132,10 +132,13 @@ final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { * @return string */ public function value() { - $id_base = $this->id_data['base']; - if ( $this->is_previewed && null !== $this->post_value( null ) ) { - return $this->post_value(); + if ( $this->is_previewed ) { + $post_value = $this->post_value( null ); + if ( null !== $post_value ) { + return $post_value; + } } + $id_base = $this->id_data['base']; $value = ''; $post = wp_get_custom_css_post( $this->stylesheet ); if ( $post ) { diff --git a/tests/phpunit/tests/customize/setting.php b/tests/phpunit/tests/customize/setting.php index 89b0720163..03fd0c28b1 100644 --- a/tests/phpunit/tests/customize/setting.php +++ b/tests/phpunit/tests/customize/setting.php @@ -395,6 +395,18 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase { $this->assertEquals( $post_data_overrides[ $name ], $this->custom_type_getter( $name, $this->undefined ) ); $this->assertEquals( $post_data_overrides[ $name ], $setting->value() ); + // Custom type that does not handle supplying the post value from the customize_value_{$id_base} filter. + $setting_id = 'custom_without_previewing_value_filter'; + $setting = $this->manager->add_setting( $setting_id, array( + 'type' => 'custom_preview_test', + 'default' => 123, + 'sanitize_callback' => array( $this->manager->nav_menus, 'intval_base10' ), + ) ); + $this->assertSame( 123, $setting->value() ); + $this->manager->set_post_value( $setting_id, '456' ); + $setting->preview(); + $this->assertSame( 456, $setting->value() ); + unset( $this->custom_type_data_previewed, $this->custom_type_data_saved ); }