WP_Theme_JSON::get_stylesheet( string[] $types = array('variables', 'styles', 'presets'), string[] $origins = null, array $options = array() ): string
- Since
- 5.8.0, 5.9.0, 6.3.0, 6.6.0, 7.0.0
- Source
wp-includes/class-wp-theme-json.php:1968
Compatibility
- WordPress
- since 7.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
$typesstring[]optional- Types of styles to load. Will load all by default. It accepts:
-variables: only the CSS Custom Properties for presets & custom ones.
-styles: only the styles section in theme.json.
-presets: only the classes for the presets.
-base-layout-styles: only the base layout styles. Deprecated in 7.0.0.
-custom-css: only the custom CSS.Default:array('variables', 'styles', 'presets') $originsstring[]optional- A list of origins to include. By default it includes VALID_ORIGINS.Default:
null $optionsarrayoptional- An array of options for now used for internal purposes only (may change without notice).Default:
array()$scopestringdefault: falseMakes sure all style are scoped to a given selector @type string $root_selector Overwrites and forces a given selector to be used on the root node @type bool $skip_root_layout_styles Omits root layout styles from the generated stylesheet.$base_layout_stylesbooldefault: falseWhen true generates only base layout styles without alignment rules.$include_block_style_variationsbooldefault: falseIncludes styles for block style variations in the generated stylesheet.
Return value
string- The resulting stylesheet.
Performance profile
How much work a call to WP_Theme_JSON::get_stylesheet() 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
- 65–130
- 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 153.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below WP_Theme_JSON::get_stylesheet()
Further down the call graph this can also reach query, option, cache, serialize 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 · 48 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme_JSON::get_stylesheet() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_string($types) && !$types | 65–85 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search() |
!is_string($types) | 70–90 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_preset_classes() |
!is_string($types) | 70–90 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables() |
!is_string($types) | 71–93 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_block_classes() |
!is_string($types) | 72–92 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), _wp_array_get() |
$origins !== null && is_string($types) && !$types | 73–94 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search() |
!is_string($types) | 75–95 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_preset_classes() |
!is_string($types) | 76–98 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_block_classes(), ->get_preset_classes() |
!is_string($types) | 76–98 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_block_classes() |
!is_string($types) | 77–97 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_preset_classes(), _wp_array_get() |
!is_string($types) | 77–97 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), _wp_array_get() |
!is_string($types) | 78–100 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_block_classes(), _wp_array_get() |
36 further outcomes, up to 130 instructions
$origins !== null && is_string($types) | 78–99 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_preset_classes() |
$origins !== null && is_string($types) | 78–99 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables() |
$origins !== null && is_string($types) | 79–102 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_block_classes() |
$origins !== null && is_string($types) | 80–101 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), _wp_array_get() |
!is_string($types) | 81–103 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_block_classes(), ->get_preset_classes() |
!is_string($types) | 82–102 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_preset_classes(), _wp_array_get() |
!is_string($types) | 83–105 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_block_classes(), ->get_preset_classes(), _wp_array_get() |
!is_string($types) | 83–105 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_block_classes(), _wp_array_get() |
$origins !== null && is_string($types) | 83–104 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_preset_classes() |
!is_string($types) && empty($options) && $root_style_key !== false | 84–104 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_root_layout_rules(), ->get_block_classes() |
$origins !== null && is_string($types) | 84–107 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_block_classes(), ->get_preset_classes() |
$origins !== null && is_string($types) | 84–107 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_block_classes() |
$origins !== null && is_string($types) | 85–106 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_preset_classes(), _wp_array_get() |
$origins !== null && is_string($types) | 85–106 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), _wp_array_get() |
$origins !== null && is_string($types) | 86–109 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_block_classes(), _wp_array_get() |
!is_string($types) && $types | 88–110 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_block_classes(), ->get_preset_classes(), _wp_array_get() |
!is_string($types) && empty($options) && $root_style_key !== false | 89–109 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_root_layout_rules(), ->get_block_classes(), ->get_preset_classes() |
!is_string($types) && empty($options) && $root_style_key !== false | 89–109 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_root_layout_rules(), ->get_block_classes() |
$origins !== null && is_string($types) | 89–112 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_block_classes(), ->get_preset_classes() |
$origins !== null && is_string($types) | 90–111 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_preset_classes(), _wp_array_get() |
!is_string($types) && empty($options) && $root_style_key !== false | 91–111 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_root_layout_rules(), ->get_block_classes(), _wp_array_get() |
$origins !== null && is_string($types) | 91–114 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_block_classes(), ->get_preset_classes(), _wp_array_get() |
$origins !== null && is_string($types) | 91–114 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_block_classes(), _wp_array_get() |
$origins !== null && is_string($types) && empty($options) && $root_style_key !== false | 92–113 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_root_layout_rules(), ->get_block_classes() |
!is_string($types) && empty($options) && $root_style_key !== false | 94–114 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_root_layout_rules(), ->get_block_classes(), ->get_preset_classes() |
!is_string($types) && empty($options) && $root_style_key !== false | 96–116 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_root_layout_rules(), ->get_block_classes(), ->get_preset_classes(), _wp_array_get() |
!is_string($types) && empty($options) && $root_style_key !== false | 96–116 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_root_layout_rules(), ->get_block_classes(), _wp_array_get() |
$origins !== null && is_string($types) && $types | 96–119 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_block_classes(), ->get_preset_classes(), _wp_array_get() |
$origins !== null && is_string($types) && empty($options) && $root_style_key !== false | 97–118 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_root_layout_rules(), ->get_block_classes(), ->get_preset_classes() |
$origins !== null && is_string($types) && empty($options) && $root_style_key !== false | 97–118 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_root_layout_rules(), ->get_block_classes() |
$origins !== null && is_string($types) && empty($options) && $root_style_key !== false | 99–120 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_root_layout_rules(), ->get_block_classes(), _wp_array_get() |
!is_string($types) && empty($options) && $types && $root_style_key !== false | 101–121 | ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_root_layout_rules(), ->get_block_classes(), ->get_preset_classes(), _wp_array_get() |
$origins !== null && is_string($types) && empty($options) && $root_style_key !== false | 102–123 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_root_layout_rules(), ->get_block_classes(), ->get_preset_classes() |
$origins !== null && is_string($types) && empty($options) && $root_style_key !== false | 104–125 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_root_layout_rules(), ->get_block_classes(), ->get_preset_classes(), _wp_array_get() |
$origins !== null && is_string($types) && empty($options) && $root_style_key !== false | 104–125 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_root_layout_rules(), ->get_block_classes(), _wp_array_get() |
$origins !== null && is_string($types) && empty($options) && $types && $root_style_key !== false | 109–130 | _deprecated_argument(), ::get_blocks_metadata(), ::get_style_nodes(), ::get_setting_nodes(), array_column(), array_search(), array_column(), array_search(), ->get_css_variables(), ->get_root_layout_rules(), ->get_block_classes(), ->get_preset_classes(), _wp_array_get() |
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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 153 | 65–130 | 18 | |
| 8.5 | 153 | 65–130 | 18 | |
| 8.4 | 153 | 65–130 | 18 | 12 fewer instructions than PHP 8.3 |
| 8.3 | 165 | 77–142 | 18 | |
| 8.2 | 165 | 77–142 | 18 | |
| 8.1 | 165 | 77–142 | 18 | |
| 7.4 | 165 | 77–142 | 18 |
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 · 11
- _deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
- _wp_array_get()Accesses an array in depth based on a path of keys.
- static::get_blocks_metadata()
- static::get_style_nodes()
- static::get_setting_nodes()
- static::scope_selector()
- static::scope_style_node_selectors()
- WP_Theme_JSON::get_css_variables()Converts each styles section into a list of rulesets to be appended to the stylesheet.
- WP_Theme_JSON::get_root_layout_rules()Outputs the CSS for layout rules on the root.
- WP_Theme_JSON::get_block_classes()Converts each style section into a list of rulesets containing the block styles to be appended to the stylesheet.
- WP_Theme_JSON::get_preset_classes()Creates new rulesets as classes for each preset value such as:
Source code
public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = null, $options = array() ) { if ( null === $origins ) { $origins = static::VALID_ORIGINS; } if ( is_string( $types ) ) { // Dispatch error and map old arguments to new ones. _deprecated_argument( __FUNCTION__, '5.9.0' ); if ( 'block_styles' === $types ) { $types = array( 'styles', 'presets' ); } elseif ( 'css_variables' === $types ) { $types = array( 'variables' ); } else { $types = array( 'variables', 'styles', 'presets' ); } } $blocks_metadata = static::get_blocks_metadata(); $style_nodes = static::get_style_nodes( $this->theme_json, $blocks_metadata, $options ); $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata ); $root_style_key = array_search( static::ROOT_BLOCK_SELECTOR, array_column( $style_nodes, 'selector' ), true ); $root_settings_key = array_search( static::ROOT_BLOCK_SELECTOR, array_column( $setting_nodes, 'selector' ), true ); if ( ! empty( $options['scope'] ) ) { foreach ( $setting_nodes as &$node ) { $node['selector'] = static::scope_selector( $options['scope'], $node['selector'] ); } foreach ( $style_nodes as &$node ) { $node = static::scope_style_node_selectors( $options['scope'], $node ); } unset( $node ); } if ( ! empty( $options['root_selector'] ) ) { if ( false !== $root_settings_key ) { $setting_nodes[ $root_settings_key ]['selector'] = $options['root_selector']; } if ( false !== $root_style_key ) { $style_nodes[ $root_style_key ]['selector'] = $options['root_selector']; } } $stylesheet = ''; if ( in_array( 'variables', $types, true ) ) { $stylesheet .= $this->get_css_variables( $setting_nodes, $origins ); } if ( in_array( 'styles', $types, true ) ) { if ( false !== $root_style_key && empty( $options['skip_root_layout_styles'] ) ) { $stylesheet .= $this->get_root_layout_rules( $style_nodes[ $root_style_key ]['selector'], $style_nodes[ $root_style_key ], $options ); } $stylesheet .= $this->get_block_classes( $style_nodes ); } if ( in_array( 'presets', $types, true ) ) { $stylesheet .= $this->get_preset_classes( $setting_nodes, $origins ); } // Load the custom CSS last so it has the highest specificity. if ( in_array( 'custom-css', $types, true ) ) { // Add the global styles root CSS. $stylesheet .= _wp_array_get( $this->theme_json, array( 'styles', 'css' ) ); } return $stylesheet; }Changelog
Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
base_layout_styles option for classic themes.from the docblockskip_root_layout_styles and include_block_style_variations options to control styles output as desired.from the docblock$type parameter, added the $types and $origins parameters.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-theme-json.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.