Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sitemaps: Do not include images not published #10194

Merged
merged 4 commits into from
Sep 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions modules/sitemaps/sitemap-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down Expand Up @@ -1117,7 +1119,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 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 ) {

Expand All @@ -1140,6 +1144,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 );
Expand Down Expand Up @@ -1192,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 ) {

Expand All @@ -1213,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 ) );
Expand Down