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

Audio::renderpublicWC 1.0

Render the block.

Method of the class: Audio{}

No Hooks.

Returns

String.

Usage

$Audio = new Audio();
$Audio->render( $block_content, $parsed_block, $rendering_context ): string;
$block_content(string) (required)
The block content.
$parsed_block(array) (required)
The parsed block.
$rendering_context(Rendering_Context) (required)
The rendering context.

Audio::render() code WC 10.8.1

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 we have a valid audio source - return empty string immediately if not.
	// For attachments, check the 'id' attribute. For external URLs, check if src exists in HTML content.
	$has_attachment_id = ! empty( $attr['id'] );
	$has_src_in_html   = preg_match( '#<audio[^>]*\ssrc=["\']([^"\']*)["\'][^>]*/?>#', $block_content );

	// If we have neither an attachment ID nor a src in the HTML content, return empty.
	if ( ! $has_attachment_id && ! $has_src_in_html ) {
		return '';
	}

	// If we have a valid source, proceed with normal rendering.
	$rendered_content = $this->render_content( $block_content, $parsed_block, $rendering_context );

	// If render_content returns empty (e.g., invalid URL), return empty string.
	if ( empty( $rendered_content ) ) {
		return '';
	}

	return $this->add_spacer( $rendered_content, $parsed_block['email_attrs'] ?? array() );
}