@@ -12,1117 +12,1117 @@ |
||
12 | 12 | class EE_Message_Resource_Manager |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * This option in the database is used to keep a record of message types that have been activated for a messenger |
|
17 | - * at some point in the history of the site. It is utilized by the implementation of the 'force' flag in |
|
18 | - * EE_Register_Message_Type. The force flag is an indication of whether a message type should be activated by |
|
19 | - * default when the message type is registered. However, if a user has explicitly deactivated a message type, then |
|
20 | - * the force flag is ignored. The method by which the code knows whether to ignore this flag is via this option. |
|
21 | - * Note, that this is NOT a historical record. Its entirely possible for a message type to have been activated for |
|
22 | - * a messenger and yet not have a record in this option. This occurs when a message type is inactivated through an |
|
23 | - * automated process (when an add-on registering the message type deactivates, or when some other code calls the |
|
24 | - * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure |
|
25 | - * the "force" flag is respected if that message type is later re-registered. |
|
26 | - * |
|
27 | - * This option should NOT be used to determine the current "active" state of a message type for a given messenger. |
|
28 | - * |
|
29 | - * The name of this option (and related methods/properties) is due to matching the original intended purpose for the |
|
30 | - * option that got superseded by later behaviour requirements. |
|
31 | - */ |
|
32 | - const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger'; |
|
33 | - |
|
34 | - /** |
|
35 | - * @type boolean $_initialized |
|
36 | - */ |
|
37 | - protected $_initialized = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * @type EE_Messenger_Collection $_messenger_collection_loader |
|
41 | - */ |
|
42 | - protected $_messenger_collection_loader; |
|
43 | - |
|
44 | - /** |
|
45 | - * @type EE_Message_Type_Collection $_message_type_collection_loader |
|
46 | - */ |
|
47 | - protected $_message_type_collection_loader; |
|
48 | - |
|
49 | - /** |
|
50 | - * @type EEM_Message_Template_Group $_message_template_group_model |
|
51 | - */ |
|
52 | - protected $_message_template_group_model; |
|
53 | - |
|
54 | - /** |
|
55 | - * @type EE_messenger[] |
|
56 | - */ |
|
57 | - protected $_installed_messengers = array(); |
|
58 | - |
|
59 | - /** |
|
60 | - * @type EE_message_type[] |
|
61 | - */ |
|
62 | - protected $_installed_message_types = array(); |
|
63 | - |
|
64 | - /** |
|
65 | - * Array of active messengers. |
|
66 | - * Format is this: |
|
67 | - * array( |
|
68 | - * 'messenger_name' => EE_messenger |
|
69 | - * ) |
|
70 | - * |
|
71 | - * @type EE_messenger[] |
|
72 | - */ |
|
73 | - protected $_active_messengers = array(); |
|
74 | - |
|
75 | - /** |
|
76 | - * Formatted array of active message types grouped per messenger. |
|
77 | - * Format is this: |
|
78 | - * array( |
|
79 | - * 'messenger_name' => array( |
|
80 | - * 'settings' => array( |
|
81 | - * '{messenger_name}-message_types' => array( |
|
82 | - * 'message_type_name' => array() //variable array of settings corresponding to message type. |
|
83 | - * ) |
|
84 | - * ) |
|
85 | - * ) |
|
86 | - * ) |
|
87 | - * |
|
88 | - * @type array |
|
89 | - */ |
|
90 | - protected $_active_message_types = array(); |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * This holds the array of messengers and their corresponding message types that have |
|
95 | - * been activated on a site at some point. This is an important record that helps the messages system |
|
96 | - * not accidentally reactivate something that was intentionally deactivated by a user. |
|
97 | - * |
|
98 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
99 | - * |
|
100 | - * @type array |
|
101 | - */ |
|
102 | - protected $_has_activated_messengers_and_message_types = array(); |
|
103 | - |
|
104 | - /** |
|
105 | - * An array of unique message type contexts across all active message types. |
|
106 | - * The array will be indexed by either 'slugs' or 'all'. |
|
107 | - * The slugs index contains an array indexed by unique context slugs with the latest label representation for that |
|
108 | - * slug. array( |
|
109 | - * 'context_slug' => 'localized label for context obtained from latest message type in the loop'. |
|
110 | - * ); |
|
111 | - * The all index returns an array in this format: |
|
112 | - * array( |
|
113 | - * 'message_type_name' => array( |
|
114 | - * 'context_slug' => array( |
|
115 | - * 'label' => 'localized label for context', |
|
116 | - * 'description' => 'localized description for context' |
|
117 | - * ) |
|
118 | - * ) |
|
119 | - * ); |
|
120 | - * |
|
121 | - * @type array |
|
122 | - */ |
|
123 | - protected $_contexts = array(); |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * EE_Message_Resource_Manager constructor. |
|
128 | - * |
|
129 | - * @param \EE_Messenger_Collection_Loader $Messenger_Collection_Loader |
|
130 | - * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader |
|
131 | - * @param \EEM_Message_Template_Group $Message_Template_Group_Model |
|
132 | - */ |
|
133 | - public function __construct( |
|
134 | - EE_Messenger_Collection_Loader $Messenger_Collection_Loader, |
|
135 | - EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader, |
|
136 | - EEM_Message_Template_Group $Message_Template_Group_Model |
|
137 | - ) { |
|
138 | - $this->_messenger_collection_loader = $Messenger_Collection_Loader; |
|
139 | - $this->_message_type_collection_loader = $Message_Type_Collection_Loader; |
|
140 | - $this->_message_template_group_model = $Message_Template_Group_Model; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - protected function _initialize_collections() |
|
148 | - { |
|
149 | - if ($this->_initialized) { |
|
150 | - return; |
|
151 | - } |
|
152 | - $this->_initialized = true; |
|
153 | - $this->_messenger_collection_loader->load_messengers_from_folder(); |
|
154 | - $this->_message_type_collection_loader->load_message_types_from_folder(); |
|
155 | - $this->get_has_activated_messengers_option(true); |
|
156 | - $this->_set_active_messengers_and_message_types(); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @return EE_Messenger_Collection |
|
162 | - */ |
|
163 | - public function messenger_collection() |
|
164 | - { |
|
165 | - $this->_initialize_collections(); |
|
166 | - return $this->_messenger_collection_loader->messenger_collection(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @return EE_messenger[] |
|
172 | - */ |
|
173 | - public function active_messengers() |
|
174 | - { |
|
175 | - $this->_initialize_collections(); |
|
176 | - return $this->_active_messengers; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * @param string $messenger_name |
|
182 | - * @return \EE_messenger |
|
183 | - */ |
|
184 | - public function get_messenger($messenger_name) |
|
185 | - { |
|
186 | - return $this->messenger_collection()->get_by_info($messenger_name); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * This returns the corresponding EE_messenger object for the given string if it is active. |
|
192 | - * |
|
193 | - * @param string $messenger |
|
194 | - * @return EE_messenger | null |
|
195 | - */ |
|
196 | - public function get_active_messenger($messenger) |
|
197 | - { |
|
198 | - $this->_initialize_collections(); |
|
199 | - return ! empty($this->_active_messengers[ $messenger ]) ? $this->_active_messengers[ $messenger ] : null; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return \EE_messenger[] |
|
205 | - */ |
|
206 | - public function installed_messengers() |
|
207 | - { |
|
208 | - if (empty($this->_installed_messengers)) { |
|
209 | - $this->_installed_messengers = array(); |
|
210 | - $this->messenger_collection()->rewind(); |
|
211 | - while ($this->messenger_collection()->valid()) { |
|
212 | - $this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current(); |
|
213 | - $this->messenger_collection()->next(); |
|
214 | - } |
|
215 | - } |
|
216 | - return $this->_installed_messengers; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string $messenger_name |
|
222 | - * @return \EE_messenger |
|
223 | - * @throws \EE_Error |
|
224 | - */ |
|
225 | - public function valid_messenger($messenger_name) |
|
226 | - { |
|
227 | - $messenger = $this->get_messenger($messenger_name); |
|
228 | - if ($messenger instanceof EE_messenger) { |
|
229 | - return $messenger; |
|
230 | - } |
|
231 | - throw new EE_Error( |
|
232 | - sprintf( |
|
233 | - __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'), |
|
234 | - $messenger_name |
|
235 | - ) |
|
236 | - ); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @return EE_Message_Type_Collection |
|
242 | - */ |
|
243 | - public function message_type_collection() |
|
244 | - { |
|
245 | - $this->_initialize_collections(); |
|
246 | - return $this->_message_type_collection_loader->message_type_collection(); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @return array |
|
252 | - */ |
|
253 | - public function active_message_types() |
|
254 | - { |
|
255 | - $this->_initialize_collections(); |
|
256 | - return $this->_active_message_types; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * @param string $message_type_name |
|
262 | - * @return \EE_message_type |
|
263 | - */ |
|
264 | - public function get_message_type($message_type_name) |
|
265 | - { |
|
266 | - return $this->message_type_collection()->get_by_info($message_type_name); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * This returns the EE_message_type from the active message types array ( if present ); |
|
272 | - * |
|
273 | - * @param string $messenger_name |
|
274 | - * @param string $message_type_name |
|
275 | - * @return \EE_message_type|null |
|
276 | - */ |
|
277 | - public function get_active_message_type_for_messenger($messenger_name, $message_type_name) |
|
278 | - { |
|
279 | - return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
280 | - ? $this->get_message_type($message_type_name) |
|
281 | - : null; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * Returns whether the given message type is active for the given messenger. |
|
287 | - * |
|
288 | - * @param string $messenger_name |
|
289 | - * @param string $message_type_name |
|
290 | - * @return bool |
|
291 | - */ |
|
292 | - public function is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
293 | - { |
|
294 | - $this->_initialize_collections(); |
|
295 | - return ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * Returns whether the given messenger is active. |
|
301 | - * |
|
302 | - * @param string $messenger_name the name of the messenger to check if active. |
|
303 | - * @return bool |
|
304 | - */ |
|
305 | - public function is_messenger_active($messenger_name) |
|
306 | - { |
|
307 | - $this->_initialize_collections(); |
|
308 | - return ! empty($this->_active_message_types[ $messenger_name ]); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * This returns any settings that might be on a message type for a messenger |
|
314 | - * |
|
315 | - * @param string $messenger_name The slug of the messenger |
|
316 | - * @param string $message_type_name The slug of the message type getting the settings for. |
|
317 | - * @return array |
|
318 | - */ |
|
319 | - public function get_message_type_settings_for_messenger($messenger_name, $message_type_name) |
|
320 | - { |
|
321 | - $settings = array(); |
|
322 | - if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
323 | - $settings = isset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings']) |
|
324 | - ? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] |
|
325 | - : array(); |
|
326 | - } |
|
327 | - return $settings; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * Returns whether the given messenger name has active message types on it. |
|
333 | - * Infers whether the messenger is active or not as well. |
|
334 | - * |
|
335 | - * @param string $messenger_name |
|
336 | - * @return bool |
|
337 | - */ |
|
338 | - public function messenger_has_active_message_types($messenger_name) |
|
339 | - { |
|
340 | - $this->_initialize_collections(); |
|
341 | - return |
|
342 | - ! empty($this->_active_message_types[ $messenger_name ]) |
|
343 | - && ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ]); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * This checks the _active_message_types property for any active message types |
|
349 | - * that are present for the given messenger and returns them. |
|
350 | - * |
|
351 | - * @since 4.9.0 |
|
352 | - * @param string $messenger_name The messenger being checked |
|
353 | - * @return EE_message_type[]|array (empty array if no active_message_types) |
|
354 | - */ |
|
355 | - public function get_active_message_types_for_messenger($messenger_name) |
|
356 | - { |
|
357 | - $message_types = array(); |
|
358 | - if (! $this->messenger_has_active_message_types($messenger_name)) { |
|
359 | - return $message_types; |
|
360 | - } |
|
361 | - $installed_message_types = $this->installed_message_types(); |
|
362 | - foreach ($installed_message_types as $message_type_name => $message_type) { |
|
363 | - if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
364 | - $message_types[ $message_type_name ] = $message_type; |
|
365 | - } |
|
366 | - } |
|
367 | - return $message_types; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * This does NOT return the _active_message_types property but |
|
373 | - * simply returns an array of active message type names from that property. |
|
374 | - * (The _active_message_types property is indexed by messenger and active message_types per messenger). |
|
375 | - * |
|
376 | - * @return array message_type references (string) |
|
377 | - */ |
|
378 | - public function list_of_active_message_types() |
|
379 | - { |
|
380 | - $active_message_type_names = array(); |
|
381 | - $this->_initialize_collections(); |
|
382 | - foreach ($this->_active_message_types as $messenger => $messenger_settings) { |
|
383 | - if (! isset($messenger_settings['settings'][ $messenger . '-message_types' ])) { |
|
384 | - continue; |
|
385 | - } |
|
386 | - foreach ($messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config) { |
|
387 | - if (! in_array($message_type_name, $active_message_type_names)) { |
|
388 | - $active_message_type_names[] = $message_type_name; |
|
389 | - } |
|
390 | - } |
|
391 | - } |
|
392 | - return $active_message_type_names; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * Same as list_of_active_message_types() except this returns actual EE_message_type objects |
|
398 | - * |
|
399 | - * @since 4.9.0 |
|
400 | - * @return \EE_message_type[] |
|
401 | - */ |
|
402 | - public function get_active_message_type_objects() |
|
403 | - { |
|
404 | - $active_message_types = array(); |
|
405 | - $installed_message_types = $this->installed_message_types(); |
|
406 | - $active_message_type_names = $this->list_of_active_message_types(); |
|
407 | - foreach ($active_message_type_names as $active_message_type_name) { |
|
408 | - if (isset($installed_message_types[ $active_message_type_name ])) { |
|
409 | - $active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ]; |
|
410 | - } |
|
411 | - } |
|
412 | - return $active_message_types; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * @return \EE_message_type[] |
|
418 | - */ |
|
419 | - public function installed_message_types() |
|
420 | - { |
|
421 | - if (empty($this->_installed_message_types)) { |
|
422 | - $this->message_type_collection()->rewind(); |
|
423 | - while ($this->message_type_collection()->valid()) { |
|
424 | - $this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current(); |
|
425 | - $this->message_type_collection()->next(); |
|
426 | - } |
|
427 | - } |
|
428 | - return $this->_installed_message_types; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * @param string $message_type_name |
|
434 | - * @return \EE_message_type |
|
435 | - * @throws \EE_Error |
|
436 | - */ |
|
437 | - public function valid_message_type($message_type_name) |
|
438 | - { |
|
439 | - $message_type = $this->get_message_type($message_type_name); |
|
440 | - if ($message_type instanceof EE_message_type) { |
|
441 | - return $message_type; |
|
442 | - } |
|
443 | - throw new EE_Error( |
|
444 | - sprintf( |
|
445 | - __('The "%1$s" message type is either invalid or not installed', 'event_espresso'), |
|
446 | - $message_type_name |
|
447 | - ) |
|
448 | - ); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * valid_message_type_for_messenger |
|
454 | - * |
|
455 | - * @param EE_messenger $messenger |
|
456 | - * @param string $message_type_name |
|
457 | - * @return boolean |
|
458 | - * @throws \EE_Error |
|
459 | - */ |
|
460 | - public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name) |
|
461 | - { |
|
462 | - $valid_message_types = $messenger->get_valid_message_types(); |
|
463 | - if (! in_array($message_type_name, $valid_message_types)) { |
|
464 | - throw new EE_Error( |
|
465 | - sprintf( |
|
466 | - __( |
|
467 | - 'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger. Double-check the spelling and verify that message type has been registered as a valid type with the messenger.', |
|
468 | - 'event_espresso' |
|
469 | - ), |
|
470 | - $message_type_name, |
|
471 | - __METHOD__, |
|
472 | - $messenger->name |
|
473 | - ) |
|
474 | - ); |
|
475 | - } |
|
476 | - return true; |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * Used to return active messengers array stored in the wp options table. |
|
482 | - * If no value is present in the option then an empty array is returned. |
|
483 | - * |
|
484 | - * @param bool $reset If true then we ignore whether the option is cached on the _active_message_types |
|
485 | - * property and pull directly from the db. Otherwise whatever is currently on the |
|
486 | - * $_active_message_types property is pulled. |
|
487 | - * @return array |
|
488 | - */ |
|
489 | - public function get_active_messengers_option($reset = false) |
|
490 | - { |
|
491 | - if ($reset) { |
|
492 | - $this->_active_message_types = get_option('ee_active_messengers', array()); |
|
493 | - } |
|
494 | - return $this->_active_message_types; |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * Used to update the active messengers array stored in the wp options table. |
|
500 | - * |
|
501 | - * @param array $active_messenger_settings Incoming data to save. If empty, then the internal cached property |
|
502 | - * representing this data is used. |
|
503 | - * @return bool FALSE if not updated, TRUE if updated. |
|
504 | - */ |
|
505 | - public function update_active_messengers_option($active_messenger_settings = array()) |
|
506 | - { |
|
507 | - $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings; |
|
508 | - // make sure _active_message_types is updated (this is the internal cache for the settings). |
|
509 | - $this->_active_message_types = $active_messenger_settings; |
|
510 | - return update_option('ee_active_messengers', $active_messenger_settings); |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Used to return has activated message types for messengers array stored in the wp options table. |
|
516 | - * If no value is present in the option then an empty array is returned. |
|
517 | - * The value is cached on the $_has_activated_messengers_and_message_types property for future calls. |
|
518 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
519 | - * |
|
520 | - * @param bool $reset Used to indicate that any cached value should be ignored. |
|
521 | - * @return array |
|
522 | - */ |
|
523 | - public function get_has_activated_messengers_option($reset = false) |
|
524 | - { |
|
525 | - if ($reset || empty($this->_has_activated_messengers_and_message_types)) { |
|
526 | - $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array()); |
|
527 | - } |
|
528 | - return $this->_has_activated_messengers_and_message_types; |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * Used to update the has activated option in the db. |
|
534 | - * |
|
535 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
536 | - * |
|
537 | - * @param array $has_activated_messengers Incoming data to save. If empty, then the internal cached property |
|
538 | - * representing this data is used. |
|
539 | - * @return bool FALSE if not updated, TRUE if updated. |
|
540 | - */ |
|
541 | - public function update_has_activated_messengers_option($has_activated_messengers = array()) |
|
542 | - { |
|
543 | - // make sure the option has been retrieved from first so we don't overwrite it accidentally. |
|
544 | - if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) { |
|
545 | - $this->get_has_activated_messengers_option(); |
|
546 | - } |
|
547 | - $has_activated_messengers = empty($has_activated_messengers) |
|
548 | - ? $this->_has_activated_messengers_and_message_types |
|
549 | - : $has_activated_messengers; |
|
550 | - return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers); |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * wrapper for _set_active_messengers_and_message_types() |
|
556 | - */ |
|
557 | - public function reset_active_messengers_and_message_types() |
|
558 | - { |
|
559 | - $this->_set_active_messengers_and_message_types(); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Generate list of active messengers and message types from collection. |
|
565 | - * This sets up the active messengers from what is present in the database. |
|
566 | - */ |
|
567 | - protected function _set_active_messengers_and_message_types() |
|
568 | - { |
|
569 | - // echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n"; |
|
570 | - // list of activated messengers as set via the admin |
|
571 | - // note calling `get_active_messengers_options` also initializes the _active_message_types property. |
|
572 | - $this->get_active_messengers_option(true); |
|
573 | - $this->ensure_messengers_are_active(array(), false, true); |
|
574 | - $this->update_active_messengers_option(); |
|
575 | - $this->update_has_activated_messengers_option(); |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * Ensures that the specified messenger is currently active. |
|
581 | - * If not, activates it and its default message types. |
|
582 | - * |
|
583 | - * @param string $messenger_name |
|
584 | - * @param bool $update_option Whether to update the option in the db or not. |
|
585 | - * @return boolean true if either already active or successfully activated. |
|
586 | - */ |
|
587 | - public function ensure_messenger_is_active($messenger_name, $update_option = true) |
|
588 | - { |
|
589 | - if (! isset($this->_active_messengers[ $messenger_name ])) { |
|
590 | - try { |
|
591 | - $this->activate_messenger($messenger_name, array(), $update_option); |
|
592 | - } catch (EE_Error $e) { |
|
593 | - EE_Error::add_error( |
|
594 | - $e->getMessage(), |
|
595 | - __FILE__, |
|
596 | - __FUNCTION__, |
|
597 | - __LINE__ |
|
598 | - ); |
|
599 | - return false; |
|
600 | - } |
|
601 | - } |
|
602 | - return true; |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * This ensures the given array of messenger names is active in the system. |
|
608 | - * Note, this method will not activate any NEW message types for the messenger when it is called. Instead, |
|
609 | - * it will automatically activate the default message types for the messenger if its not active. |
|
610 | - * |
|
611 | - * @param array $messenger_names Array of messenger names for messengers to be activated. If an empty array |
|
612 | - * (default) then will attempt to set the active messengers from the |
|
613 | - * activated_messengers option |
|
614 | - * (stored in $_active_message_types property). |
|
615 | - * @param bool $update_option Whether to update the related active messengers option. |
|
616 | - * @param bool $verify Whether to verify the messengers are installed before activating. Note if this is |
|
617 | - * set to true and a messenger is indicated as active, but is NOT installed, then it |
|
618 | - * will automatically be deactivated. |
|
619 | - */ |
|
620 | - public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false) |
|
621 | - { |
|
622 | - $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names; |
|
623 | - |
|
624 | - $not_installed = array(); |
|
625 | - foreach ($messenger_names as $messenger_name) { |
|
626 | - if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) { |
|
627 | - $not_installed[] = $messenger_name; |
|
628 | - $this->deactivate_messenger($messenger_name); |
|
629 | - continue; |
|
630 | - } |
|
631 | - $this->ensure_messenger_is_active($messenger_name, $update_option); |
|
632 | - } |
|
633 | - |
|
634 | - if (! empty($not_installed)) { |
|
635 | - EE_Error::add_error( |
|
636 | - sprintf( |
|
637 | - __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'), |
|
638 | - '<br />', |
|
639 | - implode(', ', $not_installed) |
|
640 | - ), |
|
641 | - __FILE__, |
|
642 | - __FUNCTION__, |
|
643 | - __LINE__ |
|
644 | - ); |
|
645 | - } |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * Ensures that the specified message type for the given messenger is currently active, if not activates it. |
|
651 | - * This ALSO ensures that the given messenger is active as well! |
|
652 | - * |
|
653 | - * @param string $message_type_name message type name. |
|
654 | - * @param $messenger_name |
|
655 | - * @param bool $update_option Whether to update the option in the db or not. |
|
656 | - * @return bool Returns true if already is active or if was activated successfully. |
|
657 | - * @throws \EE_Error |
|
658 | - */ |
|
659 | - public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true) |
|
660 | - { |
|
661 | - // grab the messenger to work with. |
|
662 | - $messenger = $this->valid_messenger($messenger_name); |
|
663 | - if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) { |
|
664 | - // ensure messenger is active (that's an inherent coupling between active message types and the |
|
665 | - // messenger they are being activated for. |
|
666 | - try { |
|
667 | - if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
668 | - // all is good so let's just get it active |
|
669 | - $this->activate_messenger($messenger_name, array($message_type_name), $update_option); |
|
670 | - } |
|
671 | - } catch (EE_Error $e) { |
|
672 | - EE_Error::add_error( |
|
673 | - $e->getMessage(), |
|
674 | - __FILE__, |
|
675 | - __FUNCTION__, |
|
676 | - __LINE__ |
|
677 | - ); |
|
678 | - return false; |
|
679 | - } |
|
680 | - } |
|
681 | - return true; |
|
682 | - } |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a |
|
687 | - * messenger are active in one go. |
|
688 | - * |
|
689 | - * @param array $message_type_names Array of message type names to ensure are active. |
|
690 | - * @param string $messenger_name The name of the messenger that the message types are to be activated on. |
|
691 | - * @param bool $update_option Whether to persist the activation to the database or not (default true). |
|
692 | - */ |
|
693 | - public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true) |
|
694 | - { |
|
695 | - $message_type_names = (array) $message_type_names; |
|
696 | - foreach ($message_type_names as $message_type_name) { |
|
697 | - // note, intentionally not updating option here because we're in a loop. |
|
698 | - // We'll follow the instructions of the incoming $update_option argument after the loop. |
|
699 | - $this->ensure_message_type_is_active($message_type_name, $messenger_name, false); |
|
700 | - } |
|
701 | - if ($update_option) { |
|
702 | - $this->update_active_messengers_option(); |
|
703 | - $this->update_has_activated_messengers_option(); |
|
704 | - } |
|
705 | - } |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * Activates the specified messenger. |
|
710 | - * |
|
711 | - * @param string $messenger_name |
|
712 | - * @param array $message_type_names An array of message type names to activate with this messenger. |
|
713 | - * If included we do NOT setup the default message types |
|
714 | - * (assuming they are already setup.) |
|
715 | - * @param bool $update_active_messengers_option |
|
716 | - * @return array of generated templates |
|
717 | - * @throws \EE_Error |
|
718 | - */ |
|
719 | - public function activate_messenger( |
|
720 | - $messenger_name, |
|
721 | - $message_type_names = array(), |
|
722 | - $update_active_messengers_option = true |
|
723 | - ) { |
|
724 | - $templates = array(); |
|
725 | - // grab the messenger to work with. |
|
726 | - $messenger = $this->messenger_collection()->get_by_info($messenger_name); |
|
727 | - // it's inactive. Activate it. |
|
728 | - if ($messenger instanceof EE_messenger) { |
|
729 | - $this->_active_messengers[ $messenger->name ] = $messenger; |
|
730 | - // activate incoming message types set to be activated with messenger. |
|
731 | - $message_type_names = $this->_activate_message_types($messenger, $message_type_names); |
|
732 | - // setup any initial settings for the messenger if necessary. |
|
733 | - $this->add_settings_for_messenger($messenger->name); |
|
734 | - if ($update_active_messengers_option) { |
|
735 | - $this->update_active_messengers_option(); |
|
736 | - $this->update_has_activated_messengers_option(); |
|
737 | - } |
|
738 | - // generate new templates if necessary and ensure all related templates that are already in the database are |
|
739 | - // marked active. Note, this will also deactivate a message type for a messenger if the template |
|
740 | - // cannot be successfully created during its attempt (only happens for global template attempts). |
|
741 | - if (! empty($message_type_names)) { |
|
742 | - $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true); |
|
743 | - EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names); |
|
744 | - } |
|
745 | - } |
|
746 | - return $templates; |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * Activates given message types for the given EE_messenger object. |
|
752 | - * Note: (very important) This method does not persist the activation to the database. |
|
753 | - * See code implementing this method in this class for examples of how to persist. |
|
754 | - * |
|
755 | - * @param \EE_messenger $messenger |
|
756 | - * @param array $message_type_names |
|
757 | - * @return array |
|
758 | - */ |
|
759 | - protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array()) |
|
760 | - { |
|
761 | - // If $message_type_names is empty, AND $this->_active_message_types is empty, then that means |
|
762 | - // things have never been initialized (which should happen on EEH_Activation::generate_message_templates). |
|
763 | - // So ONLY then do we need to actually grab defaults and cycle through them. Otherwise we |
|
764 | - // only override _active_message_types when an explicit array of $message_type_names has been provided. |
|
765 | - $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[ $messenger->name ]) |
|
766 | - ? $messenger->get_default_message_types() |
|
767 | - : (array) $message_type_names; |
|
768 | - |
|
769 | - // now we ALWAYS need to make sure that the messenger is active for the message types we're activating! |
|
770 | - if (! isset($this->_active_message_types[ $messenger->name ])) { |
|
771 | - $this->_active_message_types[ $messenger->name ]['settings'] = array(); |
|
772 | - } |
|
773 | - |
|
774 | - if ($message_type_names) { |
|
775 | - // cycle thru message types |
|
776 | - foreach ($message_type_names as $message_type_name) { |
|
777 | - // only register the message type as active IF it isn't already active |
|
778 | - // and if its actually installed. |
|
779 | - if (! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name) |
|
780 | - ) { |
|
781 | - $this->add_settings_for_message_type($messenger->name, $message_type_name); |
|
782 | - $this->_set_messenger_has_activated_message_type( |
|
783 | - $messenger, |
|
784 | - $message_type_name |
|
785 | - ); |
|
786 | - } |
|
787 | - } |
|
788 | - } |
|
789 | - return $message_type_names; |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * add_settings_for_message_type |
|
795 | - * NOTE This does NOT automatically persist any settings to the db. Client code should call |
|
796 | - * $this->update_active_messengers_option to persist. |
|
797 | - * |
|
798 | - * @param string $messenger_name The name of the messenger adding the settings for |
|
799 | - * @param string $message_type_name The name of the message type adding the settings for |
|
800 | - * @param array $new_settings Any new settings being set for the message type and messenger |
|
801 | - */ |
|
802 | - public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array()) |
|
803 | - { |
|
804 | - // get installed message type from collection |
|
805 | - $message_type = $this->message_type_collection()->get_by_info($message_type_name); |
|
806 | - $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name); |
|
807 | - // we need to setup any initial settings for message types |
|
808 | - if ($message_type instanceof EE_message_type) { |
|
809 | - $default_settings = $message_type->get_admin_settings_fields(); |
|
810 | - foreach ($default_settings as $field => $values) { |
|
811 | - if (isset($new_settings[ $field ])) { |
|
812 | - $existing_settings[ $field ] = $new_settings[ $field ]; |
|
813 | - continue; |
|
814 | - } |
|
815 | - if (! isset($existing_settings[ $field ])) { |
|
816 | - $existing_settings[ $field ] = $values['default']; |
|
817 | - } |
|
818 | - } |
|
819 | - } |
|
820 | - $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings; |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger |
|
826 | - * and message type. |
|
827 | - * |
|
828 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
829 | - * |
|
830 | - * @access protected |
|
831 | - * @param \EE_messenger $messenger |
|
832 | - * @param string $message_type_name |
|
833 | - */ |
|
834 | - protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name) |
|
835 | - { |
|
836 | - |
|
837 | - // if _has_activated_messengers_and_message_types is empty then lets ensure its initialized |
|
838 | - if (empty($this->_has_activated_messengers_and_message_types)) { |
|
839 | - $this->get_has_activated_messengers_option(); |
|
840 | - } |
|
841 | - |
|
842 | - // make sure this messenger has a record in the has_activated array |
|
843 | - if (! isset($this->_has_activated_messengers_and_message_types[ $messenger->name ])) { |
|
844 | - $this->_has_activated_messengers_and_message_types[ $messenger->name ] = array(); |
|
845 | - } |
|
846 | - // check if message type has already been added |
|
847 | - if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ])) { |
|
848 | - $this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name; |
|
849 | - } |
|
850 | - } |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * add_settings_for_messenger |
|
855 | - * NOTE This does NOT automatically persist any settings to the db. Client code should call |
|
856 | - * $this->update_active_messengers_option to persist. |
|
857 | - * |
|
858 | - * @param string $messenger_name The name of the messenger the settings is being added for. |
|
859 | - * @param array $new_settings An array of settings to update the existing settings. |
|
860 | - */ |
|
861 | - public function add_settings_for_messenger($messenger_name, $new_settings = array()) |
|
862 | - { |
|
863 | - $messenger = $this->get_messenger($messenger_name); |
|
864 | - if ($messenger instanceof EE_messenger) { |
|
865 | - $msgr_settings = $messenger->get_admin_settings_fields(); |
|
866 | - if (! empty($msgr_settings)) { |
|
867 | - foreach ($msgr_settings as $field => $value) { |
|
868 | - // is there a new setting for this? |
|
869 | - if (isset($new_settings[ $field ])) { |
|
870 | - $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ]; |
|
871 | - continue; |
|
872 | - } |
|
873 | - // only set the default if it isn't already set. |
|
874 | - if (! isset($this->_active_message_types[ $messenger->name ]['settings'][ $field ])) { |
|
875 | - $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value; |
|
876 | - } |
|
877 | - } |
|
878 | - } |
|
879 | - } |
|
880 | - } |
|
881 | - |
|
882 | - |
|
883 | - /** |
|
884 | - * deactivate_messenger |
|
885 | - * |
|
886 | - * @param string|EE_messenger $messenger_name name of messenger |
|
887 | - * @return void |
|
888 | - */ |
|
889 | - public function deactivate_messenger($messenger_name) |
|
890 | - { |
|
891 | - $this->_initialize_collections(); |
|
892 | - if ($messenger_name instanceof EE_messenger) { |
|
893 | - $messenger_name = $messenger_name->name; |
|
894 | - } |
|
895 | - unset($this->_active_messengers[ $messenger_name ]); |
|
896 | - unset($this->_active_message_types[ $messenger_name ]); |
|
897 | - $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name); |
|
898 | - $this->update_active_messengers_option(); |
|
899 | - } |
|
900 | - |
|
901 | - |
|
902 | - /** |
|
903 | - * Deactivates a message type (note this will deactivate across all messenger's it is active on. |
|
904 | - * |
|
905 | - * @param string $message_type_name name of message type being deactivated |
|
906 | - * @param bool $set_has_active_record By default we always record the has_active record when deactivating a message |
|
907 | - * type. However, this can be overridden if we don't want this set (usually when |
|
908 | - * this is called as a part of deregistration of a custom message type) |
|
909 | - */ |
|
910 | - public function deactivate_message_type($message_type_name, $set_has_active_record = true) |
|
911 | - { |
|
912 | - $this->_initialize_collections(); |
|
913 | - if ($message_type_name instanceof EE_message_type) { |
|
914 | - $message_type_name = $message_type_name->name; |
|
915 | - } |
|
916 | - foreach ($this->_active_message_types as $messenger_name => $settings) { |
|
917 | - unset( |
|
918 | - $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ] |
|
919 | - ); |
|
920 | - |
|
921 | - // we always record (even on deactivation) that a message type has been activated because there should at |
|
922 | - // least be a record in the "has_activated" option that it WAS active at one point. |
|
923 | - if ($set_has_active_record) { |
|
924 | - $messenger = $this->get_messenger($messenger_name); |
|
925 | - $this->_set_messenger_has_activated_message_type($messenger, $message_type_name); |
|
926 | - } |
|
927 | - } |
|
928 | - $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name); |
|
929 | - $this->update_active_messengers_option(); |
|
930 | - $this->update_has_activated_messengers_option(); |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * Deactivates a message type for a specific messenger as opposed to all messengers. |
|
936 | - * |
|
937 | - * @param string $message_type_name Name of message type being deactivated. |
|
938 | - * @param string $messenger_name Name of messenger the message type is being deactivated for. |
|
939 | - */ |
|
940 | - public function deactivate_message_type_for_messenger($message_type_name, $messenger_name) |
|
941 | - { |
|
942 | - $this->_initialize_collections(); |
|
943 | - if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
944 | - unset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]); |
|
945 | - } |
|
946 | - $this->_message_template_group_model->deactivate_message_template_groups_for( |
|
947 | - array($messenger_name), |
|
948 | - array($message_type_name) |
|
949 | - ); |
|
950 | - $this->update_active_messengers_option(); |
|
951 | - } |
|
952 | - |
|
953 | - |
|
954 | - /** |
|
955 | - * Used to verify if a message can be sent for the given messenger and message type |
|
956 | - * and that it is a generating messenger (used for generating message templates). |
|
957 | - * |
|
958 | - * @param EE_messenger $messenger messenger used in trigger |
|
959 | - * @param EE_message_type $message_type message type used in trigger |
|
960 | - * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
|
961 | - */ |
|
962 | - public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) |
|
963 | - { |
|
964 | - // get the $messengers the message type says it can be used with. |
|
965 | - foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) { |
|
966 | - if ($messenger->name === $generating_messenger |
|
967 | - && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name) |
|
968 | - ) { |
|
969 | - return true; |
|
970 | - } |
|
971 | - } |
|
972 | - return false; |
|
973 | - } |
|
974 | - |
|
975 | - |
|
976 | - /** |
|
977 | - * This returns all the contexts that are registered by all message types. |
|
978 | - * If $slugs_only is true, |
|
979 | - * then just an array indexed by unique context slugs with the latest label representation for that slug. |
|
980 | - * array( |
|
981 | - * 'context_slug' => 'localized label for context obtained from latest message type in the loop'. |
|
982 | - * ); |
|
983 | - * If $slugs_only is false, then the format is: |
|
984 | - * array( |
|
985 | - * 'message_type_name' => array( |
|
986 | - * 'context_slug' => array( |
|
987 | - * 'label' => 'localized label for context', |
|
988 | - * 'description' => 'localized description for context' |
|
989 | - * ) |
|
990 | - * ) |
|
991 | - * ); |
|
992 | - * Keep in mind that although different message types may share the same context slugs, |
|
993 | - * it is possible that the context is described differently by the message type. |
|
994 | - * |
|
995 | - * @since 4.9.0 |
|
996 | - * @param bool $slugs_only Whether to return an array of just slugs and labels (true) |
|
997 | - * or all contexts indexed by message type. |
|
998 | - * @return array |
|
999 | - */ |
|
1000 | - public function get_all_contexts($slugs_only = true) |
|
1001 | - { |
|
1002 | - $key = $slugs_only ? 'slugs' : 'all'; |
|
1003 | - // check if contexts has been setup yet. |
|
1004 | - if (empty($this->_contexts[ $key ])) { |
|
1005 | - // So let's get all active message type objects and loop through to get all unique contexts |
|
1006 | - foreach ($this->get_active_message_type_objects() as $message_type) { |
|
1007 | - if ($message_type instanceof EE_message_type) { |
|
1008 | - $message_type_contexts = $message_type->get_contexts(); |
|
1009 | - if ($slugs_only) { |
|
1010 | - foreach ($message_type_contexts as $context => $context_details) { |
|
1011 | - $this->_contexts[ $key ][ $context ] = $context_details['label']; |
|
1012 | - } |
|
1013 | - } else { |
|
1014 | - $this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts; |
|
1015 | - } |
|
1016 | - } |
|
1017 | - } |
|
1018 | - } |
|
1019 | - return ! empty($this->_contexts[ $key ]) ? $this->_contexts[ $key ] : array(); |
|
1020 | - } |
|
1021 | - |
|
1022 | - |
|
1023 | - /** |
|
1024 | - * This checks the internal record of what message types are considered "active" and verifies that |
|
1025 | - * there is an installed class definition for that message type. If the active message type does not have a |
|
1026 | - * corresponding accessible message type class then it will be deactivated from all messengers it is active on and |
|
1027 | - * any related message templates will be inactivated as well. |
|
1028 | - * |
|
1029 | - * @return bool true means all active message types are valid, false means at least one message type was |
|
1030 | - * deactivated. |
|
1031 | - */ |
|
1032 | - public function validate_active_message_types_are_installed() |
|
1033 | - { |
|
1034 | - $list_of_active_message_type_names = $this->list_of_active_message_types(); |
|
1035 | - $installed_message_types = $this->installed_message_types(); |
|
1036 | - $all_message_types_valid = true; |
|
1037 | - // loop through list of active message types and verify they are installed. |
|
1038 | - foreach ($list_of_active_message_type_names as $message_type_name) { |
|
1039 | - if (! isset($installed_message_types[ $message_type_name ])) { |
|
1040 | - $this->remove_message_type_has_been_activated_from_all_messengers( |
|
1041 | - $message_type_name, |
|
1042 | - true |
|
1043 | - ); |
|
1044 | - $this->deactivate_message_type($message_type_name, false); |
|
1045 | - $all_message_types_valid = false; |
|
1046 | - } |
|
1047 | - } |
|
1048 | - return $all_message_types_valid; |
|
1049 | - } |
|
1050 | - |
|
1051 | - |
|
1052 | - /** |
|
1053 | - * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been |
|
1054 | - * activated for the given messenger. This can be called by client code on plugin updates etc to determine whether |
|
1055 | - * to attempt automatically reactivating message types that should be activated by default or not. |
|
1056 | - * |
|
1057 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1058 | - * |
|
1059 | - * @param $message_type_name |
|
1060 | - * @param $messenger_name |
|
1061 | - * @return bool |
|
1062 | - */ |
|
1063 | - public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name) |
|
1064 | - { |
|
1065 | - $has_activated = $this->get_has_activated_messengers_option(); |
|
1066 | - return isset($has_activated[ $messenger_name ]) |
|
1067 | - && in_array($message_type_name, $has_activated[ $messenger_name ]); |
|
1068 | - } |
|
1069 | - |
|
1070 | - |
|
1071 | - /** |
|
1072 | - * This method unsets a message type from the given messenger has activated option. |
|
1073 | - * |
|
1074 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1075 | - * |
|
1076 | - * @param string $message_type_name |
|
1077 | - * @param string $messenger_name |
|
1078 | - * @param bool $consider_current_state Whether to consider whether the message type is currently active or not. |
|
1079 | - * If it is currently active, then remove. Otherwise leave it alone. |
|
1080 | - */ |
|
1081 | - public function remove_message_type_has_been_activated_for_messenger( |
|
1082 | - $message_type_name, |
|
1083 | - $messenger_name, |
|
1084 | - $consider_current_state = false |
|
1085 | - ) { |
|
1086 | - if ($consider_current_state |
|
1087 | - && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
1088 | - ) { |
|
1089 | - // when consider current state is true, this means we don't want to change anything on the "has_activated" |
|
1090 | - // record if the message type is currently active for this messenger. This is used when we want to retain |
|
1091 | - // the record for user initiated inactivations of the message type. |
|
1092 | - return; |
|
1093 | - } |
|
1094 | - $has_activated = $this->get_has_activated_messengers_option(); |
|
1095 | - $key_for_message_type = isset($has_activated[ $messenger_name ]) |
|
1096 | - ? array_search($message_type_name, $has_activated[ $messenger_name ], true) |
|
1097 | - : false; |
|
1098 | - if ($key_for_message_type !== false) { |
|
1099 | - unset($has_activated[ $messenger_name ][ $key_for_message_type ]); |
|
1100 | - $this->update_has_activated_messengers_option($has_activated); |
|
1101 | - // reset the internal cached property |
|
1102 | - $this->get_has_activated_messengers_option(true); |
|
1103 | - } |
|
1104 | - } |
|
1105 | - |
|
1106 | - |
|
1107 | - /** |
|
1108 | - * Removes a message type active record from all messengers it is attached to. |
|
1109 | - * |
|
1110 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1111 | - * |
|
1112 | - * @param $message_type_name |
|
1113 | - * @param bool $consider_current_state Whether to consider whether the message type is currently active or not. |
|
1114 | - * If it is currently active, then remove. Otherwise leave it alone. |
|
1115 | - */ |
|
1116 | - public function remove_message_type_has_been_activated_from_all_messengers( |
|
1117 | - $message_type_name, |
|
1118 | - $consider_current_state = false |
|
1119 | - ) { |
|
1120 | - foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) { |
|
1121 | - $this->remove_message_type_has_been_activated_for_messenger( |
|
1122 | - $message_type_name, |
|
1123 | - $messenger_name, |
|
1124 | - $consider_current_state |
|
1125 | - ); |
|
1126 | - } |
|
1127 | - } |
|
15 | + /** |
|
16 | + * This option in the database is used to keep a record of message types that have been activated for a messenger |
|
17 | + * at some point in the history of the site. It is utilized by the implementation of the 'force' flag in |
|
18 | + * EE_Register_Message_Type. The force flag is an indication of whether a message type should be activated by |
|
19 | + * default when the message type is registered. However, if a user has explicitly deactivated a message type, then |
|
20 | + * the force flag is ignored. The method by which the code knows whether to ignore this flag is via this option. |
|
21 | + * Note, that this is NOT a historical record. Its entirely possible for a message type to have been activated for |
|
22 | + * a messenger and yet not have a record in this option. This occurs when a message type is inactivated through an |
|
23 | + * automated process (when an add-on registering the message type deactivates, or when some other code calls the |
|
24 | + * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure |
|
25 | + * the "force" flag is respected if that message type is later re-registered. |
|
26 | + * |
|
27 | + * This option should NOT be used to determine the current "active" state of a message type for a given messenger. |
|
28 | + * |
|
29 | + * The name of this option (and related methods/properties) is due to matching the original intended purpose for the |
|
30 | + * option that got superseded by later behaviour requirements. |
|
31 | + */ |
|
32 | + const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger'; |
|
33 | + |
|
34 | + /** |
|
35 | + * @type boolean $_initialized |
|
36 | + */ |
|
37 | + protected $_initialized = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * @type EE_Messenger_Collection $_messenger_collection_loader |
|
41 | + */ |
|
42 | + protected $_messenger_collection_loader; |
|
43 | + |
|
44 | + /** |
|
45 | + * @type EE_Message_Type_Collection $_message_type_collection_loader |
|
46 | + */ |
|
47 | + protected $_message_type_collection_loader; |
|
48 | + |
|
49 | + /** |
|
50 | + * @type EEM_Message_Template_Group $_message_template_group_model |
|
51 | + */ |
|
52 | + protected $_message_template_group_model; |
|
53 | + |
|
54 | + /** |
|
55 | + * @type EE_messenger[] |
|
56 | + */ |
|
57 | + protected $_installed_messengers = array(); |
|
58 | + |
|
59 | + /** |
|
60 | + * @type EE_message_type[] |
|
61 | + */ |
|
62 | + protected $_installed_message_types = array(); |
|
63 | + |
|
64 | + /** |
|
65 | + * Array of active messengers. |
|
66 | + * Format is this: |
|
67 | + * array( |
|
68 | + * 'messenger_name' => EE_messenger |
|
69 | + * ) |
|
70 | + * |
|
71 | + * @type EE_messenger[] |
|
72 | + */ |
|
73 | + protected $_active_messengers = array(); |
|
74 | + |
|
75 | + /** |
|
76 | + * Formatted array of active message types grouped per messenger. |
|
77 | + * Format is this: |
|
78 | + * array( |
|
79 | + * 'messenger_name' => array( |
|
80 | + * 'settings' => array( |
|
81 | + * '{messenger_name}-message_types' => array( |
|
82 | + * 'message_type_name' => array() //variable array of settings corresponding to message type. |
|
83 | + * ) |
|
84 | + * ) |
|
85 | + * ) |
|
86 | + * ) |
|
87 | + * |
|
88 | + * @type array |
|
89 | + */ |
|
90 | + protected $_active_message_types = array(); |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * This holds the array of messengers and their corresponding message types that have |
|
95 | + * been activated on a site at some point. This is an important record that helps the messages system |
|
96 | + * not accidentally reactivate something that was intentionally deactivated by a user. |
|
97 | + * |
|
98 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
99 | + * |
|
100 | + * @type array |
|
101 | + */ |
|
102 | + protected $_has_activated_messengers_and_message_types = array(); |
|
103 | + |
|
104 | + /** |
|
105 | + * An array of unique message type contexts across all active message types. |
|
106 | + * The array will be indexed by either 'slugs' or 'all'. |
|
107 | + * The slugs index contains an array indexed by unique context slugs with the latest label representation for that |
|
108 | + * slug. array( |
|
109 | + * 'context_slug' => 'localized label for context obtained from latest message type in the loop'. |
|
110 | + * ); |
|
111 | + * The all index returns an array in this format: |
|
112 | + * array( |
|
113 | + * 'message_type_name' => array( |
|
114 | + * 'context_slug' => array( |
|
115 | + * 'label' => 'localized label for context', |
|
116 | + * 'description' => 'localized description for context' |
|
117 | + * ) |
|
118 | + * ) |
|
119 | + * ); |
|
120 | + * |
|
121 | + * @type array |
|
122 | + */ |
|
123 | + protected $_contexts = array(); |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * EE_Message_Resource_Manager constructor. |
|
128 | + * |
|
129 | + * @param \EE_Messenger_Collection_Loader $Messenger_Collection_Loader |
|
130 | + * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader |
|
131 | + * @param \EEM_Message_Template_Group $Message_Template_Group_Model |
|
132 | + */ |
|
133 | + public function __construct( |
|
134 | + EE_Messenger_Collection_Loader $Messenger_Collection_Loader, |
|
135 | + EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader, |
|
136 | + EEM_Message_Template_Group $Message_Template_Group_Model |
|
137 | + ) { |
|
138 | + $this->_messenger_collection_loader = $Messenger_Collection_Loader; |
|
139 | + $this->_message_type_collection_loader = $Message_Type_Collection_Loader; |
|
140 | + $this->_message_template_group_model = $Message_Template_Group_Model; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + protected function _initialize_collections() |
|
148 | + { |
|
149 | + if ($this->_initialized) { |
|
150 | + return; |
|
151 | + } |
|
152 | + $this->_initialized = true; |
|
153 | + $this->_messenger_collection_loader->load_messengers_from_folder(); |
|
154 | + $this->_message_type_collection_loader->load_message_types_from_folder(); |
|
155 | + $this->get_has_activated_messengers_option(true); |
|
156 | + $this->_set_active_messengers_and_message_types(); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @return EE_Messenger_Collection |
|
162 | + */ |
|
163 | + public function messenger_collection() |
|
164 | + { |
|
165 | + $this->_initialize_collections(); |
|
166 | + return $this->_messenger_collection_loader->messenger_collection(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @return EE_messenger[] |
|
172 | + */ |
|
173 | + public function active_messengers() |
|
174 | + { |
|
175 | + $this->_initialize_collections(); |
|
176 | + return $this->_active_messengers; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * @param string $messenger_name |
|
182 | + * @return \EE_messenger |
|
183 | + */ |
|
184 | + public function get_messenger($messenger_name) |
|
185 | + { |
|
186 | + return $this->messenger_collection()->get_by_info($messenger_name); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * This returns the corresponding EE_messenger object for the given string if it is active. |
|
192 | + * |
|
193 | + * @param string $messenger |
|
194 | + * @return EE_messenger | null |
|
195 | + */ |
|
196 | + public function get_active_messenger($messenger) |
|
197 | + { |
|
198 | + $this->_initialize_collections(); |
|
199 | + return ! empty($this->_active_messengers[ $messenger ]) ? $this->_active_messengers[ $messenger ] : null; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return \EE_messenger[] |
|
205 | + */ |
|
206 | + public function installed_messengers() |
|
207 | + { |
|
208 | + if (empty($this->_installed_messengers)) { |
|
209 | + $this->_installed_messengers = array(); |
|
210 | + $this->messenger_collection()->rewind(); |
|
211 | + while ($this->messenger_collection()->valid()) { |
|
212 | + $this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current(); |
|
213 | + $this->messenger_collection()->next(); |
|
214 | + } |
|
215 | + } |
|
216 | + return $this->_installed_messengers; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $messenger_name |
|
222 | + * @return \EE_messenger |
|
223 | + * @throws \EE_Error |
|
224 | + */ |
|
225 | + public function valid_messenger($messenger_name) |
|
226 | + { |
|
227 | + $messenger = $this->get_messenger($messenger_name); |
|
228 | + if ($messenger instanceof EE_messenger) { |
|
229 | + return $messenger; |
|
230 | + } |
|
231 | + throw new EE_Error( |
|
232 | + sprintf( |
|
233 | + __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'), |
|
234 | + $messenger_name |
|
235 | + ) |
|
236 | + ); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @return EE_Message_Type_Collection |
|
242 | + */ |
|
243 | + public function message_type_collection() |
|
244 | + { |
|
245 | + $this->_initialize_collections(); |
|
246 | + return $this->_message_type_collection_loader->message_type_collection(); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @return array |
|
252 | + */ |
|
253 | + public function active_message_types() |
|
254 | + { |
|
255 | + $this->_initialize_collections(); |
|
256 | + return $this->_active_message_types; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * @param string $message_type_name |
|
262 | + * @return \EE_message_type |
|
263 | + */ |
|
264 | + public function get_message_type($message_type_name) |
|
265 | + { |
|
266 | + return $this->message_type_collection()->get_by_info($message_type_name); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * This returns the EE_message_type from the active message types array ( if present ); |
|
272 | + * |
|
273 | + * @param string $messenger_name |
|
274 | + * @param string $message_type_name |
|
275 | + * @return \EE_message_type|null |
|
276 | + */ |
|
277 | + public function get_active_message_type_for_messenger($messenger_name, $message_type_name) |
|
278 | + { |
|
279 | + return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
280 | + ? $this->get_message_type($message_type_name) |
|
281 | + : null; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * Returns whether the given message type is active for the given messenger. |
|
287 | + * |
|
288 | + * @param string $messenger_name |
|
289 | + * @param string $message_type_name |
|
290 | + * @return bool |
|
291 | + */ |
|
292 | + public function is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
293 | + { |
|
294 | + $this->_initialize_collections(); |
|
295 | + return ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * Returns whether the given messenger is active. |
|
301 | + * |
|
302 | + * @param string $messenger_name the name of the messenger to check if active. |
|
303 | + * @return bool |
|
304 | + */ |
|
305 | + public function is_messenger_active($messenger_name) |
|
306 | + { |
|
307 | + $this->_initialize_collections(); |
|
308 | + return ! empty($this->_active_message_types[ $messenger_name ]); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * This returns any settings that might be on a message type for a messenger |
|
314 | + * |
|
315 | + * @param string $messenger_name The slug of the messenger |
|
316 | + * @param string $message_type_name The slug of the message type getting the settings for. |
|
317 | + * @return array |
|
318 | + */ |
|
319 | + public function get_message_type_settings_for_messenger($messenger_name, $message_type_name) |
|
320 | + { |
|
321 | + $settings = array(); |
|
322 | + if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
323 | + $settings = isset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings']) |
|
324 | + ? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] |
|
325 | + : array(); |
|
326 | + } |
|
327 | + return $settings; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * Returns whether the given messenger name has active message types on it. |
|
333 | + * Infers whether the messenger is active or not as well. |
|
334 | + * |
|
335 | + * @param string $messenger_name |
|
336 | + * @return bool |
|
337 | + */ |
|
338 | + public function messenger_has_active_message_types($messenger_name) |
|
339 | + { |
|
340 | + $this->_initialize_collections(); |
|
341 | + return |
|
342 | + ! empty($this->_active_message_types[ $messenger_name ]) |
|
343 | + && ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ]); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * This checks the _active_message_types property for any active message types |
|
349 | + * that are present for the given messenger and returns them. |
|
350 | + * |
|
351 | + * @since 4.9.0 |
|
352 | + * @param string $messenger_name The messenger being checked |
|
353 | + * @return EE_message_type[]|array (empty array if no active_message_types) |
|
354 | + */ |
|
355 | + public function get_active_message_types_for_messenger($messenger_name) |
|
356 | + { |
|
357 | + $message_types = array(); |
|
358 | + if (! $this->messenger_has_active_message_types($messenger_name)) { |
|
359 | + return $message_types; |
|
360 | + } |
|
361 | + $installed_message_types = $this->installed_message_types(); |
|
362 | + foreach ($installed_message_types as $message_type_name => $message_type) { |
|
363 | + if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
364 | + $message_types[ $message_type_name ] = $message_type; |
|
365 | + } |
|
366 | + } |
|
367 | + return $message_types; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * This does NOT return the _active_message_types property but |
|
373 | + * simply returns an array of active message type names from that property. |
|
374 | + * (The _active_message_types property is indexed by messenger and active message_types per messenger). |
|
375 | + * |
|
376 | + * @return array message_type references (string) |
|
377 | + */ |
|
378 | + public function list_of_active_message_types() |
|
379 | + { |
|
380 | + $active_message_type_names = array(); |
|
381 | + $this->_initialize_collections(); |
|
382 | + foreach ($this->_active_message_types as $messenger => $messenger_settings) { |
|
383 | + if (! isset($messenger_settings['settings'][ $messenger . '-message_types' ])) { |
|
384 | + continue; |
|
385 | + } |
|
386 | + foreach ($messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config) { |
|
387 | + if (! in_array($message_type_name, $active_message_type_names)) { |
|
388 | + $active_message_type_names[] = $message_type_name; |
|
389 | + } |
|
390 | + } |
|
391 | + } |
|
392 | + return $active_message_type_names; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * Same as list_of_active_message_types() except this returns actual EE_message_type objects |
|
398 | + * |
|
399 | + * @since 4.9.0 |
|
400 | + * @return \EE_message_type[] |
|
401 | + */ |
|
402 | + public function get_active_message_type_objects() |
|
403 | + { |
|
404 | + $active_message_types = array(); |
|
405 | + $installed_message_types = $this->installed_message_types(); |
|
406 | + $active_message_type_names = $this->list_of_active_message_types(); |
|
407 | + foreach ($active_message_type_names as $active_message_type_name) { |
|
408 | + if (isset($installed_message_types[ $active_message_type_name ])) { |
|
409 | + $active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ]; |
|
410 | + } |
|
411 | + } |
|
412 | + return $active_message_types; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * @return \EE_message_type[] |
|
418 | + */ |
|
419 | + public function installed_message_types() |
|
420 | + { |
|
421 | + if (empty($this->_installed_message_types)) { |
|
422 | + $this->message_type_collection()->rewind(); |
|
423 | + while ($this->message_type_collection()->valid()) { |
|
424 | + $this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current(); |
|
425 | + $this->message_type_collection()->next(); |
|
426 | + } |
|
427 | + } |
|
428 | + return $this->_installed_message_types; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * @param string $message_type_name |
|
434 | + * @return \EE_message_type |
|
435 | + * @throws \EE_Error |
|
436 | + */ |
|
437 | + public function valid_message_type($message_type_name) |
|
438 | + { |
|
439 | + $message_type = $this->get_message_type($message_type_name); |
|
440 | + if ($message_type instanceof EE_message_type) { |
|
441 | + return $message_type; |
|
442 | + } |
|
443 | + throw new EE_Error( |
|
444 | + sprintf( |
|
445 | + __('The "%1$s" message type is either invalid or not installed', 'event_espresso'), |
|
446 | + $message_type_name |
|
447 | + ) |
|
448 | + ); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * valid_message_type_for_messenger |
|
454 | + * |
|
455 | + * @param EE_messenger $messenger |
|
456 | + * @param string $message_type_name |
|
457 | + * @return boolean |
|
458 | + * @throws \EE_Error |
|
459 | + */ |
|
460 | + public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name) |
|
461 | + { |
|
462 | + $valid_message_types = $messenger->get_valid_message_types(); |
|
463 | + if (! in_array($message_type_name, $valid_message_types)) { |
|
464 | + throw new EE_Error( |
|
465 | + sprintf( |
|
466 | + __( |
|
467 | + 'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger. Double-check the spelling and verify that message type has been registered as a valid type with the messenger.', |
|
468 | + 'event_espresso' |
|
469 | + ), |
|
470 | + $message_type_name, |
|
471 | + __METHOD__, |
|
472 | + $messenger->name |
|
473 | + ) |
|
474 | + ); |
|
475 | + } |
|
476 | + return true; |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * Used to return active messengers array stored in the wp options table. |
|
482 | + * If no value is present in the option then an empty array is returned. |
|
483 | + * |
|
484 | + * @param bool $reset If true then we ignore whether the option is cached on the _active_message_types |
|
485 | + * property and pull directly from the db. Otherwise whatever is currently on the |
|
486 | + * $_active_message_types property is pulled. |
|
487 | + * @return array |
|
488 | + */ |
|
489 | + public function get_active_messengers_option($reset = false) |
|
490 | + { |
|
491 | + if ($reset) { |
|
492 | + $this->_active_message_types = get_option('ee_active_messengers', array()); |
|
493 | + } |
|
494 | + return $this->_active_message_types; |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * Used to update the active messengers array stored in the wp options table. |
|
500 | + * |
|
501 | + * @param array $active_messenger_settings Incoming data to save. If empty, then the internal cached property |
|
502 | + * representing this data is used. |
|
503 | + * @return bool FALSE if not updated, TRUE if updated. |
|
504 | + */ |
|
505 | + public function update_active_messengers_option($active_messenger_settings = array()) |
|
506 | + { |
|
507 | + $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings; |
|
508 | + // make sure _active_message_types is updated (this is the internal cache for the settings). |
|
509 | + $this->_active_message_types = $active_messenger_settings; |
|
510 | + return update_option('ee_active_messengers', $active_messenger_settings); |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Used to return has activated message types for messengers array stored in the wp options table. |
|
516 | + * If no value is present in the option then an empty array is returned. |
|
517 | + * The value is cached on the $_has_activated_messengers_and_message_types property for future calls. |
|
518 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
519 | + * |
|
520 | + * @param bool $reset Used to indicate that any cached value should be ignored. |
|
521 | + * @return array |
|
522 | + */ |
|
523 | + public function get_has_activated_messengers_option($reset = false) |
|
524 | + { |
|
525 | + if ($reset || empty($this->_has_activated_messengers_and_message_types)) { |
|
526 | + $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array()); |
|
527 | + } |
|
528 | + return $this->_has_activated_messengers_and_message_types; |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * Used to update the has activated option in the db. |
|
534 | + * |
|
535 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
536 | + * |
|
537 | + * @param array $has_activated_messengers Incoming data to save. If empty, then the internal cached property |
|
538 | + * representing this data is used. |
|
539 | + * @return bool FALSE if not updated, TRUE if updated. |
|
540 | + */ |
|
541 | + public function update_has_activated_messengers_option($has_activated_messengers = array()) |
|
542 | + { |
|
543 | + // make sure the option has been retrieved from first so we don't overwrite it accidentally. |
|
544 | + if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) { |
|
545 | + $this->get_has_activated_messengers_option(); |
|
546 | + } |
|
547 | + $has_activated_messengers = empty($has_activated_messengers) |
|
548 | + ? $this->_has_activated_messengers_and_message_types |
|
549 | + : $has_activated_messengers; |
|
550 | + return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers); |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * wrapper for _set_active_messengers_and_message_types() |
|
556 | + */ |
|
557 | + public function reset_active_messengers_and_message_types() |
|
558 | + { |
|
559 | + $this->_set_active_messengers_and_message_types(); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Generate list of active messengers and message types from collection. |
|
565 | + * This sets up the active messengers from what is present in the database. |
|
566 | + */ |
|
567 | + protected function _set_active_messengers_and_message_types() |
|
568 | + { |
|
569 | + // echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n"; |
|
570 | + // list of activated messengers as set via the admin |
|
571 | + // note calling `get_active_messengers_options` also initializes the _active_message_types property. |
|
572 | + $this->get_active_messengers_option(true); |
|
573 | + $this->ensure_messengers_are_active(array(), false, true); |
|
574 | + $this->update_active_messengers_option(); |
|
575 | + $this->update_has_activated_messengers_option(); |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * Ensures that the specified messenger is currently active. |
|
581 | + * If not, activates it and its default message types. |
|
582 | + * |
|
583 | + * @param string $messenger_name |
|
584 | + * @param bool $update_option Whether to update the option in the db or not. |
|
585 | + * @return boolean true if either already active or successfully activated. |
|
586 | + */ |
|
587 | + public function ensure_messenger_is_active($messenger_name, $update_option = true) |
|
588 | + { |
|
589 | + if (! isset($this->_active_messengers[ $messenger_name ])) { |
|
590 | + try { |
|
591 | + $this->activate_messenger($messenger_name, array(), $update_option); |
|
592 | + } catch (EE_Error $e) { |
|
593 | + EE_Error::add_error( |
|
594 | + $e->getMessage(), |
|
595 | + __FILE__, |
|
596 | + __FUNCTION__, |
|
597 | + __LINE__ |
|
598 | + ); |
|
599 | + return false; |
|
600 | + } |
|
601 | + } |
|
602 | + return true; |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * This ensures the given array of messenger names is active in the system. |
|
608 | + * Note, this method will not activate any NEW message types for the messenger when it is called. Instead, |
|
609 | + * it will automatically activate the default message types for the messenger if its not active. |
|
610 | + * |
|
611 | + * @param array $messenger_names Array of messenger names for messengers to be activated. If an empty array |
|
612 | + * (default) then will attempt to set the active messengers from the |
|
613 | + * activated_messengers option |
|
614 | + * (stored in $_active_message_types property). |
|
615 | + * @param bool $update_option Whether to update the related active messengers option. |
|
616 | + * @param bool $verify Whether to verify the messengers are installed before activating. Note if this is |
|
617 | + * set to true and a messenger is indicated as active, but is NOT installed, then it |
|
618 | + * will automatically be deactivated. |
|
619 | + */ |
|
620 | + public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false) |
|
621 | + { |
|
622 | + $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names; |
|
623 | + |
|
624 | + $not_installed = array(); |
|
625 | + foreach ($messenger_names as $messenger_name) { |
|
626 | + if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) { |
|
627 | + $not_installed[] = $messenger_name; |
|
628 | + $this->deactivate_messenger($messenger_name); |
|
629 | + continue; |
|
630 | + } |
|
631 | + $this->ensure_messenger_is_active($messenger_name, $update_option); |
|
632 | + } |
|
633 | + |
|
634 | + if (! empty($not_installed)) { |
|
635 | + EE_Error::add_error( |
|
636 | + sprintf( |
|
637 | + __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'), |
|
638 | + '<br />', |
|
639 | + implode(', ', $not_installed) |
|
640 | + ), |
|
641 | + __FILE__, |
|
642 | + __FUNCTION__, |
|
643 | + __LINE__ |
|
644 | + ); |
|
645 | + } |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * Ensures that the specified message type for the given messenger is currently active, if not activates it. |
|
651 | + * This ALSO ensures that the given messenger is active as well! |
|
652 | + * |
|
653 | + * @param string $message_type_name message type name. |
|
654 | + * @param $messenger_name |
|
655 | + * @param bool $update_option Whether to update the option in the db or not. |
|
656 | + * @return bool Returns true if already is active or if was activated successfully. |
|
657 | + * @throws \EE_Error |
|
658 | + */ |
|
659 | + public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true) |
|
660 | + { |
|
661 | + // grab the messenger to work with. |
|
662 | + $messenger = $this->valid_messenger($messenger_name); |
|
663 | + if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) { |
|
664 | + // ensure messenger is active (that's an inherent coupling between active message types and the |
|
665 | + // messenger they are being activated for. |
|
666 | + try { |
|
667 | + if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
668 | + // all is good so let's just get it active |
|
669 | + $this->activate_messenger($messenger_name, array($message_type_name), $update_option); |
|
670 | + } |
|
671 | + } catch (EE_Error $e) { |
|
672 | + EE_Error::add_error( |
|
673 | + $e->getMessage(), |
|
674 | + __FILE__, |
|
675 | + __FUNCTION__, |
|
676 | + __LINE__ |
|
677 | + ); |
|
678 | + return false; |
|
679 | + } |
|
680 | + } |
|
681 | + return true; |
|
682 | + } |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a |
|
687 | + * messenger are active in one go. |
|
688 | + * |
|
689 | + * @param array $message_type_names Array of message type names to ensure are active. |
|
690 | + * @param string $messenger_name The name of the messenger that the message types are to be activated on. |
|
691 | + * @param bool $update_option Whether to persist the activation to the database or not (default true). |
|
692 | + */ |
|
693 | + public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true) |
|
694 | + { |
|
695 | + $message_type_names = (array) $message_type_names; |
|
696 | + foreach ($message_type_names as $message_type_name) { |
|
697 | + // note, intentionally not updating option here because we're in a loop. |
|
698 | + // We'll follow the instructions of the incoming $update_option argument after the loop. |
|
699 | + $this->ensure_message_type_is_active($message_type_name, $messenger_name, false); |
|
700 | + } |
|
701 | + if ($update_option) { |
|
702 | + $this->update_active_messengers_option(); |
|
703 | + $this->update_has_activated_messengers_option(); |
|
704 | + } |
|
705 | + } |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * Activates the specified messenger. |
|
710 | + * |
|
711 | + * @param string $messenger_name |
|
712 | + * @param array $message_type_names An array of message type names to activate with this messenger. |
|
713 | + * If included we do NOT setup the default message types |
|
714 | + * (assuming they are already setup.) |
|
715 | + * @param bool $update_active_messengers_option |
|
716 | + * @return array of generated templates |
|
717 | + * @throws \EE_Error |
|
718 | + */ |
|
719 | + public function activate_messenger( |
|
720 | + $messenger_name, |
|
721 | + $message_type_names = array(), |
|
722 | + $update_active_messengers_option = true |
|
723 | + ) { |
|
724 | + $templates = array(); |
|
725 | + // grab the messenger to work with. |
|
726 | + $messenger = $this->messenger_collection()->get_by_info($messenger_name); |
|
727 | + // it's inactive. Activate it. |
|
728 | + if ($messenger instanceof EE_messenger) { |
|
729 | + $this->_active_messengers[ $messenger->name ] = $messenger; |
|
730 | + // activate incoming message types set to be activated with messenger. |
|
731 | + $message_type_names = $this->_activate_message_types($messenger, $message_type_names); |
|
732 | + // setup any initial settings for the messenger if necessary. |
|
733 | + $this->add_settings_for_messenger($messenger->name); |
|
734 | + if ($update_active_messengers_option) { |
|
735 | + $this->update_active_messengers_option(); |
|
736 | + $this->update_has_activated_messengers_option(); |
|
737 | + } |
|
738 | + // generate new templates if necessary and ensure all related templates that are already in the database are |
|
739 | + // marked active. Note, this will also deactivate a message type for a messenger if the template |
|
740 | + // cannot be successfully created during its attempt (only happens for global template attempts). |
|
741 | + if (! empty($message_type_names)) { |
|
742 | + $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true); |
|
743 | + EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names); |
|
744 | + } |
|
745 | + } |
|
746 | + return $templates; |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * Activates given message types for the given EE_messenger object. |
|
752 | + * Note: (very important) This method does not persist the activation to the database. |
|
753 | + * See code implementing this method in this class for examples of how to persist. |
|
754 | + * |
|
755 | + * @param \EE_messenger $messenger |
|
756 | + * @param array $message_type_names |
|
757 | + * @return array |
|
758 | + */ |
|
759 | + protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array()) |
|
760 | + { |
|
761 | + // If $message_type_names is empty, AND $this->_active_message_types is empty, then that means |
|
762 | + // things have never been initialized (which should happen on EEH_Activation::generate_message_templates). |
|
763 | + // So ONLY then do we need to actually grab defaults and cycle through them. Otherwise we |
|
764 | + // only override _active_message_types when an explicit array of $message_type_names has been provided. |
|
765 | + $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[ $messenger->name ]) |
|
766 | + ? $messenger->get_default_message_types() |
|
767 | + : (array) $message_type_names; |
|
768 | + |
|
769 | + // now we ALWAYS need to make sure that the messenger is active for the message types we're activating! |
|
770 | + if (! isset($this->_active_message_types[ $messenger->name ])) { |
|
771 | + $this->_active_message_types[ $messenger->name ]['settings'] = array(); |
|
772 | + } |
|
773 | + |
|
774 | + if ($message_type_names) { |
|
775 | + // cycle thru message types |
|
776 | + foreach ($message_type_names as $message_type_name) { |
|
777 | + // only register the message type as active IF it isn't already active |
|
778 | + // and if its actually installed. |
|
779 | + if (! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name) |
|
780 | + ) { |
|
781 | + $this->add_settings_for_message_type($messenger->name, $message_type_name); |
|
782 | + $this->_set_messenger_has_activated_message_type( |
|
783 | + $messenger, |
|
784 | + $message_type_name |
|
785 | + ); |
|
786 | + } |
|
787 | + } |
|
788 | + } |
|
789 | + return $message_type_names; |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * add_settings_for_message_type |
|
795 | + * NOTE This does NOT automatically persist any settings to the db. Client code should call |
|
796 | + * $this->update_active_messengers_option to persist. |
|
797 | + * |
|
798 | + * @param string $messenger_name The name of the messenger adding the settings for |
|
799 | + * @param string $message_type_name The name of the message type adding the settings for |
|
800 | + * @param array $new_settings Any new settings being set for the message type and messenger |
|
801 | + */ |
|
802 | + public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array()) |
|
803 | + { |
|
804 | + // get installed message type from collection |
|
805 | + $message_type = $this->message_type_collection()->get_by_info($message_type_name); |
|
806 | + $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name); |
|
807 | + // we need to setup any initial settings for message types |
|
808 | + if ($message_type instanceof EE_message_type) { |
|
809 | + $default_settings = $message_type->get_admin_settings_fields(); |
|
810 | + foreach ($default_settings as $field => $values) { |
|
811 | + if (isset($new_settings[ $field ])) { |
|
812 | + $existing_settings[ $field ] = $new_settings[ $field ]; |
|
813 | + continue; |
|
814 | + } |
|
815 | + if (! isset($existing_settings[ $field ])) { |
|
816 | + $existing_settings[ $field ] = $values['default']; |
|
817 | + } |
|
818 | + } |
|
819 | + } |
|
820 | + $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings; |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger |
|
826 | + * and message type. |
|
827 | + * |
|
828 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
829 | + * |
|
830 | + * @access protected |
|
831 | + * @param \EE_messenger $messenger |
|
832 | + * @param string $message_type_name |
|
833 | + */ |
|
834 | + protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name) |
|
835 | + { |
|
836 | + |
|
837 | + // if _has_activated_messengers_and_message_types is empty then lets ensure its initialized |
|
838 | + if (empty($this->_has_activated_messengers_and_message_types)) { |
|
839 | + $this->get_has_activated_messengers_option(); |
|
840 | + } |
|
841 | + |
|
842 | + // make sure this messenger has a record in the has_activated array |
|
843 | + if (! isset($this->_has_activated_messengers_and_message_types[ $messenger->name ])) { |
|
844 | + $this->_has_activated_messengers_and_message_types[ $messenger->name ] = array(); |
|
845 | + } |
|
846 | + // check if message type has already been added |
|
847 | + if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ])) { |
|
848 | + $this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name; |
|
849 | + } |
|
850 | + } |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * add_settings_for_messenger |
|
855 | + * NOTE This does NOT automatically persist any settings to the db. Client code should call |
|
856 | + * $this->update_active_messengers_option to persist. |
|
857 | + * |
|
858 | + * @param string $messenger_name The name of the messenger the settings is being added for. |
|
859 | + * @param array $new_settings An array of settings to update the existing settings. |
|
860 | + */ |
|
861 | + public function add_settings_for_messenger($messenger_name, $new_settings = array()) |
|
862 | + { |
|
863 | + $messenger = $this->get_messenger($messenger_name); |
|
864 | + if ($messenger instanceof EE_messenger) { |
|
865 | + $msgr_settings = $messenger->get_admin_settings_fields(); |
|
866 | + if (! empty($msgr_settings)) { |
|
867 | + foreach ($msgr_settings as $field => $value) { |
|
868 | + // is there a new setting for this? |
|
869 | + if (isset($new_settings[ $field ])) { |
|
870 | + $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ]; |
|
871 | + continue; |
|
872 | + } |
|
873 | + // only set the default if it isn't already set. |
|
874 | + if (! isset($this->_active_message_types[ $messenger->name ]['settings'][ $field ])) { |
|
875 | + $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value; |
|
876 | + } |
|
877 | + } |
|
878 | + } |
|
879 | + } |
|
880 | + } |
|
881 | + |
|
882 | + |
|
883 | + /** |
|
884 | + * deactivate_messenger |
|
885 | + * |
|
886 | + * @param string|EE_messenger $messenger_name name of messenger |
|
887 | + * @return void |
|
888 | + */ |
|
889 | + public function deactivate_messenger($messenger_name) |
|
890 | + { |
|
891 | + $this->_initialize_collections(); |
|
892 | + if ($messenger_name instanceof EE_messenger) { |
|
893 | + $messenger_name = $messenger_name->name; |
|
894 | + } |
|
895 | + unset($this->_active_messengers[ $messenger_name ]); |
|
896 | + unset($this->_active_message_types[ $messenger_name ]); |
|
897 | + $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name); |
|
898 | + $this->update_active_messengers_option(); |
|
899 | + } |
|
900 | + |
|
901 | + |
|
902 | + /** |
|
903 | + * Deactivates a message type (note this will deactivate across all messenger's it is active on. |
|
904 | + * |
|
905 | + * @param string $message_type_name name of message type being deactivated |
|
906 | + * @param bool $set_has_active_record By default we always record the has_active record when deactivating a message |
|
907 | + * type. However, this can be overridden if we don't want this set (usually when |
|
908 | + * this is called as a part of deregistration of a custom message type) |
|
909 | + */ |
|
910 | + public function deactivate_message_type($message_type_name, $set_has_active_record = true) |
|
911 | + { |
|
912 | + $this->_initialize_collections(); |
|
913 | + if ($message_type_name instanceof EE_message_type) { |
|
914 | + $message_type_name = $message_type_name->name; |
|
915 | + } |
|
916 | + foreach ($this->_active_message_types as $messenger_name => $settings) { |
|
917 | + unset( |
|
918 | + $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ] |
|
919 | + ); |
|
920 | + |
|
921 | + // we always record (even on deactivation) that a message type has been activated because there should at |
|
922 | + // least be a record in the "has_activated" option that it WAS active at one point. |
|
923 | + if ($set_has_active_record) { |
|
924 | + $messenger = $this->get_messenger($messenger_name); |
|
925 | + $this->_set_messenger_has_activated_message_type($messenger, $message_type_name); |
|
926 | + } |
|
927 | + } |
|
928 | + $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name); |
|
929 | + $this->update_active_messengers_option(); |
|
930 | + $this->update_has_activated_messengers_option(); |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * Deactivates a message type for a specific messenger as opposed to all messengers. |
|
936 | + * |
|
937 | + * @param string $message_type_name Name of message type being deactivated. |
|
938 | + * @param string $messenger_name Name of messenger the message type is being deactivated for. |
|
939 | + */ |
|
940 | + public function deactivate_message_type_for_messenger($message_type_name, $messenger_name) |
|
941 | + { |
|
942 | + $this->_initialize_collections(); |
|
943 | + if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
944 | + unset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]); |
|
945 | + } |
|
946 | + $this->_message_template_group_model->deactivate_message_template_groups_for( |
|
947 | + array($messenger_name), |
|
948 | + array($message_type_name) |
|
949 | + ); |
|
950 | + $this->update_active_messengers_option(); |
|
951 | + } |
|
952 | + |
|
953 | + |
|
954 | + /** |
|
955 | + * Used to verify if a message can be sent for the given messenger and message type |
|
956 | + * and that it is a generating messenger (used for generating message templates). |
|
957 | + * |
|
958 | + * @param EE_messenger $messenger messenger used in trigger |
|
959 | + * @param EE_message_type $message_type message type used in trigger |
|
960 | + * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
|
961 | + */ |
|
962 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) |
|
963 | + { |
|
964 | + // get the $messengers the message type says it can be used with. |
|
965 | + foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) { |
|
966 | + if ($messenger->name === $generating_messenger |
|
967 | + && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name) |
|
968 | + ) { |
|
969 | + return true; |
|
970 | + } |
|
971 | + } |
|
972 | + return false; |
|
973 | + } |
|
974 | + |
|
975 | + |
|
976 | + /** |
|
977 | + * This returns all the contexts that are registered by all message types. |
|
978 | + * If $slugs_only is true, |
|
979 | + * then just an array indexed by unique context slugs with the latest label representation for that slug. |
|
980 | + * array( |
|
981 | + * 'context_slug' => 'localized label for context obtained from latest message type in the loop'. |
|
982 | + * ); |
|
983 | + * If $slugs_only is false, then the format is: |
|
984 | + * array( |
|
985 | + * 'message_type_name' => array( |
|
986 | + * 'context_slug' => array( |
|
987 | + * 'label' => 'localized label for context', |
|
988 | + * 'description' => 'localized description for context' |
|
989 | + * ) |
|
990 | + * ) |
|
991 | + * ); |
|
992 | + * Keep in mind that although different message types may share the same context slugs, |
|
993 | + * it is possible that the context is described differently by the message type. |
|
994 | + * |
|
995 | + * @since 4.9.0 |
|
996 | + * @param bool $slugs_only Whether to return an array of just slugs and labels (true) |
|
997 | + * or all contexts indexed by message type. |
|
998 | + * @return array |
|
999 | + */ |
|
1000 | + public function get_all_contexts($slugs_only = true) |
|
1001 | + { |
|
1002 | + $key = $slugs_only ? 'slugs' : 'all'; |
|
1003 | + // check if contexts has been setup yet. |
|
1004 | + if (empty($this->_contexts[ $key ])) { |
|
1005 | + // So let's get all active message type objects and loop through to get all unique contexts |
|
1006 | + foreach ($this->get_active_message_type_objects() as $message_type) { |
|
1007 | + if ($message_type instanceof EE_message_type) { |
|
1008 | + $message_type_contexts = $message_type->get_contexts(); |
|
1009 | + if ($slugs_only) { |
|
1010 | + foreach ($message_type_contexts as $context => $context_details) { |
|
1011 | + $this->_contexts[ $key ][ $context ] = $context_details['label']; |
|
1012 | + } |
|
1013 | + } else { |
|
1014 | + $this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts; |
|
1015 | + } |
|
1016 | + } |
|
1017 | + } |
|
1018 | + } |
|
1019 | + return ! empty($this->_contexts[ $key ]) ? $this->_contexts[ $key ] : array(); |
|
1020 | + } |
|
1021 | + |
|
1022 | + |
|
1023 | + /** |
|
1024 | + * This checks the internal record of what message types are considered "active" and verifies that |
|
1025 | + * there is an installed class definition for that message type. If the active message type does not have a |
|
1026 | + * corresponding accessible message type class then it will be deactivated from all messengers it is active on and |
|
1027 | + * any related message templates will be inactivated as well. |
|
1028 | + * |
|
1029 | + * @return bool true means all active message types are valid, false means at least one message type was |
|
1030 | + * deactivated. |
|
1031 | + */ |
|
1032 | + public function validate_active_message_types_are_installed() |
|
1033 | + { |
|
1034 | + $list_of_active_message_type_names = $this->list_of_active_message_types(); |
|
1035 | + $installed_message_types = $this->installed_message_types(); |
|
1036 | + $all_message_types_valid = true; |
|
1037 | + // loop through list of active message types and verify they are installed. |
|
1038 | + foreach ($list_of_active_message_type_names as $message_type_name) { |
|
1039 | + if (! isset($installed_message_types[ $message_type_name ])) { |
|
1040 | + $this->remove_message_type_has_been_activated_from_all_messengers( |
|
1041 | + $message_type_name, |
|
1042 | + true |
|
1043 | + ); |
|
1044 | + $this->deactivate_message_type($message_type_name, false); |
|
1045 | + $all_message_types_valid = false; |
|
1046 | + } |
|
1047 | + } |
|
1048 | + return $all_message_types_valid; |
|
1049 | + } |
|
1050 | + |
|
1051 | + |
|
1052 | + /** |
|
1053 | + * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been |
|
1054 | + * activated for the given messenger. This can be called by client code on plugin updates etc to determine whether |
|
1055 | + * to attempt automatically reactivating message types that should be activated by default or not. |
|
1056 | + * |
|
1057 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1058 | + * |
|
1059 | + * @param $message_type_name |
|
1060 | + * @param $messenger_name |
|
1061 | + * @return bool |
|
1062 | + */ |
|
1063 | + public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name) |
|
1064 | + { |
|
1065 | + $has_activated = $this->get_has_activated_messengers_option(); |
|
1066 | + return isset($has_activated[ $messenger_name ]) |
|
1067 | + && in_array($message_type_name, $has_activated[ $messenger_name ]); |
|
1068 | + } |
|
1069 | + |
|
1070 | + |
|
1071 | + /** |
|
1072 | + * This method unsets a message type from the given messenger has activated option. |
|
1073 | + * |
|
1074 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1075 | + * |
|
1076 | + * @param string $message_type_name |
|
1077 | + * @param string $messenger_name |
|
1078 | + * @param bool $consider_current_state Whether to consider whether the message type is currently active or not. |
|
1079 | + * If it is currently active, then remove. Otherwise leave it alone. |
|
1080 | + */ |
|
1081 | + public function remove_message_type_has_been_activated_for_messenger( |
|
1082 | + $message_type_name, |
|
1083 | + $messenger_name, |
|
1084 | + $consider_current_state = false |
|
1085 | + ) { |
|
1086 | + if ($consider_current_state |
|
1087 | + && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
1088 | + ) { |
|
1089 | + // when consider current state is true, this means we don't want to change anything on the "has_activated" |
|
1090 | + // record if the message type is currently active for this messenger. This is used when we want to retain |
|
1091 | + // the record for user initiated inactivations of the message type. |
|
1092 | + return; |
|
1093 | + } |
|
1094 | + $has_activated = $this->get_has_activated_messengers_option(); |
|
1095 | + $key_for_message_type = isset($has_activated[ $messenger_name ]) |
|
1096 | + ? array_search($message_type_name, $has_activated[ $messenger_name ], true) |
|
1097 | + : false; |
|
1098 | + if ($key_for_message_type !== false) { |
|
1099 | + unset($has_activated[ $messenger_name ][ $key_for_message_type ]); |
|
1100 | + $this->update_has_activated_messengers_option($has_activated); |
|
1101 | + // reset the internal cached property |
|
1102 | + $this->get_has_activated_messengers_option(true); |
|
1103 | + } |
|
1104 | + } |
|
1105 | + |
|
1106 | + |
|
1107 | + /** |
|
1108 | + * Removes a message type active record from all messengers it is attached to. |
|
1109 | + * |
|
1110 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1111 | + * |
|
1112 | + * @param $message_type_name |
|
1113 | + * @param bool $consider_current_state Whether to consider whether the message type is currently active or not. |
|
1114 | + * If it is currently active, then remove. Otherwise leave it alone. |
|
1115 | + */ |
|
1116 | + public function remove_message_type_has_been_activated_from_all_messengers( |
|
1117 | + $message_type_name, |
|
1118 | + $consider_current_state = false |
|
1119 | + ) { |
|
1120 | + foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) { |
|
1121 | + $this->remove_message_type_has_been_activated_for_messenger( |
|
1122 | + $message_type_name, |
|
1123 | + $messenger_name, |
|
1124 | + $consider_current_state |
|
1125 | + ); |
|
1126 | + } |
|
1127 | + } |
|
1128 | 1128 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | public function get_active_messenger($messenger) |
197 | 197 | { |
198 | 198 | $this->_initialize_collections(); |
199 | - return ! empty($this->_active_messengers[ $messenger ]) ? $this->_active_messengers[ $messenger ] : null; |
|
199 | + return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null; |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $this->_installed_messengers = array(); |
210 | 210 | $this->messenger_collection()->rewind(); |
211 | 211 | while ($this->messenger_collection()->valid()) { |
212 | - $this->_installed_messengers[ $this->messenger_collection()->current()->name ] = $this->messenger_collection()->current(); |
|
212 | + $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current(); |
|
213 | 213 | $this->messenger_collection()->next(); |
214 | 214 | } |
215 | 215 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | public function is_message_type_active_for_messenger($messenger_name, $message_type_name) |
293 | 293 | { |
294 | 294 | $this->_initialize_collections(); |
295 | - return ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]); |
|
295 | + return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | public function is_messenger_active($messenger_name) |
306 | 306 | { |
307 | 307 | $this->_initialize_collections(); |
308 | - return ! empty($this->_active_message_types[ $messenger_name ]); |
|
308 | + return ! empty($this->_active_message_types[$messenger_name]); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -320,8 +320,8 @@ discard block |
||
320 | 320 | { |
321 | 321 | $settings = array(); |
322 | 322 | if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
323 | - $settings = isset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings']) |
|
324 | - ? $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] |
|
323 | + $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']) |
|
324 | + ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] |
|
325 | 325 | : array(); |
326 | 326 | } |
327 | 327 | return $settings; |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | { |
340 | 340 | $this->_initialize_collections(); |
341 | 341 | return |
342 | - ! empty($this->_active_message_types[ $messenger_name ]) |
|
343 | - && ! empty($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ]); |
|
342 | + ! empty($this->_active_message_types[$messenger_name]) |
|
343 | + && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -355,13 +355,13 @@ discard block |
||
355 | 355 | public function get_active_message_types_for_messenger($messenger_name) |
356 | 356 | { |
357 | 357 | $message_types = array(); |
358 | - if (! $this->messenger_has_active_message_types($messenger_name)) { |
|
358 | + if ( ! $this->messenger_has_active_message_types($messenger_name)) { |
|
359 | 359 | return $message_types; |
360 | 360 | } |
361 | 361 | $installed_message_types = $this->installed_message_types(); |
362 | 362 | foreach ($installed_message_types as $message_type_name => $message_type) { |
363 | 363 | if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
364 | - $message_types[ $message_type_name ] = $message_type; |
|
364 | + $message_types[$message_type_name] = $message_type; |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | return $message_types; |
@@ -380,11 +380,11 @@ discard block |
||
380 | 380 | $active_message_type_names = array(); |
381 | 381 | $this->_initialize_collections(); |
382 | 382 | foreach ($this->_active_message_types as $messenger => $messenger_settings) { |
383 | - if (! isset($messenger_settings['settings'][ $messenger . '-message_types' ])) { |
|
383 | + if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) { |
|
384 | 384 | continue; |
385 | 385 | } |
386 | - foreach ($messenger_settings['settings'][ $messenger . '-message_types' ] as $message_type_name => $message_type_config) { |
|
387 | - if (! in_array($message_type_name, $active_message_type_names)) { |
|
386 | + foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) { |
|
387 | + if ( ! in_array($message_type_name, $active_message_type_names)) { |
|
388 | 388 | $active_message_type_names[] = $message_type_name; |
389 | 389 | } |
390 | 390 | } |
@@ -405,8 +405,8 @@ discard block |
||
405 | 405 | $installed_message_types = $this->installed_message_types(); |
406 | 406 | $active_message_type_names = $this->list_of_active_message_types(); |
407 | 407 | foreach ($active_message_type_names as $active_message_type_name) { |
408 | - if (isset($installed_message_types[ $active_message_type_name ])) { |
|
409 | - $active_message_types[ $active_message_type_name ] = $installed_message_types[ $active_message_type_name ]; |
|
408 | + if (isset($installed_message_types[$active_message_type_name])) { |
|
409 | + $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name]; |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | return $active_message_types; |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | if (empty($this->_installed_message_types)) { |
422 | 422 | $this->message_type_collection()->rewind(); |
423 | 423 | while ($this->message_type_collection()->valid()) { |
424 | - $this->_installed_message_types[ $this->message_type_collection()->current()->name ] = $this->message_type_collection()->current(); |
|
424 | + $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current(); |
|
425 | 425 | $this->message_type_collection()->next(); |
426 | 426 | } |
427 | 427 | } |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name) |
461 | 461 | { |
462 | 462 | $valid_message_types = $messenger->get_valid_message_types(); |
463 | - if (! in_array($message_type_name, $valid_message_types)) { |
|
463 | + if ( ! in_array($message_type_name, $valid_message_types)) { |
|
464 | 464 | throw new EE_Error( |
465 | 465 | sprintf( |
466 | 466 | __( |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | */ |
587 | 587 | public function ensure_messenger_is_active($messenger_name, $update_option = true) |
588 | 588 | { |
589 | - if (! isset($this->_active_messengers[ $messenger_name ])) { |
|
589 | + if ( ! isset($this->_active_messengers[$messenger_name])) { |
|
590 | 590 | try { |
591 | 591 | $this->activate_messenger($messenger_name, array(), $update_option); |
592 | 592 | } catch (EE_Error $e) { |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | $this->ensure_messenger_is_active($messenger_name, $update_option); |
632 | 632 | } |
633 | 633 | |
634 | - if (! empty($not_installed)) { |
|
634 | + if ( ! empty($not_installed)) { |
|
635 | 635 | EE_Error::add_error( |
636 | 636 | sprintf( |
637 | 637 | __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'), |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | // ensure messenger is active (that's an inherent coupling between active message types and the |
665 | 665 | // messenger they are being activated for. |
666 | 666 | try { |
667 | - if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
667 | + if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
668 | 668 | // all is good so let's just get it active |
669 | 669 | $this->activate_messenger($messenger_name, array($message_type_name), $update_option); |
670 | 670 | } |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | $messenger = $this->messenger_collection()->get_by_info($messenger_name); |
727 | 727 | // it's inactive. Activate it. |
728 | 728 | if ($messenger instanceof EE_messenger) { |
729 | - $this->_active_messengers[ $messenger->name ] = $messenger; |
|
729 | + $this->_active_messengers[$messenger->name] = $messenger; |
|
730 | 730 | // activate incoming message types set to be activated with messenger. |
731 | 731 | $message_type_names = $this->_activate_message_types($messenger, $message_type_names); |
732 | 732 | // setup any initial settings for the messenger if necessary. |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | // generate new templates if necessary and ensure all related templates that are already in the database are |
739 | 739 | // marked active. Note, this will also deactivate a message type for a messenger if the template |
740 | 740 | // cannot be successfully created during its attempt (only happens for global template attempts). |
741 | - if (! empty($message_type_names)) { |
|
741 | + if ( ! empty($message_type_names)) { |
|
742 | 742 | $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true); |
743 | 743 | EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names); |
744 | 744 | } |
@@ -762,13 +762,13 @@ discard block |
||
762 | 762 | // things have never been initialized (which should happen on EEH_Activation::generate_message_templates). |
763 | 763 | // So ONLY then do we need to actually grab defaults and cycle through them. Otherwise we |
764 | 764 | // only override _active_message_types when an explicit array of $message_type_names has been provided. |
765 | - $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[ $messenger->name ]) |
|
765 | + $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name]) |
|
766 | 766 | ? $messenger->get_default_message_types() |
767 | 767 | : (array) $message_type_names; |
768 | 768 | |
769 | 769 | // now we ALWAYS need to make sure that the messenger is active for the message types we're activating! |
770 | - if (! isset($this->_active_message_types[ $messenger->name ])) { |
|
771 | - $this->_active_message_types[ $messenger->name ]['settings'] = array(); |
|
770 | + if ( ! isset($this->_active_message_types[$messenger->name])) { |
|
771 | + $this->_active_message_types[$messenger->name]['settings'] = array(); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | if ($message_type_names) { |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | foreach ($message_type_names as $message_type_name) { |
777 | 777 | // only register the message type as active IF it isn't already active |
778 | 778 | // and if its actually installed. |
779 | - if (! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name) |
|
779 | + if ( ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name) |
|
780 | 780 | ) { |
781 | 781 | $this->add_settings_for_message_type($messenger->name, $message_type_name); |
782 | 782 | $this->_set_messenger_has_activated_message_type( |
@@ -808,16 +808,16 @@ discard block |
||
808 | 808 | if ($message_type instanceof EE_message_type) { |
809 | 809 | $default_settings = $message_type->get_admin_settings_fields(); |
810 | 810 | foreach ($default_settings as $field => $values) { |
811 | - if (isset($new_settings[ $field ])) { |
|
812 | - $existing_settings[ $field ] = $new_settings[ $field ]; |
|
811 | + if (isset($new_settings[$field])) { |
|
812 | + $existing_settings[$field] = $new_settings[$field]; |
|
813 | 813 | continue; |
814 | 814 | } |
815 | - if (! isset($existing_settings[ $field ])) { |
|
816 | - $existing_settings[ $field ] = $values['default']; |
|
815 | + if ( ! isset($existing_settings[$field])) { |
|
816 | + $existing_settings[$field] = $values['default']; |
|
817 | 817 | } |
818 | 818 | } |
819 | 819 | } |
820 | - $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]['settings'] = $existing_settings; |
|
820 | + $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings; |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | |
@@ -840,12 +840,12 @@ discard block |
||
840 | 840 | } |
841 | 841 | |
842 | 842 | // make sure this messenger has a record in the has_activated array |
843 | - if (! isset($this->_has_activated_messengers_and_message_types[ $messenger->name ])) { |
|
844 | - $this->_has_activated_messengers_and_message_types[ $messenger->name ] = array(); |
|
843 | + if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
844 | + $this->_has_activated_messengers_and_message_types[$messenger->name] = array(); |
|
845 | 845 | } |
846 | 846 | // check if message type has already been added |
847 | - if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[ $messenger->name ])) { |
|
848 | - $this->_has_activated_messengers_and_message_types[ $messenger->name ][] = $message_type_name; |
|
847 | + if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
848 | + $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name; |
|
849 | 849 | } |
850 | 850 | } |
851 | 851 | |
@@ -863,16 +863,16 @@ discard block |
||
863 | 863 | $messenger = $this->get_messenger($messenger_name); |
864 | 864 | if ($messenger instanceof EE_messenger) { |
865 | 865 | $msgr_settings = $messenger->get_admin_settings_fields(); |
866 | - if (! empty($msgr_settings)) { |
|
866 | + if ( ! empty($msgr_settings)) { |
|
867 | 867 | foreach ($msgr_settings as $field => $value) { |
868 | 868 | // is there a new setting for this? |
869 | - if (isset($new_settings[ $field ])) { |
|
870 | - $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $new_settings[ $field ]; |
|
869 | + if (isset($new_settings[$field])) { |
|
870 | + $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field]; |
|
871 | 871 | continue; |
872 | 872 | } |
873 | 873 | // only set the default if it isn't already set. |
874 | - if (! isset($this->_active_message_types[ $messenger->name ]['settings'][ $field ])) { |
|
875 | - $this->_active_message_types[ $messenger->name ]['settings'][ $field ] = $value; |
|
874 | + if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) { |
|
875 | + $this->_active_message_types[$messenger->name]['settings'][$field] = $value; |
|
876 | 876 | } |
877 | 877 | } |
878 | 878 | } |
@@ -892,8 +892,8 @@ discard block |
||
892 | 892 | if ($messenger_name instanceof EE_messenger) { |
893 | 893 | $messenger_name = $messenger_name->name; |
894 | 894 | } |
895 | - unset($this->_active_messengers[ $messenger_name ]); |
|
896 | - unset($this->_active_message_types[ $messenger_name ]); |
|
895 | + unset($this->_active_messengers[$messenger_name]); |
|
896 | + unset($this->_active_message_types[$messenger_name]); |
|
897 | 897 | $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name); |
898 | 898 | $this->update_active_messengers_option(); |
899 | 899 | } |
@@ -915,7 +915,7 @@ discard block |
||
915 | 915 | } |
916 | 916 | foreach ($this->_active_message_types as $messenger_name => $settings) { |
917 | 917 | unset( |
918 | - $this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ] |
|
918 | + $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name] |
|
919 | 919 | ); |
920 | 920 | |
921 | 921 | // we always record (even on deactivation) that a message type has been activated because there should at |
@@ -941,7 +941,7 @@ discard block |
||
941 | 941 | { |
942 | 942 | $this->_initialize_collections(); |
943 | 943 | if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
944 | - unset($this->_active_message_types[ $messenger_name ]['settings'][ $messenger_name . '-message_types' ][ $message_type_name ]); |
|
944 | + unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]); |
|
945 | 945 | } |
946 | 946 | $this->_message_template_group_model->deactivate_message_template_groups_for( |
947 | 947 | array($messenger_name), |
@@ -1001,22 +1001,22 @@ discard block |
||
1001 | 1001 | { |
1002 | 1002 | $key = $slugs_only ? 'slugs' : 'all'; |
1003 | 1003 | // check if contexts has been setup yet. |
1004 | - if (empty($this->_contexts[ $key ])) { |
|
1004 | + if (empty($this->_contexts[$key])) { |
|
1005 | 1005 | // So let's get all active message type objects and loop through to get all unique contexts |
1006 | 1006 | foreach ($this->get_active_message_type_objects() as $message_type) { |
1007 | 1007 | if ($message_type instanceof EE_message_type) { |
1008 | 1008 | $message_type_contexts = $message_type->get_contexts(); |
1009 | 1009 | if ($slugs_only) { |
1010 | 1010 | foreach ($message_type_contexts as $context => $context_details) { |
1011 | - $this->_contexts[ $key ][ $context ] = $context_details['label']; |
|
1011 | + $this->_contexts[$key][$context] = $context_details['label']; |
|
1012 | 1012 | } |
1013 | 1013 | } else { |
1014 | - $this->_contexts[ $key ][ $message_type->name ] = $message_type_contexts; |
|
1014 | + $this->_contexts[$key][$message_type->name] = $message_type_contexts; |
|
1015 | 1015 | } |
1016 | 1016 | } |
1017 | 1017 | } |
1018 | 1018 | } |
1019 | - return ! empty($this->_contexts[ $key ]) ? $this->_contexts[ $key ] : array(); |
|
1019 | + return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array(); |
|
1020 | 1020 | } |
1021 | 1021 | |
1022 | 1022 | |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | $all_message_types_valid = true; |
1037 | 1037 | // loop through list of active message types and verify they are installed. |
1038 | 1038 | foreach ($list_of_active_message_type_names as $message_type_name) { |
1039 | - if (! isset($installed_message_types[ $message_type_name ])) { |
|
1039 | + if ( ! isset($installed_message_types[$message_type_name])) { |
|
1040 | 1040 | $this->remove_message_type_has_been_activated_from_all_messengers( |
1041 | 1041 | $message_type_name, |
1042 | 1042 | true |
@@ -1063,8 +1063,8 @@ discard block |
||
1063 | 1063 | public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name) |
1064 | 1064 | { |
1065 | 1065 | $has_activated = $this->get_has_activated_messengers_option(); |
1066 | - return isset($has_activated[ $messenger_name ]) |
|
1067 | - && in_array($message_type_name, $has_activated[ $messenger_name ]); |
|
1066 | + return isset($has_activated[$messenger_name]) |
|
1067 | + && in_array($message_type_name, $has_activated[$messenger_name]); |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | |
@@ -1092,11 +1092,11 @@ discard block |
||
1092 | 1092 | return; |
1093 | 1093 | } |
1094 | 1094 | $has_activated = $this->get_has_activated_messengers_option(); |
1095 | - $key_for_message_type = isset($has_activated[ $messenger_name ]) |
|
1096 | - ? array_search($message_type_name, $has_activated[ $messenger_name ], true) |
|
1095 | + $key_for_message_type = isset($has_activated[$messenger_name]) |
|
1096 | + ? array_search($message_type_name, $has_activated[$messenger_name], true) |
|
1097 | 1097 | : false; |
1098 | 1098 | if ($key_for_message_type !== false) { |
1099 | - unset($has_activated[ $messenger_name ][ $key_for_message_type ]); |
|
1099 | + unset($has_activated[$messenger_name][$key_for_message_type]); |
|
1100 | 1100 | $this->update_has_activated_messengers_option($has_activated); |
1101 | 1101 | // reset the internal cached property |
1102 | 1102 | $this->get_has_activated_messengers_option(true); |
@@ -15,67 +15,67 @@ |
||
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @see parent::get_priority() for documentation. |
|
20 | - * @return int |
|
21 | - */ |
|
22 | - public function get_priority() |
|
23 | - { |
|
24 | - return EEM_Message::priority_high; |
|
25 | - } |
|
18 | + /** |
|
19 | + * @see parent::get_priority() for documentation. |
|
20 | + * @return int |
|
21 | + */ |
|
22 | + public function get_priority() |
|
23 | + { |
|
24 | + return EEM_Message::priority_high; |
|
25 | + } |
|
26 | 26 | |
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * see abstract declaration in parent class for details. |
|
32 | - */ |
|
33 | - protected function _set_admin_pages() |
|
34 | - { |
|
35 | - $this->admin_registered_pages = array( |
|
36 | - 'events_edit' => true |
|
37 | - ); |
|
38 | - } |
|
30 | + /** |
|
31 | + * see abstract declaration in parent class for details. |
|
32 | + */ |
|
33 | + protected function _set_admin_pages() |
|
34 | + { |
|
35 | + $this->admin_registered_pages = array( |
|
36 | + 'events_edit' => true |
|
37 | + ); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | 41 | |
42 | - protected function _set_data_handler() |
|
43 | - { |
|
44 | - $this->_data_handler = 'Gateways'; |
|
45 | - } |
|
42 | + protected function _set_data_handler() |
|
43 | + { |
|
44 | + $this->_data_handler = 'Gateways'; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | - protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
51 | - { |
|
50 | + protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
51 | + { |
|
52 | 52 | |
53 | - // use the registration to get the transaction. |
|
54 | - $transaction = $registration->transaction(); |
|
53 | + // use the registration to get the transaction. |
|
54 | + $transaction = $registration->transaction(); |
|
55 | 55 | |
56 | - // bail early if no transaction |
|
57 | - if (! $transaction instanceof EE_Transaction) { |
|
58 | - throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
|
59 | - } |
|
56 | + // bail early if no transaction |
|
57 | + if (! $transaction instanceof EE_Transaction) { |
|
58 | + throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
|
59 | + } |
|
60 | 60 | |
61 | - $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
61 | + $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
62 | 62 | |
63 | - return array( $transaction, $payment ); |
|
64 | - } |
|
63 | + return array( $transaction, $payment ); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | 67 | |
68 | - protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
|
69 | - { |
|
70 | - // this is just a test |
|
71 | - return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
72 | - } |
|
68 | + protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
|
69 | + { |
|
70 | + // this is just a test |
|
71 | + return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * This message type doesn't need any settings so we are just setting to empty array. |
|
76 | - */ |
|
77 | - protected function _set_admin_settings_fields() |
|
78 | - { |
|
79 | - $this->_admin_settings_fields = array(); |
|
80 | - } |
|
74 | + /** |
|
75 | + * This message type doesn't need any settings so we are just setting to empty array. |
|
76 | + */ |
|
77 | + protected function _set_admin_settings_fields() |
|
78 | + { |
|
79 | + $this->_admin_settings_fields = array(); |
|
80 | + } |
|
81 | 81 | } |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | $transaction = $registration->transaction(); |
55 | 55 | |
56 | 56 | // bail early if no transaction |
57 | - if (! $transaction instanceof EE_Transaction) { |
|
57 | + if ( ! $transaction instanceof EE_Transaction) { |
|
58 | 58 | throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
59 | 59 | } |
60 | 60 | |
61 | - $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
61 | + $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0; |
|
62 | 62 | |
63 | - return array( $transaction, $payment ); |
|
63 | + return array($transaction, $payment); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
69 | 69 | { |
70 | 70 | // this is just a test |
71 | - return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
71 | + return $this->name.' Message Type for '.$messenger->name.' Messenger '; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -14,126 +14,126 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @see parent::get_priority() for documentation. |
|
19 | - * @return int |
|
20 | - */ |
|
21 | - public function get_priority() |
|
22 | - { |
|
23 | - return EEM_Message::priority_medium; |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - |
|
28 | - protected function _set_admin_pages() |
|
29 | - { |
|
30 | - $this->admin_registered_pages = array( |
|
31 | - 'events_edit' => true |
|
32 | - ); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
|
37 | - { |
|
38 | - // this is just a test |
|
39 | - return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - protected function _set_data_handler() |
|
46 | - { |
|
47 | - if (is_array($this->_data)) { |
|
48 | - $data_type = reset($this->_data); |
|
49 | - |
|
50 | - if (is_array($data_type)) { |
|
51 | - // grab the first item and see if its a registration. |
|
52 | - $maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type); |
|
53 | - if ($maybe_reg instanceof EE_Registration) { |
|
54 | - // is $data_type itself just an array of registrations? |
|
55 | - if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) { |
|
56 | - $regs = $data_type; |
|
57 | - } else { |
|
58 | - $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg ); |
|
59 | - } |
|
60 | - |
|
61 | - foreach ($regs as $reg) { |
|
62 | - if ($reg instanceof EE_Registration) { |
|
63 | - $this->_regs_for_sending[] = $reg->ID(); |
|
64 | - } |
|
65 | - } |
|
66 | - $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() ); |
|
67 | - $this->_data_handler = 'Gateways'; |
|
68 | - } else { |
|
69 | - $this->_data_handler = 'Gateways'; |
|
70 | - } |
|
71 | - } else { |
|
72 | - $this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
73 | - } |
|
74 | - } else { |
|
75 | - $this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
76 | - } |
|
77 | - |
|
78 | - $this->_single_message = $this->_data_handler == 'REG' ? true : false; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
84 | - { |
|
85 | - if ($context == 'admin') { |
|
86 | - // use the registration to get the transaction. |
|
87 | - $transaction = $registration->transaction(); |
|
88 | - |
|
89 | - // bail early if no transaction |
|
90 | - if (! $transaction instanceof EE_Transaction) { |
|
91 | - throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
|
92 | - } |
|
93 | - |
|
94 | - $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
95 | - return array( $transaction, $payment ); |
|
96 | - } else { |
|
97 | - return $registration; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Setup admin settings for this message type. |
|
105 | - */ |
|
106 | - protected function _set_admin_settings_fields() |
|
107 | - { |
|
108 | - $this->_admin_settings_fields = array(); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * returns an array of addressee objects for event_admins |
|
117 | - * |
|
118 | - * @access protected |
|
119 | - * @return array array of EE_Messages_Addressee objects |
|
120 | - */ |
|
121 | - protected function _admin_addressees() |
|
122 | - { |
|
123 | - if ($this->_single_message) { |
|
124 | - return array(); |
|
125 | - } |
|
126 | - return parent::_admin_addressees(); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - protected function _primary_attendee_addressees() |
|
132 | - { |
|
133 | - if ($this->_single_message) { |
|
134 | - return array(); |
|
135 | - } |
|
136 | - |
|
137 | - return parent::_primary_attendee_addressees(); |
|
138 | - } |
|
17 | + /** |
|
18 | + * @see parent::get_priority() for documentation. |
|
19 | + * @return int |
|
20 | + */ |
|
21 | + public function get_priority() |
|
22 | + { |
|
23 | + return EEM_Message::priority_medium; |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + |
|
28 | + protected function _set_admin_pages() |
|
29 | + { |
|
30 | + $this->admin_registered_pages = array( |
|
31 | + 'events_edit' => true |
|
32 | + ); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
|
37 | + { |
|
38 | + // this is just a test |
|
39 | + return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + protected function _set_data_handler() |
|
46 | + { |
|
47 | + if (is_array($this->_data)) { |
|
48 | + $data_type = reset($this->_data); |
|
49 | + |
|
50 | + if (is_array($data_type)) { |
|
51 | + // grab the first item and see if its a registration. |
|
52 | + $maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type); |
|
53 | + if ($maybe_reg instanceof EE_Registration) { |
|
54 | + // is $data_type itself just an array of registrations? |
|
55 | + if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) { |
|
56 | + $regs = $data_type; |
|
57 | + } else { |
|
58 | + $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg ); |
|
59 | + } |
|
60 | + |
|
61 | + foreach ($regs as $reg) { |
|
62 | + if ($reg instanceof EE_Registration) { |
|
63 | + $this->_regs_for_sending[] = $reg->ID(); |
|
64 | + } |
|
65 | + } |
|
66 | + $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() ); |
|
67 | + $this->_data_handler = 'Gateways'; |
|
68 | + } else { |
|
69 | + $this->_data_handler = 'Gateways'; |
|
70 | + } |
|
71 | + } else { |
|
72 | + $this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
73 | + } |
|
74 | + } else { |
|
75 | + $this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
76 | + } |
|
77 | + |
|
78 | + $this->_single_message = $this->_data_handler == 'REG' ? true : false; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
84 | + { |
|
85 | + if ($context == 'admin') { |
|
86 | + // use the registration to get the transaction. |
|
87 | + $transaction = $registration->transaction(); |
|
88 | + |
|
89 | + // bail early if no transaction |
|
90 | + if (! $transaction instanceof EE_Transaction) { |
|
91 | + throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
|
92 | + } |
|
93 | + |
|
94 | + $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
95 | + return array( $transaction, $payment ); |
|
96 | + } else { |
|
97 | + return $registration; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Setup admin settings for this message type. |
|
105 | + */ |
|
106 | + protected function _set_admin_settings_fields() |
|
107 | + { |
|
108 | + $this->_admin_settings_fields = array(); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * returns an array of addressee objects for event_admins |
|
117 | + * |
|
118 | + * @access protected |
|
119 | + * @return array array of EE_Messages_Addressee objects |
|
120 | + */ |
|
121 | + protected function _admin_addressees() |
|
122 | + { |
|
123 | + if ($this->_single_message) { |
|
124 | + return array(); |
|
125 | + } |
|
126 | + return parent::_admin_addressees(); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + protected function _primary_attendee_addressees() |
|
132 | + { |
|
133 | + if ($this->_single_message) { |
|
134 | + return array(); |
|
135 | + } |
|
136 | + |
|
137 | + return parent::_primary_attendee_addressees(); |
|
138 | + } |
|
139 | 139 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
37 | 37 | { |
38 | 38 | // this is just a test |
39 | - return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
39 | + return $this->name.' Message Type for '.$messenger->name.' Messenger '; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) { |
56 | 56 | $regs = $data_type; |
57 | 57 | } else { |
58 | - $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg ); |
|
58 | + $regs = is_array($data_type[0]) ? $data_type[0] : array($maybe_reg); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | foreach ($regs as $reg) { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $this->_regs_for_sending[] = $reg->ID(); |
64 | 64 | } |
65 | 65 | } |
66 | - $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() ); |
|
66 | + $this->_data = isset($this->_data[1]) ? array($maybe_reg->transaction(), null, $this->_data[1]) : array($maybe_reg->transaction()); |
|
67 | 67 | $this->_data_handler = 'Gateways'; |
68 | 68 | } else { |
69 | 69 | $this->_data_handler = 'Gateways'; |
@@ -82,17 +82,17 @@ discard block |
||
82 | 82 | |
83 | 83 | protected function _get_data_for_context($context, EE_Registration $registration, $id) |
84 | 84 | { |
85 | - if ($context == 'admin') { |
|
85 | + if ($context == 'admin') { |
|
86 | 86 | // use the registration to get the transaction. |
87 | 87 | $transaction = $registration->transaction(); |
88 | 88 | |
89 | 89 | // bail early if no transaction |
90 | - if (! $transaction instanceof EE_Transaction) { |
|
90 | + if ( ! $transaction instanceof EE_Transaction) { |
|
91 | 91 | throw new EE_Error(__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
92 | 92 | } |
93 | 93 | |
94 | - $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
95 | - return array( $transaction, $payment ); |
|
94 | + $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0; |
|
95 | + return array($transaction, $payment); |
|
96 | 96 | } else { |
97 | 97 | return $registration; |
98 | 98 | } |
@@ -15,50 +15,50 @@ |
||
15 | 15 | class EE_Payment_Refund_message_type extends EE_Payment_Base_message_type |
16 | 16 | { |
17 | 17 | |
18 | - public function __construct() |
|
19 | - { |
|
18 | + public function __construct() |
|
19 | + { |
|
20 | 20 | |
21 | - // setup type details for reference |
|
22 | - $this->name = 'payment_refund'; |
|
23 | - $this->description = __('This message type is used for all payment notification messages that go out for refunds.', 'event_espresso'); |
|
24 | - $this->label = array( |
|
25 | - 'singular' => __('refund issued', 'event_espresso'), |
|
26 | - 'plural' => __('refunds issued', 'event_espresso') |
|
27 | - ); |
|
21 | + // setup type details for reference |
|
22 | + $this->name = 'payment_refund'; |
|
23 | + $this->description = __('This message type is used for all payment notification messages that go out for refunds.', 'event_espresso'); |
|
24 | + $this->label = array( |
|
25 | + 'singular' => __('refund issued', 'event_espresso'), |
|
26 | + 'plural' => __('refunds issued', 'event_espresso') |
|
27 | + ); |
|
28 | 28 | |
29 | - $this->_master_templates = array( |
|
30 | - 'email' => 'payment' |
|
31 | - ); |
|
29 | + $this->_master_templates = array( |
|
30 | + 'email' => 'payment' |
|
31 | + ); |
|
32 | 32 | |
33 | - parent::__construct(); |
|
34 | - } |
|
33 | + parent::__construct(); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * _set_contexts |
|
40 | - * This sets up the contexts associated with the message_type |
|
41 | - * |
|
42 | - * @access protected |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - protected function _set_contexts() |
|
46 | - { |
|
47 | - $this->_context_label = array( |
|
48 | - 'label' => __('recipient', 'event_espresso'), |
|
49 | - 'plural' => __('recipients', 'event_espresso'), |
|
50 | - 'description' => __('Recipient\'s are who will receive the template. You may want different payment details sent out depending on who the recipient is', 'event_espresso') |
|
51 | - ); |
|
38 | + /** |
|
39 | + * _set_contexts |
|
40 | + * This sets up the contexts associated with the message_type |
|
41 | + * |
|
42 | + * @access protected |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + protected function _set_contexts() |
|
46 | + { |
|
47 | + $this->_context_label = array( |
|
48 | + 'label' => __('recipient', 'event_espresso'), |
|
49 | + 'plural' => __('recipients', 'event_espresso'), |
|
50 | + 'description' => __('Recipient\'s are who will receive the template. You may want different payment details sent out depending on who the recipient is', 'event_espresso') |
|
51 | + ); |
|
52 | 52 | |
53 | - $this->_contexts = array( |
|
54 | - 'admin' => array( |
|
55 | - 'label' => __('Event Admin', 'event_espresso'), |
|
56 | - 'description' => __('This template is what event administrators will receive on a successful refund.', 'event_espresso') |
|
57 | - ), |
|
58 | - 'primary_attendee' => array( |
|
59 | - 'label' => __('Primary Registrant', 'event_espresso'), |
|
60 | - 'description' => __('This template is what the primary registrant (the person who made the main registration) will receive on successful refund.', 'event_espresso') |
|
61 | - ) |
|
62 | - ); |
|
63 | - } |
|
53 | + $this->_contexts = array( |
|
54 | + 'admin' => array( |
|
55 | + 'label' => __('Event Admin', 'event_espresso'), |
|
56 | + 'description' => __('This template is what event administrators will receive on a successful refund.', 'event_espresso') |
|
57 | + ), |
|
58 | + 'primary_attendee' => array( |
|
59 | + 'label' => __('Primary Registrant', 'event_espresso'), |
|
60 | + 'description' => __('This template is what the primary registrant (the person who made the main registration) will receive on successful refund.', 'event_espresso') |
|
61 | + ) |
|
62 | + ); |
|
63 | + } |
|
64 | 64 | } |
@@ -14,48 +14,48 @@ |
||
14 | 14 | class EE_Registration_message_type extends EE_Registration_Base_message_type |
15 | 15 | { |
16 | 16 | |
17 | - public function __construct() |
|
18 | - { |
|
19 | - $this->name = 'registration'; |
|
20 | - $this->description = __('This message type is for messages sent to attendees when their registration is approved.', 'event_espresso'); |
|
21 | - $this->label = array( |
|
22 | - 'singular' => __('registration approved', 'event_espresso'), |
|
23 | - 'plural' => __('registrations approved', 'event_espresso') |
|
24 | - ); |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + $this->name = 'registration'; |
|
20 | + $this->description = __('This message type is for messages sent to attendees when their registration is approved.', 'event_espresso'); |
|
21 | + $this->label = array( |
|
22 | + 'singular' => __('registration approved', 'event_espresso'), |
|
23 | + 'plural' => __('registrations approved', 'event_espresso') |
|
24 | + ); |
|
25 | 25 | |
26 | - parent::__construct(); |
|
27 | - } |
|
26 | + parent::__construct(); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * _set_contexts |
|
33 | - * This sets up the contexts associated with the message_type |
|
34 | - * |
|
35 | - * @access protected |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - protected function _set_contexts() |
|
39 | - { |
|
40 | - $this->_context_label = array( |
|
41 | - 'label' => __('recipient', 'event_espresso'), |
|
42 | - 'plural' => __('recipients', 'event_espresso'), |
|
43 | - 'description' => __('Recipient\'s are who will receive the template. You may want different registration details sent out depending on who the recipient is', 'event_espresso') |
|
44 | - ); |
|
31 | + /** |
|
32 | + * _set_contexts |
|
33 | + * This sets up the contexts associated with the message_type |
|
34 | + * |
|
35 | + * @access protected |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + protected function _set_contexts() |
|
39 | + { |
|
40 | + $this->_context_label = array( |
|
41 | + 'label' => __('recipient', 'event_espresso'), |
|
42 | + 'plural' => __('recipients', 'event_espresso'), |
|
43 | + 'description' => __('Recipient\'s are who will receive the template. You may want different registration details sent out depending on who the recipient is', 'event_espresso') |
|
44 | + ); |
|
45 | 45 | |
46 | - $this->_contexts = array( |
|
47 | - 'admin' => array( |
|
48 | - 'label' => __('Event Admin', 'event_espresso'), |
|
49 | - 'description' => __('This template is what event administrators will receive with an approved registration', 'event_espresso') |
|
50 | - ), |
|
51 | - 'primary_attendee' => array( |
|
52 | - 'label' => __('Primary Registrant', 'event_espresso'), |
|
53 | - 'description' => __('This template is what the primary registrant (the person who completed the initial transaction) will receive with approved registration', 'event_espresso') |
|
54 | - ), |
|
55 | - 'attendee' => array( |
|
56 | - 'label' => __('Registrant', 'event_espresso'), |
|
57 | - 'description' => __('This template is what each registrant for the event will receive when their registration is approved.', 'event_espresso') |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
46 | + $this->_contexts = array( |
|
47 | + 'admin' => array( |
|
48 | + 'label' => __('Event Admin', 'event_espresso'), |
|
49 | + 'description' => __('This template is what event administrators will receive with an approved registration', 'event_espresso') |
|
50 | + ), |
|
51 | + 'primary_attendee' => array( |
|
52 | + 'label' => __('Primary Registrant', 'event_espresso'), |
|
53 | + 'description' => __('This template is what the primary registrant (the person who completed the initial transaction) will receive with approved registration', 'event_espresso') |
|
54 | + ), |
|
55 | + 'attendee' => array( |
|
56 | + 'label' => __('Registrant', 'event_espresso'), |
|
57 | + 'description' => __('This template is what each registrant for the event will receive when their registration is approved.', 'event_espresso') |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | } |
@@ -14,60 +14,60 @@ |
||
14 | 14 | class EE_Not_Approved_Registration_message_type extends EE_Registration_Base_message_type |
15 | 15 | { |
16 | 16 | |
17 | - public function __construct() |
|
18 | - { |
|
19 | - $this->name = 'not_approved_registration'; |
|
20 | - $this->description = __('This message type is for messages sent to registrants when their registration is set to the not approved status.', 'event_espresso'); |
|
21 | - $this->label = array( |
|
22 | - 'singular' => __('not approved registration', 'event_espresso'), |
|
23 | - 'plural' => __('not approved registrations', 'event_espresso') |
|
24 | - ); |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + $this->name = 'not_approved_registration'; |
|
20 | + $this->description = __('This message type is for messages sent to registrants when their registration is set to the not approved status.', 'event_espresso'); |
|
21 | + $this->label = array( |
|
22 | + 'singular' => __('not approved registration', 'event_espresso'), |
|
23 | + 'plural' => __('not approved registrations', 'event_espresso') |
|
24 | + ); |
|
25 | 25 | |
26 | - $this->_master_templates = array( |
|
27 | - 'email' => 'registration' |
|
28 | - ); |
|
26 | + $this->_master_templates = array( |
|
27 | + 'email' => 'registration' |
|
28 | + ); |
|
29 | 29 | |
30 | - parent::__construct(); |
|
31 | - } |
|
30 | + parent::__construct(); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * _set_contexts |
|
38 | - * This sets up the contexts associated with the message_type |
|
39 | - * |
|
40 | - * @access protected |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - protected function _set_contexts() |
|
44 | - { |
|
45 | - $this->_context_label = array( |
|
46 | - 'label' => __('recipient', 'event_espresso'), |
|
47 | - 'plural' => __('recipients', 'event_espresso'), |
|
48 | - 'description' => __('Recipient\'s are who will receive the template. You may want different registration details sent out depending on who the recipient is', 'event_espresso') |
|
49 | - ); |
|
36 | + /** |
|
37 | + * _set_contexts |
|
38 | + * This sets up the contexts associated with the message_type |
|
39 | + * |
|
40 | + * @access protected |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + protected function _set_contexts() |
|
44 | + { |
|
45 | + $this->_context_label = array( |
|
46 | + 'label' => __('recipient', 'event_espresso'), |
|
47 | + 'plural' => __('recipients', 'event_espresso'), |
|
48 | + 'description' => __('Recipient\'s are who will receive the template. You may want different registration details sent out depending on who the recipient is', 'event_espresso') |
|
49 | + ); |
|
50 | 50 | |
51 | - $this->_contexts = array( |
|
52 | - 'admin' => array( |
|
53 | - 'label' => __('Event Admin', 'event_espresso'), |
|
54 | - 'description' => __('This template is what event administrators will receive when registration status is set to not approved.', 'event_espresso') |
|
55 | - ), |
|
56 | - 'primary_attendee' => array( |
|
57 | - 'label' => __('Primary Registrant', 'event_espresso'), |
|
58 | - 'description' => __('This template is what the primary registrant (the person who completed the initial transaction) will receive when the registration status is not approved.', 'event_espresso') |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
51 | + $this->_contexts = array( |
|
52 | + 'admin' => array( |
|
53 | + 'label' => __('Event Admin', 'event_espresso'), |
|
54 | + 'description' => __('This template is what event administrators will receive when registration status is set to not approved.', 'event_espresso') |
|
55 | + ), |
|
56 | + 'primary_attendee' => array( |
|
57 | + 'label' => __('Primary Registrant', 'event_espresso'), |
|
58 | + 'description' => __('This template is what the primary registrant (the person who completed the initial transaction) will receive when the registration status is not approved.', 'event_espresso') |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | - protected function _primary_attendee_addressees() |
|
66 | - { |
|
67 | - $cached = $this->_single_message; |
|
68 | - $this->_single_message = false; |
|
69 | - $addressees = parent::_primary_attendee_addressees(); |
|
70 | - $this->_single_message = $cached; |
|
71 | - return $addressees; |
|
72 | - } |
|
65 | + protected function _primary_attendee_addressees() |
|
66 | + { |
|
67 | + $cached = $this->_single_message; |
|
68 | + $this->_single_message = false; |
|
69 | + $addressees = parent::_primary_attendee_addressees(); |
|
70 | + $this->_single_message = $cached; |
|
71 | + return $addressees; |
|
72 | + } |
|
73 | 73 | } |
@@ -16,59 +16,59 @@ |
||
16 | 16 | class EE_Registration_Summary_message_type extends EE_Registration_Base_message_type |
17 | 17 | { |
18 | 18 | |
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->name = 'registration_summary'; |
|
22 | - $this->description = __('This message type provides a summary notification to Primary Registrants and Admin recipients when there are multiple registrations in a transaction with different statuses.', 'event_espresso'); |
|
23 | - $this->label = array( |
|
24 | - 'singular' => __('registration multi-status summary', 'event_espresso'), |
|
25 | - 'plural' => __('registrations multi-status summary', 'event_espresso') |
|
26 | - ); |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->name = 'registration_summary'; |
|
22 | + $this->description = __('This message type provides a summary notification to Primary Registrants and Admin recipients when there are multiple registrations in a transaction with different statuses.', 'event_espresso'); |
|
23 | + $this->label = array( |
|
24 | + 'singular' => __('registration multi-status summary', 'event_espresso'), |
|
25 | + 'plural' => __('registrations multi-status summary', 'event_espresso') |
|
26 | + ); |
|
27 | 27 | |
28 | - $this->_master_templates = array( |
|
29 | - 'email' => 'registration' |
|
30 | - ); |
|
28 | + $this->_master_templates = array( |
|
29 | + 'email' => 'registration' |
|
30 | + ); |
|
31 | 31 | |
32 | - parent::__construct(); |
|
33 | - } |
|
32 | + parent::__construct(); |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * _set_contexts |
|
39 | - * This sets up the contexts associated with the message_type |
|
40 | - * |
|
41 | - * @access protected |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - protected function _set_contexts() |
|
45 | - { |
|
46 | - $this->_context_label = array( |
|
47 | - 'label' => __('recipient', 'event_espresso'), |
|
48 | - 'plural' => __('recipients', 'event_espresso'), |
|
49 | - 'description' => __('Recipient\'s are who will receive the template. You may want different details sent out depending on who the recipient is. To "turn off" a recipient from receiving message, simply remove any content from the "to" field in the template.', 'event_espresso') |
|
50 | - ); |
|
37 | + /** |
|
38 | + * _set_contexts |
|
39 | + * This sets up the contexts associated with the message_type |
|
40 | + * |
|
41 | + * @access protected |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + protected function _set_contexts() |
|
45 | + { |
|
46 | + $this->_context_label = array( |
|
47 | + 'label' => __('recipient', 'event_espresso'), |
|
48 | + 'plural' => __('recipients', 'event_espresso'), |
|
49 | + 'description' => __('Recipient\'s are who will receive the template. You may want different details sent out depending on who the recipient is. To "turn off" a recipient from receiving message, simply remove any content from the "to" field in the template.', 'event_espresso') |
|
50 | + ); |
|
51 | 51 | |
52 | - $this->_contexts = array( |
|
53 | - 'admin' => array( |
|
54 | - 'label' => __('Event Admin', 'event_espresso'), |
|
55 | - 'description' => __('This template is what event administrators will receive when a transaction is finalized that has registrations with multiple different statuses.', 'event_espresso') |
|
56 | - ), |
|
57 | - 'primary_attendee' => array( |
|
58 | - 'label' => __('Primary Registrant', 'event_espresso'), |
|
59 | - 'description' => __('This template is what the primary registrant (the person who completed the initial transaction) will receive when the transaction completed has registrations with different statuses. By default it is a summary email of all registrations for all events on the transaction and their status.', 'event_espresso') |
|
60 | - ) |
|
61 | - ); |
|
62 | - } |
|
52 | + $this->_contexts = array( |
|
53 | + 'admin' => array( |
|
54 | + 'label' => __('Event Admin', 'event_espresso'), |
|
55 | + 'description' => __('This template is what event administrators will receive when a transaction is finalized that has registrations with multiple different statuses.', 'event_espresso') |
|
56 | + ), |
|
57 | + 'primary_attendee' => array( |
|
58 | + 'label' => __('Primary Registrant', 'event_espresso'), |
|
59 | + 'description' => __('This template is what the primary registrant (the person who completed the initial transaction) will receive when the transaction completed has registrations with different statuses. By default it is a summary email of all registrations for all events on the transaction and their status.', 'event_espresso') |
|
60 | + ) |
|
61 | + ); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | - protected function _primary_attendee_addressees() |
|
67 | - { |
|
68 | - $cached = $this->_single_message; |
|
69 | - $this->_single_message = false; |
|
70 | - $addressees = parent::_primary_attendee_addressees(); |
|
71 | - $this->_single_message = $cached; |
|
72 | - return $addressees; |
|
73 | - } |
|
66 | + protected function _primary_attendee_addressees() |
|
67 | + { |
|
68 | + $cached = $this->_single_message; |
|
69 | + $this->_single_message = false; |
|
70 | + $addressees = parent::_primary_attendee_addressees(); |
|
71 | + $this->_single_message = $cached; |
|
72 | + return $addressees; |
|
73 | + } |
|
74 | 74 | } |
@@ -14,44 +14,44 @@ |
||
14 | 14 | class EE_Payment_message_type extends EE_Payment_Base_message_type |
15 | 15 | { |
16 | 16 | |
17 | - public function __construct() |
|
18 | - { |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | 19 | |
20 | - // setup type details for reference |
|
21 | - $this->name = 'payment'; |
|
22 | - $this->description = __('This message type is used for all payment notification messages that go out including any manual payments entered by an event administrator.', 'event_espresso'); |
|
23 | - $this->label = array( |
|
24 | - 'singular' => __('payment received', 'event_espresso'), |
|
25 | - 'plural' => __('payments received', 'event_espresso') |
|
26 | - ); |
|
20 | + // setup type details for reference |
|
21 | + $this->name = 'payment'; |
|
22 | + $this->description = __('This message type is used for all payment notification messages that go out including any manual payments entered by an event administrator.', 'event_espresso'); |
|
23 | + $this->label = array( |
|
24 | + 'singular' => __('payment received', 'event_espresso'), |
|
25 | + 'plural' => __('payments received', 'event_espresso') |
|
26 | + ); |
|
27 | 27 | |
28 | - parent::__construct(); |
|
29 | - } |
|
28 | + parent::__construct(); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * _set_contexts |
|
33 | - * This sets up the contexts associated with the message_type |
|
34 | - * |
|
35 | - * @access protected |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - protected function _set_contexts() |
|
39 | - { |
|
40 | - $this->_context_label = array( |
|
41 | - 'label' => __('recipient', 'event_espresso'), |
|
42 | - 'plural' => __('recipients', 'event_espresso'), |
|
43 | - 'description' => __('Recipient\'s are who will receive the template. You may want different payment details sent out depending on who the recipient is', 'event_espresso') |
|
44 | - ); |
|
31 | + /** |
|
32 | + * _set_contexts |
|
33 | + * This sets up the contexts associated with the message_type |
|
34 | + * |
|
35 | + * @access protected |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + protected function _set_contexts() |
|
39 | + { |
|
40 | + $this->_context_label = array( |
|
41 | + 'label' => __('recipient', 'event_espresso'), |
|
42 | + 'plural' => __('recipients', 'event_espresso'), |
|
43 | + 'description' => __('Recipient\'s are who will receive the template. You may want different payment details sent out depending on who the recipient is', 'event_espresso') |
|
44 | + ); |
|
45 | 45 | |
46 | - $this->_contexts = array( |
|
47 | - 'admin' => array( |
|
48 | - 'label' => __('Event Admin', 'event_espresso'), |
|
49 | - 'description' => __('This template is what event administrators will receive on a successful payment', 'event_espresso') |
|
50 | - ), |
|
51 | - 'primary_attendee' => array( |
|
52 | - 'label' => __('Primary Registrant', 'event_espresso'), |
|
53 | - 'description' => __('This template is what the primary registrant (the person who made the main registration) will receive on successful payment', 'event_espresso') |
|
54 | - ) |
|
55 | - ); |
|
56 | - } |
|
46 | + $this->_contexts = array( |
|
47 | + 'admin' => array( |
|
48 | + 'label' => __('Event Admin', 'event_espresso'), |
|
49 | + 'description' => __('This template is what event administrators will receive on a successful payment', 'event_espresso') |
|
50 | + ), |
|
51 | + 'primary_attendee' => array( |
|
52 | + 'label' => __('Primary Registrant', 'event_espresso'), |
|
53 | + 'description' => __('This template is what the primary registrant (the person who made the main registration) will receive on successful payment', 'event_espresso') |
|
54 | + ) |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | } |
@@ -13,123 +13,123 @@ |
||
13 | 13 | class EE_Invoice_message_type extends EE_message_type |
14 | 14 | { |
15 | 15 | |
16 | - public function __construct() |
|
17 | - { |
|
18 | - $this->name = 'invoice'; |
|
19 | - $this->description = __('The invoice message type is triggered via a url on the thank you page and via at url generated by the [INVOICE_URL] or [INVOICE_LINK] shortcode.', 'event_espresso'); |
|
20 | - $this->label = array( |
|
21 | - 'singular' => __('invoice', 'event_espresso'), |
|
22 | - 'plural' => __('invoices', 'event_espresso') |
|
23 | - ); |
|
24 | - $this->_master_templates = array(); |
|
25 | - parent::__construct(); |
|
26 | - } |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + $this->name = 'invoice'; |
|
19 | + $this->description = __('The invoice message type is triggered via a url on the thank you page and via at url generated by the [INVOICE_URL] or [INVOICE_LINK] shortcode.', 'event_espresso'); |
|
20 | + $this->label = array( |
|
21 | + 'singular' => __('invoice', 'event_espresso'), |
|
22 | + 'plural' => __('invoices', 'event_espresso') |
|
23 | + ); |
|
24 | + $this->_master_templates = array(); |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @see parent::get_priority() for documentation. |
|
32 | - * @return int |
|
33 | - */ |
|
34 | - public function get_priority() |
|
35 | - { |
|
36 | - return EEM_Message::priority_high; |
|
37 | - } |
|
30 | + /** |
|
31 | + * @see parent::get_priority() for documentation. |
|
32 | + * @return int |
|
33 | + */ |
|
34 | + public function get_priority() |
|
35 | + { |
|
36 | + return EEM_Message::priority_high; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * This method returns whether this message type should always generate a new copy |
|
42 | - * when requested, or if links can be to the already generated copy. |
|
43 | - * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table. |
|
44 | - * Invoices always generate. |
|
45 | - * @return bool false means can link to generated EE_Message. true must regenerate. |
|
46 | - */ |
|
47 | - public function always_generate() |
|
48 | - { |
|
49 | - return true; |
|
50 | - } |
|
40 | + /** |
|
41 | + * This method returns whether this message type should always generate a new copy |
|
42 | + * when requested, or if links can be to the already generated copy. |
|
43 | + * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table. |
|
44 | + * Invoices always generate. |
|
45 | + * @return bool false means can link to generated EE_Message. true must regenerate. |
|
46 | + */ |
|
47 | + public function always_generate() |
|
48 | + { |
|
49 | + return true; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - protected function _set_admin_pages() |
|
54 | - { |
|
55 | - $this->admin_registered_pages = array( 'events_edit' => true ); |
|
56 | - } |
|
53 | + protected function _set_admin_pages() |
|
54 | + { |
|
55 | + $this->admin_registered_pages = array( 'events_edit' => true ); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | 59 | |
60 | - protected function _set_data_handler() |
|
61 | - { |
|
62 | - $this->_data_handler = 'Gateways'; |
|
63 | - } |
|
60 | + protected function _set_data_handler() |
|
61 | + { |
|
62 | + $this->_data_handler = 'Gateways'; |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | 66 | |
67 | - protected function _set_with_messengers() |
|
68 | - { |
|
69 | - $this->_with_messengers = array( |
|
70 | - 'html' => array( 'pdf' ) |
|
71 | - ); |
|
72 | - } |
|
67 | + protected function _set_with_messengers() |
|
68 | + { |
|
69 | + $this->_with_messengers = array( |
|
70 | + 'html' => array( 'pdf' ) |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | 75 | |
76 | - protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
77 | - { |
|
78 | - // receipt message type data handler is 'Gateways' and it expects a transaction object. |
|
79 | - $transaction = $registration->transaction(); |
|
80 | - if ($transaction instanceof EE_Transaction) { |
|
81 | - return array( $transaction ); |
|
82 | - } |
|
83 | - return array(); |
|
84 | - } |
|
76 | + protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
77 | + { |
|
78 | + // receipt message type data handler is 'Gateways' and it expects a transaction object. |
|
79 | + $transaction = $registration->transaction(); |
|
80 | + if ($transaction instanceof EE_Transaction) { |
|
81 | + return array( $transaction ); |
|
82 | + } |
|
83 | + return array(); |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | 87 | |
88 | - protected function _set_admin_settings_fields() |
|
89 | - { |
|
90 | - $this->_admin_settings_fields = array(); |
|
91 | - } |
|
88 | + protected function _set_admin_settings_fields() |
|
89 | + { |
|
90 | + $this->_admin_settings_fields = array(); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | 94 | |
95 | - protected function _set_contexts() |
|
96 | - { |
|
97 | - $this->_context_label = array( |
|
98 | - 'label' => __('recipient', 'event_espresso'), |
|
99 | - 'plural' => __('recipients', 'event_espresso'), |
|
100 | - 'description' => __('Recipient\'s are who will view the invoice.', 'event_espresso') |
|
101 | - ); |
|
95 | + protected function _set_contexts() |
|
96 | + { |
|
97 | + $this->_context_label = array( |
|
98 | + 'label' => __('recipient', 'event_espresso'), |
|
99 | + 'plural' => __('recipients', 'event_espresso'), |
|
100 | + 'description' => __('Recipient\'s are who will view the invoice.', 'event_espresso') |
|
101 | + ); |
|
102 | 102 | |
103 | - $this->_contexts = array( |
|
104 | - 'purchaser' => array( |
|
105 | - 'label' => __('Purchaser', 'event_espresso'), |
|
106 | - 'description' => __('This template goes to the person who conducted the transaction.', 'event_espresso') |
|
107 | - ) |
|
108 | - ); |
|
109 | - } |
|
103 | + $this->_contexts = array( |
|
104 | + 'purchaser' => array( |
|
105 | + 'label' => __('Purchaser', 'event_espresso'), |
|
106 | + 'description' => __('This template goes to the person who conducted the transaction.', 'event_espresso') |
|
107 | + ) |
|
108 | + ); |
|
109 | + } |
|
110 | 110 | |
111 | 111 | |
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * used to set the valid shortcodes for the receipt message type |
|
116 | - * |
|
117 | - * @since 4.5.0 |
|
118 | - * |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - protected function _set_valid_shortcodes() |
|
122 | - { |
|
123 | - $this->_valid_shortcodes['purchaser'] = array( |
|
124 | - 'attendee_list', 'attendee', 'datetime_list', 'datetime', 'event_list', 'event', 'event_meta', 'messenger', 'organization', 'primary_registration_list', 'primary_registration_details', 'ticket_list', 'ticket', 'transaction', 'venue', 'line_item_list', 'payment_list', 'line_item', 'payment' |
|
125 | - ); |
|
126 | - } |
|
114 | + /** |
|
115 | + * used to set the valid shortcodes for the receipt message type |
|
116 | + * |
|
117 | + * @since 4.5.0 |
|
118 | + * |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + protected function _set_valid_shortcodes() |
|
122 | + { |
|
123 | + $this->_valid_shortcodes['purchaser'] = array( |
|
124 | + 'attendee_list', 'attendee', 'datetime_list', 'datetime', 'event_list', 'event', 'event_meta', 'messenger', 'organization', 'primary_registration_list', 'primary_registration_details', 'ticket_list', 'ticket', 'transaction', 'venue', 'line_item_list', 'payment_list', 'line_item', 'payment' |
|
125 | + ); |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | 129 | |
130 | 130 | |
131 | - protected function _purchaser_addressees() |
|
132 | - { |
|
133 | - return parent::_primary_attendee_addressees(); |
|
134 | - } |
|
131 | + protected function _purchaser_addressees() |
|
132 | + { |
|
133 | + return parent::_primary_attendee_addressees(); |
|
134 | + } |
|
135 | 135 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | protected function _set_admin_pages() |
54 | 54 | { |
55 | - $this->admin_registered_pages = array( 'events_edit' => true ); |
|
55 | + $this->admin_registered_pages = array('events_edit' => true); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | protected function _set_with_messengers() |
68 | 68 | { |
69 | 69 | $this->_with_messengers = array( |
70 | - 'html' => array( 'pdf' ) |
|
70 | + 'html' => array('pdf') |
|
71 | 71 | ); |
72 | 72 | } |
73 | 73 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | // receipt message type data handler is 'Gateways' and it expects a transaction object. |
79 | 79 | $transaction = $registration->transaction(); |
80 | 80 | if ($transaction instanceof EE_Transaction) { |
81 | - return array( $transaction ); |
|
81 | + return array($transaction); |
|
82 | 82 | } |
83 | 83 | return array(); |
84 | 84 | } |