wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_get_global_stylesheet › WordPress Function

Since5.9.0
Deprecatedn/a
wp_get_global_stylesheet ( $types = array() )
Parameters:
  • (array) $types Types of styles to load. Optional. It accepts 'variables', 'styles', 'presets' as values. If empty, it'll load all for themes with theme.json support and only [ 'variables', 'presets' ] for themes without theme.json support.
    Required: No
    Default: array()
Returns:
  • (string) Stylesheet.
Defined at:
Codex:

Returns the stylesheet resulting of merging core, theme, and user data.



Source

function wp_get_global_stylesheet( $types = array() ) {
	// Return cached value if it can be used and exists.
	// It's cached by theme to make sure that theme switching clears the cache.
	$can_use_cached = (
		( empty( $types ) ) &&
		( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) &&
		( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) &&
		( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) &&
		! is_admin()
	);
	$transient_name = 'global_styles_' . get_stylesheet();
	if ( $can_use_cached ) {
		$cached = get_transient( $transient_name );
		if ( $cached ) {
			return $cached;
		}
	}

	$supports_theme_json = WP_Theme_JSON_Resolver::theme_has_support();
	$supports_link_color = get_theme_support( 'experimental-link-color' );
	if ( empty( $types ) && ! $supports_theme_json ) {
		$types = array( 'variables', 'presets' );
	} elseif ( empty( $types ) ) {
		$types = array( 'variables', 'styles', 'presets' );
	}

	$origins = array( 'default', 'theme', 'user' );
	if ( ! $supports_theme_json && ! $supports_link_color ) {
		// In this case we only enqueue the core presets (CSS Custom Properties + the classes).
		$origins = array( 'default' );
	} elseif ( ! $supports_theme_json && $supports_link_color ) {
		// For the legacy link color feature to work, the CSS Custom Properties
		// should be in scope (either the core or the theme ones).
		$origins = array( 'default', 'theme' );
	}

	$tree       = WP_Theme_JSON_Resolver::get_merged_data();
	$stylesheet = $tree->get_stylesheet( $types, $origins );

	if ( $can_use_cached ) {
		// Cache for a minute.
		// This cache doesn't need to be any longer, we only want to avoid spikes on high-traffic sites.
		set_transient( $transient_name, $stylesheet, MINUTE_IN_SECONDS );
	}

	return $stylesheet;
}