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].



git-svn-id: https://develop.svn.wordpress.org/trunk@53160 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Greg Ziółkowski
2022-04-12 15:59:47 +00:00
parent 51d2b2924a
commit 1d086c57d5
4 changed files with 83 additions and 83 deletions

View File

@@ -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 "<script>window.__editorAssets = $editor_assets</script>";
}
/**
* Function that enqueues the CSS Custom Properties coming from theme.json.
*