A WordPress-centric search engine for devs and theme authors



wp_reschedule_event ›

Since2.1.0
Deprecatedn/a
wp_reschedule_event ( $timestamp, $recurrence, $hook, $args = array() )
Parameters: (4)
  • (int) $timestamp Unix timestamp (UTC) for when to run the event.
    Required: Yes
  • (string) $recurrence How often the event should recur.
    Required: Yes
  • (string) $hook Action hook to execute when event is run.
    Required: Yes
  • (array) $args Optional. Arguments to pass to the hook's callback function.
    Required: No
    Default: array()
Returns:
  • (false|void) False if the event does not get rescheduled.
Defined at:
Codex:

Reschedule a recurring event.



Source

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 );
}