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
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_namestringWhich block to retrieve the styles from. If empty, it'll return the styles for the global context.$originstringWhich 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.$transformsarrayWhich 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
- Scaling
- Constant
- Instructions
- 24–47
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 47.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls 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–43 | blocks(), ::WP_Theme_JSON_Resolver(), ->get_raw_data(), _wp_array_get() |
!empty($context) | 36–47 | blocks(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON(), ->get_raw_data(), _wp_array_get() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 47 | 24–47 | 6 | |
| 8.5 | 47 | 24–47 | 6 | |
| 8.4 | 47 | 24–47 | 6 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 50 | 24–50 | 6 | |
| 8.2 | 50 | 24–50 | 6 | |
| 8.1 | 50 | 24–50 | 6 | |
| 7.4 | 50 | 24–50 | 6 |
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
- _wp_array_get()Accesses an array in depth based on a path of keys.
- WP_Theme_JSON_Resolver::get_merged_data()Returns the data merged from multiple origins.
- WP_Theme_JSON::resolve_variables()Resolves the values of CSS variables in the given styles.
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.
Signature, return type and hooks compared across 5 parsed releases.
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 docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.