WooCommerce Code Reference

Embed extends Abstract_Block_Renderer
in package

Embed block renderer.

This renderer handles core/embed blocks, detecting audio and video provider embeds and rendering them appropriately.

Audio providers: Spotify, SoundCloud, Pocket Casts, Mixcloud, ReverbNation - rendered as audio players. Video providers: YouTube - rendered as video thumbnails with play buttons.

Table of Contents

AUDIO_PROVIDERS  = array('pocket-casts' => array('domains' => array('pca.st'), 'base_url' => 'https://pca.st/'), 'spotify' => array('domains' => array('open.spotify.com'), 'base_url' => 'https://open.spotify.com/'), 'soundcloud' => array('domains' => array('soundcloud.com'), 'base_url' => 'https://soundcloud.com/'), 'mixcloud' => array('domains' => array('mixcloud.com'), 'base_url' => 'https://www.mixcloud.com/'), 'reverbnation' => array('domains' => array('reverbnation.com'), 'base_url' => 'https://www.reverbnation.com/'))
Supported audio providers with their configuration.
VIDEO_PROVIDERS  = array('youtube' => array('domains' => array('youtube.com', 'youtu.be'), 'base_url' => 'https://www.youtube.com/'))
Supported video providers with their configuration.
render()  : string
Renders the embed 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 embed block content.
create_fallback_attributes()  : array<string|int, mixed>
Create fallback attributes for link rendering.
detect_provider_from_domains()  : string
Detect provider from content by checking against known domains.
extract_provider_url()  : string
Extract provider URL from block attributes or content.
extract_url_from_content()  : string
Extract URL from block content using DOM parsing.
get_all_provider_configs()  : array<string|int, mixed>
Get all provider configurations (audio and video).
get_all_supported_providers()  : array<string|int, mixed>
Get all supported providers (audio and video).
get_provider_base_url()  : string
Get base URL for a provider when specific URL extraction fails.
get_provider_label()  : string
Get appropriate label for the provider.
get_supported_provider()  : string
Get supported audio or video provider from block attributes or content.
get_translated_provider_label()  : string
Get translated label for a provider.
get_video_thumbnail_url()  : string
Get video thumbnail URL for supported providers.
get_youtube_thumbnail()  : string
Extract YouTube video thumbnail URL.
is_valid_url()  : bool
Validate URL using both filter_var and wp_http_validate_url.
is_video_provider()  : bool
Check if a provider is a video provider.
render_link_fallback()  : string
Render a simple link fallback for non-supported embeds.
render_video_embed()  : string
Render a video embed using the Video renderer.

Constants

AUDIO_PROVIDERS

Supported audio providers with their configuration.

private array<string|int, mixed> AUDIO_PROVIDERS = array('pocket-casts' => array('domains' => array('pca.st'), 'base_url' => 'https://pca.st/'), 'spotify' => array('domains' => array('open.spotify.com'), 'base_url' => 'https://open.spotify.com/'), 'soundcloud' => array('domains' => array('soundcloud.com'), 'base_url' => 'https://soundcloud.com/'), 'mixcloud' => array('domains' => array('mixcloud.com'), 'base_url' => 'https://www.mixcloud.com/'), 'reverbnation' => array('domains' => array('reverbnation.com'), 'base_url' => 'https://www.reverbnation.com/'))

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 embed block content.

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 (required by parent contract but unused in this implementation).

Return values
string

create_fallback_attributes()

Create fallback attributes for link rendering.

private create_fallback_attributes(string $url, string $label) : array<string|int, mixed>
Parameters
$url : string

URL for the fallback.

$label : string

Label for the fallback.

Return values
array<string|int, mixed>Fallback attributes.

detect_provider_from_domains()

Detect provider from content by checking against known domains.

private detect_provider_from_domains(string $content) : string
Parameters
$content : string

Content to check for provider domains.

Return values
stringProvider name or empty string if not found.

extract_provider_url()

Extract provider URL from block attributes or content.

private extract_provider_url(array<string|int, mixed> $attr, string $block_content) : string
Parameters
$attr : array<string|int, mixed>

Block attributes.

$block_content : string

Block content.

Return values
stringProvider URL or empty string.

get_provider_label()

Get appropriate label for the provider.

private get_provider_label(string $provider, array<string|int, mixed> $attr) : string
Parameters
$provider : string

Provider name.

$attr : array<string|int, mixed>

Block attributes.

Return values
stringLabel for the provider.

get_supported_provider()

Get supported audio or video provider from block attributes or content.

private get_supported_provider(array<string|int, mixed> $attr, string $block_content) : string
Parameters
$attr : array<string|int, mixed>

Block attributes.

$block_content : string

Block content.

Return values
stringProvider name or empty string if not supported.

Render a simple link fallback for non-supported embeds.

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

Block attributes.

$block_content : string

Block content.

$parsed_block : array<string|int, mixed>

Parsed block.

$rendering_context : Rendering_Context

Rendering context.

Return values
stringRendered link or empty string if no valid URL.

render_video_embed()

Render a video embed using the Video renderer.

private render_video_embed(string $url, string $provider, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context, string $block_content) : string
Parameters
$url : string

URL of the video.

$provider : string

Provider name.

$parsed_block : array<string|int, mixed>

Parsed block.

$rendering_context : Rendering_Context

Rendering context.

$block_content : string

Original block content.

Return values
stringRendered video embed or fallback.