Make WordPress Core

Changeset 50135

Timestamp:
02/02/2021 03:08:53 AM (4 years ago)
Author:
peterwilsoncc
Message:

Cron API: Run alternative wp-cron later, do not run on archived blogs.

Runs cron jobs later on sites using alternative cron, ie the ALTERNATE_WP_CRON constant is true, to more closely match when standard cron jobs are run. Jobs now run on the wp_loaded hook at priority 20. Prior to this change they would run on the init hook. This ensures custom post types and taxonomies are registered prior to the jobs running.

This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the wp_loaded hook from running.

Moves the existing functionality of wp_cron() in to a new private function _wp_cron().

Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes #20537, #24160.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/cron.php

    r49963 r50135  
    745745
    746746/**
    747  * Run scheduled callbacks or spawn cron for all scheduled events.
     747 * Register _wp_cron() to run on the {@see 'wp_loaded'} action.
     748 *
     749 * If the {@see 'wp_loaded'} action has already fired, this function calls
     750 * _wp_cron() directly.
    748751 *
    749752 * Warning: This function may return Boolean FALSE, but may also return a non-Boolean
     
    754757 * @since 2.1.0
    755758 * @since 5.1.0 Return value added to indicate success or failure.
     759
     760
     761
     762
     763
     764
     765
     766
     767
     768
     769
     770
     771
     772
     773
     774
     775
     776
     777
     778
     779
     780
     781
     782
    756783 *
    757784 * @return int|false On success an integer indicating number of events spawned (0 indicates no
    758785 *                   events needed to be spawned), false if spawning fails for one or more events.
    759786 */
    760 function wp_cron() {
     787function wp_cron() {
    761788    // Prevent infinite loops caused by lack of wp-cron.php.
    762789    if ( strpos( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) !== false || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ) {
Note: See TracChangeset for help on using the changeset viewer.