From 60843b4336c2fea511d8e07598373c5c71538da4 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 6 Dec 2022 14:09:53 +0000 Subject: [PATCH] Remove usage of get_default_block_editor_settings (#46112) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove usage of get_default_block_editor_settings`. * Remove to it's own function. * Fix lints. * Move to 6.2 class. * WP_Theme_JSON -> WP_Theme_JSON_Gutenberg. * Update lib/compat/wordpress-6.2/class-wp-theme-json-resolver-6-2.php Co-authored-by: André <583546+oandregal@users.noreply.github.com> * Move functionality around again. * Fix merge conflict * Fix more issues. * More moving. * Revert changes. * More reverts. Co-authored-by: André <583546+oandregal@users.noreply.github.com> --- .../get-global-styles-and-settings.php | 35 +++++++++++++++++++ ...class-wp-theme-json-resolver-gutenberg.php | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.1/get-global-styles-and-settings.php b/lib/compat/wordpress-6.1/get-global-styles-and-settings.php index fd6113c7405c4a..0829a09d084c70 100644 --- a/lib/compat/wordpress-6.1/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-6.1/get-global-styles-and-settings.php @@ -54,3 +54,38 @@ function ( $item ) { } } } + +/** + * Repeated logic from `get_default_block_editor_settings` function. When implemented into core, + * remove logic from `get_default_block_editor_settings` and simple call this function instead. + * + * @return array + */ +function gutenberg_get_legacy_theme_supports_for_theme_json() { + $theme_settings = array( + 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), + 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), + 'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ), + 'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ), + 'enableCustomSpacing' => get_theme_support( 'custom-spacing' ), + 'enableCustomUnits' => get_theme_support( 'custom-units' ), + ); + + // Theme settings. + $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) ); + if ( false !== $color_palette ) { + $theme_settings['colors'] = $color_palette; + } + + $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) ); + if ( false !== $font_sizes ) { + $theme_settings['fontSizes'] = $font_sizes; + } + + $gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) ); + if ( false !== $gradient_presets ) { + $theme_settings['gradients'] = $gradient_presets; + } + + return $theme_settings; +} diff --git a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php index fd13681e5a12ee..17f2dc87f04d00 100644 --- a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php @@ -73,7 +73,7 @@ public static function get_theme_data( $deprecated = array(), $settings = array( * So we take theme supports, transform it to theme.json shape * and merge the static::$theme upon that. */ - $theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( get_default_block_editor_settings() ); + $theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( gutenberg_get_legacy_theme_supports_for_theme_json() ); if ( ! wp_theme_has_theme_json() ) { if ( ! isset( $theme_support_data['settings']['color'] ) ) { $theme_support_data['settings']['color'] = array();