Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_reschedule_event ›

Seit2.1.0
Veraltetn/v
wp_reschedule_event ( $timestamp, $recurrence, $hook, $args = array() )
Parameter: (4)
  • (int) $timestamp Unix timestamp (UTC) for when the event was scheduled.
    Erforderlich: Ja
  • (string) $recurrence How often the event should subsequently recur. See wp_get_schedules() for accepted values.
    Erforderlich: Ja
  • (string) $hook Action hook to execute when the event is run.
    Erforderlich: Ja
  • (array) $args Optional. Array containing each separate argument to pass to the hook's callback function.
    Erforderlich: Nein
    Standard: array()
Gibt zurück:
  • (bool) True if event successfully rescheduled. False for failure.
Definiert in:
Codex:
Changelog:
  • 5.0.0

Reschedules a recurring event.

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

To change upcoming scheduled events, use {@see wp_schedule_event} to change the recurrence frequency.



Quellcode

function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
	// Make sure timestamp is a positive integer
	if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
		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 preflight or hijack rescheduling of events.
	 *
	 * 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 if not.
	 *
	 * @since 5.0.0
	 *
	 * @param null|bool $pre   Value to return instead. Default null to continue adding the event.
	 * @param stdClass  $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|false $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. Only present for recurring events.
	 * }
	 */
	$pre = apply_filters( 'pre_reschedule_event', null, $event );
	if ( null !== $pre ) {
		return $pre;
	}

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

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