Make WordPress Core

Opened 8 years ago

Last modified 3 weeks ago

#24160 assigned defect (bug)

ALTERNATE_WP_CRON runs wp_cron() too early

Reported by: r-a-y Owned by: peterwilsoncc
Milestone: 5.7 Priority: normal
Severity: normal Version: 3.4
Component: Cron API Keywords: has-patch early
Focuses: Cc:

Description (last modified by SergeyBiryukov)

See #19818 for full details.

Then, read my comment in that ticket. Was advised to create a new ticket.

We need to run 'wp_cron' later than the default priority of 10 to allow plugins that run on this hook to properly initialize.

In the patch, I've bumped the priority to 99. Let me know what you think.

Attachments (1)

24160.01.patch (522 bytes) - added by r-a-y 8 years ago.

Download all attachments as: .zip

Change History (21)

8 years ago

#1 @SergeyBiryukov
8 years ago

  • Milestone changed from Awaiting Review to 3.6

#2 @SergeyBiryukov
8 years ago

  • Summary changed from ALTERNATE_WP_CRON runs 'init' too late to ALTERNATE_WP_CRON runs 'init' too early

#3 @SergeyBiryukov
8 years ago

  • Summary changed from ALTERNATE_WP_CRON runs 'init' too early to ALTERNATE_WP_CRON runs wp_cron() too early

#4 @r-a-y
8 years ago

Thanks for correcting the ticket title, Sergey!

And thanks for the feedback from the previous ticket.

#5 @prettyboymp
8 years ago

To match where it runs with a normal cron, the hook should probably be changed to 'wp_loaded'.

#6 @ryan
8 years ago

  • Milestone changed from 3.6 to Future Release

#7 @SergeyBiryukov
6 years ago

  • Description modified (diff)
  • Keywords 4.1-early added

#8 @chriscct7
5 years ago

  • Keywords 4.1-early removed

#9 @chriscct7
5 years ago

  • Keywords early added

#11 @peterwilsoncc
2 years ago

  • Milestone set to Future Release
  • Status changed from new to reopened

This is worth some investigation so I'm reopening this and putting it down for a future release. The Cron component has a bit of a backlog, so I won't give a timeframe for now as it would set a false expectation.

#12 @peterwilsoncc
2 years ago

#37542 was marked as a duplicate.

#13 @peterwilsoncc
2 years ago

From #37542:

This can be an issue for sites registering custom taxonomies. Taxos can not be registered prior to the init hook but using the default priority causes the taxo to be registered after the cron hook fires when using alternative cron.

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.

6 months ago

#15 @peterwilsoncc
8 weeks ago

  • Keywords needs-refresh added
  • Milestone changed from Future Release to 5.7
  • Owner set to peterwilsoncc
  • Status changed from reopened to assigned

Moving this on to the 5.7 milestone for an early look.

  • I understand this will have a side-effect of fixing #20537 too
  • It's a backward compatibility break to simply move the action from 10 to a higher number. It's possible to maintain it by using wp_cron to register an action to run later on init. Possible but ugly.

#16 @johnbillion
8 weeks ago

I'm happy to help out with any of these cron tickets Peter, just shout.

#17 @peterwilsoncc
5 weeks ago

Doing some research to determine backward compatibility issues.


  • ten plugins run remove_action( 'init', 'wp_cron' )
  • the three most popular have 300K+, 40K+, and 20K+ installs

I do like @prettyboymp's suggestion above of moving the wp_loaded function to match the execution point in which alternative cron runs to the standard wp-cron. It would probably need to run late on that too (ie, priority 20 or higher).


@johnbillion I think it's safest to go with some ugly code to maintain backward compatibility. What are your thoughts on the following?

wp_cron() renamed to _wp_cron(), wp_cron_loaded() or similar.

wp_cron() continues to run on init, 10 and then looks something like this:

function wp_cron() {
  if ( did_action( 'wp_loaded' ) {
    return _wp_cron();

  add_action( 'wp_loaded', '_wp_cron', 20 );

This ticket was mentioned in Slack in #core by lukecarbis. View the logs.

5 weeks ago

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.

4 weeks ago

This ticket was mentioned in PR #842 on WordPress/wordpress-develop by peterwilsoncc.

4 weeks ago

  • Keywords needs-refresh removed

This ticket was mentioned in Slack in #core by metalandcoffee. View the logs.

3 weeks ago

Note: See TracTickets for help on using tickets.