Tribe__Events__Aggregator__Cron::action_register_cron()
Register the base frequency on WP cron system
Return
(void)
Source
File: src/Tribe/Aggregator/Cron.php
public function action_register_cron() {
// if the service isn't active, don't do anything
if ( ! tribe( 'events-aggregator.main' )->is_service_active() ) {
return;
}
// If we have an cron scheduled we bail
if ( wp_next_scheduled( self::$action ) ) {
return;
}
// Fetch the initial Date and Hour
$date = date( 'Y-m-d H' );
// Based on the Minutes construct a Cron
$minutes = (int) date( 'i' );
if ( $minutes < 15 ) {
$date .= ':00';
} elseif ( $minutes >= 15 && $minutes < 30 ) {
$date .= ':15';
}elseif ( $minutes >= 30 && $minutes < 45 ) {
$date .= ':30';
} else {
$date .= ':45';
}
$date .= ':00';
// Fetch the last half hour as a timestamp
$start_timestamp = strtotime( $date );
// randomize the time by plus/minus 0-5 minutes
$random_minutes = ( mt_rand( -5, 5 ) * 60 );
$start_timestamp += $random_minutes;
$current_time = time();
// if the start timestamp is older than RIGHT NOW, set it for 5 minutes from now
if ( $current_time > $start_timestamp ) {
$start_timestamp = $current_time + absint( $random_minutes );
}
// Now add an action twice hourly
wp_schedule_event( $start_timestamp, 'tribe-every15mins', self::$action );
}