From 475753ba7be9de2e62c19de8817323d0d562ad45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 18 Nov 2021 17:35:08 +0100 Subject: [PATCH] Disable the core color palette when the theme does not have a `theme.json` (#36496) Co-authored-by: George Mamadashvili --- ...class-wp-theme-json-resolver-gutenberg.php | 27 ++++++++++++++++++- phpunit/class-wp-theme-json-resolver-test.php | 4 +-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 65c05bea029be..3ebd995f5e706 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -157,7 +157,32 @@ public static function get_theme_data() { * So we take theme supports, transform it to theme.json shape * and merge the self::$theme upon that. */ - $theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( gutenberg_get_default_block_editor_settings() ); + $theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( gutenberg_get_default_block_editor_settings() ); + if ( ! self::theme_has_support() ) { + if ( ! isset( $theme_support_data['settings']['color'] ) ) { + $theme_support_data['settings']['color'] = array(); + } + + $default_palette = false; + if ( current_theme_supports( 'default-color-palette' ) ) { + $default_palette = true; + } + if ( ! isset( $theme_support_data['settings']['color']['palette'] ) ) { + // If the theme does not have any palette, we still want to show the core one. + $default_palette = true; + } + $theme_support_data['settings']['color']['corePalette'] = $default_palette; + + $default_gradients = false; + if ( current_theme_supports( 'default-gradient-presets' ) ) { + $default_gradients = true; + } + if ( ! isset( $theme_support_data['settings']['color']['gradients'] ) ) { + // If the theme does not have any gradients, we still want to show the core ones. + $default_gradients = true; + } + $theme_support_data['settings']['color']['coreGradients'] = $default_gradients; + } $with_theme_supports = new WP_Theme_JSON_Gutenberg( $theme_support_data ); $with_theme_supports->merge( self::$theme ); diff --git a/phpunit/class-wp-theme-json-resolver-test.php b/phpunit/class-wp-theme-json-resolver-test.php index 289a940ace3c2..eb131bb697fe5 100644 --- a/phpunit/class-wp-theme-json-resolver-test.php +++ b/phpunit/class-wp-theme-json-resolver-test.php @@ -118,8 +118,8 @@ function test_translations_are_applied() { } function test_switching_themes_recalculates_data() { - // By default, the theme for unit tests is "default", - // which doesn't have theme.json support. + // The "default" theme doesn't have theme.json support. + switch_theme( 'default' ); $default = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support(); // Switch to a theme that does have support.