Skip to content

Commit

Permalink
Move polyfill to import map function
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Jan 30, 2024
1 parent 35d249e commit f76f80f
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/wp-includes/class-wp-script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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',
)
);
}
}

Expand Down

0 comments on commit f76f80f

Please sign in to comment.