Ticket #5364 (closed defect (bug): fixed)
Cron not updated correctly when deleting a future post
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | low | Milestone: | 2.8 |
| Component: | Optimization | Version: | 2.3.1 |
| Severity: | minor | Keywords: | has-patch commit |
| Cc: |
Description
Hi,
my name is Mariano and this is my first bug report so please bear with me :D
When I delete a future post using wp_delete_post($post->ID) it does not update the cron correctly.
I use this code to actually manually delete and unschedule the future posts
$posts = $wpdb->get_results( "SELECT ID FROM $wpdb->posts where post_status = 'future';" );
foreach ($posts as $post)
{
wp_clear_scheduled_hook( 'publish_future_post', $post->ID );
wp_delete_post($post->ID)<
}
Maybe a check if the post is of post_status future and then unscheduling it in the post deletion process would fix it.
I was not able to find the unschedule in post.php -> wp_delete_post
Thanks for consideration
Mariano
Attachments
Change History
comment:1
tellyworth — 4 years ago
After we delete a post, the post ID becomes invalid. Therefore, even the entry was still in cron, when cron fires up, it tries to retrieve an invalid post, it will return right away. logic is in wp_publish_post:
$post = get_post($post_id);
if ( empty($post) )
return;
So while a fix is good, I don't think there is real harm.
- Keywords needs-patch added; cron delete post wp_delete_post removed
- Component changed from General to Optimization
wontfix? or optimization?
- Keywords has-patch commit added; needs-patch removed
- Milestone changed from 2.9 to 2.8
While this patch looks fine, it doesn't pass the unit test :-( the cron array still has the scheduled post in it afterwards.
I *think* I might know why... will find the ticket and report back
see: #8808 for the likely reason
so, if #8808 gets applied, and we use array( (string)$post_id ) instead, it should work.
on a separate note, it may be worth tweaking the cron a little bit so as to check for something like:
if args is numeric, and floatval() = intval() then cast to int.
that way, the stuff can be passed (string) $post_id etc, and it'll still work.
comment:12
westi — 3 years ago
Turns out this is due to hapazard sanitisation. [11282] makes it more regular.
comment:13
westi — 3 years ago
- Status changed from new to closed
- Resolution set to fixed


I've confirmed this in a unit test:
See test_delete_future_post_cron() in http://svn.automattic.com/wordpress-tests/wp-testcase/test_includes_post.php.