wp_reschedule_event()
wp_reschedule_event( int $timestamp, string $recurrence…
wp_reschedule_event( int $timestamp, string $recurrence, string $hook, array $args = array() )
重新安排重复发生的事件。
Reschedules a recurring event.
重新安排重复发生的事件。
Reschedules a recurring event.
目录锚点:#说明#参数#源码
说明(Description)
主要用于内部使用,它获取以前运行的重复事件的时间戳,并将其重新安排为下次运行。要更改即将发生的计划事件,请使用wp_schedule_event()更改重复频率。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $timestamp | (int) | 计划事件的时间戳(UTC)。 |
| $recurrence | (string) | 事件随后应多久重复一次。有关可接受的值,请参见wp_get_schedules()。 |
| $hook | (string) | 要在事件运行时执行的操作钩子。 |
| $args | (array) | 数组,包含要传递给钩子的回调函数的每个独立参数。 |
源码(Source)
/**
* Reschedule a recurring event.
*
* @since 2.1.0
*
* @param int $timestamp Timestamp for when to run the event.
* @param string $recurrence How often the event should recur.
* @param string $hook Action hook to execute when cron is run.
* @param array $args Optional. Arguments to pass to the hook's callback function.
* @return false|void False when does not schedule event.
*/
function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
$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 );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 5.1.0 | wp-includes/cron.php | 6 | 4 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!