wppaste
WordPress

wp_enqueue_stored_styles( $options = array() )

Since
6.1.0
Source
wp-includes/script-loader.php:3308
Fetches, processes and compiles stored core styles, then combines and renders them to the page.

Description

Styles are stored via the style engine API.

Compatibility

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

$optionsoptional
Default: array()

Performance profile

How much work a call to wp_enqueue_stored_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
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
11–51

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

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 one call costs · 8 distinct outcomes

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

WhenInstructionsCalls it makes
doing_action()11–12wp_is_block_theme(), doing_action()
!$is_block_theme16wp_is_block_theme(), doing_action(), doing_action()
$is_block_theme && empty($compiled_core_stylesheet)28–32wp_is_block_theme(), ::WP_Style_Engine_CSS_Rules_Store(), array_keys()
!doing_action() && empty($compiled_core_stylesheet)32–36wp_is_block_theme(), doing_action(), ::WP_Style_Engine_CSS_Rules_Store(), array_keys()
!doing_action() && !$is_block_theme && empty($compiled_core_stylesheet)36–40wp_is_block_theme(), doing_action(), doing_action(), ::WP_Style_Engine_CSS_Rules_Store(), array_keys()
$is_block_theme && !empty($compiled_core_stylesheet)39–43wp_is_block_theme(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), ::WP_Style_Engine_CSS_Rules_Store(), array_keys()
!doing_action() && !empty($compiled_core_stylesheet)43–47wp_is_block_theme(), doing_action(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), ::WP_Style_Engine_CSS_Rules_Store(), array_keys()
!doing_action() && !$is_block_theme && !empty($compiled_core_stylesheet)47–51wp_is_block_theme(), doing_action(), doing_action(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), ::WP_Style_Engine_CSS_Rules_Store(), array_keys()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev9111–5114
8.59111–5114
8.49111–5114
8.39111–5114
8.29111–5114
8.19111–51141 fewer instruction than PHP 7.4
7.49211–5114

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

Source code

function wp_enqueue_stored_styles( $options = array() ) {	// Note: Styles printed at wp_footer for classic themes may still end up in the head due to wp_load_classic_theme_block_styles_on_demand().	$is_block_theme   = wp_is_block_theme();	$is_classic_theme = ! $is_block_theme; 	/*	 * For block themes, this function prints stored styles in the header.	 * For classic themes, in the footer.	 */	if (		( $is_block_theme && doing_action( 'wp_footer' ) ) ||		( $is_classic_theme && doing_action( 'wp_enqueue_scripts' ) )	) {		return;	} 	$core_styles_keys         = array( 'block-supports' );	$compiled_core_stylesheet = '';	$style_tag_id             = 'core';	// Adds comment if code is prettified to identify core styles sections in debugging.	$should_prettify = isset( $options['prettify'] ) ? true === $options['prettify'] : defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;	foreach ( $core_styles_keys as $style_key ) {		if ( $should_prettify ) {			$compiled_core_stylesheet .= "/**\n * Core styles: $style_key\n */\n";		}		// Chains core store ids to signify what the styles contain.		$style_tag_id             .= '-' . $style_key;		$compiled_core_stylesheet .= wp_style_engine_get_stylesheet_from_context( $style_key, $options );	} 	// Combines Core styles.	if ( ! empty( $compiled_core_stylesheet ) ) {		wp_register_style( $style_tag_id, false );		wp_add_inline_style( $style_tag_id, $compiled_core_stylesheet );		wp_enqueue_style( $style_tag_id );	} 	// Prints out any other stores registered by themes or otherwise.	$additional_stores = WP_Style_Engine_CSS_Rules_Store::get_stores();	foreach ( array_keys( $additional_stores ) as $store_name ) {		if ( in_array( $store_name, $core_styles_keys, true ) ) {			continue;		}		$styles = wp_style_engine_get_stylesheet_from_context( $store_name, $options );		if ( ! empty( $styles ) ) {			$key = "wp-style-engine-$store_name";			wp_register_style( $key, false );			wp_add_inline_style( $key, $styles );			wp_enqueue_style( $key );		}	}}

Changelog

Introduced in 6.1.0. One change between 6.7.7 and 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.

7.0.4
Parameter $options retyped from array to untyped.verified against source
6.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 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.