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

Embed::render_caption │ private │ WC 1.0

Render the block's figcaption (if any) as a centered block appended below the embed output.

Method of the class: Embed{}

No Hooks.

Returns

string. Caption HTML or empty string.

Usage

// private - for code of main (parent) class only
$result = $this->render_caption( $block_content ): string;
$block_content(string) (required)
Block content.

Embed::render_caption() code WC 11.2.1

private function render_caption( string $block_content ): string {
	if ( ! preg_match( '/<figcaption[^>]*>(.*?)<\/figcaption>/is', $block_content, $matches ) ) {
		return '';
	}

	$caption = trim( $matches[1] );
	if ( '' === $caption ) {
		return '';
	}

	return '<div style="text-align: center; margin-top: 8px;">' . Html_Processing_Helper::sanitize_caption_html( $caption ) . '</div>';
}