WP_Theme_JSON::resolve_variables()public staticWP 6.3.0

Resolves the values of CSS variables in the given styles.

Method of the class: WP_Theme_JSON{}

No Hooks.

Return

WP_Theme_JSON. The $theme_json with resolved variables.

Usage

$result = WP_Theme_JSON::resolve_variables( $theme_json );
$theme_json(WP_Theme_JSON) (required)
The theme json resolver.

Changelog

Since 6.3.0 Introduced.

WP_Theme_JSON::resolve_variables() code WP 6.6.2

public static function resolve_variables( $theme_json ) {
	$settings    = $theme_json->get_settings();
	$styles      = $theme_json->get_raw_data()['styles'];
	$preset_vars = static::compute_preset_vars( $settings, static::VALID_ORIGINS );
	$theme_vars  = static::compute_theme_vars( $settings );
	$vars        = array_reduce(
		array_merge( $preset_vars, $theme_vars ),
		function ( $carry, $item ) {
			$name                    = $item['name'];
			$carry[ "var({$name})" ] = $item['value'];
			return $carry;
		},
		array()
	);

	$theme_json->theme_json['styles'] = self::convert_variables_to_value( $styles, $vars );
	return $theme_json;
}