Cron: Reject events when the provided `$timestamp` is not a valid timestamp.

Invalid timestamps were previously accepted by the scheduling functions but would never be run due to our implementation which caused the cron option to forever contain the events.
This rejects such events which most likely only occur due to developer error.

Props utkarshpatel, wonderboymusic, SergeyBiryukov.
See #33423, Fixes #33475

Built from https://develop.svn.wordpress.org/trunk@33936


git-svn-id: http://core.svn.wordpress.org/trunk@33905 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2015-09-07 02:39:23 +00:00
parent 36bda54e88
commit 580ca68e26
2 changed files with 26 additions and 6 deletions

View File

@ -18,13 +18,18 @@
* @param int $timestamp Timestamp for when to run the event.
* @param string $hook Action hook to execute when cron is run.
* @param array $args Optional. Arguments to pass to the hook's callback function.
* @return void|false
* @return false|void False when an event is not scheduled.
*/
function wp_schedule_single_event( $timestamp, $hook, $args = array()) {
// don't schedule a duplicate if there's already an identical event due within 10 minutes of it
// Make sure timestamp is a positive integer
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
return false;
}
// Don't schedule a duplicate if there's already an identical event due within 10 minutes of it
$next = wp_next_scheduled($hook, $args);
if ( $next && abs( $next - $timestamp ) <= 10 * MINUTE_IN_SECONDS ) {
return;
return false;
}
$crons = _get_cron_array();
@ -67,9 +72,14 @@ function wp_schedule_single_event( $timestamp, $hook, $args = array()) {
* @param string $recurrence How often the event should recur.
* @param string $hook Action hook to execute when cron is run.
* @param array $args Optional. Arguments to pass to the hook's callback function.
* @return false|void False when does not schedule event.
* @return false|void False when an event is not scheduled.
*/
function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) {
// Make sure timestamp is a positive integer
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
return false;
}
$crons = _get_cron_array();
$schedules = wp_get_schedules();
@ -100,9 +110,14 @@ function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) {
* @param string $recurrence How often the event should recur.
* @param string $hook Action hook to execute when cron is run.
* @param array $args Optional. Arguments to pass to the hook's callback function.
* @return false|void False when does not schedule event.
* @return false|void False when an event is not scheduled.
*/
function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
// Make sure timestamp is a positive integer
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
return false;
}
$crons = _get_cron_array();
$schedules = wp_get_schedules();
$key = md5( serialize( $args ) );
@ -148,6 +163,11 @@ function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() )
* as those used when originally scheduling the event.
*/
function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
// Make sure timestamp is a positive integer
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
return false;
}
$crons = _get_cron_array();
$key = md5(serialize($args));
unset( $crons[$timestamp][$hook][$key] );

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-33935';
$wp_version = '4.4-alpha-33936';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.