Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of get_default_block_editor_settings #46112

Merged
merged 13 commits into from
Dec 6, 2022
28 changes: 27 additions & 1 deletion lib/experimental/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,40 @@ public static function get_theme_data( $deprecated = array(), $settings = array(
if ( ! $settings['with_supports'] ) {
return static::$theme;
}

$editor_settings = array(
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
'disableLayoutStyles' => get_theme_support( 'disable-layout-styles' ),
'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 ) {
$editor_settings['colors'] = $color_palette;
}

$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
if ( false !== $font_sizes ) {
$editor_settings['fontSizes'] = $font_sizes;
}

$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
if ( false !== $gradient_presets ) {
$editor_settings['gradients'] = $gradient_presets;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the new code here is now a bit of a duplicate code from what is already in get_default_block_editor_settings(). I think we can solve the problem in a more efficient way by enhancing that function.


/*
* We want the presets and settings declared in theme.json
* to override the ones declared via theme supports.
* 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( $editor_settings );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I would suggest is the following:

  • Add an optional $fields parameter (array of strings) to the get_default_block_editor_settings() function.
  • Change the function internals to only compute the properties which are requested.
  • Pass the new parameter here so that only the above actually needed properties are computed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically so that we can do something like:

$theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings(
	get_default_block_editor_settings(
		array(
			'disableCustomColors',
			'disableCustomFontSizes',
			'disableCustomGradients',
			'disableLayoutStyles',
			'enableCustomLineHeight',
			'enableCustomSpacing',
			'enableCustomUnits',
			'colors',
			'fontSizes',
			'gradients',
		)
	)
);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken it up into it's own function with a comment. b0a9764

if ( ! wp_theme_has_theme_json() ) {
if ( ! isset( $theme_support_data['settings']['color'] ) ) {
$theme_support_data['settings']['color'] = array();
Expand Down