wp_unschedule_event( int $timestamp, string $hook, array $args = array(), bool $wp_error = false )
Unschedules a previously scheduled event.
Description
The $timestamp
and $hook
parameters are required so that the event can be identified.
Parameters
- $timestamp
-
(Required) Unix timestamp (UTC) of the event.
- $hook
-
(Required) Action hook of the event.
- $args
-
(Optional) Array containing each separate argument to pass to the hook's callback function.<br> Although not passed to a callback, these arguments are used to uniquely identify the event, so they should be the same as those used when originally scheduling the event.<br>
Default value: array()
- $wp_error
-
(Optional) Whether to return a WP_Error on failure.
Default value: false
Return
(bool|WP_Error) True if event successfully unscheduled. False or WP_Error on failure.
Source
File: 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 );
}
Changelog
Version | Description |
---|---|
5.7.0 | The $wp_error parameter was added. |
5.1.0 | Return value modified to boolean indicating success or failure, 'pre_unschedule_event' filter added to short-circuit the function. |
2.1.0 | Introduced. |