wppaste
WordPress

wp_get_global_styles( array $path = array(), array $context = array() ): mixed

Since
5.9.0, 6.3.0, 6.3.0
Source
wp-includes/global-styles-and-settings.php:114
Gets the styles resulting of merging core, theme, and user data.

Compatibility

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

$patharrayoptional
Path to the specific style to retrieve. Optional.
If empty, will return all styles.Default: array()
$contextarrayoptional
Metadata to know where to retrieve the $path from. Optional.Default: array()
  • $block_namestring

    Which block to retrieve the styles from. If empty, it'll return the styles for the global context.
  • $originstring

    Which origin to take data from. Valid values are 'all' (core, theme, and user) or 'base' (core and theme). If empty or unknown, 'all' is used.
  • $transformsarray

    Which transformation(s) to apply. Valid value is array( 'resolve-variables' ). If defined, variables are resolved to their value in the styles.

Return value

mixed
The styles array or individual style value to retrieve.

Performance profile

How much work a call to wp_get_global_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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
24–47

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

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_get_global_styles() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($context)24–35::WP_Theme_JSON_Resolver(), ->get_raw_data(), _wp_array_get()
empty($context)28–39::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON(), ->get_raw_data(), _wp_array_get()
!empty($context)32–43blocks(), ::WP_Theme_JSON_Resolver(), ->get_raw_data(), _wp_array_get()
!empty($context)36–47blocks(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON(), ->get_raw_data(), _wp_array_get()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev4724–476
8.54724–476
8.44724–4763 fewer instructions than PHP 8.3
8.35024–506
8.25024–506
8.15024–506
7.45024–506

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

Used by · 1

Source code

function wp_get_global_styles( $path = array(), $context = array() ) {	if ( ! empty( $context['block_name'] ) ) {		$path = array_merge( array( 'blocks', $context['block_name'] ), $path );	} 	$origin = 'custom';	if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) {		$origin = 'theme';	} 	$resolve_variables = isset( $context['transforms'] )	&& is_array( $context['transforms'] )	&& in_array( 'resolve-variables', $context['transforms'], true ); 	$merged_data = WP_Theme_JSON_Resolver::get_merged_data( $origin );	if ( $resolve_variables ) {		$merged_data = WP_Theme_JSON::resolve_variables( $merged_data );	}	$styles = $merged_data->get_raw_data()['styles'];	return _wp_array_get( $styles, $path, $styles );}

Changelog

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

6.3.0
transforms is now usable in the context parameter. In case [transforms]['resolve_variables'] is defined, variables are resolved to their value in the styles.from the docblock
6.3.0
the internal link format "var:preset|color|secondary" is resolved to "var(--wp--preset--font-size--small)" so consumers don't have to.from the docblock
5.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/global-styles-and-settings.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.