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
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 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_cover_content()
Build the cover content with background image or color.
private
build_cover_content(string $inner_content) : string
Parameters
- $inner_content : string
-
Inner content.
Return values
string — Cover content HTML.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
string — Rendered HTML.create_play_button_html()
Create the play button HTML with optional link.
private
create_play_button_html([string $link_url = '' ]) : string
Parameters
- $link_url : string = ''
-
Optional URL to link to.
Return values
string — Play button 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
string — Background 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
string — Poster URL or empty string.extract_video_url()
Extract video URL from block content.
private
extract_video_url(string $block_content) : string
Parameters
- $block_content : string
-
Block content HTML.
Return values
string — Video URL or empty string.get_background_color()
Get background color from block attributes.
private
get_background_color(array<string|int, mixed> $block_attrs, Rendering_Context $rendering_context) : string
Parameters
- $block_attrs : array<string|int, mixed>
-
Block attributes.
- $rendering_context : Rendering_Context
-
Rendering context.
Return values
string — Background color or empty string.get_current_post_url()
Get the current post permalink with security validation.
private
get_current_post_url() : string
Return values
string — Post permalink or empty string if invalid.get_minimum_height()
Get minimum height from block attributes.
private
get_minimum_height(array<string|int, mixed> $block_attrs) : string
Parameters
- $block_attrs : array<string|int, mixed>
-
Block attributes.
Return values
string — Minimum height value or empty string.get_play_icon_url()
Get the URL for the play button icon.
private
get_play_icon_url() : string
Return values
string — Play button icon URL.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.
