wp_clear_scheduled_hook

Unschedule all events attached to the specified hook.

Description

wp_clear_scheduled_hook( (string) $hook, (array) $args = array() ); 

Parameters (2)

0. $hook (string)
Action hook, the execution of which will be unscheduled.
1. $args — Optional. (array) => array()
Arguments that were to be passed to the hook's callback function.

Usage

  1. if ( !function_exists( 'wp_clear_scheduled_hook' ) ) { 
  2. require_once ABSPATH . WPINC . '/cron.php'; 
  3.  
  4. // Action hook, the execution of which will be unscheduled. 
  5. $hook = ''; 
  6.  
  7. // Optional. Arguments that were to be passed to the hook's callback function. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_clear_scheduled_hook($hook, $args); 
  12.  

Defined (1)

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

/wp-includes/cron.php  
  1. function wp_clear_scheduled_hook( $hook, $args = array() ) { 
  2. // Backward compatibility 
  3. // Previously this function took the arguments as discrete vars rather than an array like the rest of the API 
  4. if ( !is_array($args) ) { 
  5. _deprecated_argument( __FUNCTION__, '3.0.0', __('This argument has changed to an array to match the behavior of the other cron functions.') ); 
  6. $args = array_slice( func_get_args(), 1 ); 
  7.  
  8. // This logic duplicates wp_next_scheduled() 
  9. // It's required due to a scenario where wp_unschedule_event() fails due to update_option() failing,  
  10. // and, wp_next_scheduled() returns the same schedule in an infinite loop. 
  11. $crons = _get_cron_array(); 
  12. if ( empty( $crons ) ) 
  13. return; 
  14.  
  15. $key = md5( serialize( $args ) ); 
  16. foreach ( $crons as $timestamp => $cron ) { 
  17. if ( isset( $cron[ $hook ][ $key ] ) ) { 
  18. wp_unschedule_event( $timestamp, $hook, $args );