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.
- 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.
Properties
$empty_block_styles
Default empty styles block structure.
public
static array<string|int, mixed>
$empty_block_styles
= array('css' => '', 'declarations' => array(), 'classnames' => '')
Methods
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. }parse_styles_to_array()
Parse styles string to array.
public
static parse_styles_to_array(string $styles) : array<string|int, mixed>
Parameters
- $styles : string
-
Styles string.
Return values
array<string|int, mixed> —parse_value()
Parse number value from a string.
public
static parse_value(string $value) : float
Parameters
- $value : string
-
String value with value and unit.