Ticket #18997: #cron.patch
| File #cron.patch, 4.2 KB (added by , 14 years ago) |
|---|
-
wp-includes/cron.php
25 25 if ( $next && $next <= $timestamp + 600 ) 26 26 return; 27 27 28 $crons = _get_cron_array();29 28 $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args ); 30 29 $event = apply_filters('schedule_event', $event); 31 30 … … 35 34 36 35 $key = md5(serialize($event->args)); 37 36 37 $crons = _get_cron_array(); 38 38 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args ); 39 uksort( $crons, "strnatcasecmp" );40 39 _set_cron_array( $crons ); 41 40 } 42 41 … … 61 60 * @return bool|null False on failure, null when complete with scheduling event. 62 61 */ 63 62 function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) { 64 $crons = _get_cron_array();65 63 $schedules = wp_get_schedules(); 66 64 67 65 if ( !isset( $schedules[$recurrence] ) ) … … 76 74 77 75 $key = md5(serialize($event->args)); 78 76 77 $crons = _get_cron_array(); 79 78 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval ); 80 uksort( $crons, "strnatcasecmp" );81 79 _set_cron_array( $crons ); 82 80 } 83 81 … … 93 91 * @return bool|null False on failure. Null when event is rescheduled. 94 92 */ 95 93 function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array()) { 96 $crons = _get_cron_array();97 $schedules = wp_get_schedules();98 $key = md5(serialize($args));99 94 $interval = 0; 100 95 101 96 // First we try to get it from the schedule 102 if ( 0 == $interval ) 97 $schedules = wp_get_schedules(); 98 if ( !empty( $schedules ) ) 103 99 $interval = $schedules[$recurrence]['interval']; 100 104 101 // Now we try to get it from the saved interval in case the schedule disappears 105 if ( 0 == $interval ) 106 $interval = $crons[$timestamp][$hook][$key]['interval']; 102 if ( 0 == $interval ) { 103 $crons = _get_cron_array(); 104 if ( !empty( $crons ) ) { 105 $key = md5( serialize( $args ) ); 106 $interval = $crons[$timestamp][$hook][$key]['interval']; 107 } 108 } 107 109 // Now we assume something is wrong and fail to schedule 108 110 if ( 0 == $interval ) 109 111 return false; … … 135 137 */ 136 138 function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 137 139 $crons = _get_cron_array(); 140 if ( empty( $crons ) ) 141 return; 138 142 $key = md5(serialize($args)); 139 143 unset( $crons[$timestamp][$hook][$key] ); 140 144 if ( empty($crons[$timestamp][$hook]) ) 141 145 unset( $crons[$timestamp][$hook] ); 142 if ( empty($crons[$timestamp]) ) 143 unset( $crons[$timestamp] ); 144 _set_cron_array( $crons ); 146 _set_cron_array( $crons, 'removed' ); 145 147 } 146 148 147 149 /** … … 164 166 wp_unschedule_event( $timestamp, $hook, $args ); 165 167 } 166 168 169 /** 170 * Unschedule all previously scheduled cron job for a hook. 171 * 172 * Can be usefull for plugins when deactivating to clean up the cron queue 173 * 174 * The $hook parameter is required, so that the events can be 175 * identified. 176 * 177 * @since 3.4 178 * 179 * @param string $hook Action hook, the execution of which will be unscheduled. 180 */ 181 function wp_unschedule_hook( $hook ) { 182 $crons = _get_cron_array(); 183 if ( empty( $crons ) ) 184 return; 185 foreach($crons as $timestamp => $args) 186 unset( $crons[$timestamp][$hook] ); 187 _set_cron_array( $crons, 'removed' ); 188 } 189 167 190 /** 168 191 * Retrieve the next timestamp for a cron event. 169 192 * … … 175 198 */ 176 199 function wp_next_scheduled( $hook, $args = array() ) { 177 200 $crons = _get_cron_array(); 201 if ( empty( $crons ) ) 202 return false; 178 203 $key = md5(serialize($args)); 179 if ( empty($crons) )180 return false;181 204 foreach ( $crons as $timestamp => $cron ) { 182 205 if ( isset( $cron[$hook][$key] ) ) 183 206 return $timestamp; … … 373 396 * @access private 374 397 * 375 398 * @param array $cron Cron info array from {@link _get_cron_array()}. 399 * @param string $action Default value 'added'. Other possible values : 'removed'. 376 400 */ 377 function _set_cron_array($cron) { 401 function _set_cron_array($cron, $action = 'added') { 402 if ('added' == $action) 403 uksort( $crons, "strnatcasecmp" ); 404 if ('removed' == $action) 405 $crons = array_filter( $crons ); 378 406 $cron['version'] = 2; 379 407 update_option( 'cron', $cron ); 380 408 }