Ticket #35491: 35491-wp_next_scheduled.4.patch
File 35491-wp_next_scheduled.4.patch, 3.1 KB (added by , 9 years ago) |
---|
-
src/wp-includes/cron.php
From dcffe22a0a1ac9c6a36ba65f70348cabc57edcc1 Mon Sep 17 00:00:00 2001 Date: Fri, 22 Apr 2016 15:04:29 +0200 Subject: [PATCH] Updated @dhl's patch with my suggestion in comment #13 & rebased against current master --- src/wp-includes/cron.php | 15 ++++++++++----- tests/phpunit/tests/cron.php | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/cron.php b/src/wp-includes/cron.php index 493e0ec..09ab5e2 100644
a b function wp_clear_scheduled_hook( $hook, $args = array() ) { 214 214 * Retrieve the next timestamp for a cron event. 215 215 * 216 216 * @since 2.1.0 217 * @since 4.6.0 The `$ignore_args` parameter was added. 217 218 * 218 * @param string $hook Action hook to execute when cron is run. 219 * @param array $args Optional. Arguments to pass to the hook's callback function. 219 * @param string $hook Action hook to execute when cron is run. 220 * @param array|false $args Optional. Arguments to pass to the hook's callback function. 221 * @param bool $ignore_args Optional. Whether to check for any event scheduled on the action hook 222 * independently of arguments. Defaults to false. 220 223 * @return false|int The UNIX timestamp of the next time the scheduled event will occur. 221 224 */ 222 function wp_next_scheduled( $hook, $args = array() ) {225 function wp_next_scheduled( $hook, $args = array(), $ignore_args = false ) { 223 226 $crons = _get_cron_array(); 224 227 $key = md5(serialize($args)); 225 if ( empty($crons) ) 228 if ( empty($crons) ) { 226 229 return false; 230 } 227 231 foreach ( $crons as $timestamp => $cron ) { 228 if ( isset( $cron[$hook][$key] ) )232 if ( ( true === $ignore_args && isset( $cron[ $hook ] ) ) || isset( $cron[ $hook ][ $key ] ) ) { 229 233 return $timestamp; 234 } 230 235 } 231 236 return false; 232 237 } -
tests/phpunit/tests/cron.php
diff --git a/tests/phpunit/tests/cron.php b/tests/phpunit/tests/cron.php index b411a5b..59a16c7 100644
a b class Tests_Cron extends WP_UnitTestCase { 85 85 86 86 } 87 87 88 /** 89 * @ticket 35491 90 */ 91 function test_wp_next_scheduled_no_args() { 92 $hook = rand_str(); 93 $ts1 = strtotime( '+30 minutes' ); 94 $ts2 = strtotime( '+2 hours' ); 95 96 $this->assertFalse( wp_next_scheduled( $hook, null, true ) ); 97 98 wp_schedule_event( $ts1, 'hourly', $hook, array( 'foo' ) ); 99 wp_schedule_event( $ts2, 'daily', $hook, array( 'bar' ) ); 100 wp_schedule_event( $ts2, 'twicedaily', $hook, array( 'baz' ) ); 101 102 $this->assertSame( $ts1, wp_next_scheduled( $hook, null, true ) ); 103 104 wp_unschedule_event( $ts1, $hook, array( 'foo' ) ); 105 $this->assertSame( $ts2, wp_next_scheduled( $hook, null, true ) ); 106 107 wp_unschedule_event( $ts2, $hook, array( 'bar' ) ); 108 $this->assertSame( $ts2, wp_next_scheduled( $hook, null, true ) ); 109 110 wp_unschedule_event( $ts2, $hook, array( 'baz' ) ); 111 $this->assertFalse( wp_next_scheduled( $hook, null, true ) ); 112 } 113 88 114 function test_unschedule_event() { 89 115 // schedule an event and make sure it's returned by wp_next_scheduled 90 116 $hook = rand_str();