WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#5801 closed defect (bug) (fixed)

safety measure for cron to publish future post

Reported by: hailin Owned by:
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.5
Component: General Keywords:
Focuses: Cc:

Description

Sometimes future posts were published before they were scheduled.

There could be two possible reasons:

1, time is off on the local web server. When time is off, it will trigger publishing events ahead of time or ahead of time.

  1. our publish future post logic is flawed.

We store future posts to be published in cron field in each blog's option table. Theoretically, only post of type "future" can be stored there.

However, we have so many types of posts (including some legacy types), and transitioning among them is not easy to guarantee to be 100% correctly handled.

Debugging some blogs reveals that there is one post of type "draft" that was included in the cron field in the options table. And to make matter worse, when publish event is fired, we just happily publish the post, even when the type is "draft". So this logic is wrong.

One possible fix is not to publish any post NOT of type "future". But I figure that is too strict. For a safe fix, I only add logic to skip publishing "draft" posts.

Attachments (1)

755_future_posts_wporg.diff (1.8 KB) - added by hailin 7 years ago.
updated patch with ryan's feedback

Download all attachments as: .zip

Change History (5)

comment:1 @ryan7 years ago

  • Milestone changed from 2.6 to 2.5

wp_publish_post can be used outside of a future post publication context. Requests to publish drafts should not be ignored. Perhaps a better fix would be to hook a publish_future_post() function to the publish_future_post action that does the necessary checks before calling wp_publish_post().

comment:2 @lloydbudd7 years ago

  • Version set to 2.5

@hailin7 years ago

updated patch with ryan's feedback

comment:3 @hailin7 years ago

wp_publish_post so far is not used anywhere else. But I concur that it is best to make this generic, and independent.
Revised the code, tested it, and new patch attached.

comment:4 @ryan7 years ago

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

(In [6985]) Make sure post has future status before publishing from cron. Props hailin. fixes #5801

Note: See TracTickets for help on using tickets.