From 1882e40a8a64bdd93e9a06e1e1c5368bea1749b6 Mon Sep 17 00:00:00 2001 From: gziolo Date: Tue, 12 Apr 2022 16:02:19 +0000 Subject: [PATCH] Editor: Use block settings to pass assets for the iframed editor Backports changes applied in Gutenberg in https://github.com/WordPress/gutenberg/pull/37193. Props zieladam. See #55505. Follow-up for [53157]. Built from https://develop.svn.wordpress.org/trunk@53160 git-svn-id: http://core.svn.wordpress.org/trunk@52749 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-editor.php | 75 +++++++++++++++++++++++++++++++- wp-includes/default-filters.php | 5 --- wp-includes/deprecated.php | 10 +++++ wp-includes/script-loader.php | 76 --------------------------------- wp-includes/version.php | 2 +- 5 files changed, 84 insertions(+), 84 deletions(-) diff --git a/wp-includes/block-editor.php b/wp-includes/block-editor.php index 9fe559fc41..c9945eace9 100644 --- a/wp-includes/block-editor.php +++ b/wp-includes/block-editor.php @@ -287,6 +287,77 @@ function get_legacy_widget_block_editor_settings() { return $editor_settings; } +/** + * Collect the block editor assets that need to be loaded into the editor's iframe. + * + * @since 6.0.0 + * @access private + * + * @global string $pagenow The filename of the current screen. + * + * @return array The block editor assets: styles and scripts. + */ +function _wp_get_iframed_editor_assets() { + global $pagenow; + + $script_handles = array(); + $style_handles = array( + 'wp-block-editor', + 'wp-block-library', + 'wp-block-library-theme', + 'wp-edit-blocks', + ); + + if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) { + $style_handles[] = 'wp-widgets'; + $style_handles[] = 'wp-edit-widgets'; + } + + $block_registry = WP_Block_Type_Registry::get_instance(); + + foreach ( $block_registry->get_all_registered() as $block_type ) { + if ( ! empty( $block_type->style ) ) { + $style_handles[] = $block_type->style; + } + + if ( ! empty( $block_type->editor_style ) ) { + $style_handles[] = $block_type->editor_style; + } + + if ( ! empty( $block_type->script ) ) { + $script_handles[] = $block_type->script; + } + } + + $style_handles = array_unique( $style_handles ); + $done = wp_styles()->done; + + ob_start(); + + // We do not need reset styles for the iframed editor. + wp_styles()->done = array( 'wp-reset-editor-styles' ); + wp_styles()->do_items( $style_handles ); + wp_styles()->done = $done; + + $styles = ob_get_clean(); + + $script_handles = array_unique( $script_handles ); + $done = wp_scripts()->done; + + ob_start(); + + wp_scripts()->done = array(); + wp_scripts()->do_items( $script_handles ); + wp_scripts()->done = $done; + + $scripts = ob_get_clean(); + + return array( + 'styles' => $styles, + 'scripts' => $scripts, + ); +} + /** * Returns the contextualized block editor settings for a selected editor context. * @@ -394,8 +465,8 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex unset( $editor_settings['__experimentalFeatures']['spacing']['padding'] ); } - $editor_settings['localAutosaveInterval'] = 15; - + $editor_settings['__unstableResolvedAssets'] = _wp_get_iframed_editor_assets(); + $editor_settings['localAutosaveInterval'] = 15; $editor_settings['__experimentalDiscussionSettings'] = array( 'commentOrder' => get_option( 'comment_order' ), 'commentsPerPage' => get_option( 'comments_per_page' ), diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 267d16c3b1..f373aecbba 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -591,11 +591,6 @@ add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); add_action( 'wp_head', 'wp_maybe_inline_styles', 1 ); // Run for styles enqueued in . add_action( 'wp_footer', 'wp_maybe_inline_styles', 1 ); // Run for late-loaded styles in the footer. -add_action( 'admin_footer-post.php', 'wp_add_iframed_editor_assets_html' ); -add_action( 'admin_footer-post-new.php', 'wp_add_iframed_editor_assets_html' ); -add_action( 'admin_footer-widgets.php', 'wp_add_iframed_editor_assets_html' ); -add_action( 'admin_footer-site-editor.php', 'wp_add_iframed_editor_assets_html' ); - add_action( 'use_block_editor_for_post_type', '_disable_block_editor_for_navigation_post_type', 10, 2 ); add_action( 'edit_form_after_title', '_disable_content_editor_for_navigation_post_type' ); add_action( 'edit_form_after_editor', '_enable_content_editor_for_navigation_post_type' ); diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 758ab7e9f3..49a936a49e 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -4301,3 +4301,13 @@ function wp_skip_spacing_serialization( $block_type ) { array_key_exists( '__experimentalSkipSerialization', $spacing_support ) && $spacing_support['__experimentalSkipSerialization']; } + +/** + * Inject the block editor assets that need to be loaded into the editor's iframe as an inline script. + * + * @since 5.8.0 + * @deprecated 6.0.0 + */ +function wp_add_iframed_editor_assets_html() { + _deprecated_function( __FUNCTION__, '6.0.0' ); +} diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index ad3ecee5d9..1b5329d110 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -2883,82 +2883,6 @@ function _wp_normalize_relative_css_links( $css, $stylesheet_url ) { return $css; } -/** - * Inject the block editor assets that need to be loaded into the editor's iframe as an inline script. - * - * @since 5.8.0 - * - * @global string $pagenow The filename of the current screen. - */ -function wp_add_iframed_editor_assets_html() { - global $pagenow; - - if ( ! wp_should_load_block_editor_scripts_and_styles() ) { - return; - } - - $script_handles = array(); - $style_handles = array( - 'wp-block-editor', - 'wp-block-library', - 'wp-block-library-theme', - 'wp-edit-blocks', - ); - - if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) { - $style_handles[] = 'wp-widgets'; - $style_handles[] = 'wp-edit-widgets'; - } - - $block_registry = WP_Block_Type_Registry::get_instance(); - - foreach ( $block_registry->get_all_registered() as $block_type ) { - if ( ! empty( $block_type->style ) ) { - $style_handles[] = $block_type->style; - } - - if ( ! empty( $block_type->editor_style ) ) { - $style_handles[] = $block_type->editor_style; - } - - if ( ! empty( $block_type->script ) ) { - $script_handles[] = $block_type->script; - } - } - - $style_handles = array_unique( $style_handles ); - $done = wp_styles()->done; - - ob_start(); - - // We do not need reset styles for the iframed editor. - wp_styles()->done = array( 'wp-reset-editor-styles' ); - wp_styles()->do_items( $style_handles ); - wp_styles()->done = $done; - - $styles = ob_get_clean(); - - $script_handles = array_unique( $script_handles ); - $done = wp_scripts()->done; - - ob_start(); - - wp_scripts()->done = array(); - wp_scripts()->do_items( $script_handles ); - wp_scripts()->done = $done; - - $scripts = ob_get_clean(); - - $editor_assets = wp_json_encode( - array( - 'styles' => $styles, - 'scripts' => $scripts, - ) - ); - - echo ""; -} - /** * Function that enqueues the CSS Custom Properties coming from theme.json. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 61efc1899e..5a7675e91f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-53159'; +$wp_version = '6.0-alpha-53160'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.