WP_Theme_JSON::get_css_variables()protectedWP 5.8.0

Converts each styles section into a list of rulesets to be appended to the stylesheet. 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;
}

Метод класса: WP_Theme_JSON{}

Хуков нет.

Возвращает

Строку. The new stylesheet.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_css_variables( $nodes, $origins );
$nodes(массив) (обязательный)
Nodes with settings.
$origins(string[]) (обязательный)
List of origins to process.

Список изменений

С версии 5.8.0 Введена.
С версии 5.9.0 Added the $origins parameter.

Код WP_Theme_JSON::get_css_variables() WP 6.5.2

protected function get_css_variables( $nodes, $origins ) {
	$stylesheet = '';
	foreach ( $nodes as $metadata ) {
		if ( null === $metadata['selector'] ) {
			continue;
		}

		$selector = $metadata['selector'];

		$node                    = _wp_array_get( $this->theme_json, $metadata['path'], array() );
		$declarations            = static::compute_preset_vars( $node, $origins );
		$theme_vars_declarations = static::compute_theme_vars( $node );
		foreach ( $theme_vars_declarations as $theme_vars_declaration ) {
			$declarations[] = $theme_vars_declaration;
		}

		$stylesheet .= static::to_ruleset( $selector, $declarations );
	}

	return $stylesheet;
}