Cron API: Add a new cron schedule for `weekly` events.

Props Clorith.
See #47606.
Built from https://develop.svn.wordpress.org/trunk@47062


git-svn-id: http://core.svn.wordpress.org/trunk@46862 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-01-12 11:20:04 +00:00
parent f8a5ae6b93
commit 26ce3c9f19
2 changed files with 21 additions and 15 deletions

View File

@ -783,29 +783,30 @@ function wp_cron() {
/** /**
* Retrieve supported event recurrence schedules. * Retrieve supported event recurrence schedules.
* *
* The default supported recurrences are 'hourly', 'twicedaily', and 'daily'. A plugin may * The default supported recurrences are 'hourly', 'twicedaily', 'daily', and 'weekly'.
* add more by hooking into the {@see 'cron_schedules'} filter. The filter accepts an array * A plugin may add more by hooking into the {@see 'cron_schedules'} filter.
* of arrays. The outer array has a key that is the name of the schedule or for * The filter accepts an array of arrays. The outer array has a key that is the name
* example 'weekly'. The value is an array with two keys, one is 'interval' and * of the schedule, for example 'monthly'. The value is an array with two keys,
* the other is 'display'. * one is 'interval' and the other is 'display'.
* *
* The 'interval' is a number in seconds of when the cron job should run. So for * The 'interval' is a number in seconds of when the cron job should run.
* 'hourly', the time is 3600 or 60*60. For weekly, the value would be * So for 'hourly' the time is `HOUR_IN_SECONDS` (60 * 60 or 3600). For 'monthly',
* 60*60*24*7 or 604800. The value of 'interval' would then be 604800. * the value would be `MONTH_IN_SECONDS` (30 * 24 * 60 * 60 or 2592000).
* *
* The 'display' is the description. For the 'weekly' key, the 'display' would * The 'display' is the description. For the 'monthly' key, the 'display'
* be `__( 'Once Weekly' )`. * would be `__( 'Once Monthly' )`.
* *
* For your plugin, you will be passed an array. you can easily add your * For your plugin, you will be passed an array. You can easily add your
* schedule by doing the following. * schedule by doing the following.
* *
* // Filter parameter variable name is 'array'. * // Filter parameter variable name is 'array'.
* $array['weekly'] = array( * $array['monthly'] = array(
* 'interval' => 604800, * 'interval' => MONTH_IN_SECONDS,
* 'display' => __( 'Once Weekly' ) * 'display' => __( 'Once Monthly' )
* ); * );
* *
* @since 2.1.0 * @since 2.1.0
* @since 5.4.0 The 'weekly' schedule was added.
* *
* @return array * @return array
*/ */
@ -823,7 +824,12 @@ function wp_get_schedules() {
'interval' => DAY_IN_SECONDS, 'interval' => DAY_IN_SECONDS,
'display' => __( 'Once Daily' ), 'display' => __( 'Once Daily' ),
), ),
'weekly' => array(
'interval' => 7 * DAY_IN_SECONDS,
'display' => __( 'Once Weekly' ),
),
); );
/** /**
* Filters the non-default cron schedules. * Filters the non-default cron schedules.
* *

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.4-alpha-47061'; $wp_version = '5.4-alpha-47062';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.