WooCommerce Code Reference

StyleAttributesUtils
in package

StyleAttributesUtils class used for getting class and style from attributes.

Table of Contents

EMPTY_STYLE  = ['class' => '', 'style' => '', 'value' => '']
get_align_class_and_style()  : array<string|int, mixed>
Get class and style for align from attributes.
get_background_color_class_and_style()  : array<string|int, mixed>
Get class and style for background-color from attributes.
get_border_color_class_and_style()  : array<string|int, mixed>
Get class and style for border-color from attributes.
get_border_radius_class_and_style()  : array<string|int, mixed>
Get class and style for border-radius from attributes.
get_border_style_class_and_style()  : array<string|int, mixed>
Get class and style for border width from attributes.
get_border_width_class_and_style()  : array<string|int, mixed>
Get class and style for border width from attributes.
get_classes_and_styles_by_attributes()  : array<string|int, mixed>
Get classes and styles from attributes.
get_classes_by_attributes()  : string
Get space-separated classes from block attributes.
get_color_value()  : string
If color value is in preset format, convert it to a CSS var. Else return same value For example: "var:preset|color|pale-pink" -> "var(--wp--preset--color--pale-pink)" "#98b66e" -> "#98b66e"
get_font_family_class_and_style()  : array<string|int, mixed>
Get class and style for font-family from attributes.
get_font_size_class_and_style()  : array<string|int, mixed>
Get class and style for font-size from attributes.
get_font_style_class_and_style()  : array<string|int, mixed>
Get class and style for font-style from attributes.
get_font_weight_class_and_style()  : array<string|int, mixed>
Get class and style for font-weight from attributes.
get_letter_spacing_class_and_style()  : array<string|int, mixed>
Get class and style for letter-spacing from attributes.
get_line_height_class_and_style()  : array<string|int, mixed>
Get class and style for line height from attributes.
get_link_color_class_and_style()  : array<string|int, mixed>
Get class and style for link-color from attributes.
get_link_hover_color_class_and_style()  : array<string|int, mixed>
Get class and style for link-hover-color from attributes.
get_margin_class_and_style()  : array<string|int, mixed>
Get class and style for margin from attributes.
get_padding_class_and_style()  : array<string|int, mixed>
Get class and style for padding from attributes.
get_preset_value()  : string
Get CSS value for color preset.
get_spacing_value()  : string
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"
get_styles_by_attributes()  : string
Get space-separated style rules from block attributes.
get_text_align_class_and_style()  : array<string|int, mixed>
Get class and style for text align from attributes.
get_text_color_class_and_style()  : array<string|int, mixed>
Get class and style for text-color from attributes.
get_text_decoration_class_and_style()  : array<string|int, mixed>
Get class and style for text-decoration from attributes.
get_text_transform_class_and_style()  : array<string|int, mixed>
Get class and style for text-transform from attributes.
array_get_value_by_path()  : mixed
Get a value from an array based on a path e.g style.elements.link
join_styles()  : array<string|int, mixed>
Join classes and styles while removing duplicates and null values.

Constants

Methods

get_align_class_and_style()

Get class and style for align from attributes.

public static get_align_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_background_color_class_and_style()

Get class and style for background-color from attributes.

public static get_background_color_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_border_color_class_and_style()

Get class and style for border-color from attributes.

public static get_border_color_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>

Data passed to this function is not always consistent. It can be: Linked - preset color: $attributes['borderColor'] => 'luminous-vivid-orange'. Linked - custom color: $attributes['style']['border']['color'] => '#681228'. Unlinked - preset color: $attributes['style']['border']['top']['color'] => 'var:preset|color|luminous-vivid-orange' Unlinked - custom color: $attributes['style']['border']['top']['color'] => '#681228'.

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

Block attributes.

Return values
array<string|int, mixed>

get_border_radius_class_and_style()

Get class and style for border-radius from attributes.

public static get_border_radius_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_border_style_class_and_style()

Get class and style for border width from attributes.

public static get_border_style_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_border_width_class_and_style()

