wp_unschedule_event
Unschedule a previously scheduled event.
Description
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
if ( !function_exists( 'wp_unschedule_event' ) ) { require_once ABSPATH . WPINC . '/cron.php'; } // Unix timestamp (UTC) for when to run the event. $timestamp = -1; // Action hook, the execution of which will be unscheduled. $hook = ''; $args = array(); // NOTICE! Understand what this does before running. $result = wp_unschedule_event($timestamp, $hook, $args);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/cron.php
- 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] );
- if ( empty($crons[$timestamp][$hook]) )
- unset( $crons[$timestamp][$hook] );
- if ( empty($crons[$timestamp]) )
- unset( $crons[$timestamp] );
- _set_cron_array( $crons );
- }