path, [
'render_callback' => [$this, 'render']
]);
}
/**
* Render the video cover block
*/
public function render($attributes, $content): string
{
// Extract attributes with defaults
$poster_id = $attributes['posterId'] ?? 0;
$video_sources = $attributes['videoSources'] ?? [];
$mobile_sources = $attributes['mobileSources'] ?? [];
$css_class = $attributes['className'] ?? '';
$fade_class = $attributes['fadeEffect'] ?? false ? 'fade' : '';
$overlay_opacity = $attributes['overlayOpacity'] ?? 0;
$content_alignment = $attributes['contentAlignment'] ?? 'center';
$min_height = $attributes['minHeight'] ?? 0;
//Get date of current post
global $post;
$date = date('c',strtotime($post->post_date));
// If no video sources, return empty
if (empty($video_sources)) {
return '';
}
$video_id = $video_sources[0]['id'] ?? 0;
$video_post = $video_id ? get_post($video_id) : null;
$title = $video_post->post_title ?? $post->post_title;
$description = $video_post->post_content ?? $post->post_excerpt;
// Get poster URL
$poster_url = $poster_id ? wp_get_attachment_url($poster_id) : '';
// Build video tag
$classes = trim("video-cover {$fade_class} {$css_class}");
$html = '