Last active
April 11, 2016 11:31
-
-
Save ianmjones/a779ea48daa5e2939f99204322cd06ac to your computer and use it in GitHub Desktop.
Cron_Pixie::_get_schedules()
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 | |
/** | |
* Returns list of cron schedules. | |
* | |
* @return array | |
*/ | |
private function _get_schedules() { | |
// Get list of schedules. | |
$schedules = wp_get_schedules(); | |
// Append a "Once Only" schedule. | |
$schedules['once'] = array( | |
'display' => __( 'Once Only', 'wp-cron-pixie' ), | |
); | |
// Get list of jobs assigned to schedules. | |
// Using "private" function is really naughty, but it's the best option compared to querying db/options. | |
$cron_array = _get_cron_array(); | |
// Consistent timestamp for seconds until due. | |
$now = time(); | |
// Add child cron events to schedules. | |
foreach ( $cron_array as $timestamp => $jobs ) { | |
foreach ( $jobs as $hook => $events ) { | |
foreach ( $events as $key => $event ) { | |
$event['hook'] = $hook; | |
$event['timestamp'] = $timestamp; | |
$event['seconds_due'] = $timestamp - $now; | |
// The cron array also includes events without a recurring schedule. | |
$scheduled = empty( $event['schedule'] ) ? 'once' : $event['schedule']; | |
$schedules[ $scheduled ]['events'][] = $event; | |
} | |
} | |
} | |
// We need to change the associative array (map) into an indexed one (set) for easier use in collection. | |
$set = array(); | |
foreach ( $schedules as $name => $schedule ) { | |
$schedule['name'] = $name; | |
$set[] = $schedule; | |
} | |
return $set; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment