From bf6216698d049f33100253fdcc961c862fc6aa0a Mon Sep 17 00:00:00 2001 From: Adam Heckler Date: Fri, 1 Mar 2019 06:56:51 -0500 Subject: [PATCH 1/5] Add thumbnails to video sitemap Fixes #9539. Uses thumbnails from processed VideoPress videos where possible, otherwise falls back to a blank image. This will avoid Google Search Console (aka Google Webmaster Tools) from complaining about invalid URLs in video sitemaps. --- modules/sitemaps/sitemap-builder.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/sitemaps/sitemap-builder.php b/modules/sitemaps/sitemap-builder.php index c74b1f03a1ba5..84e16ae07fe6d 100644 --- a/modules/sitemaps/sitemap-builder.php +++ b/modules/sitemaps/sitemap-builder.php @@ -1319,6 +1319,19 @@ private function video_post_to_sitemap_item( $post ) { /** This filter is already documented in core/wp-includes/feed.php */ $content = apply_filters( 'the_content_feed', $content, 'rss2' ); + + // Include thumbnails for VideoPress videos, use blank image for others + if ( 'complete' === get_post_meta( $post->ID, 'videopress_status', true ) && has_post_thumbnail( $post ) ) { + $video_thumbnail_url = get_the_post_thumbnail_url( $post ); + } else { + * Filter the thumbnail image used in the video sitemap for non-VideoPress videos. + * + * @since 7.2.0 + * + * @param string $str Image URL. + */ + $video_thumbnail_url = apply_filters( 'jetpack_video_sitemap_default_thumbnail', 'https://s0.wp.com/i/blank.jpg' ); + } $item_array = array( 'url' => array( @@ -1327,7 +1340,7 @@ private function video_post_to_sitemap_item( $post ) { 'video:video' => array( /** This filter is already documented in core/wp-includes/feed.php */ 'video:title' => apply_filters( 'the_title_rss', $post->post_title ), - 'video:thumbnail_loc' => '', + 'video:thumbnail_loc' => $video_thumbnail_url, 'video:description' => $content, 'video:content_loc' => esc_url( wp_get_attachment_url( $post->ID ) ), ), From 2d96ce8169938aae857e1ab7b3c3d4c59a661272 Mon Sep 17 00:00:00 2001 From: Adam Heckler Date: Fri, 1 Mar 2019 07:23:17 -0500 Subject: [PATCH 2/5] Actually comment out the comment --- modules/sitemaps/sitemap-builder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/sitemaps/sitemap-builder.php b/modules/sitemaps/sitemap-builder.php index 84e16ae07fe6d..ddf865b3e6d97 100644 --- a/modules/sitemaps/sitemap-builder.php +++ b/modules/sitemaps/sitemap-builder.php @@ -1324,6 +1324,7 @@ private function video_post_to_sitemap_item( $post ) { if ( 'complete' === get_post_meta( $post->ID, 'videopress_status', true ) && has_post_thumbnail( $post ) ) { $video_thumbnail_url = get_the_post_thumbnail_url( $post ); } else { + /* * Filter the thumbnail image used in the video sitemap for non-VideoPress videos. * * @since 7.2.0 From b15cfe3e5a4130d742ef1fc04412887b34b34d1e Mon Sep 17 00:00:00 2001 From: Adam Heckler Date: Fri, 1 Mar 2019 07:57:57 -0500 Subject: [PATCH 3/5] Minor change to comment styling --- modules/sitemaps/sitemap-builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sitemaps/sitemap-builder.php b/modules/sitemaps/sitemap-builder.php index ddf865b3e6d97..9fa4113862054 100644 --- a/modules/sitemaps/sitemap-builder.php +++ b/modules/sitemaps/sitemap-builder.php @@ -1324,7 +1324,7 @@ private function video_post_to_sitemap_item( $post ) { if ( 'complete' === get_post_meta( $post->ID, 'videopress_status', true ) && has_post_thumbnail( $post ) ) { $video_thumbnail_url = get_the_post_thumbnail_url( $post ); } else { - /* + /** * Filter the thumbnail image used in the video sitemap for non-VideoPress videos. * * @since 7.2.0 From d81a669dfd585503bbf708ba38f1e86ba9560dcf Mon Sep 17 00:00:00 2001 From: Adam Heckler Date: Sun, 3 Mar 2019 06:02:25 -0500 Subject: [PATCH 4/5] More whitespace adjustments --- modules/sitemaps/sitemap-builder.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/sitemaps/sitemap-builder.php b/modules/sitemaps/sitemap-builder.php index 9fa4113862054..880626f660c8d 100644 --- a/modules/sitemaps/sitemap-builder.php +++ b/modules/sitemaps/sitemap-builder.php @@ -1324,13 +1324,13 @@ private function video_post_to_sitemap_item( $post ) { if ( 'complete' === get_post_meta( $post->ID, 'videopress_status', true ) && has_post_thumbnail( $post ) ) { $video_thumbnail_url = get_the_post_thumbnail_url( $post ); } else { - /** - * Filter the thumbnail image used in the video sitemap for non-VideoPress videos. - * - * @since 7.2.0 - * - * @param string $str Image URL. - */ + /** + * Filter the thumbnail image used in the video sitemap for non-VideoPress videos. + * + * @since 7.2.0 + * + * @param string $str Image URL. + */ $video_thumbnail_url = apply_filters( 'jetpack_video_sitemap_default_thumbnail', 'https://s0.wp.com/i/blank.jpg' ); } From 831d81e83b547c772da521e9dbdc0b16d74d6f20 Mon Sep 17 00:00:00 2001 From: Adam Heckler Date: Wed, 6 Mar 2019 05:21:38 -0500 Subject: [PATCH 5/5] Escape $video_thumbnail_url --- modules/sitemaps/sitemap-builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sitemaps/sitemap-builder.php b/modules/sitemaps/sitemap-builder.php index 880626f660c8d..e04f58d5ab845 100644 --- a/modules/sitemaps/sitemap-builder.php +++ b/modules/sitemaps/sitemap-builder.php @@ -1341,7 +1341,7 @@ private function video_post_to_sitemap_item( $post ) { 'video:video' => array( /** This filter is already documented in core/wp-includes/feed.php */ 'video:title' => apply_filters( 'the_title_rss', $post->post_title ), - 'video:thumbnail_loc' => $video_thumbnail_url, + 'video:thumbnail_loc' => esc_url( $video_thumbnail_url ), 'video:description' => $content, 'video:content_loc' => esc_url( wp_get_attachment_url( $post->ID ) ), ),