From cc7d781f8895fa09673f4a2b69c4408efeb33114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Wed, 23 Feb 2022 16:32:14 +0100 Subject: [PATCH 01/12] Extract function to file in compat folder --- .../wordpress-5.9/block-editor-settings.php | 145 ++++++++++++++++ lib/global-styles.php | 160 ------------------ 2 files changed, 145 insertions(+), 160 deletions(-) create mode 100644 lib/compat/wordpress-5.9/block-editor-settings.php diff --git a/lib/compat/wordpress-5.9/block-editor-settings.php b/lib/compat/wordpress-5.9/block-editor-settings.php new file mode 100644 index 00000000000000..576bc2e37260b2 --- /dev/null +++ b/lib/compat/wordpress-5.9/block-editor-settings.php @@ -0,0 +1,145 @@ +id ) + ) { + $context = 'site-editor'; + } + + if ( + defined( 'REST_REQUEST' ) && + REST_REQUEST && + isset( $_GET['context'] ) && + 'mobile' === $_GET['context'] + ) { + $context = 'mobile'; + } + + if ( 'mobile' === $context && WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) { + $settings['__experimentalStyles'] = gutenberg_get_global_styles(); + } + + if ( 'other' === $context ) { + // Make sure the styles array exists. + // In some contexts, like the navigation editor, it doesn't. + if ( ! isset( $settings['styles'] ) ) { + $settings['styles'] = array(); + } + + // Reset existing global styles. + $styles_without_existing_global_styles = array(); + foreach ( $settings['styles'] as $style ) { + if ( ! isset( $style['__unstableType'] ) || 'globalStyles' !== $style['__unstableType'] ) { + $styles_without_existing_global_styles[] = $style; + } + } + + $new_global_styles = array(); + + $css_variables = gutenberg_get_global_stylesheet( array( 'variables' ) ); + if ( '' !== $css_variables ) { + $new_global_styles[] = array( + 'css' => $css_variables, + '__unstableType' => 'presets', + ); + } + + $css_presets = gutenberg_get_global_stylesheet( array( 'presets' ) ); + if ( '' !== $css_presets ) { + $new_global_styles[] = array( + 'css' => $css_presets, + '__unstableType' => 'presets', + ); + } + + if ( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) { + $css_blocks = gutenberg_get_global_stylesheet( array( 'styles' ) ); + if ( '' !== $css_blocks ) { + $new_global_styles[] = array( + 'css' => $css_blocks, + '__unstableType' => 'theme', + ); + } + } + + $settings['styles'] = array_merge( $new_global_styles, $styles_without_existing_global_styles ); + } + + // Copied from get_block_editor_settings() at wordpress-develop/block-editor.php. + $settings['__experimentalFeatures'] = gutenberg_get_global_settings(); + + if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) { + $colors_by_origin = $settings['__experimentalFeatures']['color']['palette']; + $settings['colors'] = isset( $colors_by_origin['custom'] ) ? + $colors_by_origin['custom'] : ( + isset( $colors_by_origin['theme'] ) ? + $colors_by_origin['theme'] : + $colors_by_origin['default'] + ); + } + + if ( isset( $settings['__experimentalFeatures']['color']['gradients'] ) ) { + $gradients_by_origin = $settings['__experimentalFeatures']['color']['gradients']; + $settings['gradients'] = isset( $gradients_by_origin['custom'] ) ? + $gradients_by_origin['custom'] : ( + isset( $gradients_by_origin['theme'] ) ? + $gradients_by_origin['theme'] : + $gradients_by_origin['default'] + ); + } + + if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) { + $font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes']; + $settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ? + $font_sizes_by_origin['user'] : ( + isset( $font_sizes_by_origin['theme'] ) ? + $font_sizes_by_origin['theme'] : + $font_sizes_by_origin['default'] + ); + } + + if ( isset( $settings['__experimentalFeatures']['color']['custom'] ) ) { + $settings['disableCustomColors'] = ! $settings['__experimentalFeatures']['color']['custom']; + unset( $settings['__experimentalFeatures']['color']['custom'] ); + } + if ( isset( $settings['__experimentalFeatures']['color']['customGradient'] ) ) { + $settings['disableCustomGradients'] = ! $settings['__experimentalFeatures']['color']['customGradient']; + unset( $settings['__experimentalFeatures']['color']['customGradient'] ); + } + if ( isset( $settings['__experimentalFeatures']['typography']['customFontSize'] ) ) { + $settings['disableCustomFontSizes'] = ! $settings['__experimentalFeatures']['typography']['customFontSize']; + unset( $settings['__experimentalFeatures']['typography']['customFontSize'] ); + } + if ( isset( $settings['__experimentalFeatures']['typography']['lineHeight'] ) ) { + $settings['enableCustomLineHeight'] = $settings['__experimentalFeatures']['typography']['lineHeight']; + unset( $settings['__experimentalFeatures']['typography']['lineHeight'] ); + } + if ( isset( $settings['__experimentalFeatures']['spacing']['units'] ) ) { + $settings['enableCustomUnits'] = $settings['__experimentalFeatures']['spacing']['units']; + } + if ( isset( $settings['__experimentalFeatures']['spacing']['padding'] ) ) { + $settings['enableCustomSpacing'] = $settings['__experimentalFeatures']['spacing']['padding']; + unset( $settings['__experimentalFeatures']['spacing']['padding'] ); + } + + return $settings; +} + +add_filter( 'block_editor_settings_all', 'gutenberg_experimental_global_styles_settings', PHP_INT_MAX ); \ No newline at end of file diff --git a/lib/global-styles.php b/lib/global-styles.php index e1d7364ccf60b8..15b679d7684572 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -5,164 +5,6 @@ * @package gutenberg */ -/** - * Adds the necessary settings for the Global Styles client UI. - * - * @param array $settings Existing block editor settings. - * - * @return array New block editor settings. - */ -function gutenberg_experimental_global_styles_settings( $settings ) { - // Set what is the context for this data request. - $context = 'other'; - if ( - is_callable( 'get_current_screen' ) && - function_exists( 'gutenberg_is_edit_site_page' ) && - gutenberg_is_edit_site_page( get_current_screen()->id ) - ) { - $context = 'site-editor'; - } - - if ( - defined( 'REST_REQUEST' ) && - REST_REQUEST && - isset( $_GET['context'] ) && - 'mobile' === $_GET['context'] - ) { - $context = 'mobile'; - } - - if ( 'mobile' === $context && WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) { - $settings['__experimentalStyles'] = gutenberg_get_global_styles(); - } - - if ( 'other' === $context ) { - // Make sure the styles array exists. - // In some contexts, like the navigation editor, it doesn't. - if ( ! isset( $settings['styles'] ) ) { - $settings['styles'] = array(); - } - - // Reset existing global styles. - $styles_without_existing_global_styles = array(); - foreach ( $settings['styles'] as $style ) { - if ( - ! isset( $style['__unstableType'] ) || - // '__unstableType' is 'globalStyles' for WordPress 5.8 and 'presets' for WordPress 5.9. - // - // Note that styles classified as'theme', can be from the theme stylesheet - // or from the theme.json (the styles section). - // We are unable to identify which is which, so we can't remove and recreate those. - // Instead, we reload the theme.json styles from the plugin. - // Because they'll use the same selectors and load later, - // they'll have higher priority than core's. - // - // Theoretically, this approach with 'theme' styles could be problematic: - // if we remove style properties in the plugin, if selectors change, etc. - // We need to address this issue directly in core by alowing to identify - // styles coming from theme.json. - // - // A final note about 'theme' styles: this flag is used to identify theme - // styles that may need to be removed if the user toggles - // "Preferences > Use theme styles" in the preferences modal. - // - ! in_array( $style['__unstableType'], array( 'globalStyles', 'presets' ), true ) - ) { - $styles_without_existing_global_styles[] = $style; - } - } - - $new_global_styles = array(); - - $css_variables = gutenberg_get_global_stylesheet( array( 'variables' ) ); - if ( '' !== $css_variables ) { - $new_global_styles[] = array( - 'css' => $css_variables, - '__unstableType' => 'presets', - ); - } - - $css_presets = gutenberg_get_global_stylesheet( array( 'presets' ) ); - if ( '' !== $css_presets ) { - $new_global_styles[] = array( - 'css' => $css_presets, - '__unstableType' => 'presets', - ); - } - - if ( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) { - $css_blocks = gutenberg_get_global_stylesheet( array( 'styles' ) ); - if ( '' !== $css_blocks ) { - $new_global_styles[] = array( - 'css' => $css_blocks, - '__unstableType' => 'theme', - ); - } - } - - $settings['styles'] = array_merge( $new_global_styles, $styles_without_existing_global_styles ); - } - - // Copied from get_block_editor_settings() at wordpress-develop/block-editor.php. - $settings['__experimentalFeatures'] = gutenberg_get_global_settings(); - - if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) { - $colors_by_origin = $settings['__experimentalFeatures']['color']['palette']; - $settings['colors'] = isset( $colors_by_origin['custom'] ) ? - $colors_by_origin['custom'] : ( - isset( $colors_by_origin['theme'] ) ? - $colors_by_origin['theme'] : - $colors_by_origin['default'] - ); - } - - if ( isset( $settings['__experimentalFeatures']['color']['gradients'] ) ) { - $gradients_by_origin = $settings['__experimentalFeatures']['color']['gradients']; - $settings['gradients'] = isset( $gradients_by_origin['custom'] ) ? - $gradients_by_origin['custom'] : ( - isset( $gradients_by_origin['theme'] ) ? - $gradients_by_origin['theme'] : - $gradients_by_origin['default'] - ); - } - - if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) { - $font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes']; - $settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ? - $font_sizes_by_origin['user'] : ( - isset( $font_sizes_by_origin['theme'] ) ? - $font_sizes_by_origin['theme'] : - $font_sizes_by_origin['default'] - ); - } - - if ( isset( $settings['__experimentalFeatures']['color']['custom'] ) ) { - $settings['disableCustomColors'] = ! $settings['__experimentalFeatures']['color']['custom']; - unset( $settings['__experimentalFeatures']['color']['custom'] ); - } - if ( isset( $settings['__experimentalFeatures']['color']['customGradient'] ) ) { - $settings['disableCustomGradients'] = ! $settings['__experimentalFeatures']['color']['customGradient']; - unset( $settings['__experimentalFeatures']['color']['customGradient'] ); - } - if ( isset( $settings['__experimentalFeatures']['typography']['customFontSize'] ) ) { - $settings['disableCustomFontSizes'] = ! $settings['__experimentalFeatures']['typography']['customFontSize']; - unset( $settings['__experimentalFeatures']['typography']['customFontSize'] ); - } - if ( isset( $settings['__experimentalFeatures']['typography']['lineHeight'] ) ) { - $settings['enableCustomLineHeight'] = $settings['__experimentalFeatures']['typography']['lineHeight']; - unset( $settings['__experimentalFeatures']['typography']['lineHeight'] ); - } - if ( isset( $settings['__experimentalFeatures']['spacing']['units'] ) ) { - $settings['enableCustomUnits'] = $settings['__experimentalFeatures']['spacing']['units']; - } - if ( isset( $settings['__experimentalFeatures']['spacing']['padding'] ) ) { - $settings['enableCustomSpacing'] = $settings['__experimentalFeatures']['spacing']['padding']; - unset( $settings['__experimentalFeatures']['spacing']['padding'] ); - } - - return $settings; -} - /** * Sanitizes global styles user content removing unsafe rules. * @@ -232,8 +74,6 @@ function gutenberg_global_styles_force_filtered_html_on_import_filter( $arg ) { return $arg; } -add_filter( 'block_editor_settings_all', 'gutenberg_experimental_global_styles_settings', PHP_INT_MAX ); - // kses actions&filters. add_action( 'init', 'gutenberg_global_styles_kses_init' ); add_action( 'set_current_user', 'gutenberg_global_styles_kses_init' ); From 0247f3d98864bdd5773a12dd1f1b48b99d70fb78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Wed, 23 Feb 2022 16:38:29 +0100 Subject: [PATCH 02/12] Backport changes from core --- lib/compat/wordpress-5.9/block-editor-settings.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-5.9/block-editor-settings.php b/lib/compat/wordpress-5.9/block-editor-settings.php index 576bc2e37260b2..e7666d612d0620 100644 --- a/lib/compat/wordpress-5.9/block-editor-settings.php +++ b/lib/compat/wordpress-5.9/block-editor-settings.php @@ -108,7 +108,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) && if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) { $font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes']; $settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ? - $font_sizes_by_origin['user'] : ( + $font_sizes_by_origin['custom'] : ( isset( $font_sizes_by_origin['theme'] ) ? $font_sizes_by_origin['theme'] : $font_sizes_by_origin['default'] @@ -133,6 +133,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) && } if ( isset( $settings['__experimentalFeatures']['spacing']['units'] ) ) { $settings['enableCustomUnits'] = $settings['__experimentalFeatures']['spacing']['units']; + unset( $settings['__experimentalFeatures']['spacing']['units'] ); } if ( isset( $settings['__experimentalFeatures']['spacing']['padding'] ) ) { $settings['enableCustomSpacing'] = $settings['__experimentalFeatures']['spacing']['padding']; From a33b712569e99b40cca4611631c80fb336ec14e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Wed, 23 Feb 2022 16:48:42 +0100 Subject: [PATCH 03/12] Rename to gutenberg_get_block_editor_settings --- lib/compat/wordpress-5.9/block-editor-settings.php | 6 +++--- lib/load.php | 1 + lib/navigation-page.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/compat/wordpress-5.9/block-editor-settings.php b/lib/compat/wordpress-5.9/block-editor-settings.php index e7666d612d0620..5c2cf391a3e503 100644 --- a/lib/compat/wordpress-5.9/block-editor-settings.php +++ b/lib/compat/wordpress-5.9/block-editor-settings.php @@ -6,13 +6,13 @@ */ /** - * Adds the necessary settings for the Global Styles client UI. + * Adds styles and __experimentalFeatures to the block editor settings. * * @param array $settings Existing block editor settings. * * @return array New block editor settings. */ -function gutenberg_experimental_global_styles_settings( $settings ) { +function gutenberg_get_block_editor_settings( $settings ) { // Set what is the context for this data request. $context = 'other'; if ( @@ -143,4 +143,4 @@ function_exists( 'gutenberg_is_edit_site_page' ) && return $settings; } -add_filter( 'block_editor_settings_all', 'gutenberg_experimental_global_styles_settings', PHP_INT_MAX ); \ No newline at end of file +add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', PHP_INT_MAX ); \ No newline at end of file diff --git a/lib/load.php b/lib/load.php index 443942c98ee80a..65727d4974047c 100644 --- a/lib/load.php +++ b/lib/load.php @@ -70,6 +70,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-5.9/default-editor-styles.php'; require __DIR__ . '/compat/wordpress-5.9/register-global-styles-cpt.php'; require __DIR__ . '/compat/wordpress-5.9/script-loader.php'; +require __DIR__ . '/compat/wordpress-5.9/block-editor-settings.php'; require __DIR__ . '/compat/wordpress-6.0/get-global-styles-and-settings.php'; require __DIR__ . '/compat/wordpress-5.9/render-svg-filters.php'; require __DIR__ . '/compat/wordpress-5.9/json-file-decode.php'; diff --git a/lib/navigation-page.php b/lib/navigation-page.php index 211ab82a9c782a..01f8078b9a5d5a 100644 --- a/lib/navigation-page.php +++ b/lib/navigation-page.php @@ -107,7 +107,7 @@ function gutenberg_navigation_init( $hook ) { /*'blockNavMenus' => get_theme_support( 'block-nav-menus' ),*/ ) ); - $settings = gutenberg_experimental_global_styles_settings( $settings ); + $settings = gutenberg_get_block_editor_settings( $settings ); gutenberg_initialize_editor( 'navigation_editor', From a6dece923c0b4e2942d8e4e4af795d98848c8ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Wed, 23 Feb 2022 17:10:18 +0100 Subject: [PATCH 04/12] Backport changes from core --- .../wordpress-5.9/block-editor-settings.php | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/compat/wordpress-5.9/block-editor-settings.php b/lib/compat/wordpress-5.9/block-editor-settings.php index 5c2cf391a3e503..3aea4381255e93 100644 --- a/lib/compat/wordpress-5.9/block-editor-settings.php +++ b/lib/compat/wordpress-5.9/block-editor-settings.php @@ -43,7 +43,6 @@ function_exists( 'gutenberg_is_edit_site_page' ) && $settings['styles'] = array(); } - // Reset existing global styles. $styles_without_existing_global_styles = array(); foreach ( $settings['styles'] as $style ) { if ( ! isset( $style['__unstableType'] ) || 'globalStyles' !== $style['__unstableType'] ) { @@ -52,30 +51,33 @@ function_exists( 'gutenberg_is_edit_site_page' ) && } $new_global_styles = array(); - - $css_variables = gutenberg_get_global_stylesheet( array( 'variables' ) ); - if ( '' !== $css_variables ) { - $new_global_styles[] = array( - 'css' => $css_variables, + $presets = array( + array( + 'css' => 'variables', '__unstableType' => 'presets', - ); - } - - $css_presets = gutenberg_get_global_stylesheet( array( 'presets' ) ); - if ( '' !== $css_presets ) { - $new_global_styles[] = array( - 'css' => $css_presets, + ), + array( + 'css' => 'presets', '__unstableType' => 'presets', - ); + ), + ); + foreach ( $presets as $preset_style ) { + $actual_css = gutenberg_get_global_stylesheet( array( $preset_style['css'] ) ); + if ( '' !== $actual_css ) { + $preset_style['css'] = $actual_css; + $new_global_styles[] = $preset_style; + } } - if ( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) { - $css_blocks = gutenberg_get_global_stylesheet( array( 'styles' ) ); - if ( '' !== $css_blocks ) { - $new_global_styles[] = array( - 'css' => $css_blocks, - '__unstableType' => 'theme', - ); + if ( WP_Theme_JSON_Resolver::theme_has_support() ) { + $block_classes = array( + 'css' => 'styles', + '__unstableType' => 'theme', + ); + $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) ); + if ( '' !== $actual_css ) { + $block_classes['css'] = $actual_css; + $new_global_styles[] = $block_classes; } } From 4252f57df2b0d0c027e735a74731f54dab0cd824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Wed, 23 Feb 2022 17:11:04 +0100 Subject: [PATCH 05/12] Cover for unstable types in 5.8 and 5.9 --- lib/compat/wordpress-5.9/block-editor-settings.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-5.9/block-editor-settings.php b/lib/compat/wordpress-5.9/block-editor-settings.php index 3aea4381255e93..a00898c8d68f30 100644 --- a/lib/compat/wordpress-5.9/block-editor-settings.php +++ b/lib/compat/wordpress-5.9/block-editor-settings.php @@ -45,7 +45,11 @@ function_exists( 'gutenberg_is_edit_site_page' ) && $styles_without_existing_global_styles = array(); foreach ( $settings['styles'] as $style ) { - if ( ! isset( $style['__unstableType'] ) || 'globalStyles' !== $style['__unstableType'] ) { + if ( + ! isset( $style['__unstableType'] ) || + // 'globalStyles' is for WordPress 5.8. 'theme' and 'presets' is for WordPress 5.9. + ! in_array( $style['__unstableType'], array( 'globalStyles', 'theme', 'presets' ), true ) + ) { $styles_without_existing_global_styles[] = $style; } } From 552948c4f9d4dd22d9dc285f7b334d2ea7740492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Wed, 23 Feb 2022 17:37:43 +0100 Subject: [PATCH 06/12] Fix lint issue --- lib/compat/wordpress-5.9/block-editor-settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-5.9/block-editor-settings.php b/lib/compat/wordpress-5.9/block-editor-settings.php index a00898c8d68f30..7b4f0932e4c5c1 100644 --- a/lib/compat/wordpress-5.9/block-editor-settings.php +++ b/lib/compat/wordpress-5.9/block-editor-settings.php @@ -149,4 +149,4 @@ function_exists( 'gutenberg_is_edit_site_page' ) && return $settings; } -add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', PHP_INT_MAX ); \ No newline at end of file +add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', PHP_INT_MAX ); From 46f43e7eba93e01cddd70381b594fa9fae562873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 24 Feb 2022 12:06:11 +0100 Subject: [PATCH 07/12] Extract mobile settings to the experimental folder --- .../block-editor-settings-mobile.php | 28 +++++++++++++++++++ .../wordpress-5.9/block-editor-settings.php | 13 --------- lib/load.php | 1 + 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 lib/compat/experimental/block-editor-settings-mobile.php diff --git a/lib/compat/experimental/block-editor-settings-mobile.php b/lib/compat/experimental/block-editor-settings-mobile.php new file mode 100644 index 00000000000000..979b7de6036e06 --- /dev/null +++ b/lib/compat/experimental/block-editor-settings-mobile.php @@ -0,0 +1,28 @@ + Date: Thu, 24 Feb 2022 14:02:29 +0100 Subject: [PATCH 08/12] Port changes from https://github.com/WordPress/gutenberg/pull/36327 --- .../wordpress-5.9/block-editor-settings.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-5.9/block-editor-settings.php b/lib/compat/wordpress-5.9/block-editor-settings.php index 762914eb41a68e..5029aed595fae5 100644 --- a/lib/compat/wordpress-5.9/block-editor-settings.php +++ b/lib/compat/wordpress-5.9/block-editor-settings.php @@ -34,8 +34,25 @@ function_exists( 'gutenberg_is_edit_site_page' ) && foreach ( $settings['styles'] as $style ) { if ( ! isset( $style['__unstableType'] ) || - // 'globalStyles' is for WordPress 5.8. 'theme' and 'presets' is for WordPress 5.9. - ! in_array( $style['__unstableType'], array( 'globalStyles', 'theme', 'presets' ), true ) + // '__unstableType' is 'globalStyles' for WordPress 5.8 and 'presets' for WordPress 5.9. + // + // Note that styles classified as'theme', can be from the theme stylesheet + // or from the theme.json (the styles section). + // We are unable to identify which is which, so we can't remove and recreate those. + // Instead, we reload the theme.json styles from the plugin. + // Because they'll use the same selectors and load later, + // they'll have higher priority than core's. + // + // Theoretically, this approach with 'theme' styles could be problematic: + // if we remove style properties in the plugin, if selectors change, etc. + // We need to address this issue directly in core by alowing to identify + // styles coming from theme.json. + // + // A final note about 'theme' styles: this flag is used to identify theme + // styles that may need to be removed if the user toggles + // "Preferences > Use theme styles" in the preferences modal. + // + ! in_array( $style['__unstableType'], array( 'globalStyles', 'presets' ), true ) ) { $styles_without_existing_global_styles[] = $style; } From 64ffed54090325b9181cc9a3afc69a522a132afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 24 Feb 2022 14:07:48 +0100 Subject: [PATCH 09/12] Do not output styles in mobile --- lib/compat/wordpress-5.9/block-editor-settings.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/compat/wordpress-5.9/block-editor-settings.php b/lib/compat/wordpress-5.9/block-editor-settings.php index 5029aed595fae5..2232bae7506b40 100644 --- a/lib/compat/wordpress-5.9/block-editor-settings.php +++ b/lib/compat/wordpress-5.9/block-editor-settings.php @@ -23,6 +23,15 @@ function_exists( 'gutenberg_is_edit_site_page' ) && $context = 'site-editor'; } + if ( + defined( 'REST_REQUEST' ) && + REST_REQUEST && + isset( $_GET['context'] ) && + 'mobile' === $_GET['context'] + ) { + $context = 'mobile'; + } + if ( 'other' === $context ) { // Make sure the styles array exists. // In some contexts, like the navigation editor, it doesn't. From 4f03b0b0667cc7c7e2fa4ed9fbfc96c8ddc1be7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 24 Feb 2022 17:43:01 +0100 Subject: [PATCH 10/12] Move to 6.0 compat folder. We need the editor settings to use the plugin code until the minimim WordPress version is 6.0. --- .../{wordpress-5.9 => wordpress-6.0}/block-editor-settings.php | 0 lib/load.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/compat/{wordpress-5.9 => wordpress-6.0}/block-editor-settings.php (100%) diff --git a/lib/compat/wordpress-5.9/block-editor-settings.php b/lib/compat/wordpress-6.0/block-editor-settings.php similarity index 100% rename from lib/compat/wordpress-5.9/block-editor-settings.php rename to lib/compat/wordpress-6.0/block-editor-settings.php diff --git a/lib/load.php b/lib/load.php index 85a7a725c486ef..4ab6ccbf8a46c2 100644 --- a/lib/load.php +++ b/lib/load.php @@ -70,7 +70,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-5.9/default-editor-styles.php'; require __DIR__ . '/compat/wordpress-5.9/register-global-styles-cpt.php'; require __DIR__ . '/compat/wordpress-5.9/script-loader.php'; -require __DIR__ . '/compat/wordpress-5.9/block-editor-settings.php'; +require __DIR__ . '/compat/wordpress-6.0/block-editor-settings.php'; require __DIR__ . '/compat/experimental/block-editor-settings-mobile.php'; require __DIR__ . '/compat/wordpress-6.0/get-global-styles-and-settings.php'; require __DIR__ . '/compat/wordpress-5.9/render-svg-filters.php'; From d078f86fc8a609fe5da4c90faa41e8655e255210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 24 Feb 2022 17:57:02 +0100 Subject: [PATCH 11/12] Add comment --- lib/compat/experimental/block-editor-settings-mobile.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/compat/experimental/block-editor-settings-mobile.php b/lib/compat/experimental/block-editor-settings-mobile.php index 979b7de6036e06..1ae563a9bd82ed 100644 --- a/lib/compat/experimental/block-editor-settings-mobile.php +++ b/lib/compat/experimental/block-editor-settings-mobile.php @@ -7,6 +7,9 @@ /** * Adds settings to the mobile block editor. + * + * This is used by the settings REST endpoint and it should land in core + * as soon as lib/class-wp-rest-block-editor-settings-controller.php does. * * @param array $settings Existing block editor settings. * From 0329e09828d39ad246ba0f2da10b4ddce4abdec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 24 Feb 2022 18:04:50 +0100 Subject: [PATCH 12/12] Fix lint issues --- lib/compat/experimental/block-editor-settings-mobile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/experimental/block-editor-settings-mobile.php b/lib/compat/experimental/block-editor-settings-mobile.php index 1ae563a9bd82ed..700167dfb5ea8e 100644 --- a/lib/compat/experimental/block-editor-settings-mobile.php +++ b/lib/compat/experimental/block-editor-settings-mobile.php @@ -7,7 +7,7 @@ /** * Adds settings to the mobile block editor. - * + * * This is used by the settings REST endpoint and it should land in core * as soon as lib/class-wp-rest-block-editor-settings-controller.php does. *