# wp_unschedule_event()

URL: https://chugunov.pro/api-wordpress/functions/wp_unschedule_event/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.1.0.

## Сигнатура

```php
wp_unschedule_event( int $timestamp, string $hook, array $args = array(), bool $wp_error = false ): bool|WP_Error
```

## Описание

Параметры $timestamp и $hook обязательны, чтобы событие можно было идентифицировать.

## Параметры

- `$timestamp` `int` — обязательный. Временная метка Unix (UTC) события.
- `$hook` `string` — обязательный. Хук-действие события.
- `$args` `array` — необязательный, по умолчанию `array()`. Массив, содержащий каждый отдельный аргумент для передачи в функцию обратного вызова хука.
  
  Хотя эти аргументы не передаются в функцию обратного вызова, они используются для однозначной идентификации события, поэтому должны совпадать с теми, что использовались при первоначальном планировании события. Если аргументы не совпадают в точности, событие не будет найдено.
- `$wp_error` `bool` — необязательный, по умолчанию `false`. Возвращать ли WP_Error в случае сбоя.

## Возвращаемое значение

`bool|WP_Error` — WP_Error

## Исходный код

Файл: `wp-includes/cron.php:489`

```php
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 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.
	 * @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 );
}
```

## История изменений

- 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.

## Связанные

Использует: [`_get_cron_array`](https://chugunov.pro/api-wordpress/functions/_get_cron_array/), [`_set_cron_array`](https://chugunov.pro/api-wordpress/functions/_set_cron_array/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/), `WP_Error::__construct`.
Используется в: [`wp_clear_scheduled_hook`](https://chugunov.pro/api-wordpress/functions/wp_clear_scheduled_hook/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_unschedule_event/
