Ticket #28213: wp_schedule_single_event-r28372.patch
File wp_schedule_single_event-r28372.patch, 2.1 KB (added by , 7 years ago) |
---|
-
src/wp-includes/cron.php
20 20 * @param array $args Optional. Arguments to pass to the hook's callback function. 21 21 */ 22 22 function wp_schedule_single_event( $timestamp, $hook, $args = array()) { 23 // don't schedule a duplicate if there's already an identical event due in the next 10 minutes23 // don't schedule a duplicate if there's already an identical event due within 10 minutes of it 24 24 $next = wp_next_scheduled($hook, $args); 25 if ( $next && $next <= $timestamp +10 * MINUTE_IN_SECONDS )25 if ( $next && abs( $next - $timestamp) <= 10 * MINUTE_IN_SECONDS ) 26 26 return; 27 27 28 28 $crons = _get_cron_array(); -
tests/phpunit/tests/cron.php
223 223 // second works too 224 224 wp_schedule_single_event( $ts2, $hook, $args ); 225 225 226 // the next event should be at + 5 minutes, not +3226 // the next event should be at +3 minutes, even though that one was scheduled second 227 227 $this->assertEquals( $ts2, wp_next_scheduled($hook, $args) ); 228 228 wp_unschedule_event( $ts2, $hook, $args ); 229 // following event should be there too229 // following event at +30 minutes should be there too 230 230 $this->assertEquals( $ts1, wp_next_scheduled($hook, $args) ); 231 231 } 232 233 function test_not_duplicate_event_reversed() { 234 // duplicate events far apart should work normally regardless of order 235 $hook = rand_str(); 236 $args = array(rand_str()); 237 $ts1 = strtotime('+3 minutes'); 238 $ts2 = strtotime('+30 minutes'); 239 240 // first one works 241 wp_schedule_single_event( $ts1, $hook, $args ); 242 // second works too 243 wp_schedule_single_event( $ts2, $hook, $args ); 244 245 // the next event should be at +3 minutes 246 $this->assertEquals( $ts1, wp_next_scheduled($hook, $args) ); 247 wp_unschedule_event( $ts1, $hook, $args ); 248 // following event should be there too 249 $this->assertEquals( $ts2, wp_next_scheduled($hook, $args) ); 250 } 232 251 } 233 252 234 253 /*