Make WordPress Core

Changeset 47062


Ignore:
Timestamp:
01/12/2020 11:18:03 AM (5 years ago)
Author:
SergeyBiryukov
Message:

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

Props Clorith.
See #47606.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/cron.php

    r47060 r47062  
    784784 * Retrieve supported event recurrence schedules.
    785785 *
    786  * The default supported recurrences are 'hourly', 'twicedaily', and 'daily'. A plugin may
    787  * add more by hooking into the {@see 'cron_schedules'} filter. The filter accepts an array
    788  * of arrays. The outer array has a key that is the name of the schedule or for
    789  * example 'weekly'. The value is an array with two keys, one is 'interval' and
    790  * the other is 'display'.
    791  *
    792  * The 'interval' is a number in seconds of when the cron job should run. So for
    793  * 'hourly', the time is 3600 or 60*60. For weekly, the value would be
    794  * 60*60*24*7 or 604800. The value of 'interval' would then be 604800.
    795  *
    796  * The 'display' is the description. For the 'weekly' key, the 'display' would
    797  * be `__( 'Once Weekly' )`.
    798  *
    799  * For your plugin, you will be passed an array. you can easily add your
     786 * The default supported recurrences are 'hourly', 'twicedaily', 'daily', and 'weekly'.
     787 * A plugin may add more by hooking into the {@see 'cron_schedules'} filter.
     788 * The filter accepts an array of arrays. The outer array has a key that is the name
     789 * of the schedule, for example 'monthly'. The value is an array with two keys,
     790 * one is 'interval' and the other is 'display'.
     791 *
     792 * The 'interval' is a number in seconds of when the cron job should run.
     793 * So for 'hourly' the time is `HOUR_IN_SECONDS` (60 * 60 or 3600). For 'monthly',
     794 * the value would be `MONTH_IN_SECONDS` (30 * 24 * 60 * 60 or 2592000).
     795 *
     796 * The 'display' is the description. For the 'monthly' key, the 'display'
     797 * would be `__( 'Once Monthly' )`.
     798 *
     799 * For your plugin, you will be passed an array. You can easily add your
    800800 * schedule by doing the following.
    801801 *
    802802 *     // Filter parameter variable name is 'array'.
    803  *     $array['weekly'] = array(
    804  *         'interval' => 604800,
    805  *         'display'  => __( 'Once Weekly' )
     803 *     $array['monthly'] = array(
     804 *         'interval' => MONTH_IN_SECONDS,
     805 *         'display'  => __( 'Once Monthly' )
    806806 *     );
    807807 *
    808808 * @since 2.1.0
     809 * @since 5.4.0 The 'weekly' schedule was added.
    809810 *
    810811 * @return array
     
    824825            'display'  => __( 'Once Daily' ),
    825826        ),
     827        'weekly'     => array(
     828            'interval' => 7 * DAY_IN_SECONDS,
     829            'display'  => __( 'Once Weekly' ),
     830        ),
    826831    );
     832
    827833    /**
    828834     * Filters the non-default cron schedules.
Note: See TracChangeset for help on using the changeset viewer.