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 to run the event.
    Erforderlich: Ja
  • (string) $recurrence How often the event should recur.
    Erforderlich: Ja
  • (string) $hook Action hook to execute when event is run.
    Erforderlich: Ja
  • (array) $args Optional. Arguments to pass to the hook's callback function.
    Erforderlich: Nein
    Standard: array()
Gibt zurück:
  • (false|void) False if the event does not get rescheduled.
Definiert in:
Codex:

Reschedule a recurring event.



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

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