diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 6f5720ec21c9d..8e313d25f2a28 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -286,28 +286,33 @@ function get_legacy_widget_block_editor_settings() { * Collect the block editor assets that need to be loaded into the editor's iframe. * * @since 6.0.0 + * @since 7.0.0 Allow enqueuing script modules. * @access private * - * @global WP_Styles $wp_styles The WP_Styles current instance. - * @global WP_Scripts $wp_scripts The WP_Scripts current instance. + * @global WP_Styles $wp_styles The WP_Styles current instance. + * @global WP_Scripts $wp_scripts The WP_Scripts current instance. + * @global WP_Script_Modules $wp_script_modules The WP_Script_Modules current instance. * * @return array { * The block editor assets. * - * @type string|false $styles String containing the HTML for styles. - * @type string|false $scripts String containing the HTML for scripts. + * @type string|false $styles String containing the HTML for styles. + * @type string|false $scripts String containing the HTML for scripts. + * @type string|false $script_modules String containing the HTML for scripts. * } */ function _wp_get_iframed_editor_assets() { - global $wp_styles, $wp_scripts; + global $wp_styles, $wp_scripts, $wp_script_modules; // Keep track of the styles and scripts instance to restore later. - $current_wp_styles = $wp_styles; - $current_wp_scripts = $wp_scripts; + $current_wp_styles = $wp_styles; + $current_wp_scripts = $wp_scripts; + $current_wp_script_modules = $wp_script_modules; // Create new instances to collect the assets. $wp_styles = new WP_Styles(); $wp_scripts = new WP_Scripts(); + $wp_script_modules = $wp_script_modules->clone_without_enqueued_modules(); /* * Register all currently registered styles and scripts. The actions that @@ -379,13 +384,22 @@ function _wp_get_iframed_editor_assets() { wp_print_footer_scripts(); $scripts = ob_get_clean(); + ob_start(); + $wp_script_modules->print_import_map(); + $wp_script_modules->print_head_enqueued_script_modules(); + $wp_script_modules->print_enqueued_script_modules(); + $wp_script_modules->print_script_module_preloads(); + $script_modules = ob_get_clean(); + // Restore the original instances. - $wp_styles = $current_wp_styles; - $wp_scripts = $current_wp_scripts; + $wp_styles = $current_wp_styles; + $wp_scripts = $current_wp_scripts; + $wp_script_modules = $current_wp_script_modules; return array( - 'styles' => $styles, - 'scripts' => $scripts, + 'styles' => $styles, + 'scripts' => $scripts, + 'script_modules' => $script_modules, ); } diff --git a/src/wp-includes/class-wp-script-modules.php b/src/wp-includes/class-wp-script-modules.php index e05e1900a2b49..25e4b6a75d117 100644 --- a/src/wp-includes/class-wp-script-modules.php +++ b/src/wp-includes/class-wp-script-modules.php @@ -949,4 +949,12 @@ public function print_a11y_script_module_html() { . '
' . ''; } + + public function clone_without_enqueued_modules(): WP_Script_Modules { + $clone = new WP_Script_Modules(); + $clone->registered = $this->registered; + $clone->dependents_map = $this->dependents_map; + $clone->modules_with_missing_dependencies = $this->modules_with_missing_dependencies; + return $clone; + } }