wp_default_script_modules()
- Since
- 6.7.0
- Source
wp-includes/script-modules.php:167
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
- Scaling
- Scales with input
- Instructions
- 19–23
- Plugin surface
- None
- Called by
- 0
Reads or writes the filesystem via file_exists().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 86.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- filesystemfilesystem access
file_exists()called directly - hookthird-party callbacks
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
defined('WP_RUN_CORE_TESTS') | 19–22 | file_exists() |
!defined('WP_RUN_CORE_TESTS') | 20–23 | wp_scripts_get_suffix(), file_exists() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 84 | 19–21 | 12 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 86 | 19–23 | 12 | |
| 8.4 | 86 | 19–23 | 12 | 18 fewer instructions than PHP 8.3 |
| 8.3 | 104 | 19–23 | 12 | |
| 8.2 | 104 | 19–23 | 12 | |
| 8.1 | 104 | 19–23 | 12 | |
| 7.4 | 104 | 19–23 | 12 |
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
- wp_scripts_get_suffix()Returns the suffix that can be used for the scripts.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- wp_interactivity()Retrieves the main WP_Interactivity_API instance.
- includes_url()Retrieves the URL to the includes directory.
- wp_register_script_module()Registers the script module if no script module with that script module identifier has already been registered.
- wp_interactivity()::add_client_navigation_support_to_script_module()
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.
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.