wppaste
WordPress

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
Returns the stylesheet that results of processing the theme.json structure this object represents.

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: false

    Makes 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: false

    When true generates only base layout styles without alignment rules.
  • $include_block_style_variationsbooldefault: false

    Includes 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

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
65–130

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

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

  • hookthird-party callbacksdo_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.

WhenInstructionsCalls it makes
!is_string($types) && !$types65–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) && !$types73–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 !== false84–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) && $types88–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 !== false89–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 !== false89–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 !== false91–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 !== false92–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 !== false94–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 !== false96–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 !== false96–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) && $types96–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 !== false97–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 !== false97–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 !== false99–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 !== false101–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 !== false102–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 !== false104–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 !== false104–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 !== false109–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

PHPCompiledExecutedBranchesNotes
8.6-dev15365–13018
8.515365–13018
8.415365–1301812 fewer instructions than PHP 8.3
8.316577–14218
8.216577–14218
8.116577–14218
7.416577–14218

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

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.

  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.0
Deprecated 'base-layout-styles' type; added base_layout_styles option for classic themes.from the docblock
6.6.0
Added boolean skip_root_layout_styles and include_block_style_variations options to control styles output as desired.from the docblock
6.3.0
Add fallback layout styles for Post Template when block gap support isn't available.from the docblock
5.9.0
Removed the $type parameter, added the $types and $origins parameters.from the docblock
5.8.0
Introduced.from the docblock

About 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.