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

Embed::get_youtube_thumbnailprivateWC 1.0

Extract YouTube video thumbnail URL.

Метод класса: Embed{}

Хуков нет.

Возвращает

Строку. Thumbnail URL or empty string.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_youtube_thumbnail( $url ): string;
$url(строка) (обязательный)
YouTube video URL.

Код Embed::get_youtube_thumbnail() WC 10.4.3

private function get_youtube_thumbnail( string $url ): string {
	// Extract video ID from various YouTube URL formats.
	$video_id = '';

	if ( preg_match( '/(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9_-]+)/', $url, $matches ) ) {
		$video_id = $matches[1];
	}

	if ( empty( $video_id ) ) {
		return '';
	}

	// Return YouTube thumbnail URL.
	// Using 0.jpg format as shown in the example.
	return 'https://img.youtube.com/vi/' . $video_id . '/0.jpg';
}