| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Core; |
| 4 |
|
| 5 |
class Cron |
| 6 |
{ |
| 7 |
|
| 8 |
/** |
| 9 |
* Init WordPress hook |
| 10 |
* |
| 11 |
* @since 2.1.12 |
| 12 |
* @see Cron::weekly_events() |
| 13 |
*/ |
| 14 |
public static function init() |
| 15 |
{ |
| 16 |
$self = new self; |
| 17 |
add_filter('cron_schedules', array($self, 'add_schedules')); |
| 18 |
add_action('wp', array($self, 'schedule_events')); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Registers new cron schedules |
| 23 |
* |
| 24 |
* @param array $schedules |
| 25 |
* @return array |
| 26 |
* @since 2.1.12 |
| 27 |
* |
| 28 |
*/ |
| 29 |
public function add_schedules($schedules = array()) |
| 30 |
{ |
| 31 |
/*Adds once weekly to the existing schedules*/ |
| 32 |
$schedules['weekly'] = array( |
| 33 |
'interval' => 604800, |
| 34 |
'display' => __('Once Weekly', 'yatra'), |
| 35 |
); |
| 36 |
|
| 37 |
return $schedules; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Schedules our events |
| 42 |
* |
| 43 |
* @return void |
| 44 |
* @since 2.1.12 |
| 45 |
*/ |
| 46 |
public function schedule_events() |
| 47 |
{ |
| 48 |
$this->weekly_events(); |
| 49 |
$this->daily_events(); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Schedule weekly events |
| 54 |
* |
| 55 |
* @access private |
| 56 |
* @return void |
| 57 |
* @since 2.1.12 |
| 58 |
*/ |
| 59 |
private function weekly_events() |
| 60 |
{ |
| 61 |
if (!wp_next_scheduled('yatra_weekly_scheduled_events')) { |
| 62 |
wp_schedule_event(time(), 'weekly', 'yatra_weekly_scheduled_events'); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Schedule daily events |
| 68 |
* |
| 69 |
* @access private |
| 70 |
* @return void |
| 71 |
* @since 2.1.12 |
| 72 |
*/ |
| 73 |
private function daily_events() |
| 74 |
{ |
| 75 |
if (!wp_next_scheduled('yatra_daily_scheduled_events')) { |
| 76 |
wp_schedule_event(time(), 'daily', 'yatra_daily_scheduled_events'); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
} |
| 81 |
|