From 7d8b03458ce58c57a1c281599abc0318a3a05bae Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 1 Feb 2017 01:39:39 +0000 Subject: [PATCH] Customize: Ensure root values are accessible in multidimensional custom setting types. Fixes bad conditions in `WP_Customize_Setting::get_root_value()` and `WP_Customize_Setting::set_root_value()`. Props dlh. Amends [35007]. See #32103. Fixes #36952. git-svn-id: https://develop.svn.wordpress.org/trunk@40036 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-customize-setting.php | 4 ++-- tests/phpunit/tests/customize/setting.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-customize-setting.php b/src/wp-includes/class-wp-customize-setting.php index f89797425c..83a5b76d61 100644 --- a/src/wp-includes/class-wp-customize-setting.php +++ b/src/wp-includes/class-wp-customize-setting.php @@ -587,7 +587,7 @@ class WP_Customize_Setting { $id_base = $this->id_data['base']; if ( 'option' === $this->type ) { return get_option( $id_base, $default ); - } else if ( 'theme_mod' ) { + } elseif ( 'theme_mod' === $this->type ) { return get_theme_mod( $id_base, $default ); } else { /* @@ -616,7 +616,7 @@ class WP_Customize_Setting { $autoload = self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload']; } return update_option( $id_base, $value, $autoload ); - } else if ( 'theme_mod' ) { + } elseif ( 'theme_mod' === $this->type ) { set_theme_mod( $id_base, $value ); return true; } else { diff --git a/tests/phpunit/tests/customize/setting.php b/tests/phpunit/tests/customize/setting.php index 86a0743941..9db91a60e8 100644 --- a/tests/phpunit/tests/customize/setting.php +++ b/tests/phpunit/tests/customize/setting.php @@ -402,12 +402,21 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase { 'default' => 123, 'sanitize_callback' => array( $this->manager->nav_menus, 'intval_base10' ), ) ); + + /* + * In #36952 the conditions were such that get_theme_mod() be erroneously used + * to source the root value for a custom multidimensional type. + * Add a theme mod with the same name as the custom setting to test fix. + */ + set_theme_mod( $setting_id, 999 ); $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 ); + remove_theme_mod( $setting_id ); } /**