WordPress.org

Make WordPress Core

Ticket #21072: 20172.diff

File 20172.diff, 5.4 KB (added by evansolomon, 22 months ago)
  • wp-includes/cron.php

     
    1818 * @param int $timestamp Timestamp for when to run the event. 
    1919 * @param string $hook Action hook to execute when cron is run. 
    2020 * @param array $args Optional. Arguments to pass to the hook's callback function. 
     21 * @return bool False on failure, true when complete with scheduling event. 
    2122 */ 
    2223function wp_schedule_single_event( $timestamp, $hook, $args = array()) { 
    2324        // don't schedule a duplicate if there's already an identical event due in the next 10 minutes 
     
    3738 
    3839        $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args ); 
    3940        uksort( $crons, "strnatcasecmp" ); 
    40         _set_cron_array( $crons ); 
     41        return _set_cron_array( $crons ); 
    4142} 
    4243 
    4344/** 
     
    5859 * @param string $recurrence How often the event should recur. 
    5960 * @param string $hook Action hook to execute when cron is run. 
    6061 * @param array $args Optional. Arguments to pass to the hook's callback function. 
    61  * @return bool|null False on failure, null when complete with scheduling event. 
     62 * @return bool False on failure, true when complete with scheduling event. 
    6263 */ 
    6364function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) { 
    6465        $crons = _get_cron_array(); 
     
    7879 
    7980        $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval ); 
    8081        uksort( $crons, "strnatcasecmp" ); 
    81         _set_cron_array( $crons ); 
     82        return _set_cron_array( $crons ); 
    8283} 
    8384 
    8485/** 
     
    9091 * @param string $recurrence How often the event should recur. 
    9192 * @param string $hook Action hook to execute when cron is run. 
    9293 * @param array $args Optional. Arguments to pass to the hook's callback function. 
    93  * @return bool|null False on failure. Null when event is rescheduled. 
     94 * @return bool False on failure. True when event is rescheduled. 
    9495 */ 
    9596function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array()) { 
    9697        $crons = _get_cron_array(); 
     
    115116        else 
    116117                $timestamp = $now + ($interval - (($now - $timestamp) % $interval)); 
    117118 
    118         wp_schedule_event( $timestamp, $recurrence, $hook, $args ); 
     119        return wp_schedule_event( $timestamp, $recurrence, $hook, $args ); 
    119120} 
    120121 
    121122/** 
     
    132133 * Although not passed to a callback function, these arguments are used 
    133134 * to uniquely identify the scheduled event, so they should be the same 
    134135 * as those used when originally scheduling the event. 
     136 * @return bool False on failure, true when complete with unscheduling event. 
    135137 */ 
    136138function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 
    137139        $crons = _get_cron_array(); 
     
    141143                unset( $crons[$timestamp][$hook] ); 
    142144        if ( empty($crons[$timestamp]) ) 
    143145                unset( $crons[$timestamp] ); 
    144         _set_cron_array( $crons ); 
     146        return _set_cron_array( $crons ); 
    145147} 
    146148 
    147149/** 
     
    151153 * 
    152154 * @param string $hook Action hook, the execution of which will be unscheduled. 
    153155 * @param array $args Optional. Arguments that were to be pass to the hook's callback function. 
     156 * @return array Boolean values, for each unscheduled event with timestamps as keys. 
    154157 */ 
    155158function wp_clear_scheduled_hook( $hook, $args = array() ) { 
    156159        // Backward compatibility 
     
    160163                $args = array_slice( func_get_args(), 1 ); 
    161164        } 
    162165 
    163         while ( $timestamp = wp_next_scheduled( $hook, $args ) ) 
    164                 wp_unschedule_event( $timestamp, $hook, $args ); 
     166        $results = array(); 
     167        while ( $timestamp = wp_next_scheduled( $hook, $args ) ) { 
     168                $results[$timestamp] = wp_unschedule_event( $timestamp, $hook, $args ) 
     169 
     170        return $results; 
    165171} 
    166172 
    167173/** 
     
    190196 * 
    191197 * @since 2.1.0 
    192198 * 
    193  * @return null Cron could not be spawned, because it is not needed to run. 
     199 * @return null|WP_Error|array Null when cron could not be spawned, because it is not needed to run. 
     200 * When cron runs, return the result of wp_remote_post(). 
    194201 */ 
    195202function spawn_cron( $local_time = 0 ) { 
    196203 
     
    245252        set_transient( 'doing_cron', $doing_wp_cron ); 
    246253 
    247254        $cron_url = site_url( 'wp-cron.php?doing_wp_cron=' . $doing_wp_cron ); 
    248         wp_remote_post( $cron_url, array( 'timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters( 'https_local_ssl_verify', true ) ) ); 
     255        return wp_remote_post( $cron_url, array( 'timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters( 'https_local_ssl_verify', true ) ) ); 
    249256} 
    250257 
    251258/** 
     
    253260 * 
    254261 * @since 2.1.0 
    255262 * 
    256  * @return null When doesn't need to run Cron. 
     263 * @return null|array Null when doesn't need to run Cron. Array of spawn_cron() results when cron does run. 
    257264 */ 
    258265function wp_cron() { 
    259266 
     
    269276        if ( isset($keys[0]) && $keys[0] > $local_time ) 
    270277                return; 
    271278 
     279        $results = array(); 
    272280        $schedules = wp_get_schedules(); 
    273281        foreach ( $crons as $timestamp => $cronhooks ) { 
    274282                if ( $timestamp > $local_time ) break; 
    275283                foreach ( (array) $cronhooks as $hook => $args ) { 
    276284                        if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) ) 
    277285                                continue; 
    278                         spawn_cron( $local_time ); 
     286                        $results[] = spawn_cron( $local_time ); 
    279287                        break 2; 
    280288                } 
    281289        } 
     290 
     291        return $results; 
    282292} 
    283293 
    284294/** 
     
    376386 */ 
    377387function _set_cron_array($cron) { 
    378388        $cron['version'] = 2; 
    379         update_option( 'cron', $cron ); 
     389        return update_option( 'cron', $cron ); 
    380390} 
    381391 
    382392/**