WooCommerce Code Reference

Video extends Cover
in package

Video block renderer.

This renderer handles core/video blocks by reusing the cover block renderer to show a thumbnail with a play button overlay.

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 video block content by transforming it into a cover block structure.
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.
create_play_button_html()  : string
Create the play button HTML with optional link.
extract_background_image()  : string
Extract background image from block attributes or HTML content.
extract_poster_url()  : string
Extract poster URL from block attributes.
extract_video_url()  : string
Extract video URL from block content.
get_background_color()  : string
Get background color from block attributes.
get_current_post_url()  : string
Get the current post permalink with security validation.
get_minimum_height()  : string
Get minimum height from block attributes.
get_play_icon_url()  : string
Get the URL for the play button icon.
transform_to_cover_block()  : array<string|int, mixed>
Transform a video block into a cover block structure.
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 video block content by transforming it into a cover block structure.

protected render_content(string $block_content, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string

Shows the video poster/thumbnail with a play button overlay using the parent cover renderer.

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.

extract_poster_url()

Extract poster URL from block attributes.

private extract_poster_url(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 (unused, kept for consistency).

Return values
stringPoster URL or empty string.

transform_to_cover_block()

Transform a video block into a cover block structure.

private transform_to_cover_block(array<string|int, mixed> $video_block, string $poster_url) : array<string|int, mixed>
Parameters
$video_block : array<string|int, mixed>

Original video block.

$poster_url : string

Poster URL to use as background.

Return values
array<string|int, mixed>Cover block structure.

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.