diff --git src/wp-includes/cron.php src/wp-includes/cron.php
index fbf5a629af..1a386bb110 100644
|
|
|
|
| 21 | 21 | * Use wp_schedule_event() to schedule a recurring event. |
| 22 | 22 | * |
| 23 | 23 | * @since 2.1.0 |
| | 24 | * @since 5.0.0 Return value modified to boolean indicating success or failure. |
| | 25 | * |
| 24 | 26 | * @link https://codex.wordpress.org/Function_Reference/wp_schedule_single_event |
| 25 | 27 | * |
| 26 | 28 | * @param int $timestamp Unix timestamp (UTC) for when to next run the event. |
| 27 | 29 | * @param string $hook Action hook to execute when the event is run. |
| 28 | 30 | * @param array $args Optional. Array containing each separate argument to pass to the hook's callback function. |
| 29 | | * @return false|void False if the event did not get scheduled. |
| | 31 | * @return bool True if event successfully scheduled. False for failure. |
| 30 | 32 | */ |
| 31 | 33 | function wp_schedule_single_event( $timestamp, $hook, $args = array() ) { |
| 32 | 34 | // Make sure timestamp is a positive integer |
| … |
… |
function wp_schedule_single_event( $timestamp, $hook, $args = array() ) {
|
| 77 | 79 | 'args' => $event->args, |
| 78 | 80 | ); |
| 79 | 81 | uksort( $crons, 'strnatcasecmp' ); |
| 80 | | _set_cron_array( $crons ); |
| | 82 | return _set_cron_array( $crons ); |
| 81 | 83 | } |
| 82 | 84 | |
| 83 | 85 | /** |
| … |
… |
function wp_schedule_single_event( $timestamp, $hook, $args = array() ) {
|
| 99 | 101 | * Use wp_schedule_single_event() to schedule a non-recurring event. |
| 100 | 102 | * |
| 101 | 103 | * @since 2.1.0 |
| | 104 | * @since 5.0.0 Return value modified to boolean indicating success or failure. |
| | 105 | * |
| 102 | 106 | * @link https://codex.wordpress.org/Function_Reference/wp_schedule_event |
| 103 | 107 | * |
| 104 | 108 | * @param int $timestamp Unix timestamp (UTC) for when to next run the event. |
| 105 | 109 | * @param string $recurrence How often the event should subsequently recur. See wp_get_schedules() for accepted values. |
| 106 | 110 | * @param string $hook Action hook to execute when the event is run. |
| 107 | 111 | * @param array $args Optional. Array containing each separate argument to pass to the hook's callback function. |
| 108 | | * @return false|void False if the event did not get scheduled. |
| | 112 | * @return bool True if event successfully scheduled. False for failure. |
| 109 | 113 | */ |
| 110 | 114 | function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array() ) { |
| 111 | 115 | // Make sure timestamp is a positive integer |
| … |
… |
function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
|
| 143 | 147 | 'interval' => $event->interval, |
| 144 | 148 | ); |
| 145 | 149 | uksort( $crons, 'strnatcasecmp' ); |
| 146 | | _set_cron_array( $crons ); |
| | 150 | return _set_cron_array( $crons ); |
| 147 | 151 | } |
| 148 | 152 | |
| 149 | 153 | /** |
| 150 | 154 | * Reschedules a recurring event. |
| 151 | 155 | * |
| 152 | 156 | * @since 2.1.0 |
| | 157 | * @since 5.0.0 Return value modified to boolean indicating success or failure. |
| 153 | 158 | * |
| 154 | 159 | * @param int $timestamp Unix timestamp (UTC) for when to next run the event. |
| 155 | 160 | * @param string $recurrence How often the event should subsequently recur. See wp_get_schedules() for accepted values. |
| 156 | 161 | * @param string $hook Action hook to execute when the event is run. |
| 157 | 162 | * @param array $args Optional. Array containing each separate argument to pass to the hook's callback function. |
| 158 | | * @return false|void False if the event did not get rescheduled. |
| | 163 | * @return bool True if event successfully rescheduled. False for failure. |
| 159 | 164 | */ |
| 160 | 165 | function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) { |
| 161 | 166 | // Make sure timestamp is a positive integer |
| … |
… |
function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() )
|
| 189 | 194 | $timestamp = $now + ( $interval - ( ( $now - $timestamp ) % $interval ) ); |
| 190 | 195 | } |
| 191 | 196 | |
| 192 | | wp_schedule_event( $timestamp, $recurrence, $hook, $args ); |
| | 197 | return wp_schedule_event( $timestamp, $recurrence, $hook, $args ); |
| 193 | 198 | } |
| 194 | 199 | |
| 195 | 200 | /** |
| … |
… |
function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() )
|
| 199 | 204 | * identified. |
| 200 | 205 | * |
| 201 | 206 | * @since 2.1.0 |
| | 207 | * @since 5.0.0 Return value modified to boolean indicating success or failure. |
| 202 | 208 | * |
| 203 | 209 | * @param int $timestamp Unix timestamp (UTC) of the event. |
| 204 | 210 | * @param string $hook Action hook of the event. |
| 205 | 211 | * @param array $args Optional. Array containing each separate argument to pass to the hook's callback function. |
| 206 | 212 | * Although not passed to a callback, these arguments are used to uniquely identify the |
| 207 | 213 | * event, so they should be the same as those used when originally scheduling the event. |
| 208 | | * @return false|void False if the event did not get unscheduled. |
| | 214 | * @return bool True if event successfully rescheduled. False for failure. |
| 209 | 215 | */ |
| 210 | 216 | function wp_unschedule_event( $timestamp, $hook, $args = array() ) { |
| 211 | 217 | // Make sure timestamp is a positive integer |
| … |
… |
function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
|
| 222 | 228 | if ( empty( $crons[ $timestamp ] ) ) { |
| 223 | 229 | unset( $crons[ $timestamp ] ); |
| 224 | 230 | } |
| 225 | | _set_cron_array( $crons ); |
| | 231 | return _set_cron_array( $crons ); |
| 226 | 232 | } |
| 227 | 233 | |
| 228 | 234 | /** |
| 229 | 235 | * Unschedules all events attached to the hook with the specified arguments. |
| 230 | 236 | * |
| | 237 | * Warning: This function may return Boolean FALSE, but may also return a non-Boolean |
| | 238 | * value which evaluates to FALSE. For information about casting to booleans see the |
| | 239 | * {@link http://php.net/manual/en/language.types.boolean.php PHP documentation}. Use |
| | 240 | * the `===` operator for testing the return value of this function. |
| | 241 | * |
| 231 | 242 | * @since 2.1.0 |
| | 243 | * @since 5.0.0 Return value modified to indicate success or failure. |
| 232 | 244 | * |
| 233 | 245 | * @param string $hook Action hook, the execution of which will be unscheduled. |
| 234 | 246 | * @param array $args Optional. Arguments that were to be passed to the hook's callback function. |
| | 247 | * @return bool|int On success an integer indicating number of events unscheduled (0 indicates no |
| | 248 | * events were registered with the hook and arguments combination), false if |
| | 249 | * unscheduling one or more events fail. |
| 235 | 250 | */ |
| 236 | 251 | function wp_clear_scheduled_hook( $hook, $args = array() ) { |
| 237 | 252 | // Backward compatibility |
| … |
… |
function wp_clear_scheduled_hook( $hook, $args = array() ) {
|
| 246 | 261 | // and, wp_next_scheduled() returns the same schedule in an infinite loop. |
| 247 | 262 | $crons = _get_cron_array(); |
| 248 | 263 | if ( empty( $crons ) ) { |
| 249 | | return; |
| | 264 | return 0; |
| 250 | 265 | } |
| 251 | 266 | |
| 252 | | $key = md5( serialize( $args ) ); |
| | 267 | $results = array(); |
| | 268 | $key = md5( serialize( $args ) ); |
| 253 | 269 | foreach ( $crons as $timestamp => $cron ) { |
| 254 | 270 | if ( isset( $cron[ $hook ][ $key ] ) ) { |
| 255 | | wp_unschedule_event( $timestamp, $hook, $args ); |
| | 271 | $results[] = wp_unschedule_event( $timestamp, $hook, $args ); |
| 256 | 272 | } |
| 257 | 273 | } |
| | 274 | if ( in_array( false, $results, true ) ) { |
| | 275 | return false; |
| | 276 | } |
| | 277 | return count( $results ); |
| 258 | 278 | } |
| 259 | 279 | |
| 260 | 280 | /** |
| … |
… |
function wp_clear_scheduled_hook( $hook, $args = array() ) {
|
| 262 | 282 | * |
| 263 | 283 | * Can be useful for plugins when deactivating to clean up the cron queue. |
| 264 | 284 | * |
| | 285 | * Warning: This function may return Boolean FALSE, but may also return a non-Boolean |
| | 286 | * value which evaluates to FALSE. For information about casting to booleans see the |
| | 287 | * {@link http://php.net/manual/en/language.types.boolean.php PHP documentation}. Use |
| | 288 | * the `===` operator for testing the return value of this function. |
| | 289 | * |
| 265 | 290 | * @since 4.9.0 |
| | 291 | * @since 5.0.0 Return value added to indicate success or failure. |
| 266 | 292 | * |
| 267 | 293 | * @param string $hook Action hook, the execution of which will be unscheduled. |
| | 294 | * @return bool|int On success an integer indicating number of events unscheduled (0 indicates no |
| | 295 | * events were registered on the hook), false if unscheduling fails. |
| 268 | 296 | */ |
| 269 | 297 | function wp_unschedule_hook( $hook ) { |
| 270 | 298 | $crons = _get_cron_array(); |
| | 299 | if ( empty( $crons ) ) { |
| | 300 | return 0; |
| | 301 | } |
| 271 | 302 | |
| | 303 | $results = array(); |
| 272 | 304 | foreach ( $crons as $timestamp => $args ) { |
| | 305 | if ( ! empty( $crons[ $timestamp ][ $hook ] ) ) { |
| | 306 | $results[] = count( $crons[ $timestamp ][ $hook ] ); |
| | 307 | } |
| 273 | 308 | unset( $crons[ $timestamp ][ $hook ] ); |
| 274 | 309 | |
| 275 | 310 | if ( empty( $crons[ $timestamp ] ) ) { |
| … |
… |
function wp_unschedule_hook( $hook ) {
|
| 277 | 312 | } |
| 278 | 313 | } |
| 279 | 314 | |
| 280 | | _set_cron_array( $crons ); |
| | 315 | if ( _set_cron_array( $crons ) ) { |
| | 316 | return array_sum( $results ); |
| | 317 | } |
| | 318 | return false; |
| 281 | 319 | } |
| 282 | 320 | |
| 283 | 321 | /** |
| … |
… |
function wp_next_scheduled( $hook, $args = array() ) {
|
| 309 | 347 | * Sends a request to run cron through HTTP request that doesn't halt page loading. |
| 310 | 348 | * |
| 311 | 349 | * @since 2.1.0 |
| | 350 | * @since 5.0.0 Return values added. |
| 312 | 351 | * |
| 313 | 352 | * @param int $gmt_time Optional. Unix timestamp (UTC). Default 0 (current time is used). |
| | 353 | * @return false|WP_Error|array False if no events need to run needed to run. |
| | 354 | * When cron runs, return the result of {@see wp_remote_post} |
| 314 | 355 | */ |
| 315 | 356 | function spawn_cron( $gmt_time = 0 ) { |
| 316 | 357 | if ( ! $gmt_time ) { |
| … |
… |
function spawn_cron( $gmt_time = 0 ) {
|
| 318 | 359 | } |
| 319 | 360 | |
| 320 | 361 | if ( defined( 'DOING_CRON' ) || isset( $_GET['doing_wp_cron'] ) ) { |
| 321 | | return; |
| | 362 | return false; |
| 322 | 363 | } |
| 323 | 364 | |
| 324 | 365 | /* |
| … |
… |
function spawn_cron( $gmt_time = 0 ) {
|
| 336 | 377 | |
| 337 | 378 | // don't run if another process is currently running it or more than once every 60 sec. |
| 338 | 379 | if ( $lock + WP_CRON_LOCK_TIMEOUT > $gmt_time ) { |
| 339 | | return; |
| | 380 | return false; |
| 340 | 381 | } |
| 341 | 382 | |
| 342 | 383 | //sanity check |
| 343 | 384 | $crons = _get_cron_array(); |
| 344 | 385 | if ( ! is_array( $crons ) ) { |
| 345 | | return; |
| | 386 | return false; |
| 346 | 387 | } |
| 347 | 388 | |
| 348 | 389 | $keys = array_keys( $crons ); |
| 349 | 390 | if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) { |
| 350 | | return; |
| | 391 | return false; |
| 351 | 392 | } |
| 352 | 393 | |
| 353 | 394 | if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) { |
| 354 | 395 | if ( 'GET' !== $_SERVER['REQUEST_METHOD'] || defined( 'DOING_AJAX' ) || defined( 'XMLRPC_REQUEST' ) ) { |
| 355 | | return; |
| | 396 | return false; |
| 356 | 397 | } |
| 357 | 398 | |
| 358 | 399 | $doing_wp_cron = sprintf( '%.22F', $gmt_time ); |
| … |
… |
function spawn_cron( $gmt_time = 0 ) {
|
| 368 | 409 | flush(); |
| 369 | 410 | |
| 370 | 411 | WP_DEBUG ? include_once( ABSPATH . 'wp-cron.php' ) : @include_once( ABSPATH . 'wp-cron.php' ); |
| 371 | | return; |
| | 412 | return false; |
| 372 | 413 | } |
| 373 | 414 | |
| 374 | 415 | // Set the cron lock with the current unix timestamp, when the cron is being spawned. |
| … |
… |
function spawn_cron( $gmt_time = 0 ) {
|
| 409 | 450 | ), $doing_wp_cron |
| 410 | 451 | ); |
| 411 | 452 | |
| 412 | | wp_remote_post( $cron_request['url'], $cron_request['args'] ); |
| | 453 | return wp_remote_post( $cron_request['url'], $cron_request['args'] ); |
| 413 | 454 | } |
| 414 | 455 | |
| 415 | 456 | /** |
| 416 | 457 | * Run scheduled callbacks or spawn cron for all scheduled events. |
| 417 | 458 | * |
| | 459 | * Warning: This function may return Boolean FALSE, but may also return a non-Boolean |
| | 460 | * value which evaluates to FALSE. For information about casting to booleans see the |
| | 461 | * {@link http://php.net/manual/en/language.types.boolean.php PHP documentation}. Use |
| | 462 | * the `===` operator for testing the return value of this function. |
| | 463 | * |
| 418 | 464 | * @since 2.1.0 |
| | 465 | * @since 5.0.0 Return value added to indicate success or failure. |
| | 466 | * |
| | 467 | * @return bool|int On success an integer indicating number of events spawned (0 indicates no |
| | 468 | * events needed to be spawned), false if spawning fails for one or more events. |
| 419 | 469 | */ |
| 420 | 470 | function wp_cron() { |
| 421 | 471 | // Prevent infinite loops caused by lack of wp-cron.php |
| 422 | 472 | if ( strpos( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) !== false || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ) { |
| 423 | | return; |
| | 473 | return 0; |
| 424 | 474 | } |
| 425 | 475 | |
| 426 | | if ( false === $crons = _get_cron_array() ) { |
| 427 | | return; |
| | 476 | $crons = _get_cron_array(); |
| | 477 | if ( false === $crons ) { |
| | 478 | return 0; |
| 428 | 479 | } |
| 429 | 480 | |
| 430 | 481 | $gmt_time = microtime( true ); |
| 431 | 482 | $keys = array_keys( $crons ); |
| 432 | 483 | if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) { |
| 433 | | return; |
| | 484 | return 0; |
| 434 | 485 | } |
| 435 | 486 | |
| 436 | 487 | $schedules = wp_get_schedules(); |
| | 488 | $results = array(); |
| 437 | 489 | foreach ( $crons as $timestamp => $cronhooks ) { |
| 438 | 490 | if ( $timestamp > $gmt_time ) { |
| 439 | 491 | break; |
| … |
… |
function wp_cron() {
|
| 442 | 494 | if ( isset( $schedules[ $hook ]['callback'] ) && ! call_user_func( $schedules[ $hook ]['callback'] ) ) { |
| 443 | 495 | continue; |
| 444 | 496 | } |
| 445 | | spawn_cron( $gmt_time ); |
| | 497 | if ( is_wp_error( spawn_cron( $gmt_time ) ) ) { |
| | 498 | $results[] = false; |
| | 499 | } |
| | 500 | $results[] = true; |
| 446 | 501 | break 2; |
| 447 | 502 | } |
| 448 | 503 | } |
| | 504 | |
| | 505 | if ( in_array( false, $results, true ) ) { |
| | 506 | return false; |
| | 507 | } |
| | 508 | return count( $results ); |
| | 509 | |
| 449 | 510 | } |
| 450 | 511 | |
| 451 | 512 | /** |
| … |
… |
function _get_cron_array() {
|
| 558 | 619 | * Updates the CRON option with the new CRON array. |
| 559 | 620 | * |
| 560 | 621 | * @since 2.1.0 |
| | 622 | * @since 5.0.0 Return value modified to outcome of {@see update_option}. |
| | 623 | * |
| 561 | 624 | * @access private |
| 562 | 625 | * |
| 563 | 626 | * @param array $cron Cron info array from _get_cron_array(). |
| | 627 | * @return bool True if cron array updated, false on failure. |
| 564 | 628 | */ |
| 565 | 629 | function _set_cron_array( $cron ) { |
| 566 | 630 | $cron['version'] = 2; |
| 567 | | update_option( 'cron', $cron ); |
| | 631 | return update_option( 'cron', $cron ); |
| 568 | 632 | } |
| 569 | 633 | |
| 570 | 634 | /** |
diff --git tests/phpunit/tests/cron.php tests/phpunit/tests/cron.php
index 8caab773d9..1c8ec97a1a 100644
|
|
|
class Tests_Cron extends WP_UnitTestCase {
|
| 29 | 29 | $hook = __FUNCTION__; |
| 30 | 30 | $timestamp = strtotime( '+1 hour' ); |
| 31 | 31 | |
| 32 | | wp_schedule_single_event( $timestamp, $hook ); |
| | 32 | $scheduled = wp_schedule_single_event( $timestamp, $hook ); |
| | 33 | $this->assertTrue( $scheduled ); |
| 33 | 34 | $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); |
| 34 | 35 | |
| 35 | 36 | // it's a non recurring event |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 43 | 44 | $timestamp = strtotime( '+1 hour' ); |
| 44 | 45 | $args = array( 'foo' ); |
| 45 | 46 | |
| 46 | | wp_schedule_single_event( $timestamp, $hook, $args ); |
| | 47 | $scheduled = wp_schedule_single_event( $timestamp, $hook, $args ); |
| | 48 | $this->assertTrue( $scheduled ); |
| 47 | 49 | // this returns the timestamp only if we provide matching args |
| 48 | 50 | $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) ); |
| 49 | 51 | // these don't match so return nothing |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 60 | 62 | $recur = 'hourly'; |
| 61 | 63 | $timestamp = strtotime( '+1 hour' ); |
| 62 | 64 | |
| 63 | | wp_schedule_event( $timestamp, $recur, $hook ); |
| | 65 | $scheduled = wp_schedule_event( $timestamp, $recur, $hook ); |
| | 66 | $this->assertTrue( $scheduled ); |
| 64 | 67 | // it's scheduled for the right time |
| 65 | 68 | $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); |
| 66 | 69 | // it's a recurring event |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 74 | 77 | $recur = 'hourly'; |
| 75 | 78 | $args = array( 'foo' ); |
| 76 | 79 | |
| 77 | | wp_schedule_event( $timestamp, 'hourly', $hook, $args ); |
| | 80 | $scheduled = wp_schedule_event( $timestamp, 'hourly', $hook, $args ); |
| | 81 | $this->assertTrue( $scheduled ); |
| 78 | 82 | // this returns the timestamp only if we provide matching args |
| 79 | 83 | $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) ); |
| 80 | 84 | // these don't match so return nothing |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 94 | 98 | $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); |
| 95 | 99 | |
| 96 | 100 | // now unschedule it and make sure it's gone |
| 97 | | wp_unschedule_event( $timestamp, $hook ); |
| | 101 | $unscheduled = wp_unschedule_event( $timestamp, $hook ); |
| | 102 | $this->assertTrue( $unscheduled ); |
| 98 | 103 | $this->assertEquals( false, wp_next_scheduled( $hook ) ); |
| 99 | 104 | } |
| 100 | 105 | |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 113 | 118 | $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); |
| 114 | 119 | |
| 115 | 120 | // clear the schedule for the no args events and make sure it's gone |
| 116 | | wp_clear_scheduled_hook( $hook ); |
| | 121 | $hook_unscheduled = wp_clear_scheduled_hook( $hook ); |
| | 122 | $this->assertSame( 2, $hook_unscheduled ); |
| 117 | 123 | $this->assertFalse( wp_next_scheduled( $hook ) ); |
| 118 | 124 | // the args events should still be there |
| 119 | 125 | $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 124 | 130 | $this->assertFalse( wp_next_scheduled( $hook, $args ) ); |
| 125 | 131 | } |
| 126 | 132 | |
| | 133 | function test_clear_undefined_schedule() { |
| | 134 | $hook = __FUNCTION__; |
| | 135 | $args = array( 'arg1' ); |
| | 136 | |
| | 137 | wp_schedule_single_event( strtotime( '+1 hour' ), $hook, $args ); |
| | 138 | wp_schedule_single_event( strtotime( '+2 hour' ), $hook, $args ); |
| | 139 | |
| | 140 | // clear the schedule for no args events and ensure no events are cleared. |
| | 141 | $hook_unscheduled = wp_clear_scheduled_hook( $hook ); |
| | 142 | $this->assertSame( 0, $hook_unscheduled ); |
| | 143 | } |
| | 144 | |
| 127 | 145 | function test_clear_schedule_multiple_args() { |
| 128 | 146 | $hook = __FUNCTION__; |
| 129 | 147 | $args = array( 'arg1', 'arg2' ); |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 206 | 224 | $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); |
| 207 | 225 | |
| 208 | 226 | // clear the schedule and make sure it's gone. |
| 209 | | wp_unschedule_hook( $hook ); |
| | 227 | $unschedule_hook = wp_unschedule_hook( $hook ); |
| | 228 | $this->assertSame( 4, $unschedule_hook ); |
| 210 | 229 | $this->assertFalse( wp_next_scheduled( $hook ) ); |
| 211 | 230 | } |
| 212 | 231 | |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 221 | 240 | $ts2 = strtotime( '+3 minutes' ); |
| 222 | 241 | |
| 223 | 242 | // first one works |
| 224 | | wp_schedule_single_event( $ts1, $hook, $args ); |
| | 243 | $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); |
| 225 | 244 | // second one is ignored |
| 226 | | wp_schedule_single_event( $ts2, $hook, $args ); |
| | 245 | $this->assertFalse( wp_schedule_single_event( $ts2, $hook, $args ) ); |
| 227 | 246 | |
| 228 | 247 | // the next event should be at +5 minutes, not +3 |
| 229 | 248 | $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) ); |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 240 | 259 | $ts2 = strtotime( '+3 minutes' ); |
| 241 | 260 | |
| 242 | 261 | // first one works |
| 243 | | wp_schedule_single_event( $ts1, $hook, $args ); |
| | 262 | $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); |
| 244 | 263 | // second works too |
| 245 | | wp_schedule_single_event( $ts2, $hook, $args ); |
| | 264 | $this->assertTrue( wp_schedule_single_event( $ts2, $hook, $args ) ); |
| 246 | 265 | |
| 247 | 266 | // the next event should be at +3 minutes, even though that one was scheduled second |
| 248 | 267 | $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) ); |
| … |
… |
class Tests_Cron extends WP_UnitTestCase {
|
| 259 | 278 | $ts2 = strtotime( '+30 minutes' ); |
| 260 | 279 | |
| 261 | 280 | // first one works |
| 262 | | wp_schedule_single_event( $ts1, $hook, $args ); |
| | 281 | $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); |
| 263 | 282 | // second works too |
| 264 | | wp_schedule_single_event( $ts2, $hook, $args ); |
| | 283 | $this->assertTrue( wp_schedule_single_event( $ts2, $hook, $args ) ); |
| 265 | 284 | |
| 266 | 285 | // the next event should be at +3 minutes |
| 267 | 286 | $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) ); |