wppaste
WordPress

wp_default_styles( WP_Styles $styles )

Since
2.6.0
Source
wp-includes/script-loader.php:1546
Assigns default styles to $styles object.

Description

Nothing is returned, because the $styles parameter is passed by reference.
Meaning that whatever object is passed will be updated without having to reassign the variable that was passed back to the same value. This saves memory.

Adding default styles is not the only task, it also assigns the base_url property, the default version, and text direction for the object.

Compatibility

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

$stylesWP_Styles

Performance profile

How much work a call to wp_default_styles() 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 stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

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

Instructions
459–493

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

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

  • optionoption read or writeget_option()one call below wp_default_styles()
  • hookthird-party callbacksapply_filters()one call below wp_default_styles()

Further down the call graph this can also reach 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 · 4 distinct outcomes

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

WhenInstructionsCalls it makes
defined('SCRIPT_DEBUG') && !defined('WP_CONTENT_URL') && !function_exists() && $font_family === "off"459–471site_url(), get_bloginfo(), function_exists(), _x(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add_data(), _x(), ->add(), ->add(), ->add_data(), ->add(), ->add_data(), ->add(), ->add(), ->add(), wp_theme_has_theme_json(), current_theme_supports(), ->add()
defined('SCRIPT_DEBUG') && !defined('WP_CONTENT_URL') && !function_exists() && $font_family !== "off"464–476site_url(), get_bloginfo(), function_exists(), _x(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add_data(), _x(), urlencode(), ->add(), ->add(), ->add_data(), ->add(), ->add_data(), ->add(), ->add(), ->add(), wp_theme_has_theme_json(), current_theme_supports(), ->add()
defined('SCRIPT_DEBUG') && !defined('WP_CONTENT_URL') && !function_exists() && $subset !== "cyrillic" && $font_family === "off"475–488site_url(), get_bloginfo(), function_exists(), _x(), _x(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add_data(), _x(), ->add(), ->add(), ->add_data(), ->add(), ->add_data(), ->add(), ->add(), ->add(), wp_theme_has_theme_json(), current_theme_supports(), ->add()
defined('SCRIPT_DEBUG') && !defined('WP_CONTENT_URL') && !function_exists() && $subset !== "cyrillic" && $font_family !== "off"480–493site_url(), get_bloginfo(), function_exists(), _x(), _x(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add(), ->add_data(), _x(), urlencode(), ->add(), ->add(), ->add_data(), ->add(), ->add_data(), ->add(), ->add(), ->add(), wp_theme_has_theme_json(), current_theme_supports(), ->add()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev559459–49322
8.5559459–49322
8.4559459–493223 fewer instructions than PHP 8.3
8.3562459–49322
8.2562459–49322
8.1562459–493221 fewer instruction than PHP 7.4
7.4563459–49322

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

Source code

function wp_default_styles( $styles ) {	global $editor_styles; 	/*	 * Include an unmodified $wp_version.	 *	 * Note: wp_get_wp_version() is not used here, as this file can be included	 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case	 * wp-includes/functions.php is not loaded.	 */	require ABSPATH . WPINC . '/version.php'; 	if ( ! defined( 'SCRIPT_DEBUG' ) ) {		/*		 * Note: str_contains() is not used here, as this file can be included		 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case		 * the polyfills from wp-includes/compat.php are not loaded.		 */		define( 'SCRIPT_DEBUG', false !== strpos( $wp_version, '-src' ) );	} 	$guessurl = site_url(); 	if ( ! $guessurl ) {		$guessurl = wp_guess_url();	} 	$styles->base_url        = $guessurl;	$styles->content_url     = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';	$styles->default_version = get_bloginfo( 'version' );	$styles->text_direction  = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr';	$styles->default_dirs    = array( '/wp-admin/', '/wp-includes/css/' ); 	// Open Sans is no longer used by core, but may be relied upon by themes and plugins.	$open_sans_font_url = ''; 	/*	 * translators: If there are characters in your language that are not supported	 * by Open Sans, translate this to 'off'. Do not translate into your own language.	 */	if ( 'off' !== _x( 'on', 'Open Sans font: on or off' ) ) {		$subsets = 'latin,latin-ext'; 		/*		 * translators: To add an additional Open Sans character subset specific to your language,		 * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.		 */		$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)' ); 		if ( 'cyrillic' === $subset ) {			$subsets .= ',cyrillic,cyrillic-ext';		} elseif ( 'greek' === $subset ) {			$subsets .= ',greek,greek-ext';		} elseif ( 'vietnamese' === $subset ) {			$subsets .= ',vietnamese';		} 		// Hotlink Open Sans, for now.		$open_sans_font_url = "https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets&display=fallback";	} 	// Register a stylesheet for the selected admin color scheme.	$styles->add( 'colors', true, array( 'wp-admin', 'buttons' ) ); 	$suffix = SCRIPT_DEBUG ? '' : '.min'; 	// Admin CSS.	$styles->add( 'common', "/wp-admin/css/common$suffix.css" );	$styles->add( 'forms', "/wp-admin/css/forms$suffix.css" );	$styles->add( 'admin-menu', "/wp-admin/css/admin-menu$suffix.css" );	$styles->add( 'dashboard', "/wp-admin/css/dashboard$suffix.css" );	$styles->add( 'list-tables', "/wp-admin/css/list-tables$suffix.css" );	$styles->add( 'edit', "/wp-admin/css/edit$suffix.css" );	$styles->add( 'revisions', "/wp-admin/css/revisions$suffix.css" );	$styles->add( 'media', "/wp-admin/css/media$suffix.css" );	$styles->add( 'themes', "/wp-admin/css/themes$suffix.css" );	$styles->add( 'about', "/wp-admin/css/about$suffix.css" );	$styles->add( 'nav-menus', "/wp-admin/css/nav-menus$suffix.css" );	$styles->add( 'widgets', "/wp-admin/css/widgets$suffix.css", array( 'wp-pointer' ) );	$styles->add( 'site-icon', "/wp-admin/css/site-icon$suffix.css" );

Changelog

Introduced in 2.6.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.