WooCommerce Code Reference

Cover extends Abstract_Block_Renderer
in package

Cover block renderer.

This renderer handles core/cover 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 cover block content using a table-based layout for email compatibility.
build_cover_content()  : string
Build the cover content with background image or color.
build_email_layout()  : string
Build the email-friendly layout for cover blocks.
extract_background_image()  : string
Extract background image from block attributes or HTML content.
get_background_color()  : string
Get background color from block attributes.
get_minimum_height()  : string
Get minimum height from block attributes.
validate_and_sanitize_color()  : string
Validate and sanitize a color value, returning empty string for invalid colors.

Methods

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
stringInner 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 cover block content using a table-based layout for email compatibility.

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 cover blocks.

private build_email_layout(string $inner_content, array<string|int, mixed> $block_attrs, string $block_content, string $background_image, Rendering_Context $rendering_context) : string
Parameters
$inner_content : string

Inner content.

$block_attrs : array<string|int, mixed>

Block attributes.

$block_content : string

Original block content.

$background_image : string

Background image URL.

$rendering_context : Rendering_Context

Rendering context.

Return values
stringRendered HTML.

extract_background_image()

Extract background image from block attributes or HTML content.

private extract_background_image(array<string|int, mixed> $block_attrs, string $block_content) : string
Parameters
$block_attrs : array<string|int, mixed>

Block attributes.

$block_content : string

Original block content.

Return values
stringBackground image URL or empty string.

validate_and_sanitize_color()

Validate and sanitize a color value, returning empty string for invalid colors.

private validate_and_sanitize_color(string $color) : string
Parameters
$color : string

The color value to validate and sanitize.

Return values
stringSanitized color or empty string if invalid.