Get class and style for border width from attributes.

public static get_border_width_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_classes_and_styles_by_attributes()

Get classes and styles from attributes.

public static get_classes_and_styles_by_attributes(array<string|int, mixed> $attributes[, array<string|int, mixed> $properties = array() ][, array<string|int, mixed> $exclude = array() ]) : array<string|int, mixed>

Excludes link_color and link_hover_color since those should not apply to the container.

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

Block attributes.

$properties : array<string|int, mixed> = array()

Properties to get classes/styles from.

$exclude : array<string|int, mixed> = array()

Properties to exclude.

Return values
array<string|int, mixed>

get_classes_by_attributes()

Get space-separated classes from block attributes.

public static get_classes_by_attributes(array<string|int, mixed> $attributes[, array<string|int, mixed> $properties = array() ]) : string
Parameters
$attributes : array<string|int, mixed>

Block attributes.

$properties : array<string|int, mixed> = array()

Properties to get classes from.

Return values
stringSpace-separated classes.

get_color_value()

If color value is in preset format, convert it to a CSS var. Else return same value For example: "var:preset|color|pale-pink" -> "var(--wp--preset--color--pale-pink)" "#98b66e" -> "#98b66e"

public static get_color_value(string $color_value) : string
Parameters
$color_value : string

value to be processed.

Return values
string

get_font_family_class_and_style()

Get class and style for font-family from attributes.

public static get_font_family_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_font_size_class_and_style()

Get class and style for font-size from attributes.

public static get_font_size_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_font_style_class_and_style()

Get class and style for font-style from attributes.

public static get_font_style_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_font_weight_class_and_style()

Get class and style for font-weight from attributes.

public static get_font_weight_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_letter_spacing_class_and_style()

Get class and style for letter-spacing from attributes.

public static get_letter_spacing_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_line_height_class_and_style()

Get class and style for line height from attributes.

public static get_line_height_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

Get class and style for link-color from attributes.

public static get_link_color_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

Get class and style for link-hover-color from attributes.

public static get_link_hover_color_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_margin_class_and_style()

Get class and style for margin from attributes.

public static get_margin_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_padding_class_and_style()

Get class and style for padding from attributes.

public static get_padding_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_preset_value()

Get CSS value for color preset.

public static get_preset_value(string $preset_name) : string
Parameters
$preset_name : string

Preset name.

Return values
stringCSS value for color preset.

get_spacing_value()

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"

public static get_spacing_value(string $spacing_value) : string
Parameters
$spacing_value : string

value to be processed.

Return values
string

get_styles_by_attributes()

Get space-separated style rules from block attributes.

public static get_styles_by_attributes(array<string|int, mixed> $attributes[, array<string|int, mixed> $properties = array() ]) : string
Parameters
$attributes : array<string|int, mixed>

Block attributes.

$properties : array<string|int, mixed> = array()

Properties to get styles from.

Return values
stringSpace-separated style rules.

get_text_align_class_and_style()

Get class and style for text align from attributes.

public static get_text_align_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_text_color_class_and_style()

Get class and style for text-color from attributes.

public static get_text_color_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_text_decoration_class_and_style()

Get class and style for text-decoration from attributes.

public static get_text_decoration_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

get_text_transform_class_and_style()

Get class and style for text-transform from attributes.

public static get_text_transform_class_and_style(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Block attributes.

Return values
array<string|int, mixed>

array_get_value_by_path()

Get a value from an array based on a path e.g style.elements.link

protected static array_get_value_by_path(array<string|int, mixed> &$array, string $path[, string $delimiter = '.' ]) : mixed
Parameters
$array : array<string|int, mixed>

Target array.

$path : string

Path joined by delimiter.

$delimiter : string = '.'

Chosen delimiter defaults to ".".

Return values
mixed

join_styles()

Join classes and styles while removing duplicates and null values.

protected static join_styles(array<string|int, mixed> $rules) : array<string|int, mixed>
Parameters
$rules : array<string|int, mixed>

Array of classes or styles.

Return values
array<string|int, mixed>