Ticket #32656: 32656-30apr2016.diff
File 32656-30apr2016.diff, 7.3 KB (added by , 7 years ago) |
---|
-
wp-includes/cron.php
26 26 return false; 27 27 } 28 28 29 $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args ); 30 31 /** 32 * Filter to preflight or hijack scheduling an event. 33 * 34 * Passing a non-null value will short-circuit adding the event to the cron 35 * array, returning the passed value instead. 36 * 37 * Both single events and recurring events are passed through this filter; 38 * single events have `$event->schedule` as false, whereas recurring events 39 * have this set to a recurrence from {@see wp_get_schedules}. Recurring 40 * events also have the integer recurrence interval set as `$event->interval` 41 * 42 * @param null|mixed $pre Value to return instead. Default null to continue adding the event. 43 * @param object $event An object containing the event's data. 44 */ 45 $pre = apply_filters( 'pre_schedule_event', null, $event ); 46 if ( null !== $pre ) { 47 return $pre; 48 } 49 29 50 // Don't schedule a duplicate if there's already an identical event due within 10 minutes of it 30 51 $next = wp_next_scheduled($hook, $args); 31 52 if ( $next && abs( $next - $timestamp ) <= 10 * MINUTE_IN_SECONDS ) { … … 32 53 return false; 33 54 } 34 55 35 $crons = _get_cron_array();36 $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args );37 56 /** 38 57 * Filter a single event before it is scheduled. 39 58 * … … 49 68 50 69 $key = md5(serialize($event->args)); 51 70 71 $crons = _get_cron_array(); 52 72 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args ); 53 73 uksort( $crons, "strnatcasecmp" ); 54 74 _set_cron_array( $crons ); … … 80 100 return false; 81 101 } 82 102 83 $crons = _get_cron_array();84 103 $schedules = wp_get_schedules(); 85 104 86 105 if ( !isset( $schedules[$recurrence] ) ) … … 87 106 return false; 88 107 89 108 $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] ); 109 90 110 /** This filter is documented in wp-includes/cron.php */ 111 $pre = apply_filters( 'pre_schedule_event', null, $event ); 112 if ( null !== $pre ) { 113 return $pre; 114 } 115 116 /** This filter is documented in wp-includes/cron.php */ 91 117 $event = apply_filters( 'schedule_event', $event ); 92 118 93 119 // A plugin disallowed this event … … 96 122 97 123 $key = md5(serialize($event->args)); 98 124 125 $crons = _get_cron_array(); 99 126 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval ); 100 127 uksort( $crons, "strnatcasecmp" ); 101 128 _set_cron_array( $crons ); … … 118 145 return false; 119 146 } 120 147 148 /** 149 * Filter to preflight or hijack rescheduling of events. 150 * 151 * Passing a non-null value will short-circuit the normal rescheduling 152 * process, returning the passed value instead. 153 * 154 * Note that `$recurrence` is the original stored value. This is not 155 * guaranteed to exist when the event is rescheduled, so plugins should 156 * store the interval value and fall back to this if needed. 157 * 158 * @param null|mixed $pre Value to return instead. Default null to continue rescheduling the event. 159 * @param int $timestamp Timestamp for when the event originally ran. 160 * @param string $recurrence How often the event should recur. 161 * @param string $hook Action hook to execute when cron is run. 162 * @param array $args Optional. Arguments to pass to the hook's callback function. 163 */ 164 $pre = apply_filters( 'pre_reschedule_event', null, $timestamp, $recurrence, $hook, $args ); 165 if ( $pre !== null ) { 166 return $pre; 167 } 168 121 169 $crons = _get_cron_array(); 122 170 $schedules = wp_get_schedules(); 123 171 $key = md5( serialize( $args ) ); … … 169 217 return false; 170 218 } 171 219 220 /** 221 * Filter to preflight or hijack unscheduling of events. 222 * 223 * Passing a non-null value will short-circuit the normal unscheduling 224 * process, returning the passed value instead. 225 * 226 * @param null|mixed $pre Value to return instead. Default null to continue unscheduling the event. 227 * @param int $timestamp Timestamp for when to run the event. 228 * @param string $hook Action hook, the execution of which will be unscheduled. 229 * @param array $args Arguments to pass to the hook's callback function. 230 */ 231 $pre = apply_filters( 'pre_unschedule_event', null, $timestamp, $hook, $args ); 232 if ( $pre !== null ) { 233 return $pre; 234 } 235 172 236 $crons = _get_cron_array(); 173 237 $key = md5(serialize($args)); 174 238 unset( $crons[$timestamp][$hook][$key] ); … … 195 259 $args = array_slice( func_get_args(), 1 ); 196 260 } 197 261 262 /** 263 * Filter to preflight or hijack clearing a scheduled hook. 264 * 265 * Passing a non-null value will short-circuit the normal unscheduling 266 * process, returning the passed value instead. 267 * 268 * @param null|mixed $pre Value to return instead. Default null to continue unscheduling the event. 269 * @param string $hook Action hook, the execution of which will be unscheduled. 270 * @param array $args Arguments to pass to the hook's callback function. 271 */ 272 $pre = apply_filters( 'pre_clear_scheduled_hook', null, $hook, $args ); 273 if ( $pre !== null ) { 274 return $pre; 275 } 276 198 277 // This logic duplicates wp_next_scheduled() 199 278 // It's required due to a scenario where wp_unschedule_event() fails due to update_option() failing, 200 279 // and, wp_next_scheduled() returns the same schedule in an infinite loop. … … 222 301 function wp_next_scheduled( $hook, $args = array() ) { 223 302 $crons = _get_cron_array(); 224 303 $key = md5(serialize($args)); 225 if ( empty($crons) ) 226 return false; 227 foreach ( $crons as $timestamp => $cron ) { 228 if ( isset( $cron[$hook][$key] ) ) 229 return $timestamp; 304 $next = false; 305 306 if ( ! empty($crons) ) { 307 foreach ( $crons as $timestamp => $cron ) { 308 if ( isset( $cron[$hook][$key] ) ) { 309 $next = $timestamp; 310 break; 311 } 312 } 230 313 } 231 return false; 314 315 /** 316 * Filter the next scheduled event timestamp. 317 * 318 * @param int|boolean The UNIX timestamp when the scheduled event will next occur, or false if not found. 319 * @param string $hook Action hook to execute when cron is run. 320 * @param array $args Arguments to be passed to the callback function. Used for deduplicating events. 321 */ 322 return apply_filters( 'next_scheduled', $next, $hook, $args ); 232 323 } 233 324 234 325 /** … … 417 508 function wp_get_schedule($hook, $args = array()) { 418 509 $crons = _get_cron_array(); 419 510 $key = md5(serialize($args)); 420 if ( empty($crons) ) 421 return false; 422 foreach ( $crons as $timestamp => $cron ) { 423 if ( isset( $cron[$hook][$key] ) ) 424 return $cron[$hook][$key]['schedule']; 511 $schedule = false; 512 if ( ! empty($crons) ) { 513 foreach ( $crons as $timestamp => $cron ) { 514 if ( isset( $cron[$hook][$key] ) ) { 515 $schedule = $cron[$hook][$key]['schedule']; 516 break; 517 } 518 } 425 519 } 426 return false; 520 521 /** 522 * Filter the schedule for a hook. 523 * 524 * @param string|boolean $schedule Schedule for the hook. False if not found. 525 * @param string $hook Action hook to execute when cron is run. 526 * @param array $args Optional. Arguments to pass to the hook's callback function. 527 */ 528 return apply_filters( 'get_schedule', $schedule, $hook, $args ); 427 529 } 428 530 429 531 //