WP_Theme_JSON::convert_variables_to_value( array $styles, array $values ): array

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Replaces CSS variables with their values in place.

Parameters

$stylesarrayrequired
CSS declarations to convert.
$valuesarrayrequired
key => value pairs to use for replacement.

Return

array

Source


/**
 * Checks that a declaration provided by the user is safe.
 *
 * @since 5.9.0
 *
 * @param string $property_name  Property name in a CSS declaration, i.e. the `color` in `color: red`.
 * @param string $property_value Value in a CSS declaration, i.e. the `red` in `color: red`.
 * @return bool
 */
protected static function is_safe_css_declaration( $property_name, $property_value ) {
	$style_to_validate = $property_name . ': ' . $property_value;
	$filtered          = esc_html( safecss_filter_attr( $style_to_validate ) );
	return ! empty( trim( $filtered ) );
}

/**
 * Removes indirect properties from the given input node and
 * sets in the given output node.
 *
 * @since 6.2.0
 *
 * @param array $input  Node to process.
 * @param array $output The processed node. Passed by reference.
 */
private static function remove_indirect_properties( $input, &$output ) {
	foreach ( static::INDIRECT_PROPERTIES_METADATA as $property => $paths ) {
		foreach ( $paths as $path ) {
			$value = _wp_array_get( $input, $path );
			if (
				is_string( $value ) &&
				static::is_safe_css_declaration( $property, $value )
			) {
				_wp_array_set( $output, $path, $value );
			}
		}
	}

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

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