wppaste
WordPress

wp_get_global_stylesheet( array $types = array() ): string

Since
5.9.0, 6.1.0, 6.6.0, 7.0.0
Source
wp-includes/global-styles-and-settings.php:148
Returns the stylesheet resulting of merging core, theme, and user data.

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

$typesarrayoptional
Types of styles to load.
See 'WP_Theme_JSON::get_stylesheet' for all valid types.
If empty, will load: '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

Only touches the object cache, via wp_cache_get().

Scaling
Constant

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

Instructions
14–68

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

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

What it touches

  • cacheobject cachewp_cache_get()called directly
  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
!empty($types)14wp_cache_get()
empty($types)18wp_is_development_mode(), wp_cache_get()
wp_is_block_theme() && !$types29–30::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme()
!wp_is_block_theme() && !$types32–34::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json()
empty($types) && wp_is_block_theme() && !$types33–34wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme()
wp_is_block_theme() && !$types34–35::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_cache_set()
wp_is_block_theme() && !$types35–36wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme()
!empty($types) && wp_is_block_theme() && !$types36–37::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet()
empty($types) && !wp_is_block_theme() && !$types36–38wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json()
!wp_is_block_theme() && !$types37–39::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), wp_cache_set()
!wp_is_block_theme() && !$types38–40wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json()
empty($types) && wp_is_block_theme() && !$types38–39wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_cache_set()
54 further outcomes, up to 68 instructions
!empty($types) && !wp_is_block_theme() && !$types39–41::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet()
empty($types) && wp_is_block_theme() && !$types39–40wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme()
wp_is_block_theme() && !$types40–41wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_cache_set()
wp_is_block_theme() && !$types40–41wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet()
!empty($types) && wp_is_block_theme() && !$types41–42::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), wp_cache_set()
wp_is_block_theme() && $types41–42::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff()
empty($types) && !wp_is_block_theme() && !$types41–43wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), wp_cache_set()
!empty($types) && wp_is_block_theme() && !$types42–43wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet()
empty($types) && !wp_is_block_theme() && !$types42–44wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json()
!wp_is_block_theme() && !$types43–45wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), wp_cache_set()
!wp_is_block_theme() && !$types43–45wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet()
!empty($types) && !wp_is_block_theme() && !$types44–46::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), wp_cache_set()
!wp_is_block_theme() && $types44–46::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff()
empty($types) && wp_is_block_theme() && !$types44–45wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_cache_set()
!empty($types) && !wp_is_block_theme() && !$types45–47wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet()
wp_is_block_theme() && !$types45–46wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), wp_cache_set()
empty($types) && wp_is_block_theme() && $types45–46wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff()
wp_is_block_theme() && $types46–47::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), wp_cache_set()
wp_is_block_theme() && !$types46–47wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet()
!empty($types) && wp_is_block_theme() && !$types47–48wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), wp_cache_set()
wp_is_block_theme() && $types47–48wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff()
empty($types) && !wp_is_block_theme() && !$types47–49wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), wp_cache_set()
!empty($types) && wp_is_block_theme() && $types48–49::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), ->get_stylesheet()
!wp_is_block_theme() && !$types48–50wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), wp_cache_set()
empty($types) && !wp_is_block_theme() && $types48–50wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff()
!wp_is_block_theme() && $types49–51::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), wp_cache_set()
!wp_is_block_theme() && !$types49–51wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet()
!empty($types) && !wp_is_block_theme() && !$types50–52wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), wp_cache_set()
!wp_is_block_theme() && $types50–52wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff()
empty($types) && wp_is_block_theme() && $types50–51wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), wp_cache_set()
!empty($types) && !wp_is_block_theme() && $types51–53::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet()
wp_is_block_theme() && !$types51–52wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), wp_cache_set()
empty($types) && wp_is_block_theme() && $types51–52wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff()
wp_is_block_theme() && $types52–53wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), wp_cache_set()
wp_is_block_theme() && $types52–53wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), ->get_stylesheet()
!empty($types) && wp_is_block_theme() && $types53–54::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set()
empty($types) && !wp_is_block_theme() && $types53–55wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), wp_cache_set()
!empty($types) && wp_is_block_theme() && $types54–55wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), ->get_stylesheet()
!wp_is_block_theme() && !$types54–56wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), wp_cache_set()
empty($types) && !wp_is_block_theme() && $types54–56wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff()
!wp_is_block_theme() && $types55–57wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), wp_cache_set()
!wp_is_block_theme() && $types55–57wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet()
!empty($types) && !wp_is_block_theme() && $types56–58::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set()
empty($types) && wp_is_block_theme() && $types56–57wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), wp_cache_set()
!empty($types) && !wp_is_block_theme() && $types57–59wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet()
wp_is_block_theme() && $types57–58wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set()
wp_is_block_theme() && $types58–59wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), ->get_stylesheet()
!empty($types) && wp_is_block_theme() && $types59–60wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set()
empty($types) && !wp_is_block_theme() && $types59–61wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), wp_cache_set()
!wp_is_block_theme() && $types60–62wp_is_development_mode(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set()
!wp_is_block_theme() && $types61–63wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet()
!empty($types) && !wp_is_block_theme() && $types62–64wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set()
wp_is_block_theme() && $types63–64wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set()
!wp_is_block_theme() && $types66–68wp_is_development_mode(), wp_cache_get(), ::WP_Theme_JSON_Resolver(), ::WP_Theme_JSON_Resolver(), wp_is_block_theme(), wp_theme_has_theme_json(), ->get_stylesheet(), array_diff(), ->get_stylesheet(), wp_cache_set()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6914–689
8.56914–689
8.46914–6893 fewer instructions than PHP 8.3
8.37214–719
8.27214–719
8.17214–719
7.47214–719

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

Used by · 3

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() ); 	if ( empty( $types ) ) {		$types = array( 'variables', 'styles', 'presets' );	} 	/*	 * Enable base layout styles only mode for classic themes without theme.json.	 * This skips alignment styles that target .wp-site-blocks which is only used by block themes.	 */	$options = array();	if ( ! wp_is_block_theme() && ! wp_theme_has_theme_json() ) {		$options['base_layout_styles'] = true;	} 	/*	 * 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, $options );		$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		 */

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.

7.0.0
Deprecated 'base-layout-styles' type; classic themes now receive full styles with layout-specific alignment rules skipped via base_layout_styles option.from the docblock
6.6.0
Resolves relative paths in theme.json styles to theme absolute paths.from the docblock
6.1.0
Added 'base-layout-styles' support.from the docblock
5.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.