Skip to content

Instantly share code, notes, and snippets.

@CatEntangler
Created March 12, 2018 19:12
Show Gist options
  • Save CatEntangler/18704c113694feccf84e779d69138c71 to your computer and use it in GitHub Desktop.
Save CatEntangler/18704c113694feccf84e779d69138c71 to your computer and use it in GitHub Desktop.
Sometimes you need more than hourly WordPress events.
<?php
/*
* Not only can you reuse this throughout your application for added flexibility but
* it gives you added flexibility for scheduling your stuff.
* The default WordPress cron intervals are, as of this writing:
* - Hourly
* - Twice Daily
* - Daily
*/
add_filter( 'cron_schedules', CustomCronIntervals );
function CustomCronIntervals( $schedules, INT $seconds = 0 ) {
if( $seconds !== 0 ) {
$schedules[ "{$seconds}_custom_interval" ] = [
'interval' => $seconds,
'display' => "Once every {$seconds} seconds",
];
}
$schedules[ 'one_minute' ] = [
'interval' => 60,
'display' => 'Once every minute',
];
$schedules[ 'five_minutes' ] = [
'interval' => 300,
'display' => 'Once every 5 minutes',
];
$schedules[ 'ten_minutes' ] = [
'interval' => 600,
'display' => 'Once every 10 minutes',
];
$schedules[ 'thirty_minutes' ] = [
'interval' => 1800,
'display' => 'Once every 30 minutes',
];
return $schedules;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment