wppaste
WordPress

wp_default_script_modules()

Since
6.7.0
Source
wp-includes/script-modules.php:167
Registers all the default WordPress Script Modules.

Compatibility

WordPress
since 6.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Performance profile

How much work a call to wp_default_script_modules() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads or writes the filesystem via file_exists().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
19–23

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 86.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • filesystemfilesystem accessfile_exists()called directly
  • hookthird-party callbacksapply_filters()one call below wp_default_script_modules()

Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_default_script_modules() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
defined('WP_RUN_CORE_TESTS')19–22file_exists()
!defined('WP_RUN_CORE_TESTS')20–23wp_scripts_get_suffix(), file_exists()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8419–21122 fewer instructions than PHP 8.5
8.58619–2312
8.48619–231218 fewer instructions than PHP 8.3
8.310419–2312
8.210419–2312
8.110419–2312
7.410419–2312

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 6

Source code

function wp_default_script_modules() {	$suffix = defined( 'WP_RUN_CORE_TESTS' ) ? '.min' : wp_scripts_get_suffix(); 	/*	 * Expects multidimensional array like:	 *	 *     'interactivity/index.js' => array('dependencies' => array(…), 'version' => '…'),	 *     'interactivity-router/index.js' => array('dependencies' => array(…), 'version' => '…'),	 *     'block-library/navigation/view.js' => …	 */	$assets_file = ABSPATH . WPINC . '/assets/script-modules-packages.php';	$assets      = file_exists( $assets_file ) ? include $assets_file : array(); 	foreach ( $assets as $file_name => $script_module_data ) {		/*		 * Build the WordPress Script Module ID from the file name.		 * Prepend `@wordpress/` and remove extensions and `/index` if present:		 *   - interactivity/index.min.js         => @wordpress/interactivity		 *   - interactivity-router/index.min.js  => @wordpress/interactivity-router		 *   - block-library/navigation/view.js   => @wordpress/block-library/navigation/view		 */		$script_module_id = '@wordpress/' . preg_replace( '~(?:/index)?(?:\.min)?\.js$~D', '', $file_name, 1 ); 		/*		 * The Interactivity API is designed with server-side rendering as its primary goal, so all of its script modules		 * should be loaded with low fetchpriority and printed in the footer since they should not be needed in the		 * critical rendering path. Also, the @wordpress/a11y script module is intended to be used as a dynamic import		 * dependency, in which case the fetchpriority is irrelevant. See <https://make.wordpress.org/core/2024/10/14/updates-to-script-modules-in-6-7/>.		 * However, in case it is added as a static import dependency, the fetchpriority is explicitly set to be 'low'		 * since the module should not be involved in the critical rendering path, and if it is, its fetchpriority will		 * be bumped to match the fetchpriority of the dependent script.		 */		$args = array();		if (			str_starts_with( $script_module_id, '@wordpress/interactivity' ) ||			str_starts_with( $script_module_id, '@wordpress/block-library' ) ||			'@wordpress/a11y' === $script_module_id		) {			$args['fetchpriority'] = 'low';			$args['in_footer']     = true;		} 		// Marks all Core blocks as compatible with client-side navigation.		if ( str_starts_with( $script_module_id, '@wordpress/block-library' ) ) {			wp_interactivity()->add_client_navigation_support_to_script_module( $script_module_id );		} 		// VIPS files and the video-conversion worker are always minified — the		// non-minified versions are not shipped because they consist of large		// inlined WASM/worker code with no debugging value.		if ( str_starts_with( $file_name, 'vips/' ) || 'video-conversion/worker.js' === $file_name ) {			$file_name = str_replace( '.js', '.min.js', $file_name );		} elseif ( '' !== $suffix ) {			$file_name = str_replace( '.js', $suffix . '.js', $file_name );		} 		$path        = includes_url( "js/dist/script-modules/{$file_name}" );		$module_deps = $script_module_data['module_dependencies'] ?? array();		wp_register_script_module( $script_module_id, $path, $module_deps, $script_module_data['version'], $args );	}}

Changelog

Introduced in 6.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/script-modules.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.