WP_Script_Modules
- Since
- 6.5.0
- Source
wp-includes/class-wp-script-modules.php:26
Core class used to register script modules.
Compatibility
- WordPress
- since 6.5.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 2
Every hook that fires from inside WP_Script_Modules, in the order it appears in the class, grouped by the method that fires it.
Properties · 7
$registeredarray<string,private- Holds the registered script modules, keyed by script module identifier.
$queuestring[]private- An array of IDs for queued script modules.
$donestring[]private- Holds the script module identifiers that have been printed.
$a11y_availableboolprivate- Tracks whether the @wordpress/a11y script module is available.
$dependents_maparray<string,private- Holds a mapping of dependents (as IDs) for a given script ID.
$prioritiesstring[]private- Holds the valid values for fetchpriority.
$modules_with_missing_dependenciesstring[]private- List of IDs for script modules encountered which have missing dependencies.
Methods · 28
- register()Registers the script module if no script module with that script module identifier has already been registered.
- get_queue()Gets IDs for queued script modules.
- is_valid_fetchpriority()Checks if the provided fetchpriority is valid.
- set_fetchpriority()Sets the fetch priority for a script module.
- set_in_footer()Sets whether a script module should be printed in the footer.
- enqueue()Marks the script module to be enqueued in the page.
- dequeue()Unmarks the script module so it will no longer be enqueued in the page.
- deregister()Removes a registered script module.
- set_translations()Overrides the text domain and path used to load translations for a script module.
- print_script_module_translations()Prints translations for all enqueued script modules.
- add_hooks()Adds the hooks to print the import map, enqueued script modules and script module preloads.
- get_highest_fetchpriority()Gets the highest fetch priority for the provided script IDs.
- print_head_enqueued_script_modules()Prints the enqueued script modules in head.
- print_enqueued_script_modules()Prints the enqueued script modules in footer.
- print_script_module()Prints the enqueued script module using script tags with type="module" attributes.
- print_script_module_preloads()Prints the static dependencies of the enqueued script modules using link tags with rel="modulepreload" attributes.
- print_import_map()Prints the import map using a script tag with a type="importmap" attribute.
- get_import_map()Returns the import map array.
- get_marked_for_enqueue()Retrieves the list of script modules marked for enqueue.
- get_dependencies()Retrieves all the dependencies for the given script module identifiers, filtered by import types.
- get_dependents()Gets all dependents of a script module.
- get_recursive_dependents()Gets all recursive dependents of a script module.
- get_sorted_dependencies()Sorts the given script module identifiers based on their dependencies.
- sort_item_dependencies()Recursively sorts the dependencies for a single script module identifier.
- get_registered()Gets the data for a registered script module.
- get_src()Gets the versioned URL for a script module src.
- print_script_module_data()Print data associated with Script Modules.
- print_a11y_script_module_html()
Source code
class WP_Script_Modules { /** * Holds the registered script modules, keyed by script module identifier. * * @since 6.5.0 * @var array<string, array<string, mixed>> * @phpstan-var array<string, ScriptModule> */ private $registered = array(); /** * An array of IDs for queued script modules. * * @since 6.9.0 * @var string[] */ private $queue = array(); /** * Holds the script module identifiers that have been printed. * * @since 6.9.0 * @var string[] */ private $done = array(); /** * Tracks whether the @wordpress/a11y script module is available. * * Some additional HTML is required on the page for the module to work. Track * whether it's available to print at the appropriate time. * * @since 6.7.0 * @var bool */ private $a11y_available = false; /** * Holds a mapping of dependents (as IDs) for a given script ID. * Used to optimize recursive dependency tree checks. * * @since 6.9.0 * @var array<string, string[]> */ private $dependents_map = array(); /** * Holds the valid values for fetchpriority. * * @since 6.9.0 * @var string[] */ private $priorities = array( 'low', 'auto', 'high', ); /** * List of IDs for script modules encountered which have missing dependencies. * * An ID is added to this list when it is discovered to have missing dependencies. At this time, a warning is * emitted with {@see _doing_it_wrong()}. The ID is then added to this list, so that duplicate warnings don't occur. * * @since 6.9.1 * @var string[] */ private $modules_with_missing_dependencies = array(); /** * Registers the script module if no script module with that script module * identifier has already been registered. * * @since 6.5.0 * @since 6.9.0 Added the $args parameter. * * @param string $id The identifier of the script module. Should be unique. It will be used in the * final import map. * @param string $src Optional. Full URL of the script module, or path of the script module relative * to the WordPress root directory. If it is provided and the script module hasChangelog
Introduced in 6.5.0. 14 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
7.0.4
Method
set_translations() added.verified against source7.0.4
Method
print_script_module_translations() added.verified against source7.0.4
Method
get_registered() added.verified against source6.9.7
Method
get_queue() added.verified against source6.9.7
Method
is_valid_fetchpriority() added.verified against source6.9.7
Method
set_fetchpriority() added.verified against source6.9.7
Method
set_in_footer() added.verified against source6.9.7
Method
get_highest_fetchpriority() added.verified against source6.9.7
Method
print_head_enqueued_script_modules() added.verified against source6.9.7
Method
print_script_module() added.verified against source6.9.7
Method
get_dependents() added.verified against source6.9.7
Method
get_recursive_dependents() added.verified against source6.9.7
Method
get_sorted_dependencies() added.verified against source6.9.7
Method
sort_item_dependencies() added.verified against source6.5.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-script-modules.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.