Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Embed::get_videopress_thumbnail
Extract VideoPress video thumbnail URL. Uses WordPress oEmbed API to get thumbnail_url from the provider response. Results are cached using transients to avoid repeated HTTP requests.
Note: URL validation against VideoPress domains is done in render_video_embed() via url_matches_provider() before this method is called.
Method of the class: Embed{}
Hooks from the method
Returns
String. Thumbnail URL or empty string.
Usage
// private - for code of main (parent) class only $result = $this->get_videopress_thumbnail( $url ): string;
- $url(string) (required)
- VideoPress video URL (pre-validated by caller).
Embed::get_videopress_thumbnail() Embed::get videopress thumbnail code WC 10.7.0
private function get_videopress_thumbnail( string $url ): string {
// Generate a cache key based on the URL.
$cache_key = 'wc_email_vp_thumb_' . md5( $url );
// Check for cached thumbnail URL.
$cached_thumbnail = get_transient( $cache_key );
if ( false !== $cached_thumbnail ) {
// Return cached value (empty string means previous lookup failed).
return is_string( $cached_thumbnail ) ? $cached_thumbnail : '';
}
// Use WP_oEmbed::get_data() to fetch thumbnail from oEmbed endpoint.
// URL is pre-validated by render_video_embed() via url_matches_provider(),
// ensuring only VideoPress domains reach this point (SSRF mitigation).
$oembed = new \WP_oEmbed();
$oembed_data = $oembed->get_data( $url );
/**
* Filter the oEmbed cache time-to-live (TTL).
*
* This filter matches WordPress core's oembed_ttl filter signature:
* - $ttl: Time to live in seconds (default: DAY_IN_SECONDS)
* - $url: The URL being embedded
* - $attr: Attributes array (empty in this context)
* - $post_id: Post ID where embed is used (empty string here since email rendering is not post-specific)
*
* @param int $ttl Cache TTL in seconds.
* @param string $url The embedded URL.
* @param array $attr Attributes array.
* @param string $post_id Post ID (empty string in email context).
*/
// Default TTL matches WordPress oEmbed cache (1 day).
$cache_ttl = (int) apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, array(), '' );
// get_data() returns object|false, so check for false or non-object.
if ( false === $oembed_data || ! is_object( $oembed_data ) ) {
// Cache empty result to avoid repeated failed lookups.
set_transient( $cache_key, '', $cache_ttl );
return '';
}
// Extract thumbnail_url from oEmbed response.
if ( ! isset( $oembed_data->thumbnail_url ) ) {
// Cache empty result.
set_transient( $cache_key, '', $cache_ttl );
return '';
}
$thumbnail_url = $oembed_data->thumbnail_url;
// Validate the thumbnail URL.
if ( ! empty( $thumbnail_url ) && $this->is_valid_url( $thumbnail_url ) ) {
// Cache the valid thumbnail URL.
set_transient( $cache_key, $thumbnail_url, $cache_ttl );
return $thumbnail_url;
}
// Cache empty result for invalid URLs.
set_transient( $cache_key, '', $cache_ttl );
return '';
}