W3cubDocs

/WordPress

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

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

Version Description
6.3.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_theme_json/convert_variables_to_value