wp_reschedule_event

Reschedule a recurring event.

Description

(false|void) wp_reschedule_event( (int) $timestamp, (string) $recurrence, (string) $hook, (array) $args = array() ); 

Returns (false|void)

False if the event does not get rescheduled.

Parameters (4)

0. $timestamp (int)
Unix timestamp (UTC) for when to run the event.
1. $recurrence (string)
How often the event should recur.
2. $hook (string)
Action hook to execute when event is run.
3. $args — Optional. (array) => array()
Arguments to pass to the hook's callback function.

Usage

  1. if ( !function_exists( 'wp_reschedule_event' ) ) { 
  2. require_once ABSPATH . WPINC . '/cron.php'; 
  3.  
  4. // Unix timestamp (UTC) for when to run the event. 
  5. $timestamp = -1; 
  6.  
  7. // How often the event should recur. 
  8. $recurrence = ''; 
  9.  
  10. // Action hook to execute when event is run. 
  11. $hook = ''; 
  12.  
  13. // Optional. Arguments to pass to the hook's callback function. 
  14. $args = array(); 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wp_reschedule_event($timestamp, $recurrence, $hook, $args); 
  18.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/cron.php  
  1. function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) { 
  2. // Make sure timestamp is a positive integer 
  3. if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 
  4. return false; 
  5.  
  6. $crons = _get_cron_array(); 
  7. $schedules = wp_get_schedules(); 
  8. $key = md5( serialize( $args ) ); 
  9. $interval = 0; 
  10.  
  11. // First we try to get it from the schedule 
  12. if ( isset( $schedules[ $recurrence ] ) ) { 
  13. $interval = $schedules[ $recurrence ]['interval']; 
  14. // Now we try to get it from the saved interval in case the schedule disappears 
  15. if ( 0 == $interval ) { 
  16. $interval = $crons[ $timestamp ][ $hook ][ $key ]['interval']; 
  17. // Now we assume something is wrong and fail to schedule 
  18. if ( 0 == $interval ) { 
  19. return false; 
  20.  
  21. $now = time(); 
  22.  
  23. if ( $timestamp >= $now ) { 
  24. $timestamp = $now + $interval; 
  25. } else { 
  26. $timestamp = $now + ( $interval - ( ( $now - $timestamp ) % $interval ) ); 
  27.  
  28. wp_schedule_event( $timestamp, $recurrence, $hook, $args );