From f76f80f77ac05f51313bb2550bf36f4ca267abcf Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Tue, 30 Jan 2024 16:20:11 +0100 Subject: [PATCH] Move polyfill to import map function --- src/wp-includes/class-wp-script-modules.php | 30 ++++++--------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/wp-includes/class-wp-script-modules.php b/src/wp-includes/class-wp-script-modules.php index 4292df5981d7e..a2b3a218d7aeb 100644 --- a/src/wp-includes/class-wp-script-modules.php +++ b/src/wp-includes/class-wp-script-modules.php @@ -166,7 +166,6 @@ public function add_hooks() { add_action( $position, array( $this, 'print_import_map' ) ); add_action( $position, array( $this, 'print_enqueued_script_modules' ) ); add_action( $position, array( $this, 'print_script_module_preloads' ) ); - add_action( 'wp_footer', array( $this, 'print_import_map_polyfill' ), 11 ); } /** @@ -211,30 +210,10 @@ public function print_script_module_preloads() { /** * Prints the import map using a script tag with a type="importmap" attribute. * + * @global WP_Scripts $wp_scripts The WP_Scripts object for printing the polyfill. * @since 6.5.0 */ public function print_import_map() { - $import_map = $this->get_import_map(); - if ( ! empty( $import_map['imports'] ) ) { - wp_print_inline_script_tag( - wp_json_encode( $import_map, JSON_HEX_TAG | JSON_HEX_AMP ), - array( - 'type' => 'importmap', - 'id' => 'wp-importmap', - ) - ); - } - } - - /** - * Prints the necessary script to load import map polyfill for browsers that - * do not support import maps. It is only printed when there is an import - * map to print. - * - * @global WP_Scripts $wp_scripts The WP_Scripts object for printing inline scripts. - * @since 6.5.0 - */ - public function print_import_map_polyfill() { $import_map = $this->get_import_map(); if ( ! empty( $import_map['imports'] ) ) { global $wp_scripts; @@ -249,6 +228,13 @@ public function print_import_map_polyfill() { 'id' => 'wp-load-polyfill-importmap', ) ); + wp_print_inline_script_tag( + wp_json_encode( $import_map, JSON_HEX_TAG | JSON_HEX_AMP ), + array( + 'type' => 'importmap', + 'id' => 'wp-importmap', + ) + ); } }