Created
September 23, 2020 14:35
-
-
Save pbearne/60677ba0432968510117531f87d5f172 to your computer and use it in GitHub Desktop.
Set Recurrence of Scheduled Matador Jobs Events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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() { | |
return 'matador_15min'; | |
} | |
// to change both appiaction and job sync | |
add_filter( 'matador_scheduled_event_recurrence__all', 'custom_matador_scheduled_event_recurrence' ); | |
// to change just application sync | |
add_filter( 'matador_scheduled_event_recurrence_application_sync', 'custom_matador_scheduled_event_recurrence' ); | |
// to change just Job sync | |
add_filter( 'matador_scheduled_event_recurrence_job_sync', 'custom_matador_scheduled_event_recurrence' ); | |
/** | |
* 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 matador_custom_schedules( $schedules ) { | |
if ( ! isset( $schedules['matador_15min'] ) ) { | |
$schedules['matador_15min'] = array( | |
'interval' => 15 * 60, | |
'display' => __( 'Once every 15 minutes' ) ); | |
} | |
return $schedules; | |
} | |
add_filter( 'cron_schedules', 'matador_custom_schedules' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment