Ticket #21072: 20172.diff
| File 20172.diff, 5.4 KB (added by evansolomon, 11 months ago) |
|---|
-
wp-includes/cron.php
18 18 * @param int $timestamp Timestamp for when to run the event. 19 19 * @param string $hook Action hook to execute when cron is run. 20 20 * @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. 21 22 */ 22 23 function wp_schedule_single_event( $timestamp, $hook, $args = array()) { 23 24 // don't schedule a duplicate if there's already an identical event due in the next 10 minutes … … 37 38 38 39 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args ); 39 40 uksort( $crons, "strnatcasecmp" ); 40 _set_cron_array( $crons );41 return _set_cron_array( $crons ); 41 42 } 42 43 43 44 /** … … 58 59 * @param string $recurrence How often the event should recur. 59 60 * @param string $hook Action hook to execute when cron is run. 60 61 * @param array $args Optional. Arguments to pass to the hook's callback function. 61 * @return bool |null False on failure, nullwhen complete with scheduling event.62 * @return bool False on failure, true when complete with scheduling event. 62 63 */ 63 64 function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) { 64 65 $crons = _get_cron_array(); … … 78 79 79 80 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval ); 80 81 uksort( $crons, "strnatcasecmp" ); 81 _set_cron_array( $crons );82 return _set_cron_array( $crons ); 82 83 } 83 84 84 85 /** … … 90 91 * @param string $recurrence How often the event should recur. 91 92 * @param string $hook Action hook to execute when cron is run. 92 93 * @param array $args Optional. Arguments to pass to the hook's callback function. 93 * @return bool |null False on failure. Nullwhen event is rescheduled.94 * @return bool False on failure. True when event is rescheduled. 94 95 */ 95 96 function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array()) { 96 97 $crons = _get_cron_array(); … … 115 116 else 116 117 $timestamp = $now + ($interval - (($now - $timestamp) % $interval)); 117 118 118 wp_schedule_event( $timestamp, $recurrence, $hook, $args );119 return wp_schedule_event( $timestamp, $recurrence, $hook, $args ); 119 120 } 120 121 121 122 /** … … 132 133 * Although not passed to a callback function, these arguments are used 133 134 * to uniquely identify the scheduled event, so they should be the same 134 135 * as those used when originally scheduling the event. 136 * @return bool False on failure, true when complete with unscheduling event. 135 137 */ 136 138 function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 137 139 $crons = _get_cron_array(); … … 141 143 unset( $crons[$timestamp][$hook] ); 142 144 if ( empty($crons[$timestamp]) ) 143 145 unset( $crons[$timestamp] ); 144 _set_cron_array( $crons );146 return _set_cron_array( $crons ); 145 147 } 146 148 147 149 /** … … 151 153 * 152 154 * @param string $hook Action hook, the execution of which will be unscheduled. 153 155 * @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. 154 157 */ 155 158 function wp_clear_scheduled_hook( $hook, $args = array() ) { 156 159 // Backward compatibility … … 160 163 $args = array_slice( func_get_args(), 1 ); 161 164 } 162 165 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; 165 171 } 166 172 167 173 /** … … 190 196 * 191 197 * @since 2.1.0 192 198 * 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(). 194 201 */ 195 202 function spawn_cron( $local_time = 0 ) { 196 203 … … 245 252 set_transient( 'doing_cron', $doing_wp_cron ); 246 253 247 254 $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 ) ) ); 249 256 } 250 257 251 258 /** … … 253 260 * 254 261 * @since 2.1.0 255 262 * 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. 257 264 */ 258 265 function wp_cron() { 259 266 … … 269 276 if ( isset($keys[0]) && $keys[0] > $local_time ) 270 277 return; 271 278 279 $results = array(); 272 280 $schedules = wp_get_schedules(); 273 281 foreach ( $crons as $timestamp => $cronhooks ) { 274 282 if ( $timestamp > $local_time ) break; 275 283 foreach ( (array) $cronhooks as $hook => $args ) { 276 284 if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) ) 277 285 continue; 278 spawn_cron( $local_time );286 $results[] = spawn_cron( $local_time ); 279 287 break 2; 280 288 } 281 289 } 290 291 return $results; 282 292 } 283 293 284 294 /** … … 376 386 */ 377 387 function _set_cron_array($cron) { 378 388 $cron['version'] = 2; 379 update_option( 'cron', $cron );389 return update_option( 'cron', $cron ); 380 390 } 381 391 382 392 /**
