Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyescott/2b5cc68aee5c1cff3075a8d0563f3fd9 to your computer and use it in GitHub Desktop.
Save jeremyescott/2b5cc68aee5c1cff3075a8d0563f3fd9 to your computer and use it in GitHub Desktop.
Change the frequency of the Matador Scheduled Event / WP Cron task.
/**
* Customize Matador: Set Recurrence of Scheduled Events
*
* This function sets the recurrence of the Matador WP Cron from 'hourly'
* to the returned value. Warning: returned value must exist in the WordPress
* schedules array. Default values in the WP Schedules Array are 'hourly',
* 'twicedaily', and 'daily'. Example function uses a non-standard schedule,
* which will need to be registered in a separate function. Also, Matador Software
* provides this method as-is and will not support sites that run schedules at fewer
* than once per hour. Running more regularly will risk exceeding daily rate limits
* or causing a web host to suspend an account for too much CPU use.
*
* @return string
*/
function custom_matador_scheduled_event_recurrence__all() {
return '15min';
}
add_filter( 'matador_scheduled_event_recurrence__all', 'custom_matador_scheduled_event_recurrence__all' );
/**
* Add Schedule to WordPress Schedules Array
*
* This function adds a custom schedule to the WordPress schedules array. It
* is necessary to be included if you are trying to schedule Matador to run
* at a different frequency than the WP default of 'hourly', 'twicedaily',
* and 'daily'. If you are using a custom frequency in the function above,
* the array key MUST match the string you are returning in the Matador call.
*
* @param array $schedules
* @return array
*/
function custom_schedules( $schedules ) {
if ( ! isset( $schedules['15min'] ) ) {
$schedules['15min'] = array(
'interval' => 15 * 60,
'display' => __( 'Once every 15 minutes' ) );
}
return $schedules;
}
add_filter( 'cron_schedule', 'custom_schedules' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment