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

Embed::render_contentprotectedWC 1.0

Renders the embed block content.

Method of the class: Embed{}

No Hooks.

Returns

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->render_content( $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 (required by parent contract but unused in this implementation).

Embed::render_content() code WC 10.4.3

protected function render_content( string $block_content, array $parsed_block, Rendering_Context $rendering_context ): string { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
	$attr = $parsed_block['attrs'] ?? array();

	// Get provider and URL (validation already done in render method).
	$provider = $this->get_supported_provider( $attr, $block_content );
	$url      = $this->extract_provider_url( $attr, $block_content );

	// Check if this is a video provider - render as video block.
	if ( $this->is_video_provider( $provider ) ) {
		return $this->render_video_embed( $url, $provider, $parsed_block, $rendering_context, $block_content );
	}

	// For audio providers, use the original audio rendering logic.
	$label = $this->get_provider_label( $provider, $attr );

	// Create a mock audio block structure to reuse the Audio renderer.
	$mock_audio_block = array(
		'blockName' => 'core/audio',
		'attrs'     => array(
			'src'   => $url,
			'label' => $label,
		),
		'innerHTML' => '<figure class="wp-block-audio"><audio controls src="' . esc_attr( $url ) . '"></audio></figure>',
	);

	// Copy email attributes to the mock block.
	if ( isset( $parsed_block['email_attrs'] ) ) {
		$mock_audio_block['email_attrs'] = $parsed_block['email_attrs'];
	}

	// Use the Audio renderer to render the audio provider embed.
	$audio_renderer = new Audio();
	$audio_result   = $audio_renderer->render( $mock_audio_block['innerHTML'], $mock_audio_block, $rendering_context );

	// If audio rendering fails, fall back to a simple link.
	if ( empty( $audio_result ) ) {
		$fallback_attr = $this->create_fallback_attributes( $url, $label );
		return $this->render_link_fallback( $fallback_attr, $block_content, $parsed_block, $rendering_context );
	}

	return $audio_result;
}