Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors
Spacing_Preprocessor::get_block_horizontal_padding
Extract and validate horizontal padding from a block's style attributes.
Preset variable references (e.g. "var:preset|spacing|20") are resolved to their pixel values using the variables map when provided.
Method of the class: Spacing_Preprocessor{}
No Hooks.
Returns
Array. Padding with 'left' and 'right' keys, or empty array if invalid/absent.
Usage
// private - for code of main (parent) class only $result = $this->get_block_horizontal_padding( $block, $variables_map ): array;
- $block(array) (required)
- The block to extract padding from.
- $variables_map(array)
- Map of CSS variable names to resolved values.
Default:array()
Spacing_Preprocessor::get_block_horizontal_padding() Spacing Preprocessor::get block horizontal padding code WC 10.8.1
private function get_block_horizontal_padding( array $block, array $variables_map = array() ): array {
$padding = $block['attrs']['style']['spacing']['padding'] ?? array();
$has_left = isset( $padding['left'] );
$has_right = isset( $padding['right'] );
if ( ! $has_left && ! $has_right ) {
return array();
}
$left = $has_left ? $padding['left'] : '0px';
$right = $has_right ? $padding['right'] : '0px';
if ( ! is_string( $left ) || ! is_string( $right ) || preg_match( '/[<>"\']/', $left . $right ) ) {
return array();
}
// Resolve preset variable references (e.g. "var:preset|spacing|20")
// to their pixel values so downstream consumers get usable CSS values.
$left = Preset_Variable_Resolver::resolve( $left, $variables_map );
$right = Preset_Variable_Resolver::resolve( $right, $variables_map );
if ( $this->is_zero_value( $left ) && $this->is_zero_value( $right ) ) {
return array();
}
return array(
'left' => $left,
'right' => $right,
);
}