Ticket #5364 (closed defect (bug): fixed)

Opened 4 years ago

Last modified 3 years ago

Cron not updated correctly when deleting a future post

Reported by: develish Owned by: anonymous
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

5364.diff Download (352 bytes) - added by Denis-de-Bernardy 3 years ago.

Change History

I've confirmed this in a unit test:

There was 1 failure:

1) test_delete_future_post_cron(WPTestIncludesPost)
Failed asserting that <integer:1195415622> is false.
/home/zem/projects/wordpress/wordpress-tests/wp-testcase/test_includes_post.php:146
/home/zem/projects/wordpress/wordpress-tests/wp-testlib/base.php:348
/home/zem/projects/wordpress/wordpress-tests/wp-test.php:92

See test_delete_future_post_cron() in  http://svn.automattic.com/wordpress-tests/wp-testcase/test_includes_post.php.

  • Milestone changed from 2.5 to 2.4

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.

  • Milestone changed from 2.5 to 2.6
  • 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.

Turns out this is due to hapazard sanitisation. [11282] makes it more regular.

  • Status changed from new to closed
  • Resolution set to fixed

(In [11284]) Clear future publishing hook on post deletion. Fixes #5364 props develish and Denis-de-Bernardy.

Note: See TracTickets for help on using tickets.