Skip to content

Commit

Permalink
When a sitemap has no posts, delete it
Browse files Browse the repository at this point in the history
For both cron and CLI. Otherwise we end up with rougue empty sitemaps.

Fixes #63
  • Loading branch information
mjangda committed Mar 30, 2016
1 parent e9c02a9 commit 941d33c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions includes/msm-sitemap-builder-cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ public static function generate_sitemap_for_year_month_day( $args ) {
$date_stamp = Metro_Sitemap::get_date_stamp( $year, $month, $day );
if ( Metro_Sitemap::date_range_has_posts( $date_stamp, $date_stamp ) ) {
Metro_Sitemap::generate_sitemap_for_date( $date_stamp );
} else {
Metro_Sitemap::delete_sitemap_for_date( $date_stamp );
}

self::find_next_day_to_process( $year, $month, $day );
Expand Down
2 changes: 2 additions & 0 deletions includes/wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ function generate_sitemap_for_year_month_day( $args, $assoc_args ) {
$date_stamp = Metro_Sitemap::get_date_stamp( $year, $month, $day );
if ( Metro_Sitemap::date_range_has_posts( $date_stamp, $date_stamp ) ) {
Metro_Sitemap::generate_sitemap_for_date( $date_stamp ); // TODO: simplify; this function should accept the year, month, day and translate accordingly
} else {
Metro_Sitemap::delete_sitemap_for_date( $date_stamp );
}
}

Expand Down

0 comments on commit 941d33c

Please sign in to comment.