From b13df0de495078688e415bcd57f46619ff221bad Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 16:15:34 -0500 Subject: [PATCH 01/11] Add default-font-sizes options for classic themes --- lib/class-wp-theme-json-resolver-gutenberg.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 84f999e4e9d02..6fd2c020cb140 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -317,6 +317,19 @@ public static function get_theme_data( $deprecated = array(), $options = array() } $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients; + if ( ! isset( $theme_support_data['settings']['typography'] ) ) { + $theme_support_data['settings']['typography'] = array(); + } + $default_font_sizes = false; + if ( current_theme_supports( 'default-font-sizes' ) ) { + $default_font_sizes = true; + } + if ( ! isset( $theme_support_data['settings']['typography']['fontSizes'] ) ) { + // If the theme does not have any font sizes, we still want to show the core one. + $default_font_sizes = true; + } + $theme_support_data['settings']['typography']['defaultFontSizes'] = $default_font_sizes; + if ( ! isset( $theme_support_data['settings']['shadow'] ) ) { $theme_support_data['settings']['shadow'] = array(); } From 2f32da933f525efba4f61d757432f63d88b2a254 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 16:22:08 -0500 Subject: [PATCH 02/11] Add default-spacing-sizes options for classic themes --- lib/class-wp-theme-json-resolver-gutenberg.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 6fd2c020cb140..ce4745bc46cd7 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -330,6 +330,19 @@ public static function get_theme_data( $deprecated = array(), $options = array() } $theme_support_data['settings']['typography']['defaultFontSizes'] = $default_font_sizes; + if ( ! isset( $theme_support_data['settings']['spacing'] ) ) { + $theme_support_data['settings']['spacing'] = array(); + } + $default_spacing_sizes = false; + if ( current_theme_supports( 'default-spacing-sizes' ) ) { + $default_spacing_sizes = true; + } + if ( ! isset( $theme_support_data['settings']['spacing']['spacingSizes'] ) ) { + // If the theme does not have any spacing sizes, we still want to show the core one. + $default_spacing_sizes = true; + } + $theme_support_data['settings']['spacing']['defaultSpacingSizes'] = $default_spacing_sizes; + if ( ! isset( $theme_support_data['settings']['shadow'] ) ) { $theme_support_data['settings']['shadow'] = array(); } From 937eccadeef182ff8c96257edf78153bb06ebe7d Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 16:58:48 -0500 Subject: [PATCH 03/11] Add backport changelog --- backport-changelog/6.6/6616.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backport-changelog/6.6/6616.md b/backport-changelog/6.6/6616.md index 91261f78fb5c7..33cbf5e2bd991 100644 --- a/backport-changelog/6.6/6616.md +++ b/backport-changelog/6.6/6616.md @@ -2,4 +2,5 @@ https://github.com/WordPress/wordpress-develop/pull/6616 * https://github.com/WordPress/gutenberg/pull/58409 * https://github.com/WordPress/gutenberg/pull/61328 -* https://github.com/WordPress/gutenberg/pull/61842 \ No newline at end of file +* https://github.com/WordPress/gutenberg/pull/61842 +* https://github.com/WordPress/gutenberg/pull/62252 From d97af0ef2ca2631826b9b9ea35bb633c937ce7b8 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 18:27:31 -0500 Subject: [PATCH 04/11] Backport get_classic_theme_supports_block_editor_settings from core --- lib/block-editor.php | 44 +++++++++++++++++++ ...class-wp-theme-json-resolver-gutenberg.php | 2 +- phpunit/class-wp-theme-json-test.php | 6 +-- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 lib/block-editor.php diff --git a/lib/block-editor.php b/lib/block-editor.php new file mode 100644 index 0000000000000..b7e6da0eea873 --- /dev/null +++ b/lib/block-editor.php @@ -0,0 +1,44 @@ + 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 ) { + $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/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index ce4745bc46cd7..44c2cae07da96 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -291,7 +291,7 @@ public static function get_theme_data( $deprecated = array(), $options = 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_classic_theme_supports_block_editor_settings() ); + $theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( gutenberg_get_classic_theme_supports_block_editor_settings() ); if ( ! wp_theme_has_theme_json() ) { if ( ! isset( $theme_support_data['settings']['color'] ) ) { $theme_support_data['settings']['color'] = array(); diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index 549898b3c8773..bcf0d238400a0 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -3161,7 +3161,7 @@ public function test_get_editor_settings_blank() { public function test_get_editor_settings_custom_units_can_be_disabled() { add_theme_support( 'custom-units', array() ); - $actual = WP_Theme_JSON_Gutenberg::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() ); + $actual = WP_Theme_JSON_Gutenberg::get_from_editor_settings( gutenberg_get_classic_theme_supports_block_editor_settings() ); remove_theme_support( 'custom-units' ); $expected = array( @@ -3174,7 +3174,7 @@ public function test_get_editor_settings_custom_units_can_be_disabled() { public function test_get_editor_settings_custom_units_can_be_enabled() { add_theme_support( 'custom-units' ); - $actual = WP_Theme_JSON_Gutenberg::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() ); + $actual = WP_Theme_JSON_Gutenberg::get_from_editor_settings( gutenberg_get_classic_theme_supports_block_editor_settings() ); remove_theme_support( 'custom-units' ); $expected = array( @@ -3187,7 +3187,7 @@ public function test_get_editor_settings_custom_units_can_be_enabled() { public function test_get_editor_settings_custom_units_can_be_filtered() { add_theme_support( 'custom-units', 'rem', 'em' ); - $actual = WP_Theme_JSON_Gutenberg::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() ); + $actual = WP_Theme_JSON_Gutenberg::get_from_editor_settings( gutenberg_get_classic_theme_supports_block_editor_settings() ); remove_theme_support( 'custom-units' ); $expected = array( From a0ded7a5643a0c584607ec9efe0977647a525898 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 18:28:53 -0500 Subject: [PATCH 05/11] Add doc comment for get_theme_data new theme supports --- lib/class-wp-theme-json-resolver-gutenberg.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 44c2cae07da96..28121cf1b8c8a 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -220,6 +220,7 @@ protected static function has_same_registered_blocks( $origin ) { * @since 5.8.0 * @since 5.9.0 Theme supports have been inlined and the `$theme_support_data` argument removed. * @since 6.0.0 Added an `$options` parameter to allow the theme data to be returned without theme supports. + * @since 6.6.0 Add support for 'default-font-sizes' and 'default-spacing-sizes' theme supports. * * @param array $deprecated Deprecated. Not used. * @param array $options { From 05d7d2a96cffc8e7e90bfa64d79a02f06d37ac68 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 18:29:21 -0500 Subject: [PATCH 06/11] Add editor-spacing-sizes option for classic themes --- lib/block-editor.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/block-editor.php b/lib/block-editor.php index b7e6da0eea873..6253f6a0adca4 100644 --- a/lib/block-editor.php +++ b/lib/block-editor.php @@ -10,6 +10,7 @@ * Returns the classic theme supports settings for block editor. * * @since 6.2.0 + * @since 6.6.0 Add support for custom spacing sizes. * * @return array The classic theme supports settings. */ @@ -40,5 +41,10 @@ function gutenberg_get_classic_theme_supports_block_editor_settings() { $theme_settings['gradients'] = $gradient_presets; } + $spacing_sizes = current( (array) get_theme_support( 'editor-spacing-sizes' ) ); + if ( false !== $spacing_sizes ) { + $theme_settings['spacingSizes'] = $spacing_sizes; + } + return $theme_settings; } From 93e3a09f0a9865cf9ee1e50f9a9a20575d22c45b Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 18:29:28 -0500 Subject: [PATCH 07/11] Update types --- packages/core-data/src/entity-types/theme.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/core-data/src/entity-types/theme.ts b/packages/core-data/src/entity-types/theme.ts index 761c6461d4aca..75826c9110b65 100644 --- a/packages/core-data/src/entity-types/theme.ts +++ b/packages/core-data/src/entity-types/theme.ts @@ -129,6 +129,10 @@ declare module './base-entity-records' { * Custom font sizes if defined by the theme. */ 'editor-font-sizes': boolean | FontSize[]; + /** + * Custom spacing sizes if defined by the theme. + */ + 'editor-spacing-sizes': boolean | SpacingSize[]; /** * Custom gradient presets if defined by the theme. */ @@ -212,6 +216,12 @@ declare module './base-entity-records' { slug: string; } + export interface SpacingSize { + name: string; + size: number; + slug: string; + } + export interface GradientPreset { name: string; gradient: string; From 3a0a2734737d9931d4eaa0045501e601c1fd7d08 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 18:42:36 -0500 Subject: [PATCH 08/11] Load block-editor in the right place --- lib/{ => compat/wordpress-6.6}/block-editor.php | 0 lib/load.php | 1 + 2 files changed, 1 insertion(+) rename lib/{ => compat/wordpress-6.6}/block-editor.php (100%) diff --git a/lib/block-editor.php b/lib/compat/wordpress-6.6/block-editor.php similarity index 100% rename from lib/block-editor.php rename to lib/compat/wordpress-6.6/block-editor.php diff --git a/lib/load.php b/lib/load.php index 23985f9c8a92e..d7a324f78435e 100644 --- a/lib/load.php +++ b/lib/load.php @@ -132,6 +132,7 @@ function gutenberg_is_experiment_enabled( $name ) { // WordPress 6.6 compat. require __DIR__ . '/compat/wordpress-6.6/admin-bar.php'; require __DIR__ . '/compat/wordpress-6.6/blocks.php'; +require __DIR__ . '/compat/wordpress-6.6/block-editor.php'; require __DIR__ . '/compat/wordpress-6.6/compat.php'; require __DIR__ . '/compat/wordpress-6.6/resolve-patterns.php'; require __DIR__ . '/compat/wordpress-6.6/block-bindings/pattern-overrides.php'; From 7d63e29c7aec8efeb6af8f99938a5c8f28311fa9 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 19:31:49 -0500 Subject: [PATCH 09/11] Copy spacingSizes from editor-spacing-sizes --- lib/class-wp-theme-json-gutenberg.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index ad4e2fe105b0c..86905005efdfe 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -3630,6 +3630,13 @@ public static function get_from_editor_settings( $settings ) { $theme_settings['settings']['spacing']['padding'] = $settings['enableCustomSpacing']; } + if ( isset( $settings['spacingSizes'] ) ) { + if ( ! isset( $theme_settings['settings']['spacing'] ) ) { + $theme_settings['settings']['spacing'] = array(); + } + $theme_settings['settings']['spacing']['spacingSizes'] = $settings['spacingSizes']; + } + return $theme_settings; } From 58e3108cb1a326a41ac1353455ef2ad9218c9b31 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Mon, 3 Jun 2024 22:49:04 -0500 Subject: [PATCH 10/11] Add editor-spacing-sizes to docs --- docs/how-to-guides/themes/global-settings-and-styles.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/how-to-guides/themes/global-settings-and-styles.md b/docs/how-to-guides/themes/global-settings-and-styles.md index a5c3e828a2d66..f4b24aaf6c265 100644 --- a/docs/how-to-guides/themes/global-settings-and-styles.md +++ b/docs/how-to-guides/themes/global-settings-and-styles.md @@ -321,6 +321,7 @@ To retain backward compatibility, the existing `add_theme_support` declarations | `editor-color-palette` | Provide the list of colors via `color.palette`. | | `editor-font-sizes` | Provide the list of font size via `typography.fontSizes`. | | `editor-gradient-presets` | Provide the list of gradients via `color.gradients`. | +| `editor-spacing-sizes` | Provide the list of font size via `typography.fontSizes`. | | `appearance-tools` | Set `appearanceTools` to `true`. | | `border` | Set `border: color, radius, style, width` to `true`. | | `link-color ` | Set `color.link` to `true`. | From 2dcd295fc7eb2022ba1a7dd000c150b34f901fbd Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Tue, 4 Jun 2024 10:17:04 -0500 Subject: [PATCH 11/11] Fix editor-spacing-sizes docs --- .../themes/global-settings-and-styles.md | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/how-to-guides/themes/global-settings-and-styles.md b/docs/how-to-guides/themes/global-settings-and-styles.md index f4b24aaf6c265..f71bd67bfaf2e 100644 --- a/docs/how-to-guides/themes/global-settings-and-styles.md +++ b/docs/how-to-guides/themes/global-settings-and-styles.md @@ -310,21 +310,21 @@ There's one special setting property, `appearanceTools`, which is a boolean and To retain backward compatibility, the existing `add_theme_support` declarations that configure the block editor are retrofit in the proper categories for the top-level section. For example, if a theme uses `add_theme_support('disable-custom-colors')`, it'll be the same as setting `settings.color.custom` to `false`. If the `theme.json` contains any settings, these will take precedence over the values declared via `add_theme_support`. This is the complete list of equivalences: -| add_theme_support | theme.json setting | -| --------------------------- | --------------------------------------------------------- | -| `custom-line-height` | Set `typography.lineHeight` to `true`. | -| `custom-spacing` | Set `spacing.padding` to `true`. | -| `custom-units` | Provide the list of units via `spacing.units`. | -| `disable-custom-colors` | Set `color.custom` to `false`. | -| `disable-custom-font-sizes` | Set `typography.customFontSize` to `false`. | -| `disable-custom-gradients` | Set `color.customGradient` to `false`. | -| `editor-color-palette` | Provide the list of colors via `color.palette`. | -| `editor-font-sizes` | Provide the list of font size via `typography.fontSizes`. | -| `editor-gradient-presets` | Provide the list of gradients via `color.gradients`. | -| `editor-spacing-sizes` | Provide the list of font size via `typography.fontSizes`. | -| `appearance-tools` | Set `appearanceTools` to `true`. | -| `border` | Set `border: color, radius, style, width` to `true`. | -| `link-color ` | Set `color.link` to `true`. | +| add_theme_support | theme.json setting | +| --------------------------- | ------------------------------------------------------------- | +| `custom-line-height` | Set `typography.lineHeight` to `true`. | +| `custom-spacing` | Set `spacing.padding` to `true`. | +| `custom-units` | Provide the list of units via `spacing.units`. | +| `disable-custom-colors` | Set `color.custom` to `false`. | +| `disable-custom-font-sizes` | Set `typography.customFontSize` to `false`. | +| `disable-custom-gradients` | Set `color.customGradient` to `false`. | +| `editor-color-palette` | Provide the list of colors via `color.palette`. | +| `editor-font-sizes` | Provide the list of font size via `typography.fontSizes`. | +| `editor-gradient-presets` | Provide the list of gradients via `color.gradients`. | +| `editor-spacing-sizes` | Provide the list of spacing sizes via `spacing.spacingSizes`. | +| `appearance-tools` | Set `appearanceTools` to `true`. | +| `border` | Set `border: color, radius, style, width` to `true`. | +| `link-color ` | Set `color.link` to `true`. | #### Presets