Block Editor: Add a type property to allow Core to identify the source of the editor styles.

Gutenberg plugin need to override the editor styles provided by core selectively,
this added property allows it to do so without committing to a public API.

Props nosolosw, jorgefilipecosta.
See #53175.

Built from https://develop.svn.wordpress.org/trunk@51090


git-svn-id: http://core.svn.wordpress.org/trunk@50699 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
youknowriad 2021-06-08 08:15:57 +00:00
parent 1516d05128
commit 446dd1768a
4 changed files with 28 additions and 14 deletions

View File

@ -132,6 +132,7 @@ $available_templates = ! empty( $available_templates ) ? array_merge(
$styles = array( $styles = array(
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' ) ) { if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
@ -141,6 +142,7 @@ if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
if ( ! is_wp_error( $response ) ) { if ( ! is_wp_error( $response ) ) {
$styles[] = array( $styles[] = array(
'css' => wp_remote_retrieve_body( $response ), 'css' => wp_remote_retrieve_body( $response ),
'__unstableType' => 'theme',
); );
} }
} else { } else {
@ -149,6 +151,7 @@ if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
$styles[] = array( $styles[] = array(
'css' => file_get_contents( $file ), 'css' => file_get_contents( $file ),
'baseURL' => get_theme_file_uri( $style ), 'baseURL' => get_theme_file_uri( $style ),
'__unstableType' => 'theme',
); );
} }
} }

View File

@ -283,10 +283,14 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex
$theme_json = WP_Theme_JSON_Resolver::get_merged_data( $editor_settings ); $theme_json = WP_Theme_JSON_Resolver::get_merged_data( $editor_settings );
if ( WP_Theme_JSON_Resolver::theme_has_support() ) { 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( 'block_styles' ),
'__unstableType' => 'globalStyles',
);
$editor_settings['styles'][] = array( $editor_settings['styles'][] = array(
'css' => $theme_json->get_stylesheet( 'css_variables' ), 'css' => $theme_json->get_stylesheet( 'css_variables' ),
'__experimentalNoWrapper' => true, '__experimentalNoWrapper' => true,
'__unstableType' => 'globalStyles',
); );
} }

View File

@ -50,21 +50,25 @@ function render_block_core_legacy_widget( $attributes ) {
} }
/** /**
* On application init this does two things: * Registers the 'core/legacy-widget' block.
*
* - Registers the 'core/legacy-widget' block.
* - Intercepts any request with legacy-widget-preview in the query param and,
* if set, renders a page containing a preview of the requested Legacy Widget
* block.
*/ */
function init_legacy_widget_block() { function register_block_core_legacy_widget() {
register_block_type_from_metadata( register_block_type_from_metadata(
__DIR__ . '/legacy-widget', __DIR__ . '/legacy-widget',
array( array(
'render_callback' => 'render_block_core_legacy_widget', 'render_callback' => 'render_block_core_legacy_widget',
) )
); );
}
add_action( 'init', 'register_block_core_legacy_widget' );
/**
* Intercepts any request with legacy-widget-preview in the query param and, if
* set, renders a page containing a preview of the requested Legacy Widget
* block.
*/
function handle_legacy_widget_preview_iframe() {
if ( empty( $_GET['legacy-widget-preview'] ) ) { if ( empty( $_GET['legacy-widget-preview'] ) ) {
return; return;
} }
@ -110,4 +114,7 @@ function init_legacy_widget_block() {
exit; exit;
} }
add_action( 'init', 'init_legacy_widget_block' ); // Ensure handle_legacy_widget_preview_iframe() is called after Core's
// register_block_core_legacy_widget() (priority = 10) and after Gutenberg's
// register_block_core_legacy_widget() (priority = 20).
add_action( 'init', 'handle_legacy_widget_preview_iframe', 21 );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.8-alpha-51089'; $wp_version = '5.8-alpha-51090';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.