WooCommerce Code Reference

Gallery extends Abstract_Block_Renderer
in package

Gallery block renderer.

This renderer handles core/gallery blocks with proper email-friendly HTML layout.

Table of Contents

render()  : string
Render the block.
add_spacer()  : string
Add a spacer around the block.
compile_css()  : string
Compile objects containing CSS properties to a string.
get_styles_from_block()  : array<string|int, mixed>
Wrapper for wp_style_engine_get_styles which ensures all values are returned.
render_content()  : string
Renders the gallery block content using a table-based layout.
build_email_layout()  : string
Build the email-friendly layout for gallery blocks.
build_gallery_row_table()  : string
Build a single gallery row as a separate table (following tiled gallery pattern).
build_gallery_table()  : string
Build the gallery table structure with proper rows and cells.
extract_gallery_caption()  : string
Extract gallery-level caption from the original block content.
extract_image_from_html()  : string
Extract and sanitize image with optional link and caption from HTML content.
extract_images_from_gallery_content()  : array<string|int, mixed>
Extract all images from gallery content with their links and captions.
get_columns_from_attributes()  : int
Get the columns value from block attributes.

Methods

get_styles_from_block()

Wrapper for wp_style_engine_get_styles which ensures all values are returned.

protected 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>

build_email_layout()

Build the email-friendly layout for gallery blocks.

private build_email_layout(array<string|int, mixed> $gallery_images, array<string|int, mixed> $parsed_block, string $block_content, Rendering_Context $rendering_context) : string
Parameters
$gallery_images : array<string|int, mixed>

Array of image HTML strings.

$parsed_block : array<string|int, mixed>

Full parsed block data.

$block_content : string

Original block content.

$rendering_context : Rendering_Context

Rendering context.

Return values
stringRendered HTML.

Build a single gallery row as a separate table (following tiled gallery pattern).

private build_gallery_row_table(array<string|int, mixed> $row_images, int $total_columns, int $cell_padding) : string
Parameters
$row_images : array<string|int, mixed>

Images for this row.

$total_columns : int

Total number of columns.

$cell_padding : int

Cell padding.

Return values
stringRow table HTML.

Build the gallery table structure with proper rows and cells.

private build_gallery_table(array<string|int, mixed> $gallery_images, int $columns) : string

Uses the tiled gallery pattern: separate tables for each row, then wrap in main table.

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

Array of image HTML strings.

$columns : int

Number of columns.

Return values
stringGallery table HTML.

extract_image_from_html()

Extract and sanitize image with optional link and caption from HTML content.

private extract_image_from_html(string $html_content) : string

This is the unified method that handles all image extraction scenarios.

Parameters
$html_content : string

HTML content containing the image.

Return values
stringSanitized image HTML with proper link and caption handling.

Extract all images from gallery content with their links and captions.

private extract_images_from_gallery_content(string $block_content, array<string|int, mixed> $parsed_block) : array<string|int, mixed>
Parameters
$block_content : string

The rendered gallery block HTML.

$parsed_block : array<string|int, mixed>

The parsed block data.

Return values
array<string|int, mixed>Array of sanitized image HTML strings.