Make WordPress Core

Ticket #45797: 45797.2.diff

File 45797.2.diff, 2.5 KB (added by peterwilsoncc, 6 years ago)
  • src/wp-cron.php

    diff --git a/src/wp-cron.php b/src/wp-cron.php
    index acf5ded2d4..d704ceaf84 100644
    a b function _get_cron_lock() { 
    6666        return $value;
    6767}
    6868
    69 if ( false === $crons = _get_cron_array() ) {
     69$crons = wp_get_ready_cron_jobs();
     70if ( empty( $crons ) ) {
    7071        die();
    7172}
    7273
    73 $keys     = array_keys( $crons );
    74 $gmt_time = microtime( true );
    75 
    76 if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) {
    77         die();
    78 }
    79 
    80 
    8174// The cron lock: a unix timestamp from when the cron was spawned.
    8275$doing_cron_transient = get_transient( 'doing_cron' );
    8376
  • src/wp-includes/cron.php

    diff --git a/src/wp-includes/cron.php b/src/wp-includes/cron.php
    index 046c0dca73..c6bb637092 100644
    a b function spawn_cron( $gmt_time = 0 ) { 
    641641        }
    642642
    643643        //sanity check
    644         $crons = _get_cron_array();
    645         if ( ! is_array( $crons ) ) {
     644        $crons = wp_get_ready_cron_jobs();
     645        if ( empty( $crons ) ) {
    646646                return false;
    647647        }
    648648
    function wp_cron() { 
    736736                return 0;
    737737        }
    738738
    739         $crons = _get_cron_array();
    740         if ( false === $crons ) {
     739        $crons = wp_get_ready_cron_jobs();
     740        if ( empty( $crons ) ) {
    741741                return 0;
    742742        }
    743743
    function wp_get_schedule( $hook, $args = array() ) { 
    854854        return apply_filters( 'get_schedule', $schedule, $hook, $args );
    855855}
    856856
     857/**
     858 * Retrieve cron jobs ready to be run.
     859 *
     860 * Returns the results of _get_cron_array() limited to events ready to be run,
     861 * ie, with a timestamp in the past.
     862 *
     863 * @since 5.1.0
     864 *
     865 * @return array Cron jobs ready to be run.
     866 */
     867function wp_get_ready_cron_jobs() {
     868        /**
     869         * Filter to preflight or hijack retrieving ready cron jobs.
     870         *
     871         * Returning an array will short-circuit the normal retrieval of ready
     872         * cron jobs, causing the function to return the filtered value instead.
     873         *
     874         * @since 5.1.0
     875         *
     876         * @param null|array $pre Array of ready cron tasks to return instead. Default null
     877         *                        to continue using results from _get_cron_array().
     878         */
     879        $pre = apply_filters( 'pre_get_ready_cron_jobs', null );
     880        if ( null !== $pre ) {
     881                return $pre;
     882        }
     883
     884        $crons = _get_cron_array();
     885
     886        if ( false === $crons ) {
     887                return array();
     888        }
     889
     890        $gmt_time = microtime( true );
     891        $keys     = array_keys( $crons );
     892        if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) {
     893                return array();
     894        }
     895
     896        $results = array();
     897        foreach ( $crons as $timestamp => $cronhooks ) {
     898                if ( $timestamp > $gmt_time ) {
     899                        break;
     900                }
     901                $results[ $timestamp ] = $cronhooks;
     902        }
     903
     904        return $results;
     905}
     906
    857907//
    858908// Private functions
    859909//