Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks

Embed::renderpublicWC 1.0

Renders the embed block.

Method of the class: Embed{}

No Hooks.

Returns

String.

Usage

$Embed = new Embed();
$Embed->render( $block_content, $parsed_block, $rendering_context ): string;
$block_content(string) (required)
Block content.
$parsed_block(array) (required)
Parsed block.
$rendering_context(Rendering_Context) (required)
Rendering context.

Embed::render() code WC 11.0.0

public function render( string $block_content, array $parsed_block, Rendering_Context $rendering_context ): string {
	// Validate input parameters and required dependencies.
	if ( ! isset( $parsed_block['attrs'] ) || ! is_array( $parsed_block['attrs'] ) ||
		! class_exists( '\Automattic\WooCommerce\EmailEditor\Integrations\Utils\Table_Wrapper_Helper' ) ) {
		return '';
	}

	$attr = $parsed_block['attrs'];

	// Check if this is a supported audio or video provider embed and has a valid URL.
	$provider = $this->get_supported_provider( $attr, $block_content );
	if ( empty( $provider ) ) {
		// For non-supported embeds, try to render as a rich card using oEmbed data.
		// Only attempt the embed page fetch for WordPress embeds (type "wp-embed")
		// to avoid wasted HTTP requests to non-WordPress sites.
		$url         = $this->extract_provider_url( $attr, $block_content );
		$is_wp_embed = isset( $attr['type'] ) && 'wp-embed' === $attr['type'];
		if ( ! empty( $url ) && $is_wp_embed ) {
			$card_result = $this->render_link_embed_card( $url, $parsed_block, $rendering_context );
			if ( ! empty( $card_result ) ) {
				return $card_result;
			}
			// Fetch failed or over the fetch cap — render as compact link card instead of plain link.
			return $this->render_compact_link_card( $url, $parsed_block, $rendering_context );
		}
		return $this->render_link_fallback( $attr, $block_content, $parsed_block, $rendering_context );
	}

	$url = $this->extract_provider_url( $attr, $block_content );
	if ( empty( $url ) ) {
		// Provider was detected but URL extraction failed - provide graceful fallback.
		return $this->render_link_fallback( $attr, $block_content, $parsed_block, $rendering_context );
	}

	// If we have a valid audio or video provider embed, proceed with normal rendering.
	return $this->render_content( $block_content, $parsed_block, $rendering_context );
}