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

Deleted posts are not removed #112

Open
mjangda opened this issue Feb 14, 2017 · 4 comments
Open

Deleted posts are not removed #112

mjangda opened this issue Feb 14, 2017 · 4 comments
Assignees

Comments

@mjangda
Copy link
Member

mjangda commented Feb 14, 2017

Reproduction Steps:

  • Add a post
  • Wait for sitemap to be generated (or updated)
  • Before the next update cron runs, trash and delete the post
  • Wait for next update cron to trigger

The sitemap for today should no longer have the post but still does. This is because out update cron only looks through the post_modified column. Posts that were deleted are not included.

@mjangda
Copy link
Member Author

mjangda commented Feb 15, 2017

This is a bit tricky. Instead of looking for posts based on the last modified date, it might make sense to hook into transition post status instead and track the dates for those posts (in an option) and then use those instead. Something like:

add_action( 'transition_post_status', function( $new_status, $old_status, $post ) {
    if ( 'publish' !== $new_status || 'publish' !== $old_status ) {
        return;
    }

    $dates_to_update = get_option( 'msm_sitemap_next_run_update_dates', array() );
    $dates_to_update[] = date( 'Y-m-d', strtotime( $post->post_date ) );
    $dates_to_update = array_unique( $dates_to_update );
    update_option( 'msm_sitemap_next_run_update_dates', $dates_to_update, false );
}, 10, 3 ); 

Not sure what the implications of this are. There may be race conditions if a post is updated while the cron is triggering (although, I think those can probably happen now too).

@mattoperry
Copy link

I was thinking something very similar, except usinguntrash_post and trashed_post ... however, I think your way is better because it would save scheduling jobs for stuff being trashed from other statuses (like draft.)

@mjangda can you point me toward msm_sitemap_next_run_update_dates? Where else is that option used?

@mjangda
Copy link
Member Author

mjangda commented Feb 15, 2017

can you point me toward msm_sitemap_next_run_update_dates? Where else is that option used?

It doesn't exist yet :) My thinking was that we can add it and update update_sitemap_from_modified_posts to use it instead of the get_last_modified_posts lookup.

@mattoperry
Copy link

Makes sense :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants