Cron: Fix a case where a cache inconsistency can cause wp_clear_scheduled_hook() to enter an infinite loop.

Merges [26782] from 3.8 to the 3.7 branch.

props dd32.
fixes #25773.


git-svn-id: https://develop.svn.wordpress.org/branches/3.7@27886 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2014-04-01 03:39:35 +00:00
parent 5366d9505e
commit a2b79e3f77

View File

@ -160,8 +160,19 @@ function wp_clear_scheduled_hook( $hook, $args = array() ) {
$args = array_slice( func_get_args(), 1 );
}
while ( $timestamp = wp_next_scheduled( $hook, $args ) )
wp_unschedule_event( $timestamp, $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 );
}
}
}
/**