wp_unschedule_event

The timeline below displays how wordpress function wp_unschedule_event has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Unschedules a previously scheduled event.
 *
 * The `$timestamp` and `$hook` parameters are required so that the event can be
 * identified.
 *
 * @since 2.1.0
 * @since 5.1.0 Return value modified to boolean indicating success or failure,
 *              {@see 'pre_unschedule_event'} filter added to short-circuit the function.
 * @since 5.7.0 The `$wp_error` parameter was added.
 *
 * @param int    $timestamp Unix timestamp (UTC) of the event.
 * @param string $hook      Action hook of the event.
 * @param array  $args      Optional. Array containing each separate argument to pass to the hook's callback function.
 *                          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.
 *                          Default empty array.
 * @param bool   $wp_error  Optional. Whether to return a WP_Error on failure. Default false.
 * @return bool|WP_Error True if event successfully unscheduled. False or WP_Error on failure.
 */
function wp_unschedule_event($timestamp, $hook, $args = array(), $wp_error = false)
{
    // Make sure timestamp is a positive integer.
    if (!is_numeric($timestamp) || $timestamp <= 0) {
        if ($wp_error) {
            return new WP_Error('invalid_timestamp', __('Event timestamp must be a valid Unix timestamp.'));
        }
        return false;
    }
    /**
     * Filter to override unscheduling of events.
     *
     * Returning a non-null value will short-circuit the normal unscheduling
     * process, causing the function to return the filtered value instead.
     *
     * For plugins replacing wp-cron, return true if the event was successfully
     * unscheduled, false or a WP_Error if not.
     *
     * @since 5.1.0
     * @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
     *
     * @param null|bool|WP_Error $pre       Value to return instead. Default null to continue unscheduling the event.
     * @param int                $timestamp Timestamp for when to run the event.
     * @param string             $hook      Action hook, the execution of which will be unscheduled.
     * @param array              $args      Arguments to pass to the hook's callback function.
     * @param bool               $wp_error  Whether to return a WP_Error on failure.
     */
    $pre = apply_filters('pre_unschedule_event', null, $timestamp, $hook, $args, $wp_error);
    if (null !== $pre) {
        if ($wp_error && false === $pre) {
            return new WP_Error('pre_unschedule_event_false', __('A plugin prevented the event from being unscheduled.'));
        }
        if (!$wp_error && is_wp_error($pre)) {
            return false;
        }
        return $pre;
    }
    $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]);
    }
    return _set_cron_array($crons, $wp_error);
}

WordPress Version: 6.2

/**
 * Unschedules a previously scheduled event.
 *
 * The `$timestamp` and `$hook` parameters are required so that the event can be
 * identified.
 *
 * @since 2.1.0
 * @since 5.1.0 Return value modified to boolean indicating success or failure,
 *              {@see 'pre_unschedule_event'} filter added to short-circuit the function.
 * @since 5.7.0 The `$wp_error` parameter was added.
 *
 * @param int    $timestamp Unix timestamp (UTC) of the event.
 * @param string $hook      Action hook of the event.
 * @param array  $args      Optional. Array containing each separate argument to pass to the hook's callback function.
 *                          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.
 *                          Default empty array.
 * @param bool   $wp_error  Optional. Whether to return a WP_Error on failure. Default false.
 * @return bool|WP_Error True if event successfully unscheduled. False or WP_Error on failure.
 */
function wp_unschedule_event($timestamp, $hook, $args = array(), $wp_error = false)
{
    // Make sure timestamp is a positive integer.
    if (!is_numeric($timestamp) || $timestamp <= 0) {
        if ($wp_error) {
            return new WP_Error('invalid_timestamp', __('Event timestamp must be a valid Unix timestamp.'));
        }
        return false;
    }
    /**
     * Filter to preflight or hijack unscheduling of events.
     *
     * Returning a non-null value will short-circuit the normal unscheduling
     * process, causing the function to return the filtered value instead.
     *
     * For plugins replacing wp-cron, return true if the event was successfully
     * unscheduled, false or a WP_Error if not.
     *
     * @since 5.1.0
     * @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
     *
     * @param null|bool|WP_Error $pre       Value to return instead. Default null to continue unscheduling the event.
     * @param int                $timestamp Timestamp for when to run the event.
     * @param string             $hook      Action hook, the execution of which will be unscheduled.
     * @param array              $args      Arguments to pass to the hook's callback function.
     * @param bool               $wp_error  Whether to return a WP_Error on failure.
     */
    $pre = apply_filters('pre_unschedule_event', null, $timestamp, $hook, $args, $wp_error);
    if (null !== $pre) {
        if ($wp_error && false === $pre) {
            return new WP_Error('pre_unschedule_event_false', __('A plugin prevented the event from being unscheduled.'));
        }
        if (!$wp_error && is_wp_error($pre)) {
            return false;
        }
        return $pre;
    }
    $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]);
    }
    return _set_cron_array($crons, $wp_error);
}

