Changeset 57327 for trunk/src/wp-includes/script-modules.php
- Timestamp:
- 01/23/2024 03:32:03 AM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/script-modules.php
r57269 r57327 1 1 <?php 2 2 /** 3 * Script Modules API: Module functions3 * Script Modules API: Script Module functions 4 4 * 5 5 * @since 6.5.0 … … 19 19 * @return WP_Script_Modules The main WP_Script_Modules instance. 20 20 */ 21 function wp_ modules(){21 function wp_script_modules(): WP_Script_Modules { 22 22 static $instance = null; 23 23 if ( is_null( $instance ) ) { … … 29 29 30 30 /** 31 * Registers the module if no module with that module identifier has already32 * been registered.31 * Registers the script module if no script module with that script module 32 * identifier has already been registered. 33 33 * 34 34 * @since 6.5.0 35 35 * 36 * @param string $module_id The identifier of the module. 37 * Should be unique. It will be used 38 * in the final import map. 39 * @param string $src Full URL of the module, or path of 40 * the module relative to the 41 * WordPress root directory. 42 * @param array<string|array{id: string, import?: 'static'|'dynamic' }> $deps Optional. An array of module 43 * identifiers of the dependencies of 44 * this module. The dependencies can 45 * be strings or arrays. If they are 46 * arrays, they need an `id` key with 47 * the module identifier, and can 48 * contain an `import` key with either 49 * `static` or `dynamic`. By default, 50 * dependencies that don't contain an 51 * `import` key are considered static. 52 * @param string|false|null $version Optional. String specifying the 53 * module version number. Defaults to 54 * false. It is added to the URL as a 55 * query string for cache busting 56 * purposes. If $version is set to 57 * false, the version number is the 58 * currently installed WordPress 59 * version. If $version is set to 60 * null, no version is added. 36 * @param string $id The identifier of the script module. Should be unique. It will be used in the 37 * final import map. 38 * @param string $src Optional. Full URL of the script module, or path of the script module relative 39 * to the WordPress root directory. If it is provided and the script module has 40 * not been registered yet, it will be registered. 41 * @param array $deps { 42 * Optional. List of dependencies. 43 * 44 * @type string|array $0... { 45 * An array of script module identifiers of the dependencies of this script 46 * module. The dependencies can be strings or arrays. If they are arrays, 47 * they need an `id` key with the script module identifier, and can contain 48 * an `import` key with either `static` or `dynamic`. By default, 49 * dependencies that don't contain an `import` key are considered static. 50 * 51 * @type string $id The script module identifier. 52 * @type string $import Optional. Import type. May be either `static` or 53 * `dynamic`. Defaults to `static`. 54 * } 55 * } 56 * @param string|false|null $version Optional. String specifying the script module version number. Defaults to false. 57 * It is added to the URL as a query string for cache busting purposes. If $version 58 * is set to false, the version number is the currently installed WordPress version. 59 * If $version is set to null, no version is added. 61 60 */ 62 function wp_register_ module( $module_id, $src,$deps = array(), $version = false ) {63 wp_ modules()->register( $module_id, $src, $deps, $version );61 function wp_register_script_module( string $id, string $src, array $deps = array(), $version = false ) { 62 wp_script_modules()->register( $id, $src, $deps, $version ); 64 63 } 65 64 66 65 /** 67 * Marks the module to be enqueued in the page.66 * Marks the script module to be enqueued in the page. 68 67 * 69 * If a src is provided and the module has not been registered yet, it will be70 * registered.68 * If a src is provided and the script module has not been registered yet, it 69 * will be registered. 71 70 * 72 71 * @since 6.5.0 73 72 * 74 * @param string $module_id The identifier of the module. 75 * Should be unique. It will be used 76 * in the final import map. 77 * @param string $src Optional. Full URL of the module, 78 * or path of the module relative to 79 * the WordPress root directory. If 80 * it is provided and the module has 81 * not been registered yet, it will be 82 * registered. 83 * @param array<string|array{id: string, import?: 'static'|'dynamic' }> $deps Optional. An array of module 84 * identifiers of the dependencies of 85 * this module. The dependencies can 86 * be strings or arrays. If they are 87 * arrays, they need an `id` key with 88 * the module identifier, and can 89 * contain an `import` key with either 90 * `static` or `dynamic`. By default, 91 * dependencies that don't contain an 92 * `import` key are considered static. 93 * @param string|false|null $version Optional. String specifying the 94 * module version number. Defaults to 95 * false. It is added to the URL as a 96 * query string for cache busting 97 * purposes. If $version is set to 98 * false, the version number is the 99 * currently installed WordPress 100 * version. If $version is set to 101 * null, no version is added. 73 * @param string $id The identifier of the script module. Should be unique. It will be used in the 74 * final import map. 75 * @param string $src Optional. Full URL of the script module, or path of the script module relative 76 * to the WordPress root directory. If it is provided and the script module has 77 * not been registered yet, it will be registered. 78 * @param array $deps { 79 * Optional. List of dependencies. 80 * 81 * @type string|array $0... { 82 * An array of script module identifiers of the dependencies of this script 83 * module. The dependencies can be strings or arrays. If they are arrays, 84 * they need an `id` key with the script module identifier, and can contain 85 * an `import` key with either `static` or `dynamic`. By default, 86 * dependencies that don't contain an `import` key are considered static. 87 * 88 * @type string $id The script module identifier. 89 * @type string $import Optional. Import type. May be either `static` or 90 * `dynamic`. Defaults to `static`. 91 * } 92 * } 93 * @param string|false|null $version Optional. String specifying the script module version number. Defaults to false. 94 * It is added to the URL as a query string for cache busting purposes. If $version 95 * is set to false, the version number is the currently installed WordPress version. 96 * If $version is set to null, no version is added. 102 97 */ 103 function wp_enqueue_ module( $module_id, $src = '',$deps = array(), $version = false ) {104 wp_ modules()->enqueue( $module_id, $src, $deps, $version );98 function wp_enqueue_script_module( string $id, string $src = '', array $deps = array(), $version = false ) { 99 wp_script_modules()->enqueue( $id, $src, $deps, $version ); 105 100 } 106 101 107 102 /** 108 * Unmarks the module so it is no longer enqueued in the page.103 * Unmarks the script module so it is no longer enqueued in the page. 109 104 * 110 105 * @since 6.5.0 111 106 * 112 * @param string $ module_id The identifier of themodule.107 * @param string $id The identifier of the script module. 113 108 */ 114 function wp_dequeue_ module( $module_id ) {115 wp_ modules()->dequeue( $module_id );109 function wp_dequeue_script_module( string $id ) { 110 wp_script_modules()->dequeue( $id ); 116 111 }
Note: See TracChangeset
for help on using the changeset viewer.