WP_Theme_JSON::get_css_variables( array $nodes, string[] $origins ): string

In this article

Converts each styles section into a list of rulesets to be appended to the stylesheet.

Description

These rulesets contain all the css variables (custom variables and preset variables).

See glossary at https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax

For each section this creates a new ruleset such as:

block-selector {
  --wp--preset--category--slug: value;
  --wp--custom--variable: value;
}

Parameters

$nodesarrayrequired
Nodes with settings.
$originsstring[]required
List of origins to process.

Return

string The new stylesheet.

Source


// Output base styles.
if (
	static::ROOT_BLOCK_SELECTOR === $selector
) {
	$valid_display_modes = array( 'block', 'flex', 'grid' );
	foreach ( $layout_definitions as $layout_definition ) {
		$class_name       = isset( $layout_definition['className'] ) ? $layout_definition['className'] : false;
		$base_style_rules = isset( $layout_definition['baseStyles'] ) ? $layout_definition['baseStyles'] : array();

		if (
			! empty( $class_name ) &&
			is_array( $base_style_rules )
		) {
			// Output display mode. This requires special handling as `display` is not exposed in `safe_style_css_filter`.
			if (
				! empty( $layout_definition['displayMode'] ) &&
				is_string( $layout_definition['displayMode'] ) &&
				in_array( $layout_definition['displayMode'], $valid_display_modes, true )
			) {
				$layout_selector = sprintf(

Changelog

VersionDescription
5.9.0Added the $origins parameter.
5.8.0Introduced.

User Contributed Notes

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