WordPress.org

Make WordPress Core

Changeset 33936


Ignore:
Timestamp:
09/07/15 02:38:12 (21 months ago)
Author:
dd32
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/cron.php

    r32588 r33936  
    1919 * @param string $hook Action hook to execute when cron is run. 
    2020 * @param array $args Optional. Arguments to pass to the hook's callback function. 
    21  * @return void|false 
     21 * @return false|void False when an event is not scheduled. 
    2222 */ 
    2323function wp_schedule_single_event( $timestamp, $hook, $args = array()) { 
    24     // don't schedule a duplicate if there's already an identical event due within 10 minutes of it 
     24    // Make sure timestamp is a positive integer 
     25    if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 
     26        return false; 
     27    } 
     28 
     29    // Don't schedule a duplicate if there's already an identical event due within 10 minutes of it 
    2530    $next = wp_next_scheduled($hook, $args); 
    2631    if ( $next && abs( $next - $timestamp ) <= 10 * MINUTE_IN_SECONDS ) { 
    27         return; 
     32        return false; 
    2833    } 
    2934 
     
    6873 * @param string $hook Action hook to execute when cron is run. 
    6974 * @param array $args Optional. Arguments to pass to the hook's callback function. 
    70  * @return false|void False when does not schedule event. 
     75 * @return false|void False when an event is not scheduled. 
    7176 */ 
    7277function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) { 
     78    // Make sure timestamp is a positive integer 
     79    if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 
     80        return false; 
     81    } 
     82 
    7383    $crons = _get_cron_array(); 
    7484    $schedules = wp_get_schedules(); 
     
    101111 * @param string $hook Action hook to execute when cron is run. 
    102112 * @param array $args Optional. Arguments to pass to the hook's callback function. 
    103  * @return false|void False when does not schedule event. 
     113 * @return false|void False when an event is not scheduled. 
    104114 */ 
    105115function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) { 
     116    // Make sure timestamp is a positive integer 
     117    if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 
     118        return false; 
     119    } 
     120 
    106121    $crons = _get_cron_array(); 
    107122    $schedules = wp_get_schedules(); 
     
    149164 */ 
    150165function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 
     166    // Make sure timestamp is a positive integer 
     167    if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 
     168        return false; 
     169    } 
     170 
    151171    $crons = _get_cron_array(); 
    152172    $key = md5(serialize($args)); 
Note: See TracChangeset for help on using the changeset viewer.