Skip to content

Commit

Permalink
Disable the core color palette when the theme does not have a `theme.…
Browse files Browse the repository at this point in the history
…json` (#36496)

Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com>
  • Loading branch information
oandregal and Mamaduka committed Nov 18, 2021
1 parent a61153b commit 475753b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion lib/class-wp-theme-json-resolver-gutenberg.php
Expand Up @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions phpunit/class-wp-theme-json-resolver-test.php
Expand Up @@ -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.
Expand Down

0 comments on commit 475753b

Please sign in to comment.