Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors
Spacing_Preprocessor::get_columns_block_gap
Extracts the horizontal blockGap from a columns block.
Method of the class: Spacing_Preprocessor{}
No Hooks.
Returns
String|null. The horizontal gap value (e.g., "30px" or "var:preset|spacing|30") or null if not set.
Usage
// private - for code of main (parent) class only $result = $this->get_columns_block_gap( $columns_block, $default_gap ): ?string;
- $columns_block(array) (required)
- The columns block.
- $default_gap(string)
- Default gap value to use if blockGap is not set on the columns block.
Default:''
Spacing_Preprocessor::get_columns_block_gap() Spacing Preprocessor::get columns block gap code WC 10.8.1
private function get_columns_block_gap( array $columns_block, string $default_gap = '' ): ?string {
$block_gap = $columns_block['attrs']['style']['spacing']['blockGap'] ?? null;
// Columns block uses object format: { "top": "...", "left": "..." }.
// If blockGap.left is explicitly set, use it.
if ( is_array( $block_gap ) && isset( $block_gap['left'] ) && is_string( $block_gap['left'] ) ) {
$gap_value = $block_gap['left'];
// Validate against potentially malicious values.
if ( preg_match( '/[<>"\']/', $gap_value ) ) {
return null;
}
// Return the value as-is. WP's styles engine will handle transformation of preset variables.
return $gap_value;
}
// If blockGap.left is not set, use the default gap value if provided.
if ( $default_gap ) {
return $default_gap;
}
return null;
}