| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
Script Modules API: WP_Script_Modules class. Native support for ES Modules and Import Maps.
| File Size: | 1143 lines (41 kb) |
| Included or required: | 0 times |
| Referenced: | 0 times |
| Includes or requires: | 0 files |
WP_Script_Modules:: (28 methods):
register()
get_queue()
is_valid_fetchpriority()
set_fetchpriority()
set_in_footer()
enqueue()
dequeue()
deregister()
set_translations()
print_script_module_translations()
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_registered()
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<string|array<string, string>> $deps { param: string|false|null $version Optional. String specifying the script module version number. Defaults to false. param: array<string, string|bool> $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. return: bool Whether valid fetchpriority. param: string|mixed $priority Fetch priority. |
| set_fetchpriority( string $id, string $priority ) X-Ref |
| Sets the fetch priority for a script module. return: bool Whether setting the fetchpriority was successful. param: string $id Script module identifier. param: 'auto'|'low'|'high' $priority Fetch priority for the script module. |
| 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. return: bool Whether setting the printing location was successful. param: string $id Script module identifier. param: bool $in_footer Whether to print in the footer. |
| 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<string|array<string, string>> $deps { param: string|false|null $version Optional. String specifying the script module version number. Defaults to false. param: array<string, string|bool> $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. |
| set_translations( string $id, string $domain = 'default', string $path = '' ) X-Ref |
| Overrides the text domain and path used to load translations for a script module. This is only needed for modules whose text domain differs from 'default' or whose translation files live outside the standard locations, for example plugin modules that register their own text domain. Translations for modules that use the default domain are loaded automatically by {@see WP_Script_Modules::print_script_module_translations()}. return: bool True if the text domain was registered, false if the module is not registered. param: string $id The identifier of the script module. param: string $domain Optional. Text domain. Default 'default'. param: string $path Optional. The full file path to the directory containing translation files. |
| print_script_module_translations() X-Ref |
| Prints translations for all enqueued script modules. Outputs inline `<script>` tags that call `wp.i18n.setLocaleData()` with the translated strings for each script module. This must run before the script modules execute. Auto-detects the text domain and translation path for each module from its source URL. Modules whose text domain or path differs from the defaults can opt into a specific domain/path via {@see WP_Script_Modules::set_translations()}. |
| 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. return: 'auto'|'low'|'high' Highest fetch priority for the provided script module IDs. param: string[] $ids 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<string, array<string, string>> Array with an `imports` key mapping to an array of script module |
| 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<string, mixed>> 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. return: array<string, array<string, mixed>> List of dependencies, keyed by script module identifier. 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. |
| get_dependents( string $id ) X-Ref |
| Gets all dependents of a script module. This is not recursive. return: string[] Script module IDs. param: string $id The script ID. |
| get_recursive_dependents( string $id ) X-Ref |
| Gets all recursive dependents of a script module. return: string[] Script module IDs. param: string $id The script ID. |
| 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. return: string[] Sorted list of script module identifiers. 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. |
| sort_item_dependencies( string $id, array $import_types, array &$sorted ) X-Ref |
| Recursively sorts the dependencies for a single script module identifier. return: bool True on success, false on failure (e.g., missing dependency). 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. |
| get_registered( string $id ) X-Ref |
| Gets the data for a registered script module. return: array|null The script module data, or null if not registered. param: string $id The script module identifier. |
| 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. return: string The script module src with a version if relevant. param: string $id The script module identifier. |
| 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 : Wed Sep 16 08:20:31 2026 | Cross-referenced by PHPXref |