wppaste
WordPress

wp_default_packages_vendor( WP_Scripts $scripts )

Since
5.0.0
Source
wp-includes/script-loader.php:85
Registers all the WordPress vendor scripts that are in the standardized js/dist/vendor/ location.

Description

For the order of $scripts->add see wp_default_scripts.

Compatibility

WordPress
since 5.0.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.

Parameters

$scriptsWP_Scripts
WP_Scripts object.

Performance profile

How much work a call to wp_default_packages_vendor() 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

Reaches the database via get_user_by().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
16–91

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()one call below wp_default_packages_vendor()
  • querycontent queryget_user_by()one call below wp_default_packages_vendor()
  • cacheobject cachewp_cache_get()one call below wp_default_packages_vendor()
  • serializeserialisationmaybe_unserialize()one call below wp_default_packages_vendor()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 4 distinct outcomes

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

WhenInstructionsCalls it makes
!did_action()16–17wp_scripts_get_suffix(), did_action(), did_action()
always20–21wp_scripts_get_suffix(), did_action(), ->add_inline_script(), did_action()
always86–87wp_scripts_get_suffix(), did_action(), did_action(), get_user_locale(), esc_js(), array_values(), array_values(), array_values(), array_values(), get_option(), __(), get_option(), __(), get_option(), __(), LT(), dow()
did_action()90–91wp_scripts_get_suffix(), did_action(), ->add_inline_script(), did_action(), get_user_locale(), esc_js(), array_values(), array_values(), array_values(), array_values(), get_option(), __(), get_option(), __(), get_option(), __(), LT(), dow()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 111 instructions, 16–91 executed per call, 5 branches. The work does not change between versions.

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 · 7

  • wp_scripts_get_suffix()Returns the suffix that can be used for the scripts.
  • did_action()Retrieves the number of times an action has been fired during the current request.
  • esc_js()Escapes single quotes, `"`, ``, `&`, and fixes line endings.
  • get_user_locale()Retrieves the locale of a user.
  • wp_json_encode()Encodes a variable into JSON, with some confidence checks.
  • get_option()Retrieves an option value based on an option name.
  • __()Retrieves the translation of $text.

Used by · 1

Source code

function wp_default_packages_vendor( $scripts ) {	global $wp_locale; 	$suffix = wp_scripts_get_suffix(); 	$vendor_scripts = array(		'react',		'react-dom'         => array( 'react' ),		'react-jsx-runtime' => array( 'react' ),		'regenerator-runtime',		'moment',		'lodash',		'wp-polyfill-fetch',		'wp-polyfill-formdata',		'wp-polyfill-node-contains',		'wp-polyfill-url',		'wp-polyfill-dom-rect',		'wp-polyfill-element-closest',		'wp-polyfill-object-fit',		'wp-polyfill-inert',		'wp-polyfill',	); 	$vendor_scripts_versions = array(		'react'                       => '18.3.1.1', // Final .1 due to switch to UMD build, can be removed in the next update.		'react-dom'                   => '18.3.1.1', // Final .1 due to switch to UMD build, can be removed in the next update.		'react-jsx-runtime'           => '18.3.1',		'regenerator-runtime'         => '0.14.1',		'moment'                      => '2.30.1',		'lodash'                      => '4.17.21',		'wp-polyfill-fetch'           => '3.6.20',		'wp-polyfill-formdata'        => '4.0.10',		'wp-polyfill-node-contains'   => '4.8.0',		'wp-polyfill-url'             => '3.6.4',		'wp-polyfill-dom-rect'        => '4.8.0',		'wp-polyfill-element-closest' => '3.0.2',		'wp-polyfill-object-fit'      => '2.3.5',		'wp-polyfill-inert'           => '3.1.3',		'wp-polyfill'                 => '3.15.0',	); 	foreach ( $vendor_scripts as $handle => $dependencies ) {		if ( is_string( $dependencies ) ) {			$handle       = $dependencies;			$dependencies = array();		} 		$path    = "/wp-includes/js/dist/vendor/$handle$suffix.js";		$version = $vendor_scripts_versions[ $handle ]; 		$scripts->add( $handle, $path, $dependencies, $version, 1 );	} 	did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' ); 	did_action( 'init' ) && $scripts->add_inline_script(		'moment',		sprintf(			"moment.updateLocale( '%s', %s );",			esc_js( get_user_locale() ),			wp_json_encode(				array(					'months'         => array_values( $wp_locale->month ),					'monthsShort'    => array_values( $wp_locale->month_abbrev ),					'weekdays'       => array_values( $wp_locale->weekday ),					'weekdaysShort'  => array_values( $wp_locale->weekday_abbrev ),					'week'           => array(						'dow' => (int) get_option( 'start_of_week', 0 ),					),					'longDateFormat' => array(						'LT'   => get_option( 'time_format', __( 'g:i a' ) ),						'LTS'  => null,						'L'    => null,						'LL'   => get_option( 'date_format', __( 'F j, Y' ) ),						'LLL'  => __( 'F j, Y g:i a' ),						'LLLL' => null,					),				),				JSON_HEX_TAG | JSON_UNESCAPED_SLASHES			)

Changelog

Introduced in 5.0.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 6.9.7 tag, from src/wp-includes/script-loader.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.