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_inner_content() : string
- Extract inner content from a wrapper element.
- 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
render()
Render the block.
public
render(string $block_content, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string
Parameters
- $block_content : string
-
The block content.
- $parsed_block : array<string|int, mixed>
-
The parsed block.
- $rendering_context : Rendering_Context
-
The rendering context.
Return values
string —add_spacer()
Add a spacer around the block.
protected
add_spacer(string $content, array<string|int, mixed> $email_attrs) : string
Parameters
- $content : string
-
The block content.
- $email_attrs : array<string|int, mixed>
-
The email attributes.
Return values
string —compile_css()
Compile objects containing CSS properties to a string.
protected
compile_css(array<string|int, mixed> ...$styles) : string
Parameters
- $styles : array<string|int, mixed>
-
Style arrays to compile.
Return values
string —get_inner_content()
Extract inner content from a wrapper element.
protected
get_inner_content(string $block_content[, string $tag_name = 'div' ]) : string
Removes the outer wrapper element (e.g., div) and returns only the inner HTML content. This is useful when you need to strip the wrapper and use only the inner content.
Parameters
- $block_content : string
-
Block content with wrapper element.
- $tag_name : string = 'div'
-
Tag name of the wrapper element (default: 'div').
Return values
string — Inner content without the wrapper element, or original content if wrapper not found.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> —render_content()
Renders the gallery block content using a table-based layout.
protected
render_content(string $block_content, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string
Parameters
- $block_content : string
-
Block content.
- $parsed_block : array<string|int, mixed>
-
Parsed block.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
string —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
string — Rendered HTML.build_gallery_row_table()
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
string — Row table HTML.build_gallery_table()
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
string — Gallery table HTML.extract_gallery_caption()
Extract gallery-level caption from the original block content.
private
extract_gallery_caption(string $block_content) : string
Parameters
- $block_content : string
-
Original block content.
Return values
string — Gallery caption or empty string if not found.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
string — Sanitized image HTML with proper link and caption handling.extract_images_from_gallery_content()
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.get_columns_from_attributes()
Get the columns value from block attributes.
private
get_columns_from_attributes(array<string|int, mixed> $block_attrs) : int
Parameters
- $block_attrs : array<string|int, mixed>
-
Block attributes.
