Edit File by line
/home/zeestwma/ceyloniy.../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
* @since 6.9.0 Added the $args parameter.
[37] Fix | Delete
*
[38] Fix | Delete
* @param string $id The identifier of the script module. Should be unique. It will be used in the
[39] Fix | Delete
* final import map.
[40] Fix | Delete
* @param string $src Optional. Full URL of the script module, or path of the script module relative
[41] Fix | Delete
* to the WordPress root directory. If it is provided and the script module has
[42] Fix | Delete
* not been registered yet, it will be registered.
[43] Fix | Delete
* @param array $deps {
[44] Fix | Delete
* Optional. List of dependencies.
[45] Fix | Delete
*
[46] Fix | Delete
* @type string|array ...$0 {
[47] Fix | Delete
* An array of script module identifiers of the dependencies of this script
[48] Fix | Delete
* module. The dependencies can be strings or arrays. If they are arrays,
[49] Fix | Delete
* they need an `id` key with the script module identifier, and can contain
[50] Fix | Delete
* an `import` key with either `static` or `dynamic`. By default,
[51] Fix | Delete
* dependencies that don't contain an `import` key are considered static.
[52] Fix | Delete
*
[53] Fix | Delete
* @type string $id The script module identifier.
[54] Fix | Delete
* @type string $import Optional. Import type. May be either `static` or
[55] Fix | Delete
* `dynamic`. Defaults to `static`.
[56] Fix | Delete
* }
[57] Fix | Delete
* }
[58] Fix | Delete
* @param string|false|null $version Optional. String specifying the script module version number. Defaults to false.
[59] Fix | Delete
* It is added to the URL as a query string for cache busting purposes. If $version
[60] Fix | Delete
* is set to false, the version number is the currently installed WordPress version.
[61] Fix | Delete
* If $version is set to null, no version is added.
[62] Fix | Delete
* @param array $args {
[63] Fix | Delete
* Optional. An array of additional args. Default empty array.
[64] Fix | Delete
*
[65] Fix | Delete
* @type bool $in_footer Whether to print the script module in the footer. Only relevant to block themes. Default 'false'. Optional.
[66] Fix | Delete
* @type 'auto'|'low'|'high' $fetchpriority Fetch priority. Default 'auto'. Optional.
[67] Fix | Delete
* }
[68] Fix | Delete
*/
[69] Fix | Delete
function wp_register_script_module( string $id, string $src, array $deps = array(), $version = false, array $args = array() ) {
[70] Fix | Delete
wp_script_modules()->register( $id, $src, $deps, $version, $args );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Marks the script module to be enqueued in the page.
[75] Fix | Delete
*
[76] Fix | Delete
* If a src is provided and the script module has not been registered yet, it
[77] Fix | Delete
* will be registered.
[78] Fix | Delete
*
[79] Fix | Delete
* @since 6.5.0
[80] Fix | Delete
* @since 6.9.0 Added the $args parameter.
[81] Fix | Delete
*
[82] Fix | Delete
* @param string $id The identifier of the script module. Should be unique. It will be used in the
[83] Fix | Delete
* final import map.
[84] Fix | Delete
* @param string $src Optional. Full URL of the script module, or path of the script module relative
[85] Fix | Delete
* to the WordPress root directory. If it is provided and the script module has
[86] Fix | Delete
* not been registered yet, it will be registered.
[87] Fix | Delete
* @param array $deps {
[88] Fix | Delete
* Optional. List of dependencies.
[89] Fix | Delete
*
[90] Fix | Delete
* @type string|array ...$0 {
[91] Fix | Delete
* An array of script module identifiers of the dependencies of this script
[92] Fix | Delete
* module. The dependencies can be strings or arrays. If they are arrays,
[93] Fix | Delete
* they need an `id` key with the script module identifier, and can contain
[94] Fix | Delete
* an `import` key with either `static` or `dynamic`. By default,
[95] Fix | Delete
* dependencies that don't contain an `import` key are considered static.
[96] Fix | Delete
*
[97] Fix | Delete
* @type string $id The script module identifier.
[98] Fix | Delete
* @type string $import Optional. Import type. May be either `static` or
[99] Fix | Delete
* `dynamic`. Defaults to `static`.
[100] Fix | Delete
* }
[101] Fix | Delete
* }
[102] Fix | Delete
* @param string|false|null $version Optional. String specifying the script module version number. Defaults to false.
[103] Fix | Delete
* It is added to the URL as a query string for cache busting purposes. If $version
[104] Fix | Delete
* is set to false, the version number is the currently installed WordPress version.
[105] Fix | Delete
* If $version is set to null, no version is added.
[106] Fix | Delete
* @param array $args {
[107] Fix | Delete
* Optional. An array of additional args. Default empty array.
[108] Fix | Delete
*
[109] Fix | Delete
* @type bool $in_footer Whether to print the script module in the footer. Only relevant to block themes. Default 'false'. Optional.
[110] Fix | Delete
* @type 'auto'|'low'|'high' $fetchpriority Fetch priority. Default 'auto'. Optional.
[111] Fix | Delete
* }
[112] Fix | Delete
*/
[113] Fix | Delete
function wp_enqueue_script_module( string $id, string $src = '', array $deps = array(), $version = false, array $args = array() ) {
[114] Fix | Delete
wp_script_modules()->enqueue( $id, $src, $deps, $version, $args );
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Unmarks the script module so it is no longer enqueued in the page.
[119] Fix | Delete
*
[120] Fix | Delete
* @since 6.5.0
[121] Fix | Delete
*
[122] Fix | Delete
* @param string $id The identifier of the script module.
[123] Fix | Delete
*/
[124] Fix | Delete
function wp_dequeue_script_module( string $id ) {
[125] Fix | Delete
wp_script_modules()->dequeue( $id );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Deregisters the script module.
[130] Fix | Delete
*
[131] Fix | Delete
* @since 6.5.0
[132] Fix | Delete
*
[133] Fix | Delete
* @param string $id The identifier of the script module.
[134] Fix | Delete
*/
[135] Fix | Delete
function wp_deregister_script_module( string $id ) {
[136] Fix | Delete
wp_script_modules()->deregister( $id );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Registers all the default WordPress Script Modules.
[141] Fix | Delete
*
[142] Fix | Delete
* @since 6.7.0
[143] Fix | Delete
*/
[144] Fix | Delete
function wp_default_script_modules() {
[145] Fix | Delete
$suffix = defined( 'WP_RUN_CORE_TESTS' ) ? '.min' : wp_scripts_get_suffix();
[146] Fix | Delete
[147] Fix | Delete
/*
[148] Fix | Delete
* Expects multidimensional array like:
[149] Fix | Delete
*
[150] Fix | Delete
* 'interactivity/index.min.js' => array('dependencies' => array(…), 'version' => '…'),
[151] Fix | Delete
* 'interactivity/debug.min.js' => array('dependencies' => array(…), 'version' => '…'),
[152] Fix | Delete
* 'interactivity-router/index.min.js' => …
[153] Fix | Delete
*/
[154] Fix | Delete
$assets = include ABSPATH . WPINC . "/assets/script-modules-packages{$suffix}.php";
[155] Fix | Delete
[156] Fix | Delete
foreach ( $assets as $file_name => $script_module_data ) {
[157] Fix | Delete
/*
[158] Fix | Delete
* Build the WordPress Script Module ID from the file name.
[159] Fix | Delete
* Prepend `@wordpress/` and remove extensions and `/index` if present:
[160] Fix | Delete
* - interactivity/index.min.js => @wordpress/interactivity
[161] Fix | Delete
* - interactivity/debug.min.js => @wordpress/interactivity/debug
[162] Fix | Delete
* - block-library/query/view.js => @wordpress/block-library/query/view
[163] Fix | Delete
*/
[164] Fix | Delete
$script_module_id = '@wordpress/' . preg_replace( '~(?:/index)?(?:\.min)?\.js$~D', '', $file_name, 1 );
[165] Fix | Delete
[166] Fix | Delete
switch ( $script_module_id ) {
[167] Fix | Delete
/*
[168] Fix | Delete
* Interactivity exposes two entrypoints, "/index" and "/debug".
[169] Fix | Delete
* "/debug" should replace "/index" in development.
[170] Fix | Delete
*/
[171] Fix | Delete
case '@wordpress/interactivity/debug':
[172] Fix | Delete
if ( ! SCRIPT_DEBUG ) {
[173] Fix | Delete
continue 2;
[174] Fix | Delete
}
[175] Fix | Delete
$script_module_id = '@wordpress/interactivity';
[176] Fix | Delete
break;
[177] Fix | Delete
case '@wordpress/interactivity':
[178] Fix | Delete
if ( SCRIPT_DEBUG ) {
[179] Fix | Delete
continue 2;
[180] Fix | Delete
}
[181] Fix | Delete
break;
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
/*
[185] Fix | Delete
* The Interactivity API is designed with server-side rendering as its primary goal, so all of its script modules
[186] Fix | Delete
* should be loaded with low fetchpriority and printed in the footer since they should not be needed in the
[187] Fix | Delete
* critical rendering path. Also, the @wordpress/a11y script module is intended to be used as a dynamic import
[188] Fix | Delete
* dependency, in which case the fetchpriority is irrelevant. See <https://make.wordpress.org/core/2024/10/14/updates-to-script-modules-in-6-7/>.
[189] Fix | Delete
* However, in case it is added as a static import dependency, the fetchpriority is explicitly set to be 'low'
[190] Fix | Delete
* since the module should not be involved in the critical rendering path, and if it is, its fetchpriority will
[191] Fix | Delete
* be bumped to match the fetchpriority of the dependent script.
[192] Fix | Delete
*/
[193] Fix | Delete
$args = array();
[194] Fix | Delete
if (
[195] Fix | Delete
str_starts_with( $script_module_id, '@wordpress/interactivity' ) ||
[196] Fix | Delete
str_starts_with( $script_module_id, '@wordpress/block-library' ) ||
[197] Fix | Delete
'@wordpress/a11y' === $script_module_id
[198] Fix | Delete
) {
[199] Fix | Delete
$args['fetchpriority'] = 'low';
[200] Fix | Delete
$args['in_footer'] = true;
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
// Marks all Core blocks as compatible with client-side navigation.
[204] Fix | Delete
if ( str_starts_with( $script_module_id, '@wordpress/block-library' ) ) {
[205] Fix | Delete
wp_interactivity()->add_client_navigation_support_to_script_module( $script_module_id );
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
$path = includes_url( "js/dist/script-modules/{$file_name}" );
[209] Fix | Delete
wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'], $args );
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function