返回介绍

wp_reschedule_event()

发布于 2017-09-11 12:45:47 字数 2438 浏览 1111 评论 0 收藏 0

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

Reschedule a recurring event.


description


参数

$timestamp

(int) (Required) Unix timestamp (UTC) for when to run the event.

$recurrence

(string) (Required) How often the event should recur.

$hook

(string) (Required) Action hook to execute when event is run.

$args

(array) (Optional) Arguments to pass to the hook's callback function.

Default value: array()


返回值

(false|void) False if the event does not get rescheduled.


源代码

File: wp-includes/cron.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 );
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/cron.php: _get_cron_array()
  • wp-includes/cron.php: wp_get_schedules()
  • wp-includes/cron.php: wp_schedule_event()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文