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

Embed::render_compact_link_cardprivateWC 1.0

Render a compact link card for embeds that exceed the rich card cap. Displays the URL in a bordered card without making any HTTP requests.

Method of the class: Embed{}

No Hooks.

Returns

String. Rendered compact link card HTML.

Usage

// private - for code of main (parent) class only
$result = $this->render_compact_link_card( $url, $parsed_block, $rendering_context ): string;
$url(string) (required)
URL to render.
$parsed_block(array) (required)
Parsed block.
$rendering_context(Rendering_Context) (required)
Rendering context.

Embed::render_compact_link_card() code WC 10.8.1

private function render_compact_link_card( string $url, array $parsed_block, Rendering_Context $rendering_context ): string {
	$email_styles = $rendering_context->get_theme_styles();
	$link_color   = $email_styles['elements']['link']['color']['text'] ?? '#0073aa';
	$link_color   = Html_Processing_Helper::sanitize_color( $link_color );

	// Build display text: strip scheme from URL.
	$display_host = (string) wp_parse_url( $url, PHP_URL_HOST );
	$display_path = (string) wp_parse_url( $url, PHP_URL_PATH );
	$display_text = $display_host . $display_path;

	$link_html = sprintf(
		'<a href="%s" target="_blank" rel="noopener nofollow" style="color: %s; text-decoration: none;">%s</a>',
		esc_url( $url ),
		esc_attr( $link_color ),
		esc_html( $display_text )
	);

	$content_cell = Table_Wrapper_Helper::render_table_cell(
		$link_html,
		array( 'style' => 'padding: 12px;' )
	);

	$card_html  = '<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border: 1px solid #ddd; border-radius: 4px; width: 100%;">';
	$card_html .= '<tbody><tr>' . $content_cell . '</tr></tbody></table>';

	$outlook_wrapped = Table_Wrapper_Helper::render_outlook_table_wrapper(
		$card_html,
		array(
			'align' => 'left',
			'width' => '100%',
		)
	);

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