WooCommerce Code Reference

Preset_Variable_Resolver
in package

Resolves WordPress preset variable references to their actual values.

Block attributes store spacing values as preset references like "var:preset|spacing|20". This class provides shared methods to:

  • Convert these references to CSS variable names (--wp--preset--spacing--20)
  • Resolve them to pixel values (e.g. "20px") using a variables map
  • Convert them to CSS var() syntax for stylesheet use

Used by Content_Renderer, Spacing_Preprocessor, and Blocks_Width_Preprocessor to avoid duplicating the same resolution logic.

Table of Contents

is_preset_reference()  : bool
Check if a value is a preset variable reference.
resolve()  : string
Resolve a preset variable reference to its actual value.
to_css_var()  : string
Convert a preset variable reference to CSS var() syntax.
to_css_variable_name()  : string
Convert a preset variable reference to its CSS variable name.

Methods

resolve()

Resolve a preset variable reference to its actual value.

public static resolve(string $value, array<string|int, mixed> $variables_map) : string

Converts "var:preset|spacing|20" to the resolved pixel value (e.g. "20px") using the provided variables map. Returns the original value if not a preset reference or if the variable is not found in the map.

Parameters
$value : string

The CSS value, possibly a preset reference.

$variables_map : array<string|int, mixed>

Map of CSS variable names to resolved values.

Return values
stringThe resolved value or the original value.

to_css_var()

Convert a preset variable reference to CSS var() syntax.

public static to_css_var(string $value) : string

Transforms "var:preset|spacing|20" to "var(--wp--preset--spacing--20)". Returns the original value if not a preset reference.

Parameters
$value : string

The CSS value, possibly a preset reference.

Return values
stringThe CSS var() expression or the original value.