WP_Theme_JSON::convert_custom_properties()private staticWP 6.3.0

This is used to convert the internal representation of variables to the CSS representation. For example, var:preset|color|vivid-green-cyan becomes var(--wp--preset--color--vivid-green-cyan).

Method of the class: WP_Theme_JSON{}

No Hooks.

Return

String. The converted variable.

Usage

$result = WP_Theme_JSON::convert_custom_properties( $value );
$value(string) (required)
The variable such as var:preset|color|vivid-green-cyan to convert.

Changelog

Since 6.3.0 Introduced.

WP_Theme_JSON::convert_custom_properties() code WP 6.6.2

private static function convert_custom_properties( $value ) {
	$prefix     = 'var:';
	$prefix_len = strlen( $prefix );
	$token_in   = '|';
	$token_out  = '--';
	if ( str_starts_with( $value, $prefix ) ) {
		$unwrapped_name = str_replace(
			$token_in,
			$token_out,
			substr( $value, $prefix_len )
		);
		$value          = "var(--wp--$unwrapped_name)";
	}

	return $value;
}