WooCommerce Code Reference

Spacing_Preprocessor
in package
implements Preprocessor

This preprocessor is responsible for setting default spacing values for blocks.

In the early development phase, we are setting only margin-top for blocks that are not first or last in the columns block.

Interfaces, Classes and Traits

Preprocessor
Interface Preprocessor

Table of Contents

CONTAINER_BLOCKS  = array('core/group', 'core/post-content')
Container block names that delegate root padding to their children instead of receiving it themselves.
$post_content_block_names  : array<string|int, mixed>|null
Cached post-content block names to avoid repeated apply_filters calls.
preprocess()  : array<string|int, mixed>
Preprocesses the parsed blocks.
add_block_gaps()  : array<string|int, mixed>
Adds spacing to blocks: margin-top for vertical gaps, horizontal padding for column gaps, and root padding for children of root-level containers.
contains_post_content()  : bool
Checks whether a block contains a core/post-content descendant.
get_block_horizontal_padding()  : array<string|int, mixed>
Extract and validate horizontal padding from a block's style attributes.
get_columns_block_gap()  : string|null
Extracts the horizontal blockGap from a columns block.
get_post_content_block_names()  : array<string|int, string>
Returns the list of block names treated as "post content" for padding delegation.
get_root_padding()  : array<string|int, mixed>
Extracts and sanitizes root horizontal padding from theme styles.
has_explicit_horizontal_padding()  : bool
Checks whether a block explicitly defines any horizontal padding.
has_zero_horizontal_padding()  : bool
Checks whether a block explicitly sets zero horizontal padding.
is_zero_value()  : bool
Checks whether a CSS value is explicitly zero.

Constants

Properties

Methods

preprocess()

Preprocesses the parsed blocks.

public preprocess(array<string|int, mixed> $parsed_blocks, array<string|int, mixed> $layout, array<string|int, mixed> $styles) : array<string|int, mixed>
Parameters
$parsed_blocks : array<string|int, mixed>

Parsed blocks.

$layout : array<string|int, mixed>

Layout.

$styles : array<string|int, mixed>

Styles.

Return values
array<string|int, mixed>

add_block_gaps()

Adds spacing to blocks: margin-top for vertical gaps, horizontal padding for column gaps, and root padding for children of root-level containers.

private add_block_gaps(array<string|int, mixed> $parsed_blocks[, string $gap = '' ][, array<string|int, mixed>|null $parent_block = null ][, array<string|int, mixed> $root_padding = array() ][, bool $apply_root_padding = false ][, array<string|int, mixed> $container_padding = array() ]) : array<string|int, mixed>

Root padding is distributed from the outer email wrapper to individual block wrappers. Container blocks (groups, post-content) at the root level delegate padding to their children instead of taking it themselves. This enables alignfull blocks to skip root padding and span the full email width.

Container padding works similarly: when a template group wrapping post-content has its own horizontal padding, that padding is distributed per-block alongside root padding. Alignfull blocks skip both padding types and span the full contentSize. The template group gets a suppress-horizontal-padding flag so its renderer omits horizontal padding from its own CSS output.

Blocks fall into three categories for root padding:

  • Zero padding (has_zero_padding): skip root padding entirely — edge-to-edge intent.
  • Non-zero explicit padding (has_own_padding, !has_zero_padding): receive root padding on top of their own padding. Their own padding is internal content spacing; root padding ensures inset from the email edge. These blocks also stop delegation.
  • No explicit padding: receive root padding if delegated, or delegate if a container.
Parameters
$parsed_blocks : array<string|int, mixed>

Parsed blocks.

$gap : string = ''

Gap.

$parent_block : array<string|int, mixed>|null = null

Parent block.

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

Root horizontal padding with 'left' and 'right' keys.

$apply_root_padding : bool = false

Whether this block should receive root padding (delegated by parent container).

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

Container horizontal padding with 'left' and 'right' keys.

Return values
array<string|int, mixed>

contains_post_content()

Checks whether a block contains a core/post-content descendant.

private contains_post_content(array<string|int, mixed> $block) : bool

Searches recursively through container blocks (groups) so that deeply nested template structures like group → group → post-content are handled correctly.

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

The block to check.

Return values
boolTrue if the block has a post-content descendant.

get_block_horizontal_padding()

Extract and validate horizontal padding from a block's style attributes.

private get_block_horizontal_padding(array<string|int, mixed> $block) : array<string|int, mixed>
Parameters
$block : array<string|int, mixed>

The block to extract padding from.

Return values
array<string|int, mixed>Padding with 'left' and 'right' keys, or empty array if invalid/absent.

get_columns_block_gap()

Extracts the horizontal blockGap from a columns block.

private get_columns_block_gap(array<string|int, mixed> $columns_block[, string $default_gap = '' ]) : string|null
Parameters
$columns_block : array<string|int, mixed>

The columns block.

$default_gap : string = ''

Default gap value to use if blockGap is not set on the columns block.

Return values
string|nullThe horizontal gap value (e.g., "30px" or "var:preset|spacing|30") or null if not set.

has_explicit_horizontal_padding()

Checks whether a block explicitly defines any horizontal padding.

private has_explicit_horizontal_padding(array<string|int, mixed> $block) : bool

Containers with explicit padding (any value) manage their own layout and should stop delegating root padding to their children.

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

The block to check.

Return values
boolTrue if the block defines horizontal padding.

has_zero_horizontal_padding()

Checks whether a block explicitly sets zero horizontal padding.

private has_zero_horizontal_padding(array<string|int, mixed> $block) : bool

Explicit zero padding (0, 0px, 0em, etc.) signals that the block intentionally wants edge-to-edge layout. Root padding should not be added on top.

Non-zero padding (e.g. 20px) is internal content spacing and does not affect root padding — both can coexist independently.

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

The block to check.

Return values
boolTrue if the block explicitly sets zero horizontal padding.