@@ -16,1347 +16,1347 @@ |
||
16 | 16 | class EED_Messages extends EED_Module |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * This holds the EE_messages controller |
|
21 | - * |
|
22 | - * @deprecated 4.9.0 |
|
23 | - * @var EE_messages $_EEMSG |
|
24 | - */ |
|
25 | - protected static $_EEMSG; |
|
26 | - |
|
27 | - /** |
|
28 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
29 | - */ |
|
30 | - protected static $_message_resource_manager; |
|
31 | - |
|
32 | - /** |
|
33 | - * This holds the EE_Messages_Processor business class. |
|
34 | - * |
|
35 | - * @type EE_Messages_Processor |
|
36 | - */ |
|
37 | - protected static $_MSG_PROCESSOR; |
|
38 | - |
|
39 | - /** |
|
40 | - * holds all the paths for various messages components. |
|
41 | - * Utilized by autoloader registry |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected static $_MSG_PATHS; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
50 | - * Format is: |
|
51 | - * array( |
|
52 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
53 | - * ) |
|
54 | - * |
|
55 | - * @var EE_Messages_Template_Pack[] |
|
56 | - */ |
|
57 | - protected static $_TMP_PACKS = array(); |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @return EED_Messages|EED_Module |
|
62 | - * @throws EE_Error |
|
63 | - * @throws ReflectionException |
|
64 | - */ |
|
65 | - public static function instance() |
|
66 | - { |
|
67 | - return parent::get_instance(__CLASS__); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
73 | - * |
|
74 | - * @since 4.5.0 |
|
75 | - * @return void |
|
76 | - */ |
|
77 | - public static function set_hooks() |
|
78 | - { |
|
79 | - // actions |
|
80 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
81 | - add_action( |
|
82 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
83 | - array('EED_Messages', 'maybe_registration'), |
|
84 | - 10, |
|
85 | - 2 |
|
86 | - ); |
|
87 | - // filters |
|
88 | - add_filter( |
|
89 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
90 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
91 | - 10, |
|
92 | - 4 |
|
93 | - ); |
|
94 | - add_filter( |
|
95 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
96 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
97 | - 10, |
|
98 | - 4 |
|
99 | - ); |
|
100 | - // register routes |
|
101 | - self::_register_routes(); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - public static function set_hooks_admin() |
|
111 | - { |
|
112 | - // actions |
|
113 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
114 | - add_action( |
|
115 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
116 | - array('EED_Messages', 'payment_reminder'), |
|
117 | - 10 |
|
118 | - ); |
|
119 | - add_action( |
|
120 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
121 | - array('EED_Messages', 'maybe_registration'), |
|
122 | - 10, |
|
123 | - 3 |
|
124 | - ); |
|
125 | - add_action( |
|
126 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
127 | - array('EED_Messages', 'send_newsletter_message'), |
|
128 | - 10, |
|
129 | - 2 |
|
130 | - ); |
|
131 | - add_action( |
|
132 | - 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
133 | - array('EED_Messages', 'cancelled_registration'), |
|
134 | - 10 |
|
135 | - ); |
|
136 | - add_action( |
|
137 | - 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
138 | - array('EED_Messages', 'process_admin_payment'), |
|
139 | - 10, |
|
140 | - 1 |
|
141 | - ); |
|
142 | - // filters |
|
143 | - add_filter( |
|
144 | - 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
145 | - array('EED_Messages', 'process_resend'), |
|
146 | - 10, |
|
147 | - 2 |
|
148 | - ); |
|
149 | - add_filter( |
|
150 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
151 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
152 | - 10, |
|
153 | - 4 |
|
154 | - ); |
|
155 | - add_filter( |
|
156 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
157 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
158 | - 10, |
|
159 | - 4 |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * All the message triggers done by route go in here. |
|
166 | - * |
|
167 | - * @since 4.5.0 |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - protected static function _register_routes() |
|
171 | - { |
|
172 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
173 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
174 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
175 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
176 | - do_action('AHEE__EED_Messages___register_routes'); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * This is called when a browser display trigger is executed. |
|
182 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
183 | - * browser. |
|
184 | - * |
|
185 | - * @since 4.9.0 |
|
186 | - * @param WP $WP |
|
187 | - * @throws EE_Error |
|
188 | - * @throws InvalidArgumentException |
|
189 | - * @throws ReflectionException |
|
190 | - * @throws InvalidDataTypeException |
|
191 | - * @throws InvalidInterfaceException |
|
192 | - */ |
|
193 | - public function browser_trigger($WP) |
|
194 | - { |
|
195 | - // ensure controller is loaded |
|
196 | - self::_load_controller(); |
|
197 | - $token = self::getRequest()->getRequestParam('token'); |
|
198 | - try { |
|
199 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
200 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
201 | - } catch (EE_Error $e) { |
|
202 | - $error_msg = esc_html__( |
|
203 | - 'Please note that a system message failed to send due to a technical issue.', |
|
204 | - 'event_espresso' |
|
205 | - ); |
|
206 | - // add specific message for developers if WP_DEBUG in on |
|
207 | - $error_msg .= '||' . $e->getMessage(); |
|
208 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * This is called when a browser error trigger is executed. |
|
215 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
216 | - * message and display it. |
|
217 | - * |
|
218 | - * @since 4.9.0 |
|
219 | - * @param $WP |
|
220 | - * @throws EE_Error |
|
221 | - * @throws InvalidArgumentException |
|
222 | - * @throws InvalidDataTypeException |
|
223 | - * @throws InvalidInterfaceException |
|
224 | - */ |
|
225 | - public function browser_error_trigger($WP) |
|
226 | - { |
|
227 | - $token = self::getRequest()->getRequestParam('token'); |
|
228 | - if ($token) { |
|
229 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
230 | - if ($message instanceof EE_Message) { |
|
231 | - header('HTTP/1.1 200 OK'); |
|
232 | - $error_msg = nl2br($message->error_message()); |
|
233 | - ?> |
|
19 | + /** |
|
20 | + * This holds the EE_messages controller |
|
21 | + * |
|
22 | + * @deprecated 4.9.0 |
|
23 | + * @var EE_messages $_EEMSG |
|
24 | + */ |
|
25 | + protected static $_EEMSG; |
|
26 | + |
|
27 | + /** |
|
28 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
29 | + */ |
|
30 | + protected static $_message_resource_manager; |
|
31 | + |
|
32 | + /** |
|
33 | + * This holds the EE_Messages_Processor business class. |
|
34 | + * |
|
35 | + * @type EE_Messages_Processor |
|
36 | + */ |
|
37 | + protected static $_MSG_PROCESSOR; |
|
38 | + |
|
39 | + /** |
|
40 | + * holds all the paths for various messages components. |
|
41 | + * Utilized by autoloader registry |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected static $_MSG_PATHS; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
50 | + * Format is: |
|
51 | + * array( |
|
52 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
53 | + * ) |
|
54 | + * |
|
55 | + * @var EE_Messages_Template_Pack[] |
|
56 | + */ |
|
57 | + protected static $_TMP_PACKS = array(); |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @return EED_Messages|EED_Module |
|
62 | + * @throws EE_Error |
|
63 | + * @throws ReflectionException |
|
64 | + */ |
|
65 | + public static function instance() |
|
66 | + { |
|
67 | + return parent::get_instance(__CLASS__); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
73 | + * |
|
74 | + * @since 4.5.0 |
|
75 | + * @return void |
|
76 | + */ |
|
77 | + public static function set_hooks() |
|
78 | + { |
|
79 | + // actions |
|
80 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
81 | + add_action( |
|
82 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
83 | + array('EED_Messages', 'maybe_registration'), |
|
84 | + 10, |
|
85 | + 2 |
|
86 | + ); |
|
87 | + // filters |
|
88 | + add_filter( |
|
89 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
90 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
91 | + 10, |
|
92 | + 4 |
|
93 | + ); |
|
94 | + add_filter( |
|
95 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
96 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
97 | + 10, |
|
98 | + 4 |
|
99 | + ); |
|
100 | + // register routes |
|
101 | + self::_register_routes(); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + public static function set_hooks_admin() |
|
111 | + { |
|
112 | + // actions |
|
113 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
114 | + add_action( |
|
115 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
116 | + array('EED_Messages', 'payment_reminder'), |
|
117 | + 10 |
|
118 | + ); |
|
119 | + add_action( |
|
120 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
121 | + array('EED_Messages', 'maybe_registration'), |
|
122 | + 10, |
|
123 | + 3 |
|
124 | + ); |
|
125 | + add_action( |
|
126 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
127 | + array('EED_Messages', 'send_newsletter_message'), |
|
128 | + 10, |
|
129 | + 2 |
|
130 | + ); |
|
131 | + add_action( |
|
132 | + 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
133 | + array('EED_Messages', 'cancelled_registration'), |
|
134 | + 10 |
|
135 | + ); |
|
136 | + add_action( |
|
137 | + 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
138 | + array('EED_Messages', 'process_admin_payment'), |
|
139 | + 10, |
|
140 | + 1 |
|
141 | + ); |
|
142 | + // filters |
|
143 | + add_filter( |
|
144 | + 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
145 | + array('EED_Messages', 'process_resend'), |
|
146 | + 10, |
|
147 | + 2 |
|
148 | + ); |
|
149 | + add_filter( |
|
150 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
151 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
152 | + 10, |
|
153 | + 4 |
|
154 | + ); |
|
155 | + add_filter( |
|
156 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
157 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
158 | + 10, |
|
159 | + 4 |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * All the message triggers done by route go in here. |
|
166 | + * |
|
167 | + * @since 4.5.0 |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + protected static function _register_routes() |
|
171 | + { |
|
172 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
173 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
174 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
175 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
176 | + do_action('AHEE__EED_Messages___register_routes'); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * This is called when a browser display trigger is executed. |
|
182 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
183 | + * browser. |
|
184 | + * |
|
185 | + * @since 4.9.0 |
|
186 | + * @param WP $WP |
|
187 | + * @throws EE_Error |
|
188 | + * @throws InvalidArgumentException |
|
189 | + * @throws ReflectionException |
|
190 | + * @throws InvalidDataTypeException |
|
191 | + * @throws InvalidInterfaceException |
|
192 | + */ |
|
193 | + public function browser_trigger($WP) |
|
194 | + { |
|
195 | + // ensure controller is loaded |
|
196 | + self::_load_controller(); |
|
197 | + $token = self::getRequest()->getRequestParam('token'); |
|
198 | + try { |
|
199 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
200 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
201 | + } catch (EE_Error $e) { |
|
202 | + $error_msg = esc_html__( |
|
203 | + 'Please note that a system message failed to send due to a technical issue.', |
|
204 | + 'event_espresso' |
|
205 | + ); |
|
206 | + // add specific message for developers if WP_DEBUG in on |
|
207 | + $error_msg .= '||' . $e->getMessage(); |
|
208 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * This is called when a browser error trigger is executed. |
|
215 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
216 | + * message and display it. |
|
217 | + * |
|
218 | + * @since 4.9.0 |
|
219 | + * @param $WP |
|
220 | + * @throws EE_Error |
|
221 | + * @throws InvalidArgumentException |
|
222 | + * @throws InvalidDataTypeException |
|
223 | + * @throws InvalidInterfaceException |
|
224 | + */ |
|
225 | + public function browser_error_trigger($WP) |
|
226 | + { |
|
227 | + $token = self::getRequest()->getRequestParam('token'); |
|
228 | + if ($token) { |
|
229 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
230 | + if ($message instanceof EE_Message) { |
|
231 | + header('HTTP/1.1 200 OK'); |
|
232 | + $error_msg = nl2br($message->error_message()); |
|
233 | + ?> |
|
234 | 234 | <!DOCTYPE html> |
235 | 235 | <html> |
236 | 236 | <head></head> |
237 | 237 | <body> |
238 | 238 | <?php echo empty($error_msg) |
239 | - ? esc_html__( |
|
240 | - 'Unfortunately, we were unable to capture the error message for this message.', |
|
241 | - 'event_espresso' |
|
242 | - ) |
|
243 | - : wp_kses( |
|
244 | - $error_msg, |
|
245 | - array( |
|
246 | - 'a' => array( |
|
247 | - 'href' => array(), |
|
248 | - 'title' => array(), |
|
249 | - ), |
|
250 | - 'span' => array(), |
|
251 | - 'div' => array(), |
|
252 | - 'p' => array(), |
|
253 | - 'strong' => array(), |
|
254 | - 'em' => array(), |
|
255 | - 'br' => array(), |
|
256 | - ) |
|
257 | - ); ?> |
|
239 | + ? esc_html__( |
|
240 | + 'Unfortunately, we were unable to capture the error message for this message.', |
|
241 | + 'event_espresso' |
|
242 | + ) |
|
243 | + : wp_kses( |
|
244 | + $error_msg, |
|
245 | + array( |
|
246 | + 'a' => array( |
|
247 | + 'href' => array(), |
|
248 | + 'title' => array(), |
|
249 | + ), |
|
250 | + 'span' => array(), |
|
251 | + 'div' => array(), |
|
252 | + 'p' => array(), |
|
253 | + 'strong' => array(), |
|
254 | + 'em' => array(), |
|
255 | + 'br' => array(), |
|
256 | + ) |
|
257 | + ); ?> |
|
258 | 258 | </body> |
259 | 259 | </html> |
260 | 260 | <?php |
261 | - exit; |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * This runs when the msg_url_trigger route has initiated. |
|
269 | - * |
|
270 | - * @since 4.5.0 |
|
271 | - * @param WP $WP |
|
272 | - * @throws EE_Error |
|
273 | - * @throws InvalidArgumentException |
|
274 | - * @throws ReflectionException |
|
275 | - * @throws InvalidDataTypeException |
|
276 | - * @throws InvalidInterfaceException |
|
277 | - */ |
|
278 | - public function run($WP) |
|
279 | - { |
|
280 | - // ensure controller is loaded |
|
281 | - self::_load_controller(); |
|
282 | - // attempt to process message |
|
283 | - try { |
|
284 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
285 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
286 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
287 | - } catch (EE_Error $e) { |
|
288 | - $error_msg = esc_html__( |
|
289 | - 'Please note that a system message failed to send due to a technical issue.', |
|
290 | - 'event_espresso' |
|
291 | - ); |
|
292 | - // add specific message for developers if WP_DEBUG in on |
|
293 | - $error_msg .= '||' . $e->getMessage(); |
|
294 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * This is triggered by the 'msg_cron_trigger' route. |
|
301 | - * |
|
302 | - * @param WP $WP |
|
303 | - */ |
|
304 | - public function execute_batch_request($WP) |
|
305 | - { |
|
306 | - $this->run_cron(); |
|
307 | - header('HTTP/1.1 200 OK'); |
|
308 | - exit(); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
314 | - * request. |
|
315 | - */ |
|
316 | - public function run_cron() |
|
317 | - { |
|
318 | - self::_load_controller(); |
|
319 | - $request = self::getRequest(); |
|
320 | - // get required vars |
|
321 | - $cron_type = $request->getRequestParam('type'); |
|
322 | - $transient_key = $request->getRequestParam('key'); |
|
323 | - |
|
324 | - // now let's verify transient, if not valid exit immediately |
|
325 | - if (! get_transient($transient_key)) { |
|
326 | - /** |
|
327 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
328 | - * request. |
|
329 | - */ |
|
330 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
331 | - } |
|
332 | - |
|
333 | - // if made it here, lets' delete the transient to keep the db clean |
|
334 | - delete_transient($transient_key); |
|
335 | - |
|
336 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
337 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
338 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
339 | - self::$_MSG_PROCESSOR->$method(); |
|
340 | - } else { |
|
341 | - // no matching task |
|
342 | - /** |
|
343 | - * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
344 | - * request. |
|
345 | - */ |
|
346 | - trigger_error( |
|
347 | - esc_attr( |
|
348 | - sprintf( |
|
349 | - esc_html__('There is no task corresponding to this route %s', 'event_espresso'), |
|
350 | - $cron_type |
|
351 | - ) |
|
352 | - ) |
|
353 | - ); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * This is used to retrieve the template pack for the given name. |
|
363 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
364 | - * the default template pack is returned. |
|
365 | - * |
|
366 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
367 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
368 | - * in generating the Pack class name). |
|
369 | - * @return EE_Messages_Template_Pack |
|
370 | - * @throws EE_Error |
|
371 | - * @throws InvalidArgumentException |
|
372 | - * @throws ReflectionException |
|
373 | - * @throws InvalidDataTypeException |
|
374 | - * @throws InvalidInterfaceException |
|
375 | - */ |
|
376 | - public static function get_template_pack($template_pack_name) |
|
377 | - { |
|
378 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
379 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Retrieves an array of all template packs. |
|
385 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
386 | - * |
|
387 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
388 | - * @return EE_Messages_Template_Pack[] |
|
389 | - * @throws EE_Error |
|
390 | - * @throws InvalidArgumentException |
|
391 | - * @throws ReflectionException |
|
392 | - * @throws InvalidDataTypeException |
|
393 | - * @throws InvalidInterfaceException |
|
394 | - */ |
|
395 | - public static function get_template_packs() |
|
396 | - { |
|
397 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
398 | - |
|
399 | - // for backward compat, let's make sure this returns in the same format as originally. |
|
400 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
401 | - $template_pack_collection->rewind(); |
|
402 | - $template_packs = array(); |
|
403 | - while ($template_pack_collection->valid()) { |
|
404 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
405 | - $template_pack_collection->next(); |
|
406 | - } |
|
407 | - return $template_packs; |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
413 | - * |
|
414 | - * @since 4.5.0 |
|
415 | - * @return void |
|
416 | - * @throws EE_Error |
|
417 | - */ |
|
418 | - public static function set_autoloaders() |
|
419 | - { |
|
420 | - if (empty(self::$_MSG_PATHS)) { |
|
421 | - self::_set_messages_paths(); |
|
422 | - foreach (self::$_MSG_PATHS as $path) { |
|
423 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
424 | - } |
|
425 | - // add aliases |
|
426 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
427 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
428 | - } |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
434 | - * for use by the Messages Autoloaders |
|
435 | - * |
|
436 | - * @since 4.5.0 |
|
437 | - * @return void. |
|
438 | - */ |
|
439 | - protected static function _set_messages_paths() |
|
440 | - { |
|
441 | - $dir_ref = array( |
|
442 | - 'messages/message_type', |
|
443 | - 'messages/messenger', |
|
444 | - 'messages/defaults', |
|
445 | - 'messages/defaults/email', |
|
446 | - 'messages/data_class', |
|
447 | - 'messages/validators', |
|
448 | - 'messages/validators/email', |
|
449 | - 'messages/validators/html', |
|
450 | - 'shortcodes', |
|
451 | - ); |
|
452 | - $paths = array(); |
|
453 | - foreach ($dir_ref as $index => $dir) { |
|
454 | - $paths[ $index ] = EE_LIBRARIES . $dir; |
|
455 | - } |
|
456 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * Takes care of loading dependencies |
|
462 | - * |
|
463 | - * @since 4.5.0 |
|
464 | - * @return void |
|
465 | - * @throws EE_Error |
|
466 | - * @throws InvalidArgumentException |
|
467 | - * @throws ReflectionException |
|
468 | - * @throws InvalidDataTypeException |
|
469 | - * @throws InvalidInterfaceException |
|
470 | - */ |
|
471 | - protected static function _load_controller() |
|
472 | - { |
|
473 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
474 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
475 | - self::set_autoloaders(); |
|
476 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
477 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
478 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
479 | - } |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @param EE_Transaction $transaction |
|
485 | - * @throws EE_Error |
|
486 | - * @throws InvalidArgumentException |
|
487 | - * @throws InvalidDataTypeException |
|
488 | - * @throws InvalidInterfaceException |
|
489 | - * @throws ReflectionException |
|
490 | - */ |
|
491 | - public static function payment_reminder(EE_Transaction $transaction) |
|
492 | - { |
|
493 | - self::_load_controller(); |
|
494 | - $data = array($transaction, null); |
|
495 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * Any messages triggers for after successful gateway payments should go in here. |
|
501 | - * |
|
502 | - * @param EE_Transaction $transaction object |
|
503 | - * @param EE_Payment|null $payment object |
|
504 | - * @return void |
|
505 | - * @throws EE_Error |
|
506 | - * @throws InvalidArgumentException |
|
507 | - * @throws ReflectionException |
|
508 | - * @throws InvalidDataTypeException |
|
509 | - * @throws InvalidInterfaceException |
|
510 | - */ |
|
511 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
512 | - { |
|
513 | - // if there's no payment object, then we cannot do a payment type message! |
|
514 | - if (! $payment instanceof EE_Payment) { |
|
515 | - return; |
|
516 | - } |
|
517 | - self::_load_controller(); |
|
518 | - $data = array($transaction, $payment); |
|
519 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
520 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
521 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
522 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
523 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * @param EE_Transaction $transaction |
|
529 | - * @throws EE_Error |
|
530 | - * @throws InvalidArgumentException |
|
531 | - * @throws InvalidDataTypeException |
|
532 | - * @throws InvalidInterfaceException |
|
533 | - * @throws ReflectionException |
|
534 | - */ |
|
535 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
536 | - { |
|
537 | - self::_load_controller(); |
|
538 | - $data = array($transaction, null); |
|
539 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * Trigger for Registration messages |
|
545 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
546 | - * incoming transaction. |
|
547 | - * |
|
548 | - * @param EE_Registration $registration |
|
549 | - * @param array $extra_details |
|
550 | - * @return void |
|
551 | - * @throws EE_Error |
|
552 | - * @throws InvalidArgumentException |
|
553 | - * @throws InvalidDataTypeException |
|
554 | - * @throws InvalidInterfaceException |
|
555 | - * @throws ReflectionException |
|
556 | - * @throws EntityNotFoundException |
|
557 | - */ |
|
558 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
559 | - { |
|
560 | - |
|
561 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
562 | - // no messages please |
|
563 | - return; |
|
564 | - } |
|
565 | - |
|
566 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
567 | - $all_registrations = $registration->transaction()->registrations( |
|
568 | - array( |
|
569 | - array('REG_deleted' => false), |
|
570 | - 'order_by' => array( |
|
571 | - 'Event.EVT_name' => 'ASC', |
|
572 | - 'Attendee.ATT_lname' => 'ASC', |
|
573 | - 'Attendee.ATT_fname' => 'ASC', |
|
574 | - ), |
|
575 | - ) |
|
576 | - ); |
|
577 | - // cached array of statuses so we only trigger messages once per status. |
|
578 | - $statuses_sent = array(); |
|
579 | - self::_load_controller(); |
|
580 | - $mtgs = array(); |
|
581 | - |
|
582 | - // loop through registrations and trigger messages once per status. |
|
583 | - foreach ($all_registrations as $reg) { |
|
584 | - // already triggered? |
|
585 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
586 | - continue; |
|
587 | - } |
|
588 | - |
|
589 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
590 | - $mtgs = array_merge( |
|
591 | - $mtgs, |
|
592 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
593 | - $message_type, |
|
594 | - array($registration->transaction(), null, $reg->status_ID()) |
|
595 | - ) |
|
596 | - ); |
|
597 | - $statuses_sent[] = $reg->status_ID(); |
|
598 | - } |
|
599 | - |
|
600 | - if (count($statuses_sent) > 1) { |
|
601 | - $mtgs = array_merge( |
|
602 | - $mtgs, |
|
603 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
604 | - 'registration_summary', |
|
605 | - array($registration->transaction(), null) |
|
606 | - ) |
|
607 | - ); |
|
608 | - } |
|
609 | - |
|
610 | - // batch queue and initiate request |
|
611 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
612 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * This is a helper method used to very whether a registration notification should be sent or |
|
618 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
619 | - * |
|
620 | - * @param EE_Registration $registration [description] |
|
621 | - * @param array $extra_details [description] |
|
622 | - * @return bool true = send away, false = nope halt the presses. |
|
623 | - */ |
|
624 | - protected static function _verify_registration_notification_send( |
|
625 | - EE_Registration $registration, |
|
626 | - $extra_details = array() |
|
627 | - ) { |
|
628 | - if (! $registration->is_primary_registrant()) { |
|
629 | - return false; |
|
630 | - } |
|
631 | - $request = self::getRequest(); |
|
632 | - // first we check if we're in admin and not doing front ajax |
|
633 | - if ( |
|
634 | - ($request->isAdmin() || $request->isAdminAjax()) |
|
635 | - && ! $request->isFrontAjax() |
|
636 | - ) { |
|
637 | - $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true); |
|
638 | - // make sure appropriate admin params are set for sending messages |
|
639 | - if (! $status_change['send_notifications']) { |
|
640 | - // no messages sent please. |
|
641 | - return false; |
|
642 | - } |
|
643 | - } else { |
|
644 | - // frontend request (either regular or via AJAX) |
|
645 | - // TXN is NOT finalized ? |
|
646 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
647 | - return false; |
|
648 | - } |
|
649 | - // return visit but nothing changed ??? |
|
650 | - if ( |
|
651 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
652 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
653 | - ) { |
|
654 | - return false; |
|
655 | - } |
|
656 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
657 | - if ( |
|
658 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
659 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
660 | - ) { |
|
661 | - return false; |
|
662 | - } |
|
663 | - } |
|
664 | - // release the kraken |
|
665 | - return true; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
671 | - * status id. |
|
672 | - * |
|
673 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
674 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
675 | - * @param string $reg_status |
|
676 | - * @return array |
|
677 | - * @throws EE_Error |
|
678 | - * @throws InvalidArgumentException |
|
679 | - * @throws ReflectionException |
|
680 | - * @throws InvalidDataTypeException |
|
681 | - * @throws InvalidInterfaceException |
|
682 | - */ |
|
683 | - protected static function _get_reg_status_array($reg_status = '') |
|
684 | - { |
|
685 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
686 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
687 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
688 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * Simply returns the payment message type for the given payment status. |
|
694 | - * |
|
695 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
696 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
697 | - * @param string $payment_status The payment status being matched. |
|
698 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
699 | - * @throws EE_Error |
|
700 | - * @throws InvalidArgumentException |
|
701 | - * @throws ReflectionException |
|
702 | - * @throws InvalidDataTypeException |
|
703 | - * @throws InvalidInterfaceException |
|
704 | - */ |
|
705 | - protected static function _get_payment_message_type($payment_status) |
|
706 | - { |
|
707 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
708 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
709 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
710 | - : false; |
|
711 | - } |
|
712 | - |
|
713 | - |
|
714 | - /** |
|
715 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
716 | - * |
|
717 | - * @access public |
|
718 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
719 | - * @return bool success/fail |
|
720 | - * @throws EE_Error |
|
721 | - * @throws InvalidArgumentException |
|
722 | - * @throws InvalidDataTypeException |
|
723 | - * @throws InvalidInterfaceException |
|
724 | - * @throws ReflectionException |
|
725 | - */ |
|
726 | - public static function process_resend(array $req_data = []) |
|
727 | - { |
|
728 | - self::_load_controller(); |
|
729 | - $request = self::getRequest(); |
|
730 | - // if $msgID in this request then skip to the new resend_message |
|
731 | - if ($request->getRequestParam('MSG_ID')) { |
|
732 | - return self::resend_message(); |
|
733 | - } |
|
734 | - |
|
735 | - // make sure any incoming request data is set on the request so that it gets picked up later. |
|
736 | - foreach ((array) $req_data as $request_key => $request_value) { |
|
737 | - if (! $request->requestParamIsSet($request_key)) { |
|
738 | - $request->setRequestParam($request_key, $request_value); |
|
739 | - } |
|
740 | - } |
|
741 | - |
|
742 | - if ( |
|
743 | - ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request() |
|
744 | - ) { |
|
745 | - return false; |
|
746 | - } |
|
747 | - |
|
748 | - try { |
|
749 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
750 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
751 | - } catch (EE_Error $e) { |
|
752 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
753 | - return false; |
|
754 | - } |
|
755 | - EE_Error::add_success( |
|
756 | - esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
757 | - ); |
|
758 | - return true; // everything got queued. |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
764 | - * |
|
765 | - * @return bool |
|
766 | - * @throws EE_Error |
|
767 | - * @throws InvalidArgumentException |
|
768 | - * @throws InvalidDataTypeException |
|
769 | - * @throws InvalidInterfaceException |
|
770 | - * @throws ReflectionException |
|
771 | - */ |
|
772 | - public static function resend_message() |
|
773 | - { |
|
774 | - self::_load_controller(); |
|
775 | - |
|
776 | - $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int'); |
|
777 | - if (! $msgID) { |
|
778 | - EE_Error::add_error( |
|
779 | - esc_html__( |
|
780 | - 'Something went wrong because there is no "MSG_ID" value in the request', |
|
781 | - 'event_espresso' |
|
782 | - ), |
|
783 | - __FILE__, |
|
784 | - __FUNCTION__, |
|
785 | - __LINE__ |
|
786 | - ); |
|
787 | - return false; |
|
788 | - } |
|
789 | - |
|
790 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
791 | - |
|
792 | - // setup success message. |
|
793 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
794 | - EE_Error::add_success( |
|
795 | - sprintf( |
|
796 | - _n( |
|
797 | - 'There was %d message queued for resending.', |
|
798 | - 'There were %d messages queued for resending.', |
|
799 | - $count_ready_for_resend, |
|
800 | - 'event_espresso' |
|
801 | - ), |
|
802 | - $count_ready_for_resend |
|
803 | - ) |
|
804 | - ); |
|
805 | - return true; |
|
806 | - } |
|
807 | - |
|
808 | - |
|
809 | - /** |
|
810 | - * Message triggers for manual payment applied by admin |
|
811 | - * |
|
812 | - * @param EE_Payment $payment EE_payment object |
|
813 | - * @return bool success/fail |
|
814 | - * @throws EE_Error |
|
815 | - * @throws InvalidArgumentException |
|
816 | - * @throws ReflectionException |
|
817 | - * @throws InvalidDataTypeException |
|
818 | - * @throws InvalidInterfaceException |
|
819 | - */ |
|
820 | - public static function process_admin_payment(EE_Payment $payment) |
|
821 | - { |
|
822 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
823 | - // we need to get the transaction object |
|
824 | - $transaction = $payment->transaction(); |
|
825 | - if ($transaction instanceof EE_Transaction) { |
|
826 | - $data = array($transaction, $payment); |
|
827 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
828 | - |
|
829 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
830 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
831 | - |
|
832 | - // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
833 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
834 | - ? false : $message_type; |
|
835 | - |
|
836 | - self::_load_controller(); |
|
837 | - |
|
838 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
839 | - |
|
840 | - // get count of queued for generation |
|
841 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
842 | - array( |
|
843 | - EEM_Message::status_incomplete, |
|
844 | - EEM_Message::status_idle, |
|
845 | - ) |
|
846 | - ); |
|
847 | - |
|
848 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
849 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
850 | - return true; |
|
851 | - } else { |
|
852 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
853 | - EEM_Message::instance()->stati_indicating_failed_sending() |
|
854 | - ); |
|
855 | - /** |
|
856 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
857 | - * IMMEDIATE generation. |
|
858 | - */ |
|
859 | - if ($count_failed > 0) { |
|
860 | - EE_Error::add_error( |
|
861 | - sprintf( |
|
862 | - _n( |
|
863 | - 'The payment notification generation failed.', |
|
864 | - '%d payment notifications failed being sent.', |
|
865 | - $count_failed, |
|
866 | - 'event_espresso' |
|
867 | - ), |
|
868 | - $count_failed |
|
869 | - ), |
|
870 | - __FILE__, |
|
871 | - __FUNCTION__, |
|
872 | - __LINE__ |
|
873 | - ); |
|
874 | - |
|
875 | - return false; |
|
876 | - } else { |
|
877 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
878 | - return true; |
|
879 | - } |
|
880 | - } |
|
881 | - } else { |
|
882 | - EE_Error::add_error( |
|
883 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
884 | - 'event_espresso' |
|
885 | - ); |
|
886 | - return false; |
|
887 | - } |
|
888 | - } |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
893 | - * |
|
894 | - * @since 4.3.0 |
|
895 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
896 | - * @param int $grp_id a specific message template group id. |
|
897 | - * @return void |
|
898 | - * @throws EE_Error |
|
899 | - * @throws InvalidArgumentException |
|
900 | - * @throws InvalidDataTypeException |
|
901 | - * @throws InvalidInterfaceException |
|
902 | - * @throws ReflectionException |
|
903 | - */ |
|
904 | - public static function send_newsletter_message($registrations, $grp_id) |
|
905 | - { |
|
906 | - // make sure mtp is id and set it in the request later messages setup. |
|
907 | - self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id); |
|
908 | - self::_load_controller(); |
|
909 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
910 | - } |
|
911 | - |
|
912 | - |
|
913 | - /** |
|
914 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
915 | - * |
|
916 | - * @since 4.3.0 |
|
917 | - * @param string $registration_message_trigger_url |
|
918 | - * @param EE_Registration $registration |
|
919 | - * @param string $messenger |
|
920 | - * @param string $message_type |
|
921 | - * @return string |
|
922 | - * @throws EE_Error |
|
923 | - * @throws InvalidArgumentException |
|
924 | - * @throws InvalidDataTypeException |
|
925 | - * @throws InvalidInterfaceException |
|
926 | - */ |
|
927 | - public static function registration_message_trigger_url( |
|
928 | - $registration_message_trigger_url, |
|
929 | - EE_Registration $registration, |
|
930 | - $messenger = 'html', |
|
931 | - $message_type = 'invoice' |
|
932 | - ) { |
|
933 | - // whitelist $messenger |
|
934 | - switch ($messenger) { |
|
935 | - case 'pdf': |
|
936 | - $sending_messenger = 'pdf'; |
|
937 | - $generating_messenger = 'html'; |
|
938 | - break; |
|
939 | - case 'html': |
|
940 | - default: |
|
941 | - $sending_messenger = 'html'; |
|
942 | - $generating_messenger = 'html'; |
|
943 | - break; |
|
944 | - } |
|
945 | - // whitelist $message_type |
|
946 | - switch ($message_type) { |
|
947 | - case 'receipt': |
|
948 | - $message_type = 'receipt'; |
|
949 | - break; |
|
950 | - case 'invoice': |
|
951 | - default: |
|
952 | - $message_type = 'invoice'; |
|
953 | - break; |
|
954 | - } |
|
955 | - // verify that both the messenger AND the message type are active |
|
956 | - if ( |
|
957 | - EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
958 | - && EEH_MSG_Template::is_mt_active($message_type) |
|
959 | - ) { |
|
960 | - // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
961 | - $template_query_params = array( |
|
962 | - 'MTP_is_active' => true, |
|
963 | - 'MTP_messenger' => $generating_messenger, |
|
964 | - 'MTP_message_type' => $message_type, |
|
965 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
966 | - ); |
|
967 | - // get the message template group. |
|
968 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
969 | - // if we don't have an EE_Message_Template_Group then return |
|
970 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
971 | - // remove EVT_ID from query params so that global templates get picked up |
|
972 | - unset($template_query_params['Event.EVT_ID']); |
|
973 | - // get global template as the fallback |
|
974 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
975 | - } |
|
976 | - // if we don't have an EE_Message_Template_Group then return |
|
977 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
978 | - return ''; |
|
979 | - } |
|
980 | - // generate the URL |
|
981 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
982 | - $sending_messenger, |
|
983 | - $generating_messenger, |
|
984 | - 'purchaser', |
|
985 | - $message_type, |
|
986 | - $registration, |
|
987 | - $msg_template_group->ID(), |
|
988 | - $registration->transaction_ID() |
|
989 | - ); |
|
990 | - } |
|
991 | - return $registration_message_trigger_url; |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - /** |
|
996 | - * Use to generate and return a message preview! |
|
997 | - * |
|
998 | - * @param string $type This should correspond with a valid message type |
|
999 | - * @param string $context This should correspond with a valid context for the message type |
|
1000 | - * @param string $messenger This should correspond with a valid messenger. |
|
1001 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
1002 | - * preview |
|
1003 | - * @return bool|string The body of the message or if send is requested, sends. |
|
1004 | - * @throws EE_Error |
|
1005 | - * @throws InvalidArgumentException |
|
1006 | - * @throws InvalidDataTypeException |
|
1007 | - * @throws InvalidInterfaceException |
|
1008 | - * @throws ReflectionException |
|
1009 | - */ |
|
1010 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
1011 | - { |
|
1012 | - self::_load_controller(); |
|
1013 | - $mtg = new EE_Message_To_Generate( |
|
1014 | - $messenger, |
|
1015 | - $type, |
|
1016 | - array(), |
|
1017 | - $context, |
|
1018 | - true |
|
1019 | - ); |
|
1020 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
1021 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
1022 | - // loop through all content for the preview and remove any persisted records. |
|
1023 | - $content = ''; |
|
1024 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
1025 | - $content = $message->content(); |
|
1026 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
1027 | - $message->delete(); |
|
1028 | - } |
|
1029 | - } |
|
1030 | - return $content; |
|
1031 | - } else { |
|
1032 | - return $generated_preview_queue; |
|
1033 | - } |
|
1034 | - } |
|
1035 | - |
|
1036 | - |
|
1037 | - /** |
|
1038 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
1039 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
1040 | - * content found in the EE_Message objects in the queue. |
|
1041 | - * |
|
1042 | - * @since 4.9.0 |
|
1043 | - * @param string $messenger a string matching a valid active messenger in the system |
|
1044 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
1045 | - * type name is still required to send along the message type to the |
|
1046 | - * messenger because this is used for determining what specific |
|
1047 | - * variations might be loaded for the generated message. |
|
1048 | - * @param EE_Messages_Queue $queue |
|
1049 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
1050 | - * aggregate EE_Message object. |
|
1051 | - * @return bool success or fail. |
|
1052 | - * @throws EE_Error |
|
1053 | - * @throws InvalidArgumentException |
|
1054 | - * @throws ReflectionException |
|
1055 | - * @throws InvalidDataTypeException |
|
1056 | - * @throws InvalidInterfaceException |
|
1057 | - */ |
|
1058 | - public static function send_message_with_messenger_only( |
|
1059 | - $messenger, |
|
1060 | - $message_type, |
|
1061 | - EE_Messages_Queue $queue, |
|
1062 | - $custom_subject = '' |
|
1063 | - ) { |
|
1064 | - self::_load_controller(); |
|
1065 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
1066 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
1067 | - 'Message_To_Generate_From_Queue', |
|
1068 | - array( |
|
1069 | - $messenger, |
|
1070 | - $message_type, |
|
1071 | - $queue, |
|
1072 | - $custom_subject, |
|
1073 | - ) |
|
1074 | - ); |
|
1075 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
1076 | - } |
|
1077 | - |
|
1078 | - |
|
1079 | - /** |
|
1080 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
1081 | - * |
|
1082 | - * @since 4.9.0 |
|
1083 | - * @param array $message_ids An array of message ids |
|
1084 | - * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
1085 | - * messages. |
|
1086 | - * @throws EE_Error |
|
1087 | - * @throws InvalidArgumentException |
|
1088 | - * @throws InvalidDataTypeException |
|
1089 | - * @throws InvalidInterfaceException |
|
1090 | - * @throws ReflectionException |
|
1091 | - */ |
|
1092 | - public static function generate_now($message_ids) |
|
1093 | - { |
|
1094 | - self::_load_controller(); |
|
1095 | - $messages = EEM_Message::instance()->get_all( |
|
1096 | - array( |
|
1097 | - 0 => array( |
|
1098 | - 'MSG_ID' => array('IN', $message_ids), |
|
1099 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
1100 | - ), |
|
1101 | - ) |
|
1102 | - ); |
|
1103 | - $generated_queue = false; |
|
1104 | - if ($messages) { |
|
1105 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
1106 | - } |
|
1107 | - |
|
1108 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
1109 | - EE_Error::add_error( |
|
1110 | - esc_html__( |
|
1111 | - 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
1112 | - 'event_espresso' |
|
1113 | - ), |
|
1114 | - __FILE__, |
|
1115 | - __FUNCTION__, |
|
1116 | - __LINE__ |
|
1117 | - ); |
|
1118 | - } |
|
1119 | - return $generated_queue; |
|
1120 | - } |
|
1121 | - |
|
1122 | - |
|
1123 | - /** |
|
1124 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
1125 | - * EEM_Message::status_idle |
|
1126 | - * |
|
1127 | - * @since 4.9.0 |
|
1128 | - * @param $message_ids |
|
1129 | - * @return bool|EE_Messages_Queue false if no messages sent. |
|
1130 | - * @throws EE_Error |
|
1131 | - * @throws InvalidArgumentException |
|
1132 | - * @throws InvalidDataTypeException |
|
1133 | - * @throws InvalidInterfaceException |
|
1134 | - * @throws ReflectionException |
|
1135 | - */ |
|
1136 | - public static function send_now($message_ids) |
|
1137 | - { |
|
1138 | - self::_load_controller(); |
|
1139 | - $messages = EEM_Message::instance()->get_all( |
|
1140 | - array( |
|
1141 | - 0 => array( |
|
1142 | - 'MSG_ID' => array('IN', $message_ids), |
|
1143 | - 'STS_ID' => array( |
|
1144 | - 'IN', |
|
1145 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
1146 | - ), |
|
1147 | - ), |
|
1148 | - ) |
|
1149 | - ); |
|
1150 | - $sent_queue = false; |
|
1151 | - if ($messages) { |
|
1152 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
1153 | - } |
|
1154 | - |
|
1155 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
1156 | - EE_Error::add_error( |
|
1157 | - esc_html__( |
|
1158 | - 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
1159 | - 'event_espresso' |
|
1160 | - ), |
|
1161 | - __FILE__, |
|
1162 | - __FUNCTION__, |
|
1163 | - __LINE__ |
|
1164 | - ); |
|
1165 | - } else { |
|
1166 | - // can count how many sent by using the messages in the queue |
|
1167 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
1168 | - if ($sent_count > 0) { |
|
1169 | - EE_Error::add_success( |
|
1170 | - sprintf( |
|
1171 | - _n( |
|
1172 | - 'There was %d message successfully sent.', |
|
1173 | - 'There were %d messages successfully sent.', |
|
1174 | - $sent_count, |
|
1175 | - 'event_espresso' |
|
1176 | - ), |
|
1177 | - $sent_count |
|
1178 | - ) |
|
1179 | - ); |
|
1180 | - } else { |
|
1181 | - EE_Error::overwrite_errors(); |
|
1182 | - EE_Error::add_error( |
|
1183 | - esc_html__( |
|
1184 | - 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
261 | + exit; |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * This runs when the msg_url_trigger route has initiated. |
|
269 | + * |
|
270 | + * @since 4.5.0 |
|
271 | + * @param WP $WP |
|
272 | + * @throws EE_Error |
|
273 | + * @throws InvalidArgumentException |
|
274 | + * @throws ReflectionException |
|
275 | + * @throws InvalidDataTypeException |
|
276 | + * @throws InvalidInterfaceException |
|
277 | + */ |
|
278 | + public function run($WP) |
|
279 | + { |
|
280 | + // ensure controller is loaded |
|
281 | + self::_load_controller(); |
|
282 | + // attempt to process message |
|
283 | + try { |
|
284 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
285 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
286 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
287 | + } catch (EE_Error $e) { |
|
288 | + $error_msg = esc_html__( |
|
289 | + 'Please note that a system message failed to send due to a technical issue.', |
|
290 | + 'event_espresso' |
|
291 | + ); |
|
292 | + // add specific message for developers if WP_DEBUG in on |
|
293 | + $error_msg .= '||' . $e->getMessage(); |
|
294 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * This is triggered by the 'msg_cron_trigger' route. |
|
301 | + * |
|
302 | + * @param WP $WP |
|
303 | + */ |
|
304 | + public function execute_batch_request($WP) |
|
305 | + { |
|
306 | + $this->run_cron(); |
|
307 | + header('HTTP/1.1 200 OK'); |
|
308 | + exit(); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
314 | + * request. |
|
315 | + */ |
|
316 | + public function run_cron() |
|
317 | + { |
|
318 | + self::_load_controller(); |
|
319 | + $request = self::getRequest(); |
|
320 | + // get required vars |
|
321 | + $cron_type = $request->getRequestParam('type'); |
|
322 | + $transient_key = $request->getRequestParam('key'); |
|
323 | + |
|
324 | + // now let's verify transient, if not valid exit immediately |
|
325 | + if (! get_transient($transient_key)) { |
|
326 | + /** |
|
327 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
328 | + * request. |
|
329 | + */ |
|
330 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
331 | + } |
|
332 | + |
|
333 | + // if made it here, lets' delete the transient to keep the db clean |
|
334 | + delete_transient($transient_key); |
|
335 | + |
|
336 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
337 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
338 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
339 | + self::$_MSG_PROCESSOR->$method(); |
|
340 | + } else { |
|
341 | + // no matching task |
|
342 | + /** |
|
343 | + * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
344 | + * request. |
|
345 | + */ |
|
346 | + trigger_error( |
|
347 | + esc_attr( |
|
348 | + sprintf( |
|
349 | + esc_html__('There is no task corresponding to this route %s', 'event_espresso'), |
|
350 | + $cron_type |
|
351 | + ) |
|
352 | + ) |
|
353 | + ); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * This is used to retrieve the template pack for the given name. |
|
363 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
364 | + * the default template pack is returned. |
|
365 | + * |
|
366 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
367 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
368 | + * in generating the Pack class name). |
|
369 | + * @return EE_Messages_Template_Pack |
|
370 | + * @throws EE_Error |
|
371 | + * @throws InvalidArgumentException |
|
372 | + * @throws ReflectionException |
|
373 | + * @throws InvalidDataTypeException |
|
374 | + * @throws InvalidInterfaceException |
|
375 | + */ |
|
376 | + public static function get_template_pack($template_pack_name) |
|
377 | + { |
|
378 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
379 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Retrieves an array of all template packs. |
|
385 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
386 | + * |
|
387 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
388 | + * @return EE_Messages_Template_Pack[] |
|
389 | + * @throws EE_Error |
|
390 | + * @throws InvalidArgumentException |
|
391 | + * @throws ReflectionException |
|
392 | + * @throws InvalidDataTypeException |
|
393 | + * @throws InvalidInterfaceException |
|
394 | + */ |
|
395 | + public static function get_template_packs() |
|
396 | + { |
|
397 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
398 | + |
|
399 | + // for backward compat, let's make sure this returns in the same format as originally. |
|
400 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
401 | + $template_pack_collection->rewind(); |
|
402 | + $template_packs = array(); |
|
403 | + while ($template_pack_collection->valid()) { |
|
404 | + $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
405 | + $template_pack_collection->next(); |
|
406 | + } |
|
407 | + return $template_packs; |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
413 | + * |
|
414 | + * @since 4.5.0 |
|
415 | + * @return void |
|
416 | + * @throws EE_Error |
|
417 | + */ |
|
418 | + public static function set_autoloaders() |
|
419 | + { |
|
420 | + if (empty(self::$_MSG_PATHS)) { |
|
421 | + self::_set_messages_paths(); |
|
422 | + foreach (self::$_MSG_PATHS as $path) { |
|
423 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
424 | + } |
|
425 | + // add aliases |
|
426 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
427 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
428 | + } |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
434 | + * for use by the Messages Autoloaders |
|
435 | + * |
|
436 | + * @since 4.5.0 |
|
437 | + * @return void. |
|
438 | + */ |
|
439 | + protected static function _set_messages_paths() |
|
440 | + { |
|
441 | + $dir_ref = array( |
|
442 | + 'messages/message_type', |
|
443 | + 'messages/messenger', |
|
444 | + 'messages/defaults', |
|
445 | + 'messages/defaults/email', |
|
446 | + 'messages/data_class', |
|
447 | + 'messages/validators', |
|
448 | + 'messages/validators/email', |
|
449 | + 'messages/validators/html', |
|
450 | + 'shortcodes', |
|
451 | + ); |
|
452 | + $paths = array(); |
|
453 | + foreach ($dir_ref as $index => $dir) { |
|
454 | + $paths[ $index ] = EE_LIBRARIES . $dir; |
|
455 | + } |
|
456 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * Takes care of loading dependencies |
|
462 | + * |
|
463 | + * @since 4.5.0 |
|
464 | + * @return void |
|
465 | + * @throws EE_Error |
|
466 | + * @throws InvalidArgumentException |
|
467 | + * @throws ReflectionException |
|
468 | + * @throws InvalidDataTypeException |
|
469 | + * @throws InvalidInterfaceException |
|
470 | + */ |
|
471 | + protected static function _load_controller() |
|
472 | + { |
|
473 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
474 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
475 | + self::set_autoloaders(); |
|
476 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
477 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
478 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
479 | + } |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @param EE_Transaction $transaction |
|
485 | + * @throws EE_Error |
|
486 | + * @throws InvalidArgumentException |
|
487 | + * @throws InvalidDataTypeException |
|
488 | + * @throws InvalidInterfaceException |
|
489 | + * @throws ReflectionException |
|
490 | + */ |
|
491 | + public static function payment_reminder(EE_Transaction $transaction) |
|
492 | + { |
|
493 | + self::_load_controller(); |
|
494 | + $data = array($transaction, null); |
|
495 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * Any messages triggers for after successful gateway payments should go in here. |
|
501 | + * |
|
502 | + * @param EE_Transaction $transaction object |
|
503 | + * @param EE_Payment|null $payment object |
|
504 | + * @return void |
|
505 | + * @throws EE_Error |
|
506 | + * @throws InvalidArgumentException |
|
507 | + * @throws ReflectionException |
|
508 | + * @throws InvalidDataTypeException |
|
509 | + * @throws InvalidInterfaceException |
|
510 | + */ |
|
511 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
512 | + { |
|
513 | + // if there's no payment object, then we cannot do a payment type message! |
|
514 | + if (! $payment instanceof EE_Payment) { |
|
515 | + return; |
|
516 | + } |
|
517 | + self::_load_controller(); |
|
518 | + $data = array($transaction, $payment); |
|
519 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
520 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
521 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
522 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
523 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * @param EE_Transaction $transaction |
|
529 | + * @throws EE_Error |
|
530 | + * @throws InvalidArgumentException |
|
531 | + * @throws InvalidDataTypeException |
|
532 | + * @throws InvalidInterfaceException |
|
533 | + * @throws ReflectionException |
|
534 | + */ |
|
535 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
536 | + { |
|
537 | + self::_load_controller(); |
|
538 | + $data = array($transaction, null); |
|
539 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * Trigger for Registration messages |
|
545 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
546 | + * incoming transaction. |
|
547 | + * |
|
548 | + * @param EE_Registration $registration |
|
549 | + * @param array $extra_details |
|
550 | + * @return void |
|
551 | + * @throws EE_Error |
|
552 | + * @throws InvalidArgumentException |
|
553 | + * @throws InvalidDataTypeException |
|
554 | + * @throws InvalidInterfaceException |
|
555 | + * @throws ReflectionException |
|
556 | + * @throws EntityNotFoundException |
|
557 | + */ |
|
558 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
559 | + { |
|
560 | + |
|
561 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
562 | + // no messages please |
|
563 | + return; |
|
564 | + } |
|
565 | + |
|
566 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
567 | + $all_registrations = $registration->transaction()->registrations( |
|
568 | + array( |
|
569 | + array('REG_deleted' => false), |
|
570 | + 'order_by' => array( |
|
571 | + 'Event.EVT_name' => 'ASC', |
|
572 | + 'Attendee.ATT_lname' => 'ASC', |
|
573 | + 'Attendee.ATT_fname' => 'ASC', |
|
574 | + ), |
|
575 | + ) |
|
576 | + ); |
|
577 | + // cached array of statuses so we only trigger messages once per status. |
|
578 | + $statuses_sent = array(); |
|
579 | + self::_load_controller(); |
|
580 | + $mtgs = array(); |
|
581 | + |
|
582 | + // loop through registrations and trigger messages once per status. |
|
583 | + foreach ($all_registrations as $reg) { |
|
584 | + // already triggered? |
|
585 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
586 | + continue; |
|
587 | + } |
|
588 | + |
|
589 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
590 | + $mtgs = array_merge( |
|
591 | + $mtgs, |
|
592 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
593 | + $message_type, |
|
594 | + array($registration->transaction(), null, $reg->status_ID()) |
|
595 | + ) |
|
596 | + ); |
|
597 | + $statuses_sent[] = $reg->status_ID(); |
|
598 | + } |
|
599 | + |
|
600 | + if (count($statuses_sent) > 1) { |
|
601 | + $mtgs = array_merge( |
|
602 | + $mtgs, |
|
603 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
604 | + 'registration_summary', |
|
605 | + array($registration->transaction(), null) |
|
606 | + ) |
|
607 | + ); |
|
608 | + } |
|
609 | + |
|
610 | + // batch queue and initiate request |
|
611 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
612 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * This is a helper method used to very whether a registration notification should be sent or |
|
618 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
619 | + * |
|
620 | + * @param EE_Registration $registration [description] |
|
621 | + * @param array $extra_details [description] |
|
622 | + * @return bool true = send away, false = nope halt the presses. |
|
623 | + */ |
|
624 | + protected static function _verify_registration_notification_send( |
|
625 | + EE_Registration $registration, |
|
626 | + $extra_details = array() |
|
627 | + ) { |
|
628 | + if (! $registration->is_primary_registrant()) { |
|
629 | + return false; |
|
630 | + } |
|
631 | + $request = self::getRequest(); |
|
632 | + // first we check if we're in admin and not doing front ajax |
|
633 | + if ( |
|
634 | + ($request->isAdmin() || $request->isAdminAjax()) |
|
635 | + && ! $request->isFrontAjax() |
|
636 | + ) { |
|
637 | + $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true); |
|
638 | + // make sure appropriate admin params are set for sending messages |
|
639 | + if (! $status_change['send_notifications']) { |
|
640 | + // no messages sent please. |
|
641 | + return false; |
|
642 | + } |
|
643 | + } else { |
|
644 | + // frontend request (either regular or via AJAX) |
|
645 | + // TXN is NOT finalized ? |
|
646 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
647 | + return false; |
|
648 | + } |
|
649 | + // return visit but nothing changed ??? |
|
650 | + if ( |
|
651 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
652 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
653 | + ) { |
|
654 | + return false; |
|
655 | + } |
|
656 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
657 | + if ( |
|
658 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
659 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
660 | + ) { |
|
661 | + return false; |
|
662 | + } |
|
663 | + } |
|
664 | + // release the kraken |
|
665 | + return true; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
671 | + * status id. |
|
672 | + * |
|
673 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
674 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
675 | + * @param string $reg_status |
|
676 | + * @return array |
|
677 | + * @throws EE_Error |
|
678 | + * @throws InvalidArgumentException |
|
679 | + * @throws ReflectionException |
|
680 | + * @throws InvalidDataTypeException |
|
681 | + * @throws InvalidInterfaceException |
|
682 | + */ |
|
683 | + protected static function _get_reg_status_array($reg_status = '') |
|
684 | + { |
|
685 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
686 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
687 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
688 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * Simply returns the payment message type for the given payment status. |
|
694 | + * |
|
695 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
696 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
697 | + * @param string $payment_status The payment status being matched. |
|
698 | + * @return bool|string The payment message type slug matching the status or false if no match. |
|
699 | + * @throws EE_Error |
|
700 | + * @throws InvalidArgumentException |
|
701 | + * @throws ReflectionException |
|
702 | + * @throws InvalidDataTypeException |
|
703 | + * @throws InvalidInterfaceException |
|
704 | + */ |
|
705 | + protected static function _get_payment_message_type($payment_status) |
|
706 | + { |
|
707 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
708 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
709 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
710 | + : false; |
|
711 | + } |
|
712 | + |
|
713 | + |
|
714 | + /** |
|
715 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
716 | + * |
|
717 | + * @access public |
|
718 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
719 | + * @return bool success/fail |
|
720 | + * @throws EE_Error |
|
721 | + * @throws InvalidArgumentException |
|
722 | + * @throws InvalidDataTypeException |
|
723 | + * @throws InvalidInterfaceException |
|
724 | + * @throws ReflectionException |
|
725 | + */ |
|
726 | + public static function process_resend(array $req_data = []) |
|
727 | + { |
|
728 | + self::_load_controller(); |
|
729 | + $request = self::getRequest(); |
|
730 | + // if $msgID in this request then skip to the new resend_message |
|
731 | + if ($request->getRequestParam('MSG_ID')) { |
|
732 | + return self::resend_message(); |
|
733 | + } |
|
734 | + |
|
735 | + // make sure any incoming request data is set on the request so that it gets picked up later. |
|
736 | + foreach ((array) $req_data as $request_key => $request_value) { |
|
737 | + if (! $request->requestParamIsSet($request_key)) { |
|
738 | + $request->setRequestParam($request_key, $request_value); |
|
739 | + } |
|
740 | + } |
|
741 | + |
|
742 | + if ( |
|
743 | + ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request() |
|
744 | + ) { |
|
745 | + return false; |
|
746 | + } |
|
747 | + |
|
748 | + try { |
|
749 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
750 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
751 | + } catch (EE_Error $e) { |
|
752 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
753 | + return false; |
|
754 | + } |
|
755 | + EE_Error::add_success( |
|
756 | + esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
757 | + ); |
|
758 | + return true; // everything got queued. |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
764 | + * |
|
765 | + * @return bool |
|
766 | + * @throws EE_Error |
|
767 | + * @throws InvalidArgumentException |
|
768 | + * @throws InvalidDataTypeException |
|
769 | + * @throws InvalidInterfaceException |
|
770 | + * @throws ReflectionException |
|
771 | + */ |
|
772 | + public static function resend_message() |
|
773 | + { |
|
774 | + self::_load_controller(); |
|
775 | + |
|
776 | + $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int'); |
|
777 | + if (! $msgID) { |
|
778 | + EE_Error::add_error( |
|
779 | + esc_html__( |
|
780 | + 'Something went wrong because there is no "MSG_ID" value in the request', |
|
781 | + 'event_espresso' |
|
782 | + ), |
|
783 | + __FILE__, |
|
784 | + __FUNCTION__, |
|
785 | + __LINE__ |
|
786 | + ); |
|
787 | + return false; |
|
788 | + } |
|
789 | + |
|
790 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
791 | + |
|
792 | + // setup success message. |
|
793 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
794 | + EE_Error::add_success( |
|
795 | + sprintf( |
|
796 | + _n( |
|
797 | + 'There was %d message queued for resending.', |
|
798 | + 'There were %d messages queued for resending.', |
|
799 | + $count_ready_for_resend, |
|
800 | + 'event_espresso' |
|
801 | + ), |
|
802 | + $count_ready_for_resend |
|
803 | + ) |
|
804 | + ); |
|
805 | + return true; |
|
806 | + } |
|
807 | + |
|
808 | + |
|
809 | + /** |
|
810 | + * Message triggers for manual payment applied by admin |
|
811 | + * |
|
812 | + * @param EE_Payment $payment EE_payment object |
|
813 | + * @return bool success/fail |
|
814 | + * @throws EE_Error |
|
815 | + * @throws InvalidArgumentException |
|
816 | + * @throws ReflectionException |
|
817 | + * @throws InvalidDataTypeException |
|
818 | + * @throws InvalidInterfaceException |
|
819 | + */ |
|
820 | + public static function process_admin_payment(EE_Payment $payment) |
|
821 | + { |
|
822 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
823 | + // we need to get the transaction object |
|
824 | + $transaction = $payment->transaction(); |
|
825 | + if ($transaction instanceof EE_Transaction) { |
|
826 | + $data = array($transaction, $payment); |
|
827 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
828 | + |
|
829 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
830 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
831 | + |
|
832 | + // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
833 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
834 | + ? false : $message_type; |
|
835 | + |
|
836 | + self::_load_controller(); |
|
837 | + |
|
838 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
839 | + |
|
840 | + // get count of queued for generation |
|
841 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
842 | + array( |
|
843 | + EEM_Message::status_incomplete, |
|
844 | + EEM_Message::status_idle, |
|
845 | + ) |
|
846 | + ); |
|
847 | + |
|
848 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
849 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
850 | + return true; |
|
851 | + } else { |
|
852 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
853 | + EEM_Message::instance()->stati_indicating_failed_sending() |
|
854 | + ); |
|
855 | + /** |
|
856 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
857 | + * IMMEDIATE generation. |
|
858 | + */ |
|
859 | + if ($count_failed > 0) { |
|
860 | + EE_Error::add_error( |
|
861 | + sprintf( |
|
862 | + _n( |
|
863 | + 'The payment notification generation failed.', |
|
864 | + '%d payment notifications failed being sent.', |
|
865 | + $count_failed, |
|
866 | + 'event_espresso' |
|
867 | + ), |
|
868 | + $count_failed |
|
869 | + ), |
|
870 | + __FILE__, |
|
871 | + __FUNCTION__, |
|
872 | + __LINE__ |
|
873 | + ); |
|
874 | + |
|
875 | + return false; |
|
876 | + } else { |
|
877 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
878 | + return true; |
|
879 | + } |
|
880 | + } |
|
881 | + } else { |
|
882 | + EE_Error::add_error( |
|
883 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
884 | + 'event_espresso' |
|
885 | + ); |
|
886 | + return false; |
|
887 | + } |
|
888 | + } |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
893 | + * |
|
894 | + * @since 4.3.0 |
|
895 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
896 | + * @param int $grp_id a specific message template group id. |
|
897 | + * @return void |
|
898 | + * @throws EE_Error |
|
899 | + * @throws InvalidArgumentException |
|
900 | + * @throws InvalidDataTypeException |
|
901 | + * @throws InvalidInterfaceException |
|
902 | + * @throws ReflectionException |
|
903 | + */ |
|
904 | + public static function send_newsletter_message($registrations, $grp_id) |
|
905 | + { |
|
906 | + // make sure mtp is id and set it in the request later messages setup. |
|
907 | + self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id); |
|
908 | + self::_load_controller(); |
|
909 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
910 | + } |
|
911 | + |
|
912 | + |
|
913 | + /** |
|
914 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
915 | + * |
|
916 | + * @since 4.3.0 |
|
917 | + * @param string $registration_message_trigger_url |
|
918 | + * @param EE_Registration $registration |
|
919 | + * @param string $messenger |
|
920 | + * @param string $message_type |
|
921 | + * @return string |
|
922 | + * @throws EE_Error |
|
923 | + * @throws InvalidArgumentException |
|
924 | + * @throws InvalidDataTypeException |
|
925 | + * @throws InvalidInterfaceException |
|
926 | + */ |
|
927 | + public static function registration_message_trigger_url( |
|
928 | + $registration_message_trigger_url, |
|
929 | + EE_Registration $registration, |
|
930 | + $messenger = 'html', |
|
931 | + $message_type = 'invoice' |
|
932 | + ) { |
|
933 | + // whitelist $messenger |
|
934 | + switch ($messenger) { |
|
935 | + case 'pdf': |
|
936 | + $sending_messenger = 'pdf'; |
|
937 | + $generating_messenger = 'html'; |
|
938 | + break; |
|
939 | + case 'html': |
|
940 | + default: |
|
941 | + $sending_messenger = 'html'; |
|
942 | + $generating_messenger = 'html'; |
|
943 | + break; |
|
944 | + } |
|
945 | + // whitelist $message_type |
|
946 | + switch ($message_type) { |
|
947 | + case 'receipt': |
|
948 | + $message_type = 'receipt'; |
|
949 | + break; |
|
950 | + case 'invoice': |
|
951 | + default: |
|
952 | + $message_type = 'invoice'; |
|
953 | + break; |
|
954 | + } |
|
955 | + // verify that both the messenger AND the message type are active |
|
956 | + if ( |
|
957 | + EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
958 | + && EEH_MSG_Template::is_mt_active($message_type) |
|
959 | + ) { |
|
960 | + // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
961 | + $template_query_params = array( |
|
962 | + 'MTP_is_active' => true, |
|
963 | + 'MTP_messenger' => $generating_messenger, |
|
964 | + 'MTP_message_type' => $message_type, |
|
965 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
966 | + ); |
|
967 | + // get the message template group. |
|
968 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
969 | + // if we don't have an EE_Message_Template_Group then return |
|
970 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
971 | + // remove EVT_ID from query params so that global templates get picked up |
|
972 | + unset($template_query_params['Event.EVT_ID']); |
|
973 | + // get global template as the fallback |
|
974 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
975 | + } |
|
976 | + // if we don't have an EE_Message_Template_Group then return |
|
977 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
978 | + return ''; |
|
979 | + } |
|
980 | + // generate the URL |
|
981 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
982 | + $sending_messenger, |
|
983 | + $generating_messenger, |
|
984 | + 'purchaser', |
|
985 | + $message_type, |
|
986 | + $registration, |
|
987 | + $msg_template_group->ID(), |
|
988 | + $registration->transaction_ID() |
|
989 | + ); |
|
990 | + } |
|
991 | + return $registration_message_trigger_url; |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + /** |
|
996 | + * Use to generate and return a message preview! |
|
997 | + * |
|
998 | + * @param string $type This should correspond with a valid message type |
|
999 | + * @param string $context This should correspond with a valid context for the message type |
|
1000 | + * @param string $messenger This should correspond with a valid messenger. |
|
1001 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
1002 | + * preview |
|
1003 | + * @return bool|string The body of the message or if send is requested, sends. |
|
1004 | + * @throws EE_Error |
|
1005 | + * @throws InvalidArgumentException |
|
1006 | + * @throws InvalidDataTypeException |
|
1007 | + * @throws InvalidInterfaceException |
|
1008 | + * @throws ReflectionException |
|
1009 | + */ |
|
1010 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
1011 | + { |
|
1012 | + self::_load_controller(); |
|
1013 | + $mtg = new EE_Message_To_Generate( |
|
1014 | + $messenger, |
|
1015 | + $type, |
|
1016 | + array(), |
|
1017 | + $context, |
|
1018 | + true |
|
1019 | + ); |
|
1020 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
1021 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
1022 | + // loop through all content for the preview and remove any persisted records. |
|
1023 | + $content = ''; |
|
1024 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
1025 | + $content = $message->content(); |
|
1026 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
1027 | + $message->delete(); |
|
1028 | + } |
|
1029 | + } |
|
1030 | + return $content; |
|
1031 | + } else { |
|
1032 | + return $generated_preview_queue; |
|
1033 | + } |
|
1034 | + } |
|
1035 | + |
|
1036 | + |
|
1037 | + /** |
|
1038 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
1039 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
1040 | + * content found in the EE_Message objects in the queue. |
|
1041 | + * |
|
1042 | + * @since 4.9.0 |
|
1043 | + * @param string $messenger a string matching a valid active messenger in the system |
|
1044 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
1045 | + * type name is still required to send along the message type to the |
|
1046 | + * messenger because this is used for determining what specific |
|
1047 | + * variations might be loaded for the generated message. |
|
1048 | + * @param EE_Messages_Queue $queue |
|
1049 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
1050 | + * aggregate EE_Message object. |
|
1051 | + * @return bool success or fail. |
|
1052 | + * @throws EE_Error |
|
1053 | + * @throws InvalidArgumentException |
|
1054 | + * @throws ReflectionException |
|
1055 | + * @throws InvalidDataTypeException |
|
1056 | + * @throws InvalidInterfaceException |
|
1057 | + */ |
|
1058 | + public static function send_message_with_messenger_only( |
|
1059 | + $messenger, |
|
1060 | + $message_type, |
|
1061 | + EE_Messages_Queue $queue, |
|
1062 | + $custom_subject = '' |
|
1063 | + ) { |
|
1064 | + self::_load_controller(); |
|
1065 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
1066 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
1067 | + 'Message_To_Generate_From_Queue', |
|
1068 | + array( |
|
1069 | + $messenger, |
|
1070 | + $message_type, |
|
1071 | + $queue, |
|
1072 | + $custom_subject, |
|
1073 | + ) |
|
1074 | + ); |
|
1075 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
1076 | + } |
|
1077 | + |
|
1078 | + |
|
1079 | + /** |
|
1080 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
1081 | + * |
|
1082 | + * @since 4.9.0 |
|
1083 | + * @param array $message_ids An array of message ids |
|
1084 | + * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
1085 | + * messages. |
|
1086 | + * @throws EE_Error |
|
1087 | + * @throws InvalidArgumentException |
|
1088 | + * @throws InvalidDataTypeException |
|
1089 | + * @throws InvalidInterfaceException |
|
1090 | + * @throws ReflectionException |
|
1091 | + */ |
|
1092 | + public static function generate_now($message_ids) |
|
1093 | + { |
|
1094 | + self::_load_controller(); |
|
1095 | + $messages = EEM_Message::instance()->get_all( |
|
1096 | + array( |
|
1097 | + 0 => array( |
|
1098 | + 'MSG_ID' => array('IN', $message_ids), |
|
1099 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
1100 | + ), |
|
1101 | + ) |
|
1102 | + ); |
|
1103 | + $generated_queue = false; |
|
1104 | + if ($messages) { |
|
1105 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
1106 | + } |
|
1107 | + |
|
1108 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
1109 | + EE_Error::add_error( |
|
1110 | + esc_html__( |
|
1111 | + 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
1112 | + 'event_espresso' |
|
1113 | + ), |
|
1114 | + __FILE__, |
|
1115 | + __FUNCTION__, |
|
1116 | + __LINE__ |
|
1117 | + ); |
|
1118 | + } |
|
1119 | + return $generated_queue; |
|
1120 | + } |
|
1121 | + |
|
1122 | + |
|
1123 | + /** |
|
1124 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
1125 | + * EEM_Message::status_idle |
|
1126 | + * |
|
1127 | + * @since 4.9.0 |
|
1128 | + * @param $message_ids |
|
1129 | + * @return bool|EE_Messages_Queue false if no messages sent. |
|
1130 | + * @throws EE_Error |
|
1131 | + * @throws InvalidArgumentException |
|
1132 | + * @throws InvalidDataTypeException |
|
1133 | + * @throws InvalidInterfaceException |
|
1134 | + * @throws ReflectionException |
|
1135 | + */ |
|
1136 | + public static function send_now($message_ids) |
|
1137 | + { |
|
1138 | + self::_load_controller(); |
|
1139 | + $messages = EEM_Message::instance()->get_all( |
|
1140 | + array( |
|
1141 | + 0 => array( |
|
1142 | + 'MSG_ID' => array('IN', $message_ids), |
|
1143 | + 'STS_ID' => array( |
|
1144 | + 'IN', |
|
1145 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
1146 | + ), |
|
1147 | + ), |
|
1148 | + ) |
|
1149 | + ); |
|
1150 | + $sent_queue = false; |
|
1151 | + if ($messages) { |
|
1152 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
1153 | + } |
|
1154 | + |
|
1155 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
1156 | + EE_Error::add_error( |
|
1157 | + esc_html__( |
|
1158 | + 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
1159 | + 'event_espresso' |
|
1160 | + ), |
|
1161 | + __FILE__, |
|
1162 | + __FUNCTION__, |
|
1163 | + __LINE__ |
|
1164 | + ); |
|
1165 | + } else { |
|
1166 | + // can count how many sent by using the messages in the queue |
|
1167 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
1168 | + if ($sent_count > 0) { |
|
1169 | + EE_Error::add_success( |
|
1170 | + sprintf( |
|
1171 | + _n( |
|
1172 | + 'There was %d message successfully sent.', |
|
1173 | + 'There were %d messages successfully sent.', |
|
1174 | + $sent_count, |
|
1175 | + 'event_espresso' |
|
1176 | + ), |
|
1177 | + $sent_count |
|
1178 | + ) |
|
1179 | + ); |
|
1180 | + } else { |
|
1181 | + EE_Error::overwrite_errors(); |
|
1182 | + EE_Error::add_error( |
|
1183 | + esc_html__( |
|
1184 | + 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
1185 | 1185 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
1186 | - 'event_espresso' |
|
1187 | - ), |
|
1188 | - __FILE__, |
|
1189 | - __FUNCTION__, |
|
1190 | - __LINE__ |
|
1191 | - ); |
|
1192 | - } |
|
1193 | - } |
|
1194 | - return $sent_queue; |
|
1195 | - } |
|
1196 | - |
|
1197 | - |
|
1198 | - /** |
|
1199 | - * Generate and send immediately from the given $message_ids |
|
1200 | - * |
|
1201 | - * @param array $message_ids EE_Message entity ids. |
|
1202 | - * @throws EE_Error |
|
1203 | - * @throws InvalidArgumentException |
|
1204 | - * @throws InvalidDataTypeException |
|
1205 | - * @throws InvalidInterfaceException |
|
1206 | - * @throws ReflectionException |
|
1207 | - */ |
|
1208 | - public static function generate_and_send_now(array $message_ids) |
|
1209 | - { |
|
1210 | - $generated_queue = self::generate_now($message_ids); |
|
1211 | - // now let's just trigger sending immediately from this queue. |
|
1212 | - $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
1213 | - ? $generated_queue->execute() |
|
1214 | - : 0; |
|
1215 | - if ($messages_sent) { |
|
1216 | - EE_Error::add_success( |
|
1217 | - esc_html( |
|
1218 | - sprintf( |
|
1219 | - _n( |
|
1220 | - 'There was %d message successfully generated and sent.', |
|
1221 | - 'There were %d messages successfully generated and sent.', |
|
1222 | - $messages_sent, |
|
1223 | - 'event_espresso' |
|
1224 | - ), |
|
1225 | - $messages_sent |
|
1226 | - ) |
|
1227 | - ) |
|
1228 | - ); |
|
1229 | - // errors would be added via the generate_now method. |
|
1230 | - } |
|
1231 | - } |
|
1232 | - |
|
1233 | - |
|
1234 | - /** |
|
1235 | - * This will queue the incoming message ids for resending. |
|
1236 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
1237 | - * |
|
1238 | - * @since 4.9.0 |
|
1239 | - * @param array $message_ids An array of EE_Message IDs |
|
1240 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
1241 | - * resending. |
|
1242 | - * @throws EE_Error |
|
1243 | - * @throws InvalidArgumentException |
|
1244 | - * @throws InvalidDataTypeException |
|
1245 | - * @throws InvalidInterfaceException |
|
1246 | - * @throws ReflectionException |
|
1247 | - */ |
|
1248 | - public static function queue_for_resending($message_ids) |
|
1249 | - { |
|
1250 | - self::_load_controller(); |
|
1251 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1252 | - |
|
1253 | - // get queue and count |
|
1254 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1255 | - |
|
1256 | - if ( |
|
1257 | - $queue_count > 0 |
|
1258 | - ) { |
|
1259 | - EE_Error::add_success( |
|
1260 | - sprintf( |
|
1261 | - _n( |
|
1262 | - '%d message successfully queued for resending.', |
|
1263 | - '%d messages successfully queued for resending.', |
|
1264 | - $queue_count, |
|
1265 | - 'event_espresso' |
|
1266 | - ), |
|
1267 | - $queue_count |
|
1268 | - ) |
|
1269 | - ); |
|
1270 | - /** |
|
1271 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1272 | - */ |
|
1273 | - } elseif ( |
|
1274 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1275 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1276 | - ) { |
|
1277 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1278 | - if ($queue_count > 0) { |
|
1279 | - EE_Error::add_success( |
|
1280 | - sprintf( |
|
1281 | - _n( |
|
1282 | - '%d message successfully sent.', |
|
1283 | - '%d messages successfully sent.', |
|
1284 | - $queue_count, |
|
1285 | - 'event_espresso' |
|
1286 | - ), |
|
1287 | - $queue_count |
|
1288 | - ) |
|
1289 | - ); |
|
1290 | - } else { |
|
1291 | - EE_Error::add_error( |
|
1292 | - esc_html__( |
|
1293 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1294 | - 'event_espresso' |
|
1295 | - ), |
|
1296 | - __FILE__, |
|
1297 | - __FUNCTION__, |
|
1298 | - __LINE__ |
|
1299 | - ); |
|
1300 | - } |
|
1301 | - } else { |
|
1302 | - EE_Error::add_error( |
|
1303 | - esc_html__( |
|
1304 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1305 | - 'event_espresso' |
|
1306 | - ), |
|
1307 | - __FILE__, |
|
1308 | - __FUNCTION__, |
|
1309 | - __LINE__ |
|
1310 | - ); |
|
1311 | - } |
|
1312 | - return (bool) $queue_count; |
|
1313 | - } |
|
1314 | - |
|
1315 | - |
|
1316 | - /** |
|
1317 | - * debug |
|
1318 | - * |
|
1319 | - * @param string $class |
|
1320 | - * @param string $func |
|
1321 | - * @param string $line |
|
1322 | - * @param \EE_Transaction $transaction |
|
1323 | - * @param array $info |
|
1324 | - * @param bool $display_request |
|
1325 | - * @throws EE_Error |
|
1326 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
1327 | - */ |
|
1328 | - protected static function log( |
|
1329 | - $class = '', |
|
1330 | - $func = '', |
|
1331 | - $line = '', |
|
1332 | - EE_Transaction $transaction, |
|
1333 | - $info = array(), |
|
1334 | - $display_request = false |
|
1335 | - ) { |
|
1336 | - if (defined('EE_DEBUG') && EE_DEBUG) { |
|
1337 | - if ($transaction instanceof EE_Transaction) { |
|
1338 | - // don't serialize objects |
|
1339 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
1340 | - $info['TXN_status'] = $transaction->status_ID(); |
|
1341 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1342 | - if ($transaction->ID()) { |
|
1343 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1344 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1345 | - } |
|
1346 | - } |
|
1347 | - } |
|
1348 | - } |
|
1349 | - |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Resets all the static properties in this class when called. |
|
1353 | - */ |
|
1354 | - public static function reset() |
|
1355 | - { |
|
1356 | - self::$_EEMSG = null; |
|
1357 | - self::$_message_resource_manager = null; |
|
1358 | - self::$_MSG_PROCESSOR = null; |
|
1359 | - self::$_MSG_PATHS = null; |
|
1360 | - self::$_TMP_PACKS = array(); |
|
1361 | - } |
|
1186 | + 'event_espresso' |
|
1187 | + ), |
|
1188 | + __FILE__, |
|
1189 | + __FUNCTION__, |
|
1190 | + __LINE__ |
|
1191 | + ); |
|
1192 | + } |
|
1193 | + } |
|
1194 | + return $sent_queue; |
|
1195 | + } |
|
1196 | + |
|
1197 | + |
|
1198 | + /** |
|
1199 | + * Generate and send immediately from the given $message_ids |
|
1200 | + * |
|
1201 | + * @param array $message_ids EE_Message entity ids. |
|
1202 | + * @throws EE_Error |
|
1203 | + * @throws InvalidArgumentException |
|
1204 | + * @throws InvalidDataTypeException |
|
1205 | + * @throws InvalidInterfaceException |
|
1206 | + * @throws ReflectionException |
|
1207 | + */ |
|
1208 | + public static function generate_and_send_now(array $message_ids) |
|
1209 | + { |
|
1210 | + $generated_queue = self::generate_now($message_ids); |
|
1211 | + // now let's just trigger sending immediately from this queue. |
|
1212 | + $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
1213 | + ? $generated_queue->execute() |
|
1214 | + : 0; |
|
1215 | + if ($messages_sent) { |
|
1216 | + EE_Error::add_success( |
|
1217 | + esc_html( |
|
1218 | + sprintf( |
|
1219 | + _n( |
|
1220 | + 'There was %d message successfully generated and sent.', |
|
1221 | + 'There were %d messages successfully generated and sent.', |
|
1222 | + $messages_sent, |
|
1223 | + 'event_espresso' |
|
1224 | + ), |
|
1225 | + $messages_sent |
|
1226 | + ) |
|
1227 | + ) |
|
1228 | + ); |
|
1229 | + // errors would be added via the generate_now method. |
|
1230 | + } |
|
1231 | + } |
|
1232 | + |
|
1233 | + |
|
1234 | + /** |
|
1235 | + * This will queue the incoming message ids for resending. |
|
1236 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
1237 | + * |
|
1238 | + * @since 4.9.0 |
|
1239 | + * @param array $message_ids An array of EE_Message IDs |
|
1240 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
1241 | + * resending. |
|
1242 | + * @throws EE_Error |
|
1243 | + * @throws InvalidArgumentException |
|
1244 | + * @throws InvalidDataTypeException |
|
1245 | + * @throws InvalidInterfaceException |
|
1246 | + * @throws ReflectionException |
|
1247 | + */ |
|
1248 | + public static function queue_for_resending($message_ids) |
|
1249 | + { |
|
1250 | + self::_load_controller(); |
|
1251 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1252 | + |
|
1253 | + // get queue and count |
|
1254 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1255 | + |
|
1256 | + if ( |
|
1257 | + $queue_count > 0 |
|
1258 | + ) { |
|
1259 | + EE_Error::add_success( |
|
1260 | + sprintf( |
|
1261 | + _n( |
|
1262 | + '%d message successfully queued for resending.', |
|
1263 | + '%d messages successfully queued for resending.', |
|
1264 | + $queue_count, |
|
1265 | + 'event_espresso' |
|
1266 | + ), |
|
1267 | + $queue_count |
|
1268 | + ) |
|
1269 | + ); |
|
1270 | + /** |
|
1271 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1272 | + */ |
|
1273 | + } elseif ( |
|
1274 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1275 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1276 | + ) { |
|
1277 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1278 | + if ($queue_count > 0) { |
|
1279 | + EE_Error::add_success( |
|
1280 | + sprintf( |
|
1281 | + _n( |
|
1282 | + '%d message successfully sent.', |
|
1283 | + '%d messages successfully sent.', |
|
1284 | + $queue_count, |
|
1285 | + 'event_espresso' |
|
1286 | + ), |
|
1287 | + $queue_count |
|
1288 | + ) |
|
1289 | + ); |
|
1290 | + } else { |
|
1291 | + EE_Error::add_error( |
|
1292 | + esc_html__( |
|
1293 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1294 | + 'event_espresso' |
|
1295 | + ), |
|
1296 | + __FILE__, |
|
1297 | + __FUNCTION__, |
|
1298 | + __LINE__ |
|
1299 | + ); |
|
1300 | + } |
|
1301 | + } else { |
|
1302 | + EE_Error::add_error( |
|
1303 | + esc_html__( |
|
1304 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1305 | + 'event_espresso' |
|
1306 | + ), |
|
1307 | + __FILE__, |
|
1308 | + __FUNCTION__, |
|
1309 | + __LINE__ |
|
1310 | + ); |
|
1311 | + } |
|
1312 | + return (bool) $queue_count; |
|
1313 | + } |
|
1314 | + |
|
1315 | + |
|
1316 | + /** |
|
1317 | + * debug |
|
1318 | + * |
|
1319 | + * @param string $class |
|
1320 | + * @param string $func |
|
1321 | + * @param string $line |
|
1322 | + * @param \EE_Transaction $transaction |
|
1323 | + * @param array $info |
|
1324 | + * @param bool $display_request |
|
1325 | + * @throws EE_Error |
|
1326 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
1327 | + */ |
|
1328 | + protected static function log( |
|
1329 | + $class = '', |
|
1330 | + $func = '', |
|
1331 | + $line = '', |
|
1332 | + EE_Transaction $transaction, |
|
1333 | + $info = array(), |
|
1334 | + $display_request = false |
|
1335 | + ) { |
|
1336 | + if (defined('EE_DEBUG') && EE_DEBUG) { |
|
1337 | + if ($transaction instanceof EE_Transaction) { |
|
1338 | + // don't serialize objects |
|
1339 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
1340 | + $info['TXN_status'] = $transaction->status_ID(); |
|
1341 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1342 | + if ($transaction->ID()) { |
|
1343 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1344 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1345 | + } |
|
1346 | + } |
|
1347 | + } |
|
1348 | + } |
|
1349 | + |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * Resets all the static properties in this class when called. |
|
1353 | + */ |
|
1354 | + public static function reset() |
|
1355 | + { |
|
1356 | + self::$_EEMSG = null; |
|
1357 | + self::$_message_resource_manager = null; |
|
1358 | + self::$_MSG_PROCESSOR = null; |
|
1359 | + self::$_MSG_PATHS = null; |
|
1360 | + self::$_TMP_PACKS = array(); |
|
1361 | + } |
|
1362 | 1362 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | 'event_espresso' |
205 | 205 | ); |
206 | 206 | // add specific message for developers if WP_DEBUG in on |
207 | - $error_msg .= '||' . $e->getMessage(); |
|
207 | + $error_msg .= '||'.$e->getMessage(); |
|
208 | 208 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
209 | 209 | } |
210 | 210 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | 'event_espresso' |
291 | 291 | ); |
292 | 292 | // add specific message for developers if WP_DEBUG in on |
293 | - $error_msg .= '||' . $e->getMessage(); |
|
293 | + $error_msg .= '||'.$e->getMessage(); |
|
294 | 294 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
295 | 295 | } |
296 | 296 | } |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | $transient_key = $request->getRequestParam('key'); |
323 | 323 | |
324 | 324 | // now let's verify transient, if not valid exit immediately |
325 | - if (! get_transient($transient_key)) { |
|
325 | + if ( ! get_transient($transient_key)) { |
|
326 | 326 | /** |
327 | 327 | * trigger error so this gets in the error logs. This is important because it happens on a non-user |
328 | 328 | * request. |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | delete_transient($transient_key); |
335 | 335 | |
336 | 336 | if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
337 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
337 | + $method = 'batch_'.$cron_type.'_from_queue'; |
|
338 | 338 | if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
339 | 339 | self::$_MSG_PROCESSOR->$method(); |
340 | 340 | } else { |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | $template_pack_collection->rewind(); |
402 | 402 | $template_packs = array(); |
403 | 403 | while ($template_pack_collection->valid()) { |
404 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
404 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
405 | 405 | $template_pack_collection->next(); |
406 | 406 | } |
407 | 407 | return $template_packs; |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | ); |
452 | 452 | $paths = array(); |
453 | 453 | foreach ($dir_ref as $index => $dir) { |
454 | - $paths[ $index ] = EE_LIBRARIES . $dir; |
|
454 | + $paths[$index] = EE_LIBRARIES.$dir; |
|
455 | 455 | } |
456 | 456 | self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
457 | 457 | } |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | */ |
471 | 471 | protected static function _load_controller() |
472 | 472 | { |
473 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
473 | + if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
474 | 474 | EE_Registry::instance()->load_core('Request_Handler'); |
475 | 475 | self::set_autoloaders(); |
476 | 476 | self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
512 | 512 | { |
513 | 513 | // if there's no payment object, then we cannot do a payment type message! |
514 | - if (! $payment instanceof EE_Payment) { |
|
514 | + if ( ! $payment instanceof EE_Payment) { |
|
515 | 515 | return; |
516 | 516 | } |
517 | 517 | self::_load_controller(); |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
559 | 559 | { |
560 | 560 | |
561 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
561 | + if ( ! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
562 | 562 | // no messages please |
563 | 563 | return; |
564 | 564 | } |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | EE_Registration $registration, |
626 | 626 | $extra_details = array() |
627 | 627 | ) { |
628 | - if (! $registration->is_primary_registrant()) { |
|
628 | + if ( ! $registration->is_primary_registrant()) { |
|
629 | 629 | return false; |
630 | 630 | } |
631 | 631 | $request = self::getRequest(); |
@@ -636,14 +636,14 @@ discard block |
||
636 | 636 | ) { |
637 | 637 | $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true); |
638 | 638 | // make sure appropriate admin params are set for sending messages |
639 | - if (! $status_change['send_notifications']) { |
|
639 | + if ( ! $status_change['send_notifications']) { |
|
640 | 640 | // no messages sent please. |
641 | 641 | return false; |
642 | 642 | } |
643 | 643 | } else { |
644 | 644 | // frontend request (either regular or via AJAX) |
645 | 645 | // TXN is NOT finalized ? |
646 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
646 | + if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
647 | 647 | return false; |
648 | 648 | } |
649 | 649 | // return visit but nothing changed ??? |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | |
735 | 735 | // make sure any incoming request data is set on the request so that it gets picked up later. |
736 | 736 | foreach ((array) $req_data as $request_key => $request_value) { |
737 | - if (! $request->requestParamIsSet($request_key)) { |
|
737 | + if ( ! $request->requestParamIsSet($request_key)) { |
|
738 | 738 | $request->setRequestParam($request_key, $request_value); |
739 | 739 | } |
740 | 740 | } |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | self::_load_controller(); |
775 | 775 | |
776 | 776 | $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int'); |
777 | - if (! $msgID) { |
|
777 | + if ( ! $msgID) { |
|
778 | 778 | EE_Error::add_error( |
779 | 779 | esc_html__( |
780 | 780 | 'Something went wrong because there is no "MSG_ID" value in the request', |
@@ -967,14 +967,14 @@ discard block |
||
967 | 967 | // get the message template group. |
968 | 968 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
969 | 969 | // if we don't have an EE_Message_Template_Group then return |
970 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
970 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
971 | 971 | // remove EVT_ID from query params so that global templates get picked up |
972 | 972 | unset($template_query_params['Event.EVT_ID']); |
973 | 973 | // get global template as the fallback |
974 | 974 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
975 | 975 | } |
976 | 976 | // if we don't have an EE_Message_Template_Group then return |
977 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
977 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
978 | 978 | return ''; |
979 | 979 | } |
980 | 980 | // generate the URL |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
1106 | 1106 | } |
1107 | 1107 | |
1108 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
1108 | + if ( ! $generated_queue instanceof EE_Messages_Queue) { |
|
1109 | 1109 | EE_Error::add_error( |
1110 | 1110 | esc_html__( |
1111 | 1111 | 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
1153 | 1153 | } |
1154 | 1154 | |
1155 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
1155 | + if ( ! $sent_queue instanceof EE_Messages_Queue) { |
|
1156 | 1156 | EE_Error::add_error( |
1157 | 1157 | esc_html__( |
1158 | 1158 | 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
@@ -1340,7 +1340,7 @@ discard block |
||
1340 | 1340 | $info['TXN_status'] = $transaction->status_ID(); |
1341 | 1341 | $info['TXN_reg_steps'] = $transaction->reg_steps(); |
1342 | 1342 | if ($transaction->ID()) { |
1343 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1343 | + $index = 'EE_Transaction: '.$transaction->ID(); |
|
1344 | 1344 | EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
1345 | 1345 | } |
1346 | 1346 | } |