1: <?php
2: /**
3: * Cron
4: *
5: * @package EPL
6: * @subpackage Classes/Cron
7: * @copyright Copyright (c) 2019, Merv Barett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 3.2
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: /**
18: * EPL_Cron Class
19: *
20: * This class handles scheduled events
21: *
22: * @since 3.2
23: */
24: class EPL_Cron {
25:
26: /**
27: * Get things going
28: *
29: * @since 3.2
30: * @see EPL_Cron::weekly_events()
31: */
32: public function __construct() {
33: add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
34: add_action( 'wp', array( $this, 'schedule_events' ) );
35: }
36:
37: /**
38: * Registers new cron schedules
39: *
40: * @since 3.2
41: *
42: * @param array $schedules Cron schedules.
43: * @return array
44: */
45: public function add_schedules( $schedules = array() ) {
46: // Adds once weekly to the existing schedules.
47: $schedules['weekly'] = array(
48: 'interval' => 604800,
49: 'display' => __( 'Once Weekly', 'easy-property-listings' ),
50: );
51:
52: return $schedules;
53: }
54:
55: /**
56: * Schedules our events
57: *
58: * @access public
59: * @since 3.2
60: * @return void
61: */
62: public function schedule_events() {
63: $this->weekly_events();
64: $this->daily_events();
65: }
66:
67: /**
68: * Schedule weekly events
69: *
70: * @access private
71: * @since 3.2
72: * @return void
73: */
74: private function weekly_events() {
75: if ( ! wp_next_scheduled( 'epl_weekly_scheduled_events' ) ) {
76: wp_schedule_event( time(), 'weekly', 'epl_weekly_scheduled_events' );
77: }
78: }
79:
80: /**
81: * Schedule daily events
82: *
83: * @access private
84: * @since 3.2
85: * @return void
86: */
87: private function daily_events() {
88: if ( ! wp_next_scheduled( 'epl_daily_scheduled_events' ) ) {
89: wp_schedule_event( time(), 'daily', 'epl_daily_scheduled_events' );
90: }
91: }
92: }
93: $epl_cron = new EPL_Cron();
94: