wp_get_global_stylesheet( array $types = array() ): string
- Since
- 5.9.0, 6.1.0, 6.6.0
- Source
wp-includes/global-styles-and-settings.php:151
Compatibility
- WordPress
- since 6.6.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
$typesarrayoptional- Types of styles to load.
See 'WP_Theme_JSON::get_stylesheet' for all valid types.
If empty, it'll load the following:
- for themes without theme.json: 'variables', 'presets', 'base-layout-styles'.
- for themes with theme.json: 'variables', 'presets', 'styles'.Default:array()
Return value
string- Stylesheet.
Performance profile
How much work a call to wp_get_global_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
- Constant
- Instructions
- 14–79
- Plugin surface
- None
- Called by
- 3
Only touches the object cache, via wp_cache_get().
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 84.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_get()called directly - hookthird-party callbacks
apply_filters()one call below wp_get_global_stylesheet()
Further down the call graph this can also reach option, serialize, transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 66 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_global_stylesheet() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($types) | 14 | wp_cache_get() |
empty($types) | 18 | wp_is_development_mode(), wp_cache_get() |
!$types | 30–32 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json() |
empty($types) && !$types | 34–36 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json() |
!$types | 35–37 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), wp_cache_set() |
!$types | 36–38 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json() |
!empty($types) && !$types | 37–39 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet() |
empty($types) && !$types | 39–41 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), wp_cache_set() |
empty($types) && !$types | 40–42 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json() |
$types | 41–43 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff() |
!$types | 41–43 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), wp_cache_set() |
!$types | 41–43 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet() |
54 further outcomes, up to 79 instructions
!empty($types) && !$types | 42–44 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), wp_cache_set() |
!empty($types) && !$types | 43–45 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet() |
empty($types) && $types | 45–47 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff() |
empty($types) && !$types | 45–47 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), wp_cache_set() |
!empty($types) && !$types | 46–49 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
$types | 46–48 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), wp_cache_set() |
!$types | 46–48 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), wp_cache_set() |
$types | 47–49 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff() |
!$types | 47–49 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet() |
!empty($types) && $types | 48–50 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet() |
!empty($types) && !$types | 48–50 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), wp_cache_set() |
!empty($types) && !$types | 50–53 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!$types | 50–53 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
empty($types) && $types | 50–52 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), wp_cache_set() |
!empty($types) && !$types | 51–54 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
empty($types) && $types | 51–53 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff() |
!empty($types) && !$types | 52–55 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
$types | 52–54 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), wp_cache_set() |
$types | 52–54 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet() |
!$types | 52–54 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), wp_cache_set() |
!empty($types) && $types | 53–55 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set() |
!empty($types) && $types | 54–56 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet() |
!$types | 54–57 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!empty($types) && !$types | 55–58 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
!$types | 55–58 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
!empty($types) && !$types | 56–59 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!$types | 56–59 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
empty($types) && $types | 56–58 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), wp_cache_set() |
!empty($types) && $types | 57–60 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!empty($types) && !$types | 57–60 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
$types | 57–59 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set() |
$types | 58–60 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet() |
!empty($types) && $types | 59–61 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set() |
!$types | 59–62 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
!$types | 60–63 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!empty($types) && $types | 61–64 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!empty($types) && !$types | 61–64 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
$types | 61–64 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!$types | 61–64 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
!empty($types) && $types | 62–65 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
!empty($types) && $types | 63–66 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
$types | 63–65 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set() |
$types | 65–68 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!$types | 65–68 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
!empty($types) && $types | 66–69 | ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
$types | 66–69 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
!empty($types) && $types | 67–70 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
$types | 67–70 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!empty($types) && $types | 68–71 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
$types | 70–73 | wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
$types | 71–74 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet() |
!empty($types) && $types | 72–75 | wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
$types | 72–75 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
$types | 76–79 | wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), current_theme_supports(), current_theme_supports(), current_theme_supports(), ->get_stylesheet(), wp_cache_set() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 84 | 14–79 | 14 | |
| 8.5 | 84 | 14–79 | 14 | |
| 8.4 | 84 | 14–79 | 14 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 87 | 14–82 | 14 | |
| 8.2 | 87 | 14–82 | 14 | |
| 8.1 | 87 | 14–82 | 14 | |
| 7.4 | 87 | 14–82 | 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_development_mode()Checks whether the site is in the given development mode.
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- wp_theme_has_theme_json()Checks whether a theme or its parent has a theme.json file.
- current_theme_supports()Checks a theme's support for a given feature.
- wp_cache_set()Saves the data to the cache.
- WP_Theme_JSON_Resolver::resolve_theme_file_uris()Resolves relative paths in theme.json styles to theme absolute paths and merges them with incoming theme JSON.
- WP_Theme_JSON_Resolver::get_merged_data()Returns the data merged from multiple origins.
Used by · 3
- get_block_editor_settings()Returns the contextualized block editor settings for a selected editor context.
- wp_enqueue_global_styles()Enqueues the global styles defined via theme.json.
- wp_enqueue_global_styles_css_custom_properties()Function that enqueues the CSS Custom Properties coming from theme.json.
Source code
function wp_get_global_stylesheet( $types = array() ) { /* * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme * developer's workflow. */ $can_use_cached = empty( $types ) && ! wp_is_development_mode( 'theme' ); /* * By using the 'theme_json' group, this data is marked to be non-persistent across requests. * @see `wp_cache_add_non_persistent_groups()`. * * The rationale for this is to make sure derived data from theme.json * is always fresh from the potential modifications done via hooks * that can use dynamic data (modify the stylesheet depending on some option, * settings depending on user permissions, etc.). * See some of the existing hooks to modify theme.json behavior: * @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/ * * A different alternative considered was to invalidate the cache upon certain * events such as options add/update/delete, user meta, etc. * It was judged not enough, hence this approach. * @see https://github.com/WordPress/gutenberg/pull/45372 */ $cache_group = 'theme_json'; $cache_key = 'wp_get_global_stylesheet'; if ( $can_use_cached ) { $cached = wp_cache_get( $cache_key, $cache_group ); if ( $cached ) { return $cached; } } $tree = WP_Theme_JSON_Resolver::resolve_theme_file_uris( WP_Theme_JSON_Resolver::get_merged_data() ); $supports_theme_json = wp_theme_has_theme_json(); if ( empty( $types ) && ! $supports_theme_json ) { $types = array( 'variables', 'presets', 'base-layout-styles' ); } elseif ( empty( $types ) ) { $types = array( 'variables', 'styles', 'presets' ); } /* * If variables are part of the stylesheet, then add them. * This is so themes without a theme.json still work as before 5.9: * they can override the default presets. * See https://core.trac.wordpress.org/ticket/54782 */ $styles_variables = ''; if ( in_array( 'variables', $types, true ) ) { /* * Only use the default, theme, and custom origins. Why? * Because styles for `blocks` origin are added at a later phase * (i.e. in the render cycle). Here, only the ones in use are rendered. * @see wp_add_global_styles_for_blocks */ $origins = array( 'default', 'theme', 'custom' ); $styles_variables = $tree->get_stylesheet( array( 'variables' ), $origins ); $types = array_diff( $types, array( 'variables' ) ); } /* * For the remaining types (presets, styles), we do consider origins: * * - themes without theme.json: only the classes for the presets defined by core * - themes with theme.json: the presets and styles classes, both from core and the theme */ $styles_rest = ''; if ( ! empty( $types ) ) { /* * Only use the default, theme, and custom origins. Why? * Because styles for `blocks` origin are added at a later phase * (i.e. in the render cycle). Here, only the ones in use are rendered. * @see wp_add_global_styles_for_blocks */ $origins = array( 'default', 'theme', 'custom' ); /* * If the theme doesn't have theme.json but supports both appearance tools and color palette, * the 'theme' origin should be included so color palette presets are also output. */ if ( ! $supports_theme_json && ( current_theme_supports( 'appearance-tools' ) || current_theme_supports( 'border' ) ) && current_theme_supports( 'editor-color-palette' ) ) {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.
About 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.