/** * Add VideoObject schema entries (FV Player + YouTube) dynamically to the @graph. * Deduplicates, ensures fallback thumbnails, and prioritizes permanent pages over blog posts. */ function dc_schema_add_videos($post, &$graph) { global $wpdb; $page_url = get_permalink($post->ID); $page_title = get_the_title($post->ID); $page_desc = dc_get_post_specific_description($post->ID); $page_date = get_the_date('c', $post->ID); $mod_date = get_the_modified_date('c', $post->ID); $site_url = home_url(); $fallback_thumbnail = 'https://dcdouglas.com/wp-content/uploads/2025/07/DC-Douglas-Film-FEstival-2024.webp'; $video_objects = []; $dedup_videos = []; // Handle FV Player videos $player_ids = $wpdb->get_col($wpdb->prepare( "SELECT id_player FROM {$wpdb->prefix}fv_player_playermeta WHERE meta_key = 'post_id' AND meta_value = %d", $post->ID )); foreach ($player_ids as $player_id) { $video_id_list = $wpdb->get_var($wpdb->prepare( "SELECT videos FROM {$wpdb->prefix}fv_player_players WHERE id = %d", $player_id )); if (empty($video_id_list)) continue; $video_ids = array_map('trim', explode(',', $video_id_list)); foreach ($video_ids as $vid_id) { if (in_array($vid_id, $dedup_videos)) continue; $dedup_videos[] = $vid_id; $video = $wpdb->get_row($wpdb->prepare( "SELECT src, splash, title, duration, last_check FROM {$wpdb->prefix}fv_player_videos WHERE id = %d", $vid_id )); if (!$video || empty($video->src)) continue; $title = !empty($video->title) ? $video->title : "{$page_title} (Clip)"; $desc = !empty($page_desc) ? $page_desc : "A clip featuring D.C. Douglas."; $thumb = !empty($video->splash) ? $video->splash : $fallback_thumbnail; $uploadDate = !empty($video->last_check) ? date('c', strtotime($video->last_check)) : $page_date; $video_objects[] = [ "@type" => "VideoObject", "@id" => "{$page_url}#video-{$vid_id}", "name" => $title, "description" => $desc, "thumbnailUrl" => $thumb, "uploadDate" => $uploadDate, "datePublished" => $page_date, "dateModified" => $mod_date, "contentUrl" => $page_url, "embedUrl" => $video->src, "publisher" => [ "@type" => "Organization", "name" => "D.C. Douglas Official Site", "url" => $site_url ], "author" => [ "@type" => "Person", "name" => "D.C. Douglas", "url" => $site_url ] ]; } } // Handle YouTube embeds in content preg_match_all('/https?:\/\/(?:www\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9_-]+)/i', $post->post_content, $yt_matches); foreach ($yt_matches[1] as $video_id) { $unique_id = "yt-{$video_id}"; if (in_array($unique_id, $dedup_videos)) continue; $dedup_videos[] = $unique_id; $video_objects[] = [ "@type" => "VideoObject", "@id" => "{$page_url}#video-{$video_id}", "name" => $page_title, "description" => $page_desc, "thumbnailUrl" => "https://img.youtube.com/vi/{$video_id}/hqdefault.jpg", "uploadDate" => $page_date, "datePublished" => $page_date, "dateModified" => $mod_date, "contentUrl" => $page_url, "embedUrl" => "https://www.youtube.com/embed/{$video_id}", "publisher" => [ "@type" => "Organization", "name" => "D.C. Douglas Official Site", "url" => $site_url ], "author" => [ "@type" => "Person", "name" => "D.C. Douglas", "url" => $site_url ] ]; } if (!empty($video_objects)) { $graph = array_merge($graph, $video_objects); } } // Insert calls into each schema branch (acting, voiceover, blog) if (function_exists('dc_schema_add_videos')) { // Example insertion points: // In Acting schema block, before $schema output // In Voiceover schema block, before $schema output // In Blog schema block, before $schema output // These calls would be manually placed at the actual $schema echo points: // dc_schema_add_videos($post, $graph); }