Title: WP_Script_Modules::get_import_map
Published: April 3, 2024
Last modified: August 20, 2026

---

# WP_Script_Modules::get_import_map(): array<string,

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#changelog)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Returns the import map array.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#return)󠁿

 array<string, array<string, string>> Array with an `imports` key mapping to an 
array of script module identifiers and their respective URLs, including the version
query.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#source)󠁿

    ```php
    private function get_import_map(): array {
    	global $wp_scripts;

    	$imports = array();

    	// Identify script modules that are dependencies of classic scripts.
    	$classic_script_module_dependencies = array();
    	if ( $wp_scripts instanceof WP_Scripts ) {
    		$handles = array_merge(
    			$wp_scripts->queue,
    			$wp_scripts->to_do,
    			$wp_scripts->done
    		);

    		$processed = array();
    		while ( ! empty( $handles ) ) {
    			$handle = array_pop( $handles );
    			if ( isset( $processed[ $handle ] ) || ! isset( $wp_scripts->registered[ $handle ] ) ) {
    				continue;
    			}
    			$processed[ $handle ] = true;

    			$module_dependencies = $wp_scripts->get_data( $handle, 'module_dependencies' );
    			if ( is_array( $module_dependencies ) ) {
    				$missing_module_dependencies = array();
    				foreach ( $module_dependencies as $module ) {
    					if ( is_string( $module ) ) {
    						$id = $module;
    					} elseif ( is_array( $module ) && isset( $module['id'] ) && is_string( $module['id'] ) ) {
    						$id = $module['id'];
    					} else {
    						// Invalid module dependency was supplied by direct manipulation of the extra data.
    						// Normally, this error scenario would be caught when WP_Scripts::add_data() is called.
    						continue;
    					}

    					if ( ! isset( $this->registered[ $id ] ) ) {
    						$missing_module_dependencies[] = $id;
    					} else {
    						$classic_script_module_dependencies[] = $id;
    					}
    				}

    				if ( count( $missing_module_dependencies ) > 0 ) {
    					_doing_it_wrong(
    						'WP_Scripts::add_data',
    						sprintf(
    							/* translators: 1: Script handle, 2: 'module_dependencies', 3: List of missing dependency IDs. */
    							__( 'The script with the handle "%1$s" was enqueued with script module dependencies ("%2$s") that are not registered: %3$s.' ),
    							$handle,
    							'module_dependencies',
    							implode( wp_get_list_item_separator(), $missing_module_dependencies )
    						),
    						'7.0.0'
    					);
    				}
    			}

    			foreach ( $wp_scripts->registered[ $handle ]->deps as $dep ) {
    				if ( ! isset( $processed[ $dep ] ) ) {
    					$handles[] = $dep;
    				}
    			}
    		}
    	}

    	// Note: the script modules in $this->queue are not included in the importmap because they get printed as scripts.
    	$ids = array_unique(
    		array_merge(
    			$classic_script_module_dependencies,
    			array_keys( $this->get_dependencies( array_merge( $this->queue, $classic_script_module_dependencies ) ) )
    		)
    	);
    	foreach ( $ids as $id ) {
    		$src = $this->get_src( $id );
    		if ( '' !== $src ) {
    			$imports[ $id ] = $src;
    		}
    	}
    	return array( 'imports' => $imports );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-script-modules.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-script-modules.php#L644)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-script-modules.php#L644-L724)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Script_Modules::get_src()](https://developer.wordpress.org/reference/classes/wp_script_modules/get_src/)`wp-includes/class-wp-script-modules.php` |

Gets the versioned URL for a script module src.

  | 
| [WP_Script_Modules::get_dependencies()](https://developer.wordpress.org/reference/classes/wp_script_modules/get_dependencies/)`wp-includes/class-wp-script-modules.php` |

Retrieves all the dependencies for the given script module identifiers, filtered by import types.

  | 
| [wp_get_list_item_separator()](https://developer.wordpress.org/reference/functions/wp_get_list_item_separator/)`wp-includes/l10n.php` |

Retrieves the list item separator based on the locale.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_doing_it_wrong()](https://developer.wordpress.org/reference/functions/_doing_it_wrong/)`wp-includes/functions.php` |

Marks something as being incorrectly called.

  |

[Show 2 more](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#)

| Used by | Description | 
| [WP_Script_Modules::print_script_module_data()](https://developer.wordpress.org/reference/classes/wp_script_modules/print_script_module_data/)`wp-includes/class-wp-script-modules.php` |

Print data associated with Script Modules.

  | 
| [WP_Script_Modules::print_import_map()](https://developer.wordpress.org/reference/classes/wp_script_modules/print_import_map/)`wp-includes/class-wp-script-modules.php` |

Prints the import map using a script tag with a type=”importmap” attribute.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_script_modules/get_import_map/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Script module dependencies (`'module_dependencies'`) of classic scripts are now included. | 
| [6.5.0](https://developer.wordpress.org/reference/since/6.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_script_modules%2Fget_import_map%2F)
before being able to contribute a note or feedback.