From 446dd1768a1f390c3cdb32323a7b729c79020a20 Mon Sep 17 00:00:00 2001 From: youknowriad Date: Tue, 8 Jun 2021 08:15:57 +0000 Subject: [PATCH] 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 --- wp-admin/edit-form-blocks.php | 11 +++++++---- wp-includes/block-editor.php | 6 +++++- wp-includes/blocks/legacy-widget.php | 23 +++++++++++++++-------- wp-includes/version.php | 2 +- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php index 3aead40a7b..71328d0ad5 100644 --- a/wp-admin/edit-form-blocks.php +++ b/wp-admin/edit-form-blocks.php @@ -131,7 +131,8 @@ $available_templates = ! empty( $available_templates ) ? array_merge( // 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 @@ if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) { $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/wp-includes/block-editor.php b/wp-includes/block-editor.php index 3234c4ad1f..101cc1ba71 100644 --- a/wp-includes/block-editor.php +++ b/wp-includes/block-editor.php @@ -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 ); 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( 'css' => $theme_json->get_stylesheet( 'css_variables' ), '__experimentalNoWrapper' => true, + '__unstableType' => 'globalStyles', ); } diff --git a/wp-includes/blocks/legacy-widget.php b/wp-includes/blocks/legacy-widget.php index 6a49111b8e..f8b64ab5c1 100644 --- a/wp-includes/blocks/legacy-widget.php +++ b/wp-includes/blocks/legacy-widget.php @@ -50,21 +50,25 @@ function render_block_core_legacy_widget( $attributes ) { } /** - * On application init this does two things: - * - * - 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. + * Registers the 'core/legacy-widget' block. */ -function init_legacy_widget_block() { +function register_block_core_legacy_widget() { register_block_type_from_metadata( __DIR__ . '/legacy-widget', array( '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'] ) ) { return; } @@ -110,4 +114,7 @@ function init_legacy_widget_block() { 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 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 658d14c5c4..9b5170df1f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @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.