wp_reschedule_event( int $timestamp, string $recurrence, string $hook, array $args = array(), bool $wp_error = false )

Reschedules a recurring event.


Description

Mainly for internal use, this takes the UTC timestamp of a previously run recurring event and reschedules it for its next run.

To change upcoming scheduled events, use wp_schedule_event() to change the recurrence frequency.


Parameters

$timestamp

(Required) Unix timestamp (UTC) for when the event was scheduled.

$recurrence

(Required) How often the event should subsequently recur.<br> See wp_get_schedules() for accepted values.

$hook

(Required) Action hook to execute when the event is run.

$args

(Optional) Array containing arguments to pass to the hook's callback function. Each value in the array is passed to the callback as an individual parameter.<br> The array keys are ignored.

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 rescheduled. False or WP_Error on failure.


Source

File: wp-includes/cron.php

function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
	// Make sure timestamp is a positive integer
	if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
		return false;
	}

	$crons = _get_cron_array();
	$schedules = wp_get_schedules();
	$key = md5( serialize( $args ) );
	$interval = 0;

	// First we try to get it 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 ) {
		$interval = $crons[ $timestamp ][ $hook ][ $key ]['interval'];
	}
	// Now we assume something is wrong and fail to schedule
	if ( 0 == $interval ) {
		return false;
	}

	$now = time();

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

	wp_schedule_event( $timestamp, $recurrence, $hook, $args );
}


Changelog

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_reschedule_event' filter added to short-circuit the function.
2.1.0 Introduced.