WP_Theme_JSON::get_stylesheet() WordPress Method

The WP_Theme_JSON::get_stylesheet() method is used to get the stylesheet information for a theme. This method is static, so it can be called without an object.

WP_Theme_JSON::get_stylesheet( array $types = array('variables', 'styles', 'presets'), array $origins = null ) #

Returns the stylesheet that results of processing the theme.json structure this object represents.


Parameters

$types

(array)(Optional)Types of styles to load. Will load all by default. It accepts:

  • variables: only the CSS Custom Properties for presets & custom ones.
  • styles: only the styles section in theme.json.
  • presets: only the classes for the presets.

Default value: array('variables', 'styles', 'presets')

$origins

(array)(Optional)A list of origins to include. By default it includes VALID_ORIGINS.

Default value: null


Top ↑

Return

(string) Stylesheet.


Top ↑

Source

File: wp-includes/class-wp-theme-json.php

	public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = null ) {
		if ( null === $origins ) {
			$origins = static::VALID_ORIGINS;
		}

		if ( is_string( $types ) ) {
			// Dispatch error and map old arguments to new ones.
			_deprecated_argument( __FUNCTION__, '5.9.0' );
			if ( 'block_styles' === $types ) {
				$types = array( 'styles', 'presets' );
			} elseif ( 'css_variables' === $types ) {
				$types = array( 'variables' );
			} else {
				$types = array( 'variables', 'styles', 'presets' );
			}
		}

		$blocks_metadata = static::get_blocks_metadata();
		$style_nodes     = static::get_style_nodes( $this->theme_json, $blocks_metadata );
		$setting_nodes   = static::get_setting_nodes( $this->theme_json, $blocks_metadata );

		$stylesheet = '';

		if ( in_array( 'variables', $types, true ) ) {
			$stylesheet .= $this->get_css_variables( $setting_nodes, $origins );
		}

		if ( in_array( 'styles', $types, true ) ) {
			$stylesheet .= $this->get_block_classes( $style_nodes );
		}

		if ( in_array( 'presets', $types, true ) ) {
			$stylesheet .= $this->get_preset_classes( $setting_nodes, $origins );
		}

		return $stylesheet;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Removed the $type parameter, added the$typesand$origins` parameters.
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.