diff --git a/wp-includes/cron.php b/wp-includes/cron.php index e3bd917e25..a1d33ff58d 100644 --- a/wp-includes/cron.php +++ b/wp-includes/cron.php @@ -744,7 +744,10 @@ function spawn_cron( $gmt_time = 0 ) { } /** - * Run scheduled callbacks or spawn cron for all scheduled events. + * Register _wp_cron() to run on the {@see 'wp_loaded'} action. + * + * If the {@see 'wp_loaded'} action has already fired, this function calls + * _wp_cron() directly. * * Warning: This function may return Boolean FALSE, but may also return a non-Boolean * value which evaluates to FALSE. For information about casting to booleans see the @@ -753,11 +756,35 @@ function spawn_cron( $gmt_time = 0 ) { * * @since 2.1.0 * @since 5.1.0 Return value added to indicate success or failure. + * @since 5.7.0 Functionality moved to _wp_cron() to which this becomes a wrapper. + * + * @return bool|int|void On success an integer indicating number of events spawned (0 indicates no + * events needed to be spawned), false if spawning fails for one or more events or + * void if the function registered _wp_cron() to run on the action. + */ +function wp_cron() { + if ( did_action( 'wp_loaded' ) ) { + return _wp_cron(); + } + + add_action( 'wp_loaded', '_wp_cron', 20 ); +} + +/** + * Run scheduled callbacks or spawn cron for all scheduled events. + * + * Warning: This function may return Boolean FALSE, but may also return a non-Boolean + * value which evaluates to FALSE. For information about casting to booleans see the + * {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use + * the `===` operator for testing the return value of this function. + * + * @since 5.7.0 + * @access private * * @return int|false On success an integer indicating number of events spawned (0 indicates no * events needed to be spawned), false if spawning fails for one or more events. */ -function wp_cron() { +function _wp_cron() { // Prevent infinite loops caused by lack of wp-cron.php. if ( strpos( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) !== false || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ) { return 0; diff --git a/wp-includes/version.php b/wp-includes/version.php index 3b52bfca0b..ea7f042b19 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-alpha-50134'; +$wp_version = '5.7-alpha-50135'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.