# wp_reschedule_event()

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

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

## Сигнатура

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

## Описание

Преимущественно для внутреннего использования: берёт временную метку Unix (UTC) ранее выполненного повторяющегося события и перепланирует его на следующий запуск.
Чтобы изменить предстоящие запланированные события, используйте wp_schedule_event() для изменения периодичности повторения.

## Параметры

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

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

`bool|WP_Error` — WP_Error

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

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

```php
function wp_reschedule_event( $timestamp, $recurrence, $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;
	}

	$schedules = wp_get_schedules();
	$interval  = 0;

	// First we try to get the interval from the schedule.
	if ( isset( $schedules[ $recurrence ] ) ) {
		$interval = $schedules[ $recurrence ]['interval'];
	}

	// Now we try to get it from the saved interval in case the schedule disappears.
	if ( 0 === $interval ) {
		$scheduled_event = wp_get_scheduled_event( $hook, $args, $timestamp );

		if ( $scheduled_event && isset( $scheduled_event->interval ) ) {
			$interval = $scheduled_event->interval;
		}
	}

	$event = (object) array(
		'hook'      => $hook,
		'timestamp' => $timestamp,
		'schedule'  => $recurrence,
		'args'      => $args,
		'interval'  => $interval,
	);

	/**
	 * Filter to override rescheduling of a recurring event.
	 *
	 * Returning a non-null value will short-circuit the normal rescheduling
	 * process, causing the function to return the filtered value instead.
	 *
	 * For plugins replacing wp-cron, return true if the event was successfully
	 * rescheduled, 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 adding the event.
	 * @param object             $event    {
	 *     An object containing an event's data.
	 *
	 *     @type string $hook      Action hook to execute when the event is run.
	 *     @type int    $timestamp Unix timestamp (UTC) for when to next run the event.
	 *     @type string $schedule  How often the event should subsequently recur.
	 *     @type array  $args      Array containing each separate argument to pass to the hook's callback function.
	 *     @type int    $interval  The interval time in seconds for the schedule.
	 * }
	 * @param bool               $wp_error Whether to return a WP_Error on failure.
	 */
	$pre = apply_filters( 'pre_reschedule_event', null, $event, $wp_error );

	if ( null !== $pre ) {
		if ( $wp_error && false === $pre ) {
			return new WP_Error(
				'pre_reschedule_event_false',
				__( 'A plugin prevented the event from being rescheduled.' )
			);
		}

		if ( ! $wp_error && is_wp_error( $pre ) ) {
			return false;
		}

		return $pre;
	}

	// Now we assume something is wrong and fail to schedule.
	if ( 0 === $interval ) {
		if ( $wp_error ) {
			return new WP_Error(
				'invalid_schedule',
				__( 'Event schedule does not exist.' )
			);
		}

		return false;
	}

	$now = time();

	if ( $timestamp >= $now ) {
		$timestamp = $now + $interval;
	} else {
		$timestamp = $now + ( $interval - ( ( $now - $timestamp ) % $interval ) );
	}

	return wp_schedule_event( $timestamp, $recurrence, $hook, $args, $wp_error );
}
```

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

- 5.7.0 — The $wp_error parameter was added.
- 5.1.0 — Return value modified to boolean indicating success or failure, 'pre_reschedule_event' filter added to short-circuit the function.
- 2.1.0 — Introduced.

## Связанные

Использует: [`wp_get_scheduled_event`](https://chugunov.pro/api-wordpress/functions/wp_get_scheduled_event/), [`wp_get_schedules`](https://chugunov.pro/api-wordpress/functions/wp_get_schedules/), [`wp_schedule_event`](https://chugunov.pro/api-wordpress/functions/wp_schedule_event/), [`__`](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`.

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