WordPress Version: 6.1

/**
 * Unschedule a previously scheduled event.
 *
 * The $timestamp and $hook parameters are required so that the event can be
 * identified.
 *
 * @since 2.1.0
 * @since 5.1.0 Return value modified to boolean indicating success or failure,
 *              {@see 'pre_unschedule_event'} filter added to short-circuit the function.
 * @since 5.7.0 The `$wp_error` parameter was added.
 *
 * @param int    $timestamp Unix timestamp (UTC) of the event.
 * @param string $hook      Action hook of the event.
 * @param array  $args      Optional. Array containing each separate argument to pass to the hook's callback function.
 *                          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.
 *                          Default empty array.
 * @param bool   $wp_error  Optional. Whether to return a WP_Error on failure. Default false.
 * @return bool|WP_Error True if event successfully unscheduled. False or WP_Error on failure.
 */
function wp_unschedule_event($timestamp, $hook, $args = array(), $wp_error = false)
{
    // Make sure timestamp is a positive integer.
    if (!is_numeric($timestamp) || $timestamp <= 0) {
        if ($wp_error) {
            return new WP_Error('invalid_timestamp', __('Event timestamp must be a valid Unix timestamp.'));
        }
        return false;
    }
    /**
     * Filter to preflight or hijack unscheduling of events.
     *
     * Returning a non-null value will short-circuit the normal unscheduling
     * process, causing the function to return the filtered value instead.
     *
     * For plugins replacing wp-cron, return true if the event was successfully
     * unscheduled, false or a WP_Error if not.
     *
     * @since 5.1.0
     * @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
     *
     * @param null|bool|WP_Error $pre       Value to return instead. Default null to continue unscheduling the event.
     * @param int                $timestamp Timestamp for when to run the event.
     * @param string             $hook      Action hook, the execution of which will be unscheduled.
     * @param array              $args      Arguments to pass to the hook's callback function.
     * @param bool               $wp_error  Whether to return a WP_Error on failure.
     */
    $pre = apply_filters('pre_unschedule_event', null, $timestamp, $hook, $args, $wp_error);
    if (null !== $pre) {
        if ($wp_error && false === $pre) {
            return new WP_Error('pre_unschedule_event_false', __('A plugin prevented the event from being unscheduled.'));
        }
        if (!$wp_error && is_wp_error($pre)) {
            return false;
        }
        return $pre;
    }
    $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]);
    }
    return _set_cron_array($crons, $wp_error);
}

WordPress Version: 5.7

/**
 * Unschedule a previously scheduled event.
 *
 * The $timestamp and $hook parameters are required so that the event can be
 * identified.
 *
 * @since 2.1.0
 * @since 5.1.0 Return value modified to boolean indicating success or failure,
 *              {@see 'pre_unschedule_event'} filter added to short-circuit the function.
 * @since 5.7.0 The `$wp_error` parameter was added.
 *
 * @param int    $timestamp Unix timestamp (UTC) of the event.
 * @param string $hook      Action hook of the event.
 * @param array  $args      Optional. Array containing each separate argument to pass to the hook's callback function.
 *                          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.
 *                          Default empty array.
 * @param bool   $wp_error  Optional. Whether to return a WP_Error on failure. Default false.
 * @return bool|WP_Error True if event successfully unscheduled. False or WP_Error on failure.
 */
function wp_unschedule_event($timestamp, $hook, $args = array(), $wp_error = false)
{
    // Make sure timestamp is a positive integer.
    if (!is_numeric($timestamp) || $timestamp <= 0) {
        if ($wp_error) {
            return new WP_Error('invalid_timestamp', __('Event timestamp must be a valid Unix timestamp.'));
        }
        return false;
    }
    /**
     * Filter to preflight or hijack unscheduling of events.
     *
     * Returning a non-null value will short-circuit the normal unscheduling
     * process, causing the function to return the filtered value instead.
     *
     * For plugins replacing wp-cron, return true if the event was successfully
     * unscheduled, false if not.
     *
     * @since 5.1.0
     * @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
     *
     * @param null|bool|WP_Error $pre       Value to return instead. Default null to continue unscheduling the event.
     * @param int                $timestamp Timestamp for when to run the event.
     * @param string             $hook      Action hook, the execution of which will be unscheduled.
     * @param array              $args      Arguments to pass to the hook's callback function.
     * @param bool               $wp_error  Whether to return a WP_Error on failure.
     */
    $pre = apply_filters('pre_unschedule_event', null, $timestamp, $hook, $args, $wp_error);
    if (null !== $pre) {
        if ($wp_error && false === $pre) {
            return new WP_Error('pre_unschedule_event_false', __('A plugin prevented the event from being unscheduled.'));
        }
        if (!$wp_error && is_wp_error($pre)) {
            return false;
        }
        return $pre;
    }
    $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]);
    }
    return _set_cron_array($crons, $wp_error);
}

