[ 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: 363 lines (13 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_Script_Modules:: (12 methods):
  register()
  enqueue()
  dequeue()
  deregister()
  add_hooks()
  print_enqueued_script_modules()
  print_script_module_preloads()
  print_import_map()
  get_import_map()
  get_marked_for_enqueue()
  get_dependencies()
  get_src()


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.

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.

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.


print_enqueued_script_modules()   X-Ref
Prints the enqueued script modules using script tags with type="module"
attributes.


print_script_module_preloads()   X-Ref
Prints the 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.

return: 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.

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

get_src( string $id )   X-Ref
No description



Generated : Sat Apr 27 08:20:02 2024 Cross-referenced by PHPXref