Cron: Fix a case where a cache inconsistency can cause wp_clear_scheduled_hook() to enter an infinite loop. This unravels the function from using other cron api functions to looping over the cron array directly. See #25773

git-svn-id: https://develop.svn.wordpress.org/trunk@26782 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2013-12-07 09:12:51 +00:00
parent 821b80eba4
commit 457e59656a
1 changed files with 13 additions and 2 deletions

View File

@ -168,9 +168,20 @@ function wp_clear_scheduled_hook( $hook, $args = array() ) {
$args = array_slice( func_get_args(), 1 ); $args = array_slice( func_get_args(), 1 );
} }
while ( $timestamp = wp_next_scheduled( $hook, $args ) ) // This logic duplicates wp_next_scheduled()
// It's required due to a scenario where wp_unschedule_event() fails due to update_option() failing,
// and, wp_next_scheduled() returns the same schedule in an infinite loop.
$crons = _get_cron_array();
if ( empty( $crons ) )
return;
$key = md5( serialize( $args ) );
foreach ( $crons as $timestamp => $cron ) {
if ( isset( $cron[ $hook ][ $key ] ) ) {
wp_unschedule_event( $timestamp, $hook, $args ); wp_unschedule_event( $timestamp, $hook, $args );
} }
}
}
/** /**
* Retrieve the next timestamp for a cron event. * Retrieve the next timestamp for a cron event.