WooCommerce Code Reference

Styles_Helper
in package

This class should guarantee that our work with the DOMDocument is unified and safe.

Table of Contents

$empty_block_styles  : array<string|int, mixed>
Default empty styles block structure.
clamp_to_static_px()  : string|null
Convert a CSS clamp() value to a static px value for email clients.
convert_to_px()  : string|null
Convert a CSS value to a static px value for email clients.
extend_block_styles()  : array<string|int, mixed>
Extend block styles with CSS declarations.
get_block_styles()  : array<string|int, mixed>
Get block styles.
get_normalized_block_styles()  : array<string|int, mixed>
Get normalized block styles by translating color slugs to actual color values.
get_styles_from_block()  : array<string|int, mixed>
Wrapper for wp_style_engine_get_styles which ensures all values are returned.
parse_styles_to_array()  : array<string|int, mixed>
Parse styles string to array.
parse_value()  : float
Parse number value from a string.
remove_css_unit()  : string
Remove the CSS unit from a string.

Properties

Methods

clamp_to_static_px()

Convert a CSS clamp() value to a static px value for email clients.

public static clamp_to_static_px(string $clamp_str[, string $strategy = 'min' ]) : string|null
Parameters
$clamp_str : string

The clamp() CSS string (e.g., "clamp(30px, 5vw, 50px)").

$strategy : string = 'min'

"min"|"max"|"avg" — which strategy to use.

Return values
string|nullThe static pixel value (e.g., 30px).

convert_to_px()

Convert a CSS value to a static px value for email clients.

public static convert_to_px(string $input[, bool $use_fallback = true ][, int|null $base_font_size = 16 ]) : string|null

This is mostly for use in font size, spacing, etc.

Parameters
$input : string

The CSS value to convert.

$use_fallback : bool = true

Whether to use the fallback value if the input is not a valid CSS value.

$base_font_size : int|null = 16

The base font size to use for conversion.

Return values
string|nullThe static pixel value (e.g., 30px).

extend_block_styles()

Extend block styles with CSS declarations.

public static extend_block_styles(array<string|int, mixed> $block_styles, array<string|int, mixed> $css_declarations) : array<string|int, mixed>
Parameters
$block_styles : array<string|int, mixed>

WP_Style_Engine styles array (must contain 'declarations' and 'css' keys).

$css_declarations : array<string|int, mixed>

An associative array of CSS definitions, e.g. array( "$property" => "$value", "$property" => "$value" ).

Return values
array<string|int, mixed>{ @type string $css A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag. @type string[] $declarations An associative array of CSS definitions, e.g. `array( "$property" => "$value", "$property" => "$value" )`. @type string $classnames Classnames separated by a space. }

get_block_styles()

Get block styles.

public static get_block_styles(array<string|int, mixed> $block_attributes, Rendering_Context $rendering_context, array<string|int, mixed> $properties) : array<string|int, mixed>
Parameters
$block_attributes : array<string|int, mixed>

Block attributes.

$rendering_context : Rendering_Context

Rendering context.

$properties : array<string|int, mixed>

List of style properties to include. Supported values: 'spacing', 'padding', 'margin', 'border', 'border-width', 'border-style', 'border-radius', 'border-color', 'background', 'background-color', 'color', 'typography', 'font-size', 'font-family', 'font-weight', 'text-align'.

Return values
array<string|int, mixed>{ @type string $css A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag. @type string[] $declarations An associative array of CSS definitions, e.g. `array( "$property" => "$value", "$property" => "$value" )`. @type string $classnames Classnames separated by a space. }

get_normalized_block_styles()

Get normalized block styles by translating color slugs to actual color values.

public static get_normalized_block_styles(array<string|int, mixed> $block_attributes, Rendering_Context $rendering_context) : array<string|int, mixed>

This method handles the normalization of color-related attributes like backgroundColor, textColor, borderColor, and linkColor by translating them from slugs to actual color values using the rendering context.

Parameters
$block_attributes : array<string|int, mixed>

Block attributes containing color slugs.

$rendering_context : Rendering_Context

Rendering context for color translation.

Return values
array<string|int, mixed>Normalized block styles with translated color values.

get_styles_from_block()

Wrapper for wp_style_engine_get_styles which ensures all values are returned.

public static get_styles_from_block(array<string|int, mixed> $block_styles[, bool $skip_convert_vars = false ]) : array<string|int, mixed>
Parameters
$block_styles : array<string|int, mixed>

Array of block styles.

$skip_convert_vars : bool = false

If true, --wp_preset--spacing--x type values will be left in the original var:preset:spacing:x format.

Return values
array<string|int, mixed>{ @type string $css A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag. @type string[] $declarations An associative array of CSS definitions, e.g. `array( "$property" => "$value", "$property" => "$value" )`. @type string $classnames Classnames separated by a space. }