Ticket #15148: 15148.diff
File 15148.diff, 4.7 KB (added by , 13 years ago) |
---|
-
wp-includes/cron.php
33 33 if ( ! $event ) 34 34 return false; 35 35 36 $key = md5(serialize($event->args)); 37 38 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args ); 39 uksort( $crons, "strnatcasecmp" ); 40 _set_cron_array( $crons ); 36 wp_cron_insert_event($event); 41 37 } 42 38 43 39 /** … … 72 68 if ( ! $event ) 73 69 return false; 74 70 75 $key = md5(serialize($event->args)); 76 77 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval ); 78 uksort( $crons, "strnatcasecmp" ); 79 _set_cron_array( $crons ); 71 wp_cron_insert_event($event); 80 72 } 81 73 82 74 /** … … 97 89 $interval = 0; 98 90 99 91 // First we try to get it from the schedule 100 if ( 0 == $interval)92 if ( isset($schedules[$recurrence]) ) 101 93 $interval = $schedules[$recurrence]['interval']; 102 94 // Now we try to get it from the saved interval in case the schedule disappears 103 if ( 0 == $interval ) 104 $interval = $crons[$timestamp][$hook][$key]['interval']; 95 if ( 0 == $interval ) { 96 $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'args' => $args ); 97 $event = wp_cron_get_event( $event ); 98 if ( $event ) 99 $interval = $event->interval; 100 } 105 101 // Now we assume something is wrong and fail to schedule 106 102 if ( 0 == $interval ) 107 103 return false; … … 132 128 * as those used when originally scheduling the event. 133 129 */ 134 130 function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 135 $crons = _get_cron_array(); 136 $key = md5(serialize($args)); 137 unset( $crons[$timestamp][$hook][$key] ); 138 if ( empty($crons[$timestamp][$hook]) ) 139 unset( $crons[$timestamp][$hook] ); 140 if ( empty($crons[$timestamp]) ) 141 unset( $crons[$timestamp] ); 142 _set_cron_array( $crons ); 131 $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'args' => $args ); 132 wp_cron_delete_event($event); 143 133 } 144 134 145 135 /** … … 172 162 * @return bool|int The UNIX timestamp of the next time the scheduled event will occur. 173 163 */ 174 164 function wp_next_scheduled( $hook, $args = array() ) { 175 $crons = _get_cron_array(); 176 $key = md5(serialize($args)); 177 if ( empty($crons) ) 165 $event = (object) array( 'hook' => $hook, 'timestamp' => 'next', 'args' => $args ); 166 167 $event = wp_cron_get_event( $event ); 168 169 if ( !$event ) 178 170 return false; 179 foreach ( $crons as $timestamp => $cron ) { 180 if ( isset( $cron[$hook][$key] ) ) 181 return $timestamp; 182 } 183 return false; 171 172 return $event->timestamp; 184 173 } 185 174 186 175 /** … … 349 338 // Private functions 350 339 // 351 340 341 function wp_cron_delete_event( $event ) { 342 if ( null !== $result = apply_filters('wp_cron_delete_event', null, $event) ) 343 return $result; 344 345 $crons = _get_cron_array(); 346 $key = md5(serialize($event->args)); 347 unset( $crons[$event->timestamp][$event->hook][$key] ); 348 if ( empty($crons[$event->timestamp][$event->hook]) ) 349 unset( $crons[$event->timestamp][$event->hook] ); 350 if ( empty($crons[$event->timestamp]) ) 351 unset( $crons[$event->timestamp] ); 352 _set_cron_array( $crons ); 353 } 354 355 function wp_cron_get_event( $event ) { 356 if ( null !== $result = apply_filters('wp_cron_get_event', null, $event) ) 357 return $result; 358 359 $crons = _get_cron_array(); 360 $key = md5(serialize($event->args)); 361 if ( empty($crons) ) 362 return false; 363 364 if ( empty($event->timestamp) || 'next' == $event->timestamp ) { 365 foreach ( $crons as $timestamp => $cron ) { 366 if ( isset( $cron[$event->hook][$key] ) ) 367 return (object) array( 'hook' => $event->hook, 'args' => $event->args, 'timestamp' => $timestamp, 'schedule' => $cron[$event->hook][$key]['schedule'], 'interval' => $cron[$event->hook][$key]['interval']); 368 } 369 return false; 370 } 371 372 if ( isset($cron[$event->timestamp][$event->hook][$key]) ) 373 return (object) array( 'hook' => $event->hook, 'args' => $event->args, 'timestamp' => $event->timestamp, 'schedule' => $cron[$event->timestamp][$event->hook][$key]['schedule'], 'interval' => $cron[$event->timestamp][$event->hook][$key]['interval']); 374 375 return false; 376 } 377 378 function wp_cron_get_events( $args ) { 379 if ( null !== $result = apply_filters('wp_cron_get_events', null, $args) ) 380 return $result; 381 382 // @todo 383 return null; 384 } 385 386 function wp_cron_insert_event( $event ) { 387 if ( null !== $result = apply_filters('wp_cron_insert_event', null, $event) ) 388 return $result; 389 390 $key = md5(serialize($event->args)); 391 392 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval ); 393 uksort( $crons, "strnatcasecmp" ); 394 _set_cron_array( $crons ); 395 } 396 352 397 /** 353 398 * Retrieve cron info array option. 354 399 *