wp_get_schedules()
wp_get_schedules() 检索支持的事件重复计划。 Retrieve supported even…
wp_get_schedules()
检索支持的事件重复计划。
Retrieve supported event recurrence schedules.
目录锚点:#说明#参数#源码#笔记
说明(Description)
默认支持的重复事件为“每小时”、“twicedaily”、“daily”和“weekly”。插件可以通过挂接到“cron_schedules”过滤器来添加更多。过滤器接受数组。外部数组有一个键,它是计划的名称,例如“monthly”。这个值是一个有两个键的数组,一个是“interval”,另一个是“display”。“interval”是cron作业应该运行的时间(以秒为单位)。所以对于“小时”来说,时间是小时,单位是秒(60或3600)。对于“monthly”,值将是MONTH_IN_SECONDS(30 24 60 60或2592000)。“显示”是描述。对于“monthly”键,“display”将是“Once monthly”。对于你的插件,你将得到一个数组。您可以通过执行以下操作轻松地添加日程安排。//筛选器参数变量名为“array”。$array[‘monthly’]=array(’interval’=>MONTH_IN_SECONDS,’display’=>uuu(’Once monthly’));
参数(Parameters)
参数 | 类型 | 说明 |
---|
源码(Source)
/** * Retrieve supported and filtered Cron recurrences. * * The supported recurrences are 'hourly' 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' ) * ); * * * @since 2.1.0 * * @return array */ 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' ) ), ); /** * Filter 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 ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
5.4.0 | wp-includes/cron.php | 14 | 14 |
笔记(Notes)
基本示例
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!