Jake Vanderwerf
2026-02-14 27fb820ae9081fb56957cf75e79eccd8a99edd52
inc/blocks/VideoCoverBlock.php
@@ -41,6 +41,7 @@
    */
   public function render($attributes, $content): string
   {
      // Extract attributes with defaults
      $poster_id = $attributes['posterId'] ?? 0;
      $video_sources = $attributes['videoSources'] ?? [];
@@ -53,14 +54,17 @@
      //Get date of current post
      global $post;
      $date = date('c',strtotime($post->post_date));
      $title = $attributes['title'] ?? $post->post_title;
      $description = $attributes['description'] ?? $post->post_excerpt;
      // 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
@@ -81,7 +85,7 @@
            "uploadDate": "'.$date.'"
        }
    </script>
    <div class="wrap">
    <div class="wrap abs edges">
        <div class="video-container">';
      $html .= '<video';
      $html .= ' muted loop playsinline autoplay';
@@ -90,38 +94,39 @@
         $html .= ' poster="' . esc_url($poster_url) . '"';
      }
      $html .= '>';
      $html .= ' fetch-priority="high">';
      // Add mobile sources first (lower resolution)
      foreach ($mobile_sources as $source) {
         if (!empty($source['url']) && !empty($source['mime'])) {
            $html .= '<source';
            $html .= ' src="' . esc_url($source['url']) . '"';
            $html .= ' type="' . esc_attr($source['mime']) . '"';
            $html .= ' media="(max-width: 767px)"';
            $html .= '>';
         }
      }
      // Add desktop sources
      foreach ($video_sources as $source) {
         if (!empty($source['url']) && !empty($source['mime'])) {
            $html .= '<source';
            $html .= ' src="' . esc_url($source['url']) . '"';
            $html .= ' data-src="' . esc_url($source['url']) . '"';
            $html .= ' type="' . esc_attr($source['mime']) . '"';
            // Add media query for desktop if mobile sources exist
            if (!empty($mobile_sources)) {
               $html .= ' media="(min-width: 768px)"';
            }
            $html .= '>';
         }
      }
      $html .= '</video>';
      $html .= '</div></div><div class="inner-wrap"></div></section>';
      $inner_content = $this->extractInnerContent($content);
      $html .= '</div></div><div class="inner-wrap">'.$inner_content.'</div></section>';
      return $html;
   }
   /**
    * Extract inner content from the saved block content
    * Removes the wrapper div and returns just the inner blocks HTML
    */
   protected function extractInnerContent(string $content): string
   {
      if (empty($content)) {
         return '';
      }
      // Remove the placeholder wrapper div
      $content = preg_replace('/<div[^>]*class="[^"]*video-cover-wrapper-placeholder[^"]*"[^>]*>/', '', $content, 1);
      $content = preg_replace('/<\/div>\s*$/', '', $content, 1);
      return trim($content);
   }
}