wp_default_packages_inline_scripts( WP_Scripts $scripts )
- Since
- 5.0.0, 6.4.0
- Source
wp-includes/script-loader.php:341
Compatibility
- WordPress
- since 6.4.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_inline_scripts() 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
- Constant
- Instructions
- 243–262
- Plugin surface
- None
- Called by
- 1
Reaches the database via get_user_by().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 264.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()one call below wp_default_packages_inline_scripts() - cacheobject cache
wp_cache_get()one call below wp_default_packages_inline_scripts() - serializeserialisation
maybe_unserialize()one call below wp_default_packages_inline_scripts() - querycontent query
get_user_by()one call below wp_default_packages_inline_scripts()
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_inline_scripts() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
wp_installing() && empty($timezone_string) | 243–248 | get_rest_url(), sanitize_url(), ->add_inline_script(), wp_installing(), admin_url(), ->get_blog_prefix(), get_current_user_id(), get_user_meta(), wp_json_encode(), sprintf(), ->add_inline_script(), get_current_user_id(), ( function() {(), get_option(), get_option(), get_user_locale(), array_values(), array_values(), array_values(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_option(), __(), get_option(), __(), get_option(), __(), __(), offset(), time(), ->add_inline_script(), ->add_inline_script() |
!wp_installing() && empty($timezone_string) | 245–250 | get_rest_url(), sanitize_url(), ->add_inline_script(), wp_installing(), wp_create_nonce(), admin_url(), ->get_blog_prefix(), get_current_user_id(), get_user_meta(), wp_json_encode(), sprintf(), ->add_inline_script(), get_current_user_id(), ( function() {(), get_option(), get_option(), get_user_locale(), array_values(), array_values(), array_values(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_option(), __(), get_option(), __(), get_option(), __(), __(), offset(), time(), ->add_inline_script(), ->add_inline_script() |
wp_installing() && !empty($timezone_string) | 255–260 | get_rest_url(), sanitize_url(), ->add_inline_script(), wp_installing(), admin_url(), ->get_blog_prefix(), get_current_user_id(), get_user_meta(), wp_json_encode(), sprintf(), ->add_inline_script(), get_current_user_id(), ( function() {(), get_option(), ->add_inline_script(), ->add_inline_script(), ->format(), get_option(), get_user_locale(), array_values(), array_values(), array_values(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_option(), __(), get_option(), __(), get_option(), __(), __(), offset(), time(), ->add_inline_script(), ->add_inline_script() |
!wp_installing() && !empty($timezone_string) | 257–262 | get_rest_url(), sanitize_url(), ->add_inline_script(), wp_installing(), wp_create_nonce(), admin_url(), ->get_blog_prefix(), get_current_user_id(), get_user_meta(), wp_json_encode(), sprintf(), ->add_inline_script(), get_current_user_id(), ( function() {(), get_option(), ->add_inline_script(), ->add_inline_script(), ->format(), get_option(), get_user_locale(), array_values(), array_values(), array_values(), array_values(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), get_option(), __(), get_option(), __(), get_option(), __(), __(), offset(), time(), ->add_inline_script(), ->add_inline_script() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 263 | 243–261 | 3 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 264 | 243–262 | 3 | |
| 8.4 | 264 | 243–262 | 3 | 13 fewer instructions than PHP 8.3 |
| 8.3 | 277 | 256–275 | 3 | |
| 8.2 | 277 | 256–275 | 3 | |
| 8.1 | 277 | 256–275 | 3 | |
| 7.4 | 277 | 256–275 | 3 |
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 · 13
- sanitize_url()Sanitizes a URL for database or redirect usage.
- get_rest_url()Retrieves the URL to a REST endpoint on a site.
- wp_installing()Checks or sets whether WordPress is in "installation" mode.
- wp_create_nonce()Creates a cryptographic token tied to a specific action, user, user session, and window of time.
- admin_url()Retrieves the URL to the admin area for the current site.
- get_current_user_id()Gets the current user's ID.
- get_user_meta()Retrieves user meta field for 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.
- get_user_locale()Retrieves the locale of a user.
- __()Retrieves the translation of $text.
- DateTime::__construct()
Show all 13
- DateTimeZone::__construct()
Used by · 1
- wp_default_packages()Registers all the WordPress packages scripts.
Source code
function wp_default_packages_inline_scripts( $scripts ) { global $wp_locale, $wpdb; if ( isset( $scripts->registered['wp-api-fetch'] ) ) { $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks'; } $scripts->add_inline_script( 'wp-api-fetch', sprintf( 'wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', sanitize_url( get_rest_url() ) ), 'after' ); $scripts->add_inline_script( 'wp-api-fetch', implode( "\n", array( sprintf( 'wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', wp_installing() ? '' : wp_create_nonce( 'wp_rest' ) ), 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', sprintf( 'wp.apiFetch.nonceEndpoint = "%s";', admin_url( 'admin-ajax.php?action=rest-nonce' ) ), ) ), 'after' ); $meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences'; $user_id = get_current_user_id(); $preload_data = get_user_meta( $user_id, $meta_key, true ); $scripts->add_inline_script( 'wp-preferences', sprintf( '( function() { var serverData = %s; var userId = "%d"; var persistenceLayer = wp.preferencesPersistence.__unstableCreatePersistenceLayer( serverData, userId ); var preferencesStore = wp.preferences.store; wp.data.dispatch( preferencesStore ).setPersistenceLayer( persistenceLayer ); } ) ();', wp_json_encode( $preload_data, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), $user_id ) ); // Backwards compatibility - configure the old wp-data persistence system. $scripts->add_inline_script( 'wp-data', implode( "\n", array( '( function() {', ' var userId = ' . get_current_user_id() . ';', ' var storageKey = "WP_DATA_USER_" + userId;', ' wp.data', ' .use( wp.data.plugins.persistence, { storageKey: storageKey } );', '} )();', ) ) ); // Calculate the timezone abbr (EDT, PST) if possible. $timezone_string = get_option( 'timezone_string', 'UTC' ); $timezone_abbr = ''; if ( ! empty( $timezone_string ) ) { $timezone_date = new DateTime( 'now', new DateTimeZone( $timezone_string ) ); $timezone_abbr = $timezone_date->format( 'T' ); } $gmt_offset = get_option( 'gmt_offset', 0 ); $scripts->add_inline_script(Changelog
Introduced in 5.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
wp-date inline script output.from the docblockAbout 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.