Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: script-modules.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Script Modules API: Script Module functions
[2] Fix | Delete
*
[3] Fix | Delete
* @since 6.5.0
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Script Modules
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Retrieves the main WP_Script_Modules instance.
[11] Fix | Delete
*
[12] Fix | Delete
* This function provides access to the WP_Script_Modules instance, creating one
[13] Fix | Delete
* if it doesn't exist yet.
[14] Fix | Delete
*
[15] Fix | Delete
* @since 6.5.0
[16] Fix | Delete
*
[17] Fix | Delete
* @global WP_Script_Modules $wp_script_modules
[18] Fix | Delete
*
[19] Fix | Delete
* @return WP_Script_Modules The main WP_Script_Modules instance.
[20] Fix | Delete
*/
[21] Fix | Delete
function wp_script_modules(): WP_Script_Modules {
[22] Fix | Delete
global $wp_script_modules;
[23] Fix | Delete
[24] Fix | Delete
if ( ! ( $wp_script_modules instanceof WP_Script_Modules ) ) {
[25] Fix | Delete
$wp_script_modules = new WP_Script_Modules();
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
return $wp_script_modules;
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Registers the script module if no script module with that script module
[33] Fix | Delete
* identifier has already been registered.
[34] Fix | Delete
*
[35] Fix | Delete
* @since 6.5.0
[36] Fix | Delete
*
[37] Fix | Delete
* @param string $id The identifier of the script module. Should be unique. It will be used in the
[38] Fix | Delete
* final import map.
[39] Fix | Delete
* @param string $src Optional. Full URL of the script module, or path of the script module relative
[40] Fix | Delete
* to the WordPress root directory. If it is provided and the script module has
[41] Fix | Delete
* not been registered yet, it will be registered.
[42] Fix | Delete
* @param array $deps {
[43] Fix | Delete
* Optional. List of dependencies.
[44] Fix | Delete
*
[45] Fix | Delete
* @type string|array ...$0 {
[46] Fix | Delete
* An array of script module identifiers of the dependencies of this script
[47] Fix | Delete
* module. The dependencies can be strings or arrays. If they are arrays,
[48] Fix | Delete
* they need an `id` key with the script module identifier, and can contain
[49] Fix | Delete
* an `import` key with either `static` or `dynamic`. By default,
[50] Fix | Delete
* dependencies that don't contain an `import` key are considered static.
[51] Fix | Delete
*
[52] Fix | Delete
* @type string $id The script module identifier.
[53] Fix | Delete
* @type string $import Optional. Import type. May be either `static` or
[54] Fix | Delete
* `dynamic`. Defaults to `static`.
[55] Fix | Delete
* }
[56] Fix | Delete
* }
[57] Fix | Delete
* @param string|false|null $version Optional. String specifying the script module version number. Defaults to false.
[58] Fix | Delete
* It is added to the URL as a query string for cache busting purposes. If $version
[59] Fix | Delete
* is set to false, the version number is the currently installed WordPress version.
[60] Fix | Delete
* If $version is set to null, no version is added.
[61] Fix | Delete
*/
[62] Fix | Delete
function wp_register_script_module( string $id, string $src, array $deps = array(), $version = false ) {
[63] Fix | Delete
wp_script_modules()->register( $id, $src, $deps, $version );
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Marks the script module to be enqueued in the page.
[68] Fix | Delete
*
[69] Fix | Delete
* If a src is provided and the script module has not been registered yet, it
[70] Fix | Delete
* will be registered.
[71] Fix | Delete
*
[72] Fix | Delete
* @since 6.5.0
[73] Fix | Delete
*
[74] Fix | Delete
* @param string $id The identifier of the script module. Should be unique. It will be used in the
[75] Fix | Delete
* final import map.
[76] Fix | Delete
* @param string $src Optional. Full URL of the script module, or path of the script module relative
[77] Fix | Delete
* to the WordPress root directory. If it is provided and the script module has
[78] Fix | Delete
* not been registered yet, it will be registered.
[79] Fix | Delete
* @param array $deps {
[80] Fix | Delete
* Optional. List of dependencies.
[81] Fix | Delete
*
[82] Fix | Delete
* @type string|array ...$0 {
[83] Fix | Delete
* An array of script module identifiers of the dependencies of this script
[84] Fix | Delete
* module. The dependencies can be strings or arrays. If they are arrays,
[85] Fix | Delete
* they need an `id` key with the script module identifier, and can contain
[86] Fix | Delete
* an `import` key with either `static` or `dynamic`. By default,
[87] Fix | Delete
* dependencies that don't contain an `import` key are considered static.
[88] Fix | Delete
*
[89] Fix | Delete
* @type string $id The script module identifier.
[90] Fix | Delete
* @type string $import Optional. Import type. May be either `static` or
[91] Fix | Delete
* `dynamic`. Defaults to `static`.
[92] Fix | Delete
* }
[93] Fix | Delete
* }
[94] Fix | Delete
* @param string|false|null $version Optional. String specifying the script module version number. Defaults to false.
[95] Fix | Delete
* It is added to the URL as a query string for cache busting purposes. If $version
[96] Fix | Delete
* is set to false, the version number is the currently installed WordPress version.
[97] Fix | Delete
* If $version is set to null, no version is added.
[98] Fix | Delete
*/
[99] Fix | Delete
function wp_enqueue_script_module( string $id, string $src = '', array $deps = array(), $version = false ) {
[100] Fix | Delete
wp_script_modules()->enqueue( $id, $src, $deps, $version );
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Unmarks the script module so it is no longer enqueued in the page.
[105] Fix | Delete
*
[106] Fix | Delete
* @since 6.5.0
[107] Fix | Delete
*
[108] Fix | Delete
* @param string $id The identifier of the script module.
[109] Fix | Delete
*/
[110] Fix | Delete
function wp_dequeue_script_module( string $id ) {
[111] Fix | Delete
wp_script_modules()->dequeue( $id );
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Deregisters the script module.
[116] Fix | Delete
*
[117] Fix | Delete
* @since 6.5.0
[118] Fix | Delete
*
[119] Fix | Delete
* @param string $id The identifier of the script module.
[120] Fix | Delete
*/
[121] Fix | Delete
function wp_deregister_script_module( string $id ) {
[122] Fix | Delete
wp_script_modules()->deregister( $id );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Registers all the default WordPress Script Modules.
[127] Fix | Delete
*
[128] Fix | Delete
* @since 6.7.0
[129] Fix | Delete
*/
[130] Fix | Delete
function wp_default_script_modules() {
[131] Fix | Delete
$suffix = defined( 'WP_RUN_CORE_TESTS' ) ? '.min' : wp_scripts_get_suffix();
[132] Fix | Delete
[133] Fix | Delete
/*
[134] Fix | Delete
* Expects multidimensional array like:
[135] Fix | Delete
*
[136] Fix | Delete
* 'interactivity/index.min.js' => array('dependencies' => array(…), 'version' => '…'),
[137] Fix | Delete
* 'interactivity/debug.min.js' => array('dependencies' => array(…), 'version' => '…'),
[138] Fix | Delete
* 'interactivity-router/index.min.js' => …
[139] Fix | Delete
*/
[140] Fix | Delete
$assets = include ABSPATH . WPINC . "/assets/script-modules-packages{$suffix}.php";
[141] Fix | Delete
[142] Fix | Delete
foreach ( $assets as $file_name => $script_module_data ) {
[143] Fix | Delete
/*
[144] Fix | Delete
* Build the WordPress Script Module ID from the file name.
[145] Fix | Delete
* Prepend `@wordpress/` and remove extensions and `/index` if present:
[146] Fix | Delete
* - interactivity/index.min.js => @wordpress/interactivity
[147] Fix | Delete
* - interactivity/debug.min.js => @wordpress/interactivity/debug
[148] Fix | Delete
* - block-library/query/view.js => @wordpress/block-library/query/view
[149] Fix | Delete
*/
[150] Fix | Delete
$script_module_id = '@wordpress/' . preg_replace( '~(?:/index)?(?:\.min)?\.js$~D', '', $file_name, 1 );
[151] Fix | Delete
[152] Fix | Delete
switch ( $script_module_id ) {
[153] Fix | Delete
/*
[154] Fix | Delete
* Interactivity exposes two entrypoints, "/index" and "/debug".
[155] Fix | Delete
* "/debug" should replace "/index" in development.
[156] Fix | Delete
*/
[157] Fix | Delete
case '@wordpress/interactivity/debug':
[158] Fix | Delete
if ( ! SCRIPT_DEBUG ) {
[159] Fix | Delete
continue 2;
[160] Fix | Delete
}
[161] Fix | Delete
$script_module_id = '@wordpress/interactivity';
[162] Fix | Delete
break;
[163] Fix | Delete
case '@wordpress/interactivity':
[164] Fix | Delete
if ( SCRIPT_DEBUG ) {
[165] Fix | Delete
continue 2;
[166] Fix | Delete
}
[167] Fix | Delete
break;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
$path = includes_url( "js/dist/script-modules/{$file_name}" );
[171] Fix | Delete
wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'] );
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function