[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> class-wp-script-modules.php (summary)

Script Modules API: WP_Script_Modules class. Native support for ES Modules and Import Maps.

File Size: 926 lines (32 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_Script_Modules:: (25 methods):
  register()
  get_queue()
  is_valid_fetchpriority()
  set_fetchpriority()
  set_in_footer()
  enqueue()
  dequeue()
  deregister()
  add_hooks()
  get_highest_fetchpriority()
  print_head_enqueued_script_modules()
  print_enqueued_script_modules()
  print_script_module()
  print_script_module_preloads()
  print_import_map()
  get_import_map()
  get_marked_for_enqueue()
  get_dependencies()
  get_dependents()
  get_recursive_dependents()
  get_sorted_dependencies()
  sort_item_dependencies()
  get_src()
  print_script_module_data()
  print_a11y_script_module_html()


Class: WP_Script_Modules  - X-Ref

Core class used to register script modules.

register( string $id, string $src, array $deps = array()   X-Ref
Registers the script module if no script module with that script module
identifier has already been registered.

param: string            $id       The identifier of the script module. Should be unique. It will be used in the
param: string            $src      Optional. Full URL of the script module, or path of the script module relative
param: array             $deps     {
param: string|false|null $version  Optional. String specifying the script module version number. Defaults to false.
param: array             $args     {

get_queue()   X-Ref
Gets IDs for queued script modules.

return: string[] Script module IDs.

is_valid_fetchpriority( $priority )   X-Ref
Checks if the provided fetchpriority is valid.

param: string|mixed $priority Fetch priority.
return: bool Whether valid fetchpriority.

set_fetchpriority( string $id, string $priority )   X-Ref
Sets the fetch priority for a script module.

param: string              $id       Script module identifier.
param: 'auto'|'low'|'high' $priority Fetch priority for the script module.
return: bool Whether setting the fetchpriority was successful.

set_in_footer( string $id, bool $in_footer )   X-Ref
Sets whether a script module should be printed in the footer.

This is only relevant in block themes.

param: string           $id        Script module identifier.
param: bool             $in_footer Whether to print in the footer.
return: bool Whether setting the printing location was successful.

enqueue( string $id, string $src = '', array $deps = array()   X-Ref
Marks the script module to be enqueued in the page.

If a src is provided and the script module has not been registered yet, it
will be registered.

param: string            $id       The identifier of the script module. Should be unique. It will be used in the
param: string            $src      Optional. Full URL of the script module, or path of the script module relative
param: array             $deps     {
param: string|false|null $version  Optional. String specifying the script module version number. Defaults to false.
param: array             $args     {

dequeue( string $id )   X-Ref
Unmarks the script module so it will no longer be enqueued in the page.

param: string $id The identifier of the script module.

deregister( string $id )   X-Ref
Removes a registered script module.

param: string $id The identifier of the script module.

add_hooks()   X-Ref
Adds the hooks to print the import map, enqueued script modules and script
module preloads.

In classic themes, the script modules used by the blocks are not yet known
when the `wp_head` actions is fired, so it needs to print everything in the
footer.


get_highest_fetchpriority( array $ids )   X-Ref
Gets the highest fetch priority for the provided script IDs.

param: string[] $ids Script module IDs.
return: 'auto'|'low'|'high' Highest fetch priority for the provided script module IDs.

print_head_enqueued_script_modules()   X-Ref
Prints the enqueued script modules in head.

This is only used in block themes.


print_enqueued_script_modules()   X-Ref
Prints the enqueued script modules in footer.


print_script_module( string $id )   X-Ref
Prints the enqueued script module using script tags with type="module"
attributes.

param: string $id The script module identifier.

print_script_module_preloads()   X-Ref
Prints the static dependencies of the enqueued script modules using
link tags with rel="modulepreload" attributes.

If a script module is marked for enqueue, it will not be preloaded.


print_import_map()   X-Ref
Prints the import map using a script tag with a type="importmap" attribute.


get_import_map()   X-Ref
Returns the import map array.

return: array Array with an `imports` key mapping to an array of script module identifiers and their respective

get_marked_for_enqueue()   X-Ref
Retrieves the list of script modules marked for enqueue.

Even though this is a private method and is unused in core, there are ecosystem plugins accessing it via the
Reflection API. The ecosystem should rather use {@see self::get_queue()}.

return: array<string, array> Script modules marked for enqueue, keyed by script module identifier.

get_dependencies( array $ids, array $import_types = array( 'static', 'dynamic' )   X-Ref
Retrieves all the dependencies for the given script module identifiers, filtered by import types.

It will consolidate an array containing a set of unique dependencies based
on the requested import types: 'static', 'dynamic', or both. This method is
recursive and also retrieves dependencies of the dependencies.

param: string[] $ids          The identifiers of the script modules for which to gather dependencies.
param: string[] $import_types Optional. Import types of dependencies to retrieve: 'static', 'dynamic', or both.
return: string[] List of IDs for script module dependencies.

get_dependents( string $id )   X-Ref
Gets all dependents of a script module.

This is not recursive.

param: string $id The script ID.
return: string[] Script module IDs.

get_recursive_dependents( string $id )   X-Ref
Gets all recursive dependents of a script module.

param: string $id The script ID.
return: string[] Script module IDs.

get_sorted_dependencies( array $ids, array $import_types = array( 'static', 'dynamic' )   X-Ref
Sorts the given script module identifiers based on their dependencies.

It will return a list of script module identifiers sorted in the order
they should be printed, so that dependencies are printed before the script
modules that depend on them.

param: string[] $ids          The identifiers of the script modules to sort.
param: string[] $import_types Optional. Import types of dependencies to retrieve: 'static', 'dynamic', or both.
return: string[] Sorted list of script module identifiers.

sort_item_dependencies( string $id, array $import_types, array &$sorted )   X-Ref
Recursively sorts the dependencies for a single script module identifier.

param: string   $id           The identifier of the script module to sort.
param: string[] $import_types Optional. Import types of dependencies to retrieve: 'static', 'dynamic', or both.
param: string[] &$sorted      The array of sorted identifiers, passed by reference.
return: bool True on success, false on failure (e.g., missing dependency).

get_src( string $id )   X-Ref
Gets the versioned URL for a script module src.

If $version is set to false, the version number is the currently installed
WordPress version. If $version is set to null, no version is added.
Otherwise, the string passed in $version is used.

param: string $id The script module identifier.
return: string The script module src with a version if relevant.

print_script_module_data()   X-Ref
Print data associated with Script Modules.

The data will be embedded in the page HTML and can be read by Script Modules on page load.


print_a11y_script_module_html()   X-Ref




Generated : Sun Oct 26 08:20:05 2025 Cross-referenced by PHPXref