diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php index e757dc4fe8..3a399c2fcd 100644 --- a/wp-admin/edit-form-blocks.php +++ b/wp-admin/edit-form-blocks.php @@ -18,10 +18,9 @@ if ( ! defined( 'ABSPATH' ) ) { * @global WP_Post_Type $post_type_object * @global WP_Post $post Global post object. * @global string $title - * @global array $editor_styles * @global array $wp_meta_boxes */ -global $post_type, $post_type_object, $post, $title, $editor_styles, $wp_meta_boxes; +global $post_type, $post_type_object, $post, $title, $wp_meta_boxes; $block_editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) ); @@ -128,36 +127,6 @@ $available_templates = ! empty( $available_templates ) ? array_merge( $available_templates ) : $available_templates; -// 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', - ), -); -if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) { - foreach ( $editor_styles as $style ) { - if ( preg_match( '~^(https?:)?//~', $style ) ) { - $response = wp_remote_get( $style ); - if ( ! is_wp_error( $response ) ) { - $styles[] = array( - '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', - ); - } - } - } -} - // Lock settings. $user_id = wp_check_post_lock( $post->ID ); if ( $user_id ) { @@ -212,7 +181,7 @@ $editor_settings = array( 'titlePlaceholder' => apply_filters( 'enter_title_here', __( 'Add title' ), $post ), 'bodyPlaceholder' => $body_placeholder, 'autosaveInterval' => AUTOSAVE_INTERVAL, - 'styles' => $styles, + 'styles' => get_block_editor_theme_styles(), 'richEditingEnabled' => user_can_richedit(), 'postLock' => $lock_details, 'postLockUtils' => array( diff --git a/wp-admin/widgets-form-blocks.php b/wp-admin/widgets-form-blocks.php index a40b01fd64..6921ff7a15 100644 --- a/wp-admin/widgets-form-blocks.php +++ b/wp-admin/widgets-form-blocks.php @@ -25,7 +25,7 @@ $preload_paths = array( block_editor_rest_api_preload( $preload_paths, $block_editor_context ); $editor_settings = get_block_editor_settings( - get_legacy_widget_block_editor_settings(), + array_merge( get_legacy_widget_block_editor_settings(), array( 'styles' => get_block_editor_theme_styles() ) ), $block_editor_context ); diff --git a/wp-includes/block-editor.php b/wp-includes/block-editor.php index 90ba12d096..e0a40e7365 100644 --- a/wp-includes/block-editor.php +++ b/wp-includes/block-editor.php @@ -464,3 +464,48 @@ function block_editor_rest_api_preload( array $preload_paths, $block_editor_cont 'after' ); } + +/** + * Creates an array of theme styles to load into the block editor. + * + * @since 5.8.0 + * + * @global array $editor_styles + * + * @return array An array of theme styles for the block editor. Includes default font family + * style and theme stylesheets. + */ +function get_block_editor_theme_styles() { + global $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', + ), + ); + if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) { + foreach ( $editor_styles as $style ) { + if ( preg_match( '~^(https?:)?//~', $style ) ) { + $response = wp_remote_get( $style ); + if ( ! is_wp_error( $response ) ) { + $styles[] = array( + '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', + ); + } + } + } + } + + return $styles; +} diff --git a/wp-includes/blocks/legacy-widget.php b/wp-includes/blocks/legacy-widget.php index f8b64ab5c1..030aa88f56 100644 --- a/wp-includes/blocks/legacy-widget.php +++ b/wp-includes/blocks/legacy-widget.php @@ -24,13 +24,14 @@ function render_block_core_legacy_widget( $attributes ) { return ''; } - if ( method_exists( $wp_widget_factory, 'get_widget_object' ) ) { - $widget_object = $wp_widget_factory->get_widget_object( $attributes['idBase'] ); + $id_base = $attributes['idBase']; + if ( method_exists( $wp_widget_factory, 'get_widget_key' ) ) { + $widget_key = $wp_widget_factory->get_widget_key( $id_base ); } else { - $widget_object = gutenberg_get_widget_object( $attributes['idBase'] ); + $widget_key = gutenberg_get_widget_key( $id_base ); } - if ( ! $widget_object ) { + if ( ! $widget_key ) { return ''; } @@ -45,7 +46,7 @@ function render_block_core_legacy_widget( $attributes ) { } ob_start(); - the_widget( get_class( $widget_object ), $instance ); + the_widget( $widget_key, $instance ); return ob_get_clean(); } @@ -90,7 +91,6 @@ function handle_legacy_widget_preview_iframe() {