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
2 people authored and noisysocks committed Nov 22, 2021
1 parent 2069d76 commit 54018e4
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 54018e4

Please sign in to comment.