wp_enqueue_stored_styles( $options = array() )
- Since
- 6.1.0
- Source
wp-includes/script-loader.php:3308
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
- Scaling
- Scales with input
- Instructions
- 11–51
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 91.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls it makes |
|---|---|---|
doing_action() | 11–12 | wp_is_block_theme(), doing_action() |
!$is_block_theme | 16 | wp_is_block_theme(), doing_action(), doing_action() |
$is_block_theme && empty($compiled_core_stylesheet) | 28–32 | wp_is_block_theme(), ::WP_Style_Engine_CSS_Rules_Store(), array_keys() |
!doing_action() && empty($compiled_core_stylesheet) | 32–36 | wp_is_block_theme(), doing_action(), ::WP_Style_Engine_CSS_Rules_Store(), array_keys() |
!doing_action() && !$is_block_theme && empty($compiled_core_stylesheet) | 36–40 | wp_is_block_theme(), doing_action(), doing_action(), ::WP_Style_Engine_CSS_Rules_Store(), array_keys() |
$is_block_theme && !empty($compiled_core_stylesheet) | 39–43 | wp_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–47 | wp_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–51 | wp_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 91 | 11–51 | 14 | |
| 8.5 | 91 | 11–51 | 14 | |
| 8.4 | 91 | 11–51 | 14 | |
| 8.3 | 91 | 11–51 | 14 | |
| 8.2 | 91 | 11–51 | 14 | |
| 8.1 | 91 | 11–51 | 14 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 92 | 11–51 | 14 |
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_is_block_theme()Returns whether the active theme is a block-based theme or not.
- doing_action()Returns whether or not an action hook is currently being processed.
- wp_style_engine_get_stylesheet_from_context()Returns compiled CSS from a store, if found.
- wp_register_style()Registers a CSS stylesheet.
- wp_add_inline_style()Adds extra CSS styles to a registered stylesheet.
- wp_enqueue_style()Enqueues a CSS stylesheet.
- WP_Style_Engine_CSS_Rules_Store::get_stores()Gets an array of all available stores.
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.
Signature, return type and hooks compared across 5 parsed releases.
$options retyped from array to untyped.verified against sourceAbout 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.