Created
March 12, 2018 19:12
-
-
Save TwistedTabby/18704c113694feccf84e779d69138c71 to your computer and use it in GitHub Desktop.
Sometimes you need more than hourly WordPress 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
<?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