From 10b6223c2af59d3c1b49b0cde078fd5f232ce54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Tue, 1 Jun 2021 17:30:48 +0200 Subject: [PATCH 1/4] Allow third-parties to identify global styles --- src/wp-includes/block-editor.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 5a92e55d2b42d..f6039719bbf61 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -285,10 +285,14 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex $theme_json = WP_Theme_JSON_Resolver::get_merged_data( $editor_settings ); if ( WP_Theme_JSON_Resolver::theme_has_support() ) { - $editor_settings['styles'][] = array( 'css' => $theme_json->get_stylesheet( 'block_styles' ) ); $editor_settings['styles'][] = array( - 'css' => $theme_json->get_stylesheet( 'css_variables' ), - '__experimentalNoWrapper' => true, + 'css' => $theme_json->get_stylesheet( 'block_styles' ), + '__experimentalGlobalStyles' => true + ); + $editor_settings['styles'][] = array( + 'css' => $theme_json->get_stylesheet( 'css_variables' ), + '__experimentalNoWrapper' => true, + '__experimentalGlobalStyles' => true ); } From a37e152344261980b73c3ab6ea1516420eb31484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Tue, 1 Jun 2021 17:54:42 +0200 Subject: [PATCH 2/4] Fix lint issues --- src/wp-includes/block-editor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index f6039719bbf61..081d1da7c3827 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -287,12 +287,12 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex if ( WP_Theme_JSON_Resolver::theme_has_support() ) { $editor_settings['styles'][] = array( 'css' => $theme_json->get_stylesheet( 'block_styles' ), - '__experimentalGlobalStyles' => true + '__experimentalGlobalStyles' => true, ); $editor_settings['styles'][] = array( 'css' => $theme_json->get_stylesheet( 'css_variables' ), '__experimentalNoWrapper' => true, - '__experimentalGlobalStyles' => true + '__experimentalGlobalStyles' => true, ); } From 36158535e7931991d6772502be7d5b4a717550ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Wed, 2 Jun 2021 11:48:51 +0200 Subject: [PATCH 3/4] Make the flag general and tag all the styles we add in the settings --- src/wp-admin/edit-form-blocks.php | 11 +++++++---- src/wp-includes/block-editor.php | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/edit-form-blocks.php b/src/wp-admin/edit-form-blocks.php index 3aead40a7bb27..c86850c4317bf 100644 --- a/src/wp-admin/edit-form-blocks.php +++ b/src/wp-admin/edit-form-blocks.php @@ -131,7 +131,8 @@ function( $classes ) { // Editor Styles. $styles = array( array( - 'css' => 'body { font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif }', + 'css' => 'body { font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif }', + '__unstableType' => 'core' ), ); if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) { @@ -140,15 +141,17 @@ function( $classes ) { $response = wp_remote_get( $style ); if ( ! is_wp_error( $response ) ) { $styles[] = array( - 'css' => wp_remote_retrieve_body( $response ), + 'css' => wp_remote_retrieve_body( $response ), + '__unstableType' => 'theme' ); } } else { $file = get_theme_file_path( $style ); if ( is_file( $file ) ) { $styles[] = array( - 'css' => file_get_contents( $file ), - 'baseURL' => get_theme_file_uri( $style ), + 'css' => file_get_contents( $file ), + 'baseURL' => get_theme_file_uri( $style ), + '__unstableType' => 'theme' ); } } diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 081d1da7c3827..7954864b0d708 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -287,12 +287,12 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex if ( WP_Theme_JSON_Resolver::theme_has_support() ) { $editor_settings['styles'][] = array( 'css' => $theme_json->get_stylesheet( 'block_styles' ), - '__experimentalGlobalStyles' => true, + '__unstableType' => 'globalStyles', ); $editor_settings['styles'][] = array( 'css' => $theme_json->get_stylesheet( 'css_variables' ), '__experimentalNoWrapper' => true, - '__experimentalGlobalStyles' => true, + '__unstableType' => 'globalStyles', ); } From a943c0370f99f40dfabf12b233d40d9bc87f31de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Wed, 2 Jun 2021 11:57:35 +0200 Subject: [PATCH 4/4] Fix lint issues --- src/wp-admin/edit-form-blocks.php | 14 +++++++------- src/wp-includes/block-editor.php | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/wp-admin/edit-form-blocks.php b/src/wp-admin/edit-form-blocks.php index c86850c4317bf..71328d0ad5dd4 100644 --- a/src/wp-admin/edit-form-blocks.php +++ b/src/wp-admin/edit-form-blocks.php @@ -131,8 +131,8 @@ function( $classes ) { // Editor Styles. $styles = array( array( - 'css' => 'body { font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif }', - '__unstableType' => 'core' + 'css' => 'body { font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif }', + '__unstableType' => 'core', ), ); if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) { @@ -141,17 +141,17 @@ function( $classes ) { $response = wp_remote_get( $style ); if ( ! is_wp_error( $response ) ) { $styles[] = array( - 'css' => wp_remote_retrieve_body( $response ), - '__unstableType' => 'theme' + 'css' => wp_remote_retrieve_body( $response ), + '__unstableType' => 'theme', ); } } else { $file = get_theme_file_path( $style ); if ( is_file( $file ) ) { $styles[] = array( - 'css' => file_get_contents( $file ), - 'baseURL' => get_theme_file_uri( $style ), - '__unstableType' => 'theme' + 'css' => file_get_contents( $file ), + 'baseURL' => get_theme_file_uri( $style ), + '__unstableType' => 'theme', ); } } diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 7954864b0d708..f14144e6ca27c 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -286,13 +286,13 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex if ( WP_Theme_JSON_Resolver::theme_has_support() ) { $editor_settings['styles'][] = array( - 'css' => $theme_json->get_stylesheet( 'block_styles' ), + 'css' => $theme_json->get_stylesheet( 'block_styles' ), '__unstableType' => 'globalStyles', ); $editor_settings['styles'][] = array( - 'css' => $theme_json->get_stylesheet( 'css_variables' ), - '__experimentalNoWrapper' => true, - '__unstableType' => 'globalStyles', + 'css' => $theme_json->get_stylesheet( 'css_variables' ), + '__experimentalNoWrapper' => true, + '__unstableType' => 'globalStyles', ); }