WordPress at a glance
Home All Function Functions APIs Cron API

wp_get_schedules() WP 1.0

Retrieve supported event recurrence schedules.

The default supported recurrences are 'hourly', 'twicedaily', 'daily', and 'weekly'. 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, for example 'monthly'. 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 HOUR_IN_SECONDS (60 60 or 3600). For 'monthly', the value would be MONTH_IN_SECONDS (30 24 60 60 or 2592000).

The 'display' is the description. For the 'monthly' key, the 'display' would be __('Once Monthly').

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['monthly'] = array(
	'interval' => MONTH_IN_SECONDS,
	'display'  => __( 'Once Monthly' )
);
✈ 1 time = 0.000001s = speed of light | 50000 times = 0.91s = very fast | PHP 7.0.19, WP 5.0.2
Hooks from the function
Return

Array.

Usage

wp_get_schedules();

Changelog

Since 2.1.0 Introduced.
Since 5.4.0 The 'weekly' schedule was added.

Code of wp get schedules: wp-includes/cron.php WP 5.5

<?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' ),
		),
		'weekly'     => array(
			'interval' => WEEK_IN_SECONDS,
			'display'  => __( 'Once Weekly' ),
		),
	);

	/**
	 * 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 );
}

Related Functions

From tag: cron (schedule)

No comments
        Log In . Register