Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
);
}

Expand Down
8 changes: 8 additions & 0 deletions src/wp-includes/class-wp-script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,4 +949,12 @@ public function print_a11y_script_module_html() {
. '<div id="a11y-speak-polite" class="a11y-speak-region" aria-live="polite" aria-relevant="additions text" aria-atomic="true"></div>'
. '</div>';
}

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;
}
}
Loading