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

	// Add the global styles root CSS.
	$stylesheet = isset( $this->theme_json['styles']['css'] ) ? $this->theme_json['styles']['css'] : '';

	// Add the global styles block CSS.
	if ( isset( $this->theme_json['styles']['blocks'] ) ) {
		foreach ( $this->theme_json['styles']['blocks'] as $name => $node ) {
			$custom_block_css = isset( $this->theme_json['styles']['blocks'][ $name ]['css'] )
				? $this->theme_json['styles']['blocks'][ $name ]['css']
				: null;
			if ( $custom_block_css ) {
				$selector    = static::$blocks_metadata[ $name ]['selector'];
				$stylesheet .= $this->process_blocks_custom_css( $custom_block_css, $selector );
			}
		}
	}

	return $stylesheet;
}

/**
 * Returns the page templates of the active theme.

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.