重新安排定期活动。

原型

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

参数

$timestamp (int) (Required) 用于何时运行事件的Unix时间戳(UTC)。

$recurrence (string) (Required) 该事件应该多久发生一次。

$hook (string) (Required) 在事件运行时执行的Action钩子。

$args (array) (Optional)  传递给hook的回调函数的参数。

返回值

(false|void)  如果事件未重新安排,则返回false。

源文件

路径:wp-includes/cron.php

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

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_reschedule_event/