From 23626d46a63e63e9a99e6ef5e508759fa6d396b6 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 21 Sep 2018 15:03:00 -0500 Subject: [PATCH 1/4] Docs: Correct return informaiton --- modules/sitemaps/sitemap-builder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/sitemaps/sitemap-builder.php b/modules/sitemaps/sitemap-builder.php index b83a7c497da67..a15f2eeab8c30 100644 --- a/modules/sitemaps/sitemap-builder.php +++ b/modules/sitemaps/sitemap-builder.php @@ -1117,7 +1117,9 @@ private function post_to_sitemap_item( $post ) { * * @param WP_Post $post The image post to be processed. * - * @return string An XML fragment representing the post URL. + * @return array + * @type string $xml An XML fragment representing the post URL. + * @type string $last_modified Date post was last modified. */ private function image_post_to_sitemap_item( $post ) { From 29687f964ec3ec2ae4c9c87afbcf1bc6440fd4f6 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 21 Sep 2018 15:03:23 -0500 Subject: [PATCH 2/4] Sitemaps: Do not include images that are not published. --- modules/sitemaps/sitemap-builder.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/sitemaps/sitemap-builder.php b/modules/sitemaps/sitemap-builder.php index a15f2eeab8c30..819b862c81bfa 100644 --- a/modules/sitemaps/sitemap-builder.php +++ b/modules/sitemaps/sitemap-builder.php @@ -1142,6 +1142,15 @@ private function image_post_to_sitemap_item( $post ) { $url = wp_get_attachment_url( $post->ID ); + // Do not include the image if the attached parent is not published. + // Unattached will be published. Otherwise, will inherit parent status. + if ( 'publish' !== get_post_status( $post ) ) { + return array( + 'xml' => null, + 'last_modified' => null, + ); + } + $parent_url = get_permalink( get_post( $post->post_parent ) ); if ( '' == $parent_url ) { // WPCS: loose comparison ok. $parent_url = get_permalink( $post ); From c337da428a275c76682efb2ce20155224638b95e Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 21 Sep 2018 16:06:19 -0500 Subject: [PATCH 3/4] Update docs to match return --- modules/sitemaps/sitemap-builder.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/sitemaps/sitemap-builder.php b/modules/sitemaps/sitemap-builder.php index 819b862c81bfa..595a446eb902e 100644 --- a/modules/sitemaps/sitemap-builder.php +++ b/modules/sitemaps/sitemap-builder.php @@ -1040,7 +1040,9 @@ public function news_sitemap_xml() { * * @param WP_Post $post The post to be processed. * - * @return array An array representing the post URL. + * @return array + * @type array $xml An XML fragment representing the post URL. + * @type string $last_modified Date post was last modified. */ private function post_to_sitemap_item( $post ) { @@ -1118,7 +1120,7 @@ private function post_to_sitemap_item( $post ) { * @param WP_Post $post The image post to be processed. * * @return array - * @type string $xml An XML fragment representing the post URL. + * @type array $xml An XML fragment representing the post URL. * @type string $last_modified Date post was last modified. */ private function image_post_to_sitemap_item( $post ) { @@ -1203,7 +1205,9 @@ private function image_post_to_sitemap_item( $post ) { * * @param WP_Post $post The video post to be processed. * - * @return string An XML fragment representing the post URL. + * @return array + * @type array $xml An XML fragment representing the post URL. + * @type string $last_modified Date post was last modified. */ private function video_post_to_sitemap_item( $post ) { From ce8df3e706ed4ebd3f2990d67c6f041caaf8c53c Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 21 Sep 2018 16:06:46 -0500 Subject: [PATCH 4/4] Do not include videos unless they are unattached or attached to published posts --- modules/sitemaps/sitemap-builder.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/sitemaps/sitemap-builder.php b/modules/sitemaps/sitemap-builder.php index 595a446eb902e..26a9179386f1f 100644 --- a/modules/sitemaps/sitemap-builder.php +++ b/modules/sitemaps/sitemap-builder.php @@ -1228,6 +1228,15 @@ private function video_post_to_sitemap_item( $post ) { ); } + // Do not include the video if the attached parent is not published. + // Unattached will be published. Otherwise, will inherit parent status. + if ( 'publish' !== get_post_status( $post ) ) { + return array( + 'xml' => null, + 'last_modified' => null, + ); + } + $parent_url = esc_url( get_permalink( get_post( $post->post_parent ) ) ); if ( '' == $parent_url ) { // WPCS: loose comparison ok. $parent_url = esc_url( get_permalink( $post ) );