返回介绍

wp_get_schedules()

发布于 2017-09-11 12:08:34 字数 3800 浏览 1005 评论 0 收藏 0

wp_get_schedules()

Retrieve supported event recurrence schedules.


description

The default supported recurrences are ‘hourly’, ‘twicedaily’, and ‘daily’. A plugin may add more by hooking into the ‘cron_schedules’ filter. The filter accepts an array of arrays. The outer array has a key that is the name of the schedule or for example ‘weekly’. The value is an array with two keys, one is ‘interval’ and the other is ‘display’.

The ‘interval’ is a number in seconds of when the cron job should run. So for ‘hourly’, the time is 3600 or 60_60. For weekly, the value would be 60_60_24_7 or 604800. The value of ‘interval’ would then be 604800.

The ‘display’ is the description. For the ‘weekly’ key, the ‘display’ would be __( 'Once Weekly' ).

For your plugin, you will be passed an array. you can easily add your schedule by doing the following.

// Filter parameter variable name is 'array'.
$array['weekly'] = array(
    'interval' => 604800,
       'display'  => __( 'Once Weekly' )
);

返回值

(array)


源代码

File: wp-includes/cron.php

function wp_get_schedules() {
	$schedules = array(
		'hourly'     => array( 'interval' => HOUR_IN_SECONDS,      'display' => __( 'Once Hourly' ) ),
		'twicedaily' => array( 'interval' => 12 * HOUR_IN_SECONDS, 'display' => __( 'Twice Daily' ) ),
		'daily'      => array( 'interval' => DAY_IN_SECONDS,       'display' => __( 'Once Daily' ) ),
	);
	/**
	 * Filters the non-default cron schedules.
	 *
	 * @since 2.1.0
	 *
	 * @param array $new_schedules An array of non-default cron schedules. Default empty.
	 */
	return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/cron.php: cron_schedules
  • wp-includes/l10n.php: __()
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/cron.php: wp_schedule_event()
  • wp-includes/cron.php: wp_reschedule_event()
  • wp-includes/cron.php: wp_cron()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example
    The ‘display’ is the description. For the ‘weekly’ key, the ‘display’ would be

    
    __( 'Once Weekly' );
    

    For your plugin, you will be passed an array. You can easily add a new interval schedule by doing the following using the ‘cron_schedules’ filter.

    
     add_filter( 'cron_schedules', 'cron_add_weekly' );
     
     function cron_add_weekly( $schedules ) {
     	// Adds once weekly to the existing schedules.
     	$schedules['weekly'] = array(
     		'interval' => 604800,
     		'display' => __( 'Once Weekly' )
     	);
     	return $schedules;
     }
    

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

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

发布评论

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