1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
||
11 | class EE_Messages_Scheduler extends EE_BASE { |
||
12 | |||
13 | /** |
||
14 | * Number of seconds between batch sends/generates on the cron job. |
||
15 | * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
||
16 | * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
||
17 | * @type int |
||
18 | */ |
||
19 | const message_cron_schedule = 300; |
||
20 | |||
21 | /** |
||
22 | * Constructor |
||
23 | */ |
||
24 | public function __construct() { |
||
25 | //register tasks (and make sure only registered once). |
||
26 | if ( ! has_action( 'FHEE__EEH_Activation__get_cron_tasks', array( $this, 'register_scheduled_tasks' ) ) ) { |
||
27 | add_action( 'FHEE__EEH_Activation__get_cron_tasks', array( $this, 'register_scheduled_tasks' ), 10 ); |
||
28 | } |
||
29 | |||
30 | //register callbacks for scheduled events (but make sure they are set only once). |
||
31 | if ( ! has_action( 'AHEE__EE_Messages_Scheduler__generation', array( 'EE_Messages_Scheduler', 'batch_generation' ) ) ) { |
||
32 | add_action( 'AHEE__EE_Messages_Scheduler__generation', array( 'EE_Messages_Scheduler', 'batch_generation') ); |
||
33 | add_action( 'AHEE__EE_Messages_Scheduler__sending', array( 'EE_Messages_Scheduler', 'batch_sending' ) ); |
||
34 | } |
||
35 | |||
36 | //add custom schedules |
||
37 | add_filter( 'cron_schedules', array( $this, 'custom_schedules' ) ); |
||
38 | } |
||
39 | |||
40 | |||
41 | |||
42 | |||
43 | /** |
||
44 | * Add custom schedules for wp_cron |
||
45 | * @param $schedules |
||
46 | */ |
||
47 | public function custom_schedules( $schedules ) { |
||
48 | $schedules['ee_message_cron'] = array( |
||
49 | 'interval' => self::message_cron_schedule, |
||
50 | 'display' => __( 'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)', 'event_espresso' ) |
||
51 | ); |
||
52 | return $schedules; |
||
53 | } |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and remove. |
||
58 | * @param array $tasks already existing scheduled tasks |
||
59 | * @return array |
||
60 | */ |
||
61 | public function register_scheduled_tasks( $tasks ) { |
||
62 | $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron'; |
||
63 | $tasks['AHEE__EE_Messages_Scheduler__sending'] = 'ee_message_cron'; |
||
64 | return $tasks; |
||
65 | } |
||
66 | |||
67 | |||
68 | /** |
||
69 | * This initiates a non-blocking separate request to execute on a scheduled task. |
||
70 | * Note: The EED_Messages module has the handlers for these requests. |
||
71 | * @param string $task The task the request is being generated for. |
||
72 | */ |
||
73 | public static function initiate_scheduled_non_blocking_request( $task ) { |
||
96 | |||
97 | |||
98 | |||
99 | |||
100 | |||
101 | /** |
||
102 | * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event |
||
103 | */ |
||
104 | public static function batch_generation() { |
||
107 | |||
108 | |||
109 | |||
110 | |||
111 | /** |
||
112 | * Callback for scheduled AHEE__EE_Messages_Scheduler__sending |
||
113 | */ |
||
114 | public static function batch_sending() { |
||
117 | |||
118 | } //end EE_Messages_Scheduler |