wp_unschedule_event

Unschedule a previously scheduled event.

Description

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

The $timestamp and $hook parameters are required so that the event can be identified.

Returns (false|void)

False if the event does not get unscheduled.

Parameters (3)

0. $timestamp (int)
Unix timestamp (UTC) for when to run the event.
1. $hook (string)
Action hook, the execution of which will be unscheduled.
2. $args — Optional. (array) => array()
Arguments to pass to the hook's callback function. Although not passed to a callback function, these arguments are used to uniquely identify the scheduled event, so they should be the same as those used when originally scheduling the event.

Usage

  1. if ( !function_exists( 'wp_unschedule_event' ) ) { 
  2. require_once ABSPATH . WPINC . '/cron.php'; 
  3.  
  4. // Unix timestamp (UTC) for when to run the event. 
  5. $timestamp = -1; 
  6.  
  7. // Action hook, the execution of which will be unscheduled. 
  8. $hook = ''; 
  9. $args = array(); 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = wp_unschedule_event($timestamp, $hook, $args); 
  13.  

Defined (1)

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

/wp-includes/cron.php  
  1. function wp_unschedule_event( $timestamp, $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. $key = md5(serialize($args)); 
  8. unset( $crons[$timestamp][$hook][$key] ); 
  9. if ( empty($crons[$timestamp][$hook]) ) 
  10. unset( $crons[$timestamp][$hook] ); 
  11. if ( empty($crons[$timestamp]) ) 
  12. unset( $crons[$timestamp] ); 
  13. _set_cron_array( $crons );