Automattic\WooCommerce\Blocks\Utils

StyleAttributesUtils::get_spacing_value()public staticWC 1.0

If spacing value is in preset format, convert it to a CSS var. Else return same value For example: "var:preset|spacing|50" -> "var(--wp--preset--spacing--50)" "50px" -> "50px"

Method of the class: StyleAttributesUtils{}

No Hooks.

Return

(String).

Usage

$result = StyleAttributesUtils::get_spacing_value( $spacing_value );
$spacing_value(string) (required)
value to be processed.

StyleAttributesUtils::get_spacing_value() code WC 9.4.2

public static function get_spacing_value( $spacing_value ) {
	// Used following code as reference: https://github.com/WordPress/gutenberg/blob/cff6d70d6ff5a26e212958623dc3130569f95685/lib/block-supports/layout.php/#L219-L225.
	if ( is_string( $spacing_value ) && str_contains( $spacing_value, 'var:preset|spacing|' ) ) {
		$spacing_value = str_replace( 'var:preset|spacing|', '', $spacing_value );
		return sprintf( 'var(--wp--preset--spacing--%s)', $spacing_value );
	}

	return $spacing_value;
}