WordPress Version: 5.4

/**
 * Unschedule a previously scheduled event.
 *
 * The $timestamp and $hook parameters are required so that the event can be
 * identified.
 *
 * @since 2.1.0
 * @since 5.1.0 Return value modified to boolean indicating success or failure,
 *              {@see 'pre_unschedule_event'} filter added to short-circuit the function.
 *
 * @param int    $timestamp Unix timestamp (UTC) of the event.
 * @param string $hook      Action hook of the event.
 * @param array  $args      Optional. Array containing each separate argument to pass to the hook's callback function.
 *                          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.
 * @return bool True if event successfully unscheduled. False for failure.
 */
function wp_unschedule_event($timestamp, $hook, $args = array())
{
    // Make sure timestamp is a positive integer.
    if (!is_numeric($timestamp) || $timestamp <= 0) {
        return false;
    }
    /**
     * Filter to preflight or hijack unscheduling of events.
     *
     * Returning a non-null value will short-circuit the normal unscheduling
     * process, causing the function to return the filtered value instead.
     *
     * For plugins replacing wp-cron, return true if the event was successfully
     * unscheduled, false if not.
     *
     * @since 5.1.0
     *
     * @param null|bool $pre       Value to return instead. Default null to continue unscheduling the event.
     * @param int       $timestamp Timestamp for when to run the event.
     * @param string    $hook      Action hook, the execution of which will be unscheduled.
     * @param array     $args      Arguments to pass to the hook's callback function.
     */
    $pre = apply_filters('pre_unschedule_event', null, $timestamp, $hook, $args);
    if (null !== $pre) {
        return $pre;
    }
    $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]);
    }
    return _set_cron_array($crons);
}

WordPress Version: 5.1

/**
 * Unschedule a previously scheduled event.
 *
 * The $timestamp and $hook parameters are required so that the event can be
 * identified.
 *
 * @since 2.1.0
 * @since 5.1.0 Return value modified to boolean indicating success or failure,
 *              {@see 'pre_unschedule_event'} filter added to short-circuit the function.
 *
 * @param int    $timestamp Unix timestamp (UTC) of the event.
 * @param string $hook      Action hook of the event.
 * @param array  $args      Optional. Array containing each separate argument to pass to the hook's callback function.
 *                          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.
 * @return bool True if event successfully unscheduled. False for failure.
 */
function wp_unschedule_event($timestamp, $hook, $args = array())
{
    // Make sure timestamp is a positive integer
    if (!is_numeric($timestamp) || $timestamp <= 0) {
        return false;
    }
    /**
     * Filter to preflight or hijack unscheduling of events.
     *
     * Returning a non-null value will short-circuit the normal unscheduling
     * process, causing the function to return the filtered value instead.
     *
     * For plugins replacing wp-cron, return true if the event was successfully
     * unscheduled, false if not.
     *
     * @since 5.1.0
     *
     * @param null|bool $pre       Value to return instead. Default null to continue unscheduling the event.
     * @param int       $timestamp Timestamp for when to run the event.
     * @param string    $hook      Action hook, the execution of which will be unscheduled.
     * @param array     $args      Arguments to pass to the hook's callback function.
     */
    $pre = apply_filters('pre_unschedule_event', null, $timestamp, $hook, $args);
    if (null !== $pre) {
        return $pre;
    }
    $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]);
    }
    return _set_cron_array($crons);
}

WordPress Version: 4.7

/**
 * Unschedule a previously scheduled event.
 *
 * The $timestamp and $hook parameters are required so that the event can be
 * identified.
 *
 * @since 2.1.0
 *
 * @param int $timestamp Unix timestamp (UTC) for when to run the event.
 * @param string $hook Action hook, the execution of which will be unscheduled.
 * @param array $args 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.
 * @return false|void False if the event does not get unscheduled.
 */
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);
}

WordPress Version: 4.4

/**
 * Unschedule a previously scheduled cron job.
 *
 * The $timestamp and $hook parameters are required, so that the event can be
 * identified.
 *
 * @since 2.1.0
 *
 * @param int $timestamp Timestamp for when to run the event.
 * @param string $hook Action hook, the execution of which will be unscheduled.
 * @param array $args 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.
 * @return false|void False when an event is not unscheduled.
 */
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);
}

WordPress Version: 3.7

/**
 * Unschedule a previously scheduled cron job.
 *
 * The $timestamp and $hook parameters are required, so that the event can be
 * identified.
 *
 * @since 2.1.0
 *
 * @param int $timestamp Timestamp for when to run the event.
 * @param string $hook Action hook, the execution of which will be unscheduled.
 * @param array $args 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.
 */
function wp_unschedule_event($timestamp, $hook, $args = array())
{
    $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);
}