WP_Theme_JSON::get_stylesheet( string[] $types = array(‘variables’, ‘styles’, ‘presets’), string[] $origins = null, array $options = array() ): string

In this article

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

Parameters

$typesstring[]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:array('variables', 'styles', 'presets')

$originsstring[]optional
A list of origins to include. By default it includes VALID_ORIGINS.

Default:null

$optionsarrayoptional
An array of options for now used for internal purposes only (may change without notice).
The options currently supported are 'scope' that makes sure all style are scoped to a given selector, and root_selector which overwrites and forces a given selector to be used on the root node.

Default:array()

Return

string The resulting stylesheet.

Source

		if ( null !== $duotone_selector ) {
			static::$blocks_metadata[ $block_name ]['duotone'] = $duotone_selector;
		}

		// If the block has style variations, append their selectors to the block metadata.
		if ( ! empty( $block_type->styles ) ) {
			$style_selectors = array();
			foreach ( $block_type->styles as $style ) {
				$style_selectors[ $style['name'] ] = static::get_block_style_variation_selector( $style['name'], static::$blocks_metadata[ $block_name ]['selector'] );
			}
			static::$blocks_metadata[ $block_name ]['styleVariations'] = $style_selectors;
		}
	}

	return static::$blocks_metadata;
}

/**
 * Given a tree, removes the keys that are not present in the schema.
 *
 * It is recursive and modifies the input in-place.
 *
 * @since 5.8.0
 *
 * @param array $tree   Input to process.
 * @param array $schema Schema to adhere to.
 * @return array The modified $tree.
 */
protected static function remove_keys_not_in_schema( $tree, $schema ) {
	if ( ! is_array( $tree ) ) {
		return $tree;
	}

	foreach ( $tree as $key => $value ) {
		// Remove keys not in the schema or with null/empty values.
		if ( ! array_key_exists( $key, $schema ) ) {
			unset( $tree[ $key ] );
			continue;
		}

		if ( is_array( $schema[ $key ] ) ) {
			if ( ! is_array( $value ) ) {
				unset( $tree[ $key ] );
			} elseif ( wp_is_numeric_array( $value ) ) {
				// If indexed, process each item in the array.
				foreach ( $value as $item_key => $item_value ) {
					if ( isset( $schema[ $key ][0] ) && is_array( $schema[ $key ][0] ) ) {
						$tree[ $key ][ $item_key ] = self::remove_keys_not_in_schema( $item_value, $schema[ $key ][0] );
					} else {
						// If the schema does not define a further structure, keep the value as is.
						$tree[ $key ][ $item_key ] = $item_value;
					}
				}
			} else {
				// If associative, process as a single object.
				$tree[ $key ] = self::remove_keys_not_in_schema( $value, $schema[ $key ] );

				if ( empty( $tree[ $key ] ) ) {
					unset( $tree[ $key ] );
				}
			}
		}
	}
	return $tree;
}

/**
 * Returns the existing settings for each block.
 *
 * Example:
 *
 *     {
 *       'root': {
 *         'color': {
 *           'custom': true
 *         }
 *       },
 *       'core/paragraph': {
 *         'spacing': {
 *           'customPadding': true
 *         }
 *       }
 *     }
 *
 * @since 5.8.0
 *
 * @return array Settings per block.
 */
public function get_settings() {
	if ( ! isset( $this->theme_json['settings'] ) ) {
		return array();
	} else {
		return $this->theme_json['settings'];
	}
}

/**

Changelog

VersionDescription
6.3.0Add fallback layout styles for Post Template when block gap support isn’t available.
5.9.0Removed the $type parameter, added the $types and $origins parameters.
5.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.