Completed
Branch FET-Wait-List (8e9360)
by
unknown
103:16 queued 91:24
created
core/libraries/messages/EE_Messages_Generator.lib.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
      * there's a single shared message template group among all the events.  Otherwise it returns null.
460 460
      *
461 461
      * @param array $event_ids
462
-     * @return EE_Message_Template_Group|null
462
+     * @return null|EE_Base_Class
463 463
      * @throws EE_Error
464 464
      * @throws InvalidArgumentException
465 465
      * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
     /**
496 496
      * Retrieves the global message template group for the current messenger and message type.
497 497
      *
498
-     * @return EE_Message_Template_Group|null
498
+     * @return null|EE_Base_Class
499 499
      * @throws EE_Error
500 500
      * @throws InvalidArgumentException
501 501
      * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
      * @param EE_Messages_Addressee     $recipient
642 642
      * @param array                     $templates formatted array of templates used for parsing data.
643 643
      * @param EE_Message_Template_Group $message_template_group
644
-     * @return bool|EE_Message
644
+     * @return EE_Message
645 645
      * @throws EE_Error
646 646
      */
647 647
     protected function _setup_message_object(
Please login to merge, or discard this patch.
Indentation   +966 added lines, -966 removed lines patch added patch discarded remove patch
@@ -13,970 +13,970 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @type EE_Messages_Data_Handler_Collection
18
-     */
19
-    protected $_data_handler_collection;
20
-
21
-    /**
22
-     * @type  EE_Message_Template_Group_Collection
23
-     */
24
-    protected $_template_collection;
25
-
26
-    /**
27
-     * This will hold the data handler for the current EE_Message being generated.
28
-     *
29
-     * @type EE_Messages_incoming_data
30
-     */
31
-    protected $_current_data_handler;
32
-
33
-    /**
34
-     * This holds the EE_Messages_Queue that contains the messages to generate.
35
-     *
36
-     * @type EE_Messages_Queue
37
-     */
38
-    protected $_generation_queue;
39
-
40
-    /**
41
-     * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
42
-     *
43
-     * @type EE_Messages_Queue
44
-     */
45
-    protected $_ready_queue;
46
-
47
-    /**
48
-     * This is a container for any error messages that get created through the generation
49
-     * process.
50
-     *
51
-     * @type array
52
-     */
53
-    protected $_error_msg = array();
54
-
55
-    /**
56
-     * Flag used to set when the current EE_Message in the generation queue has been verified.
57
-     *
58
-     * @type bool
59
-     */
60
-    protected $_verified = false;
61
-
62
-    /**
63
-     * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
64
-     *
65
-     * @type EE_messenger
66
-     */
67
-    protected $_current_messenger;
68
-
69
-    /**
70
-     * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
71
-     *
72
-     * @type EE_message_type
73
-     */
74
-    protected $_current_message_type;
75
-
76
-    /**
77
-     * @type EEH_Parse_Shortcodes
78
-     */
79
-    protected $_shortcode_parser;
80
-
81
-
82
-    /**
83
-     * @param EE_Messages_Queue                     $generation_queue
84
-     * @param \EE_Messages_Queue                    $ready_queue
85
-     * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
86
-     * @param \EE_Message_Template_Group_Collection $template_collection
87
-     * @param \EEH_Parse_Shortcodes                 $shortcode_parser
88
-     */
89
-    public function __construct(
90
-        EE_Messages_Queue $generation_queue,
91
-        EE_Messages_Queue $ready_queue,
92
-        EE_Messages_Data_Handler_Collection $data_handler_collection,
93
-        EE_Message_Template_Group_Collection $template_collection,
94
-        EEH_Parse_Shortcodes $shortcode_parser
95
-    ) {
96
-        $this->_generation_queue        = $generation_queue;
97
-        $this->_ready_queue             = $ready_queue;
98
-        $this->_data_handler_collection = $data_handler_collection;
99
-        $this->_template_collection     = $template_collection;
100
-        $this->_shortcode_parser        = $shortcode_parser;
101
-    }
102
-
103
-
104
-    /**
105
-     * @return EE_Messages_Queue
106
-     */
107
-    public function generation_queue()
108
-    {
109
-        return $this->_generation_queue;
110
-    }
111
-
112
-
113
-    /**
114
-     *  This iterates through the provided queue and generates the EE_Message objects.
115
-     *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
116
-     *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
117
-     *  for the caller to decide what to do with it.
118
-     *
119
-     * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
120
-     * @return EE_Messages_Queue The new queue for holding generated EE_Message objects.
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    public function generate($save = true)
125
-    {
126
-        //iterate through the messages in the queue, generate, and add to new queue.
127
-        $this->_generation_queue->get_message_repository()->rewind();
128
-        while ($this->_generation_queue->get_message_repository()->valid()) {
129
-            //reset "current" properties
130
-            $this->_reset_current_properties();
131
-
132
-            /** @type EE_Message $msg */
133
-            $msg = $this->_generation_queue->get_message_repository()->current();
134
-
135
-            /**
136
-             * need to get the next object and capture it for setting manually after deletes.  The reason is that when
137
-             * an object is removed from the repo then valid for the next object will fail.
138
-             */
139
-            $this->_generation_queue->get_message_repository()->next();
140
-            $next_msg = $this->_generation_queue->get_message_repository()->current();
141
-            //restore pointer to current item
142
-            $this->_generation_queue->get_message_repository()->set_current($msg);
143
-
144
-            //skip and delete if the current $msg is NOT incomplete (queued for generation)
145
-            if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
146
-                //we keep this item in the db just remove from the repo.
147
-                $this->_generation_queue->get_message_repository()->remove($msg);
148
-                //next item
149
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
150
-                continue;
151
-            }
152
-
153
-            if ($this->_verify()) {
154
-                //let's get generating!
155
-                $this->_generate();
156
-            }
157
-
158
-            //don't persist debug_only messages if the messages system is not in debug mode.
159
-            if ($msg->STS_ID() === EEM_Message::status_debug_only
160
-                && ! EEM_Message::debug()
161
-            ) {
162
-                do_action(
163
-                    'AHEE__EE_Messages_Generator__generate__before_debug_delete',
164
-                    $msg,
165
-                    $this->_error_msg,
166
-                    $this->_current_messenger,
167
-                    $this->_current_message_type,
168
-                    $this->_current_data_handler
169
-                );
170
-                $this->_generation_queue->get_message_repository()->delete();
171
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
172
-                continue;
173
-            }
174
-
175
-            //if there are error messages then let's set the status and the error message.
176
-            if ($this->_error_msg) {
177
-                //if the status is already debug only, then let's leave it at that.
178
-                if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
179
-                    $msg->set_STS_ID(EEM_Message::status_failed);
180
-                }
181
-                do_action(
182
-                    'AHEE__EE_Messages_Generator__generate__processing_failed_message',
183
-                    $msg,
184
-                    $this->_error_msg,
185
-                    $this->_current_messenger,
186
-                    $this->_current_message_type,
187
-                    $this->_current_data_handler
188
-                );
189
-                $msg->set_error_message(
190
-                    esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
191
-                    . "\n"
192
-                    . implode("\n", $this->_error_msg)
193
-                );
194
-                $msg->set_modified(time());
195
-            } else {
196
-                do_action(
197
-                    'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
198
-                    $msg,
199
-                    $this->_error_msg,
200
-                    $this->_current_messenger,
201
-                    $this->_current_message_type,
202
-                    $this->_current_data_handler
203
-                );
204
-                //remove from db
205
-                $this->_generation_queue->get_message_repository()->delete();
206
-            }
207
-            //next item
208
-            $this->_generation_queue->get_message_repository()->set_current($next_msg);
209
-        }
210
-
211
-        //generation queue is ALWAYS saved to record any errors in the generation process.
212
-        $this->_generation_queue->save();
213
-
214
-        /**
215
-         * save _ready_queue if flag set.
216
-         * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
217
-         * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
218
-         * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
219
-         * irrelevant.
220
-         */
221
-        if ($save) {
222
-            $this->_ready_queue->save();
223
-        }
224
-
225
-        //final reset of properties
226
-        $this->_reset_current_properties();
227
-
228
-        return $this->_ready_queue;
229
-    }
230
-
231
-
232
-    /**
233
-     * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
234
-     * in the generation queue.
235
-     */
236
-    protected function _reset_current_properties()
237
-    {
238
-        $this->_verified = false;
239
-        //make sure any _data value in the current message type is reset
240
-        if ($this->_current_message_type instanceof EE_message_type) {
241
-            $this->_current_message_type->reset_data();
242
-        }
243
-        $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
244
-    }
245
-
246
-
247
-    /**
248
-     * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
249
-     * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
250
-     * _generating_queue.
251
-     *
252
-     * @return bool Whether the message was successfully generated or not.
253
-     * @throws EE_Error
254
-     * @throws InvalidArgumentException
255
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
-     */
258
-    protected function _generate()
259
-    {
260
-        //double check verification has run and that everything is ready to work with (saves us having to validate
261
-        // everything again).
262
-        if (! $this->_verified) {
263
-            return false; //get out because we don't have a valid setup to work with.
264
-        }
265
-
266
-
267
-        try {
268
-            $addressees = $this->_current_message_type->get_addressees(
269
-                $this->_current_data_handler,
270
-                $this->_generation_queue->get_message_repository()->current()->context()
271
-            );
272
-        } catch (EE_Error $e) {
273
-            $this->_error_msg[] = $e->getMessage();
274
-            return false;
275
-        }
276
-
277
-
278
-        //if no addressees then get out because there is nothing to generation (possible bad data).
279
-        if (! $this->_valid_addressees($addressees)) {
280
-            do_action(
281
-                'AHEE__EE_Messages_Generator___generate__invalid_addressees',
282
-                $this->_generation_queue->get_message_repository()->current(),
283
-                $addressees,
284
-                $this->_current_messenger,
285
-                $this->_current_message_type,
286
-                $this->_current_data_handler
287
-            );
288
-            $this->_generation_queue->get_message_repository()->current()->set_STS_ID(
289
-                EEM_Message::status_debug_only
290
-            );
291
-            $this->_error_msg[] = esc_html__(
292
-                'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
293
-                'event_espresso'
294
-            );
295
-            return false;
296
-        }
297
-
298
-        $message_template_group = $this->_get_message_template_group();
299
-
300
-        //in the unlikely event there is no EE_Message_Template_Group available, get out!
301
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
302
-            $this->_error_msg[] = esc_html__(
303
-                'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
304
-                'event_espresso'
305
-            );
306
-            return false;
307
-        }
308
-
309
-        //get formatted templates for using to parse and setup EE_Message objects.
310
-        $templates = $this->_get_templates($message_template_group);
311
-
312
-
313
-        //setup new EE_Message objects (and add to _ready_queue)
314
-        return $this->_assemble_messages($addressees, $templates, $message_template_group);
315
-    }
316
-
317
-
318
-    /**
319
-     * Retrieves the message template group being used for generating messages.
320
-     * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
321
-     *
322
-     * @return EE_Message_Template_Group|null
323
-     * @throws EE_Error
324
-     * @throws InvalidArgumentException
325
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
326
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
327
-     */
328
-    protected function _get_message_template_group()
329
-    {
330
-        //first see if there is a specific message template group requested (current message in the queue has a specific
331
-        //GRP_ID
332
-        $message_template_group = $this->_specific_message_template_group_from_queue();
333
-        if ($message_template_group instanceof EE_Message_Template_Group) {
334
-            return $message_template_group;
335
-        }
336
-
337
-        //get event_ids from the datahandler so we can check to see if there's already a message template group for them
338
-        //in the collection.
339
-        $event_ids              = $this->_get_event_ids_from_current_data_handler();
340
-        $message_template_group = $this->_template_collection->get_by_key(
341
-            $this->_template_collection->getKey(
342
-                $this->_current_messenger->name,
343
-                $this->_current_message_type->name,
344
-                $event_ids
345
-            )
346
-        );
347
-
348
-        //if we have a message template group then no need to hit the database, just return it.
349
-        if ($message_template_group instanceof EE_Message_Template_Group) {
350
-            return $message_template_group;
351
-        }
352
-
353
-        //okay made it here, so let's get the global group first for this messenger and message type to ensure
354
-        //there is no override set.
355
-        $global_message_template_group =
356
-            $this->_get_global_message_template_group_for_current_messenger_and_message_type();
357
-
358
-        if ($global_message_template_group instanceof EE_Message_Template_Group
359
-            && $global_message_template_group->get('MTP_is_override')
360
-        ) {
361
-            return $global_message_template_group;
362
-        }
363
-
364
-        //if we're still here, that means there was no message template group for the events in the collection and
365
-        //the global message template group for the messenger and message type is not set for override.  So next step is
366
-        //to see if there is a common shared custom message template group for this set of events.
367
-        $message_template_group = $this->_get_shared_message_template_for_events($event_ids);
368
-        if ($message_template_group instanceof EE_Message_Template_Group) {
369
-            return $message_template_group;
370
-        }
371
-
372
-        //STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
373
-        //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
374
-        //and return it.
375
-        if ($global_message_template_group instanceof EE_Message_Template_Group) {
376
-            $this->_template_collection->add(
377
-                $global_message_template_group,
378
-                $event_ids
379
-            );
380
-            return $global_message_template_group;
381
-        }
382
-
383
-        //if we land here that means there's NO active message template group for this set.
384
-        //TODO this will be a good target for some optimization down the road.  Whenever there is no active message
385
-        //template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
386
-        //this should likely bit hit rarely enough that it's not a significant issue.
387
-        return null;
388
-    }
389
-
390
-
391
-    /**
392
-     * This checks the current message in the queue and determines if there is a specific Message Template Group
393
-     * requested for that message.
394
-     *
395
-     * @return EE_Message_Template_Group|null
396
-     * @throws EE_Error
397
-     * @throws InvalidArgumentException
398
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
399
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
400
-     */
401
-    protected function _specific_message_template_group_from_queue()
402
-    {
403
-        //is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
404
-        //so let's use that.
405
-        $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
406
-
407
-        if ($GRP_ID) {
408
-            //attempt to retrieve from repo first
409
-            $message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
410
-            if ($message_template_group instanceof EE_Message_Template_Group) {
411
-                return $message_template_group;  //got it!
412
-            }
413
-
414
-            //nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
415
-            //is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
416
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
417
-            if ($message_template_group instanceof EE_Message_Template_Group) {
418
-                $this->_template_collection->add($message_template_group);
419
-                return $message_template_group;
420
-            }
421
-        }
422
-        return null;
423
-    }
424
-
425
-
426
-    /**
427
-     * Returns whether the event ids passed in all share the same message template group for the current message type
428
-     * and messenger.
429
-     *
430
-     * @param array $event_ids
431
-     * @return bool true means they DO share the same message template group, false means they don't.
432
-     * @throws EE_Error
433
-     * @throws InvalidArgumentException
434
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
435
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
436
-     */
437
-    protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
438
-    {
439
-        foreach ($this->_current_data_handler->events as $event) {
440
-            $event_ids[$event['ID']] = $event['ID'];
441
-        }
442
-        $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
443
-            array(
444
-                array(
445
-                    'Event.EVT_ID'           => array('IN', $event_ids),
446
-                    'MTP_messenger'    => $this->_current_messenger->name,
447
-                    'MTP_message_type' => $this->_current_message_type->name,
448
-                ),
449
-            ),
450
-            'GRP_ID',
451
-            true
452
-        );
453
-        return $count_of_message_template_groups === 1;
454
-    }
455
-
456
-
457
-    /**
458
-     * This will get the shared message template group for events that are in the current data handler but ONLY if
459
-     * there's a single shared message template group among all the events.  Otherwise it returns null.
460
-     *
461
-     * @param array $event_ids
462
-     * @return EE_Message_Template_Group|null
463
-     * @throws EE_Error
464
-     * @throws InvalidArgumentException
465
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
466
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
467
-     */
468
-    protected function _get_shared_message_template_for_events(array $event_ids)
469
-    {
470
-        $message_template_group = null;
471
-        if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
472
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one(
473
-                array(
474
-                    array(
475
-                        'Event.EVT_ID'           => array('IN', $event_ids),
476
-                        'MTP_messenger'    => $this->_current_messenger->name,
477
-                        'MTP_message_type' => $this->_current_message_type->name,
478
-                        'MTP_is_active'    => true,
479
-                    ),
480
-                    'group_by' => 'GRP_ID',
481
-                )
482
-            );
483
-            //store this in the collection if its valid
484
-            if ($message_template_group instanceof EE_Message_Template_Group) {
485
-                $this->_template_collection->add(
486
-                    $message_template_group,
487
-                    $event_ids
488
-                );
489
-            }
490
-        }
491
-        return $message_template_group;
492
-    }
493
-
494
-
495
-    /**
496
-     * Retrieves the global message template group for the current messenger and message type.
497
-     *
498
-     * @return EE_Message_Template_Group|null
499
-     * @throws EE_Error
500
-     * @throws InvalidArgumentException
501
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
502
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
503
-     */
504
-    protected function _get_global_message_template_group_for_current_messenger_and_message_type()
505
-    {
506
-        //first check the collection (we use an array with 0 in it to represent global groups).
507
-        $global_message_template_group = $this->_template_collection->get_by_key(
508
-            $this->_template_collection->getKey(
509
-                $this->_current_messenger->name,
510
-                $this->_current_message_type->name,
511
-                array(0)
512
-            )
513
-        );
514
-
515
-        //if we don't have a group lets hit the db.
516
-        if (! $global_message_template_group instanceof EE_Message_Template_Group) {
517
-            $global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
518
-                array(
519
-                    array(
520
-                        'MTP_messenger'    => $this->_current_messenger->name,
521
-                        'MTP_message_type' => $this->_current_message_type->name,
522
-                        'MTP_is_active'    => true,
523
-                        'MTP_is_global'    => true,
524
-                    ),
525
-                )
526
-            );
527
-            //if we have a group, add it to the collection.
528
-            if ($global_message_template_group instanceof EE_Message_Template_Group) {
529
-                $this->_template_collection->add(
530
-                    $global_message_template_group,
531
-                    array(0)
532
-                );
533
-            }
534
-        }
535
-        return $global_message_template_group;
536
-    }
537
-
538
-
539
-    /**
540
-     * Returns an array of event ids for all the events within the current data handler.
541
-     *
542
-     * @return array
543
-     */
544
-    protected function _get_event_ids_from_current_data_handler()
545
-    {
546
-        $event_ids = array();
547
-        foreach ($this->_current_data_handler->events as $event) {
548
-            $event_ids[$event['ID']] = $event['ID'];
549
-        }
550
-        return $event_ids;
551
-    }
552
-
553
-
554
-    /**
555
-     *  Retrieves formatted array of template information for each context specific to the given
556
-     *  EE_Message_Template_Group
557
-     *
558
-     * @param EE_Message_Template_Group $message_template_group
559
-     * @return array The returned array is in this structure:
560
-     *                          array(
561
-     *                          'field_name' => array(
562
-     *                          'context' => 'content'
563
-     *                          )
564
-     *                          )
565
-     * @throws EE_Error
566
-     */
567
-    protected function _get_templates(EE_Message_Template_Group $message_template_group)
568
-    {
569
-        $templates         = array();
570
-        $context_templates = $message_template_group->context_templates();
571
-        foreach ($context_templates as $context => $template_fields) {
572
-            foreach ($template_fields as $template_field => $template_obj) {
573
-                if (! $template_obj instanceof EE_Message_Template) {
574
-                    continue;
575
-                }
576
-                $templates[$template_field][$context] = $template_obj->get('MTP_content');
577
-            }
578
-        }
579
-        return $templates;
580
-    }
581
-
582
-
583
-    /**
584
-     * Assembles new fully generated EE_Message objects and adds to _ready_queue
585
-     *
586
-     * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
587
-     *                                               context.
588
-     * @param array                     $templates   formatted array of templates used for parsing data.
589
-     * @param EE_Message_Template_Group $message_template_group
590
-     * @return bool true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
591
-     *                                               method will attempt to generate ALL EE_Message objects and add to
592
-     *                                               the _ready_queue.  Successfully generated messages get added to the
593
-     *                                               queue with EEM_Message::status_idle, unsuccessfully generated
594
-     *                                               messages will get added to the queue as EEM_Message::status_failed.
595
-     *                                               Very rarely should "false" be returned from this method.
596
-     * @throws EE_Error
597
-     */
598
-    protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
599
-    {
600
-
601
-        //if templates are empty then get out because we can't generate anything.
602
-        if (! $templates) {
603
-            $this->_error_msg[] = esc_html__(
604
-                'Unable to assemble messages because there are no templates retrieved for generating the messages with',
605
-                'event_espresso'
606
-            );
607
-            return false;
608
-        }
609
-
610
-        //We use this as the counter for generated messages because don't forget we may be executing this inside of a
611
-        //generation_queue.  So _ready_queue may have generated EE_Message objects already.
612
-        $generated_count = 0;
613
-        foreach ($addressees as $context => $recipients) {
614
-            foreach ($recipients as $recipient) {
615
-                $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
616
-                if ($message instanceof EE_Message) {
617
-                    $this->_ready_queue->add(
618
-                        $message,
619
-                        array(),
620
-                        $this->_generation_queue->get_message_repository()->is_preview(),
621
-                        $this->_generation_queue->get_message_repository()->is_test_send()
622
-                    );
623
-                    $generated_count++;
624
-                }
625
-
626
-                //if the current MSG being generated is for a test send then we'll only use ONE message in the
627
-                // generation.
628
-                if ($this->_generation_queue->get_message_repository()->is_test_send()) {
629
-                    break 2;
630
-                }
631
-            }
632
-        }
633
-
634
-        //if there are no generated messages then something else fatal went wrong.
635
-        return $generated_count > 0;
636
-    }
637
-
638
-
639
-    /**
640
-     * @param string                    $context   The context for the generated message.
641
-     * @param EE_Messages_Addressee     $recipient
642
-     * @param array                     $templates formatted array of templates used for parsing data.
643
-     * @param EE_Message_Template_Group $message_template_group
644
-     * @return bool|EE_Message
645
-     * @throws EE_Error
646
-     */
647
-    protected function _setup_message_object(
648
-        $context,
649
-        EE_Messages_Addressee $recipient,
650
-        $templates,
651
-        EE_Message_Template_Group $message_template_group
652
-    ) {
653
-        //stuff we already know
654
-        $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
655
-        $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
656
-            ? $this->_current_data_handler->txn->ID()
657
-            : $transaction_id;
658
-        $message_fields = array(
659
-            'GRP_ID'           => $message_template_group->ID(),
660
-            'TXN_ID'           => $transaction_id,
661
-            'MSG_messenger'    => $this->_current_messenger->name,
662
-            'MSG_message_type' => $this->_current_message_type->name,
663
-            'MSG_context'      => $context,
664
-        );
665
-
666
-        //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
667
-        // the info from the att_obj found in the EE_Messages_Addressee object.
668
-        if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
669
-            $message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
670
-                ? $recipient->att_obj->ID()
671
-                : 0;
672
-            $message_fields['MSG_recipient_type'] = 'Attendee';
673
-        } else {
674
-            $message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
675
-            $message_fields['MSG_recipient_type'] = $recipient->recipient_type;
676
-        }
677
-        $message = EE_Message_Factory::create($message_fields);
678
-
679
-        //grab valid shortcodes for shortcode parser
680
-        $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
681
-        $m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
682
-
683
-        //if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing
684
-        if ((
685
-                (
686
-                    empty($templates['to'][$context])
687
-                    && ! $this->_current_messenger->allow_empty_to_field()
688
-                )
689
-                || ! $message_template_group->is_context_active($context)
690
-            )
691
-            && ! $this->_generation_queue->get_message_repository()->is_preview()
692
-        ) {
693
-            //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
694
-            //field.
695
-            return false;
696
-        }
697
-        $error_msg = array();
698
-        foreach ($templates as $field => $field_context) {
699
-            $error_msg = array();
700
-            //let's setup the valid shortcodes for the incoming context.
701
-            $valid_shortcodes = $mt_shortcodes[$context];
702
-            //merge in valid shortcodes for the field.
703
-            $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
704
-            if (isset($templates[$field][$context])) {
705
-                //prefix field.
706
-                $column_name = 'MSG_' . $field;
707
-                try {
708
-                    $content = $this->_shortcode_parser->parse_message_template(
709
-                        $templates[$field][$context],
710
-                        $recipient,
711
-                        $shortcodes,
712
-                        $this->_current_message_type,
713
-                        $this->_current_messenger,
714
-                        $message
715
-                    );
716
-                    $message->set_field_or_extra_meta($column_name, $content);
717
-                } catch (EE_Error $e) {
718
-                    $error_msg[] = sprintf(
719
-                        esc_html__(
720
-                            'There was a problem generating the content for the field %s: %s',
721
-                            'event_espresso'
722
-                        ),
723
-                        $field,
724
-                        $e->getMessage()
725
-                    );
726
-                    $message->set_STS_ID(EEM_Message::status_failed);
727
-                }
728
-            }
729
-        }
730
-
731
-        if ($message->STS_ID() === EEM_Message::status_failed) {
732
-            $error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
733
-                         . "\n"
734
-                         . implode("\n", $error_msg);
735
-            $message->set_error_message($error_msg);
736
-        } else {
737
-            $message->set_STS_ID(EEM_Message::status_idle);
738
-        }
739
-        return $message;
740
-    }
741
-
742
-
743
-    /**
744
-     * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
745
-     * error message if either is missing.
746
-     *
747
-     * @return bool true means there were no errors, false means there were errors.
748
-     * @throws EE_Error
749
-     * @throws ReflectionException
750
-     */
751
-    protected function _verify()
752
-    {
753
-        //reset error message to an empty array.
754
-        $this->_error_msg = array();
755
-        $valid            = true;
756
-        $valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
757
-        $valid            = $valid ? $this->_validate_and_setup_data() : $valid;
758
-
759
-        //set the verified flag so we know everything has been validated.
760
-        $this->_verified = $valid;
761
-
762
-        return $valid;
763
-    }
764
-
765
-
766
-    /**
767
-     * This accepts an array and validates that it is an array indexed by context with each value being an array of
768
-     * EE_Messages_Addressee objects.
769
-     *
770
-     * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
771
-     * @return bool
772
-     */
773
-    protected function _valid_addressees($addressees)
774
-    {
775
-        if (! $addressees || ! is_array($addressees)) {
776
-            return false;
777
-        }
778
-
779
-        foreach ($addressees as $addressee_array) {
780
-            foreach ($addressee_array as $addressee) {
781
-                if (! $addressee instanceof EE_Messages_Addressee) {
782
-                    return false;
783
-                }
784
-            }
785
-        }
786
-        return true;
787
-    }
788
-
789
-
790
-    /**
791
-     * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
792
-     * queue. This process sets error messages if something is wrong.
793
-     *
794
-     * @return bool   true is if there are no errors.  false is if there is.
795
-     */
796
-    protected function _validate_messenger_and_message_type()
797
-    {
798
-
799
-        //first are there any existing error messages?  If so then return.
800
-        if ($this->_error_msg) {
801
-            return false;
802
-        }
803
-        /** @type EE_Message $message */
804
-        $message = $this->_generation_queue->get_message_repository()->current();
805
-        try {
806
-            $this->_current_messenger = $message->valid_messenger(true)
807
-                ? $message->messenger_object()
808
-                : null;
809
-        } catch (Exception $e) {
810
-            $this->_error_msg[] = $e->getMessage();
811
-        }
812
-        try {
813
-            $this->_current_message_type = $message->valid_message_type(true)
814
-                ? $message->message_type_object()
815
-                : null;
816
-        } catch (Exception $e) {
817
-            $this->_error_msg[] = $e->getMessage();
818
-        }
819
-
820
-        /**
821
-         * Check if there is any generation data, but only if this is not for a preview.
822
-         */
823
-        if (! $this->_generation_queue->get_message_repository()->get_generation_data()
824
-            && (
825
-                ! $this->_generation_queue->get_message_repository()->is_preview()
826
-                && $this->_generation_queue->get_message_repository()->get_data_handler()
827
-                   !== 'EE_Messages_Preview_incoming_data'
828
-            )
829
-        ) {
830
-            $this->_error_msg[] = esc_html__(
831
-                'There is no generation data for this message. Unable to generate.',
832
-                'event_espresso'
833
-            );
834
-        }
835
-
836
-        return empty($this->_error_msg);
837
-    }
838
-
839
-
840
-    /**
841
-     * This method retrieves the expected data handler for the message type and validates the generation data for that
842
-     * data handler.
843
-     *
844
-     * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
845
-     * @throws EE_Error
846
-     * @throws ReflectionException
847
-     */
848
-    protected function _validate_and_setup_data()
849
-    {
850
-
851
-        //First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
852
-        //be used anyways.
853
-        if ($this->_error_msg) {
854
-            return false;
855
-        }
856
-
857
-        $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
858
-
859
-        /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
860
-        $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
861
-            ? $this->_generation_queue->get_message_repository()->get_data_handler()
862
-            : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
863
-
864
-        //If this EE_Message is for a preview, then let's switch out to the preview data handler.
865
-        if ($this->_generation_queue->get_message_repository()->is_preview()) {
866
-            $data_handler_class_name = 'EE_Messages_Preview_incoming_data';
867
-        }
868
-
869
-        //First get the class name for the data handler (and also verifies it exists.
870
-        if (! class_exists($data_handler_class_name)) {
871
-            $this->_error_msg[] = sprintf(
872
-                esc_html__(
873
-                    'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
874
-                    'event_espresso'
875
-                ),
876
-                'EE_Messages_incoming_data',
877
-                $data_handler_class_name
878
-            );
879
-            return false;
880
-        }
881
-
882
-        //convert generation_data for data_handler_instantiation.
883
-        $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
884
-
885
-        //note, this may set error messages as well.
886
-        $this->_set_data_handler($generation_data, $data_handler_class_name);
887
-
888
-        return empty($this->_error_msg);
889
-    }
890
-
891
-
892
-    /**
893
-     * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
894
-     * adds it to the _data repository.
895
-     *
896
-     * @param mixed  $generating_data           This is data expected by the instantiated data handler.
897
-     * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
898
-     *                                          instantiated.
899
-     * @return void .
900
-     * @throws EE_Error
901
-     * @throws ReflectionException
902
-     */
903
-    protected function _set_data_handler($generating_data, $data_handler_class_name)
904
-    {
905
-        //valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
906
-        //is already a ready data handler in the repository.
907
-        $this->_current_data_handler = $this->_data_handler_collection->get_by_key(
908
-            $this->_data_handler_collection->get_key(
909
-                $data_handler_class_name,
910
-                $generating_data
911
-            )
912
-        );
913
-        if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
914
-            //no saved data_handler in the repo so let's set one up and add it to the repo.
915
-            try {
916
-                $this->_current_data_handler = new $data_handler_class_name($generating_data);
917
-                $this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
918
-            } catch (EE_Error $e) {
919
-                $this->_error_msg[] = $e->get_error();
920
-            }
921
-        }
922
-    }
923
-
924
-
925
-    /**
926
-     * The queued EE_Message for generation does not save the data used for generation as objects
927
-     * because serialization of those objects could be problematic if the data is saved to the db.
928
-     * So this method calls the static method on the associated data_handler for the given message_type
929
-     * and that preps the data for later instantiation when generating.
930
-     *
931
-     * @param EE_Message_To_Generate $message_to_generate
932
-     * @param bool                   $preview Indicate whether this is being used for a preview or not.
933
-     * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
934
-     */
935
-    protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
936
-    {
937
-        /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
938
-        $data_handler = $message_to_generate->get_data_handler_class_name($preview);
939
-        if (! $message_to_generate->valid()) {
940
-            return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
941
-        }
942
-        return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
943
-    }
944
-
945
-
946
-    /**
947
-     * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
948
-     *
949
-     * @param EE_Message_To_Generate $message_to_generate
950
-     * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
951
-     * @throws InvalidArgumentException
952
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
953
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
954
-     */
955
-    public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
956
-    {
957
-        //prep data
958
-        $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
959
-
960
-        $message = $message_to_generate->get_EE_Message();
961
-
962
-        //is there a GRP_ID in the request?
963
-        if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
964
-            $message->set_GRP_ID($GRP_ID);
965
-        }
966
-
967
-        if ($data === false) {
968
-            $message->set_STS_ID(EEM_Message::status_failed);
969
-            $message->set_error_message(
970
-                esc_html__(
971
-                    'Unable to prepare data for persistence to the database.',
972
-                    'event_espresso'
973
-                )
974
-            );
975
-        } else {
976
-            //make sure that the data handler is cached on the message as well
977
-            $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
978
-        }
979
-
980
-        $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
981
-    }
16
+	/**
17
+	 * @type EE_Messages_Data_Handler_Collection
18
+	 */
19
+	protected $_data_handler_collection;
20
+
21
+	/**
22
+	 * @type  EE_Message_Template_Group_Collection
23
+	 */
24
+	protected $_template_collection;
25
+
26
+	/**
27
+	 * This will hold the data handler for the current EE_Message being generated.
28
+	 *
29
+	 * @type EE_Messages_incoming_data
30
+	 */
31
+	protected $_current_data_handler;
32
+
33
+	/**
34
+	 * This holds the EE_Messages_Queue that contains the messages to generate.
35
+	 *
36
+	 * @type EE_Messages_Queue
37
+	 */
38
+	protected $_generation_queue;
39
+
40
+	/**
41
+	 * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
42
+	 *
43
+	 * @type EE_Messages_Queue
44
+	 */
45
+	protected $_ready_queue;
46
+
47
+	/**
48
+	 * This is a container for any error messages that get created through the generation
49
+	 * process.
50
+	 *
51
+	 * @type array
52
+	 */
53
+	protected $_error_msg = array();
54
+
55
+	/**
56
+	 * Flag used to set when the current EE_Message in the generation queue has been verified.
57
+	 *
58
+	 * @type bool
59
+	 */
60
+	protected $_verified = false;
61
+
62
+	/**
63
+	 * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
64
+	 *
65
+	 * @type EE_messenger
66
+	 */
67
+	protected $_current_messenger;
68
+
69
+	/**
70
+	 * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
71
+	 *
72
+	 * @type EE_message_type
73
+	 */
74
+	protected $_current_message_type;
75
+
76
+	/**
77
+	 * @type EEH_Parse_Shortcodes
78
+	 */
79
+	protected $_shortcode_parser;
80
+
81
+
82
+	/**
83
+	 * @param EE_Messages_Queue                     $generation_queue
84
+	 * @param \EE_Messages_Queue                    $ready_queue
85
+	 * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
86
+	 * @param \EE_Message_Template_Group_Collection $template_collection
87
+	 * @param \EEH_Parse_Shortcodes                 $shortcode_parser
88
+	 */
89
+	public function __construct(
90
+		EE_Messages_Queue $generation_queue,
91
+		EE_Messages_Queue $ready_queue,
92
+		EE_Messages_Data_Handler_Collection $data_handler_collection,
93
+		EE_Message_Template_Group_Collection $template_collection,
94
+		EEH_Parse_Shortcodes $shortcode_parser
95
+	) {
96
+		$this->_generation_queue        = $generation_queue;
97
+		$this->_ready_queue             = $ready_queue;
98
+		$this->_data_handler_collection = $data_handler_collection;
99
+		$this->_template_collection     = $template_collection;
100
+		$this->_shortcode_parser        = $shortcode_parser;
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return EE_Messages_Queue
106
+	 */
107
+	public function generation_queue()
108
+	{
109
+		return $this->_generation_queue;
110
+	}
111
+
112
+
113
+	/**
114
+	 *  This iterates through the provided queue and generates the EE_Message objects.
115
+	 *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
116
+	 *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
117
+	 *  for the caller to decide what to do with it.
118
+	 *
119
+	 * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
120
+	 * @return EE_Messages_Queue The new queue for holding generated EE_Message objects.
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	public function generate($save = true)
125
+	{
126
+		//iterate through the messages in the queue, generate, and add to new queue.
127
+		$this->_generation_queue->get_message_repository()->rewind();
128
+		while ($this->_generation_queue->get_message_repository()->valid()) {
129
+			//reset "current" properties
130
+			$this->_reset_current_properties();
131
+
132
+			/** @type EE_Message $msg */
133
+			$msg = $this->_generation_queue->get_message_repository()->current();
134
+
135
+			/**
136
+			 * need to get the next object and capture it for setting manually after deletes.  The reason is that when
137
+			 * an object is removed from the repo then valid for the next object will fail.
138
+			 */
139
+			$this->_generation_queue->get_message_repository()->next();
140
+			$next_msg = $this->_generation_queue->get_message_repository()->current();
141
+			//restore pointer to current item
142
+			$this->_generation_queue->get_message_repository()->set_current($msg);
143
+
144
+			//skip and delete if the current $msg is NOT incomplete (queued for generation)
145
+			if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
146
+				//we keep this item in the db just remove from the repo.
147
+				$this->_generation_queue->get_message_repository()->remove($msg);
148
+				//next item
149
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
150
+				continue;
151
+			}
152
+
153
+			if ($this->_verify()) {
154
+				//let's get generating!
155
+				$this->_generate();
156
+			}
157
+
158
+			//don't persist debug_only messages if the messages system is not in debug mode.
159
+			if ($msg->STS_ID() === EEM_Message::status_debug_only
160
+				&& ! EEM_Message::debug()
161
+			) {
162
+				do_action(
163
+					'AHEE__EE_Messages_Generator__generate__before_debug_delete',
164
+					$msg,
165
+					$this->_error_msg,
166
+					$this->_current_messenger,
167
+					$this->_current_message_type,
168
+					$this->_current_data_handler
169
+				);
170
+				$this->_generation_queue->get_message_repository()->delete();
171
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
172
+				continue;
173
+			}
174
+
175
+			//if there are error messages then let's set the status and the error message.
176
+			if ($this->_error_msg) {
177
+				//if the status is already debug only, then let's leave it at that.
178
+				if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
179
+					$msg->set_STS_ID(EEM_Message::status_failed);
180
+				}
181
+				do_action(
182
+					'AHEE__EE_Messages_Generator__generate__processing_failed_message',
183
+					$msg,
184
+					$this->_error_msg,
185
+					$this->_current_messenger,
186
+					$this->_current_message_type,
187
+					$this->_current_data_handler
188
+				);
189
+				$msg->set_error_message(
190
+					esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
191
+					. "\n"
192
+					. implode("\n", $this->_error_msg)
193
+				);
194
+				$msg->set_modified(time());
195
+			} else {
196
+				do_action(
197
+					'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
198
+					$msg,
199
+					$this->_error_msg,
200
+					$this->_current_messenger,
201
+					$this->_current_message_type,
202
+					$this->_current_data_handler
203
+				);
204
+				//remove from db
205
+				$this->_generation_queue->get_message_repository()->delete();
206
+			}
207
+			//next item
208
+			$this->_generation_queue->get_message_repository()->set_current($next_msg);
209
+		}
210
+
211
+		//generation queue is ALWAYS saved to record any errors in the generation process.
212
+		$this->_generation_queue->save();
213
+
214
+		/**
215
+		 * save _ready_queue if flag set.
216
+		 * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
217
+		 * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
218
+		 * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
219
+		 * irrelevant.
220
+		 */
221
+		if ($save) {
222
+			$this->_ready_queue->save();
223
+		}
224
+
225
+		//final reset of properties
226
+		$this->_reset_current_properties();
227
+
228
+		return $this->_ready_queue;
229
+	}
230
+
231
+
232
+	/**
233
+	 * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
234
+	 * in the generation queue.
235
+	 */
236
+	protected function _reset_current_properties()
237
+	{
238
+		$this->_verified = false;
239
+		//make sure any _data value in the current message type is reset
240
+		if ($this->_current_message_type instanceof EE_message_type) {
241
+			$this->_current_message_type->reset_data();
242
+		}
243
+		$this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
244
+	}
245
+
246
+
247
+	/**
248
+	 * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
249
+	 * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
250
+	 * _generating_queue.
251
+	 *
252
+	 * @return bool Whether the message was successfully generated or not.
253
+	 * @throws EE_Error
254
+	 * @throws InvalidArgumentException
255
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
+	 */
258
+	protected function _generate()
259
+	{
260
+		//double check verification has run and that everything is ready to work with (saves us having to validate
261
+		// everything again).
262
+		if (! $this->_verified) {
263
+			return false; //get out because we don't have a valid setup to work with.
264
+		}
265
+
266
+
267
+		try {
268
+			$addressees = $this->_current_message_type->get_addressees(
269
+				$this->_current_data_handler,
270
+				$this->_generation_queue->get_message_repository()->current()->context()
271
+			);
272
+		} catch (EE_Error $e) {
273
+			$this->_error_msg[] = $e->getMessage();
274
+			return false;
275
+		}
276
+
277
+
278
+		//if no addressees then get out because there is nothing to generation (possible bad data).
279
+		if (! $this->_valid_addressees($addressees)) {
280
+			do_action(
281
+				'AHEE__EE_Messages_Generator___generate__invalid_addressees',
282
+				$this->_generation_queue->get_message_repository()->current(),
283
+				$addressees,
284
+				$this->_current_messenger,
285
+				$this->_current_message_type,
286
+				$this->_current_data_handler
287
+			);
288
+			$this->_generation_queue->get_message_repository()->current()->set_STS_ID(
289
+				EEM_Message::status_debug_only
290
+			);
291
+			$this->_error_msg[] = esc_html__(
292
+				'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
293
+				'event_espresso'
294
+			);
295
+			return false;
296
+		}
297
+
298
+		$message_template_group = $this->_get_message_template_group();
299
+
300
+		//in the unlikely event there is no EE_Message_Template_Group available, get out!
301
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
302
+			$this->_error_msg[] = esc_html__(
303
+				'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
304
+				'event_espresso'
305
+			);
306
+			return false;
307
+		}
308
+
309
+		//get formatted templates for using to parse and setup EE_Message objects.
310
+		$templates = $this->_get_templates($message_template_group);
311
+
312
+
313
+		//setup new EE_Message objects (and add to _ready_queue)
314
+		return $this->_assemble_messages($addressees, $templates, $message_template_group);
315
+	}
316
+
317
+
318
+	/**
319
+	 * Retrieves the message template group being used for generating messages.
320
+	 * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
321
+	 *
322
+	 * @return EE_Message_Template_Group|null
323
+	 * @throws EE_Error
324
+	 * @throws InvalidArgumentException
325
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
326
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
327
+	 */
328
+	protected function _get_message_template_group()
329
+	{
330
+		//first see if there is a specific message template group requested (current message in the queue has a specific
331
+		//GRP_ID
332
+		$message_template_group = $this->_specific_message_template_group_from_queue();
333
+		if ($message_template_group instanceof EE_Message_Template_Group) {
334
+			return $message_template_group;
335
+		}
336
+
337
+		//get event_ids from the datahandler so we can check to see if there's already a message template group for them
338
+		//in the collection.
339
+		$event_ids              = $this->_get_event_ids_from_current_data_handler();
340
+		$message_template_group = $this->_template_collection->get_by_key(
341
+			$this->_template_collection->getKey(
342
+				$this->_current_messenger->name,
343
+				$this->_current_message_type->name,
344
+				$event_ids
345
+			)
346
+		);
347
+
348
+		//if we have a message template group then no need to hit the database, just return it.
349
+		if ($message_template_group instanceof EE_Message_Template_Group) {
350
+			return $message_template_group;
351
+		}
352
+
353
+		//okay made it here, so let's get the global group first for this messenger and message type to ensure
354
+		//there is no override set.
355
+		$global_message_template_group =
356
+			$this->_get_global_message_template_group_for_current_messenger_and_message_type();
357
+
358
+		if ($global_message_template_group instanceof EE_Message_Template_Group
359
+			&& $global_message_template_group->get('MTP_is_override')
360
+		) {
361
+			return $global_message_template_group;
362
+		}
363
+
364
+		//if we're still here, that means there was no message template group for the events in the collection and
365
+		//the global message template group for the messenger and message type is not set for override.  So next step is
366
+		//to see if there is a common shared custom message template group for this set of events.
367
+		$message_template_group = $this->_get_shared_message_template_for_events($event_ids);
368
+		if ($message_template_group instanceof EE_Message_Template_Group) {
369
+			return $message_template_group;
370
+		}
371
+
372
+		//STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
373
+		//So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
374
+		//and return it.
375
+		if ($global_message_template_group instanceof EE_Message_Template_Group) {
376
+			$this->_template_collection->add(
377
+				$global_message_template_group,
378
+				$event_ids
379
+			);
380
+			return $global_message_template_group;
381
+		}
382
+
383
+		//if we land here that means there's NO active message template group for this set.
384
+		//TODO this will be a good target for some optimization down the road.  Whenever there is no active message
385
+		//template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
386
+		//this should likely bit hit rarely enough that it's not a significant issue.
387
+		return null;
388
+	}
389
+
390
+
391
+	/**
392
+	 * This checks the current message in the queue and determines if there is a specific Message Template Group
393
+	 * requested for that message.
394
+	 *
395
+	 * @return EE_Message_Template_Group|null
396
+	 * @throws EE_Error
397
+	 * @throws InvalidArgumentException
398
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
399
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
400
+	 */
401
+	protected function _specific_message_template_group_from_queue()
402
+	{
403
+		//is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
404
+		//so let's use that.
405
+		$GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
406
+
407
+		if ($GRP_ID) {
408
+			//attempt to retrieve from repo first
409
+			$message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
410
+			if ($message_template_group instanceof EE_Message_Template_Group) {
411
+				return $message_template_group;  //got it!
412
+			}
413
+
414
+			//nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
415
+			//is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
416
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
417
+			if ($message_template_group instanceof EE_Message_Template_Group) {
418
+				$this->_template_collection->add($message_template_group);
419
+				return $message_template_group;
420
+			}
421
+		}
422
+		return null;
423
+	}
424
+
425
+
426
+	/**
427
+	 * Returns whether the event ids passed in all share the same message template group for the current message type
428
+	 * and messenger.
429
+	 *
430
+	 * @param array $event_ids
431
+	 * @return bool true means they DO share the same message template group, false means they don't.
432
+	 * @throws EE_Error
433
+	 * @throws InvalidArgumentException
434
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
435
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
436
+	 */
437
+	protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
438
+	{
439
+		foreach ($this->_current_data_handler->events as $event) {
440
+			$event_ids[$event['ID']] = $event['ID'];
441
+		}
442
+		$count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
443
+			array(
444
+				array(
445
+					'Event.EVT_ID'           => array('IN', $event_ids),
446
+					'MTP_messenger'    => $this->_current_messenger->name,
447
+					'MTP_message_type' => $this->_current_message_type->name,
448
+				),
449
+			),
450
+			'GRP_ID',
451
+			true
452
+		);
453
+		return $count_of_message_template_groups === 1;
454
+	}
455
+
456
+
457
+	/**
458
+	 * This will get the shared message template group for events that are in the current data handler but ONLY if
459
+	 * there's a single shared message template group among all the events.  Otherwise it returns null.
460
+	 *
461
+	 * @param array $event_ids
462
+	 * @return EE_Message_Template_Group|null
463
+	 * @throws EE_Error
464
+	 * @throws InvalidArgumentException
465
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
466
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
467
+	 */
468
+	protected function _get_shared_message_template_for_events(array $event_ids)
469
+	{
470
+		$message_template_group = null;
471
+		if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
472
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one(
473
+				array(
474
+					array(
475
+						'Event.EVT_ID'           => array('IN', $event_ids),
476
+						'MTP_messenger'    => $this->_current_messenger->name,
477
+						'MTP_message_type' => $this->_current_message_type->name,
478
+						'MTP_is_active'    => true,
479
+					),
480
+					'group_by' => 'GRP_ID',
481
+				)
482
+			);
483
+			//store this in the collection if its valid
484
+			if ($message_template_group instanceof EE_Message_Template_Group) {
485
+				$this->_template_collection->add(
486
+					$message_template_group,
487
+					$event_ids
488
+				);
489
+			}
490
+		}
491
+		return $message_template_group;
492
+	}
493
+
494
+
495
+	/**
496
+	 * Retrieves the global message template group for the current messenger and message type.
497
+	 *
498
+	 * @return EE_Message_Template_Group|null
499
+	 * @throws EE_Error
500
+	 * @throws InvalidArgumentException
501
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
502
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
503
+	 */
504
+	protected function _get_global_message_template_group_for_current_messenger_and_message_type()
505
+	{
506
+		//first check the collection (we use an array with 0 in it to represent global groups).
507
+		$global_message_template_group = $this->_template_collection->get_by_key(
508
+			$this->_template_collection->getKey(
509
+				$this->_current_messenger->name,
510
+				$this->_current_message_type->name,
511
+				array(0)
512
+			)
513
+		);
514
+
515
+		//if we don't have a group lets hit the db.
516
+		if (! $global_message_template_group instanceof EE_Message_Template_Group) {
517
+			$global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
518
+				array(
519
+					array(
520
+						'MTP_messenger'    => $this->_current_messenger->name,
521
+						'MTP_message_type' => $this->_current_message_type->name,
522
+						'MTP_is_active'    => true,
523
+						'MTP_is_global'    => true,
524
+					),
525
+				)
526
+			);
527
+			//if we have a group, add it to the collection.
528
+			if ($global_message_template_group instanceof EE_Message_Template_Group) {
529
+				$this->_template_collection->add(
530
+					$global_message_template_group,
531
+					array(0)
532
+				);
533
+			}
534
+		}
535
+		return $global_message_template_group;
536
+	}
537
+
538
+
539
+	/**
540
+	 * Returns an array of event ids for all the events within the current data handler.
541
+	 *
542
+	 * @return array
543
+	 */
544
+	protected function _get_event_ids_from_current_data_handler()
545
+	{
546
+		$event_ids = array();
547
+		foreach ($this->_current_data_handler->events as $event) {
548
+			$event_ids[$event['ID']] = $event['ID'];
549
+		}
550
+		return $event_ids;
551
+	}
552
+
553
+
554
+	/**
555
+	 *  Retrieves formatted array of template information for each context specific to the given
556
+	 *  EE_Message_Template_Group
557
+	 *
558
+	 * @param EE_Message_Template_Group $message_template_group
559
+	 * @return array The returned array is in this structure:
560
+	 *                          array(
561
+	 *                          'field_name' => array(
562
+	 *                          'context' => 'content'
563
+	 *                          )
564
+	 *                          )
565
+	 * @throws EE_Error
566
+	 */
567
+	protected function _get_templates(EE_Message_Template_Group $message_template_group)
568
+	{
569
+		$templates         = array();
570
+		$context_templates = $message_template_group->context_templates();
571
+		foreach ($context_templates as $context => $template_fields) {
572
+			foreach ($template_fields as $template_field => $template_obj) {
573
+				if (! $template_obj instanceof EE_Message_Template) {
574
+					continue;
575
+				}
576
+				$templates[$template_field][$context] = $template_obj->get('MTP_content');
577
+			}
578
+		}
579
+		return $templates;
580
+	}
581
+
582
+
583
+	/**
584
+	 * Assembles new fully generated EE_Message objects and adds to _ready_queue
585
+	 *
586
+	 * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
587
+	 *                                               context.
588
+	 * @param array                     $templates   formatted array of templates used for parsing data.
589
+	 * @param EE_Message_Template_Group $message_template_group
590
+	 * @return bool true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
591
+	 *                                               method will attempt to generate ALL EE_Message objects and add to
592
+	 *                                               the _ready_queue.  Successfully generated messages get added to the
593
+	 *                                               queue with EEM_Message::status_idle, unsuccessfully generated
594
+	 *                                               messages will get added to the queue as EEM_Message::status_failed.
595
+	 *                                               Very rarely should "false" be returned from this method.
596
+	 * @throws EE_Error
597
+	 */
598
+	protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
599
+	{
600
+
601
+		//if templates are empty then get out because we can't generate anything.
602
+		if (! $templates) {
603
+			$this->_error_msg[] = esc_html__(
604
+				'Unable to assemble messages because there are no templates retrieved for generating the messages with',
605
+				'event_espresso'
606
+			);
607
+			return false;
608
+		}
609
+
610
+		//We use this as the counter for generated messages because don't forget we may be executing this inside of a
611
+		//generation_queue.  So _ready_queue may have generated EE_Message objects already.
612
+		$generated_count = 0;
613
+		foreach ($addressees as $context => $recipients) {
614
+			foreach ($recipients as $recipient) {
615
+				$message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
616
+				if ($message instanceof EE_Message) {
617
+					$this->_ready_queue->add(
618
+						$message,
619
+						array(),
620
+						$this->_generation_queue->get_message_repository()->is_preview(),
621
+						$this->_generation_queue->get_message_repository()->is_test_send()
622
+					);
623
+					$generated_count++;
624
+				}
625
+
626
+				//if the current MSG being generated is for a test send then we'll only use ONE message in the
627
+				// generation.
628
+				if ($this->_generation_queue->get_message_repository()->is_test_send()) {
629
+					break 2;
630
+				}
631
+			}
632
+		}
633
+
634
+		//if there are no generated messages then something else fatal went wrong.
635
+		return $generated_count > 0;
636
+	}
637
+
638
+
639
+	/**
640
+	 * @param string                    $context   The context for the generated message.
641
+	 * @param EE_Messages_Addressee     $recipient
642
+	 * @param array                     $templates formatted array of templates used for parsing data.
643
+	 * @param EE_Message_Template_Group $message_template_group
644
+	 * @return bool|EE_Message
645
+	 * @throws EE_Error
646
+	 */
647
+	protected function _setup_message_object(
648
+		$context,
649
+		EE_Messages_Addressee $recipient,
650
+		$templates,
651
+		EE_Message_Template_Group $message_template_group
652
+	) {
653
+		//stuff we already know
654
+		$transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
655
+		$transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
656
+			? $this->_current_data_handler->txn->ID()
657
+			: $transaction_id;
658
+		$message_fields = array(
659
+			'GRP_ID'           => $message_template_group->ID(),
660
+			'TXN_ID'           => $transaction_id,
661
+			'MSG_messenger'    => $this->_current_messenger->name,
662
+			'MSG_message_type' => $this->_current_message_type->name,
663
+			'MSG_context'      => $context,
664
+		);
665
+
666
+		//recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
667
+		// the info from the att_obj found in the EE_Messages_Addressee object.
668
+		if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
669
+			$message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
670
+				? $recipient->att_obj->ID()
671
+				: 0;
672
+			$message_fields['MSG_recipient_type'] = 'Attendee';
673
+		} else {
674
+			$message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
675
+			$message_fields['MSG_recipient_type'] = $recipient->recipient_type;
676
+		}
677
+		$message = EE_Message_Factory::create($message_fields);
678
+
679
+		//grab valid shortcodes for shortcode parser
680
+		$mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
681
+		$m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
682
+
683
+		//if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing
684
+		if ((
685
+				(
686
+					empty($templates['to'][$context])
687
+					&& ! $this->_current_messenger->allow_empty_to_field()
688
+				)
689
+				|| ! $message_template_group->is_context_active($context)
690
+			)
691
+			&& ! $this->_generation_queue->get_message_repository()->is_preview()
692
+		) {
693
+			//we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
694
+			//field.
695
+			return false;
696
+		}
697
+		$error_msg = array();
698
+		foreach ($templates as $field => $field_context) {
699
+			$error_msg = array();
700
+			//let's setup the valid shortcodes for the incoming context.
701
+			$valid_shortcodes = $mt_shortcodes[$context];
702
+			//merge in valid shortcodes for the field.
703
+			$shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
704
+			if (isset($templates[$field][$context])) {
705
+				//prefix field.
706
+				$column_name = 'MSG_' . $field;
707
+				try {
708
+					$content = $this->_shortcode_parser->parse_message_template(
709
+						$templates[$field][$context],
710
+						$recipient,
711
+						$shortcodes,
712
+						$this->_current_message_type,
713
+						$this->_current_messenger,
714
+						$message
715
+					);
716
+					$message->set_field_or_extra_meta($column_name, $content);
717
+				} catch (EE_Error $e) {
718
+					$error_msg[] = sprintf(
719
+						esc_html__(
720
+							'There was a problem generating the content for the field %s: %s',
721
+							'event_espresso'
722
+						),
723
+						$field,
724
+						$e->getMessage()
725
+					);
726
+					$message->set_STS_ID(EEM_Message::status_failed);
727
+				}
728
+			}
729
+		}
730
+
731
+		if ($message->STS_ID() === EEM_Message::status_failed) {
732
+			$error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
733
+						 . "\n"
734
+						 . implode("\n", $error_msg);
735
+			$message->set_error_message($error_msg);
736
+		} else {
737
+			$message->set_STS_ID(EEM_Message::status_idle);
738
+		}
739
+		return $message;
740
+	}
741
+
742
+
743
+	/**
744
+	 * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
745
+	 * error message if either is missing.
746
+	 *
747
+	 * @return bool true means there were no errors, false means there were errors.
748
+	 * @throws EE_Error
749
+	 * @throws ReflectionException
750
+	 */
751
+	protected function _verify()
752
+	{
753
+		//reset error message to an empty array.
754
+		$this->_error_msg = array();
755
+		$valid            = true;
756
+		$valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
757
+		$valid            = $valid ? $this->_validate_and_setup_data() : $valid;
758
+
759
+		//set the verified flag so we know everything has been validated.
760
+		$this->_verified = $valid;
761
+
762
+		return $valid;
763
+	}
764
+
765
+
766
+	/**
767
+	 * This accepts an array and validates that it is an array indexed by context with each value being an array of
768
+	 * EE_Messages_Addressee objects.
769
+	 *
770
+	 * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
771
+	 * @return bool
772
+	 */
773
+	protected function _valid_addressees($addressees)
774
+	{
775
+		if (! $addressees || ! is_array($addressees)) {
776
+			return false;
777
+		}
778
+
779
+		foreach ($addressees as $addressee_array) {
780
+			foreach ($addressee_array as $addressee) {
781
+				if (! $addressee instanceof EE_Messages_Addressee) {
782
+					return false;
783
+				}
784
+			}
785
+		}
786
+		return true;
787
+	}
788
+
789
+
790
+	/**
791
+	 * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
792
+	 * queue. This process sets error messages if something is wrong.
793
+	 *
794
+	 * @return bool   true is if there are no errors.  false is if there is.
795
+	 */
796
+	protected function _validate_messenger_and_message_type()
797
+	{
798
+
799
+		//first are there any existing error messages?  If so then return.
800
+		if ($this->_error_msg) {
801
+			return false;
802
+		}
803
+		/** @type EE_Message $message */
804
+		$message = $this->_generation_queue->get_message_repository()->current();
805
+		try {
806
+			$this->_current_messenger = $message->valid_messenger(true)
807
+				? $message->messenger_object()
808
+				: null;
809
+		} catch (Exception $e) {
810
+			$this->_error_msg[] = $e->getMessage();
811
+		}
812
+		try {
813
+			$this->_current_message_type = $message->valid_message_type(true)
814
+				? $message->message_type_object()
815
+				: null;
816
+		} catch (Exception $e) {
817
+			$this->_error_msg[] = $e->getMessage();
818
+		}
819
+
820
+		/**
821
+		 * Check if there is any generation data, but only if this is not for a preview.
822
+		 */
823
+		if (! $this->_generation_queue->get_message_repository()->get_generation_data()
824
+			&& (
825
+				! $this->_generation_queue->get_message_repository()->is_preview()
826
+				&& $this->_generation_queue->get_message_repository()->get_data_handler()
827
+				   !== 'EE_Messages_Preview_incoming_data'
828
+			)
829
+		) {
830
+			$this->_error_msg[] = esc_html__(
831
+				'There is no generation data for this message. Unable to generate.',
832
+				'event_espresso'
833
+			);
834
+		}
835
+
836
+		return empty($this->_error_msg);
837
+	}
838
+
839
+
840
+	/**
841
+	 * This method retrieves the expected data handler for the message type and validates the generation data for that
842
+	 * data handler.
843
+	 *
844
+	 * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
845
+	 * @throws EE_Error
846
+	 * @throws ReflectionException
847
+	 */
848
+	protected function _validate_and_setup_data()
849
+	{
850
+
851
+		//First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
852
+		//be used anyways.
853
+		if ($this->_error_msg) {
854
+			return false;
855
+		}
856
+
857
+		$generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
858
+
859
+		/** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
860
+		$data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
861
+			? $this->_generation_queue->get_message_repository()->get_data_handler()
862
+			: 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
863
+
864
+		//If this EE_Message is for a preview, then let's switch out to the preview data handler.
865
+		if ($this->_generation_queue->get_message_repository()->is_preview()) {
866
+			$data_handler_class_name = 'EE_Messages_Preview_incoming_data';
867
+		}
868
+
869
+		//First get the class name for the data handler (and also verifies it exists.
870
+		if (! class_exists($data_handler_class_name)) {
871
+			$this->_error_msg[] = sprintf(
872
+				esc_html__(
873
+					'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
874
+					'event_espresso'
875
+				),
876
+				'EE_Messages_incoming_data',
877
+				$data_handler_class_name
878
+			);
879
+			return false;
880
+		}
881
+
882
+		//convert generation_data for data_handler_instantiation.
883
+		$generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
884
+
885
+		//note, this may set error messages as well.
886
+		$this->_set_data_handler($generation_data, $data_handler_class_name);
887
+
888
+		return empty($this->_error_msg);
889
+	}
890
+
891
+
892
+	/**
893
+	 * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
894
+	 * adds it to the _data repository.
895
+	 *
896
+	 * @param mixed  $generating_data           This is data expected by the instantiated data handler.
897
+	 * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
898
+	 *                                          instantiated.
899
+	 * @return void .
900
+	 * @throws EE_Error
901
+	 * @throws ReflectionException
902
+	 */
903
+	protected function _set_data_handler($generating_data, $data_handler_class_name)
904
+	{
905
+		//valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
906
+		//is already a ready data handler in the repository.
907
+		$this->_current_data_handler = $this->_data_handler_collection->get_by_key(
908
+			$this->_data_handler_collection->get_key(
909
+				$data_handler_class_name,
910
+				$generating_data
911
+			)
912
+		);
913
+		if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
914
+			//no saved data_handler in the repo so let's set one up and add it to the repo.
915
+			try {
916
+				$this->_current_data_handler = new $data_handler_class_name($generating_data);
917
+				$this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
918
+			} catch (EE_Error $e) {
919
+				$this->_error_msg[] = $e->get_error();
920
+			}
921
+		}
922
+	}
923
+
924
+
925
+	/**
926
+	 * The queued EE_Message for generation does not save the data used for generation as objects
927
+	 * because serialization of those objects could be problematic if the data is saved to the db.
928
+	 * So this method calls the static method on the associated data_handler for the given message_type
929
+	 * and that preps the data for later instantiation when generating.
930
+	 *
931
+	 * @param EE_Message_To_Generate $message_to_generate
932
+	 * @param bool                   $preview Indicate whether this is being used for a preview or not.
933
+	 * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
934
+	 */
935
+	protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
936
+	{
937
+		/** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
938
+		$data_handler = $message_to_generate->get_data_handler_class_name($preview);
939
+		if (! $message_to_generate->valid()) {
940
+			return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
941
+		}
942
+		return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
943
+	}
944
+
945
+
946
+	/**
947
+	 * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
948
+	 *
949
+	 * @param EE_Message_To_Generate $message_to_generate
950
+	 * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
951
+	 * @throws InvalidArgumentException
952
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
953
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
954
+	 */
955
+	public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
956
+	{
957
+		//prep data
958
+		$data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
959
+
960
+		$message = $message_to_generate->get_EE_Message();
961
+
962
+		//is there a GRP_ID in the request?
963
+		if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
964
+			$message->set_GRP_ID($GRP_ID);
965
+		}
966
+
967
+		if ($data === false) {
968
+			$message->set_STS_ID(EEM_Message::status_failed);
969
+			$message->set_error_message(
970
+				esc_html__(
971
+					'Unable to prepare data for persistence to the database.',
972
+					'event_espresso'
973
+				)
974
+			);
975
+		} else {
976
+			//make sure that the data handler is cached on the message as well
977
+			$data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
978
+		}
979
+
980
+		$this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
981
+	}
982 982
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
     {
260 260
         //double check verification has run and that everything is ready to work with (saves us having to validate
261 261
         // everything again).
262
-        if (! $this->_verified) {
262
+        if ( ! $this->_verified) {
263 263
             return false; //get out because we don't have a valid setup to work with.
264 264
         }
265 265
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 
277 277
 
278 278
         //if no addressees then get out because there is nothing to generation (possible bad data).
279
-        if (! $this->_valid_addressees($addressees)) {
279
+        if ( ! $this->_valid_addressees($addressees)) {
280 280
             do_action(
281 281
                 'AHEE__EE_Messages_Generator___generate__invalid_addressees',
282 282
                 $this->_generation_queue->get_message_repository()->current(),
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         $message_template_group = $this->_get_message_template_group();
299 299
 
300 300
         //in the unlikely event there is no EE_Message_Template_Group available, get out!
301
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
301
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
302 302
             $this->_error_msg[] = esc_html__(
303 303
                 'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
304 304
                 'event_espresso'
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
             //attempt to retrieve from repo first
409 409
             $message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
410 410
             if ($message_template_group instanceof EE_Message_Template_Group) {
411
-                return $message_template_group;  //got it!
411
+                return $message_template_group; //got it!
412 412
             }
413 413
 
414 414
             //nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
         );
514 514
 
515 515
         //if we don't have a group lets hit the db.
516
-        if (! $global_message_template_group instanceof EE_Message_Template_Group) {
516
+        if ( ! $global_message_template_group instanceof EE_Message_Template_Group) {
517 517
             $global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
518 518
                 array(
519 519
                     array(
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         $context_templates = $message_template_group->context_templates();
571 571
         foreach ($context_templates as $context => $template_fields) {
572 572
             foreach ($template_fields as $template_field => $template_obj) {
573
-                if (! $template_obj instanceof EE_Message_Template) {
573
+                if ( ! $template_obj instanceof EE_Message_Template) {
574 574
                     continue;
575 575
                 }
576 576
                 $templates[$template_field][$context] = $template_obj->get('MTP_content');
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
     {
600 600
 
601 601
         //if templates are empty then get out because we can't generate anything.
602
-        if (! $templates) {
602
+        if ( ! $templates) {
603 603
             $this->_error_msg[] = esc_html__(
604 604
                 'Unable to assemble messages because there are no templates retrieved for generating the messages with',
605 605
                 'event_espresso'
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
             $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
704 704
             if (isset($templates[$field][$context])) {
705 705
                 //prefix field.
706
-                $column_name = 'MSG_' . $field;
706
+                $column_name = 'MSG_'.$field;
707 707
                 try {
708 708
                     $content = $this->_shortcode_parser->parse_message_template(
709 709
                         $templates[$field][$context],
@@ -772,13 +772,13 @@  discard block
 block discarded – undo
772 772
      */
773 773
     protected function _valid_addressees($addressees)
774 774
     {
775
-        if (! $addressees || ! is_array($addressees)) {
775
+        if ( ! $addressees || ! is_array($addressees)) {
776 776
             return false;
777 777
         }
778 778
 
779 779
         foreach ($addressees as $addressee_array) {
780 780
             foreach ($addressee_array as $addressee) {
781
-                if (! $addressee instanceof EE_Messages_Addressee) {
781
+                if ( ! $addressee instanceof EE_Messages_Addressee) {
782 782
                     return false;
783 783
                 }
784 784
             }
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
         /**
821 821
          * Check if there is any generation data, but only if this is not for a preview.
822 822
          */
823
-        if (! $this->_generation_queue->get_message_repository()->get_generation_data()
823
+        if ( ! $this->_generation_queue->get_message_repository()->get_generation_data()
824 824
             && (
825 825
                 ! $this->_generation_queue->get_message_repository()->is_preview()
826 826
                 && $this->_generation_queue->get_message_repository()->get_data_handler()
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
         /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
860 860
         $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
861 861
             ? $this->_generation_queue->get_message_repository()->get_data_handler()
862
-            : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
862
+            : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data';
863 863
 
864 864
         //If this EE_Message is for a preview, then let's switch out to the preview data handler.
865 865
         if ($this->_generation_queue->get_message_repository()->is_preview()) {
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
         }
868 868
 
869 869
         //First get the class name for the data handler (and also verifies it exists.
870
-        if (! class_exists($data_handler_class_name)) {
870
+        if ( ! class_exists($data_handler_class_name)) {
871 871
             $this->_error_msg[] = sprintf(
872 872
                 esc_html__(
873 873
                     'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
                 $generating_data
911 911
             )
912 912
         );
913
-        if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
913
+        if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
914 914
             //no saved data_handler in the repo so let's set one up and add it to the repo.
915 915
             try {
916 916
                 $this->_current_data_handler = new $data_handler_class_name($generating_data);
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
     {
937 937
         /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
938 938
         $data_handler = $message_to_generate->get_data_handler_class_name($preview);
939
-        if (! $message_to_generate->valid()) {
939
+        if ( ! $message_to_generate->valid()) {
940 940
             return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
941 941
         }
942 942
         return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
Please login to merge, or discard this patch.
messages/templates/ee_msg_editor_active_context_element.template.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@  discard block
 block discarded – undo
10 10
  * @var int    $message_template_group_id The ID for the message template group this context belongs to.
11 11
  */
12 12
 $active_message = sprintf(
13
-    esc_html__(
14
-        'The template for %1$s is currently %2$sactive%3$s.',
15
-        'event_espresso'
16
-    ),
17
-    $context_label,
18
-    '<strong>',
19
-    '</strong>'
13
+	esc_html__(
14
+		'The template for %1$s is currently %2$sactive%3$s.',
15
+		'event_espresso'
16
+	),
17
+	$context_label,
18
+	'<strong>',
19
+	'</strong>'
20 20
 );
21 21
 $inactive_message = sprintf(
22
-    esc_html__(
23
-        'The template for %1$s is currently %2$sinactive%3$s.',
24
-        'event_espresso'
25
-    ),
26
-    $context_label,
27
-    '<strong>',
28
-    '</strong>'
22
+	esc_html__(
23
+		'The template for %1$s is currently %2$sinactive%3$s.',
24
+		'event_espresso'
25
+	),
26
+	$context_label,
27
+	'<strong>',
28
+	'</strong>'
29 29
 );
30 30
 ?>
31 31
 <div class="context-active-control-container">
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
         <span id="on-off-nonce-<?php echo $context; ?>" class="hidden"><?php echo $nonce; ?></span>
35 35
         <span class="ee-on-off-toggle-label">
36 36
             <?php
37
-            echo $is_active ? $active_message : $inactive_message;
38
-            ?>
37
+			echo $is_active ? $active_message : $inactive_message;
38
+			?>
39 39
         </span>
40 40
         <div class="hidden js-data">
41 41
             <span class="ee-active-message"><?php echo $active_message; ?></span>
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
         </div>
44 44
         <div class="switch">
45 45
             <?php
46
-            $checked = $is_active ? ' checked="checked"' : '';
47
-            ?>
46
+			$checked = $is_active ? ' checked="checked"' : '';
47
+			?>
48 48
             <input data-grpid="<?php echo $message_template_group_id; ?>" id="ee-on-off-toggle-<?php echo $context; ?>" type="checkbox" class="ee-on-off-toggle ee-toggle-round-flat"<?php echo $checked; ?> value="<?php echo $on_off_action; ?>">
49 49
             <label for="ee-on-off-toggle-<?php echo $context; ?>"></label>
50 50
         </div>
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Template_List_Table.class.php 2 patches
Indentation   +368 added lines, -368 removed lines patch added patch discarded remove patch
@@ -13,373 +13,373 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @return Messages_Admin_Page
18
-     */
19
-    public function get_admin_page()
20
-    {
21
-        return $this->_admin_page;
22
-    }
23
-
24
-
25
-    /**
26
-     * Setup data object
27
-     */
28
-    protected function _setup_data()
29
-    {
30
-        $this->_data           = $this->get_admin_page()->get_message_templates(
31
-            $this->_per_page,
32
-            $this->_view,
33
-            false
34
-        );
35
-        $this->_all_data_count = $this->get_admin_page()->get_message_templates(
36
-            $this->_per_page,
37
-            $this->_view,
38
-            true,
39
-            true
40
-        );
41
-    }
42
-
43
-
44
-    /**
45
-     * Set internal properties
46
-     */
47
-    protected function _set_properties()
48
-    {
49
-        $this->_wp_list_args = array(
50
-            'singular' => esc_html__('Message Template Group', 'event_espresso'),
51
-            'plural'   => esc_html__('Message Template', 'event_espresso'),
52
-            'ajax'     => true, //for now,
53
-            'screen'   => $this->get_admin_page()->get_current_screen()->id,
54
-        );
55
-        $this->_columns      = array(
56
-            //'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57
-            'message_type' => esc_html__('Message Type', 'event_espresso'),
58
-            'messenger'    => esc_html__('Messenger', 'event_espresso'),
59
-            'description'  => esc_html__('Description', 'event_espresso'),
60
-        );
61
-
62
-        $this->_sortable_columns = array(
63
-            'messenger' => array('MTP_messenger' => true),
64
-        );
65
-
66
-        $this->_hidden_columns = array();
67
-    }
68
-
69
-
70
-    /**
71
-     * Overriding the single_row method from parent to verify whether the $item has an accessible
72
-     * message_type or messenger object before generating the row.
73
-     *
74
-     * @param EE_Message_Template_Group $item
75
-     * @return string
76
-     * @throws EE_Error
77
-     */
78
-    public function single_row($item)
79
-    {
80
-        $message_type = $item->message_type_obj();
81
-        $messenger    = $item->messenger_obj();
82
-
83
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
84
-            echo '';
85
-            return;
86
-        }
87
-
88
-        parent::single_row($item);
89
-    }
90
-
91
-
92
-    /**
93
-     * @return array
94
-     * @throws EE_Error
95
-     */
96
-    protected function _get_table_filters()
97
-    {
98
-        $filters = array();
99
-
100
-        //get select inputs
101
-        $select_inputs = array(
102
-            $this->_get_messengers_dropdown_filter(),
103
-            $this->_get_message_types_dropdown_filter(),
104
-        );
105
-
106
-        //set filters to select inputs if they aren't empty
107
-        foreach ($select_inputs as $select_input) {
108
-            if ($select_input) {
109
-                $filters[] = $select_input;
110
-            }
111
-        }
112
-        return $filters;
113
-    }
114
-
115
-    /**
116
-     * We're just removing the search box for message templates, not needed.
117
-     *
118
-     * @param string $text
119
-     * @param string $input_id
120
-     * @return string ;
121
-     */
122
-    public function search_box($text, $input_id)
123
-    {
124
-        return '';
125
-    }
126
-
127
-
128
-    /**
129
-     * Add counts to the _views property
130
-     */
131
-    protected function _add_view_counts()
132
-    {
133
-        foreach ($this->_views as $view => $args) {
134
-            $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
135
-                $this->_per_page,
136
-                $view,
137
-                true,
138
-                true
139
-            );
140
-        }
141
-    }
142
-
143
-
144
-    /**
145
-     * @param EE_Message_Template_Group $item
146
-     * @return string
147
-     */
148
-    public function column_cb($item)
149
-    {
150
-        return '';
151
-    }
152
-
153
-
154
-    /**
155
-     * @param EE_Message_Template_Group $item
156
-     * @return string
157
-     * @throws EE_Error
158
-     */
159
-    public function column_description($item)
160
-    {
161
-        return '<p>' . $item->message_type_obj()->description . '</p>';
162
-    }
163
-
164
-
165
-    /**
166
-     * @param EE_Message_Template_Group $item
167
-     * @return string
168
-     * @throws EE_Error
169
-     */
170
-    public function column_messenger($item)
171
-    {
172
-        //Return the name contents
173
-        return sprintf(
174
-            '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
175
-            /* $1%s */
176
-            $this->_get_name_link_for_messenger($item),
177
-            /* $2%s */
178
-            $item->GRP_ID(),
179
-            /* %4$s */
180
-            $this->_get_context_links($item),
181
-            /* $3%s */
182
-            $this->row_actions($this->_get_actions_for_messenger_column($item))
183
-        );
184
-    }
185
-
186
-    /**
187
-     * column_message_type
188
-     *
189
-     * @param  EE_Message_Template_Group $item message info for the row
190
-     * @return string message_type name
191
-     * @throws EE_Error
192
-     */
193
-    public function column_message_type($item)
194
-    {
195
-        return ucwords($item->message_type_obj()->label['singular']);
196
-    }
197
-
198
-
199
-    /**
200
-     * Generate dropdown filter select input for messengers
201
-     *
202
-     * @param bool $global
203
-     * @return string
204
-     * @throws EE_Error
205
-     */
206
-    protected function _get_messengers_dropdown_filter($global = true)
207
-    {
208
-        $messenger_options                                   = array();
209
-        $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
210
-            array(
211
-                array(
212
-                    'MTP_is_active' => true,
213
-                    'MTP_is_global' => $global,
214
-                ),
215
-                'group_by' => 'MTP_messenger',
216
-            )
217
-        );
218
-
219
-        foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
220
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
221
-                $messenger                          = $active_message_template_group->messenger_obj();
222
-                $messenger_label                    = $messenger instanceof EE_messenger
223
-                    ? $messenger->label['singular']
224
-                    : $active_message_template_group->messenger();
225
-                $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
226
-            }
227
-        }
228
-        return $this->get_admin_page()->get_messengers_select_input($messenger_options);
229
-    }
230
-
231
-
232
-    /**
233
-     * Generate dropdown filter select input for message types
234
-     *
235
-     * @param bool $global
236
-     * @return string
237
-     * @throws EE_Error
238
-     */
239
-    protected function _get_message_types_dropdown_filter($global = true)
240
-    {
241
-        $message_type_options                                   = array();
242
-        $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
243
-            array(
244
-                array(
245
-                    'MTP_is_active' => true,
246
-                    'MTP_is_global' => true,
247
-                ),
248
-                'group_by' => 'MTP_message_type',
249
-            )
250
-        );
251
-
252
-        foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
253
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
254
-                $message_type               = $active_message_template_group->message_type_obj();
255
-                $message_type_label         = $message_type instanceof EE_message_type
256
-                    ? $message_type->label['singular']
257
-                    : $active_message_template_group->message_type();
258
-                $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
259
-            }
260
-        }
261
-        return $this->get_admin_page()->get_message_types_select_input($message_type_options);
262
-    }
263
-
264
-
265
-    /**
266
-     * Return the edit url for the message template group.
267
-     * @param EE_Message_Template_Group $item
268
-     * @return string
269
-     * @throws EE_Error
270
-     */
271
-    protected function _get_edit_url(EE_Message_Template_Group $item)
272
-    {
273
-        $edit_url = '';
274
-        // edit link but only if item isn't trashed.
275
-        if (! $item->get('MTP_deleted')
276
-            && EE_Registry::instance()->CAP->current_user_can(
277
-                'ee_edit_message',
278
-                'espresso_messages_edit_message_template',
279
-                $item->ID()
280
-            )) {
281
-            $edit_url = EE_Admin_Page::add_query_args_and_nonce(
282
-                array(
283
-                    'action' => 'edit_message_template',
284
-                    'id'     => $item->GRP_ID(),
285
-                ),
286
-                EE_MSG_ADMIN_URL
287
-            );
288
-        }
289
-        return $edit_url;
290
-    }
291
-
292
-
293
-    /**
294
-     * Get the context link string for the messenger column.
295
-     * @param EE_Message_Template_Group $item
296
-     * @return string
297
-     * @throws EE_Error
298
-     */
299
-    protected function _get_context_links(EE_Message_Template_Group $item)
300
-    {
301
-        //first check if we even show the context links or not.
302
-        if (! EE_Registry::instance()->CAP->current_user_can(
303
-            'ee_edit_message',
304
-            'espresso_messages_edit_message_template',
305
-            $item->ID()
306
-        )
307
-            || $item->get('MTP_deleted')
308
-        ) {
309
-            return '';
310
-        }
311
-        //we want to display the contexts in here so we need to set them up
312
-        $c_label           = $item->context_label();
313
-        $c_configs         = $item->contexts_config();
314
-        $ctxt              = array();
315
-        $context_templates = $item->context_templates();
316
-        foreach ($context_templates as $context => $template_fields) {
317
-            $mtp_to        = ! empty($context_templates[$context]['to'])
318
-                             && $context_templates[$context]['to'] instanceof EE_Message_Template
319
-                ? $context_templates[$context]['to']->get('MTP_content')
320
-                : null;
321
-            $inactive_class      = (
322
-                empty($mtp_to)
323
-                && ! empty($context_templates[$context]['to'])
324
-            )
325
-            || ! $item->is_context_active($context)
326
-                ? ' mtp-inactive'
327
-                : '';
328
-            $context_title = ucwords($c_configs[$context]['label']);
329
-            $edit_link     = EE_Admin_Page::add_query_args_and_nonce(array(
330
-                'action'  => 'edit_message_template',
331
-                'id'      => $item->GRP_ID(),
332
-                'context' => $context,
333
-            ), EE_MSG_ADMIN_URL);
334
-            $ctxt[]        =  '<a'
335
-                  . ' href="' . $edit_link . '"'
336
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"'
337
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
338
-                  . $context_title
339
-                  . '</a>';
340
-        }
341
-
342
-        return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt);
343
-    }
344
-
345
-
346
-    /**
347
-     * Get the Name string from the messenger column (linked to edit if the context allows for that).
348
-     * @param EE_Message_Template_Group $item
349
-     * @return string
350
-     * @throws EE_Error
351
-     */
352
-    protected function _get_name_link_for_messenger(EE_Message_Template_Group $item)
353
-    {
354
-        $edit_url = $this->_get_edit_url($item);
355
-        return $edit_url
356
-            ? '<a href="' . $edit_url . '"'
357
-              . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
358
-              . ucwords($item->messenger_obj()->label['singular'])
359
-              . '</a>'
360
-            : ucwords($item->messenger_obj()->label['singular']);
361
-    }
362
-
363
-
364
-    /**
365
-     * Return the actions array for the messenger column.
366
-     * @param EE_Message_Template_Group $item
367
-     * @return array
368
-     * @throws EE_Error
369
-     */
370
-    protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item)
371
-    {
372
-        $actions = array();
373
-        if ($edit_url = $this->_get_edit_url($item)) {
374
-            $actions = array(
375
-                'edit' => '<a href="' . $edit_url . '"'
376
-                          . ' class="' . $item->message_type() . '-edit-link"'
377
-                          . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
378
-                          . esc_html__('Edit', 'event_espresso')
379
-                          . '</a>'
380
-            );
381
-        }
382
-        return $actions;
383
-    }
16
+	/**
17
+	 * @return Messages_Admin_Page
18
+	 */
19
+	public function get_admin_page()
20
+	{
21
+		return $this->_admin_page;
22
+	}
23
+
24
+
25
+	/**
26
+	 * Setup data object
27
+	 */
28
+	protected function _setup_data()
29
+	{
30
+		$this->_data           = $this->get_admin_page()->get_message_templates(
31
+			$this->_per_page,
32
+			$this->_view,
33
+			false
34
+		);
35
+		$this->_all_data_count = $this->get_admin_page()->get_message_templates(
36
+			$this->_per_page,
37
+			$this->_view,
38
+			true,
39
+			true
40
+		);
41
+	}
42
+
43
+
44
+	/**
45
+	 * Set internal properties
46
+	 */
47
+	protected function _set_properties()
48
+	{
49
+		$this->_wp_list_args = array(
50
+			'singular' => esc_html__('Message Template Group', 'event_espresso'),
51
+			'plural'   => esc_html__('Message Template', 'event_espresso'),
52
+			'ajax'     => true, //for now,
53
+			'screen'   => $this->get_admin_page()->get_current_screen()->id,
54
+		);
55
+		$this->_columns      = array(
56
+			//'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57
+			'message_type' => esc_html__('Message Type', 'event_espresso'),
58
+			'messenger'    => esc_html__('Messenger', 'event_espresso'),
59
+			'description'  => esc_html__('Description', 'event_espresso'),
60
+		);
61
+
62
+		$this->_sortable_columns = array(
63
+			'messenger' => array('MTP_messenger' => true),
64
+		);
65
+
66
+		$this->_hidden_columns = array();
67
+	}
68
+
69
+
70
+	/**
71
+	 * Overriding the single_row method from parent to verify whether the $item has an accessible
72
+	 * message_type or messenger object before generating the row.
73
+	 *
74
+	 * @param EE_Message_Template_Group $item
75
+	 * @return string
76
+	 * @throws EE_Error
77
+	 */
78
+	public function single_row($item)
79
+	{
80
+		$message_type = $item->message_type_obj();
81
+		$messenger    = $item->messenger_obj();
82
+
83
+		if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
84
+			echo '';
85
+			return;
86
+		}
87
+
88
+		parent::single_row($item);
89
+	}
90
+
91
+
92
+	/**
93
+	 * @return array
94
+	 * @throws EE_Error
95
+	 */
96
+	protected function _get_table_filters()
97
+	{
98
+		$filters = array();
99
+
100
+		//get select inputs
101
+		$select_inputs = array(
102
+			$this->_get_messengers_dropdown_filter(),
103
+			$this->_get_message_types_dropdown_filter(),
104
+		);
105
+
106
+		//set filters to select inputs if they aren't empty
107
+		foreach ($select_inputs as $select_input) {
108
+			if ($select_input) {
109
+				$filters[] = $select_input;
110
+			}
111
+		}
112
+		return $filters;
113
+	}
114
+
115
+	/**
116
+	 * We're just removing the search box for message templates, not needed.
117
+	 *
118
+	 * @param string $text
119
+	 * @param string $input_id
120
+	 * @return string ;
121
+	 */
122
+	public function search_box($text, $input_id)
123
+	{
124
+		return '';
125
+	}
126
+
127
+
128
+	/**
129
+	 * Add counts to the _views property
130
+	 */
131
+	protected function _add_view_counts()
132
+	{
133
+		foreach ($this->_views as $view => $args) {
134
+			$this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
135
+				$this->_per_page,
136
+				$view,
137
+				true,
138
+				true
139
+			);
140
+		}
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param EE_Message_Template_Group $item
146
+	 * @return string
147
+	 */
148
+	public function column_cb($item)
149
+	{
150
+		return '';
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param EE_Message_Template_Group $item
156
+	 * @return string
157
+	 * @throws EE_Error
158
+	 */
159
+	public function column_description($item)
160
+	{
161
+		return '<p>' . $item->message_type_obj()->description . '</p>';
162
+	}
163
+
164
+
165
+	/**
166
+	 * @param EE_Message_Template_Group $item
167
+	 * @return string
168
+	 * @throws EE_Error
169
+	 */
170
+	public function column_messenger($item)
171
+	{
172
+		//Return the name contents
173
+		return sprintf(
174
+			'%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
175
+			/* $1%s */
176
+			$this->_get_name_link_for_messenger($item),
177
+			/* $2%s */
178
+			$item->GRP_ID(),
179
+			/* %4$s */
180
+			$this->_get_context_links($item),
181
+			/* $3%s */
182
+			$this->row_actions($this->_get_actions_for_messenger_column($item))
183
+		);
184
+	}
185
+
186
+	/**
187
+	 * column_message_type
188
+	 *
189
+	 * @param  EE_Message_Template_Group $item message info for the row
190
+	 * @return string message_type name
191
+	 * @throws EE_Error
192
+	 */
193
+	public function column_message_type($item)
194
+	{
195
+		return ucwords($item->message_type_obj()->label['singular']);
196
+	}
197
+
198
+
199
+	/**
200
+	 * Generate dropdown filter select input for messengers
201
+	 *
202
+	 * @param bool $global
203
+	 * @return string
204
+	 * @throws EE_Error
205
+	 */
206
+	protected function _get_messengers_dropdown_filter($global = true)
207
+	{
208
+		$messenger_options                                   = array();
209
+		$active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
210
+			array(
211
+				array(
212
+					'MTP_is_active' => true,
213
+					'MTP_is_global' => $global,
214
+				),
215
+				'group_by' => 'MTP_messenger',
216
+			)
217
+		);
218
+
219
+		foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
220
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
221
+				$messenger                          = $active_message_template_group->messenger_obj();
222
+				$messenger_label                    = $messenger instanceof EE_messenger
223
+					? $messenger->label['singular']
224
+					: $active_message_template_group->messenger();
225
+				$messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
226
+			}
227
+		}
228
+		return $this->get_admin_page()->get_messengers_select_input($messenger_options);
229
+	}
230
+
231
+
232
+	/**
233
+	 * Generate dropdown filter select input for message types
234
+	 *
235
+	 * @param bool $global
236
+	 * @return string
237
+	 * @throws EE_Error
238
+	 */
239
+	protected function _get_message_types_dropdown_filter($global = true)
240
+	{
241
+		$message_type_options                                   = array();
242
+		$active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
243
+			array(
244
+				array(
245
+					'MTP_is_active' => true,
246
+					'MTP_is_global' => true,
247
+				),
248
+				'group_by' => 'MTP_message_type',
249
+			)
250
+		);
251
+
252
+		foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
253
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
254
+				$message_type               = $active_message_template_group->message_type_obj();
255
+				$message_type_label         = $message_type instanceof EE_message_type
256
+					? $message_type->label['singular']
257
+					: $active_message_template_group->message_type();
258
+				$message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
259
+			}
260
+		}
261
+		return $this->get_admin_page()->get_message_types_select_input($message_type_options);
262
+	}
263
+
264
+
265
+	/**
266
+	 * Return the edit url for the message template group.
267
+	 * @param EE_Message_Template_Group $item
268
+	 * @return string
269
+	 * @throws EE_Error
270
+	 */
271
+	protected function _get_edit_url(EE_Message_Template_Group $item)
272
+	{
273
+		$edit_url = '';
274
+		// edit link but only if item isn't trashed.
275
+		if (! $item->get('MTP_deleted')
276
+			&& EE_Registry::instance()->CAP->current_user_can(
277
+				'ee_edit_message',
278
+				'espresso_messages_edit_message_template',
279
+				$item->ID()
280
+			)) {
281
+			$edit_url = EE_Admin_Page::add_query_args_and_nonce(
282
+				array(
283
+					'action' => 'edit_message_template',
284
+					'id'     => $item->GRP_ID(),
285
+				),
286
+				EE_MSG_ADMIN_URL
287
+			);
288
+		}
289
+		return $edit_url;
290
+	}
291
+
292
+
293
+	/**
294
+	 * Get the context link string for the messenger column.
295
+	 * @param EE_Message_Template_Group $item
296
+	 * @return string
297
+	 * @throws EE_Error
298
+	 */
299
+	protected function _get_context_links(EE_Message_Template_Group $item)
300
+	{
301
+		//first check if we even show the context links or not.
302
+		if (! EE_Registry::instance()->CAP->current_user_can(
303
+			'ee_edit_message',
304
+			'espresso_messages_edit_message_template',
305
+			$item->ID()
306
+		)
307
+			|| $item->get('MTP_deleted')
308
+		) {
309
+			return '';
310
+		}
311
+		//we want to display the contexts in here so we need to set them up
312
+		$c_label           = $item->context_label();
313
+		$c_configs         = $item->contexts_config();
314
+		$ctxt              = array();
315
+		$context_templates = $item->context_templates();
316
+		foreach ($context_templates as $context => $template_fields) {
317
+			$mtp_to        = ! empty($context_templates[$context]['to'])
318
+							 && $context_templates[$context]['to'] instanceof EE_Message_Template
319
+				? $context_templates[$context]['to']->get('MTP_content')
320
+				: null;
321
+			$inactive_class      = (
322
+				empty($mtp_to)
323
+				&& ! empty($context_templates[$context]['to'])
324
+			)
325
+			|| ! $item->is_context_active($context)
326
+				? ' mtp-inactive'
327
+				: '';
328
+			$context_title = ucwords($c_configs[$context]['label']);
329
+			$edit_link     = EE_Admin_Page::add_query_args_and_nonce(array(
330
+				'action'  => 'edit_message_template',
331
+				'id'      => $item->GRP_ID(),
332
+				'context' => $context,
333
+			), EE_MSG_ADMIN_URL);
334
+			$ctxt[]        =  '<a'
335
+				  . ' href="' . $edit_link . '"'
336
+				  . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"'
337
+				  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
338
+				  . $context_title
339
+				  . '</a>';
340
+		}
341
+
342
+		return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt);
343
+	}
344
+
345
+
346
+	/**
347
+	 * Get the Name string from the messenger column (linked to edit if the context allows for that).
348
+	 * @param EE_Message_Template_Group $item
349
+	 * @return string
350
+	 * @throws EE_Error
351
+	 */
352
+	protected function _get_name_link_for_messenger(EE_Message_Template_Group $item)
353
+	{
354
+		$edit_url = $this->_get_edit_url($item);
355
+		return $edit_url
356
+			? '<a href="' . $edit_url . '"'
357
+			  . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
358
+			  . ucwords($item->messenger_obj()->label['singular'])
359
+			  . '</a>'
360
+			: ucwords($item->messenger_obj()->label['singular']);
361
+	}
362
+
363
+
364
+	/**
365
+	 * Return the actions array for the messenger column.
366
+	 * @param EE_Message_Template_Group $item
367
+	 * @return array
368
+	 * @throws EE_Error
369
+	 */
370
+	protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item)
371
+	{
372
+		$actions = array();
373
+		if ($edit_url = $this->_get_edit_url($item)) {
374
+			$actions = array(
375
+				'edit' => '<a href="' . $edit_url . '"'
376
+						  . ' class="' . $item->message_type() . '-edit-link"'
377
+						  . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
378
+						  . esc_html__('Edit', 'event_espresso')
379
+						  . '</a>'
380
+			);
381
+		}
382
+		return $actions;
383
+	}
384 384
 }
385 385
 
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      */
28 28
     protected function _setup_data()
29 29
     {
30
-        $this->_data           = $this->get_admin_page()->get_message_templates(
30
+        $this->_data = $this->get_admin_page()->get_message_templates(
31 31
             $this->_per_page,
32 32
             $this->_view,
33 33
             false
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
             'ajax'     => true, //for now,
53 53
             'screen'   => $this->get_admin_page()->get_current_screen()->id,
54 54
         );
55
-        $this->_columns      = array(
55
+        $this->_columns = array(
56 56
             //'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57 57
             'message_type' => esc_html__('Message Type', 'event_espresso'),
58 58
             'messenger'    => esc_html__('Messenger', 'event_espresso'),
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $message_type = $item->message_type_obj();
81 81
         $messenger    = $item->messenger_obj();
82 82
 
83
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
83
+        if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
84 84
             echo '';
85 85
             return;
86 86
         }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      */
159 159
     public function column_description($item)
160 160
     {
161
-        return '<p>' . $item->message_type_obj()->description . '</p>';
161
+        return '<p>'.$item->message_type_obj()->description.'</p>';
162 162
     }
163 163
 
164 164
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
     {
273 273
         $edit_url = '';
274 274
         // edit link but only if item isn't trashed.
275
-        if (! $item->get('MTP_deleted')
275
+        if ( ! $item->get('MTP_deleted')
276 276
             && EE_Registry::instance()->CAP->current_user_can(
277 277
                 'ee_edit_message',
278 278
                 'espresso_messages_edit_message_template',
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     protected function _get_context_links(EE_Message_Template_Group $item)
300 300
     {
301 301
         //first check if we even show the context links or not.
302
-        if (! EE_Registry::instance()->CAP->current_user_can(
302
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
303 303
             'ee_edit_message',
304 304
             'espresso_messages_edit_message_template',
305 305
             $item->ID()
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
                              && $context_templates[$context]['to'] instanceof EE_Message_Template
319 319
                 ? $context_templates[$context]['to']->get('MTP_content')
320 320
                 : null;
321
-            $inactive_class      = (
321
+            $inactive_class = (
322 322
                 empty($mtp_to)
323 323
                 && ! empty($context_templates[$context]['to'])
324 324
             )
@@ -331,15 +331,15 @@  discard block
 block discarded – undo
331 331
                 'id'      => $item->GRP_ID(),
332 332
                 'context' => $context,
333 333
             ), EE_MSG_ADMIN_URL);
334
-            $ctxt[]        =  '<a'
335
-                  . ' href="' . $edit_link . '"'
336
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"'
337
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
334
+            $ctxt[] = '<a'
335
+                  . ' href="'.$edit_link.'"'
336
+                  . ' class="'.$item->message_type().'-'.$context.'-edit-link'.$inactive_class.'"'
337
+                  . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">'
338 338
                   . $context_title
339 339
                   . '</a>';
340 340
         }
341 341
 
342
-        return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt);
342
+        return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])).implode(' | ', $ctxt);
343 343
     }
344 344
 
345 345
 
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
     {
354 354
         $edit_url = $this->_get_edit_url($item);
355 355
         return $edit_url
356
-            ? '<a href="' . $edit_url . '"'
357
-              . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
356
+            ? '<a href="'.$edit_url.'"'
357
+              . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">'
358 358
               . ucwords($item->messenger_obj()->label['singular'])
359 359
               . '</a>'
360 360
             : ucwords($item->messenger_obj()->label['singular']);
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
         $actions = array();
373 373
         if ($edit_url = $this->_get_edit_url($item)) {
374 374
             $actions = array(
375
-                'edit' => '<a href="' . $edit_url . '"'
376
-                          . ' class="' . $item->message_type() . '-edit-link"'
377
-                          . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
375
+                'edit' => '<a href="'.$edit_url.'"'
376
+                          . ' class="'.$item->message_type().'-edit-link"'
377
+                          . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">'
378 378
                           . esc_html__('Edit', 'event_espresso')
379 379
                           . '</a>'
380 380
             );
Please login to merge, or discard this patch.
acceptance_tests/Page/MessagesAdmin.php 1 patch
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -14,286 +14,286 @@
 block discarded – undo
14 14
 class MessagesAdmin extends CoreAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * Context slug for the admin messages context.
19
-     * @var string
20
-     */
21
-    const ADMIN_CONTEXT_SLUG = 'admin';
17
+	/**
18
+	 * Context slug for the admin messages context.
19
+	 * @var string
20
+	 */
21
+	const ADMIN_CONTEXT_SLUG = 'admin';
22 22
 
23
-    /**
24
-     * Context slug for the primary attendee messages context
25
-     * @var string
26
-     */
27
-    const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
23
+	/**
24
+	 * Context slug for the primary attendee messages context
25
+	 * @var string
26
+	 */
27
+	const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
28 28
 
29 29
 
30
-    /**
31
-     * Status reference for the EEM_Message::status_sent status.
32
-     * @var string
33
-     */
34
-    const MESSAGE_STATUS_SENT = 'MSN';
30
+	/**
31
+	 * Status reference for the EEM_Message::status_sent status.
32
+	 * @var string
33
+	 */
34
+	const MESSAGE_STATUS_SENT = 'MSN';
35 35
 
36 36
 
37
-    /**
38
-     * Message type slug for the Payment Failed message type
39
-     */
40
-    const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
37
+	/**
38
+	 * Message type slug for the Payment Failed message type
39
+	 */
40
+	const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
41 41
 
42 42
 
43
-    /**
44
-     * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
45
-     * @var string
46
-     */
47
-    const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR =
48
-        '#global_messages_settings-do-messages-on-same-request';
43
+	/**
44
+	 * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
45
+	 * @var string
46
+	 */
47
+	const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR =
48
+		'#global_messages_settings-do-messages-on-same-request';
49 49
 
50 50
 
51
-    /**
52
-     * Selector for the Global Messages Settings submit button in the Messages Settings tab.
53
-     * @var string
54
-     */
55
-    const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
56
-
51
+	/**
52
+	 * Selector for the Global Messages Settings submit button in the Messages Settings tab.
53
+	 * @var string
54
+	 */
55
+	const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
56
+
57 57
 
58
-    /**
59
-     * This is the container where active message types for a messenger are found/dragged to.
60
-     * @var string
61
-     */
62
-    const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types';
63
-
64
-
65
-    /**
66
-     * Locator for the context switcher selector on the Message Template Editor page.
67
-     * @var string
68
-     */
69
-    const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select";
70
-
71
-
72
-    /**
73
-     * Locator for the context switcher submit button in the Message Template Editor page.
74
-     * @var string
75
-     */
76
-    const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt";
77
-
78
-
79
-    /**
80
-     * Locator for the dialog container used for housing viewed messages in the message activity list table.
81
-     * @var string
82
-     */
83
-    const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content';
84
-
85
-
86
-    /**
87
-     * Returns the selector for the on/off toggle for context on the message template editor.
88
-     */
89
-    const MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE =
90
-        "//div[@class='activate_context_on_off_toggle_container']/div[@class='switch']/label";
91
-
92
-
93
-
94
-    /**
95
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
96
-     *                                  a string.
97
-     * @return string
98
-     */
99
-    public static function messageActivityListTableUrl($additional_params = '')
100
-    {
101
-        return self::adminUrl('espresso_messages', 'default', $additional_params);
102
-    }
103
-
104
-
105
-    /**
106
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
107
-     *                                  a string.
108
-     * @return string
109
-     */
110
-    public static function defaultMessageTemplateListTableUrl($additional_params = '')
111
-    {
112
-        return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
113
-    }
114
-
115
-
116
-    /**
117
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
118
-     *                                  a string.
119
-     * @return string
120
-     */
121
-    public static function customMessageTemplateListTableUrl($additional_params = '')
122
-    {
123
-        return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
124
-    }
125
-
126
-
127
-    /**
128
-     * @return string
129
-     */
130
-    public static function messageSettingsUrl()
131
-    {
132
-        return self::adminUrl('espresso_messages', 'settings');
133
-    }
134
-
135
-
136
-
137
-    public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger(
138
-        $message_type_slug,
139
-        $messenger_slug = 'email'
140
-    ) {
141
-        return "#$message_type_slug-messagetype-$messenger_slug";
142
-    }
143
-
144
-
145
-    /**
146
-     * @param string $message_type_slug
147
-     * @param string $context
148
-     * @return string
149
-     */
150
-    public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
151
-    {
152
-        return $context
153
-            ? '.' . $message_type_slug . '-' . $context . '-edit-link'
154
-            : '.' . $message_type_slug . '-edit-link';
155
-    }
156
-
157
-
158
-    /**
159
-     * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
160
-     *
161
-     * @param        $field
162
-     * @param        $message_type_label
163
-     * @param string $message_status
164
-     * @param string $messenger
165
-     * @param string $context
166
-     * @param string $table_cell_content_for_field
167
-     * @param int    $number_in_set   It's possible that the given parameters could match multiple items in the view.
168
-     *                                This allows you to indicate which item from the set to match.  If this is set to 0
169
-     *                                then all matches for the locator will be returned.
170
-     * @return string
171
-     * @throws \InvalidArgumentException
172
-     */
173
-    public static function messagesActivityListTableCellSelectorFor(
174
-        $field,
175
-        $message_type_label,
176
-        $message_status = self::MESSAGE_STATUS_SENT,
177
-        $messenger = 'Email',
178
-        $context = 'Event Admin',
179
-        $table_cell_content_for_field = '',
180
-        $number_in_set = 1
181
-    ) {
182
-        $selector = "//tbody[@id='the-list']";
183
-        $selector .= "//tr[contains(@class, 'msg-status-$message_status')]"
184
-                     . "//td[contains(@class, 'message_type') and text()='$message_type_label']";
185
-        if ($messenger) {
186
-            $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
187
-        }
188
-        $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
189
-        $selector .= $table_cell_content_for_field
190
-            ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
191
-            : "/ancestor::tr/td[contains(@class, 'column-$field')]";
192
-        return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector;
193
-    }
194
-
195
-
196
-    /**
197
-     * Selector for the Create Custom button found in the message template list table.
198
-     * @param string $message_type_label
199
-     * @param string $messenger_label
200
-     * @return string
201
-     */
202
-    public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label)
203
-    {
204
-        $selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']"
205
-                    . "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]"
206
-                    . "//ancestor::tr/td/a[@class='button button-small']";
207
-        return $selector;
208
-    }
209
-
210
-
211
-    /**
212
-     * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to
213
-     * the FIRST match (which will be the latest message sent if the table is default sorted).
214
-     *
215
-     * @param string $message_type_label    The visible message type label for the row you want to match
216
-     * @param string $message_status        The status of the message for the row you want to match.
217
-     * @param string $messenger             The visible messenger label for the row you want to match.
218
-     * @param string $context               The visible context label for the row you want to match.
219
-     * @param int    $number_in_set         It's possible that the given parameters could match multiple items in the
220
-     *                                      view. This allows you to indicate which item from the set to match.
221
-     * @return string
222
-     * @throws \InvalidArgumentException
223
-     */
224
-    public static function messagesActivityListTableViewButtonSelectorFor(
225
-        $message_type_label,
226
-        $message_status = self::MESSAGE_STATUS_SENT,
227
-        $messenger = 'Email',
228
-        $context = 'Event Admin',
229
-        $number_in_set = 1
230
-    ) {
231
-        $selector = self::messagesActivityListTableCellSelectorFor(
232
-            'action',
233
-            $message_type_label,
234
-            $message_status,
235
-            $messenger,
236
-            $context,
237
-            '',
238
-            $number_in_set
239
-        );
240
-        $selector .= "/a/span[contains(@class, 'ee-message-action-link-view')"
241
-                     . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]";
242
-        return $selector;
243
-    }
244
-
245
-
246
-    /**
247
-     * Locator for the delete action link for a message item in the message activity list table.
248
-     * Note: The link is not visible by default, so the column would need hovered over for the link to appear.
249
-     *
250
-     * @param        $message_type_label
251
-     * @param string $message_status
252
-     * @param string $messenger
253
-     * @param string $context
254
-     * @param int    $number_in_set
255
-     * @return string
256
-     * @throws \InvalidArgumentException
257
-     */
258
-    public static function messagesActivityListTableDeleteActionSelectorFor(
259
-        $message_type_label,
260
-        $message_status = self::MESSAGE_STATUS_SENT,
261
-        $messenger = 'Email',
262
-        $context = 'Event Admin',
263
-        $number_in_set = 1
264
-    ) {
265
-        $selector = self::messagesActivityListTableCellSelectorFor(
266
-            'to',
267
-            $message_type_label,
268
-            $message_status,
269
-            $messenger,
270
-            $context,
271
-            '',
272
-            $number_in_set
273
-        );
274
-        $selector .= "/div/span[@class='delete']/a";
275
-        return $selector;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * Returns the input selector for a given field in the message template editor.
282
-     * Assumes one is already viewing the Message Template Editor.
283
-     * @param string     $field
284
-     * @return string
285
-     */
286
-    public static function messageInputFieldSelectorFor($field)
287
-    {
288
-        return "//div[@id='post-body']//input[@id='$field-content']";
289
-    }
290
-
291
-
292
-    /**
293
-     * Wrapper for self::messageInputFieldSelectorFor('to') that takes care of getting the input for the To field.
294
-     */
295
-    public static function messageTemplateToFieldSelector()
296
-    {
297
-        return self::messageInputFieldSelectorFor('to');
298
-    }
58
+	/**
59
+	 * This is the container where active message types for a messenger are found/dragged to.
60
+	 * @var string
61
+	 */
62
+	const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types';
63
+
64
+
65
+	/**
66
+	 * Locator for the context switcher selector on the Message Template Editor page.
67
+	 * @var string
68
+	 */
69
+	const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select";
70
+
71
+
72
+	/**
73
+	 * Locator for the context switcher submit button in the Message Template Editor page.
74
+	 * @var string
75
+	 */
76
+	const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt";
77
+
78
+
79
+	/**
80
+	 * Locator for the dialog container used for housing viewed messages in the message activity list table.
81
+	 * @var string
82
+	 */
83
+	const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content';
84
+
85
+
86
+	/**
87
+	 * Returns the selector for the on/off toggle for context on the message template editor.
88
+	 */
89
+	const MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE =
90
+		"//div[@class='activate_context_on_off_toggle_container']/div[@class='switch']/label";
91
+
92
+
93
+
94
+	/**
95
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
96
+	 *                                  a string.
97
+	 * @return string
98
+	 */
99
+	public static function messageActivityListTableUrl($additional_params = '')
100
+	{
101
+		return self::adminUrl('espresso_messages', 'default', $additional_params);
102
+	}
103
+
104
+
105
+	/**
106
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
107
+	 *                                  a string.
108
+	 * @return string
109
+	 */
110
+	public static function defaultMessageTemplateListTableUrl($additional_params = '')
111
+	{
112
+		return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
113
+	}
114
+
115
+
116
+	/**
117
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
118
+	 *                                  a string.
119
+	 * @return string
120
+	 */
121
+	public static function customMessageTemplateListTableUrl($additional_params = '')
122
+	{
123
+		return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
124
+	}
125
+
126
+
127
+	/**
128
+	 * @return string
129
+	 */
130
+	public static function messageSettingsUrl()
131
+	{
132
+		return self::adminUrl('espresso_messages', 'settings');
133
+	}
134
+
135
+
136
+
137
+	public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger(
138
+		$message_type_slug,
139
+		$messenger_slug = 'email'
140
+	) {
141
+		return "#$message_type_slug-messagetype-$messenger_slug";
142
+	}
143
+
144
+
145
+	/**
146
+	 * @param string $message_type_slug
147
+	 * @param string $context
148
+	 * @return string
149
+	 */
150
+	public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
151
+	{
152
+		return $context
153
+			? '.' . $message_type_slug . '-' . $context . '-edit-link'
154
+			: '.' . $message_type_slug . '-edit-link';
155
+	}
156
+
157
+
158
+	/**
159
+	 * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
160
+	 *
161
+	 * @param        $field
162
+	 * @param        $message_type_label
163
+	 * @param string $message_status
164
+	 * @param string $messenger
165
+	 * @param string $context
166
+	 * @param string $table_cell_content_for_field
167
+	 * @param int    $number_in_set   It's possible that the given parameters could match multiple items in the view.
168
+	 *                                This allows you to indicate which item from the set to match.  If this is set to 0
169
+	 *                                then all matches for the locator will be returned.
170
+	 * @return string
171
+	 * @throws \InvalidArgumentException
172
+	 */
173
+	public static function messagesActivityListTableCellSelectorFor(
174
+		$field,
175
+		$message_type_label,
176
+		$message_status = self::MESSAGE_STATUS_SENT,
177
+		$messenger = 'Email',
178
+		$context = 'Event Admin',
179
+		$table_cell_content_for_field = '',
180
+		$number_in_set = 1
181
+	) {
182
+		$selector = "//tbody[@id='the-list']";
183
+		$selector .= "//tr[contains(@class, 'msg-status-$message_status')]"
184
+					 . "//td[contains(@class, 'message_type') and text()='$message_type_label']";
185
+		if ($messenger) {
186
+			$selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
187
+		}
188
+		$selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
189
+		$selector .= $table_cell_content_for_field
190
+			? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
191
+			: "/ancestor::tr/td[contains(@class, 'column-$field')]";
192
+		return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector;
193
+	}
194
+
195
+
196
+	/**
197
+	 * Selector for the Create Custom button found in the message template list table.
198
+	 * @param string $message_type_label
199
+	 * @param string $messenger_label
200
+	 * @return string
201
+	 */
202
+	public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label)
203
+	{
204
+		$selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']"
205
+					. "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]"
206
+					. "//ancestor::tr/td/a[@class='button button-small']";
207
+		return $selector;
208
+	}
209
+
210
+
211
+	/**
212
+	 * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to
213
+	 * the FIRST match (which will be the latest message sent if the table is default sorted).
214
+	 *
215
+	 * @param string $message_type_label    The visible message type label for the row you want to match
216
+	 * @param string $message_status        The status of the message for the row you want to match.
217
+	 * @param string $messenger             The visible messenger label for the row you want to match.
218
+	 * @param string $context               The visible context label for the row you want to match.
219
+	 * @param int    $number_in_set         It's possible that the given parameters could match multiple items in the
220
+	 *                                      view. This allows you to indicate which item from the set to match.
221
+	 * @return string
222
+	 * @throws \InvalidArgumentException
223
+	 */
224
+	public static function messagesActivityListTableViewButtonSelectorFor(
225
+		$message_type_label,
226
+		$message_status = self::MESSAGE_STATUS_SENT,
227
+		$messenger = 'Email',
228
+		$context = 'Event Admin',
229
+		$number_in_set = 1
230
+	) {
231
+		$selector = self::messagesActivityListTableCellSelectorFor(
232
+			'action',
233
+			$message_type_label,
234
+			$message_status,
235
+			$messenger,
236
+			$context,
237
+			'',
238
+			$number_in_set
239
+		);
240
+		$selector .= "/a/span[contains(@class, 'ee-message-action-link-view')"
241
+					 . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]";
242
+		return $selector;
243
+	}
244
+
245
+
246
+	/**
247
+	 * Locator for the delete action link for a message item in the message activity list table.
248
+	 * Note: The link is not visible by default, so the column would need hovered over for the link to appear.
249
+	 *
250
+	 * @param        $message_type_label
251
+	 * @param string $message_status
252
+	 * @param string $messenger
253
+	 * @param string $context
254
+	 * @param int    $number_in_set
255
+	 * @return string
256
+	 * @throws \InvalidArgumentException
257
+	 */
258
+	public static function messagesActivityListTableDeleteActionSelectorFor(
259
+		$message_type_label,
260
+		$message_status = self::MESSAGE_STATUS_SENT,
261
+		$messenger = 'Email',
262
+		$context = 'Event Admin',
263
+		$number_in_set = 1
264
+	) {
265
+		$selector = self::messagesActivityListTableCellSelectorFor(
266
+			'to',
267
+			$message_type_label,
268
+			$message_status,
269
+			$messenger,
270
+			$context,
271
+			'',
272
+			$number_in_set
273
+		);
274
+		$selector .= "/div/span[@class='delete']/a";
275
+		return $selector;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * Returns the input selector for a given field in the message template editor.
282
+	 * Assumes one is already viewing the Message Template Editor.
283
+	 * @param string     $field
284
+	 * @return string
285
+	 */
286
+	public static function messageInputFieldSelectorFor($field)
287
+	{
288
+		return "//div[@id='post-body']//input[@id='$field-content']";
289
+	}
290
+
291
+
292
+	/**
293
+	 * Wrapper for self::messageInputFieldSelectorFor('to') that takes care of getting the input for the To field.
294
+	 */
295
+	public static function messageTemplateToFieldSelector()
296
+	{
297
+		return self::messageInputFieldSelectorFor('to');
298
+	}
299 299
 }
300 300
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Helpers/MessagesAdmin.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -10,276 +10,276 @@
 block discarded – undo
10 10
  */
11 11
 trait MessagesAdmin
12 12
 {
13
-    /**
14
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
15
-     *                                  a string.
16
-     */
17
-    public function amOnMessagesActivityListTablePage($additional_params = '')
18
-    {
19
-        $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
-    }
13
+	/**
14
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
15
+	 *                                  a string.
16
+	 */
17
+	public function amOnMessagesActivityListTablePage($additional_params = '')
18
+	{
19
+		$this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
+	}
21 21
 
22
-    /**
23
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
24
-     *                                  a string.
25
-     */
26
-    public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
-    {
28
-        $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
-    }
22
+	/**
23
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
24
+	 *                                  a string.
25
+	 */
26
+	public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
+	{
28
+		$this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
34
-     *                                  a string.
35
-     */
36
-    public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
-    {
38
-        $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
-    }
32
+	/**
33
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
34
+	 *                                  a string.
35
+	 */
36
+	public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
+	{
38
+		$this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
+	}
40 40
 
41 41
 
42
-    /**
43
-     * Directs to message settings page
44
-     */
45
-    public function amOnMessageSettingsPage()
46
-    {
47
-        $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
-    }
42
+	/**
43
+	 * Directs to message settings page
44
+	 */
45
+	public function amOnMessageSettingsPage()
46
+	{
47
+		$this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
+	}
49 49
 
50 50
 
51
-    public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
-    {
53
-        $this->actor()->dragAndDrop(
54
-            MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
-            MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
-        );
57
-    }
51
+	public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
+	{
53
+		$this->actor()->dragAndDrop(
54
+			MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
+			MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
+		);
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * Assumes you are already on the list table page that has the ui for editing the template.
62
-     * @param string $message_type_slug
63
-     * @param string $context [optional] if you want to click directly to the given context in the editor
64
-     */
65
-    public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
-    {
67
-        $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
-    }
60
+	/**
61
+	 * Assumes you are already on the list table page that has the ui for editing the template.
62
+	 * @param string $message_type_slug
63
+	 * @param string $context [optional] if you want to click directly to the given context in the editor
64
+	 */
65
+	public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
+	{
67
+		$this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
-     * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
-     *
75
-     * @param int    $expected_occurence_count
76
-     * @param string $text_to_check_for
77
-     * @param string $field
78
-     * @param string $message_type_label
79
-     * @param string $message_status
80
-     * @param string $messenger
81
-     * @param string $context
82
-     */
83
-    public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
-        $expected_occurence_count,
85
-        $text_to_check_for,
86
-        $field,
87
-        $message_type_label,
88
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
-        $messenger = 'Email',
90
-        $context = 'Event Admin'
91
-    ) {
92
-        $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
-            $field,
94
-            $message_type_label,
95
-            $message_status,
96
-            $messenger,
97
-            $context,
98
-            $text_to_check_for,
99
-            0
100
-        ));
101
-        $actual_count = count($elements);
102
-        $this->actor()->assertEquals(
103
-            $expected_occurence_count,
104
-            $actual_count,
105
-            sprintf(
106
-                'Expected %s of the %s text for the %s field but there were actually %s counted.',
107
-                $expected_occurence_count,
108
-                $text_to_check_for,
109
-                $field,
110
-                $actual_count
111
-            )
112
-        );
113
-    }
71
+	/**
72
+	 * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
+	 * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
+	 *
75
+	 * @param int    $expected_occurence_count
76
+	 * @param string $text_to_check_for
77
+	 * @param string $field
78
+	 * @param string $message_type_label
79
+	 * @param string $message_status
80
+	 * @param string $messenger
81
+	 * @param string $context
82
+	 */
83
+	public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
+		$expected_occurence_count,
85
+		$text_to_check_for,
86
+		$field,
87
+		$message_type_label,
88
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
+		$messenger = 'Email',
90
+		$context = 'Event Admin'
91
+	) {
92
+		$elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
+			$field,
94
+			$message_type_label,
95
+			$message_status,
96
+			$messenger,
97
+			$context,
98
+			$text_to_check_for,
99
+			0
100
+		));
101
+		$actual_count = count($elements);
102
+		$this->actor()->assertEquals(
103
+			$expected_occurence_count,
104
+			$actual_count,
105
+			sprintf(
106
+				'Expected %s of the %s text for the %s field but there were actually %s counted.',
107
+				$expected_occurence_count,
108
+				$text_to_check_for,
109
+				$field,
110
+				$actual_count
111
+			)
112
+		);
113
+	}
114 114
 
115 115
 
116
-    /**
117
-     * This will create a custom message template for the given messenger and message type from the context of the
118
-     * default (global) message template list table.
119
-     * Also takes care of verifying the template was created.
120
-     * @param string $message_type_label
121
-     * @param string $messenger_label
122
-     */
123
-    public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label)
124
-    {
125
-        $this->amOnDefaultMessageTemplateListTablePage();
126
-        $this->actor()->click(
127
-            MessagesPage::createCustomButtonForMessageTypeAndMessenger(
128
-                $message_type_label,
129
-                $messenger_label
130
-            )
131
-        );
132
-        $this->actor()->seeInField('#title', 'New Custom Template');
133
-    }
116
+	/**
117
+	 * This will create a custom message template for the given messenger and message type from the context of the
118
+	 * default (global) message template list table.
119
+	 * Also takes care of verifying the template was created.
120
+	 * @param string $message_type_label
121
+	 * @param string $messenger_label
122
+	 */
123
+	public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label)
124
+	{
125
+		$this->amOnDefaultMessageTemplateListTablePage();
126
+		$this->actor()->click(
127
+			MessagesPage::createCustomButtonForMessageTypeAndMessenger(
128
+				$message_type_label,
129
+				$messenger_label
130
+			)
131
+		);
132
+		$this->actor()->seeInField('#title', 'New Custom Template');
133
+	}
134 134
 
135 135
 
136
-    /**
137
-     * This switches the context of the current messages template to the given reference.
138
-     * @param string $context_reference  This should be the visible label for the option.
139
-     */
140
-    public function switchContextTo($context_reference)
141
-    {
142
-        $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference);
143
-        $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR);
144
-        $this->actor()->waitForText($context_reference, 10, 'h1');
145
-    }
136
+	/**
137
+	 * This switches the context of the current messages template to the given reference.
138
+	 * @param string $context_reference  This should be the visible label for the option.
139
+	 */
140
+	public function switchContextTo($context_reference)
141
+	{
142
+		$this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference);
143
+		$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR);
144
+		$this->actor()->waitForText($context_reference, 10, 'h1');
145
+	}
146 146
 
147 147
 
148
-    /**
149
-     * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after
150
-     * toggling.
151
-     *
152
-     * @param string $context_string           What context is being switched (used for the expected state text)
153
-     * @param bool   $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive
154
-     *                                         (false)
155
-     */
156
-    public function toggleContextState($context_string, $expected_state_is_active = true)
157
-    {
158
-        $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE);
159
-        if ($expected_state_is_active) {
160
-            $this->actor()->waitForText("The template for $context_string is currently active.");
161
-        } else {
162
-            $this->actor()->waitForText("The template for $context_string is currently inactive");
163
-        }
164
-    }
148
+	/**
149
+	 * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after
150
+	 * toggling.
151
+	 *
152
+	 * @param string $context_string           What context is being switched (used for the expected state text)
153
+	 * @param bool   $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive
154
+	 *                                         (false)
155
+	 */
156
+	public function toggleContextState($context_string, $expected_state_is_active = true)
157
+	{
158
+		$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE);
159
+		if ($expected_state_is_active) {
160
+			$this->actor()->waitForText("The template for $context_string is currently active.");
161
+		} else {
162
+			$this->actor()->waitForText("The template for $context_string is currently inactive");
163
+		}
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * Triggers saving the message template.
169
-     * @param bool $and_close   Use to indicate to click the Save and Close button.
170
-     */
171
-    public function saveMessageTemplate($and_close = false)
172
-    {
173
-        if ($and_close) {
174
-            $this->actor()->click('Save and Close');
175
-        } else {
176
-            $this->actor()->click('Save');
177
-        }
178
-        $this->actor()->waitForText('successfully updated');
179
-    }
167
+	/**
168
+	 * Triggers saving the message template.
169
+	 * @param bool $and_close   Use to indicate to click the Save and Close button.
170
+	 */
171
+	public function saveMessageTemplate($and_close = false)
172
+	{
173
+		if ($and_close) {
174
+			$this->actor()->click('Save and Close');
175
+		} else {
176
+			$this->actor()->click('Save');
177
+		}
178
+		$this->actor()->waitForText('successfully updated');
179
+	}
180 180
 
181 181
 
182
-    /**
183
-     * This takes care of clicking the View Message icon for the given parameters.
184
-     * Assumes you are already viewing the messages activity list table.
185
-     * @param        $message_type_label
186
-     * @param        $message_status
187
-     * @param string $messenger
188
-     * @param string $context
189
-     * @param int    $number_in_set
190
-     */
191
-    public function viewMessageInMessagesListTableFor(
192
-        $message_type_label,
193
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
194
-        $messenger = 'Email',
195
-        $context = 'Event Admin',
196
-        $number_in_set = 1
197
-    ) {
198
-        $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor(
199
-            $message_type_label,
200
-            $message_status,
201
-            $messenger,
202
-            $context,
203
-            $number_in_set
204
-        ));
205
-    }
182
+	/**
183
+	 * This takes care of clicking the View Message icon for the given parameters.
184
+	 * Assumes you are already viewing the messages activity list table.
185
+	 * @param        $message_type_label
186
+	 * @param        $message_status
187
+	 * @param string $messenger
188
+	 * @param string $context
189
+	 * @param int    $number_in_set
190
+	 */
191
+	public function viewMessageInMessagesListTableFor(
192
+		$message_type_label,
193
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
194
+		$messenger = 'Email',
195
+		$context = 'Event Admin',
196
+		$number_in_set = 1
197
+	) {
198
+		$this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor(
199
+			$message_type_label,
200
+			$message_status,
201
+			$messenger,
202
+			$context,
203
+			$number_in_set
204
+		));
205
+	}
206 206
 
207 207
 
208
-    /**
209
-     * Takes care of deleting a message matching the given parameters via the message activity list table.
210
-     * Assumes you are already viewing the messages activity list table.
211
-     * @param        $message_type_label
212
-     * @param        $message_status
213
-     * @param string $messenger
214
-     * @param string $context
215
-     * @param int    $number_in_set
216
-     */
217
-    public function deleteMessageInMessagesListTableFor(
218
-        $message_type_label,
219
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
220
-        $messenger = 'Email',
221
-        $context = 'Event Admin',
222
-        $number_in_set = 1
223
-    ) {
224
-        $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor(
225
-            $message_type_label,
226
-            $message_status,
227
-            $messenger,
228
-            $context,
229
-            $number_in_set
230
-        );
231
-        $this->actor()->moveMouseOver(
232
-            MessagesPage::messagesActivityListTableCellSelectorFor(
233
-                'to',
234
-                $message_type_label,
235
-                $message_status,
236
-                $messenger,
237
-                $context,
238
-                '',
239
-                $number_in_set
240
-            ),
241
-            5,
242
-            5
243
-        );
244
-        $this->actor()->waitForElementVisible(
245
-            $delete_action_selector
246
-        );
247
-        $this->actor()->click(
248
-            $delete_action_selector
249
-        );
250
-        $this->actor()->waitForText('successfully deleted');
251
-    }
208
+	/**
209
+	 * Takes care of deleting a message matching the given parameters via the message activity list table.
210
+	 * Assumes you are already viewing the messages activity list table.
211
+	 * @param        $message_type_label
212
+	 * @param        $message_status
213
+	 * @param string $messenger
214
+	 * @param string $context
215
+	 * @param int    $number_in_set
216
+	 */
217
+	public function deleteMessageInMessagesListTableFor(
218
+		$message_type_label,
219
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
220
+		$messenger = 'Email',
221
+		$context = 'Event Admin',
222
+		$number_in_set = 1
223
+	) {
224
+		$delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor(
225
+			$message_type_label,
226
+			$message_status,
227
+			$messenger,
228
+			$context,
229
+			$number_in_set
230
+		);
231
+		$this->actor()->moveMouseOver(
232
+			MessagesPage::messagesActivityListTableCellSelectorFor(
233
+				'to',
234
+				$message_type_label,
235
+				$message_status,
236
+				$messenger,
237
+				$context,
238
+				'',
239
+				$number_in_set
240
+			),
241
+			5,
242
+			5
243
+		);
244
+		$this->actor()->waitForElementVisible(
245
+			$delete_action_selector
246
+		);
247
+		$this->actor()->click(
248
+			$delete_action_selector
249
+		);
250
+		$this->actor()->waitForText('successfully deleted');
251
+	}
252 252
 
253 253
 
254
-    /**
255
-     * Assuming you have already triggered the view modal for a single message from the context of the message activity
256
-     * list table, this will take care of validating the given text is in that window.
257
-     * @param string $text_to_view
258
-     */
259
-    public function seeTextInViewMessageModal($text_to_view, $should_not_see = false)
260
-    {
261
-        $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
262
-        $this->actor()->switchToIframe('message-view-window');
263
-        $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view);
264
-        $this->actor()->switchToIframe();
265
-    }
254
+	/**
255
+	 * Assuming you have already triggered the view modal for a single message from the context of the message activity
256
+	 * list table, this will take care of validating the given text is in that window.
257
+	 * @param string $text_to_view
258
+	 */
259
+	public function seeTextInViewMessageModal($text_to_view, $should_not_see = false)
260
+	{
261
+		$this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
262
+		$this->actor()->switchToIframe('message-view-window');
263
+		$should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view);
264
+		$this->actor()->switchToIframe();
265
+	}
266 266
 
267 267
 
268
-    /**
269
-     * Assuming you have already triggered the view modal for a single message from the context of the message activity
270
-     * list table, this will take care of validating the given text is NOT that window.
271
-     * @param string $text_to_view
272
-     */
273
-    public function dontSeeTextInViewMessageModal($text_to_view)
274
-    {
275
-        $this->seeTextInViewMessageModal($text_to_view, true);
276
-    }
268
+	/**
269
+	 * Assuming you have already triggered the view modal for a single message from the context of the message activity
270
+	 * list table, this will take care of validating the given text is NOT that window.
271
+	 * @param string $text_to_view
272
+	 */
273
+	public function dontSeeTextInViewMessageModal($text_to_view)
274
+	{
275
+		$this->seeTextInViewMessageModal($text_to_view, true);
276
+	}
277 277
 
278 278
 
279
-    public function dismissMessageModal()
280
-    {
281
-        $this->actor()->click('#espresso-admin-page-overlay-dv');
282
-        //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail.
283
-        $this->actor()->click('form#EE_Message_List_Table-table-frm');
284
-    }
279
+	public function dismissMessageModal()
280
+	{
281
+		$this->actor()->click('#espresso-admin-page-overlay-dv');
282
+		//this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail.
283
+		$this->actor()->click('form#EE_Message_List_Table-table-frm');
284
+	}
285 285
 }
Please login to merge, or discard this patch.
acceptance_tests/tests/e-TestContextActivationToggleCept.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
 $event_label = 'Testing Context Deactivation';
9 9
 
10 10
 $I->wantTo(
11
-    'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
-    . ' expected'
11
+	'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
+	. ' expected'
13 13
 );
14 14
 
15 15
 $I->loginAsAdmin();
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 $I->see('The template for Primary Registrant Recipient is currently inactive.');
35 35
 
36 36
 $I->amGoingTo(
37
-    'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
37
+	'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
38 38
 );
39 39
 $I->amOnDefaultEventsListTablePage();
40 40
 $I->click(EventsAdmin::ADD_NEW_EVENT_BUTTON_SELECTOR);
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 $event_link = $I->observeLinkUrlAt(EventsAdmin::EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR);
45 45
 $event_id = $I->observeValueFromInputAt(EventsAdmin::EVENT_EDITOR_EVT_ID_SELECTOR);
46 46
 $test_registration_details = array(
47
-    'fname' => 'ContextTestGuy',
48
-    'lname' => 'ContextTestDude',
49
-    'email' => '[email protected]',
47
+	'fname' => 'ContextTestGuy',
48
+	'lname' => 'ContextTestDude',
49
+	'email' => '[email protected]',
50 50
 );
51 51
 $I->logOut();
52 52
 $I->amOnUrl($event_link);
@@ -63,48 +63,48 @@  discard block
 block discarded – undo
63 63
 $I->amOnMessagesActivityListTablePage();
64 64
 //verify registrant context
65 65
 $I->see(
66
-    $test_registration_details['email'],
67
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
-        'to',
69
-        'Registration Approved',
70
-        MessagesAdmin::MESSAGE_STATUS_SENT,
71
-        '',
72
-        'Registrant'
73
-    )
66
+	$test_registration_details['email'],
67
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
+		'to',
69
+		'Registration Approved',
70
+		MessagesAdmin::MESSAGE_STATUS_SENT,
71
+		'',
72
+		'Registrant'
73
+	)
74 74
 );
75 75
 $I->deleteMessageInMessagesListTableFor(
76
-    'Registration Approved',
77
-    MessagesAdmin::MESSAGE_STATUS_SENT,
78
-    'Email',
79
-    'Registrant'
76
+	'Registration Approved',
77
+	MessagesAdmin::MESSAGE_STATUS_SENT,
78
+	'Email',
79
+	'Registrant'
80 80
 );
81 81
 //verify admin context
82 82
 $I->see(
83
-    '[email protected]',
84
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
-        'to',
86
-        'Registration Approved',
87
-        MessagesAdmin::MESSAGE_STATUS_SENT
88
-    )
83
+	'[email protected]',
84
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
+		'to',
86
+		'Registration Approved',
87
+		MessagesAdmin::MESSAGE_STATUS_SENT
88
+	)
89 89
 );
90 90
 $I->deleteMessageInMessagesListTableFor(
91
-    'Registration Approved'
91
+	'Registration Approved'
92 92
 );
93 93
 //verify primary registrant context is NOT present.
94 94
 $I->dontSee(
95
-    $test_registration_details['email'],
96
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
-        'to',
98
-        'Registration Approved',
99
-        MessagesAdmin::MESSAGE_STATUS_SENT,
100
-        '',
101
-        'Primary Registrant'
102
-    )
95
+	$test_registration_details['email'],
96
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
+		'to',
98
+		'Registration Approved',
99
+		MessagesAdmin::MESSAGE_STATUS_SENT,
100
+		'',
101
+		'Primary Registrant'
102
+	)
103 103
 );
104 104
 
105 105
 $I->amGoingTo(
106
-    'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
-    . ' field to an empty string to verify the message does not send for that context.'
106
+	'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
+	. ' field to an empty string to verify the message does not send for that context.'
108 108
 );
109 109
 $I->amOnDefaultMessageTemplateListTablePage();
110 110
 $I->clickToEditMessageTemplateByMessageType('registration', 'primary_attendee');
@@ -128,41 +128,41 @@  discard block
 block discarded – undo
128 128
 $I->amOnMessagesActivityListTablePage();
129 129
 //verify registrant context
130 130
 $I->see(
131
-    $test_registration_details['email'],
132
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
-        'to',
134
-        'Registration Approved',
135
-        MessagesAdmin::MESSAGE_STATUS_SENT,
136
-        '',
137
-        'Registrant'
138
-    )
131
+	$test_registration_details['email'],
132
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
+		'to',
134
+		'Registration Approved',
135
+		MessagesAdmin::MESSAGE_STATUS_SENT,
136
+		'',
137
+		'Registrant'
138
+	)
139 139
 );
140 140
 $I->deleteMessageInMessagesListTableFor(
141
-    'Registration Approved',
142
-    MessagesAdmin::MESSAGE_STATUS_SENT,
143
-    'Email',
144
-    'Registrant'
141
+	'Registration Approved',
142
+	MessagesAdmin::MESSAGE_STATUS_SENT,
143
+	'Email',
144
+	'Registrant'
145 145
 );
146 146
 //verify admin context
147 147
 $I->see(
148
-    '[email protected]',
149
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
-        'to',
151
-        'Registration Approved',
152
-        MessagesAdmin::MESSAGE_STATUS_SENT
153
-    )
148
+	'[email protected]',
149
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
+		'to',
151
+		'Registration Approved',
152
+		MessagesAdmin::MESSAGE_STATUS_SENT
153
+	)
154 154
 );
155 155
 $I->deleteMessageInMessagesListTableFor(
156
-    'Registration Approved'
156
+	'Registration Approved'
157 157
 );
158 158
 //verify primary registrant context is NOT present.
159 159
 $I->dontSee(
160
-    $test_registration_details['email'],
161
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
-        'to',
163
-        'Registration Approved',
164
-        MessagesAdmin::MESSAGE_STATUS_SENT,
165
-        '',
166
-        'Primary Registrant'
167
-    )
160
+	$test_registration_details['email'],
161
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
+		'to',
163
+		'Registration Approved',
164
+		MessagesAdmin::MESSAGE_STATUS_SENT,
165
+		'',
166
+		'Primary Registrant'
167
+	)
168 168
 );
169 169
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3065,7 +3065,7 @@
 block discarded – undo
3065 3065
      *
3066 3066
      * @param  int  $GRP_ID        The group being deleted
3067 3067
      * @param  bool $include_group whether to delete the Message Template Group as well.
3068
-     * @return bool boolean to indicate the success of the deletes or not.
3068
+     * @return integer boolean to indicate the success of the deletes or not.
3069 3069
      * @throws EE_Error
3070 3070
      * @throws InvalidArgumentException
3071 3071
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         $this->_admin_base_url  = EE_MSG_ADMIN_URL;
94 94
         $this->_admin_base_path = EE_MSG_ADMIN;
95 95
         
96
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
96
+        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array();
97 97
         
98 98
         $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
99 99
         $this->_load_message_resource_manager();
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
             array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
253 253
             $messenger_options
254 254
         );
255
-        $input             = new EE_Select_Input(
255
+        $input = new EE_Select_Input(
256 256
             $messenger_options,
257 257
             array(
258 258
                 'html_name'  => 'ee_messenger_filter_by',
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
             array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291 291
             $message_type_options
292 292
         );
293
-        $input                = new EE_Select_Input(
293
+        $input = new EE_Select_Input(
294 294
             $message_type_options,
295 295
             array(
296 296
                 'html_name'  => 'ee_message_type_filter_by',
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
             array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
329 329
             $context_options
330 330
         );
331
-        $input           = new EE_Select_Input(
331
+        $input = new EE_Select_Input(
332 332
             $context_options,
333 333
             array(
334 334
                 'html_name'  => 'ee_context_filter_by',
@@ -710,53 +710,53 @@  discard block
 block discarded – undo
710 710
     
711 711
     public function messages_help_tab()
712 712
     {
713
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
713
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
714 714
     }
715 715
     
716 716
     
717 717
     public function messengers_help_tab()
718 718
     {
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
719
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
720 720
     }
721 721
     
722 722
     
723 723
     public function message_types_help_tab()
724 724
     {
725
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
725
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
726 726
     }
727 727
     
728 728
     
729 729
     public function messages_overview_help_tab()
730 730
     {
731
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
731
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
732 732
     }
733 733
     
734 734
     
735 735
     public function message_templates_help_tab()
736 736
     {
737
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
737
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
738 738
     }
739 739
     
740 740
     
741 741
     public function edit_message_template_help_tab()
742 742
     {
743
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
743
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
744 744
                         . esc_attr__('Editor Title', 'event_espresso')
745 745
                         . '" />';
746
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
746
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
747 747
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
748 748
                         . '" />';
749
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
749
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
750 750
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
751 751
                         . '" />';
752
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
752
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
753 753
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
754 754
                         . '" />';
755
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
755
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
756 756
                         . esc_attr__('Publish Metabox', 'event_espresso')
757 757
                         . '" />';
758 758
         EEH_Template::display_template(
759
-            EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
759
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
760 760
             $args
761 761
         );
762 762
     }
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
         $this->_set_shortcodes();
768 768
         $args['shortcodes'] = $this->_shortcodes;
769 769
         EEH_Template::display_template(
770
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
770
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
771 771
             $args
772 772
         );
773 773
     }
@@ -775,16 +775,16 @@  discard block
 block discarded – undo
775 775
     
776 776
     public function preview_message_help_tab()
777 777
     {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
778
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
779 779
     }
780 780
     
781 781
     
782 782
     public function settings_help_tab()
783 783
     {
784
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
785
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
786
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
787
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
784
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
785
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
786
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
787
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
788 788
         $args['img3'] = '<div class="switch">'
789 789
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
790 790
                         . ' type="checkbox" checked="checked">'
@@ -795,18 +795,18 @@  discard block
 block discarded – undo
795 795
                         . ' type="checkbox">'
796 796
                         . '<label for="ee-on-off-toggle-on"></label>'
797 797
                         . '</div>';
798
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
798
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
799 799
     }
800 800
     
801 801
     
802 802
     public function load_scripts_styles()
803 803
     {
804
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
804
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
805 805
         wp_enqueue_style('espresso_ee_msg');
806 806
         
807
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
807
+        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js',
808 808
             array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
809
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
809
+        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
810 810
             array('ee-dialog'), EVENT_ESPRESSO_VERSION);
811 811
     }
812 812
     
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
         
839 839
         $this->_set_shortcodes();
840 840
         
841
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
841
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
842 842
             esc_html__(
843 843
                 'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
844 844
                 'event_espresso'
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
         
854 854
         wp_register_script(
855 855
             'ee_msgs_edit_js',
856
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
856
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
857 857
             array('jquery'),
858 858
             EVENT_ESPRESSO_VERSION
859 859
         );
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
     {
897 897
         wp_register_style(
898 898
             'ee-message-settings',
899
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
899
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
900 900
             array(),
901 901
             EVENT_ESPRESSO_VERSION
902 902
         );
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
             }
983 983
             $status_bulk_actions = $common_bulk_actions;
984 984
             //unset bulk actions not applying to status
985
-            if (! empty($status_bulk_actions)) {
985
+            if ( ! empty($status_bulk_actions)) {
986 986
                 switch ($status) {
987 987
                     case EEM_Message::status_idle:
988 988
                     case EEM_Message::status_resend:
@@ -1007,7 +1007,7 @@  discard block
 block discarded – undo
1007 1007
             }
1008 1008
 
1009 1009
             //skip adding messenger executing status to views because it will be included with the Failed view.
1010
-            if ( $status === EEM_Message::status_messenger_executing ) {
1010
+            if ($status === EEM_Message::status_messenger_executing) {
1011 1011
                 continue;
1012 1012
             }
1013 1013
             
@@ -1059,37 +1059,37 @@  discard block
 block discarded – undo
1059 1059
         /** @type array $status_items status legend setup */
1060 1060
         $status_items = array(
1061 1061
             'sent_status'       => array(
1062
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1062
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1063 1063
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1064 1064
             ),
1065 1065
             'idle_status'       => array(
1066
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1066
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1067 1067
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1068 1068
             ),
1069 1069
             'failed_status'     => array(
1070
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1070
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1071 1071
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1072 1072
             ),
1073 1073
             'messenger_executing_status' => array(
1074
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1074
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1075 1075
                 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1076 1076
             ),
1077 1077
             'resend_status'     => array(
1078
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1078
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1079 1079
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1080 1080
             ),
1081 1081
             'incomplete_status' => array(
1082
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1082
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1083 1083
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1084 1084
             ),
1085 1085
             'retry_status'      => array(
1086
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1086
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1087 1087
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1088 1088
             )
1089 1089
         );
1090 1090
         if (EEM_Message::debug()) {
1091 1091
             $status_items['debug_only_status'] = array(
1092
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1092
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1093 1093
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1094 1094
             );
1095 1095
         }
@@ -1101,8 +1101,8 @@  discard block
 block discarded – undo
1101 1101
     protected function _custom_mtps_preview()
1102 1102
     {
1103 1103
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1104
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1105
-            . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1104
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1105
+            . ' alt="'.esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso').'" />';
1106 1106
         $this->_template_args['preview_text'] = '<strong>'
1107 1107
             . esc_html__(
1108 1108
                 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
@@ -1384,7 +1384,7 @@  discard block
 block discarded – undo
1384 1384
                             //let's verify if we need this extra field via the shortcodes parameter.
1385 1385
                             $continue = false;
1386 1386
                             if (isset($extra_array['shortcodes_required'])) {
1387
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1387
+                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1388 1388
                                     if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1389 1389
                                         $continue = true;
1390 1390
                                     }
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
                                 }
1395 1395
                             }
1396 1396
                             
1397
-                            $field_id                                = $reference_field
1397
+                            $field_id = $reference_field
1398 1398
                                                                        . '-'
1399 1399
                                                                        . $extra_field
1400 1400
                                                                        . '-content';
@@ -1402,8 +1402,8 @@  discard block
 block discarded – undo
1402 1402
                             $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1403 1403
                                                                        . $reference_field
1404 1404
                                                                        . '][content]['
1405
-                                                                       . $extra_field . ']';
1406
-                            $css_class                               = isset($extra_array['css_class'])
1405
+                                                                       . $extra_field.']';
1406
+                            $css_class = isset($extra_array['css_class'])
1407 1407
                                 ? $extra_array['css_class']
1408 1408
                                 : '';
1409 1409
                             
@@ -1414,7 +1414,7 @@  discard block
 block discarded – undo
1414 1414
                                     is_array($validators[$extra_field])
1415 1415
                                     && isset($validators[$extra_field]['msg'])
1416 1416
                                 )
1417
-                                ? 'validate-error ' . $css_class
1417
+                                ? 'validate-error '.$css_class
1418 1418
                                 : $css_class;
1419 1419
                             
1420 1420
                             $template_form_fields[$field_id]['value'] = ! empty($message_templates)
@@ -1450,11 +1450,11 @@  discard block
 block discarded – undo
1450 1450
                                 
1451 1451
                             }/**/
1452 1452
                         }
1453
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1454
-                        $templatefield_templatename_id = $reference_field . '-name';
1453
+                        $templatefield_MTP_id          = $reference_field.'-MTP_ID';
1454
+                        $templatefield_templatename_id = $reference_field.'-name';
1455 1455
                         
1456 1456
                         $template_form_fields[$templatefield_MTP_id] = array(
1457
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1457
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1458 1458
                             'label'      => null,
1459 1459
                             'input'      => 'hidden',
1460 1460
                             'type'       => 'int',
@@ -1467,7 +1467,7 @@  discard block
 block discarded – undo
1467 1467
                         );
1468 1468
                         
1469 1469
                         $template_form_fields[$templatefield_templatename_id] = array(
1470
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1470
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1471 1471
                             'label'      => null,
1472 1472
                             'input'      => 'hidden',
1473 1473
                             'type'       => 'string',
@@ -1481,9 +1481,9 @@  discard block
 block discarded – undo
1481 1481
                     }
1482 1482
                     continue; //skip the next stuff, we got the necessary fields here for this dataset.
1483 1483
                 } else {
1484
-                    $field_id                                 = $template_field . '-content';
1484
+                    $field_id                                 = $template_field.'-content';
1485 1485
                     $template_form_fields[$field_id]          = $field_setup_array;
1486
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1486
+                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields['.$template_field.'][content]';
1487 1487
                     $message_template                         = isset($message_templates[$context][$template_field])
1488 1488
                         ? $message_templates[$context][$template_field]
1489 1489
                         : null;
@@ -1506,7 +1506,7 @@  discard block
 block discarded – undo
1506 1506
                     $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1507 1507
                                                                     && in_array($template_field, $v_fields, true)
1508 1508
                                                                     && isset($validators[$template_field]['msg'])
1509
-                        ? 'validate-error ' . $css_class
1509
+                        ? 'validate-error '.$css_class
1510 1510
                         : $css_class;
1511 1511
                     
1512 1512
                     //shortcode selector
@@ -1517,12 +1517,12 @@  discard block
 block discarded – undo
1517 1517
                 
1518 1518
                 //k took care of content field(s) now let's take care of others.
1519 1519
                 
1520
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1521
-                $templatefield_field_templatename_id = $template_field . '-name';
1520
+                $templatefield_MTP_id                = $template_field.'-MTP_ID';
1521
+                $templatefield_field_templatename_id = $template_field.'-name';
1522 1522
                 
1523 1523
                 //foreach template field there are actually two form fields created
1524 1524
                 $template_form_fields[$templatefield_MTP_id] = array(
1525
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1525
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1526 1526
                     'label'      => null,
1527 1527
                     'input'      => 'hidden',
1528 1528
                     'type'       => 'int',
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
                 );
1536 1536
                 
1537 1537
                 $template_form_fields[$templatefield_field_templatename_id] = array(
1538
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1538
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1539 1539
                     'label'      => null,
1540 1540
                     'input'      => 'hidden',
1541 1541
                     'type'       => 'string',
@@ -1653,7 +1653,7 @@  discard block
 block discarded – undo
1653 1653
                 'format'     => '%d',
1654 1654
                 'db-col'     => 'MTP_deleted'
1655 1655
             );
1656
-            $sidebar_form_fields['ee-msg-author']  = array(
1656
+            $sidebar_form_fields['ee-msg-author'] = array(
1657 1657
                 'name'       => 'MTP_user_id',
1658 1658
                 'label'      => esc_html__('Author', 'event_espresso'),
1659 1659
                 'input'      => 'hidden',
@@ -1672,17 +1672,17 @@  discard block
 block discarded – undo
1672 1672
                 'value' => $action
1673 1673
             );
1674 1674
             
1675
-            $sidebar_form_fields['ee-msg-id']        = array(
1675
+            $sidebar_form_fields['ee-msg-id'] = array(
1676 1676
                 'name'  => 'id',
1677 1677
                 'input' => 'hidden',
1678 1678
                 'type'  => 'int',
1679 1679
                 'value' => $GRP_ID
1680 1680
             );
1681 1681
             $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1682
-                'name'  => $action . '_nonce',
1682
+                'name'  => $action.'_nonce',
1683 1683
                 'input' => 'hidden',
1684 1684
                 'type'  => 'string',
1685
-                'value' => wp_create_nonce($action . '_nonce')
1685
+                'value' => wp_create_nonce($action.'_nonce')
1686 1686
             );
1687 1687
             
1688 1688
             if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
@@ -1714,7 +1714,7 @@  discard block
 block discarded – undo
1714 1714
         );
1715 1715
         
1716 1716
         //add preview button
1717
-        $preview_url    = parent::add_query_args_and_nonce(
1717
+        $preview_url = parent::add_query_args_and_nonce(
1718 1718
             array(
1719 1719
                 'message_type' => $message_template_group->message_type(),
1720 1720
                 'messenger'    => $message_template_group->messenger(),
@@ -1724,7 +1724,7 @@  discard block
 block discarded – undo
1724 1724
             ),
1725 1725
             $this->_admin_base_url
1726 1726
         );
1727
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1727
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1728 1728
                           . esc_html__('Preview', 'event_espresso')
1729 1729
                           . '</a>';
1730 1730
         
@@ -1761,7 +1761,7 @@  discard block
 block discarded – undo
1761 1761
         
1762 1762
         $this->_template_path = $this->_template_args['GRP_ID']
1763 1763
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1764
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1764
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1765 1765
         
1766 1766
         //send along EE_Message_Template_Group object for further template use.
1767 1767
         $this->_template_args['MTP'] = $message_template_group;
@@ -1816,7 +1816,7 @@  discard block
 block discarded – undo
1816 1816
     ) {
1817 1817
         $template_args = array(
1818 1818
             'context' => $context,
1819
-            'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1819
+            'nonce' => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1820 1820
             'is_active' => $message_template_group->is_context_active($context),
1821 1821
             'on_off_action' => $message_template_group->is_context_active($context)
1822 1822
                 ? 'context-off'
@@ -1825,7 +1825,7 @@  discard block
 block discarded – undo
1825 1825
             'message_template_group_id' => $message_template_group->ID()
1826 1826
         );
1827 1827
         return EEH_Template::display_template(
1828
-          EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1828
+          EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1829 1829
           $template_args,
1830 1830
           true
1831 1831
         );
@@ -1845,7 +1845,7 @@  discard block
 block discarded – undo
1845 1845
     {
1846 1846
         $success = true;
1847 1847
         //check for required data
1848
-        if (!isset(
1848
+        if ( ! isset(
1849 1849
             $this->_req_data['message_template_group_id'],
1850 1850
             $this->_req_data['context'],
1851 1851
             $this->_req_data['status']
@@ -1862,10 +1862,10 @@  discard block
 block discarded – undo
1862 1862
         $nonce = isset($this->_req_data['toggle_context_nonce'])
1863 1863
             ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1864 1864
             : '';
1865
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1865
+        $nonce_ref = 'activate_'.$this->_req_data['context'].'_toggle_nonce';
1866 1866
         $this->_verify_nonce($nonce, $nonce_ref);
1867 1867
         $status = $this->_req_data['status'];
1868
-        if ($status !== 'off' && $status !=='on') {
1868
+        if ($status !== 'off' && $status !== 'on') {
1869 1869
             EE_Error::add_error(
1870 1870
                 sprintf(
1871 1871
                     esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
@@ -1880,7 +1880,7 @@  discard block
 block discarded – undo
1880 1880
         $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1881 1881
             $this->_req_data['message_template_group_id']
1882 1882
         );
1883
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1883
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1884 1884
             EE_Error::add_error(
1885 1885
                 sprintf(
1886 1886
                     esc_html__(
@@ -2124,7 +2124,7 @@  discard block
 block discarded – undo
2124 2124
         }
2125 2125
         
2126 2126
         //let's add a button to go back to the edit view
2127
-        $query_args             = array(
2127
+        $query_args = array(
2128 2128
             'id'      => $this->_req_data['GRP_ID'],
2129 2129
             'context' => $this->_req_data['context'],
2130 2130
             'action'  => 'edit_message_template'
@@ -2150,7 +2150,7 @@  discard block
 block discarded – undo
2150 2150
         );
2151 2151
         //setup display of preview.
2152 2152
         $this->_admin_page_title                    = $preview_title;
2153
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2153
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview);
2154 2154
         $this->_template_args['data']['force_json'] = true;
2155 2155
         
2156 2156
         return '';
@@ -2256,7 +2256,7 @@  discard block
 block discarded – undo
2256 2256
         }
2257 2257
         
2258 2258
         //setup variation select values for the currently selected template.
2259
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2259
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2260 2260
             $this->_message_template_group->messenger(),
2261 2261
             $this->_message_template_group->message_type()
2262 2262
         );
@@ -2270,12 +2270,12 @@  discard block
 block discarded – undo
2270 2270
         
2271 2271
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2272 2272
         
2273
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2273
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2274 2274
             'MTP_template_pack',
2275 2275
             $tp_select_values,
2276 2276
             $this->_message_template_group->get_template_pack_name()
2277 2277
         );
2278
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2278
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2279 2279
             'MTP_template_variation',
2280 2280
             $variations_select_values,
2281 2281
             $this->_message_template_group->get_template_pack_variation()
@@ -2285,7 +2285,7 @@  discard block
 block discarded – undo
2285 2285
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2286 2286
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2287 2287
         
2288
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2288
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2289 2289
         
2290 2290
         EEH_Template::display_template($template, $template_args);
2291 2291
     }
@@ -2314,14 +2314,14 @@  discard block
 block discarded – undo
2314 2314
         if ( ! empty($fields)) {
2315 2315
             //yup there be fields
2316 2316
             foreach ($fields as $field => $config) {
2317
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2317
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2318 2318
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2319 2319
                 $default  = isset($config['default']) ? $config['default'] : '';
2320 2320
                 $default  = isset($config['value']) ? $config['value'] : $default;
2321 2321
                 
2322 2322
                 // if type is hidden and the value is empty
2323 2323
                 // something may have gone wrong so let's correct with the defaults
2324
-                $fix              = $config['input'] === 'hidden'
2324
+                $fix = $config['input'] === 'hidden'
2325 2325
                                     && isset($existing[$field])
2326 2326
                                     && empty($existing[$field])
2327 2327
                     ? $default
@@ -2331,7 +2331,7 @@  discard block
 block discarded – undo
2331 2331
                     : $fix;
2332 2332
                 
2333 2333
                 $template_form_fields[$field_id] = array(
2334
-                    'name'       => 'test_settings_fld[' . $field . ']',
2334
+                    'name'       => 'test_settings_fld['.$field.']',
2335 2335
                     'label'      => $config['label'],
2336 2336
                     'input'      => $config['input'],
2337 2337
                     'type'       => $config['type'],
@@ -2399,7 +2399,7 @@  discard block
 block discarded – undo
2399 2399
         );
2400 2400
         
2401 2401
         return EEH_Template::display_template(
2402
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2402
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2403 2403
             $template_args,
2404 2404
             true
2405 2405
         );
@@ -2424,7 +2424,7 @@  discard block
 block discarded – undo
2424 2424
         //$messenger = $this->_message_template_group->messenger_obj();
2425 2425
         //now let's set the content depending on the status of the shortcodes array
2426 2426
         if (empty($shortcodes)) {
2427
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2427
+            $content = '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2428 2428
             echo $content;
2429 2429
         } else {
2430 2430
             //$alt = 0;
@@ -2561,7 +2561,7 @@  discard block
 block discarded – undo
2561 2561
                     <?php
2562 2562
                 }
2563 2563
                 //setup nonce_url
2564
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2564
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2565 2565
                 ?>
2566 2566
                 <select name="context">
2567 2567
                     <?php
@@ -2662,7 +2662,7 @@  discard block
 block discarded – undo
2662 2662
         $context      = ucwords(str_replace('_', ' ', $context_slug));
2663 2663
         
2664 2664
         $item_desc = $messenger_label && $message_type_label
2665
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2665
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
2666 2666
             : '';
2667 2667
         $item_desc .= 'Message Template';
2668 2668
         $query_args  = array();
@@ -2764,7 +2764,7 @@  discard block
 block discarded – undo
2764 2764
                                 //default setup for it.
2765 2765
                                 //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2766 2766
                                 $updated = $MTP->insert($message_template_fields);
2767
-                                if (! $updated || is_wp_error($updated)) {
2767
+                                if ( ! $updated || is_wp_error($updated)) {
2768 2768
                                     EE_Error::add_error(
2769 2769
                                         sprintf(
2770 2770
                                             esc_html__('%s field could not be updated.', 'event_espresso'),
@@ -3125,7 +3125,7 @@  discard block
 block discarded – undo
3125 3125
             : 'email';
3126 3126
         
3127 3127
         //let's setup the messenger tabs
3128
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3128
+        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3129 3129
             $this->_m_mt_settings['messenger_tabs'],
3130 3130
             'messenger_links',
3131 3131
             '|',
@@ -3193,10 +3193,10 @@  discard block
 block discarded – undo
3193 3193
                 
3194 3194
                 $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3195 3195
                     'label'    => ucwords($message_type->label['singular']),
3196
-                    'class'    => 'message-type-' . $a_or_i,
3197
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3198
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3199
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3196
+                    'class'    => 'message-type-'.$a_or_i,
3197
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3198
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3199
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3200 3200
                     'title'    => $a_or_i === 'active'
3201 3201
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3202 3202
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3232,9 +3232,9 @@  discard block
 block discarded – undo
3232 3232
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3233 3233
             
3234 3234
             foreach ($fields as $fldname => $fldprops) {
3235
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3235
+                $field_id                       = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3236 3236
                 $template_form_field[$field_id] = array(
3237
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3237
+                    'name'       => 'message_type_settings['.$fldname.']',
3238 3238
                     'label'      => $fldprops['label'],
3239 3239
                     'input'      => $fldprops['field_type'],
3240 3240
                     'type'       => $fldprops['value_type'],
@@ -3285,12 +3285,12 @@  discard block
 block discarded – undo
3285 3285
             $settings_template_args['hidden_fields'],
3286 3286
             'array'
3287 3287
         );
3288
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3288
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3289 3289
             ? ' hidden'
3290 3290
             : '';
3291 3291
         
3292 3292
         
3293
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3293
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3294 3294
         $content  = EEH_Template::display_template($template, $settings_template_args, true);
3295 3295
         
3296 3296
         return $content;
@@ -3325,11 +3325,11 @@  discard block
 block discarded – undo
3325 3325
                 )
3326 3326
                     ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3327 3327
                     : '';
3328
-                $m_boxes[$messenger . '_a_box']         = sprintf(
3328
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3329 3329
                     esc_html__('%s Settings', 'event_espresso'),
3330 3330
                     $tab_array['label']
3331 3331
                 );
3332
-                $m_template_args[$messenger . '_a_box'] = array(
3332
+                $m_template_args[$messenger.'_a_box'] = array(
3333 3333
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3334 3334
                     'inactive_message_types' => isset(
3335 3335
                         $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
@@ -3345,8 +3345,8 @@  discard block
 block discarded – undo
3345 3345
                 // message type meta boxes
3346 3346
                 // (which is really just the inactive container for each messenger
3347 3347
                 // showing inactive message types for that messenger)
3348
-                $mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3349
-                $mt_template_args[$messenger . '_i_box'] = array(
3348
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3349
+                $mt_template_args[$messenger.'_i_box'] = array(
3350 3350
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3351 3351
                     'inactive_message_types' => isset(
3352 3352
                         $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
@@ -3364,14 +3364,14 @@  discard block
 block discarded – undo
3364 3364
         
3365 3365
         
3366 3366
         //register messenger metaboxes
3367
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3367
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3368 3368
         foreach ($m_boxes as $box => $label) {
3369 3369
             $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3370 3370
             $msgr          = str_replace('_a_box', '', $box);
3371 3371
             add_meta_box(
3372
-                'espresso_' . $msgr . '_settings',
3372
+                'espresso_'.$msgr.'_settings',
3373 3373
                 $label,
3374
-                function ($post, $metabox) {
3374
+                function($post, $metabox) {
3375 3375
                     echo EEH_Template::display_template(
3376 3376
                             $metabox["args"]["template_path"],
3377 3377
                             $metabox["args"]["template_args"],
@@ -3386,17 +3386,17 @@  discard block
 block discarded – undo
3386 3386
         }
3387 3387
         
3388 3388
         //register message type metaboxes
3389
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3389
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3390 3390
         foreach ($mt_boxes as $box => $label) {
3391 3391
             $callback_args = array(
3392 3392
                 'template_path' => $mt_template_path,
3393 3393
                 'template_args' => $mt_template_args[$box]
3394 3394
             );
3395
-            $mt            = str_replace('_i_box', '', $box);
3395
+            $mt = str_replace('_i_box', '', $box);
3396 3396
             add_meta_box(
3397
-                'espresso_' . $mt . '_inactive_mts',
3397
+                'espresso_'.$mt.'_inactive_mts',
3398 3398
                 $label,
3399
-                function ($post, $metabox) {
3399
+                function($post, $metabox) {
3400 3400
                     echo EEH_Template::display_template(
3401 3401
                             $metabox["args"]["template_path"],
3402 3402
                             $metabox["args"]["template_args"],
@@ -3543,7 +3543,7 @@  discard block
 block discarded – undo
3543 3543
             if ($form->is_valid()) {
3544 3544
                 $valid_data = $form->valid_data();
3545 3545
                 foreach ($valid_data as $property => $value) {
3546
-                    $setter = 'set_' . $property;
3546
+                    $setter = 'set_'.$property;
3547 3547
                     if (method_exists($network_config, $setter)) {
3548 3548
                         $network_config->{$setter}($value);
3549 3549
                     } else if (
@@ -3578,8 +3578,8 @@  discard block
 block discarded – undo
3578 3578
      */
3579 3579
     protected function _get_mt_tabs($tab_array)
3580 3580
     {
3581
-        $tab_array = (array)$tab_array;
3582
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3581
+        $tab_array = (array) $tab_array;
3582
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3583 3583
         $tabs      = '';
3584 3584
         
3585 3585
         foreach ($tab_array as $tab) {
@@ -3612,9 +3612,9 @@  discard block
 block discarded – undo
3612 3612
             $existing_settings = $messenger->get_existing_admin_settings();
3613 3613
             
3614 3614
             foreach ($fields as $fldname => $fldprops) {
3615
-                $field_id                       = $messenger->name . '-' . $fldname;
3615
+                $field_id                       = $messenger->name.'-'.$fldname;
3616 3616
                 $template_form_field[$field_id] = array(
3617
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3617
+                    'name'       => 'messenger_settings['.$field_id.']',
3618 3618
                     'label'      => $fldprops['label'],
3619 3619
                     'input'      => $fldprops['field_type'],
3620 3620
                     'type'       => $fldprops['value_type'],
@@ -3649,7 +3649,7 @@  discard block
 block discarded – undo
3649 3649
         //make sure any active message types that are existing are included in the hidden fields
3650 3650
         if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3651 3651
             foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3652
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3652
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array(
3653 3653
                     'type'  => 'hidden',
3654 3654
                     'value' => $mt
3655 3655
                 );
@@ -3678,9 +3678,9 @@  discard block
 block discarded – undo
3678 3678
         
3679 3679
         
3680 3680
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3681
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3681
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3682 3682
         $settings_template_args['on_off_status'] = $active ? true : false;
3683
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3683
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3684 3684
         $content                                 = EEH_Template::display_template(
3685 3685
             $template,
3686 3686
             $settings_template_args,
@@ -3720,7 +3720,7 @@  discard block
 block discarded – undo
3720 3720
         $nonce     = isset($this->_req_data['activate_nonce'])
3721 3721
             ? sanitize_text_field($this->_req_data['activate_nonce'])
3722 3722
             : '';
3723
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3723
+        $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce';
3724 3724
         
3725 3725
         $this->_verify_nonce($nonce, $nonce_ref);
3726 3726
         
@@ -3836,7 +3836,7 @@  discard block
 block discarded – undo
3836 3836
         
3837 3837
         //do a nonce check here since we're not arriving via a normal route
3838 3838
         $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3839
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3839
+        $nonce_ref = $this->_req_data['message_type'].'_nonce';
3840 3840
         
3841 3841
         $this->_verify_nonce($nonce, $nonce_ref);
3842 3842
         
@@ -4197,7 +4197,7 @@  discard block
 block discarded – undo
4197 4197
         $message_type = $message_types[$this->_req_data['message_type']];
4198 4198
         $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4199 4199
         
4200
-        $content                         = $this->_message_type_settings_content(
4200
+        $content = $this->_message_type_settings_content(
4201 4201
             $message_type,
4202 4202
             $messenger,
4203 4203
             true
Please login to merge, or discard this patch.
Indentation   +4043 added lines, -4043 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidInterfaceException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('NO direct script access allowed');
8
+	exit('NO direct script access allowed');
9 9
 }
10 10
 
11 11
 /**
@@ -23,2557 +23,2557 @@  discard block
 block discarded – undo
23 23
 class Messages_Admin_Page extends EE_Admin_Page
24 24
 {
25 25
     
26
-    /**
27
-     * @type EE_Message_Resource_Manager $_message_resource_manager
28
-     */
29
-    protected $_message_resource_manager;
26
+	/**
27
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
28
+	 */
29
+	protected $_message_resource_manager;
30 30
     
31
-    /**
32
-     * @type string $_active_message_type_name
33
-     */
34
-    protected $_active_message_type_name = '';
31
+	/**
32
+	 * @type string $_active_message_type_name
33
+	 */
34
+	protected $_active_message_type_name = '';
35 35
     
36
-    /**
37
-     * @type EE_messenger $_active_messenger
38
-     */
39
-    protected $_active_messenger;
40
-    protected $_activate_state;
41
-    protected $_activate_meta_box_type;
42
-    protected $_current_message_meta_box;
43
-    protected $_current_message_meta_box_object;
44
-    protected $_context_switcher;
45
-    protected $_shortcodes = array();
46
-    protected $_active_messengers = array();
47
-    protected $_active_message_types = array();
36
+	/**
37
+	 * @type EE_messenger $_active_messenger
38
+	 */
39
+	protected $_active_messenger;
40
+	protected $_activate_state;
41
+	protected $_activate_meta_box_type;
42
+	protected $_current_message_meta_box;
43
+	protected $_current_message_meta_box_object;
44
+	protected $_context_switcher;
45
+	protected $_shortcodes = array();
46
+	protected $_active_messengers = array();
47
+	protected $_active_message_types = array();
48 48
     
49
-    /**
50
-     * @var EE_Message_Template_Group $_message_template_group
51
-     */
52
-    protected $_message_template_group;
53
-    protected $_m_mt_settings = array();
49
+	/**
50
+	 * @var EE_Message_Template_Group $_message_template_group
51
+	 */
52
+	protected $_message_template_group;
53
+	protected $_m_mt_settings = array();
54 54
     
55 55
     
56
-    /**
57
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
-     * IF there is no group then it gets automatically set to the Default template pack.
59
-     *
60
-     * @since 4.5.0
61
-     *
62
-     * @var EE_Messages_Template_Pack
63
-     */
64
-    protected $_template_pack;
56
+	/**
57
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
58
+	 * IF there is no group then it gets automatically set to the Default template pack.
59
+	 *
60
+	 * @since 4.5.0
61
+	 *
62
+	 * @var EE_Messages_Template_Pack
63
+	 */
64
+	protected $_template_pack;
65 65
     
66 66
     
67
-    /**
68
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
-     * group is.  If there is no group then it automatically gets set to default.
70
-     *
71
-     * @since 4.5.0
72
-     *
73
-     * @var string
74
-     */
75
-    protected $_variation;
67
+	/**
68
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
69
+	 * group is.  If there is no group then it automatically gets set to default.
70
+	 *
71
+	 * @since 4.5.0
72
+	 *
73
+	 * @var string
74
+	 */
75
+	protected $_variation;
76 76
     
77 77
     
78
-    /**
79
-     * @param bool $routing
80
-     */
81
-    public function __construct($routing = true)
82
-    {
83
-        //make sure messages autoloader is running
84
-        EED_Messages::set_autoloaders();
85
-        parent::__construct($routing);
86
-    }
78
+	/**
79
+	 * @param bool $routing
80
+	 */
81
+	public function __construct($routing = true)
82
+	{
83
+		//make sure messages autoloader is running
84
+		EED_Messages::set_autoloaders();
85
+		parent::__construct($routing);
86
+	}
87 87
     
88 88
     
89
-    protected function _init_page_props()
90
-    {
91
-        $this->page_slug        = EE_MSG_PG_SLUG;
92
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
93
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
94
-        $this->_admin_base_path = EE_MSG_ADMIN;
95
-        
96
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
97
-        
98
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
99
-        $this->_load_message_resource_manager();
100
-    }
89
+	protected function _init_page_props()
90
+	{
91
+		$this->page_slug        = EE_MSG_PG_SLUG;
92
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
93
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
94
+		$this->_admin_base_path = EE_MSG_ADMIN;
95
+        
96
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
97
+        
98
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
99
+		$this->_load_message_resource_manager();
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
105
-     *
106
-     * @throws EE_Error
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidInterfaceException
109
-     * @throws InvalidArgumentException
110
-     * @throws ReflectionException
111
-     */
112
-    protected function _load_message_resource_manager()
113
-    {
114
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
115
-    }
103
+	/**
104
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
105
+	 *
106
+	 * @throws EE_Error
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidInterfaceException
109
+	 * @throws InvalidArgumentException
110
+	 * @throws ReflectionException
111
+	 */
112
+	protected function _load_message_resource_manager()
113
+	{
114
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * @deprecated 4.9.9.rc.014
120
-     * @return array
121
-     * @throws EE_Error
122
-     * @throws InvalidArgumentException
123
-     * @throws InvalidDataTypeException
124
-     * @throws InvalidInterfaceException
125
-     */
126
-    public function get_messengers_for_list_table()
127
-    {
128
-        EE_Error::doing_it_wrong(
129
-            __METHOD__,
130
-            sprintf(
131
-                esc_html__(
132
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
133
-                    'event_espresso'
134
-                ),
135
-                'Messages_Admin_Page::get_messengers_select_input()'
136
-            ),
137
-            '4.9.9.rc.014'
138
-        );
139
-        
140
-        $m_values          = array();
141
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
142
-        //setup messengers for selects
143
-        $i = 1;
144
-        foreach ($active_messengers as $active_messenger) {
145
-            if ($active_messenger instanceof EE_Message) {
146
-                $m_values[$i]['id']   = $active_messenger->messenger();
147
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
148
-                $i++;
149
-            }
150
-        }
151
-        
152
-        return $m_values;
153
-    }
118
+	/**
119
+	 * @deprecated 4.9.9.rc.014
120
+	 * @return array
121
+	 * @throws EE_Error
122
+	 * @throws InvalidArgumentException
123
+	 * @throws InvalidDataTypeException
124
+	 * @throws InvalidInterfaceException
125
+	 */
126
+	public function get_messengers_for_list_table()
127
+	{
128
+		EE_Error::doing_it_wrong(
129
+			__METHOD__,
130
+			sprintf(
131
+				esc_html__(
132
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
133
+					'event_espresso'
134
+				),
135
+				'Messages_Admin_Page::get_messengers_select_input()'
136
+			),
137
+			'4.9.9.rc.014'
138
+		);
139
+        
140
+		$m_values          = array();
141
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
142
+		//setup messengers for selects
143
+		$i = 1;
144
+		foreach ($active_messengers as $active_messenger) {
145
+			if ($active_messenger instanceof EE_Message) {
146
+				$m_values[$i]['id']   = $active_messenger->messenger();
147
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
148
+				$i++;
149
+			}
150
+		}
151
+        
152
+		return $m_values;
153
+	}
154 154
 
155 155
 
156
-    /**
157
-     * @deprecated 4.9.9.rc.014
158
-     * @return array
159
-     * @throws EE_Error
160
-     * @throws InvalidArgumentException
161
-     * @throws InvalidDataTypeException
162
-     * @throws InvalidInterfaceException
163
-     */
164
-    public function get_message_types_for_list_table()
165
-    {
166
-        EE_Error::doing_it_wrong(
167
-            __METHOD__,
168
-            sprintf(
169
-                esc_html__(
170
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
171
-                    'event_espresso'
172
-                ),
173
-                'Messages_Admin_Page::get_message_types_select_input()'
174
-            ),
175
-            '4.9.9.rc.014'
176
-        );
177
-        
178
-        $mt_values       = array();
179
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
180
-        $i               = 1;
181
-        foreach ($active_messages as $active_message) {
182
-            if ($active_message instanceof EE_Message) {
183
-                $mt_values[$i]['id']   = $active_message->message_type();
184
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
185
-                $i++;
186
-            }
187
-        }
188
-        
189
-        return $mt_values;
190
-    }
156
+	/**
157
+	 * @deprecated 4.9.9.rc.014
158
+	 * @return array
159
+	 * @throws EE_Error
160
+	 * @throws InvalidArgumentException
161
+	 * @throws InvalidDataTypeException
162
+	 * @throws InvalidInterfaceException
163
+	 */
164
+	public function get_message_types_for_list_table()
165
+	{
166
+		EE_Error::doing_it_wrong(
167
+			__METHOD__,
168
+			sprintf(
169
+				esc_html__(
170
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
171
+					'event_espresso'
172
+				),
173
+				'Messages_Admin_Page::get_message_types_select_input()'
174
+			),
175
+			'4.9.9.rc.014'
176
+		);
177
+        
178
+		$mt_values       = array();
179
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
180
+		$i               = 1;
181
+		foreach ($active_messages as $active_message) {
182
+			if ($active_message instanceof EE_Message) {
183
+				$mt_values[$i]['id']   = $active_message->message_type();
184
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
185
+				$i++;
186
+			}
187
+		}
188
+        
189
+		return $mt_values;
190
+	}
191 191
 
192 192
 
193
-    /**
194
-     * @deprecated 4.9.9.rc.014
195
-     * @return array
196
-     * @throws EE_Error
197
-     * @throws InvalidArgumentException
198
-     * @throws InvalidDataTypeException
199
-     * @throws InvalidInterfaceException
200
-     */
201
-    public function get_contexts_for_message_types_for_list_table()
202
-    {
203
-        EE_Error::doing_it_wrong(
204
-            __METHOD__,
205
-            sprintf(
206
-                esc_html__(
207
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
208
-                    'event_espresso'
209
-                ),
210
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
211
-            ),
212
-            '4.9.9.rc.014'
213
-        );
214
-        
215
-        $contexts                = array();
216
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
217
-        foreach ($active_message_contexts as $active_message) {
218
-            if ($active_message instanceof EE_Message) {
219
-                $message_type = $active_message->message_type_object();
220
-                if ($message_type instanceof EE_message_type) {
221
-                    $message_type_contexts = $message_type->get_contexts();
222
-                    foreach ($message_type_contexts as $context => $context_details) {
223
-                        $contexts[$context] = $context_details['label'];
224
-                    }
225
-                }
226
-            }
227
-        }
228
-        
229
-        return $contexts;
230
-    }
193
+	/**
194
+	 * @deprecated 4.9.9.rc.014
195
+	 * @return array
196
+	 * @throws EE_Error
197
+	 * @throws InvalidArgumentException
198
+	 * @throws InvalidDataTypeException
199
+	 * @throws InvalidInterfaceException
200
+	 */
201
+	public function get_contexts_for_message_types_for_list_table()
202
+	{
203
+		EE_Error::doing_it_wrong(
204
+			__METHOD__,
205
+			sprintf(
206
+				esc_html__(
207
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
208
+					'event_espresso'
209
+				),
210
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
211
+			),
212
+			'4.9.9.rc.014'
213
+		);
214
+        
215
+		$contexts                = array();
216
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
217
+		foreach ($active_message_contexts as $active_message) {
218
+			if ($active_message instanceof EE_Message) {
219
+				$message_type = $active_message->message_type_object();
220
+				if ($message_type instanceof EE_message_type) {
221
+					$message_type_contexts = $message_type->get_contexts();
222
+					foreach ($message_type_contexts as $context => $context_details) {
223
+						$contexts[$context] = $context_details['label'];
224
+					}
225
+				}
226
+			}
227
+		}
228
+        
229
+		return $contexts;
230
+	}
231 231
 
232 232
 
233
-    /**
234
-     * Generate select input with provided messenger options array.
235
-     *
236
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
237
-     *                                 labels.
238
-     * @return string
239
-     * @throws EE_Error
240
-     */
241
-    public function get_messengers_select_input($messenger_options)
242
-    {
243
-        //if empty or just one value then just return an empty string
244
-        if (empty($messenger_options)
245
-            || ! is_array($messenger_options)
246
-            || count($messenger_options) === 1
247
-        ) {
248
-            return '';
249
-        }
250
-        //merge in default
251
-        $messenger_options = array_merge(
252
-            array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
253
-            $messenger_options
254
-        );
255
-        $input             = new EE_Select_Input(
256
-            $messenger_options,
257
-            array(
258
-                'html_name'  => 'ee_messenger_filter_by',
259
-                'html_id'    => 'ee_messenger_filter_by',
260
-                'html_class' => 'wide',
261
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
262
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
263
-                    : 'none_selected'
264
-            )
265
-        );
266
-        
267
-        return $input->get_html_for_input();
268
-    }
233
+	/**
234
+	 * Generate select input with provided messenger options array.
235
+	 *
236
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
237
+	 *                                 labels.
238
+	 * @return string
239
+	 * @throws EE_Error
240
+	 */
241
+	public function get_messengers_select_input($messenger_options)
242
+	{
243
+		//if empty or just one value then just return an empty string
244
+		if (empty($messenger_options)
245
+			|| ! is_array($messenger_options)
246
+			|| count($messenger_options) === 1
247
+		) {
248
+			return '';
249
+		}
250
+		//merge in default
251
+		$messenger_options = array_merge(
252
+			array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
253
+			$messenger_options
254
+		);
255
+		$input             = new EE_Select_Input(
256
+			$messenger_options,
257
+			array(
258
+				'html_name'  => 'ee_messenger_filter_by',
259
+				'html_id'    => 'ee_messenger_filter_by',
260
+				'html_class' => 'wide',
261
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
262
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
263
+					: 'none_selected'
264
+			)
265
+		);
266
+        
267
+		return $input->get_html_for_input();
268
+	}
269 269
 
270 270
 
271
-    /**
272
-     * Generate select input with provided message type options array.
273
-     *
274
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
275
-     *                                    message type labels
276
-     * @return string
277
-     * @throws EE_Error
278
-     */
279
-    public function get_message_types_select_input($message_type_options)
280
-    {
281
-        //if empty or count of options is 1 then just return an empty string
282
-        if (empty($message_type_options)
283
-            || ! is_array($message_type_options)
284
-            || count($message_type_options) === 1
285
-        ) {
286
-            return '';
287
-        }
288
-        //merge in default
289
-        $message_type_options = array_merge(
290
-            array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291
-            $message_type_options
292
-        );
293
-        $input                = new EE_Select_Input(
294
-            $message_type_options,
295
-            array(
296
-                'html_name'  => 'ee_message_type_filter_by',
297
-                'html_id'    => 'ee_message_type_filter_by',
298
-                'html_class' => 'wide',
299
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
300
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
301
-                    : 'none_selected',
302
-            )
303
-        );
304
-        
305
-        return $input->get_html_for_input();
306
-    }
271
+	/**
272
+	 * Generate select input with provided message type options array.
273
+	 *
274
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
275
+	 *                                    message type labels
276
+	 * @return string
277
+	 * @throws EE_Error
278
+	 */
279
+	public function get_message_types_select_input($message_type_options)
280
+	{
281
+		//if empty or count of options is 1 then just return an empty string
282
+		if (empty($message_type_options)
283
+			|| ! is_array($message_type_options)
284
+			|| count($message_type_options) === 1
285
+		) {
286
+			return '';
287
+		}
288
+		//merge in default
289
+		$message_type_options = array_merge(
290
+			array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291
+			$message_type_options
292
+		);
293
+		$input                = new EE_Select_Input(
294
+			$message_type_options,
295
+			array(
296
+				'html_name'  => 'ee_message_type_filter_by',
297
+				'html_id'    => 'ee_message_type_filter_by',
298
+				'html_class' => 'wide',
299
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
300
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
301
+					: 'none_selected',
302
+			)
303
+		);
304
+        
305
+		return $input->get_html_for_input();
306
+	}
307 307
 
308 308
 
309
-    /**
310
-     * Generate select input with provide message type contexts array.
311
-     *
312
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
313
-     *                               context label.
314
-     * @return string
315
-     * @throws EE_Error
316
-     */
317
-    public function get_contexts_for_message_types_select_input($context_options)
318
-    {
319
-        //if empty or count of options is one then just return empty string
320
-        if (empty($context_options)
321
-            || ! is_array($context_options)
322
-            || count($context_options) === 1
323
-        ) {
324
-            return '';
325
-        }
326
-        //merge in default
327
-        $context_options = array_merge(
328
-            array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
329
-            $context_options
330
-        );
331
-        $input           = new EE_Select_Input(
332
-            $context_options,
333
-            array(
334
-                'html_name'  => 'ee_context_filter_by',
335
-                'html_id'    => 'ee_context_filter_by',
336
-                'html_class' => 'wide',
337
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
338
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
339
-                    : 'none_selected',
340
-            )
341
-        );
342
-        
343
-        return $input->get_html_for_input();
344
-    }
309
+	/**
310
+	 * Generate select input with provide message type contexts array.
311
+	 *
312
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
313
+	 *                               context label.
314
+	 * @return string
315
+	 * @throws EE_Error
316
+	 */
317
+	public function get_contexts_for_message_types_select_input($context_options)
318
+	{
319
+		//if empty or count of options is one then just return empty string
320
+		if (empty($context_options)
321
+			|| ! is_array($context_options)
322
+			|| count($context_options) === 1
323
+		) {
324
+			return '';
325
+		}
326
+		//merge in default
327
+		$context_options = array_merge(
328
+			array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
329
+			$context_options
330
+		);
331
+		$input           = new EE_Select_Input(
332
+			$context_options,
333
+			array(
334
+				'html_name'  => 'ee_context_filter_by',
335
+				'html_id'    => 'ee_context_filter_by',
336
+				'html_class' => 'wide',
337
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
338
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
339
+					: 'none_selected',
340
+			)
341
+		);
342
+        
343
+		return $input->get_html_for_input();
344
+	}
345 345
     
346 346
     
347
-    protected function _ajax_hooks()
348
-    {
349
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
350
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
351
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
352
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
353
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
354
-        add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
355
-    }
347
+	protected function _ajax_hooks()
348
+	{
349
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
350
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
351
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
352
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
353
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
354
+		add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
355
+	}
356 356
     
357 357
     
358
-    protected function _define_page_props()
359
-    {
360
-        $this->_admin_page_title = $this->page_label;
361
-        $this->_labels           = array(
362
-            'buttons'    => array(
363
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
364
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
365
-                'delete' => esc_html__('Delete Message Template', 'event_espresso')
366
-            ),
367
-            'publishbox' => esc_html__('Update Actions', 'event_espresso')
368
-        );
369
-    }
358
+	protected function _define_page_props()
359
+	{
360
+		$this->_admin_page_title = $this->page_label;
361
+		$this->_labels           = array(
362
+			'buttons'    => array(
363
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
364
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
365
+				'delete' => esc_html__('Delete Message Template', 'event_espresso')
366
+			),
367
+			'publishbox' => esc_html__('Update Actions', 'event_espresso')
368
+		);
369
+	}
370 370
     
371 371
     
372
-    /**
373
-     *        an array for storing key => value pairs of request actions and their corresponding methods
374
-     * @access protected
375
-     * @return void
376
-     */
377
-    protected function _set_page_routes()
378
-    {
379
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
380
-            ? $this->_req_data['GRP_ID']
381
-            : 0;
382
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
383
-            ? $this->_req_data['id']
384
-            : $grp_id;
385
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
386
-            ? $this->_req_data['MSG_ID']
387
-            : 0;
388
-        
389
-        $this->_page_routes = array(
390
-            'default'                          => array(
391
-                'func'       => '_message_queue_list_table',
392
-                'capability' => 'ee_read_global_messages'
393
-            ),
394
-            'global_mtps'                      => array(
395
-                'func'       => '_ee_default_messages_overview_list_table',
396
-                'capability' => 'ee_read_global_messages'
397
-            ),
398
-            'custom_mtps'                      => array(
399
-                'func'       => '_custom_mtps_preview',
400
-                'capability' => 'ee_read_messages'
401
-            ),
402
-            'add_new_message_template'         => array(
403
-                'func'       => '_add_message_template',
404
-                'capability' => 'ee_edit_messages',
405
-                'noheader'   => true
406
-            ),
407
-            'edit_message_template'            => array(
408
-                'func'       => '_edit_message_template',
409
-                'capability' => 'ee_edit_message',
410
-                'obj_id'     => $grp_id
411
-            ),
412
-            'preview_message'                  => array(
413
-                'func'               => '_preview_message',
414
-                'capability'         => 'ee_read_message',
415
-                'obj_id'             => $grp_id,
416
-                'noheader'           => true,
417
-                'headers_sent_route' => 'display_preview_message'
418
-            ),
419
-            'display_preview_message'          => array(
420
-                'func'       => '_display_preview_message',
421
-                'capability' => 'ee_read_message',
422
-                'obj_id'     => $grp_id
423
-            ),
424
-            'insert_message_template'          => array(
425
-                'func'       => '_insert_or_update_message_template',
426
-                'capability' => 'ee_edit_messages',
427
-                'args'       => array('new_template' => true),
428
-                'noheader'   => true
429
-            ),
430
-            'update_message_template'          => array(
431
-                'func'       => '_insert_or_update_message_template',
432
-                'capability' => 'ee_edit_message',
433
-                'obj_id'     => $grp_id,
434
-                'args'       => array('new_template' => false),
435
-                'noheader'   => true
436
-            ),
437
-            'trash_message_template'           => array(
438
-                'func'       => '_trash_or_restore_message_template',
439
-                'capability' => 'ee_delete_message',
440
-                'obj_id'     => $grp_id,
441
-                'args'       => array('trash' => true, 'all' => true),
442
-                'noheader'   => true
443
-            ),
444
-            'trash_message_template_context'   => array(
445
-                'func'       => '_trash_or_restore_message_template',
446
-                'capability' => 'ee_delete_message',
447
-                'obj_id'     => $grp_id,
448
-                'args'       => array('trash' => true),
449
-                'noheader'   => true
450
-            ),
451
-            'restore_message_template'         => array(
452
-                'func'       => '_trash_or_restore_message_template',
453
-                'capability' => 'ee_delete_message',
454
-                'obj_id'     => $grp_id,
455
-                'args'       => array('trash' => false, 'all' => true),
456
-                'noheader'   => true
457
-            ),
458
-            'restore_message_template_context' => array(
459
-                'func'       => '_trash_or_restore_message_template',
460
-                'capability' => 'ee_delete_message',
461
-                'obj_id'     => $grp_id,
462
-                'args'       => array('trash' => false),
463
-                'noheader'   => true
464
-            ),
465
-            'delete_message_template'          => array(
466
-                'func'       => '_delete_message_template',
467
-                'capability' => 'ee_delete_message',
468
-                'obj_id'     => $grp_id,
469
-                'noheader'   => true
470
-            ),
471
-            'reset_to_default'                 => array(
472
-                'func'       => '_reset_to_default_template',
473
-                'capability' => 'ee_edit_message',
474
-                'obj_id'     => $grp_id,
475
-                'noheader'   => true
476
-            ),
477
-            'settings'                         => array(
478
-                'func'       => '_settings',
479
-                'capability' => 'manage_options'
480
-            ),
481
-            'update_global_settings'           => array(
482
-                'func'       => '_update_global_settings',
483
-                'capability' => 'manage_options',
484
-                'noheader'   => true
485
-            ),
486
-            'generate_now'                     => array(
487
-                'func'       => '_generate_now',
488
-                'capability' => 'ee_send_message',
489
-                'noheader'   => true
490
-            ),
491
-            'generate_and_send_now'            => array(
492
-                'func'       => '_generate_and_send_now',
493
-                'capability' => 'ee_send_message',
494
-                'noheader'   => true
495
-            ),
496
-            'queue_for_resending'              => array(
497
-                'func'       => '_queue_for_resending',
498
-                'capability' => 'ee_send_message',
499
-                'noheader'   => true
500
-            ),
501
-            'send_now'                         => array(
502
-                'func'       => '_send_now',
503
-                'capability' => 'ee_send_message',
504
-                'noheader'   => true
505
-            ),
506
-            'delete_ee_message'                => array(
507
-                'func'       => '_delete_ee_messages',
508
-                'capability' => 'ee_delete_messages',
509
-                'noheader'   => true
510
-            ),
511
-            'delete_ee_messages'               => array(
512
-                'func'       => '_delete_ee_messages',
513
-                'capability' => 'ee_delete_messages',
514
-                'noheader'   => true,
515
-                'obj_id'     => $msg_id
516
-            )
517
-        );
518
-    }
372
+	/**
373
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
374
+	 * @access protected
375
+	 * @return void
376
+	 */
377
+	protected function _set_page_routes()
378
+	{
379
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
380
+			? $this->_req_data['GRP_ID']
381
+			: 0;
382
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
383
+			? $this->_req_data['id']
384
+			: $grp_id;
385
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
386
+			? $this->_req_data['MSG_ID']
387
+			: 0;
388
+        
389
+		$this->_page_routes = array(
390
+			'default'                          => array(
391
+				'func'       => '_message_queue_list_table',
392
+				'capability' => 'ee_read_global_messages'
393
+			),
394
+			'global_mtps'                      => array(
395
+				'func'       => '_ee_default_messages_overview_list_table',
396
+				'capability' => 'ee_read_global_messages'
397
+			),
398
+			'custom_mtps'                      => array(
399
+				'func'       => '_custom_mtps_preview',
400
+				'capability' => 'ee_read_messages'
401
+			),
402
+			'add_new_message_template'         => array(
403
+				'func'       => '_add_message_template',
404
+				'capability' => 'ee_edit_messages',
405
+				'noheader'   => true
406
+			),
407
+			'edit_message_template'            => array(
408
+				'func'       => '_edit_message_template',
409
+				'capability' => 'ee_edit_message',
410
+				'obj_id'     => $grp_id
411
+			),
412
+			'preview_message'                  => array(
413
+				'func'               => '_preview_message',
414
+				'capability'         => 'ee_read_message',
415
+				'obj_id'             => $grp_id,
416
+				'noheader'           => true,
417
+				'headers_sent_route' => 'display_preview_message'
418
+			),
419
+			'display_preview_message'          => array(
420
+				'func'       => '_display_preview_message',
421
+				'capability' => 'ee_read_message',
422
+				'obj_id'     => $grp_id
423
+			),
424
+			'insert_message_template'          => array(
425
+				'func'       => '_insert_or_update_message_template',
426
+				'capability' => 'ee_edit_messages',
427
+				'args'       => array('new_template' => true),
428
+				'noheader'   => true
429
+			),
430
+			'update_message_template'          => array(
431
+				'func'       => '_insert_or_update_message_template',
432
+				'capability' => 'ee_edit_message',
433
+				'obj_id'     => $grp_id,
434
+				'args'       => array('new_template' => false),
435
+				'noheader'   => true
436
+			),
437
+			'trash_message_template'           => array(
438
+				'func'       => '_trash_or_restore_message_template',
439
+				'capability' => 'ee_delete_message',
440
+				'obj_id'     => $grp_id,
441
+				'args'       => array('trash' => true, 'all' => true),
442
+				'noheader'   => true
443
+			),
444
+			'trash_message_template_context'   => array(
445
+				'func'       => '_trash_or_restore_message_template',
446
+				'capability' => 'ee_delete_message',
447
+				'obj_id'     => $grp_id,
448
+				'args'       => array('trash' => true),
449
+				'noheader'   => true
450
+			),
451
+			'restore_message_template'         => array(
452
+				'func'       => '_trash_or_restore_message_template',
453
+				'capability' => 'ee_delete_message',
454
+				'obj_id'     => $grp_id,
455
+				'args'       => array('trash' => false, 'all' => true),
456
+				'noheader'   => true
457
+			),
458
+			'restore_message_template_context' => array(
459
+				'func'       => '_trash_or_restore_message_template',
460
+				'capability' => 'ee_delete_message',
461
+				'obj_id'     => $grp_id,
462
+				'args'       => array('trash' => false),
463
+				'noheader'   => true
464
+			),
465
+			'delete_message_template'          => array(
466
+				'func'       => '_delete_message_template',
467
+				'capability' => 'ee_delete_message',
468
+				'obj_id'     => $grp_id,
469
+				'noheader'   => true
470
+			),
471
+			'reset_to_default'                 => array(
472
+				'func'       => '_reset_to_default_template',
473
+				'capability' => 'ee_edit_message',
474
+				'obj_id'     => $grp_id,
475
+				'noheader'   => true
476
+			),
477
+			'settings'                         => array(
478
+				'func'       => '_settings',
479
+				'capability' => 'manage_options'
480
+			),
481
+			'update_global_settings'           => array(
482
+				'func'       => '_update_global_settings',
483
+				'capability' => 'manage_options',
484
+				'noheader'   => true
485
+			),
486
+			'generate_now'                     => array(
487
+				'func'       => '_generate_now',
488
+				'capability' => 'ee_send_message',
489
+				'noheader'   => true
490
+			),
491
+			'generate_and_send_now'            => array(
492
+				'func'       => '_generate_and_send_now',
493
+				'capability' => 'ee_send_message',
494
+				'noheader'   => true
495
+			),
496
+			'queue_for_resending'              => array(
497
+				'func'       => '_queue_for_resending',
498
+				'capability' => 'ee_send_message',
499
+				'noheader'   => true
500
+			),
501
+			'send_now'                         => array(
502
+				'func'       => '_send_now',
503
+				'capability' => 'ee_send_message',
504
+				'noheader'   => true
505
+			),
506
+			'delete_ee_message'                => array(
507
+				'func'       => '_delete_ee_messages',
508
+				'capability' => 'ee_delete_messages',
509
+				'noheader'   => true
510
+			),
511
+			'delete_ee_messages'               => array(
512
+				'func'       => '_delete_ee_messages',
513
+				'capability' => 'ee_delete_messages',
514
+				'noheader'   => true,
515
+				'obj_id'     => $msg_id
516
+			)
517
+		);
518
+	}
519 519
     
520 520
     
521
-    protected function _set_page_config()
522
-    {
523
-        $this->_page_config = array(
524
-            'default'                  => array(
525
-                'nav'           => array(
526
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
527
-                    'order' => 10
528
-                ),
529
-                'list_table'    => 'EE_Message_List_Table',
530
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
531
-                'require_nonce' => false
532
-            ),
533
-            'global_mtps'              => array(
534
-                'nav'           => array(
535
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
536
-                    'order' => 20
537
-                ),
538
-                'list_table'    => 'Messages_Template_List_Table',
539
-                'help_tabs'     => array(
540
-                    'messages_overview_help_tab'                                => array(
541
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
542
-                        'filename' => 'messages_overview'
543
-                    ),
544
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
545
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
546
-                        'filename' => 'messages_overview_table_column_headings'
547
-                    ),
548
-                    'messages_overview_messages_filters_help_tab'               => array(
549
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
550
-                        'filename' => 'messages_overview_filters'
551
-                    ),
552
-                    'messages_overview_messages_views_help_tab'                 => array(
553
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
554
-                        'filename' => 'messages_overview_views'
555
-                    ),
556
-                    'message_overview_message_types_help_tab'                   => array(
557
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
558
-                        'filename' => 'messages_overview_types'
559
-                    ),
560
-                    'messages_overview_messengers_help_tab'                     => array(
561
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
562
-                        'filename' => 'messages_overview_messengers',
563
-                    ),
564
-                ),
565
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
566
-                'require_nonce' => false
567
-            ),
568
-            'custom_mtps'              => array(
569
-                'nav'           => array(
570
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
571
-                    'order' => 30
572
-                ),
573
-                'help_tabs'     => array(),
574
-                'help_tour'     => array(),
575
-                'require_nonce' => false
576
-            ),
577
-            'add_new_message_template' => array(
578
-                'nav'           => array(
579
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
580
-                    'order'      => 5,
581
-                    'persistent' => false
582
-                ),
583
-                'require_nonce' => false
584
-            ),
585
-            'edit_message_template'    => array(
586
-                'labels'        => array(
587
-                    'buttons'    => array(
588
-                        'reset' => esc_html__('Reset Templates'),
589
-                    ),
590
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso')
591
-                ),
592
-                'nav'           => array(
593
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
594
-                    'order'      => 5,
595
-                    'persistent' => false,
596
-                    'url'        => ''
597
-                ),
598
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
599
-                'has_metaboxes' => true,
600
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
601
-                'help_tabs'     => array(
602
-                    'edit_message_template'       => array(
603
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
604
-                        'callback' => 'edit_message_template_help_tab'
605
-                    ),
606
-                    'message_templates_help_tab'  => array(
607
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
608
-                        'filename' => 'messages_templates'
609
-                    ),
610
-                    'message_template_shortcodes' => array(
611
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
612
-                        'callback' => 'message_template_shortcodes_help_tab'
613
-                    ),
614
-                    'message_preview_help_tab'    => array(
615
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
616
-                        'filename' => 'messages_preview'
617
-                    ),
618
-                    'messages_overview_other_help_tab'                          => array(
619
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
620
-                        'filename' => 'messages_overview_other',
621
-                    ),
622
-                ),
623
-                'require_nonce' => false
624
-            ),
625
-            'display_preview_message'  => array(
626
-                'nav'           => array(
627
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
628
-                    'order'      => 5,
629
-                    'url'        => '',
630
-                    'persistent' => false
631
-                ),
632
-                'help_tabs'     => array(
633
-                    'preview_message' => array(
634
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
635
-                        'callback' => 'preview_message_help_tab'
636
-                    )
637
-                ),
638
-                'require_nonce' => false
639
-            ),
640
-            'settings'                 => array(
641
-                'nav'           => array(
642
-                    'label' => esc_html__('Settings', 'event_espresso'),
643
-                    'order' => 40
644
-                ),
645
-                'metaboxes'     => array('_messages_settings_metaboxes'),
646
-                'help_tabs'     => array(
647
-                    'messages_settings_help_tab'               => array(
648
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
649
-                        'filename' => 'messages_settings'
650
-                    ),
651
-                    'messages_settings_message_types_help_tab' => array(
652
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
653
-                        'filename' => 'messages_settings_message_types'
654
-                    ),
655
-                    'messages_settings_messengers_help_tab'    => array(
656
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
657
-                        'filename' => 'messages_settings_messengers'
658
-                    ),
659
-                ),
660
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
661
-                'require_nonce' => false
662
-            )
663
-        );
664
-    }
521
+	protected function _set_page_config()
522
+	{
523
+		$this->_page_config = array(
524
+			'default'                  => array(
525
+				'nav'           => array(
526
+					'label' => esc_html__('Message Activity', 'event_espresso'),
527
+					'order' => 10
528
+				),
529
+				'list_table'    => 'EE_Message_List_Table',
530
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
531
+				'require_nonce' => false
532
+			),
533
+			'global_mtps'              => array(
534
+				'nav'           => array(
535
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
536
+					'order' => 20
537
+				),
538
+				'list_table'    => 'Messages_Template_List_Table',
539
+				'help_tabs'     => array(
540
+					'messages_overview_help_tab'                                => array(
541
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
542
+						'filename' => 'messages_overview'
543
+					),
544
+					'messages_overview_messages_table_column_headings_help_tab' => array(
545
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
546
+						'filename' => 'messages_overview_table_column_headings'
547
+					),
548
+					'messages_overview_messages_filters_help_tab'               => array(
549
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
550
+						'filename' => 'messages_overview_filters'
551
+					),
552
+					'messages_overview_messages_views_help_tab'                 => array(
553
+						'title'    => esc_html__('Message Views', 'event_espresso'),
554
+						'filename' => 'messages_overview_views'
555
+					),
556
+					'message_overview_message_types_help_tab'                   => array(
557
+						'title'    => esc_html__('Message Types', 'event_espresso'),
558
+						'filename' => 'messages_overview_types'
559
+					),
560
+					'messages_overview_messengers_help_tab'                     => array(
561
+						'title'    => esc_html__('Messengers', 'event_espresso'),
562
+						'filename' => 'messages_overview_messengers',
563
+					),
564
+				),
565
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
566
+				'require_nonce' => false
567
+			),
568
+			'custom_mtps'              => array(
569
+				'nav'           => array(
570
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
571
+					'order' => 30
572
+				),
573
+				'help_tabs'     => array(),
574
+				'help_tour'     => array(),
575
+				'require_nonce' => false
576
+			),
577
+			'add_new_message_template' => array(
578
+				'nav'           => array(
579
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
580
+					'order'      => 5,
581
+					'persistent' => false
582
+				),
583
+				'require_nonce' => false
584
+			),
585
+			'edit_message_template'    => array(
586
+				'labels'        => array(
587
+					'buttons'    => array(
588
+						'reset' => esc_html__('Reset Templates'),
589
+					),
590
+					'publishbox' => esc_html__('Update Actions', 'event_espresso')
591
+				),
592
+				'nav'           => array(
593
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
594
+					'order'      => 5,
595
+					'persistent' => false,
596
+					'url'        => ''
597
+				),
598
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
599
+				'has_metaboxes' => true,
600
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
601
+				'help_tabs'     => array(
602
+					'edit_message_template'       => array(
603
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
604
+						'callback' => 'edit_message_template_help_tab'
605
+					),
606
+					'message_templates_help_tab'  => array(
607
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
608
+						'filename' => 'messages_templates'
609
+					),
610
+					'message_template_shortcodes' => array(
611
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
612
+						'callback' => 'message_template_shortcodes_help_tab'
613
+					),
614
+					'message_preview_help_tab'    => array(
615
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
616
+						'filename' => 'messages_preview'
617
+					),
618
+					'messages_overview_other_help_tab'                          => array(
619
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
620
+						'filename' => 'messages_overview_other',
621
+					),
622
+				),
623
+				'require_nonce' => false
624
+			),
625
+			'display_preview_message'  => array(
626
+				'nav'           => array(
627
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
628
+					'order'      => 5,
629
+					'url'        => '',
630
+					'persistent' => false
631
+				),
632
+				'help_tabs'     => array(
633
+					'preview_message' => array(
634
+						'title'    => esc_html__('About Previews', 'event_espresso'),
635
+						'callback' => 'preview_message_help_tab'
636
+					)
637
+				),
638
+				'require_nonce' => false
639
+			),
640
+			'settings'                 => array(
641
+				'nav'           => array(
642
+					'label' => esc_html__('Settings', 'event_espresso'),
643
+					'order' => 40
644
+				),
645
+				'metaboxes'     => array('_messages_settings_metaboxes'),
646
+				'help_tabs'     => array(
647
+					'messages_settings_help_tab'               => array(
648
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
649
+						'filename' => 'messages_settings'
650
+					),
651
+					'messages_settings_message_types_help_tab' => array(
652
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
653
+						'filename' => 'messages_settings_message_types'
654
+					),
655
+					'messages_settings_messengers_help_tab'    => array(
656
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
657
+						'filename' => 'messages_settings_messengers'
658
+					),
659
+				),
660
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
661
+				'require_nonce' => false
662
+			)
663
+		);
664
+	}
665 665
     
666 666
     
667
-    protected function _add_screen_options()
668
-    {
669
-        //todo
670
-    }
667
+	protected function _add_screen_options()
668
+	{
669
+		//todo
670
+	}
671 671
     
672 672
     
673
-    protected function _add_screen_options_global_mtps()
674
-    {
675
-        /**
676
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
677
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
678
-         */
679
-        $page_title              = $this->_admin_page_title;
680
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
681
-        $this->_per_page_screen_option();
682
-        $this->_admin_page_title = $page_title;
683
-    }
673
+	protected function _add_screen_options_global_mtps()
674
+	{
675
+		/**
676
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
677
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
678
+		 */
679
+		$page_title              = $this->_admin_page_title;
680
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
681
+		$this->_per_page_screen_option();
682
+		$this->_admin_page_title = $page_title;
683
+	}
684 684
     
685 685
     
686
-    protected function _add_screen_options_default()
687
-    {
688
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
689
-        $this->_per_page_screen_option();
690
-    }
686
+	protected function _add_screen_options_default()
687
+	{
688
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
689
+		$this->_per_page_screen_option();
690
+	}
691 691
     
692 692
     
693
-    //none of the below group are currently used for Messages
694
-    protected function _add_feature_pointers()
695
-    {
696
-    }
693
+	//none of the below group are currently used for Messages
694
+	protected function _add_feature_pointers()
695
+	{
696
+	}
697 697
     
698
-    public function admin_init()
699
-    {
700
-    }
698
+	public function admin_init()
699
+	{
700
+	}
701 701
     
702
-    public function admin_notices()
703
-    {
704
-    }
702
+	public function admin_notices()
703
+	{
704
+	}
705 705
     
706
-    public function admin_footer_scripts()
707
-    {
708
-    }
706
+	public function admin_footer_scripts()
707
+	{
708
+	}
709 709
     
710 710
     
711
-    public function messages_help_tab()
712
-    {
713
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
714
-    }
711
+	public function messages_help_tab()
712
+	{
713
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
714
+	}
715 715
     
716 716
     
717
-    public function messengers_help_tab()
718
-    {
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
720
-    }
717
+	public function messengers_help_tab()
718
+	{
719
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
720
+	}
721 721
     
722 722
     
723
-    public function message_types_help_tab()
724
-    {
725
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
726
-    }
723
+	public function message_types_help_tab()
724
+	{
725
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
726
+	}
727 727
     
728 728
     
729
-    public function messages_overview_help_tab()
730
-    {
731
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
732
-    }
729
+	public function messages_overview_help_tab()
730
+	{
731
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
732
+	}
733 733
     
734 734
     
735
-    public function message_templates_help_tab()
736
-    {
737
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
738
-    }
735
+	public function message_templates_help_tab()
736
+	{
737
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
738
+	}
739 739
     
740 740
     
741
-    public function edit_message_template_help_tab()
742
-    {
743
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
744
-                        . esc_attr__('Editor Title', 'event_espresso')
745
-                        . '" />';
746
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
747
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
748
-                        . '" />';
749
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
750
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
751
-                        . '" />';
752
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
753
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
754
-                        . '" />';
755
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
756
-                        . esc_attr__('Publish Metabox', 'event_espresso')
757
-                        . '" />';
758
-        EEH_Template::display_template(
759
-            EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
760
-            $args
761
-        );
762
-    }
741
+	public function edit_message_template_help_tab()
742
+	{
743
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
744
+						. esc_attr__('Editor Title', 'event_espresso')
745
+						. '" />';
746
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
747
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
748
+						. '" />';
749
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
750
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
751
+						. '" />';
752
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
753
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
754
+						. '" />';
755
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
756
+						. esc_attr__('Publish Metabox', 'event_espresso')
757
+						. '" />';
758
+		EEH_Template::display_template(
759
+			EE_MSG_TEMPLATE_PATH  . 'ee_msg_messages_templates_editor_help_tab.template.php',
760
+			$args
761
+		);
762
+	}
763 763
     
764 764
     
765
-    public function message_template_shortcodes_help_tab()
766
-    {
767
-        $this->_set_shortcodes();
768
-        $args['shortcodes'] = $this->_shortcodes;
769
-        EEH_Template::display_template(
770
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
771
-            $args
772
-        );
773
-    }
765
+	public function message_template_shortcodes_help_tab()
766
+	{
767
+		$this->_set_shortcodes();
768
+		$args['shortcodes'] = $this->_shortcodes;
769
+		EEH_Template::display_template(
770
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
771
+			$args
772
+		);
773
+	}
774 774
     
775 775
     
776
-    public function preview_message_help_tab()
777
-    {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
779
-    }
776
+	public function preview_message_help_tab()
777
+	{
778
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
779
+	}
780 780
     
781 781
     
782
-    public function settings_help_tab()
783
-    {
784
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
785
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
786
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
787
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
788
-        $args['img3'] = '<div class="switch">'
789
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
790
-                        . ' type="checkbox" checked="checked">'
791
-                        . '<label for="ee-on-off-toggle-on"></label>'
792
-                        . '</div>';
793
-        $args['img4'] = '<div class="switch">'
794
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
795
-                        . ' type="checkbox">'
796
-                        . '<label for="ee-on-off-toggle-on"></label>'
797
-                        . '</div>';
798
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
799
-    }
782
+	public function settings_help_tab()
783
+	{
784
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
785
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
786
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
787
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
788
+		$args['img3'] = '<div class="switch">'
789
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
790
+						. ' type="checkbox" checked="checked">'
791
+						. '<label for="ee-on-off-toggle-on"></label>'
792
+						. '</div>';
793
+		$args['img4'] = '<div class="switch">'
794
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
795
+						. ' type="checkbox">'
796
+						. '<label for="ee-on-off-toggle-on"></label>'
797
+						. '</div>';
798
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
799
+	}
800 800
     
801 801
     
802
-    public function load_scripts_styles()
803
-    {
804
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
805
-        wp_enqueue_style('espresso_ee_msg');
806
-        
807
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
808
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
809
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
810
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
811
-    }
802
+	public function load_scripts_styles()
803
+	{
804
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
805
+		wp_enqueue_style('espresso_ee_msg');
806
+        
807
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
808
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
809
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
810
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
811
+	}
812 812
     
813 813
     
814
-    public function load_scripts_styles_default()
815
-    {
816
-        wp_enqueue_script('ee-msg-list-table-js');
817
-    }
814
+	public function load_scripts_styles_default()
815
+	{
816
+		wp_enqueue_script('ee-msg-list-table-js');
817
+	}
818 818
     
819 819
     
820
-    public function wp_editor_css($mce_css)
821
-    {
822
-        //if we're on the edit_message_template route
823
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
824
-            $message_type_name = $this->_active_message_type_name;
820
+	public function wp_editor_css($mce_css)
821
+	{
822
+		//if we're on the edit_message_template route
823
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
824
+			$message_type_name = $this->_active_message_type_name;
825 825
             
826
-            //we're going to REPLACE the existing mce css
827
-            //we need to get the css file location from the active messenger
828
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
829
-                'wpeditor', $this->_variation);
830
-        }
831
-        
832
-        return $mce_css;
833
-    }
826
+			//we're going to REPLACE the existing mce css
827
+			//we need to get the css file location from the active messenger
828
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
829
+				'wpeditor', $this->_variation);
830
+		}
831
+        
832
+		return $mce_css;
833
+	}
834 834
     
835 835
     
836
-    public function load_scripts_styles_edit_message_template()
837
-    {
838
-        
839
-        $this->_set_shortcodes();
840
-        
841
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
842
-            esc_html__(
843
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
844
-                'event_espresso'
845
-            ),
846
-            $this->_message_template_group->messenger_obj()->label['singular'],
847
-            $this->_message_template_group->message_type_obj()->label['singular']
848
-        );
849
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
850
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
851
-            'event_espresso'
852
-        );
853
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
854
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
855
-            'event_espresso'
856
-        );
857
-        
858
-        wp_register_script(
859
-            'ee_msgs_edit_js',
860
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
861
-            array('jquery'),
862
-            EVENT_ESPRESSO_VERSION
863
-        );
864
-        
865
-        wp_enqueue_script('ee_admin_js');
866
-        wp_enqueue_script('ee_msgs_edit_js');
867
-        
868
-        //add in special css for tiny_mce
869
-        add_filter('mce_css', array($this, 'wp_editor_css'));
870
-    }
836
+	public function load_scripts_styles_edit_message_template()
837
+	{
838
+        
839
+		$this->_set_shortcodes();
840
+        
841
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
842
+			esc_html__(
843
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
844
+				'event_espresso'
845
+			),
846
+			$this->_message_template_group->messenger_obj()->label['singular'],
847
+			$this->_message_template_group->message_type_obj()->label['singular']
848
+		);
849
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
850
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
851
+			'event_espresso'
852
+		);
853
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
854
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
855
+			'event_espresso'
856
+		);
857
+        
858
+		wp_register_script(
859
+			'ee_msgs_edit_js',
860
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
861
+			array('jquery'),
862
+			EVENT_ESPRESSO_VERSION
863
+		);
864
+        
865
+		wp_enqueue_script('ee_admin_js');
866
+		wp_enqueue_script('ee_msgs_edit_js');
867
+        
868
+		//add in special css for tiny_mce
869
+		add_filter('mce_css', array($this, 'wp_editor_css'));
870
+	}
871 871
     
872 872
     
873
-    public function load_scripts_styles_display_preview_message()
874
-    {
875
-        
876
-        $this->_set_message_template_group();
877
-        
878
-        if (isset($this->_req_data['messenger'])) {
879
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
880
-                $this->_req_data['messenger']
881
-            );
882
-        }
883
-        
884
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
885
-        
886
-        
887
-        wp_enqueue_style('espresso_preview_css',
888
-            $this->_active_messenger->get_variation(
889
-                $this->_template_pack,
890
-                $message_type_name,
891
-                true,
892
-                'preview',
893
-                $this->_variation
894
-            )
895
-        );
896
-    }
873
+	public function load_scripts_styles_display_preview_message()
874
+	{
875
+        
876
+		$this->_set_message_template_group();
877
+        
878
+		if (isset($this->_req_data['messenger'])) {
879
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
880
+				$this->_req_data['messenger']
881
+			);
882
+		}
883
+        
884
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
885
+        
886
+        
887
+		wp_enqueue_style('espresso_preview_css',
888
+			$this->_active_messenger->get_variation(
889
+				$this->_template_pack,
890
+				$message_type_name,
891
+				true,
892
+				'preview',
893
+				$this->_variation
894
+			)
895
+		);
896
+	}
897 897
     
898 898
     
899
-    public function load_scripts_styles_settings()
900
-    {
901
-        wp_register_style(
902
-            'ee-message-settings',
903
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
904
-            array(),
905
-            EVENT_ESPRESSO_VERSION
906
-        );
907
-        wp_enqueue_style('ee-text-links');
908
-        wp_enqueue_style('ee-message-settings');
909
-        wp_enqueue_script('ee-messages-settings');
910
-    }
899
+	public function load_scripts_styles_settings()
900
+	{
901
+		wp_register_style(
902
+			'ee-message-settings',
903
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
904
+			array(),
905
+			EVENT_ESPRESSO_VERSION
906
+		);
907
+		wp_enqueue_style('ee-text-links');
908
+		wp_enqueue_style('ee-message-settings');
909
+		wp_enqueue_script('ee-messages-settings');
910
+	}
911 911
     
912 912
     
913
-    /**
914
-     * set views array for List Table
915
-     */
916
-    public function _set_list_table_views_global_mtps()
917
-    {
918
-        $this->_views = array(
919
-            'in_use' => array(
920
-                'slug'        => 'in_use',
921
-                'label'       => esc_html__('In Use', 'event_espresso'),
922
-                'count'       => 0,
923
-            )
924
-        );
925
-    }
913
+	/**
914
+	 * set views array for List Table
915
+	 */
916
+	public function _set_list_table_views_global_mtps()
917
+	{
918
+		$this->_views = array(
919
+			'in_use' => array(
920
+				'slug'        => 'in_use',
921
+				'label'       => esc_html__('In Use', 'event_espresso'),
922
+				'count'       => 0,
923
+			)
924
+		);
925
+	}
926 926
 
927 927
 
928
-    /**
929
-     * Set views array for the Custom Template List Table
930
-     */
931
-    public function _set_list_table_views_custom_mtps()
932
-    {
933
-        $this->_set_list_table_views_global_mtps();
934
-        $this->_views['in_use']['bulk_action'] = array(
935
-                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
936
-        );
937
-    }
928
+	/**
929
+	 * Set views array for the Custom Template List Table
930
+	 */
931
+	public function _set_list_table_views_custom_mtps()
932
+	{
933
+		$this->_set_list_table_views_global_mtps();
934
+		$this->_views['in_use']['bulk_action'] = array(
935
+				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
936
+		);
937
+	}
938 938
 
939 939
 
940
-    /**
941
-     * set views array for message queue list table
942
-     *
943
-     * @throws InvalidDataTypeException
944
-     * @throws InvalidInterfaceException
945
-     * @throws InvalidArgumentException
946
-     * @throws EE_Error
947
-     * @throws ReflectionException
948
-     */
949
-    public function _set_list_table_views_default()
950
-    {
951
-        EE_Registry::instance()->load_helper('Template');
952
-        
953
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
954
-            'ee_send_message',
955
-            'message_list_table_bulk_actions'
956
-        )
957
-            ? array(
958
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
959
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
960
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
961
-                'send_now'              => esc_html__('Send Now', 'event_espresso')
962
-            )
963
-            : array();
964
-        
965
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
966
-            'ee_delete_messages',
967
-            'message_list_table_bulk_actions'
968
-        )
969
-            ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
970
-            : array();
971
-        
972
-        
973
-        $this->_views = array(
974
-            'all' => array(
975
-                'slug'        => 'all',
976
-                'label'       => esc_html__('All', 'event_espresso'),
977
-                'count'       => 0,
978
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
979
-            )
980
-        );
981
-        
982
-        
983
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
984
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
985
-                continue;
986
-            }
987
-            $status_bulk_actions = $common_bulk_actions;
988
-            //unset bulk actions not applying to status
989
-            if (! empty($status_bulk_actions)) {
990
-                switch ($status) {
991
-                    case EEM_Message::status_idle:
992
-                    case EEM_Message::status_resend:
993
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
994
-                        break;
940
+	/**
941
+	 * set views array for message queue list table
942
+	 *
943
+	 * @throws InvalidDataTypeException
944
+	 * @throws InvalidInterfaceException
945
+	 * @throws InvalidArgumentException
946
+	 * @throws EE_Error
947
+	 * @throws ReflectionException
948
+	 */
949
+	public function _set_list_table_views_default()
950
+	{
951
+		EE_Registry::instance()->load_helper('Template');
952
+        
953
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
954
+			'ee_send_message',
955
+			'message_list_table_bulk_actions'
956
+		)
957
+			? array(
958
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
959
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
960
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
961
+				'send_now'              => esc_html__('Send Now', 'event_espresso')
962
+			)
963
+			: array();
964
+        
965
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
966
+			'ee_delete_messages',
967
+			'message_list_table_bulk_actions'
968
+		)
969
+			? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
970
+			: array();
971
+        
972
+        
973
+		$this->_views = array(
974
+			'all' => array(
975
+				'slug'        => 'all',
976
+				'label'       => esc_html__('All', 'event_espresso'),
977
+				'count'       => 0,
978
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
979
+			)
980
+		);
981
+        
982
+        
983
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
984
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
985
+				continue;
986
+			}
987
+			$status_bulk_actions = $common_bulk_actions;
988
+			//unset bulk actions not applying to status
989
+			if (! empty($status_bulk_actions)) {
990
+				switch ($status) {
991
+					case EEM_Message::status_idle:
992
+					case EEM_Message::status_resend:
993
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
994
+						break;
995 995
                     
996
-                    case EEM_Message::status_failed:
997
-                    case EEM_Message::status_debug_only:
998
-                    case EEM_Message::status_messenger_executing:
999
-                        $status_bulk_actions = array();
1000
-                        break;
996
+					case EEM_Message::status_failed:
997
+					case EEM_Message::status_debug_only:
998
+					case EEM_Message::status_messenger_executing:
999
+						$status_bulk_actions = array();
1000
+						break;
1001 1001
                     
1002
-                    case EEM_Message::status_incomplete:
1003
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1004
-                        break;
1002
+					case EEM_Message::status_incomplete:
1003
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1004
+						break;
1005 1005
                     
1006
-                    case EEM_Message::status_retry:
1007
-                    case EEM_Message::status_sent:
1008
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1009
-                        break;
1010
-                }
1011
-            }
1006
+					case EEM_Message::status_retry:
1007
+					case EEM_Message::status_sent:
1008
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1009
+						break;
1010
+				}
1011
+			}
1012 1012
 
1013
-            //skip adding messenger executing status to views because it will be included with the Failed view.
1014
-            if ( $status === EEM_Message::status_messenger_executing ) {
1015
-                continue;
1016
-            }
1013
+			//skip adding messenger executing status to views because it will be included with the Failed view.
1014
+			if ( $status === EEM_Message::status_messenger_executing ) {
1015
+				continue;
1016
+			}
1017 1017
             
1018
-            $this->_views[strtolower($status)] = array(
1019
-                'slug'        => strtolower($status),
1020
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1021
-                'count'       => 0,
1022
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1023
-            );
1024
-        }
1025
-    }
1018
+			$this->_views[strtolower($status)] = array(
1019
+				'slug'        => strtolower($status),
1020
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1021
+				'count'       => 0,
1022
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
1023
+			);
1024
+		}
1025
+	}
1026 1026
     
1027 1027
     
1028
-    protected function _ee_default_messages_overview_list_table()
1029
-    {
1030
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1031
-        $this->display_admin_list_table_page_with_no_sidebar();
1032
-    }
1028
+	protected function _ee_default_messages_overview_list_table()
1029
+	{
1030
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1031
+		$this->display_admin_list_table_page_with_no_sidebar();
1032
+	}
1033 1033
     
1034 1034
     
1035
-    protected function _message_queue_list_table()
1036
-    {
1037
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1038
-        $this->_template_args['per_column']        = 6;
1039
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1040
-        $this->_template_args['before_list_table'] = '<h3>'
1041
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1042
-                                                     . '</h3>';
1043
-        $this->display_admin_list_table_page_with_no_sidebar();
1044
-    }
1035
+	protected function _message_queue_list_table()
1036
+	{
1037
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1038
+		$this->_template_args['per_column']        = 6;
1039
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1040
+		$this->_template_args['before_list_table'] = '<h3>'
1041
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1042
+													 . '</h3>';
1043
+		$this->display_admin_list_table_page_with_no_sidebar();
1044
+	}
1045 1045
     
1046 1046
     
1047
-    protected function _message_legend_items()
1048
-    {
1049
-        
1050
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1051
-        $action_items       = array();
1052
-        
1053
-        foreach ($action_css_classes as $action_item => $action_details) {
1054
-            if ($action_item === 'see_notifications_for') {
1055
-                continue;
1056
-            }
1057
-            $action_items[$action_item] = array(
1058
-                'class' => $action_details['css_class'],
1059
-                'desc'  => $action_details['label']
1060
-            );
1061
-        }
1062
-        
1063
-        /** @type array $status_items status legend setup */
1064
-        $status_items = array(
1065
-            'sent_status'       => array(
1066
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1067
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1068
-            ),
1069
-            'idle_status'       => array(
1070
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1071
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1072
-            ),
1073
-            'failed_status'     => array(
1074
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1075
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1076
-            ),
1077
-            'messenger_executing_status' => array(
1078
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1079
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1080
-            ),
1081
-            'resend_status'     => array(
1082
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1083
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1084
-            ),
1085
-            'incomplete_status' => array(
1086
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1087
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1088
-            ),
1089
-            'retry_status'      => array(
1090
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1091
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1092
-            )
1093
-        );
1094
-        if (EEM_Message::debug()) {
1095
-            $status_items['debug_only_status'] = array(
1096
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1097
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1098
-            );
1099
-        }
1100
-        
1101
-        return array_merge($action_items, $status_items);
1102
-    }
1047
+	protected function _message_legend_items()
1048
+	{
1049
+        
1050
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1051
+		$action_items       = array();
1052
+        
1053
+		foreach ($action_css_classes as $action_item => $action_details) {
1054
+			if ($action_item === 'see_notifications_for') {
1055
+				continue;
1056
+			}
1057
+			$action_items[$action_item] = array(
1058
+				'class' => $action_details['css_class'],
1059
+				'desc'  => $action_details['label']
1060
+			);
1061
+		}
1062
+        
1063
+		/** @type array $status_items status legend setup */
1064
+		$status_items = array(
1065
+			'sent_status'       => array(
1066
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1067
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
1068
+			),
1069
+			'idle_status'       => array(
1070
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1071
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
1072
+			),
1073
+			'failed_status'     => array(
1074
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1075
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
1076
+			),
1077
+			'messenger_executing_status' => array(
1078
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1079
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
1080
+			),
1081
+			'resend_status'     => array(
1082
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1083
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
1084
+			),
1085
+			'incomplete_status' => array(
1086
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1087
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1088
+			),
1089
+			'retry_status'      => array(
1090
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1091
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1092
+			)
1093
+		);
1094
+		if (EEM_Message::debug()) {
1095
+			$status_items['debug_only_status'] = array(
1096
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1097
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1098
+			);
1099
+		}
1100
+        
1101
+		return array_merge($action_items, $status_items);
1102
+	}
1103 1103
     
1104 1104
     
1105
-    protected function _custom_mtps_preview()
1106
-    {
1107
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1108
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1109
-            . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1110
-        $this->_template_args['preview_text'] = '<strong>'
1111
-            . esc_html__(
1112
-                'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1113
-                'event_espresso'
1114
-            )
1115
-            . '</strong>';
1105
+	protected function _custom_mtps_preview()
1106
+	{
1107
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1108
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1109
+			. ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />';
1110
+		$this->_template_args['preview_text'] = '<strong>'
1111
+			. esc_html__(
1112
+				'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1113
+				'event_espresso'
1114
+			)
1115
+			. '</strong>';
1116 1116
 
1117
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1118
-    }
1117
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1118
+	}
1119 1119
 
1120 1120
 
1121
-    /**
1122
-     * get_message_templates
1123
-     * This gets all the message templates for listing on the overview list.
1124
-     *
1125
-     * @access public
1126
-     * @param int    $perpage the amount of templates groups to show per page
1127
-     * @param string $type    the current _view we're getting templates for
1128
-     * @param bool   $count   return count?
1129
-     * @param bool   $all     disregard any paging info (get all data);
1130
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1131
-     * @return array
1132
-     * @throws EE_Error
1133
-     * @throws InvalidArgumentException
1134
-     * @throws InvalidDataTypeException
1135
-     * @throws InvalidInterfaceException
1136
-     */
1137
-    public function get_message_templates(
1138
-        $perpage = 10,
1139
-        $type = 'in_use',
1140
-        $count = false,
1141
-        $all = false,
1142
-        $global = true)
1143
-    {
1144
-        
1145
-        $MTP = EEM_Message_Template_Group::instance();
1146
-        
1147
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1148
-        $orderby                    = $this->_req_data['orderby'];
1149
-        
1150
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1151
-            ? $this->_req_data['order']
1152
-            : 'ASC';
1153
-        
1154
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1155
-            ? $this->_req_data['paged']
1156
-            : 1;
1157
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1158
-            ? $this->_req_data['perpage']
1159
-            : $perpage;
1160
-        
1161
-        $offset = ($current_page - 1) * $per_page;
1162
-        $limit  = $all ? null : array($offset, $per_page);
1163
-        
1164
-        
1165
-        //options will match what is in the _views array property
1166
-        switch ($type) {
1167
-            case 'in_use':
1168
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1169
-                break;
1170
-            default:
1171
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1172
-        }
1173
-        
1174
-        return $templates;
1175
-    }
1121
+	/**
1122
+	 * get_message_templates
1123
+	 * This gets all the message templates for listing on the overview list.
1124
+	 *
1125
+	 * @access public
1126
+	 * @param int    $perpage the amount of templates groups to show per page
1127
+	 * @param string $type    the current _view we're getting templates for
1128
+	 * @param bool   $count   return count?
1129
+	 * @param bool   $all     disregard any paging info (get all data);
1130
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1131
+	 * @return array
1132
+	 * @throws EE_Error
1133
+	 * @throws InvalidArgumentException
1134
+	 * @throws InvalidDataTypeException
1135
+	 * @throws InvalidInterfaceException
1136
+	 */
1137
+	public function get_message_templates(
1138
+		$perpage = 10,
1139
+		$type = 'in_use',
1140
+		$count = false,
1141
+		$all = false,
1142
+		$global = true)
1143
+	{
1144
+        
1145
+		$MTP = EEM_Message_Template_Group::instance();
1146
+        
1147
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1148
+		$orderby                    = $this->_req_data['orderby'];
1149
+        
1150
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1151
+			? $this->_req_data['order']
1152
+			: 'ASC';
1153
+        
1154
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1155
+			? $this->_req_data['paged']
1156
+			: 1;
1157
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1158
+			? $this->_req_data['perpage']
1159
+			: $perpage;
1160
+        
1161
+		$offset = ($current_page - 1) * $per_page;
1162
+		$limit  = $all ? null : array($offset, $per_page);
1163
+        
1164
+        
1165
+		//options will match what is in the _views array property
1166
+		switch ($type) {
1167
+			case 'in_use':
1168
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1169
+				break;
1170
+			default:
1171
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1172
+		}
1173
+        
1174
+		return $templates;
1175
+	}
1176 1176
     
1177 1177
     
1178
-    /**
1179
-     * filters etc might need a list of installed message_types
1180
-     * @return array an array of message type objects
1181
-     */
1182
-    public function get_installed_message_types()
1183
-    {
1184
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1185
-        $installed               = array();
1186
-        
1187
-        foreach ($installed_message_types as $message_type) {
1188
-            $installed[$message_type->name] = $message_type;
1189
-        }
1190
-        
1191
-        return $installed;
1192
-    }
1178
+	/**
1179
+	 * filters etc might need a list of installed message_types
1180
+	 * @return array an array of message type objects
1181
+	 */
1182
+	public function get_installed_message_types()
1183
+	{
1184
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1185
+		$installed               = array();
1186
+        
1187
+		foreach ($installed_message_types as $message_type) {
1188
+			$installed[$message_type->name] = $message_type;
1189
+		}
1190
+        
1191
+		return $installed;
1192
+	}
1193 1193
     
1194 1194
     
1195
-    /**
1196
-     * _add_message_template
1197
-     *
1198
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1199
-     *
1200
-     * @param string $message_type
1201
-     * @param string $messenger
1202
-     * @param string $GRP_ID
1203
-     *
1204
-     * @throws EE_error
1205
-     */
1206
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1207
-    {
1208
-        //set values override any request data
1209
-        $message_type = ! empty($message_type) ? $message_type : '';
1210
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1211
-            ? $this->_req_data['message_type']
1212
-            : $message_type;
1213
-        
1214
-        $messenger = ! empty($messenger) ? $messenger : '';
1215
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1216
-            ? $this->_req_data['messenger']
1217
-            : $messenger;
1218
-        
1219
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1220
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1221
-        
1222
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1223
-        if (empty($message_type) || empty($messenger)) {
1224
-            throw new EE_Error(
1225
-                esc_html__(
1226
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1227
-                    'event_espresso'
1228
-                )
1229
-            );
1230
-        }
1231
-        
1232
-        //we need the GRP_ID for the template being used as the base for the new template
1233
-        if (empty($GRP_ID)) {
1234
-            throw new EE_Error(
1235
-                esc_html__(
1236
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1237
-                    'event_espresso'
1238
-                )
1239
-            );
1240
-        }
1241
-        
1242
-        //let's just make sure the template gets generated!
1243
-        
1244
-        //we need to reassign some variables for what the insert is expecting
1245
-        $this->_req_data['MTP_messenger']    = $messenger;
1246
-        $this->_req_data['MTP_message_type'] = $message_type;
1247
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1248
-        $this->_insert_or_update_message_template(true);
1249
-    }
1195
+	/**
1196
+	 * _add_message_template
1197
+	 *
1198
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1199
+	 *
1200
+	 * @param string $message_type
1201
+	 * @param string $messenger
1202
+	 * @param string $GRP_ID
1203
+	 *
1204
+	 * @throws EE_error
1205
+	 */
1206
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1207
+	{
1208
+		//set values override any request data
1209
+		$message_type = ! empty($message_type) ? $message_type : '';
1210
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1211
+			? $this->_req_data['message_type']
1212
+			: $message_type;
1213
+        
1214
+		$messenger = ! empty($messenger) ? $messenger : '';
1215
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1216
+			? $this->_req_data['messenger']
1217
+			: $messenger;
1218
+        
1219
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1220
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1221
+        
1222
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1223
+		if (empty($message_type) || empty($messenger)) {
1224
+			throw new EE_Error(
1225
+				esc_html__(
1226
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1227
+					'event_espresso'
1228
+				)
1229
+			);
1230
+		}
1231
+        
1232
+		//we need the GRP_ID for the template being used as the base for the new template
1233
+		if (empty($GRP_ID)) {
1234
+			throw new EE_Error(
1235
+				esc_html__(
1236
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1237
+					'event_espresso'
1238
+				)
1239
+			);
1240
+		}
1241
+        
1242
+		//let's just make sure the template gets generated!
1243
+        
1244
+		//we need to reassign some variables for what the insert is expecting
1245
+		$this->_req_data['MTP_messenger']    = $messenger;
1246
+		$this->_req_data['MTP_message_type'] = $message_type;
1247
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1248
+		$this->_insert_or_update_message_template(true);
1249
+	}
1250 1250
 
1251 1251
 
1252
-    /**
1253
-     * public wrapper for the _add_message_template method
1254
-     *
1255
-     * @param string $message_type     message type slug
1256
-     * @param string $messenger        messenger slug
1257
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1258
-     *                                 off of.
1259
-     * @throws EE_error
1260
-     */
1261
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1262
-    {
1263
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1264
-    }
1252
+	/**
1253
+	 * public wrapper for the _add_message_template method
1254
+	 *
1255
+	 * @param string $message_type     message type slug
1256
+	 * @param string $messenger        messenger slug
1257
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1258
+	 *                                 off of.
1259
+	 * @throws EE_error
1260
+	 */
1261
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1262
+	{
1263
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1264
+	}
1265 1265
 
1266 1266
 
1267
-    /**
1268
-     * _edit_message_template
1269
-     *
1270
-     * @access protected
1271
-     * @return void
1272
-     * @throws InvalidIdentifierException
1273
-     * @throws DomainException
1274
-     * @throws EE_Error
1275
-     * @throws InvalidArgumentException
1276
-     * @throws ReflectionException
1277
-     * @throws InvalidDataTypeException
1278
-     * @throws InvalidInterfaceException
1279
-     */
1280
-    protected function _edit_message_template()
1281
-    {
1282
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1283
-        $template_fields = '';
1284
-        $sidebar_fields  = '';
1285
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1286
-        // valid html in the templates.
1287
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1288
-        
1289
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1290
-            ? absint($this->_req_data['id'])
1291
-            : false;
1292
-        
1293
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1294
-        $message_template_group = $this->_message_template_group;
1295
-        $c_label                = $message_template_group->context_label();
1296
-        $c_config               = $message_template_group->contexts_config();
1297
-        
1298
-        reset($c_config);
1299
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1300
-            ? strtolower($this->_req_data['context'])
1301
-            : key($c_config);
1302
-        
1303
-        
1304
-        if (empty($GRP_ID)) {
1305
-            $action = 'insert_message_template';
1306
-            $edit_message_template_form_url = add_query_arg(
1307
-                array('action' => $action, 'noheader' => true),
1308
-                EE_MSG_ADMIN_URL
1309
-            );
1310
-        } else {
1311
-            $action = 'update_message_template';
1312
-            $edit_message_template_form_url = add_query_arg(
1313
-                array('action' => $action, 'noheader' => true),
1314
-                EE_MSG_ADMIN_URL
1315
-            );
1316
-        }
1317
-        
1318
-        //set active messenger for this view
1319
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1320
-            $message_template_group->messenger()
1321
-        );
1322
-        $this->_active_message_type_name = $message_template_group->message_type();
1323
-        
1324
-        
1325
-        //Do we have any validation errors?
1326
-        $validators = $this->_get_transient();
1327
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1328
-        
1329
-        
1330
-        //we need to assemble the title from Various details
1331
-        $context_label = sprintf(
1332
-            esc_html__('(%s %s)', 'event_espresso'),
1333
-            $c_config[$context]['label'],
1334
-            ucwords($c_label['label'])
1335
-        );
1336
-        
1337
-        $title = sprintf(
1338
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1339
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1340
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1341
-            $context_label
1342
-        );
1343
-        
1344
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1345
-        $this->_template_args['message_template'] = $message_template_group;
1346
-        $this->_template_args['is_extra_fields']  = false;
1347
-        
1348
-        
1349
-        //let's get EEH_MSG_Template so we can get template form fields
1350
-        $template_field_structure = EEH_MSG_Template::get_fields(
1351
-            $message_template_group->messenger(),
1352
-            $message_template_group->message_type()
1353
-        );
1354
-        
1355
-        if ( ! $template_field_structure) {
1356
-            $template_field_structure = false;
1357
-            $template_fields          = esc_html__(
1358
-                'There was an error in assembling the fields for this display (you should see an error message)',
1359
-                'event_espresso'
1360
-            );
1361
-        }
1362
-        
1363
-        
1364
-        $message_templates = $message_template_group->context_templates();
1365
-        
1366
-        
1367
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1368
-        // will get handled in the "extra" array.
1369
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1370
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1371
-                unset($template_field_structure[$context][$reference_field]);
1372
-            }
1373
-        }
1374
-        
1375
-        //let's loop through the template_field_structure and actually assemble the input fields!
1376
-        if ( ! empty($template_field_structure)) {
1377
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1378
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1379
-                // the extra array and reset them.
1380
-                if ($template_field === 'extra') {
1381
-                    $this->_template_args['is_extra_fields'] = true;
1382
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1383
-                        $message_template = $message_templates[$context][$reference_field];
1384
-                        $content          = $message_template instanceof EE_Message_Template
1385
-                            ? $message_template->get('MTP_content')
1386
-                            : '';
1387
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1388
-                            //let's verify if we need this extra field via the shortcodes parameter.
1389
-                            $continue = false;
1390
-                            if (isset($extra_array['shortcodes_required'])) {
1391
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1392
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1393
-                                        $continue = true;
1394
-                                    }
1395
-                                }
1396
-                                if ($continue) {
1397
-                                    continue;
1398
-                                }
1399
-                            }
1267
+	/**
1268
+	 * _edit_message_template
1269
+	 *
1270
+	 * @access protected
1271
+	 * @return void
1272
+	 * @throws InvalidIdentifierException
1273
+	 * @throws DomainException
1274
+	 * @throws EE_Error
1275
+	 * @throws InvalidArgumentException
1276
+	 * @throws ReflectionException
1277
+	 * @throws InvalidDataTypeException
1278
+	 * @throws InvalidInterfaceException
1279
+	 */
1280
+	protected function _edit_message_template()
1281
+	{
1282
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1283
+		$template_fields = '';
1284
+		$sidebar_fields  = '';
1285
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1286
+		// valid html in the templates.
1287
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1288
+        
1289
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1290
+			? absint($this->_req_data['id'])
1291
+			: false;
1292
+        
1293
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1294
+		$message_template_group = $this->_message_template_group;
1295
+		$c_label                = $message_template_group->context_label();
1296
+		$c_config               = $message_template_group->contexts_config();
1297
+        
1298
+		reset($c_config);
1299
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1300
+			? strtolower($this->_req_data['context'])
1301
+			: key($c_config);
1302
+        
1303
+        
1304
+		if (empty($GRP_ID)) {
1305
+			$action = 'insert_message_template';
1306
+			$edit_message_template_form_url = add_query_arg(
1307
+				array('action' => $action, 'noheader' => true),
1308
+				EE_MSG_ADMIN_URL
1309
+			);
1310
+		} else {
1311
+			$action = 'update_message_template';
1312
+			$edit_message_template_form_url = add_query_arg(
1313
+				array('action' => $action, 'noheader' => true),
1314
+				EE_MSG_ADMIN_URL
1315
+			);
1316
+		}
1317
+        
1318
+		//set active messenger for this view
1319
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1320
+			$message_template_group->messenger()
1321
+		);
1322
+		$this->_active_message_type_name = $message_template_group->message_type();
1323
+        
1324
+        
1325
+		//Do we have any validation errors?
1326
+		$validators = $this->_get_transient();
1327
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1328
+        
1329
+        
1330
+		//we need to assemble the title from Various details
1331
+		$context_label = sprintf(
1332
+			esc_html__('(%s %s)', 'event_espresso'),
1333
+			$c_config[$context]['label'],
1334
+			ucwords($c_label['label'])
1335
+		);
1336
+        
1337
+		$title = sprintf(
1338
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1339
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1340
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1341
+			$context_label
1342
+		);
1343
+        
1344
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1345
+		$this->_template_args['message_template'] = $message_template_group;
1346
+		$this->_template_args['is_extra_fields']  = false;
1347
+        
1348
+        
1349
+		//let's get EEH_MSG_Template so we can get template form fields
1350
+		$template_field_structure = EEH_MSG_Template::get_fields(
1351
+			$message_template_group->messenger(),
1352
+			$message_template_group->message_type()
1353
+		);
1354
+        
1355
+		if ( ! $template_field_structure) {
1356
+			$template_field_structure = false;
1357
+			$template_fields          = esc_html__(
1358
+				'There was an error in assembling the fields for this display (you should see an error message)',
1359
+				'event_espresso'
1360
+			);
1361
+		}
1362
+        
1363
+        
1364
+		$message_templates = $message_template_group->context_templates();
1365
+        
1366
+        
1367
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1368
+		// will get handled in the "extra" array.
1369
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1370
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1371
+				unset($template_field_structure[$context][$reference_field]);
1372
+			}
1373
+		}
1374
+        
1375
+		//let's loop through the template_field_structure and actually assemble the input fields!
1376
+		if ( ! empty($template_field_structure)) {
1377
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1378
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1379
+				// the extra array and reset them.
1380
+				if ($template_field === 'extra') {
1381
+					$this->_template_args['is_extra_fields'] = true;
1382
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1383
+						$message_template = $message_templates[$context][$reference_field];
1384
+						$content          = $message_template instanceof EE_Message_Template
1385
+							? $message_template->get('MTP_content')
1386
+							: '';
1387
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1388
+							//let's verify if we need this extra field via the shortcodes parameter.
1389
+							$continue = false;
1390
+							if (isset($extra_array['shortcodes_required'])) {
1391
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1392
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1393
+										$continue = true;
1394
+									}
1395
+								}
1396
+								if ($continue) {
1397
+									continue;
1398
+								}
1399
+							}
1400 1400
                             
1401
-                            $field_id                                = $reference_field
1402
-                                                                       . '-'
1403
-                                                                       . $extra_field
1404
-                                                                       . '-content';
1405
-                            $template_form_fields[$field_id]         = $extra_array;
1406
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1407
-                                                                       . $reference_field
1408
-                                                                       . '][content]['
1409
-                                                                       . $extra_field . ']';
1410
-                            $css_class                               = isset($extra_array['css_class'])
1411
-                                ? $extra_array['css_class']
1412
-                                : '';
1401
+							$field_id                                = $reference_field
1402
+																	   . '-'
1403
+																	   . $extra_field
1404
+																	   . '-content';
1405
+							$template_form_fields[$field_id]         = $extra_array;
1406
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1407
+																	   . $reference_field
1408
+																	   . '][content]['
1409
+																	   . $extra_field . ']';
1410
+							$css_class                               = isset($extra_array['css_class'])
1411
+								? $extra_array['css_class']
1412
+								: '';
1413 1413
                             
1414
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1415
-                                && in_array($extra_field, $v_fields, true)
1416
-                                &&
1417
-                                (
1418
-                                    is_array($validators[$extra_field])
1419
-                                    && isset($validators[$extra_field]['msg'])
1420
-                                )
1421
-                                ? 'validate-error ' . $css_class
1422
-                                : $css_class;
1414
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1415
+								&& in_array($extra_field, $v_fields, true)
1416
+								&&
1417
+								(
1418
+									is_array($validators[$extra_field])
1419
+									&& isset($validators[$extra_field]['msg'])
1420
+								)
1421
+								? 'validate-error ' . $css_class
1422
+								: $css_class;
1423 1423
                             
1424
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1425
-                                                                        && isset($content[$extra_field])
1426
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1427
-                                : '';
1424
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1425
+																		&& isset($content[$extra_field])
1426
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1427
+								: '';
1428 1428
                             
1429
-                            //do we have a validation error?  if we do then let's use that value instead
1430
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1431
-                                ? $validators[$extra_field]['value']
1432
-                                : $template_form_fields[$field_id]['value'];
1429
+							//do we have a validation error?  if we do then let's use that value instead
1430
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1431
+								? $validators[$extra_field]['value']
1432
+								: $template_form_fields[$field_id]['value'];
1433 1433
                             
1434 1434
                             
1435
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1435
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1436 1436
                             
1437
-                            //shortcode selector
1438
-                            $field_name_to_use                                 = $extra_field === 'main'
1439
-                                ? 'content'
1440
-                                : $extra_field;
1441
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1442
-                                $field_name_to_use,
1443
-                                $field_id
1444
-                            );
1437
+							//shortcode selector
1438
+							$field_name_to_use                                 = $extra_field === 'main'
1439
+								? 'content'
1440
+								: $extra_field;
1441
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1442
+								$field_name_to_use,
1443
+								$field_id
1444
+							);
1445 1445
                             
1446
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1447
-                                //we want to decode the entities
1448
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1449
-                                    html_entity_decode(
1450
-                                        $template_form_fields[$field_id]['value'],
1451
-                                        ENT_QUOTES,
1452
-                                        "UTF-8")
1453
-                                );
1446
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1447
+								//we want to decode the entities
1448
+								$template_form_fields[$field_id]['value'] = stripslashes(
1449
+									html_entity_decode(
1450
+										$template_form_fields[$field_id]['value'],
1451
+										ENT_QUOTES,
1452
+										"UTF-8")
1453
+								);
1454 1454
                                 
1455
-                            }/**/
1456
-                        }
1457
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1458
-                        $templatefield_templatename_id = $reference_field . '-name';
1455
+							}/**/
1456
+						}
1457
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1458
+						$templatefield_templatename_id = $reference_field . '-name';
1459 1459
                         
1460
-                        $template_form_fields[$templatefield_MTP_id] = array(
1461
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1462
-                            'label'      => null,
1463
-                            'input'      => 'hidden',
1464
-                            'type'       => 'int',
1465
-                            'required'   => false,
1466
-                            'validation' => false,
1467
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1468
-                            'css_class'  => '',
1469
-                            'format'     => '%d',
1470
-                            'db-col'     => 'MTP_ID'
1471
-                        );
1460
+						$template_form_fields[$templatefield_MTP_id] = array(
1461
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1462
+							'label'      => null,
1463
+							'input'      => 'hidden',
1464
+							'type'       => 'int',
1465
+							'required'   => false,
1466
+							'validation' => false,
1467
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1468
+							'css_class'  => '',
1469
+							'format'     => '%d',
1470
+							'db-col'     => 'MTP_ID'
1471
+						);
1472 1472
                         
1473
-                        $template_form_fields[$templatefield_templatename_id] = array(
1474
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1475
-                            'label'      => null,
1476
-                            'input'      => 'hidden',
1477
-                            'type'       => 'string',
1478
-                            'required'   => false,
1479
-                            'validation' => true,
1480
-                            'value'      => $reference_field,
1481
-                            'css_class'  => '',
1482
-                            'format'     => '%s',
1483
-                            'db-col'     => 'MTP_template_field'
1484
-                        );
1485
-                    }
1486
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1487
-                } else {
1488
-                    $field_id                                 = $template_field . '-content';
1489
-                    $template_form_fields[$field_id]          = $field_setup_array;
1490
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1491
-                    $message_template                         = isset($message_templates[$context][$template_field])
1492
-                        ? $message_templates[$context][$template_field]
1493
-                        : null;
1494
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1495
-                                                                && is_array($message_templates[$context])
1496
-                                                                && $message_template instanceof EE_Message_Template
1497
-                        ? $message_template->get('MTP_content')
1498
-                        : '';
1473
+						$template_form_fields[$templatefield_templatename_id] = array(
1474
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1475
+							'label'      => null,
1476
+							'input'      => 'hidden',
1477
+							'type'       => 'string',
1478
+							'required'   => false,
1479
+							'validation' => true,
1480
+							'value'      => $reference_field,
1481
+							'css_class'  => '',
1482
+							'format'     => '%s',
1483
+							'db-col'     => 'MTP_template_field'
1484
+						);
1485
+					}
1486
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1487
+				} else {
1488
+					$field_id                                 = $template_field . '-content';
1489
+					$template_form_fields[$field_id]          = $field_setup_array;
1490
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1491
+					$message_template                         = isset($message_templates[$context][$template_field])
1492
+						? $message_templates[$context][$template_field]
1493
+						: null;
1494
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1495
+																&& is_array($message_templates[$context])
1496
+																&& $message_template instanceof EE_Message_Template
1497
+						? $message_template->get('MTP_content')
1498
+						: '';
1499 1499
                     
1500
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1501
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1502
-                        ? $validators[$template_field]['value']
1503
-                        : $template_form_fields[$field_id]['value'];
1500
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1501
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1502
+						? $validators[$template_field]['value']
1503
+						: $template_form_fields[$field_id]['value'];
1504 1504
                     
1505 1505
                     
1506
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1507
-                    $css_class                                    = isset($field_setup_array['css_class'])
1508
-                        ? $field_setup_array['css_class']
1509
-                        : '';
1510
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1511
-                                                                    && in_array($template_field, $v_fields, true)
1512
-                                                                    && isset($validators[$template_field]['msg'])
1513
-                        ? 'validate-error ' . $css_class
1514
-                        : $css_class;
1506
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1507
+					$css_class                                    = isset($field_setup_array['css_class'])
1508
+						? $field_setup_array['css_class']
1509
+						: '';
1510
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1511
+																	&& in_array($template_field, $v_fields, true)
1512
+																	&& isset($validators[$template_field]['msg'])
1513
+						? 'validate-error ' . $css_class
1514
+						: $css_class;
1515 1515
                     
1516
-                    //shortcode selector
1517
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1518
-                        $template_field, $field_id
1519
-                    );
1520
-                }
1516
+					//shortcode selector
1517
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1518
+						$template_field, $field_id
1519
+					);
1520
+				}
1521 1521
                 
1522
-                //k took care of content field(s) now let's take care of others.
1522
+				//k took care of content field(s) now let's take care of others.
1523 1523
                 
1524
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1525
-                $templatefield_field_templatename_id = $template_field . '-name';
1524
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1525
+				$templatefield_field_templatename_id = $template_field . '-name';
1526 1526
                 
1527
-                //foreach template field there are actually two form fields created
1528
-                $template_form_fields[$templatefield_MTP_id] = array(
1529
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1530
-                    'label'      => null,
1531
-                    'input'      => 'hidden',
1532
-                    'type'       => 'int',
1533
-                    'required'   => false,
1534
-                    'validation' => true,
1535
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1536
-                    'css_class'  => '',
1537
-                    'format'     => '%d',
1538
-                    'db-col'     => 'MTP_ID'
1539
-                );
1527
+				//foreach template field there are actually two form fields created
1528
+				$template_form_fields[$templatefield_MTP_id] = array(
1529
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1530
+					'label'      => null,
1531
+					'input'      => 'hidden',
1532
+					'type'       => 'int',
1533
+					'required'   => false,
1534
+					'validation' => true,
1535
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1536
+					'css_class'  => '',
1537
+					'format'     => '%d',
1538
+					'db-col'     => 'MTP_ID'
1539
+				);
1540 1540
                 
1541
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1542
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1543
-                    'label'      => null,
1544
-                    'input'      => 'hidden',
1545
-                    'type'       => 'string',
1546
-                    'required'   => false,
1547
-                    'validation' => true,
1548
-                    'value'      => $template_field,
1549
-                    'css_class'  => '',
1550
-                    'format'     => '%s',
1551
-                    'db-col'     => 'MTP_template_field'
1552
-                );
1541
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1542
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1543
+					'label'      => null,
1544
+					'input'      => 'hidden',
1545
+					'type'       => 'string',
1546
+					'required'   => false,
1547
+					'validation' => true,
1548
+					'value'      => $template_field,
1549
+					'css_class'  => '',
1550
+					'format'     => '%s',
1551
+					'db-col'     => 'MTP_template_field'
1552
+				);
1553 1553
                 
1554
-            }
1554
+			}
1555 1555
             
1556
-            //add other fields
1557
-            $template_form_fields['ee-msg-current-context'] = array(
1558
-                'name'       => 'MTP_context',
1559
-                'label'      => null,
1560
-                'input'      => 'hidden',
1561
-                'type'       => 'string',
1562
-                'required'   => false,
1563
-                'validation' => true,
1564
-                'value'      => $context,
1565
-                'css_class'  => '',
1566
-                'format'     => '%s',
1567
-                'db-col'     => 'MTP_context'
1568
-            );
1556
+			//add other fields
1557
+			$template_form_fields['ee-msg-current-context'] = array(
1558
+				'name'       => 'MTP_context',
1559
+				'label'      => null,
1560
+				'input'      => 'hidden',
1561
+				'type'       => 'string',
1562
+				'required'   => false,
1563
+				'validation' => true,
1564
+				'value'      => $context,
1565
+				'css_class'  => '',
1566
+				'format'     => '%s',
1567
+				'db-col'     => 'MTP_context'
1568
+			);
1569 1569
             
1570
-            $template_form_fields['ee-msg-grp-id'] = array(
1571
-                'name'       => 'GRP_ID',
1572
-                'label'      => null,
1573
-                'input'      => 'hidden',
1574
-                'type'       => 'int',
1575
-                'required'   => false,
1576
-                'validation' => true,
1577
-                'value'      => $GRP_ID,
1578
-                'css_class'  => '',
1579
-                'format'     => '%d',
1580
-                'db-col'     => 'GRP_ID'
1581
-            );
1570
+			$template_form_fields['ee-msg-grp-id'] = array(
1571
+				'name'       => 'GRP_ID',
1572
+				'label'      => null,
1573
+				'input'      => 'hidden',
1574
+				'type'       => 'int',
1575
+				'required'   => false,
1576
+				'validation' => true,
1577
+				'value'      => $GRP_ID,
1578
+				'css_class'  => '',
1579
+				'format'     => '%d',
1580
+				'db-col'     => 'GRP_ID'
1581
+			);
1582 1582
             
1583
-            $template_form_fields['ee-msg-messenger'] = array(
1584
-                'name'       => 'MTP_messenger',
1585
-                'label'      => null,
1586
-                'input'      => 'hidden',
1587
-                'type'       => 'string',
1588
-                'required'   => false,
1589
-                'validation' => true,
1590
-                'value'      => $message_template_group->messenger(),
1591
-                'css_class'  => '',
1592
-                'format'     => '%s',
1593
-                'db-col'     => 'MTP_messenger'
1594
-            );
1583
+			$template_form_fields['ee-msg-messenger'] = array(
1584
+				'name'       => 'MTP_messenger',
1585
+				'label'      => null,
1586
+				'input'      => 'hidden',
1587
+				'type'       => 'string',
1588
+				'required'   => false,
1589
+				'validation' => true,
1590
+				'value'      => $message_template_group->messenger(),
1591
+				'css_class'  => '',
1592
+				'format'     => '%s',
1593
+				'db-col'     => 'MTP_messenger'
1594
+			);
1595 1595
             
1596
-            $template_form_fields['ee-msg-message-type'] = array(
1597
-                'name'       => 'MTP_message_type',
1598
-                'label'      => null,
1599
-                'input'      => 'hidden',
1600
-                'type'       => 'string',
1601
-                'required'   => false,
1602
-                'validation' => true,
1603
-                'value'      => $message_template_group->message_type(),
1604
-                'css_class'  => '',
1605
-                'format'     => '%s',
1606
-                'db-col'     => 'MTP_message_type'
1607
-            );
1596
+			$template_form_fields['ee-msg-message-type'] = array(
1597
+				'name'       => 'MTP_message_type',
1598
+				'label'      => null,
1599
+				'input'      => 'hidden',
1600
+				'type'       => 'string',
1601
+				'required'   => false,
1602
+				'validation' => true,
1603
+				'value'      => $message_template_group->message_type(),
1604
+				'css_class'  => '',
1605
+				'format'     => '%s',
1606
+				'db-col'     => 'MTP_message_type'
1607
+			);
1608 1608
             
1609
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1610
-                'name'       => 'MTP_is_global',
1611
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1612
-                'input'      => 'hidden',
1613
-                'type'       => 'int',
1614
-                'required'   => false,
1615
-                'validation' => true,
1616
-                'value'      => $message_template_group->get('MTP_is_global'),
1617
-                'css_class'  => '',
1618
-                'format'     => '%d',
1619
-                'db-col'     => 'MTP_is_global'
1620
-            );
1609
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1610
+				'name'       => 'MTP_is_global',
1611
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1612
+				'input'      => 'hidden',
1613
+				'type'       => 'int',
1614
+				'required'   => false,
1615
+				'validation' => true,
1616
+				'value'      => $message_template_group->get('MTP_is_global'),
1617
+				'css_class'  => '',
1618
+				'format'     => '%d',
1619
+				'db-col'     => 'MTP_is_global'
1620
+			);
1621 1621
             
1622
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1623
-                'name'       => 'MTP_is_override',
1624
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1625
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1626
-                'type'       => 'int',
1627
-                'required'   => false,
1628
-                'validation' => true,
1629
-                'value'      => $message_template_group->get('MTP_is_override'),
1630
-                'css_class'  => '',
1631
-                'format'     => '%d',
1632
-                'db-col'     => 'MTP_is_override'
1633
-            );
1622
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1623
+				'name'       => 'MTP_is_override',
1624
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1625
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1626
+				'type'       => 'int',
1627
+				'required'   => false,
1628
+				'validation' => true,
1629
+				'value'      => $message_template_group->get('MTP_is_override'),
1630
+				'css_class'  => '',
1631
+				'format'     => '%d',
1632
+				'db-col'     => 'MTP_is_override'
1633
+			);
1634 1634
             
1635
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1636
-                'name'       => 'MTP_is_active',
1637
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1638
-                'input'      => 'hidden',
1639
-                'type'       => 'int',
1640
-                'required'   => false,
1641
-                'validation' => true,
1642
-                'value'      => $message_template_group->is_active(),
1643
-                'css_class'  => '',
1644
-                'format'     => '%d',
1645
-                'db-col'     => 'MTP_is_active'
1646
-            );
1635
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1636
+				'name'       => 'MTP_is_active',
1637
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1638
+				'input'      => 'hidden',
1639
+				'type'       => 'int',
1640
+				'required'   => false,
1641
+				'validation' => true,
1642
+				'value'      => $message_template_group->is_active(),
1643
+				'css_class'  => '',
1644
+				'format'     => '%d',
1645
+				'db-col'     => 'MTP_is_active'
1646
+			);
1647 1647
             
1648
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1649
-                'name'       => 'MTP_deleted',
1650
-                'label'      => null,
1651
-                'input'      => 'hidden',
1652
-                'type'       => 'int',
1653
-                'required'   => false,
1654
-                'validation' => true,
1655
-                'value'      => $message_template_group->get('MTP_deleted'),
1656
-                'css_class'  => '',
1657
-                'format'     => '%d',
1658
-                'db-col'     => 'MTP_deleted'
1659
-            );
1660
-            $sidebar_form_fields['ee-msg-author']  = array(
1661
-                'name'       => 'MTP_user_id',
1662
-                'label'      => esc_html__('Author', 'event_espresso'),
1663
-                'input'      => 'hidden',
1664
-                'type'       => 'int',
1665
-                'required'   => false,
1666
-                'validation' => false,
1667
-                'value'      => $message_template_group->user(),
1668
-                'format'     => '%d',
1669
-                'db-col'     => 'MTP_user_id'
1670
-            );
1648
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1649
+				'name'       => 'MTP_deleted',
1650
+				'label'      => null,
1651
+				'input'      => 'hidden',
1652
+				'type'       => 'int',
1653
+				'required'   => false,
1654
+				'validation' => true,
1655
+				'value'      => $message_template_group->get('MTP_deleted'),
1656
+				'css_class'  => '',
1657
+				'format'     => '%d',
1658
+				'db-col'     => 'MTP_deleted'
1659
+			);
1660
+			$sidebar_form_fields['ee-msg-author']  = array(
1661
+				'name'       => 'MTP_user_id',
1662
+				'label'      => esc_html__('Author', 'event_espresso'),
1663
+				'input'      => 'hidden',
1664
+				'type'       => 'int',
1665
+				'required'   => false,
1666
+				'validation' => false,
1667
+				'value'      => $message_template_group->user(),
1668
+				'format'     => '%d',
1669
+				'db-col'     => 'MTP_user_id'
1670
+			);
1671 1671
             
1672
-            $sidebar_form_fields['ee-msg-route'] = array(
1673
-                'name'  => 'action',
1674
-                'input' => 'hidden',
1675
-                'type'  => 'string',
1676
-                'value' => $action
1677
-            );
1672
+			$sidebar_form_fields['ee-msg-route'] = array(
1673
+				'name'  => 'action',
1674
+				'input' => 'hidden',
1675
+				'type'  => 'string',
1676
+				'value' => $action
1677
+			);
1678 1678
             
1679
-            $sidebar_form_fields['ee-msg-id']        = array(
1680
-                'name'  => 'id',
1681
-                'input' => 'hidden',
1682
-                'type'  => 'int',
1683
-                'value' => $GRP_ID
1684
-            );
1685
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1686
-                'name'  => $action . '_nonce',
1687
-                'input' => 'hidden',
1688
-                'type'  => 'string',
1689
-                'value' => wp_create_nonce($action . '_nonce')
1690
-            );
1679
+			$sidebar_form_fields['ee-msg-id']        = array(
1680
+				'name'  => 'id',
1681
+				'input' => 'hidden',
1682
+				'type'  => 'int',
1683
+				'value' => $GRP_ID
1684
+			);
1685
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1686
+				'name'  => $action . '_nonce',
1687
+				'input' => 'hidden',
1688
+				'type'  => 'string',
1689
+				'value' => wp_create_nonce($action . '_nonce')
1690
+			);
1691 1691
             
1692
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1693
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1694
-                    'name'  => 'template_switch',
1695
-                    'input' => 'hidden',
1696
-                    'type'  => 'int',
1697
-                    'value' => 1
1698
-                );
1699
-            }
1692
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1693
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1694
+					'name'  => 'template_switch',
1695
+					'input' => 'hidden',
1696
+					'type'  => 'int',
1697
+					'value' => 1
1698
+				);
1699
+			}
1700 1700
             
1701 1701
             
1702
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1703
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1702
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1703
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1704 1704
             
1705 1705
             
1706
-        } //end if ( !empty($template_field_structure) )
1707
-        
1708
-        //set extra content for publish box
1709
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1710
-        $this->_set_publish_post_box_vars(
1711
-            'id',
1712
-            $GRP_ID,
1713
-            false,
1714
-            add_query_arg(
1715
-                array('action' => 'global_mtps'),
1716
-                $this->_admin_base_url
1717
-            )
1718
-        );
1719
-        
1720
-        //add preview button
1721
-        $preview_url    = parent::add_query_args_and_nonce(
1722
-            array(
1723
-                'message_type' => $message_template_group->message_type(),
1724
-                'messenger'    => $message_template_group->messenger(),
1725
-                'context'      => $context,
1726
-                'GRP_ID'       => $GRP_ID,
1727
-                'action'       => 'preview_message'
1728
-            ),
1729
-            $this->_admin_base_url
1730
-        );
1731
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1732
-                          . esc_html__('Preview', 'event_espresso')
1733
-                          . '</a>';
1734
-        
1735
-        
1736
-        //setup context switcher
1737
-        $context_switcher_args = array(
1738
-            'page'    => 'espresso_messages',
1739
-            'action'  => 'edit_message_template',
1740
-            'id'      => $GRP_ID,
1741
-            'context' => $context,
1742
-            'extra'   => $preview_button
1743
-        );
1744
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1745
-        
1746
-        
1747
-        //main box
1748
-        $this->_template_args['template_fields']                         = $template_fields;
1749
-        $this->_template_args['sidebar_box_id']                          = 'details';
1750
-        $this->_template_args['action']                                  = $action;
1751
-        $this->_template_args['context']                                 = $context;
1752
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1753
-        $this->_template_args['learn_more_about_message_templates_link'] =
1754
-            $this->_learn_more_about_message_templates_link();
1755
-        
1756
-        
1757
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1758
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1759
-            $message_template_group,
1760
-            $context,
1761
-            $context_label
1762
-        );
1763
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1764
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1765
-        
1766
-        $this->_template_path = $this->_template_args['GRP_ID']
1767
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1768
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1769
-        
1770
-        //send along EE_Message_Template_Group object for further template use.
1771
-        $this->_template_args['MTP'] = $message_template_group;
1772
-        
1773
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1774
-            $this->_template_path,
1775
-            $this->_template_args,
1776
-            true
1777
-        );
1778
-        
1779
-        
1780
-        //finally, let's set the admin_page title
1781
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1782
-        
1783
-        
1784
-        //we need to take care of setting the shortcodes property for use elsewhere.
1785
-        $this->_set_shortcodes();
1786
-        
1787
-        
1788
-        //final template wrapper
1789
-        $this->display_admin_page_with_sidebar();
1790
-    }
1706
+		} //end if ( !empty($template_field_structure) )
1707
+        
1708
+		//set extra content for publish box
1709
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1710
+		$this->_set_publish_post_box_vars(
1711
+			'id',
1712
+			$GRP_ID,
1713
+			false,
1714
+			add_query_arg(
1715
+				array('action' => 'global_mtps'),
1716
+				$this->_admin_base_url
1717
+			)
1718
+		);
1719
+        
1720
+		//add preview button
1721
+		$preview_url    = parent::add_query_args_and_nonce(
1722
+			array(
1723
+				'message_type' => $message_template_group->message_type(),
1724
+				'messenger'    => $message_template_group->messenger(),
1725
+				'context'      => $context,
1726
+				'GRP_ID'       => $GRP_ID,
1727
+				'action'       => 'preview_message'
1728
+			),
1729
+			$this->_admin_base_url
1730
+		);
1731
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1732
+						  . esc_html__('Preview', 'event_espresso')
1733
+						  . '</a>';
1734
+        
1735
+        
1736
+		//setup context switcher
1737
+		$context_switcher_args = array(
1738
+			'page'    => 'espresso_messages',
1739
+			'action'  => 'edit_message_template',
1740
+			'id'      => $GRP_ID,
1741
+			'context' => $context,
1742
+			'extra'   => $preview_button
1743
+		);
1744
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1745
+        
1746
+        
1747
+		//main box
1748
+		$this->_template_args['template_fields']                         = $template_fields;
1749
+		$this->_template_args['sidebar_box_id']                          = 'details';
1750
+		$this->_template_args['action']                                  = $action;
1751
+		$this->_template_args['context']                                 = $context;
1752
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1753
+		$this->_template_args['learn_more_about_message_templates_link'] =
1754
+			$this->_learn_more_about_message_templates_link();
1755
+        
1756
+        
1757
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1758
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1759
+			$message_template_group,
1760
+			$context,
1761
+			$context_label
1762
+		);
1763
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1764
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1765
+        
1766
+		$this->_template_path = $this->_template_args['GRP_ID']
1767
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1768
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1769
+        
1770
+		//send along EE_Message_Template_Group object for further template use.
1771
+		$this->_template_args['MTP'] = $message_template_group;
1772
+        
1773
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1774
+			$this->_template_path,
1775
+			$this->_template_args,
1776
+			true
1777
+		);
1778
+        
1779
+        
1780
+		//finally, let's set the admin_page title
1781
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1782
+        
1783
+        
1784
+		//we need to take care of setting the shortcodes property for use elsewhere.
1785
+		$this->_set_shortcodes();
1786
+        
1787
+        
1788
+		//final template wrapper
1789
+		$this->display_admin_page_with_sidebar();
1790
+	}
1791 1791
     
1792 1792
     
1793
-    public function filter_tinymce_init($mceInit, $editor_id)
1794
-    {
1795
-        return $mceInit;
1796
-    }
1793
+	public function filter_tinymce_init($mceInit, $editor_id)
1794
+	{
1795
+		return $mceInit;
1796
+	}
1797 1797
     
1798 1798
     
1799
-    public function add_context_switcher()
1800
-    {
1801
-        return $this->_context_switcher;
1802
-    }
1799
+	public function add_context_switcher()
1800
+	{
1801
+		return $this->_context_switcher;
1802
+	}
1803 1803
 
1804 1804
 
1805
-    /**
1806
-     * Adds the activation/deactivation toggle for the message template context.
1807
-     *
1808
-     * @param EE_Message_Template_Group $message_template_group
1809
-     * @param string                    $context
1810
-     * @param string                    $context_label
1811
-     * @return string
1812
-     * @throws DomainException
1813
-     * @throws EE_Error
1814
-     * @throws InvalidIdentifierException
1815
-     */
1816
-    protected function add_active_context_element(
1817
-        EE_Message_Template_Group $message_template_group,
1818
-        $context,
1819
-        $context_label
1820
-    ) {
1821
-        $template_args = array(
1822
-            'context' => $context,
1823
-            'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1824
-            'is_active' => $message_template_group->is_context_active($context),
1825
-            'on_off_action' => $message_template_group->is_context_active($context)
1826
-                ? 'context-off'
1827
-                : 'context-on',
1828
-            'context_label' => str_replace(array('(', ')'), '', $context_label),
1829
-            'message_template_group_id' => $message_template_group->ID()
1830
-        );
1831
-        return EEH_Template::display_template(
1832
-          EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1833
-          $template_args,
1834
-          true
1835
-        );
1836
-    }
1805
+	/**
1806
+	 * Adds the activation/deactivation toggle for the message template context.
1807
+	 *
1808
+	 * @param EE_Message_Template_Group $message_template_group
1809
+	 * @param string                    $context
1810
+	 * @param string                    $context_label
1811
+	 * @return string
1812
+	 * @throws DomainException
1813
+	 * @throws EE_Error
1814
+	 * @throws InvalidIdentifierException
1815
+	 */
1816
+	protected function add_active_context_element(
1817
+		EE_Message_Template_Group $message_template_group,
1818
+		$context,
1819
+		$context_label
1820
+	) {
1821
+		$template_args = array(
1822
+			'context' => $context,
1823
+			'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1824
+			'is_active' => $message_template_group->is_context_active($context),
1825
+			'on_off_action' => $message_template_group->is_context_active($context)
1826
+				? 'context-off'
1827
+				: 'context-on',
1828
+			'context_label' => str_replace(array('(', ')'), '', $context_label),
1829
+			'message_template_group_id' => $message_template_group->ID()
1830
+		);
1831
+		return EEH_Template::display_template(
1832
+		  EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1833
+		  $template_args,
1834
+		  true
1835
+		);
1836
+	}
1837 1837
 
1838 1838
 
1839
-    /**
1840
-     * Ajax callback for `toggle_context_template` ajax action.
1841
-     * Handles toggling the message context on or off.
1842
-     * @throws EE_Error
1843
-     * @throws InvalidArgumentException
1844
-     * @throws InvalidDataTypeException
1845
-     * @throws InvalidIdentifierException
1846
-     * @throws InvalidInterfaceException
1847
-     */
1848
-    public function toggle_context_template()
1849
-    {
1850
-        $success = true;
1851
-        //check for required data
1852
-        if (!isset(
1853
-            $this->_req_data['message_template_group_id'],
1854
-            $this->_req_data['context'],
1855
-            $this->_req_data['status']
1856
-        )) {
1857
-            EE_Error::add_error(
1858
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1859
-                __FILE__,
1860
-                __FUNCTION__,
1861
-                __LINE__
1862
-            );
1863
-            $success = false;
1864
-        }
1839
+	/**
1840
+	 * Ajax callback for `toggle_context_template` ajax action.
1841
+	 * Handles toggling the message context on or off.
1842
+	 * @throws EE_Error
1843
+	 * @throws InvalidArgumentException
1844
+	 * @throws InvalidDataTypeException
1845
+	 * @throws InvalidIdentifierException
1846
+	 * @throws InvalidInterfaceException
1847
+	 */
1848
+	public function toggle_context_template()
1849
+	{
1850
+		$success = true;
1851
+		//check for required data
1852
+		if (!isset(
1853
+			$this->_req_data['message_template_group_id'],
1854
+			$this->_req_data['context'],
1855
+			$this->_req_data['status']
1856
+		)) {
1857
+			EE_Error::add_error(
1858
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1859
+				__FILE__,
1860
+				__FUNCTION__,
1861
+				__LINE__
1862
+			);
1863
+			$success = false;
1864
+		}
1865 1865
 
1866
-        $nonce = isset($this->_req_data['toggle_context_nonce'])
1867
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1868
-            : '';
1869
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1870
-        $this->_verify_nonce($nonce, $nonce_ref);
1871
-        $status = $this->_req_data['status'];
1872
-        if ($status !== 'off' && $status !=='on') {
1873
-            EE_Error::add_error(
1874
-                sprintf(
1875
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1876
-                    $this->_req_data['status']
1877
-                ),
1878
-                __FILE__,
1879
-                __FUNCTION__,
1880
-                __LINE__
1881
-            );
1882
-            $success = false;
1883
-        }
1884
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1885
-            $this->_req_data['message_template_group_id']
1886
-        );
1887
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1888
-            EE_Error::add_error(
1889
-                sprintf(
1890
-                    esc_html__(
1891
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1892
-                        'event_espresso'
1893
-                    ),
1894
-                    $this->_req_data['message_template_group_id'],
1895
-                    'EE_Message_Template_Group'
1896
-                ),
1897
-                __FILE__,
1898
-                __FUNCTION__,
1899
-                __LINE__
1900
-            );
1901
-            $success = false;
1902
-        }
1903
-        if ($success) {
1904
-            $success = $status === 'off'
1905
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1906
-                : $message_template_group->activate_context($this->_req_data['context']);
1907
-        }
1908
-        $this->_template_args['success'] = $success;
1909
-        $this->_return_json();
1910
-    }
1866
+		$nonce = isset($this->_req_data['toggle_context_nonce'])
1867
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1868
+			: '';
1869
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1870
+		$this->_verify_nonce($nonce, $nonce_ref);
1871
+		$status = $this->_req_data['status'];
1872
+		if ($status !== 'off' && $status !=='on') {
1873
+			EE_Error::add_error(
1874
+				sprintf(
1875
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1876
+					$this->_req_data['status']
1877
+				),
1878
+				__FILE__,
1879
+				__FUNCTION__,
1880
+				__LINE__
1881
+			);
1882
+			$success = false;
1883
+		}
1884
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1885
+			$this->_req_data['message_template_group_id']
1886
+		);
1887
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1888
+			EE_Error::add_error(
1889
+				sprintf(
1890
+					esc_html__(
1891
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1892
+						'event_espresso'
1893
+					),
1894
+					$this->_req_data['message_template_group_id'],
1895
+					'EE_Message_Template_Group'
1896
+				),
1897
+				__FILE__,
1898
+				__FUNCTION__,
1899
+				__LINE__
1900
+			);
1901
+			$success = false;
1902
+		}
1903
+		if ($success) {
1904
+			$success = $status === 'off'
1905
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1906
+				: $message_template_group->activate_context($this->_req_data['context']);
1907
+		}
1908
+		$this->_template_args['success'] = $success;
1909
+		$this->_return_json();
1910
+	}
1911 1911
 
1912 1912
 
1913 1913
     
1914
-    public function _add_form_element_before()
1915
-    {
1916
-        return '<form method="post" action="'
1917
-               . $this->_template_args["edit_message_template_form_url"]
1918
-               . '" id="ee-msg-edit-frm">';
1919
-    }
1914
+	public function _add_form_element_before()
1915
+	{
1916
+		return '<form method="post" action="'
1917
+			   . $this->_template_args["edit_message_template_form_url"]
1918
+			   . '" id="ee-msg-edit-frm">';
1919
+	}
1920 1920
     
1921
-    public function _add_form_element_after()
1922
-    {
1923
-        return '</form>';
1924
-    }
1921
+	public function _add_form_element_after()
1922
+	{
1923
+		return '</form>';
1924
+	}
1925 1925
 
1926 1926
 
1927
-    /**
1928
-     * This executes switching the template pack for a message template.
1929
-     *
1930
-     * @since 4.5.0
1931
-     * @throws EE_Error
1932
-     * @throws InvalidDataTypeException
1933
-     * @throws InvalidInterfaceException
1934
-     * @throws InvalidArgumentException
1935
-     * @throws ReflectionException
1936
-     */
1937
-    public function switch_template_pack()
1938
-    {
1939
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1940
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1941
-        
1942
-        //verify we have needed values.
1943
-        if (empty($GRP_ID) || empty($template_pack)) {
1944
-            $this->_template_args['error'] = true;
1945
-            EE_Error::add_error(
1946
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1947
-                __FILE__,
1948
-                __FUNCTION__,
1949
-                __LINE__
1950
-            );
1951
-        } else {
1952
-            //get template, set the new template_pack and then reset to default
1953
-            /** @type EE_Message_Template_Group $message_template_group */
1954
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1927
+	/**
1928
+	 * This executes switching the template pack for a message template.
1929
+	 *
1930
+	 * @since 4.5.0
1931
+	 * @throws EE_Error
1932
+	 * @throws InvalidDataTypeException
1933
+	 * @throws InvalidInterfaceException
1934
+	 * @throws InvalidArgumentException
1935
+	 * @throws ReflectionException
1936
+	 */
1937
+	public function switch_template_pack()
1938
+	{
1939
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1940
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1941
+        
1942
+		//verify we have needed values.
1943
+		if (empty($GRP_ID) || empty($template_pack)) {
1944
+			$this->_template_args['error'] = true;
1945
+			EE_Error::add_error(
1946
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1947
+				__FILE__,
1948
+				__FUNCTION__,
1949
+				__LINE__
1950
+			);
1951
+		} else {
1952
+			//get template, set the new template_pack and then reset to default
1953
+			/** @type EE_Message_Template_Group $message_template_group */
1954
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1955 1955
             
1956
-            $message_template_group->set_template_pack_name($template_pack);
1957
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1958
-            $this->_req_data['mt']   = $message_template_group->message_type();
1956
+			$message_template_group->set_template_pack_name($template_pack);
1957
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1958
+			$this->_req_data['mt']   = $message_template_group->message_type();
1959 1959
             
1960
-            $query_args = $this->_reset_to_default_template();
1960
+			$query_args = $this->_reset_to_default_template();
1961 1961
             
1962
-            if (empty($query_args['id'])) {
1963
-                EE_Error::add_error(
1964
-                    esc_html__(
1965
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1966
-                        'event_espresso'
1967
-                    ),
1968
-                    __FILE__,
1969
-                    __FUNCTION__,
1970
-                    __LINE__
1971
-                );
1972
-                $this->_template_args['error'] = true;
1973
-            } else {
1974
-                $template_label       = $message_template_group->get_template_pack()->label;
1975
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1976
-                EE_Error::add_success(
1977
-                    sprintf(
1978
-                        esc_html__(
1979
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1980
-                            'event_espresso'
1981
-                        ),
1982
-                        $template_label,
1983
-                        $template_pack_labels->template_pack
1984
-                    )
1985
-                );
1986
-                //generate the redirect url for js.
1987
-                $url                                          = self::add_query_args_and_nonce($query_args,
1988
-                    $this->_admin_base_url);
1989
-                $this->_template_args['data']['redirect_url'] = $url;
1990
-                $this->_template_args['success']              = true;
1991
-            }
1962
+			if (empty($query_args['id'])) {
1963
+				EE_Error::add_error(
1964
+					esc_html__(
1965
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1966
+						'event_espresso'
1967
+					),
1968
+					__FILE__,
1969
+					__FUNCTION__,
1970
+					__LINE__
1971
+				);
1972
+				$this->_template_args['error'] = true;
1973
+			} else {
1974
+				$template_label       = $message_template_group->get_template_pack()->label;
1975
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1976
+				EE_Error::add_success(
1977
+					sprintf(
1978
+						esc_html__(
1979
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1980
+							'event_espresso'
1981
+						),
1982
+						$template_label,
1983
+						$template_pack_labels->template_pack
1984
+					)
1985
+				);
1986
+				//generate the redirect url for js.
1987
+				$url                                          = self::add_query_args_and_nonce($query_args,
1988
+					$this->_admin_base_url);
1989
+				$this->_template_args['data']['redirect_url'] = $url;
1990
+				$this->_template_args['success']              = true;
1991
+			}
1992 1992
             
1993
-            $this->_return_json();
1993
+			$this->_return_json();
1994 1994
             
1995
-        }
1996
-    }
1995
+		}
1996
+	}
1997 1997
 
1998 1998
 
1999
-    /**
2000
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2001
-     * they want.
2002
-     *
2003
-     * @access protected
2004
-     * @return array|null
2005
-     * @throws EE_Error
2006
-     * @throws InvalidArgumentException
2007
-     * @throws InvalidDataTypeException
2008
-     * @throws InvalidInterfaceException
2009
-     */
2010
-    protected function _reset_to_default_template()
2011
-    {
2012
-        
2013
-        $templates = array();
2014
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2015
-        //we need to make sure we've got the info we need.
2016
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2017
-            EE_Error::add_error(
2018
-                esc_html__(
2019
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2020
-                    'event_espresso'
2021
-                ),
2022
-                __FILE__, __FUNCTION__, __LINE__
2023
-            );
2024
-        }
2025
-        
2026
-        // all templates will be reset to whatever the defaults are
2027
-        // for the global template matching the messenger and message type.
2028
-        $success = ! empty($GRP_ID) ? true : false;
2029
-        
2030
-        if ($success) {
1999
+	/**
2000
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2001
+	 * they want.
2002
+	 *
2003
+	 * @access protected
2004
+	 * @return array|null
2005
+	 * @throws EE_Error
2006
+	 * @throws InvalidArgumentException
2007
+	 * @throws InvalidDataTypeException
2008
+	 * @throws InvalidInterfaceException
2009
+	 */
2010
+	protected function _reset_to_default_template()
2011
+	{
2012
+        
2013
+		$templates = array();
2014
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2015
+		//we need to make sure we've got the info we need.
2016
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2017
+			EE_Error::add_error(
2018
+				esc_html__(
2019
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2020
+					'event_espresso'
2021
+				),
2022
+				__FILE__, __FUNCTION__, __LINE__
2023
+			);
2024
+		}
2025
+        
2026
+		// all templates will be reset to whatever the defaults are
2027
+		// for the global template matching the messenger and message type.
2028
+		$success = ! empty($GRP_ID) ? true : false;
2029
+        
2030
+		if ($success) {
2031 2031
             
2032
-            //let's first determine if the incoming template is a global template,
2033
-            // if it isn't then we need to get the global template matching messenger and message type.
2034
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2032
+			//let's first determine if the incoming template is a global template,
2033
+			// if it isn't then we need to get the global template matching messenger and message type.
2034
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2035 2035
             
2036 2036
             
2037
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2038
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2037
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2038
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2039 2039
             
2040
-            if ($success) {
2041
-                // if successfully deleted, lets generate the new ones.
2042
-                // Note. We set GLOBAL to true, because resets on ANY template
2043
-                // will use the related global template defaults for regeneration.
2044
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2045
-                // HOWEVER, we DO keep the template pack and template variation set
2046
-                // for the current custom template when resetting.
2047
-                $templates = $this->_generate_new_templates(
2048
-                    $this->_req_data['msgr'],
2049
-                    $this->_req_data['mt'],
2050
-                    $GRP_ID,
2051
-                    true
2052
-                );
2053
-            }
2040
+			if ($success) {
2041
+				// if successfully deleted, lets generate the new ones.
2042
+				// Note. We set GLOBAL to true, because resets on ANY template
2043
+				// will use the related global template defaults for regeneration.
2044
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2045
+				// HOWEVER, we DO keep the template pack and template variation set
2046
+				// for the current custom template when resetting.
2047
+				$templates = $this->_generate_new_templates(
2048
+					$this->_req_data['msgr'],
2049
+					$this->_req_data['mt'],
2050
+					$GRP_ID,
2051
+					true
2052
+				);
2053
+			}
2054 2054
             
2055
-        }
2056
-        
2057
-        //any error messages?
2058
-        if ( ! $success) {
2059
-            EE_Error::add_error(
2060
-                esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2061
-                    'event_espresso'),
2062
-                __FILE__, __FUNCTION__, __LINE__
2063
-            );
2064
-        }
2065
-        
2066
-        //all good, let's add a success message!
2067
-        if ($success && ! empty($templates)) {
2068
-            //the info for the template we generated is the first element in the returned array
2069
-            // $templates = $templates[0];
2070
-            EE_Error::overwrite_success();
2071
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2072
-        }
2073
-        
2074
-        
2075
-        $query_args = array(
2076
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2077
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2078
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2079
-        );
2080
-        
2081
-        //if called via ajax then we return query args otherwise redirect
2082
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2083
-            return $query_args;
2084
-        } else {
2085
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2055
+		}
2056
+        
2057
+		//any error messages?
2058
+		if ( ! $success) {
2059
+			EE_Error::add_error(
2060
+				esc_html__('Something went wrong with deleting existing templates. Unable to reset to default',
2061
+					'event_espresso'),
2062
+				__FILE__, __FUNCTION__, __LINE__
2063
+			);
2064
+		}
2065
+        
2066
+		//all good, let's add a success message!
2067
+		if ($success && ! empty($templates)) {
2068
+			//the info for the template we generated is the first element in the returned array
2069
+			// $templates = $templates[0];
2070
+			EE_Error::overwrite_success();
2071
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2072
+		}
2073
+        
2074
+        
2075
+		$query_args = array(
2076
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2077
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2078
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
2079
+		);
2080
+        
2081
+		//if called via ajax then we return query args otherwise redirect
2082
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2083
+			return $query_args;
2084
+		} else {
2085
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2086 2086
 
2087
-            return null;
2088
-        }
2089
-    }
2087
+			return null;
2088
+		}
2089
+	}
2090 2090
 
2091 2091
 
2092
-    /**
2093
-     * Retrieve and set the message preview for display.
2094
-     *
2095
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2096
-     * @return string
2097
-     * @throws EE_Error
2098
-     * @throws InvalidArgumentException
2099
-     * @throws InvalidDataTypeException
2100
-     * @throws InvalidInterfaceException
2101
-     */
2102
-    public function _preview_message($send = false)
2103
-    {
2104
-        //first make sure we've got the necessary parameters
2105
-        if (
2106
-        ! isset(
2107
-            $this->_req_data['message_type'],
2108
-            $this->_req_data['messenger'],
2109
-            $this->_req_data['messenger'],
2110
-            $this->_req_data['GRP_ID']
2111
-        )
2112
-        ) {
2113
-            EE_Error::add_error(
2114
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2115
-                __FILE__, __FUNCTION__, __LINE__
2116
-            );
2117
-        }
2118
-        
2119
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2120
-        
2121
-        
2122
-        //get the preview!
2123
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2124
-            $this->_req_data['messenger'], $send);
2125
-        
2126
-        if ($send) {
2127
-            return $preview;
2128
-        }
2129
-        
2130
-        //let's add a button to go back to the edit view
2131
-        $query_args             = array(
2132
-            'id'      => $this->_req_data['GRP_ID'],
2133
-            'context' => $this->_req_data['context'],
2134
-            'action'  => 'edit_message_template'
2135
-        );
2136
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2137
-        $preview_button         = '<a href="'
2138
-                                  . $go_back_url
2139
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2140
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2141
-                                  . '</a>';
2142
-        $message_types          = $this->get_installed_message_types();
2143
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger(
2144
-                $this->_req_data['messenger']
2145
-        );
2146
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2147
-            ? ucwords($active_messenger->label['singular'])
2148
-            : esc_html__('Unknown Messenger', 'event_espresso');
2149
-        //let's provide a helpful title for context
2150
-        $preview_title = sprintf(
2151
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2152
-            $active_messenger_label,
2153
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2154
-        );
2155
-        //setup display of preview.
2156
-        $this->_admin_page_title                    = $preview_title;
2157
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2158
-        $this->_template_args['data']['force_json'] = true;
2159
-        
2160
-        return '';
2161
-    }
2092
+	/**
2093
+	 * Retrieve and set the message preview for display.
2094
+	 *
2095
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2096
+	 * @return string
2097
+	 * @throws EE_Error
2098
+	 * @throws InvalidArgumentException
2099
+	 * @throws InvalidDataTypeException
2100
+	 * @throws InvalidInterfaceException
2101
+	 */
2102
+	public function _preview_message($send = false)
2103
+	{
2104
+		//first make sure we've got the necessary parameters
2105
+		if (
2106
+		! isset(
2107
+			$this->_req_data['message_type'],
2108
+			$this->_req_data['messenger'],
2109
+			$this->_req_data['messenger'],
2110
+			$this->_req_data['GRP_ID']
2111
+		)
2112
+		) {
2113
+			EE_Error::add_error(
2114
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2115
+				__FILE__, __FUNCTION__, __LINE__
2116
+			);
2117
+		}
2118
+        
2119
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2120
+        
2121
+        
2122
+		//get the preview!
2123
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
2124
+			$this->_req_data['messenger'], $send);
2125
+        
2126
+		if ($send) {
2127
+			return $preview;
2128
+		}
2129
+        
2130
+		//let's add a button to go back to the edit view
2131
+		$query_args             = array(
2132
+			'id'      => $this->_req_data['GRP_ID'],
2133
+			'context' => $this->_req_data['context'],
2134
+			'action'  => 'edit_message_template'
2135
+		);
2136
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2137
+		$preview_button         = '<a href="'
2138
+								  . $go_back_url
2139
+								  . '" class="button-secondary messages-preview-go-back-button">'
2140
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2141
+								  . '</a>';
2142
+		$message_types          = $this->get_installed_message_types();
2143
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger(
2144
+				$this->_req_data['messenger']
2145
+		);
2146
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2147
+			? ucwords($active_messenger->label['singular'])
2148
+			: esc_html__('Unknown Messenger', 'event_espresso');
2149
+		//let's provide a helpful title for context
2150
+		$preview_title = sprintf(
2151
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2152
+			$active_messenger_label,
2153
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2154
+		);
2155
+		//setup display of preview.
2156
+		$this->_admin_page_title                    = $preview_title;
2157
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
2158
+		$this->_template_args['data']['force_json'] = true;
2159
+        
2160
+		return '';
2161
+	}
2162 2162
     
2163 2163
     
2164
-    /**
2165
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2166
-     * gets called automatically.
2167
-     *
2168
-     * @since 4.5.0
2169
-     *
2170
-     * @return string
2171
-     */
2172
-    protected function _display_preview_message()
2173
-    {
2174
-        $this->display_admin_page_with_no_sidebar();
2175
-    }
2164
+	/**
2165
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2166
+	 * gets called automatically.
2167
+	 *
2168
+	 * @since 4.5.0
2169
+	 *
2170
+	 * @return string
2171
+	 */
2172
+	protected function _display_preview_message()
2173
+	{
2174
+		$this->display_admin_page_with_no_sidebar();
2175
+	}
2176 2176
     
2177 2177
     
2178
-    /**
2179
-     * registers metaboxes that should show up on the "edit_message_template" page
2180
-     *
2181
-     * @access protected
2182
-     * @return void
2183
-     */
2184
-    protected function _register_edit_meta_boxes()
2185
-    {
2186
-        add_meta_box(
2187
-            'mtp_valid_shortcodes',
2188
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2189
-            array($this, 'shortcode_meta_box'),
2190
-            $this->_current_screen->id,
2191
-            'side',
2192
-            'default');
2193
-        add_meta_box(
2194
-            'mtp_extra_actions',
2195
-            esc_html__('Extra Actions', 'event_espresso'),
2196
-            array($this, 'extra_actions_meta_box'),
2197
-            $this->_current_screen->id,
2198
-            'side',
2199
-            'high'
2200
-        );
2201
-        add_meta_box(
2202
-            'mtp_templates',
2203
-            esc_html__('Template Styles', 'event_espresso'),
2204
-            array($this, 'template_pack_meta_box'),
2205
-            $this->_current_screen->id,
2206
-            'side',
2207
-            'high'
2208
-        );
2209
-    }
2178
+	/**
2179
+	 * registers metaboxes that should show up on the "edit_message_template" page
2180
+	 *
2181
+	 * @access protected
2182
+	 * @return void
2183
+	 */
2184
+	protected function _register_edit_meta_boxes()
2185
+	{
2186
+		add_meta_box(
2187
+			'mtp_valid_shortcodes',
2188
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2189
+			array($this, 'shortcode_meta_box'),
2190
+			$this->_current_screen->id,
2191
+			'side',
2192
+			'default');
2193
+		add_meta_box(
2194
+			'mtp_extra_actions',
2195
+			esc_html__('Extra Actions', 'event_espresso'),
2196
+			array($this, 'extra_actions_meta_box'),
2197
+			$this->_current_screen->id,
2198
+			'side',
2199
+			'high'
2200
+		);
2201
+		add_meta_box(
2202
+			'mtp_templates',
2203
+			esc_html__('Template Styles', 'event_espresso'),
2204
+			array($this, 'template_pack_meta_box'),
2205
+			$this->_current_screen->id,
2206
+			'side',
2207
+			'high'
2208
+		);
2209
+	}
2210 2210
 
2211 2211
 
2212
-    /**
2213
-     * metabox content for all template pack and variation selection.
2214
-     *
2215
-     * @since 4.5.0
2216
-     * @return string
2217
-     * @throws DomainException
2218
-     * @throws EE_Error
2219
-     * @throws InvalidArgumentException
2220
-     * @throws ReflectionException
2221
-     * @throws InvalidDataTypeException
2222
-     * @throws InvalidInterfaceException
2223
-     */
2224
-    public function template_pack_meta_box()
2225
-    {
2226
-        $this->_set_message_template_group();
2227
-        
2228
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2229
-        
2230
-        $tp_select_values = array();
2231
-        
2232
-        foreach ($tp_collection as $tp) {
2233
-            //only include template packs that support this messenger and message type!
2234
-            $supports = $tp->get_supports();
2235
-            if (
2236
-                ! isset($supports[$this->_message_template_group->messenger()])
2237
-                || ! in_array(
2238
-                    $this->_message_template_group->message_type(),
2239
-                    $supports[$this->_message_template_group->messenger()],
2240
-                    true
2241
-                )
2242
-            ) {
2243
-                //not supported
2244
-                continue;
2245
-            }
2212
+	/**
2213
+	 * metabox content for all template pack and variation selection.
2214
+	 *
2215
+	 * @since 4.5.0
2216
+	 * @return string
2217
+	 * @throws DomainException
2218
+	 * @throws EE_Error
2219
+	 * @throws InvalidArgumentException
2220
+	 * @throws ReflectionException
2221
+	 * @throws InvalidDataTypeException
2222
+	 * @throws InvalidInterfaceException
2223
+	 */
2224
+	public function template_pack_meta_box()
2225
+	{
2226
+		$this->_set_message_template_group();
2227
+        
2228
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2229
+        
2230
+		$tp_select_values = array();
2231
+        
2232
+		foreach ($tp_collection as $tp) {
2233
+			//only include template packs that support this messenger and message type!
2234
+			$supports = $tp->get_supports();
2235
+			if (
2236
+				! isset($supports[$this->_message_template_group->messenger()])
2237
+				|| ! in_array(
2238
+					$this->_message_template_group->message_type(),
2239
+					$supports[$this->_message_template_group->messenger()],
2240
+					true
2241
+				)
2242
+			) {
2243
+				//not supported
2244
+				continue;
2245
+			}
2246 2246
             
2247
-            $tp_select_values[] = array(
2248
-                'text' => $tp->label,
2249
-                'id'   => $tp->dbref
2250
-            );
2251
-        }
2252
-        
2253
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2254
-        // the default template pack.  This still allows for the odd template pack to override.
2255
-        if (empty($tp_select_values)) {
2256
-            $tp_select_values[] = array(
2257
-                'text' => esc_html__('Default', 'event_espresso'),
2258
-                'id'   => 'default'
2259
-            );
2260
-        }
2261
-        
2262
-        //setup variation select values for the currently selected template.
2263
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2264
-            $this->_message_template_group->messenger(),
2265
-            $this->_message_template_group->message_type()
2266
-        );
2267
-        $variations_select_values = array();
2268
-        foreach ($variations as $variation => $label) {
2269
-            $variations_select_values[] = array(
2270
-                'text' => $label,
2271
-                'id'   => $variation
2272
-            );
2273
-        }
2274
-        
2275
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2276
-        
2277
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2278
-            'MTP_template_pack',
2279
-            $tp_select_values,
2280
-            $this->_message_template_group->get_template_pack_name()
2281
-        );
2282
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2283
-            'MTP_template_variation',
2284
-            $variations_select_values,
2285
-            $this->_message_template_group->get_template_pack_variation()
2286
-        );
2287
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2288
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2289
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2290
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2291
-        
2292
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2293
-        
2294
-        EEH_Template::display_template($template, $template_args);
2295
-    }
2247
+			$tp_select_values[] = array(
2248
+				'text' => $tp->label,
2249
+				'id'   => $tp->dbref
2250
+			);
2251
+		}
2252
+        
2253
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2254
+		// the default template pack.  This still allows for the odd template pack to override.
2255
+		if (empty($tp_select_values)) {
2256
+			$tp_select_values[] = array(
2257
+				'text' => esc_html__('Default', 'event_espresso'),
2258
+				'id'   => 'default'
2259
+			);
2260
+		}
2261
+        
2262
+		//setup variation select values for the currently selected template.
2263
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2264
+			$this->_message_template_group->messenger(),
2265
+			$this->_message_template_group->message_type()
2266
+		);
2267
+		$variations_select_values = array();
2268
+		foreach ($variations as $variation => $label) {
2269
+			$variations_select_values[] = array(
2270
+				'text' => $label,
2271
+				'id'   => $variation
2272
+			);
2273
+		}
2274
+        
2275
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2276
+        
2277
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2278
+			'MTP_template_pack',
2279
+			$tp_select_values,
2280
+			$this->_message_template_group->get_template_pack_name()
2281
+		);
2282
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2283
+			'MTP_template_variation',
2284
+			$variations_select_values,
2285
+			$this->_message_template_group->get_template_pack_variation()
2286
+		);
2287
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2288
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2289
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2290
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2291
+        
2292
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2293
+        
2294
+		EEH_Template::display_template($template, $template_args);
2295
+	}
2296 2296
     
2297 2297
     
2298
-    /**
2299
-     * This meta box holds any extra actions related to Message Templates
2300
-     * For now, this includes Resetting templates to defaults and sending a test email.
2301
-     *
2302
-     * @access  public
2303
-     * @return void
2304
-     * @throws EE_Error
2305
-     */
2306
-    public function extra_actions_meta_box()
2307
-    {
2308
-        $template_form_fields = array();
2309
-        
2310
-        $extra_args = array(
2311
-            'msgr'   => $this->_message_template_group->messenger(),
2312
-            'mt'     => $this->_message_template_group->message_type(),
2313
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2314
-        );
2315
-        //first we need to see if there are any fields
2316
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2317
-        
2318
-        if ( ! empty($fields)) {
2319
-            //yup there be fields
2320
-            foreach ($fields as $field => $config) {
2321
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2322
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2323
-                $default  = isset($config['default']) ? $config['default'] : '';
2324
-                $default  = isset($config['value']) ? $config['value'] : $default;
2298
+	/**
2299
+	 * This meta box holds any extra actions related to Message Templates
2300
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2301
+	 *
2302
+	 * @access  public
2303
+	 * @return void
2304
+	 * @throws EE_Error
2305
+	 */
2306
+	public function extra_actions_meta_box()
2307
+	{
2308
+		$template_form_fields = array();
2309
+        
2310
+		$extra_args = array(
2311
+			'msgr'   => $this->_message_template_group->messenger(),
2312
+			'mt'     => $this->_message_template_group->message_type(),
2313
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2314
+		);
2315
+		//first we need to see if there are any fields
2316
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2317
+        
2318
+		if ( ! empty($fields)) {
2319
+			//yup there be fields
2320
+			foreach ($fields as $field => $config) {
2321
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2322
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2323
+				$default  = isset($config['default']) ? $config['default'] : '';
2324
+				$default  = isset($config['value']) ? $config['value'] : $default;
2325 2325
                 
2326
-                // if type is hidden and the value is empty
2327
-                // something may have gone wrong so let's correct with the defaults
2328
-                $fix              = $config['input'] === 'hidden'
2329
-                                    && isset($existing[$field])
2330
-                                    && empty($existing[$field])
2331
-                    ? $default
2332
-                    : '';
2333
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2334
-                    ? $existing[$field]
2335
-                    : $fix;
2326
+				// if type is hidden and the value is empty
2327
+				// something may have gone wrong so let's correct with the defaults
2328
+				$fix              = $config['input'] === 'hidden'
2329
+									&& isset($existing[$field])
2330
+									&& empty($existing[$field])
2331
+					? $default
2332
+					: '';
2333
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2334
+					? $existing[$field]
2335
+					: $fix;
2336 2336
                 
2337
-                $template_form_fields[$field_id] = array(
2338
-                    'name'       => 'test_settings_fld[' . $field . ']',
2339
-                    'label'      => $config['label'],
2340
-                    'input'      => $config['input'],
2341
-                    'type'       => $config['type'],
2342
-                    'required'   => $config['required'],
2343
-                    'validation' => $config['validation'],
2344
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2345
-                    'css_class'  => $config['css_class'],
2346
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2347
-                    'default'    => $default,
2348
-                    'format'     => $config['format']
2349
-                );
2350
-            }
2351
-        }
2352
-        
2353
-        $test_settings_fields = ! empty($template_form_fields)
2354
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2355
-            : '';
2356
-        
2357
-        $test_settings_html = '';
2358
-        //print out $test_settings_fields
2359
-        if ( ! empty($test_settings_fields)) {
2360
-            echo $test_settings_fields;
2361
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2362
-            $test_settings_html .= 'name="test_button" value="';
2363
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2364
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2365
-        }
2366
-        
2367
-        //and button
2368
-        $test_settings_html .= '<p>'
2369
-                               . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2370
-                               . '</p>';
2371
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2372
-        $test_settings_html .= $this->get_action_link_or_button(
2373
-            'reset_to_default',
2374
-            'reset',
2375
-            $extra_args,
2376
-            'button-primary reset-default-button'
2377
-        );
2378
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2379
-        echo $test_settings_html;
2380
-    }
2337
+				$template_form_fields[$field_id] = array(
2338
+					'name'       => 'test_settings_fld[' . $field . ']',
2339
+					'label'      => $config['label'],
2340
+					'input'      => $config['input'],
2341
+					'type'       => $config['type'],
2342
+					'required'   => $config['required'],
2343
+					'validation' => $config['validation'],
2344
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2345
+					'css_class'  => $config['css_class'],
2346
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2347
+					'default'    => $default,
2348
+					'format'     => $config['format']
2349
+				);
2350
+			}
2351
+		}
2352
+        
2353
+		$test_settings_fields = ! empty($template_form_fields)
2354
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2355
+			: '';
2356
+        
2357
+		$test_settings_html = '';
2358
+		//print out $test_settings_fields
2359
+		if ( ! empty($test_settings_fields)) {
2360
+			echo $test_settings_fields;
2361
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2362
+			$test_settings_html .= 'name="test_button" value="';
2363
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2364
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2365
+		}
2366
+        
2367
+		//and button
2368
+		$test_settings_html .= '<p>'
2369
+							   . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2370
+							   . '</p>';
2371
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2372
+		$test_settings_html .= $this->get_action_link_or_button(
2373
+			'reset_to_default',
2374
+			'reset',
2375
+			$extra_args,
2376
+			'button-primary reset-default-button'
2377
+		);
2378
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2379
+		echo $test_settings_html;
2380
+	}
2381 2381
 
2382 2382
 
2383
-    /**
2384
-     * This returns the shortcode selector skeleton for a given context and field.
2385
-     *
2386
-     * @since 4.9.rc.000
2387
-     * @param string $field           The name of the field retrieving shortcodes for.
2388
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2389
-     * @return string
2390
-     * @throws DomainException
2391
-     * @throws EE_Error
2392
-     * @throws InvalidArgumentException
2393
-     * @throws ReflectionException
2394
-     * @throws InvalidDataTypeException
2395
-     * @throws InvalidInterfaceException
2396
-     */
2397
-    protected function _get_shortcode_selector($field, $linked_input_id)
2398
-    {
2399
-        $template_args = array(
2400
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2401
-            'fieldname'       => $field,
2402
-            'linked_input_id' => $linked_input_id
2403
-        );
2404
-        
2405
-        return EEH_Template::display_template(
2406
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2407
-            $template_args,
2408
-            true
2409
-        );
2410
-    }
2383
+	/**
2384
+	 * This returns the shortcode selector skeleton for a given context and field.
2385
+	 *
2386
+	 * @since 4.9.rc.000
2387
+	 * @param string $field           The name of the field retrieving shortcodes for.
2388
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2389
+	 * @return string
2390
+	 * @throws DomainException
2391
+	 * @throws EE_Error
2392
+	 * @throws InvalidArgumentException
2393
+	 * @throws ReflectionException
2394
+	 * @throws InvalidDataTypeException
2395
+	 * @throws InvalidInterfaceException
2396
+	 */
2397
+	protected function _get_shortcode_selector($field, $linked_input_id)
2398
+	{
2399
+		$template_args = array(
2400
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2401
+			'fieldname'       => $field,
2402
+			'linked_input_id' => $linked_input_id
2403
+		);
2404
+        
2405
+		return EEH_Template::display_template(
2406
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2407
+			$template_args,
2408
+			true
2409
+		);
2410
+	}
2411 2411
 
2412 2412
 
2413
-    /**
2414
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2415
-     * page)
2416
-     *
2417
-     * @access public
2418
-     * @return void
2419
-     * @throws EE_Error
2420
-     * @throws InvalidArgumentException
2421
-     * @throws ReflectionException
2422
-     * @throws InvalidDataTypeException
2423
-     * @throws InvalidInterfaceException
2424
-     */
2425
-    public function shortcode_meta_box()
2426
-    {
2427
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2428
-        //$messenger = $this->_message_template_group->messenger_obj();
2429
-        //now let's set the content depending on the status of the shortcodes array
2430
-        if (empty($shortcodes)) {
2431
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2432
-            echo $content;
2433
-        } else {
2434
-            //$alt = 0;
2435
-            ?>
2413
+	/**
2414
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2415
+	 * page)
2416
+	 *
2417
+	 * @access public
2418
+	 * @return void
2419
+	 * @throws EE_Error
2420
+	 * @throws InvalidArgumentException
2421
+	 * @throws ReflectionException
2422
+	 * @throws InvalidDataTypeException
2423
+	 * @throws InvalidInterfaceException
2424
+	 */
2425
+	public function shortcode_meta_box()
2426
+	{
2427
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2428
+		//$messenger = $this->_message_template_group->messenger_obj();
2429
+		//now let's set the content depending on the status of the shortcodes array
2430
+		if (empty($shortcodes)) {
2431
+			$content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2432
+			echo $content;
2433
+		} else {
2434
+			//$alt = 0;
2435
+			?>
2436 2436
             <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2437 2437
             <p class="small-text"><?php printf(
2438
-                    esc_html__(
2439
-                        'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2440
-                        'event_espresso'
2441
-                    ),
2442
-                    '<span class="dashicons dashicons-menu"></span>'
2443
-                ); ?></p>
2438
+					esc_html__(
2439
+						'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2440
+						'event_espresso'
2441
+					),
2442
+					'<span class="dashicons dashicons-menu"></span>'
2443
+				); ?></p>
2444 2444
             <?php
2445
-        }
2445
+		}
2446 2446
         
2447 2447
         
2448
-    }
2448
+	}
2449 2449
 
2450 2450
 
2451
-    /**
2452
-     * used to set the $_shortcodes property for when its needed elsewhere.
2453
-     *
2454
-     * @access protected
2455
-     * @return void
2456
-     * @throws EE_Error
2457
-     * @throws InvalidArgumentException
2458
-     * @throws ReflectionException
2459
-     * @throws InvalidDataTypeException
2460
-     * @throws InvalidInterfaceException
2461
-     */
2462
-    protected function _set_shortcodes()
2463
-    {
2464
-        
2465
-        //no need to run this if the property is already set
2466
-        if ( ! empty($this->_shortcodes)) {
2467
-            return;
2468
-        }
2469
-        
2470
-        $this->_shortcodes = $this->_get_shortcodes();
2471
-    }
2451
+	/**
2452
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2453
+	 *
2454
+	 * @access protected
2455
+	 * @return void
2456
+	 * @throws EE_Error
2457
+	 * @throws InvalidArgumentException
2458
+	 * @throws ReflectionException
2459
+	 * @throws InvalidDataTypeException
2460
+	 * @throws InvalidInterfaceException
2461
+	 */
2462
+	protected function _set_shortcodes()
2463
+	{
2464
+        
2465
+		//no need to run this if the property is already set
2466
+		if ( ! empty($this->_shortcodes)) {
2467
+			return;
2468
+		}
2469
+        
2470
+		$this->_shortcodes = $this->_get_shortcodes();
2471
+	}
2472 2472
 
2473 2473
 
2474
-    /**
2475
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2476
-     * property)
2477
-     *
2478
-     * @access  protected
2479
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2480
-     *                         for. Defaults to all (for the given context)
2481
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2482
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2483
-     *                         true just an array of shortcode/label pairs.
2484
-     * @throws EE_Error
2485
-     * @throws InvalidArgumentException
2486
-     * @throws ReflectionException
2487
-     * @throws InvalidDataTypeException
2488
-     * @throws InvalidInterfaceException
2489
-     */
2490
-    protected function _get_shortcodes($fields = array(), $merged = true)
2491
-    {
2492
-        $this->_set_message_template_group();
2493
-        
2494
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2495
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2496
-            ? absint($this->_req_data['id'])
2497
-            : false;
2498
-        $context = isset($this->_req_data['context'])
2499
-            ? $this->_req_data['context']
2500
-            : key($this->_message_template_group->contexts_config());
2501
-        
2502
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2503
-    }
2474
+	/**
2475
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2476
+	 * property)
2477
+	 *
2478
+	 * @access  protected
2479
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2480
+	 *                         for. Defaults to all (for the given context)
2481
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2482
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2483
+	 *                         true just an array of shortcode/label pairs.
2484
+	 * @throws EE_Error
2485
+	 * @throws InvalidArgumentException
2486
+	 * @throws ReflectionException
2487
+	 * @throws InvalidDataTypeException
2488
+	 * @throws InvalidInterfaceException
2489
+	 */
2490
+	protected function _get_shortcodes($fields = array(), $merged = true)
2491
+	{
2492
+		$this->_set_message_template_group();
2493
+        
2494
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2495
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2496
+			? absint($this->_req_data['id'])
2497
+			: false;
2498
+		$context = isset($this->_req_data['context'])
2499
+			? $this->_req_data['context']
2500
+			: key($this->_message_template_group->contexts_config());
2501
+        
2502
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2503
+	}
2504 2504
 
2505 2505
 
2506
-    /**
2507
-     * This sets the _message_template property (containing the called message_template object)
2508
-     *
2509
-     * @access protected
2510
-     * @return void
2511
-     * @throws EE_Error
2512
-     * @throws InvalidArgumentException
2513
-     * @throws ReflectionException
2514
-     * @throws InvalidDataTypeException
2515
-     * @throws InvalidInterfaceException
2516
-     */
2517
-    protected function _set_message_template_group()
2518
-    {
2519
-        
2520
-        if ( ! empty($this->_message_template_group)) {
2521
-            return;
2522
-        } //get out if this is already set.
2523
-        
2524
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2525
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2526
-        
2527
-        //let's get the message templates
2528
-        $MTP = EEM_Message_Template_Group::instance();
2529
-        
2530
-        if (empty($GRP_ID)) {
2531
-            $this->_message_template_group = $MTP->create_default_object();
2532
-        } else {
2533
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2534
-        }
2535
-        
2536
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2537
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2538
-        
2539
-    }
2506
+	/**
2507
+	 * This sets the _message_template property (containing the called message_template object)
2508
+	 *
2509
+	 * @access protected
2510
+	 * @return void
2511
+	 * @throws EE_Error
2512
+	 * @throws InvalidArgumentException
2513
+	 * @throws ReflectionException
2514
+	 * @throws InvalidDataTypeException
2515
+	 * @throws InvalidInterfaceException
2516
+	 */
2517
+	protected function _set_message_template_group()
2518
+	{
2519
+        
2520
+		if ( ! empty($this->_message_template_group)) {
2521
+			return;
2522
+		} //get out if this is already set.
2523
+        
2524
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2525
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2526
+        
2527
+		//let's get the message templates
2528
+		$MTP = EEM_Message_Template_Group::instance();
2529
+        
2530
+		if (empty($GRP_ID)) {
2531
+			$this->_message_template_group = $MTP->create_default_object();
2532
+		} else {
2533
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2534
+		}
2535
+        
2536
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2537
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2538
+        
2539
+	}
2540 2540
 
2541 2541
 
2542
-    /**
2543
-     * sets up a context switcher for edit forms
2544
-     *
2545
-     * @access  protected
2546
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2547
-     * @param array                      $args                  various things the context switcher needs.
2548
-     * @throws EE_Error
2549
-     */
2550
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2551
-    {
2552
-        $context_details = $template_group_object->contexts_config();
2553
-        $context_label   = $template_group_object->context_label();
2554
-        ob_start();
2555
-        ?>
2542
+	/**
2543
+	 * sets up a context switcher for edit forms
2544
+	 *
2545
+	 * @access  protected
2546
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2547
+	 * @param array                      $args                  various things the context switcher needs.
2548
+	 * @throws EE_Error
2549
+	 */
2550
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2551
+	{
2552
+		$context_details = $template_group_object->contexts_config();
2553
+		$context_label   = $template_group_object->context_label();
2554
+		ob_start();
2555
+		?>
2556 2556
         <div class="ee-msg-switcher-container">
2557 2557
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2558 2558
                 <?php
2559
-                foreach ($args as $name => $value) {
2560
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2561
-                        continue;
2562
-                    }
2563
-                    ?>
2559
+				foreach ($args as $name => $value) {
2560
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2561
+						continue;
2562
+					}
2563
+					?>
2564 2564
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2565 2565
                     <?php
2566
-                }
2567
-                //setup nonce_url
2568
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2569
-                ?>
2566
+				}
2567
+				//setup nonce_url
2568
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2569
+				?>
2570 2570
                 <select name="context">
2571 2571
                     <?php
2572
-                    $context_templates = $template_group_object->context_templates();
2573
-                    if (is_array($context_templates)) :
2574
-                        foreach ($context_templates as $context => $template_fields) :
2575
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2576
-                            ?>
2572
+					$context_templates = $template_group_object->context_templates();
2573
+					if (is_array($context_templates)) :
2574
+						foreach ($context_templates as $context => $template_fields) :
2575
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2576
+							?>
2577 2577
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2578 2578
                                 <?php echo $context_details[$context]['label']; ?>
2579 2579
                             </option>
@@ -2586,1823 +2586,1823 @@  discard block
 block discarded – undo
2586 2586
             <?php echo $args['extra']; ?>
2587 2587
         </div> <!-- end .ee-msg-switcher-container -->
2588 2588
         <?php
2589
-        $output = ob_get_contents();
2590
-        ob_clean();
2591
-        $this->_context_switcher = $output;
2592
-    }
2589
+		$output = ob_get_contents();
2590
+		ob_clean();
2591
+		$this->_context_switcher = $output;
2592
+	}
2593 2593
     
2594 2594
     
2595
-    /**
2596
-     * utility for sanitizing new values coming in.
2597
-     * Note: this is only used when updating a context.
2598
-     *
2599
-     * @access protected
2600
-     *
2601
-     * @param int $index This helps us know which template field to select from the request array.
2602
-     *
2603
-     * @return array
2604
-     */
2605
-    protected function _set_message_template_column_values($index)
2606
-    {
2607
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2608
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2609
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2610
-            }
2611
-        }
2612
-        
2613
-        
2614
-        $set_column_values = array(
2615
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2616
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2617
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2618
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2619
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2620
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2621
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2622
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2623
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2624
-                ? absint($this->_req_data['MTP_is_global'])
2625
-                : 0,
2626
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2627
-                ? absint($this->_req_data['MTP_is_override'])
2628
-                : 0,
2629
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2630
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2631
-        );
2632
-        
2633
-        
2634
-        return $set_column_values;
2635
-    }
2595
+	/**
2596
+	 * utility for sanitizing new values coming in.
2597
+	 * Note: this is only used when updating a context.
2598
+	 *
2599
+	 * @access protected
2600
+	 *
2601
+	 * @param int $index This helps us know which template field to select from the request array.
2602
+	 *
2603
+	 * @return array
2604
+	 */
2605
+	protected function _set_message_template_column_values($index)
2606
+	{
2607
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2608
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2609
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2610
+			}
2611
+		}
2612
+        
2613
+        
2614
+		$set_column_values = array(
2615
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2616
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2617
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2618
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2619
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2620
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2621
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2622
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2623
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2624
+				? absint($this->_req_data['MTP_is_global'])
2625
+				: 0,
2626
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2627
+				? absint($this->_req_data['MTP_is_override'])
2628
+				: 0,
2629
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2630
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2631
+		);
2632
+        
2633
+        
2634
+		return $set_column_values;
2635
+	}
2636 2636
     
2637 2637
     
2638
-    protected function _insert_or_update_message_template($new = false)
2639
-    {
2640
-        
2641
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2642
-        $success  = 0;
2643
-        $override = false;
2644
-        
2645
-        //setup notices description
2646
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2647
-        
2648
-        //need the message type and messenger objects to be able to use the labels for the notices
2649
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2650
-        $messenger_label  = $messenger_object instanceof EE_messenger
2651
-            ? ucwords($messenger_object->label['singular'])
2652
-            : '';
2653
-        
2654
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2655
-            ? $this->_req_data['MTP_message_type']
2656
-            : '';
2657
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2658
-        
2659
-        $message_type_label = $message_type_object instanceof EE_message_type
2660
-            ? ucwords($message_type_object->label['singular'])
2661
-            : '';
2662
-        
2663
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2664
-            ? $this->_req_data['MTP_context']
2665
-            : '';
2666
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2667
-        
2668
-        $item_desc = $messenger_label && $message_type_label
2669
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2670
-            : '';
2671
-        $item_desc .= 'Message Template';
2672
-        $query_args  = array();
2673
-        $edit_array  = array();
2674
-        $action_desc = '';
2675
-        
2676
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2677
-        // user to edit.
2678
-        if ($new) {
2679
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2680
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2681
-                if (empty($edit_array)) {
2682
-                    $success = 0;
2683
-                } else {
2684
-                    $success    = 1;
2685
-                    $edit_array = $edit_array[0];
2686
-                    $query_args = array(
2687
-                        'id'      => $edit_array['GRP_ID'],
2688
-                        'context' => $edit_array['MTP_context'],
2689
-                        'action'  => 'edit_message_template'
2690
-                    );
2691
-                }
2692
-            }
2693
-            $action_desc = 'created';
2694
-        } else {
2695
-            $MTPG = EEM_Message_Template_Group::instance();
2696
-            $MTP  = EEM_Message_Template::instance();
2638
+	protected function _insert_or_update_message_template($new = false)
2639
+	{
2640
+        
2641
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2642
+		$success  = 0;
2643
+		$override = false;
2644
+        
2645
+		//setup notices description
2646
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2647
+        
2648
+		//need the message type and messenger objects to be able to use the labels for the notices
2649
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2650
+		$messenger_label  = $messenger_object instanceof EE_messenger
2651
+			? ucwords($messenger_object->label['singular'])
2652
+			: '';
2653
+        
2654
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2655
+			? $this->_req_data['MTP_message_type']
2656
+			: '';
2657
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2658
+        
2659
+		$message_type_label = $message_type_object instanceof EE_message_type
2660
+			? ucwords($message_type_object->label['singular'])
2661
+			: '';
2662
+        
2663
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2664
+			? $this->_req_data['MTP_context']
2665
+			: '';
2666
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2667
+        
2668
+		$item_desc = $messenger_label && $message_type_label
2669
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2670
+			: '';
2671
+		$item_desc .= 'Message Template';
2672
+		$query_args  = array();
2673
+		$edit_array  = array();
2674
+		$action_desc = '';
2675
+        
2676
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2677
+		// user to edit.
2678
+		if ($new) {
2679
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2680
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2681
+				if (empty($edit_array)) {
2682
+					$success = 0;
2683
+				} else {
2684
+					$success    = 1;
2685
+					$edit_array = $edit_array[0];
2686
+					$query_args = array(
2687
+						'id'      => $edit_array['GRP_ID'],
2688
+						'context' => $edit_array['MTP_context'],
2689
+						'action'  => 'edit_message_template'
2690
+					);
2691
+				}
2692
+			}
2693
+			$action_desc = 'created';
2694
+		} else {
2695
+			$MTPG = EEM_Message_Template_Group::instance();
2696
+			$MTP  = EEM_Message_Template::instance();
2697 2697
             
2698 2698
             
2699
-            //run update for each template field in displayed context
2700
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2701
-                EE_Error::add_error(
2702
-                    esc_html__(
2703
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2704
-                        'event_espresso'
2705
-                    ),
2706
-                    __FILE__,
2707
-                    __FUNCTION__,
2708
-                    __LINE__
2709
-                );
2710
-                $success = 0;
2699
+			//run update for each template field in displayed context
2700
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2701
+				EE_Error::add_error(
2702
+					esc_html__(
2703
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2704
+						'event_espresso'
2705
+					),
2706
+					__FILE__,
2707
+					__FUNCTION__,
2708
+					__LINE__
2709
+				);
2710
+				$success = 0;
2711 2711
                 
2712
-            } else {
2713
-                //first validate all fields!
2714
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2715
-                    $message_type_slug);
2712
+			} else {
2713
+				//first validate all fields!
2714
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2715
+					$message_type_slug);
2716 2716
                 
2717
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2718
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2719
-                //  WE need to make sure there is no actual error messages in validates.
2720
-                if (is_array($validates) && ! empty($validates)) {
2721
-                    //add the transient so when the form loads we know which fields to highlight
2722
-                    $this->_add_transient('edit_message_template', $validates);
2717
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2718
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2719
+				//  WE need to make sure there is no actual error messages in validates.
2720
+				if (is_array($validates) && ! empty($validates)) {
2721
+					//add the transient so when the form loads we know which fields to highlight
2722
+					$this->_add_transient('edit_message_template', $validates);
2723 2723
                     
2724
-                    $success = 0;
2724
+					$success = 0;
2725 2725
                     
2726
-                    //setup notices
2727
-                    foreach ($validates as $field => $error) {
2728
-                        if (isset($error['msg'])) {
2729
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2730
-                        }
2731
-                    }
2726
+					//setup notices
2727
+					foreach ($validates as $field => $error) {
2728
+						if (isset($error['msg'])) {
2729
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2730
+						}
2731
+					}
2732 2732
                     
2733
-                } else {
2734
-                    $set_column_values = array();
2735
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2736
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2733
+				} else {
2734
+					$set_column_values = array();
2735
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2736
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2737 2737
                         
2738
-                        $where_cols_n_values = array(
2739
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2740
-                        );
2738
+						$where_cols_n_values = array(
2739
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2740
+						);
2741 2741
                         
2742
-                        $message_template_fields = array(
2743
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2744
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2745
-                            'MTP_context'        => $set_column_values['MTP_context'],
2746
-                            'MTP_content'        => $set_column_values['MTP_content']
2747
-                        );
2748
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2749
-                            if ($updated === false) {
2750
-                                EE_Error::add_error(
2751
-                                    sprintf(
2752
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2753
-                                        $template_field
2754
-                                    ),
2755
-                                    __FILE__,
2756
-                                    __FUNCTION__,
2757
-                                    __LINE__
2758
-                                );
2759
-                            } else {
2760
-                                $success = 1;
2761
-                            }
2762
-                        } else {
2763
-                            //only do this logic if we don't have a MTP_ID for this field
2764
-                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2765
-                                //this has already been through the template field validator and sanitized, so it will be
2766
-                                //safe to insert this field.  Why insert?  This typically happens when we introduce a new
2767
-                                //message template field in a messenger/message type and existing users don't have the
2768
-                                //default setup for it.
2769
-                                //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2770
-                                $updated = $MTP->insert($message_template_fields);
2771
-                                if (! $updated || is_wp_error($updated)) {
2772
-                                    EE_Error::add_error(
2773
-                                        sprintf(
2774
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2775
-                                            $template_field
2776
-                                        ),
2777
-                                        __FILE__,
2778
-                                        __FUNCTION__,
2779
-                                        __LINE__
2780
-                                    );
2781
-                                    $success = 0;
2782
-                                } else {
2783
-                                    $success = 1;
2784
-                                }
2785
-                            }
2786
-                        }
2787
-                        $action_desc = 'updated';
2788
-                    }
2742
+						$message_template_fields = array(
2743
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2744
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2745
+							'MTP_context'        => $set_column_values['MTP_context'],
2746
+							'MTP_content'        => $set_column_values['MTP_content']
2747
+						);
2748
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2749
+							if ($updated === false) {
2750
+								EE_Error::add_error(
2751
+									sprintf(
2752
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2753
+										$template_field
2754
+									),
2755
+									__FILE__,
2756
+									__FUNCTION__,
2757
+									__LINE__
2758
+								);
2759
+							} else {
2760
+								$success = 1;
2761
+							}
2762
+						} else {
2763
+							//only do this logic if we don't have a MTP_ID for this field
2764
+							if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2765
+								//this has already been through the template field validator and sanitized, so it will be
2766
+								//safe to insert this field.  Why insert?  This typically happens when we introduce a new
2767
+								//message template field in a messenger/message type and existing users don't have the
2768
+								//default setup for it.
2769
+								//@link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2770
+								$updated = $MTP->insert($message_template_fields);
2771
+								if (! $updated || is_wp_error($updated)) {
2772
+									EE_Error::add_error(
2773
+										sprintf(
2774
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2775
+											$template_field
2776
+										),
2777
+										__FILE__,
2778
+										__FUNCTION__,
2779
+										__LINE__
2780
+									);
2781
+									$success = 0;
2782
+								} else {
2783
+									$success = 1;
2784
+								}
2785
+							}
2786
+						}
2787
+						$action_desc = 'updated';
2788
+					}
2789 2789
                     
2790
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2791
-                    $mtpg_fields = array(
2792
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2793
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2794
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2795
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2796
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2797
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2798
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2799
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2800
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2801
-                            : '',
2802
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2803
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2804
-                            : ''
2805
-                    );
2790
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2791
+					$mtpg_fields = array(
2792
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2793
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2794
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2795
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2796
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2797
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2798
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2799
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2800
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2801
+							: '',
2802
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2803
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2804
+							: ''
2805
+					);
2806 2806
                     
2807
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2808
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2807
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2808
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2809 2809
                     
2810
-                    if ($updated === false) {
2811
-                        EE_Error::add_error(
2812
-                            sprintf(
2813
-                                esc_html__(
2814
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2815
-                                    'event_espresso'
2816
-                                ),
2817
-                                $set_column_values['GRP_ID']
2818
-                            ),
2819
-                            __FILE__,
2820
-                            __FUNCTION__,
2821
-                            __LINE__
2822
-                        );
2823
-                    } else {
2824
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2825
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2826
-                            ? $this->_req_data['MTP_template_pack']
2827
-                            : 'default';
2810
+					if ($updated === false) {
2811
+						EE_Error::add_error(
2812
+							sprintf(
2813
+								esc_html__(
2814
+									'The Message Template Group (%d) was NOT updated for some reason',
2815
+									'event_espresso'
2816
+								),
2817
+								$set_column_values['GRP_ID']
2818
+							),
2819
+							__FILE__,
2820
+							__FUNCTION__,
2821
+							__LINE__
2822
+						);
2823
+					} else {
2824
+						//k now we need to ensure the template_pack and template_variation fields are set.
2825
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2826
+							? $this->_req_data['MTP_template_pack']
2827
+							: 'default';
2828 2828
                         
2829
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2830
-                            ? $this->_req_data['MTP_template_variation']
2831
-                            : 'default';
2829
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2830
+							? $this->_req_data['MTP_template_variation']
2831
+							: 'default';
2832 2832
                         
2833
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2834
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2835
-                            $mtpg_obj->set_template_pack_name($template_pack);
2836
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2837
-                        }
2838
-                        $success = 1;
2839
-                    }
2840
-                }
2841
-            }
2833
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2834
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2835
+							$mtpg_obj->set_template_pack_name($template_pack);
2836
+							$mtpg_obj->set_template_pack_variation($template_variation);
2837
+						}
2838
+						$success = 1;
2839
+					}
2840
+				}
2841
+			}
2842 2842
             
2843
-        }
2844
-        
2845
-        //we return things differently if doing ajax
2846
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2847
-            $this->_template_args['success'] = $success;
2848
-            $this->_template_args['error']   = ! $success ? true : false;
2849
-            $this->_template_args['content'] = '';
2850
-            $this->_template_args['data']    = array(
2851
-                'grpID'        => $edit_array['GRP_ID'],
2852
-                'templateName' => $edit_array['template_name']
2853
-            );
2854
-            if ($success) {
2855
-                EE_Error::overwrite_success();
2856
-                EE_Error::add_success(
2857
-                    esc_html__(
2858
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2859
-                        'event_espresso'
2860
-                    )
2861
-                );
2862
-            }
2843
+		}
2844
+        
2845
+		//we return things differently if doing ajax
2846
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2847
+			$this->_template_args['success'] = $success;
2848
+			$this->_template_args['error']   = ! $success ? true : false;
2849
+			$this->_template_args['content'] = '';
2850
+			$this->_template_args['data']    = array(
2851
+				'grpID'        => $edit_array['GRP_ID'],
2852
+				'templateName' => $edit_array['template_name']
2853
+			);
2854
+			if ($success) {
2855
+				EE_Error::overwrite_success();
2856
+				EE_Error::add_success(
2857
+					esc_html__(
2858
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2859
+						'event_espresso'
2860
+					)
2861
+				);
2862
+			}
2863 2863
             
2864
-            $this->_return_json();
2865
-        }
2866
-        
2867
-        
2868
-        //was a test send triggered?
2869
-        if (isset($this->_req_data['test_button'])) {
2870
-            EE_Error::overwrite_success();
2871
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2872
-            $override = true;
2873
-        }
2874
-        
2875
-        if (empty($query_args)) {
2876
-            $query_args = array(
2877
-                'id'      => $this->_req_data['GRP_ID'],
2878
-                'context' => $context_slug,
2879
-                'action'  => 'edit_message_template'
2880
-            );
2881
-        }
2882
-        
2883
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2884
-    }
2864
+			$this->_return_json();
2865
+		}
2866
+        
2867
+        
2868
+		//was a test send triggered?
2869
+		if (isset($this->_req_data['test_button'])) {
2870
+			EE_Error::overwrite_success();
2871
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2872
+			$override = true;
2873
+		}
2874
+        
2875
+		if (empty($query_args)) {
2876
+			$query_args = array(
2877
+				'id'      => $this->_req_data['GRP_ID'],
2878
+				'context' => $context_slug,
2879
+				'action'  => 'edit_message_template'
2880
+			);
2881
+		}
2882
+        
2883
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2884
+	}
2885 2885
 
2886 2886
 
2887
-    /**
2888
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2889
-     *
2890
-     * @param  string $context      what context being tested
2891
-     * @param  string $messenger    messenger being tested
2892
-     * @param  string $message_type message type being tested
2893
-     * @throws EE_Error
2894
-     * @throws InvalidArgumentException
2895
-     * @throws InvalidDataTypeException
2896
-     * @throws InvalidInterfaceException
2897
-     */
2898
-    protected function _do_test_send($context, $messenger, $message_type)
2899
-    {
2900
-        //set things up for preview
2901
-        $this->_req_data['messenger']    = $messenger;
2902
-        $this->_req_data['message_type'] = $message_type;
2903
-        $this->_req_data['context']      = $context;
2904
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2905
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2906
-        
2907
-        //let's save any existing fields that might be required by the messenger
2908
-        if (
2909
-            isset($this->_req_data['test_settings_fld'])
2910
-            && $active_messenger instanceof EE_messenger
2911
-            && apply_filters(
2912
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2913
-                true,
2914
-                $this->_req_data['test_settings_fld'],
2915
-                $active_messenger
2916
-            )
2917
-        ) {
2918
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2919
-        }
2920
-        
2921
-        $success = $this->_preview_message(true);
2922
-        
2923
-        if ($success) {
2924
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2925
-        } else {
2926
-            EE_Error::add_error(
2927
-                esc_html__('The test message was not sent', 'event_espresso'),
2928
-                __FILE__,
2929
-                __FUNCTION__,
2930
-                __LINE__
2931
-            );
2932
-        }
2933
-    }
2887
+	/**
2888
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2889
+	 *
2890
+	 * @param  string $context      what context being tested
2891
+	 * @param  string $messenger    messenger being tested
2892
+	 * @param  string $message_type message type being tested
2893
+	 * @throws EE_Error
2894
+	 * @throws InvalidArgumentException
2895
+	 * @throws InvalidDataTypeException
2896
+	 * @throws InvalidInterfaceException
2897
+	 */
2898
+	protected function _do_test_send($context, $messenger, $message_type)
2899
+	{
2900
+		//set things up for preview
2901
+		$this->_req_data['messenger']    = $messenger;
2902
+		$this->_req_data['message_type'] = $message_type;
2903
+		$this->_req_data['context']      = $context;
2904
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2905
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2906
+        
2907
+		//let's save any existing fields that might be required by the messenger
2908
+		if (
2909
+			isset($this->_req_data['test_settings_fld'])
2910
+			&& $active_messenger instanceof EE_messenger
2911
+			&& apply_filters(
2912
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2913
+				true,
2914
+				$this->_req_data['test_settings_fld'],
2915
+				$active_messenger
2916
+			)
2917
+		) {
2918
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2919
+		}
2920
+        
2921
+		$success = $this->_preview_message(true);
2922
+        
2923
+		if ($success) {
2924
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2925
+		} else {
2926
+			EE_Error::add_error(
2927
+				esc_html__('The test message was not sent', 'event_espresso'),
2928
+				__FILE__,
2929
+				__FUNCTION__,
2930
+				__LINE__
2931
+			);
2932
+		}
2933
+	}
2934 2934
     
2935 2935
     
2936
-    /**
2937
-     * _generate_new_templates
2938
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2939
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2940
-     * for the event.
2941
-     *
2942
-     *
2943
-     * @param  string $messenger     the messenger we are generating templates for
2944
-     * @param array   $message_types array of message types that the templates are generated for.
2945
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2946
-     *                               indicate the message_template_group being used as the base.
2947
-     *
2948
-     * @param bool    $global
2949
-     *
2950
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2951
-     *                               encountering problems.
2952
-     * @throws EE_Error
2953
-     */
2954
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2955
-    {
2956
-        
2957
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2958
-        // just don't generate any templates.
2959
-        if (empty($message_types)) {
2960
-            return true;
2961
-        }
2962
-        
2963
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2964
-    }
2936
+	/**
2937
+	 * _generate_new_templates
2938
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2939
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2940
+	 * for the event.
2941
+	 *
2942
+	 *
2943
+	 * @param  string $messenger     the messenger we are generating templates for
2944
+	 * @param array   $message_types array of message types that the templates are generated for.
2945
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2946
+	 *                               indicate the message_template_group being used as the base.
2947
+	 *
2948
+	 * @param bool    $global
2949
+	 *
2950
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2951
+	 *                               encountering problems.
2952
+	 * @throws EE_Error
2953
+	 */
2954
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2955
+	{
2956
+        
2957
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
2958
+		// just don't generate any templates.
2959
+		if (empty($message_types)) {
2960
+			return true;
2961
+		}
2962
+        
2963
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2964
+	}
2965 2965
 
2966 2966
 
2967
-    /**
2968
-     * [_trash_or_restore_message_template]
2969
-     *
2970
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2971
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2972
-     *                        an individual context (FALSE).
2973
-     * @return void
2974
-     * @throws EE_Error
2975
-     * @throws InvalidArgumentException
2976
-     * @throws InvalidDataTypeException
2977
-     * @throws InvalidInterfaceException
2978
-     */
2979
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2980
-    {
2981
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2982
-        $MTP = EEM_Message_Template_Group::instance();
2983
-        
2984
-        $success = 1;
2985
-        
2986
-        //incoming GRP_IDs
2987
-        if ($all) {
2988
-            //Checkboxes
2989
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2990
-                //if array has more than one element then success message should be plural.
2991
-                //todo: what about nonce?
2992
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2967
+	/**
2968
+	 * [_trash_or_restore_message_template]
2969
+	 *
2970
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2971
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2972
+	 *                        an individual context (FALSE).
2973
+	 * @return void
2974
+	 * @throws EE_Error
2975
+	 * @throws InvalidArgumentException
2976
+	 * @throws InvalidDataTypeException
2977
+	 * @throws InvalidInterfaceException
2978
+	 */
2979
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2980
+	{
2981
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2982
+		$MTP = EEM_Message_Template_Group::instance();
2983
+        
2984
+		$success = 1;
2985
+        
2986
+		//incoming GRP_IDs
2987
+		if ($all) {
2988
+			//Checkboxes
2989
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2990
+				//if array has more than one element then success message should be plural.
2991
+				//todo: what about nonce?
2992
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2993 2993
                 
2994
-                //cycle through checkboxes
2995
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2996
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2997
-                    if ( ! $trashed_or_restored) {
2998
-                        $success = 0;
2999
-                    }
3000
-                }
3001
-            } else {
3002
-                //grab single GRP_ID and handle
3003
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3004
-                if ( ! empty($GRP_ID)) {
3005
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3006
-                    if ( ! $trashed_or_restored) {
3007
-                        $success = 0;
3008
-                    }
3009
-                } else {
3010
-                    $success = 0;
3011
-                }
3012
-            }
2994
+				//cycle through checkboxes
2995
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2996
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2997
+					if ( ! $trashed_or_restored) {
2998
+						$success = 0;
2999
+					}
3000
+				}
3001
+			} else {
3002
+				//grab single GRP_ID and handle
3003
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3004
+				if ( ! empty($GRP_ID)) {
3005
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3006
+					if ( ! $trashed_or_restored) {
3007
+						$success = 0;
3008
+					}
3009
+				} else {
3010
+					$success = 0;
3011
+				}
3012
+			}
3013 3013
             
3014
-        }
3014
+		}
3015 3015
         
3016
-        $action_desc = $trash
3017
-            ? esc_html__('moved to the trash', 'event_espresso')
3018
-            : esc_html__('restored', 'event_espresso');
3016
+		$action_desc = $trash
3017
+			? esc_html__('moved to the trash', 'event_espresso')
3018
+			: esc_html__('restored', 'event_espresso');
3019 3019
         
3020
-        $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3020
+		$action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc;
3021 3021
         
3022
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3023
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3022
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
3023
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3024 3024
         
3025
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3026
-            'event_espresso') : $item_desc;
3025
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
3026
+			'event_espresso') : $item_desc;
3027 3027
         
3028
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
3028
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
3029 3029
         
3030
-    }
3030
+	}
3031 3031
 
3032 3032
 
3033
-    /**
3034
-     * [_delete_message_template]
3035
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3036
-     *
3037
-     * @return void
3038
-     * @throws EE_Error
3039
-     * @throws InvalidArgumentException
3040
-     * @throws InvalidDataTypeException
3041
-     * @throws InvalidInterfaceException
3042
-     */
3043
-    protected function _delete_message_template()
3044
-    {
3045
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3046
-        
3047
-        //checkboxes
3048
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3049
-            //if array has more than one element then success message should be plural
3050
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3033
+	/**
3034
+	 * [_delete_message_template]
3035
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3036
+	 *
3037
+	 * @return void
3038
+	 * @throws EE_Error
3039
+	 * @throws InvalidArgumentException
3040
+	 * @throws InvalidDataTypeException
3041
+	 * @throws InvalidInterfaceException
3042
+	 */
3043
+	protected function _delete_message_template()
3044
+	{
3045
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3046
+        
3047
+		//checkboxes
3048
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3049
+			//if array has more than one element then success message should be plural
3050
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3051 3051
             
3052
-            //cycle through bulk action checkboxes
3053
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3054
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3055
-            }
3056
-        } else {
3057
-            //grab single grp_id and delete
3058
-            $GRP_ID  = absint($this->_req_data['id']);
3059
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3060
-        }
3061
-        
3062
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3063
-        
3064
-    }
3052
+			//cycle through bulk action checkboxes
3053
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3054
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3055
+			}
3056
+		} else {
3057
+			//grab single grp_id and delete
3058
+			$GRP_ID  = absint($this->_req_data['id']);
3059
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3060
+		}
3061
+        
3062
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3063
+        
3064
+	}
3065 3065
 
3066 3066
 
3067
-    /**
3068
-     * helper for permanently deleting a mtP group and all related message_templates
3069
-     *
3070
-     * @param  int  $GRP_ID        The group being deleted
3071
-     * @param  bool $include_group whether to delete the Message Template Group as well.
3072
-     * @return bool boolean to indicate the success of the deletes or not.
3073
-     * @throws EE_Error
3074
-     * @throws InvalidArgumentException
3075
-     * @throws InvalidDataTypeException
3076
-     * @throws InvalidInterfaceException
3077
-     */
3078
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3079
-    {
3080
-        $success = 1;
3081
-        $MTPG    = EEM_Message_Template_Group::instance();
3082
-        //first let's GET this group
3083
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3084
-        //then delete permanently all the related Message Templates
3085
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3086
-        
3087
-        if ($deleted === 0) {
3088
-            $success = 0;
3089
-        }
3090
-        
3091
-        //now delete permanently this particular group
3092
-        
3093
-        if ($include_group && ! $MTG->delete_permanently()) {
3094
-            $success = 0;
3095
-        }
3096
-        
3097
-        return $success;
3098
-    }
3067
+	/**
3068
+	 * helper for permanently deleting a mtP group and all related message_templates
3069
+	 *
3070
+	 * @param  int  $GRP_ID        The group being deleted
3071
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
3072
+	 * @return bool boolean to indicate the success of the deletes or not.
3073
+	 * @throws EE_Error
3074
+	 * @throws InvalidArgumentException
3075
+	 * @throws InvalidDataTypeException
3076
+	 * @throws InvalidInterfaceException
3077
+	 */
3078
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3079
+	{
3080
+		$success = 1;
3081
+		$MTPG    = EEM_Message_Template_Group::instance();
3082
+		//first let's GET this group
3083
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3084
+		//then delete permanently all the related Message Templates
3085
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3086
+        
3087
+		if ($deleted === 0) {
3088
+			$success = 0;
3089
+		}
3090
+        
3091
+		//now delete permanently this particular group
3092
+        
3093
+		if ($include_group && ! $MTG->delete_permanently()) {
3094
+			$success = 0;
3095
+		}
3096
+        
3097
+		return $success;
3098
+	}
3099 3099
     
3100 3100
     
3101
-    /**
3102
-     *    _learn_more_about_message_templates_link
3103
-     * @access protected
3104
-     * @return string
3105
-     */
3106
-    protected function _learn_more_about_message_templates_link()
3107
-    {
3108
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3109
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3110
-               . '</a>';
3111
-    }
3101
+	/**
3102
+	 *    _learn_more_about_message_templates_link
3103
+	 * @access protected
3104
+	 * @return string
3105
+	 */
3106
+	protected function _learn_more_about_message_templates_link()
3107
+	{
3108
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3109
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3110
+			   . '</a>';
3111
+	}
3112 3112
 
3113 3113
 
3114
-    /**
3115
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3116
-     * ajax and other routes.
3117
-     *
3118
-     * @return void
3119
-     * @throws DomainException
3120
-     */
3121
-    protected function _settings()
3122
-    {
3123
-        
3124
-        
3125
-        $this->_set_m_mt_settings();
3126
-        
3127
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3128
-            ? $this->_req_data['selected_messenger']
3129
-            : 'email';
3130
-        
3131
-        //let's setup the messenger tabs
3132
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3133
-            $this->_m_mt_settings['messenger_tabs'],
3134
-            'messenger_links',
3135
-            '|',
3136
-            $selected_messenger
3137
-        );
3138
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3139
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3140
-        
3141
-        $this->display_admin_page_with_sidebar();
3142
-        
3143
-    }
3114
+	/**
3115
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3116
+	 * ajax and other routes.
3117
+	 *
3118
+	 * @return void
3119
+	 * @throws DomainException
3120
+	 */
3121
+	protected function _settings()
3122
+	{
3123
+        
3124
+        
3125
+		$this->_set_m_mt_settings();
3126
+        
3127
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3128
+			? $this->_req_data['selected_messenger']
3129
+			: 'email';
3130
+        
3131
+		//let's setup the messenger tabs
3132
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3133
+			$this->_m_mt_settings['messenger_tabs'],
3134
+			'messenger_links',
3135
+			'|',
3136
+			$selected_messenger
3137
+		);
3138
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3139
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3140
+        
3141
+		$this->display_admin_page_with_sidebar();
3142
+        
3143
+	}
3144 3144
 
3145 3145
 
3146
-    /**
3147
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3148
-     *
3149
-     * @access protected
3150
-     * @return void
3151
-     * @throws DomainException
3152
-     */
3153
-    protected function _set_m_mt_settings()
3154
-    {
3155
-        //first if this is already set then lets get out no need to regenerate data.
3156
-        if ( ! empty($this->_m_mt_settings)) {
3157
-            return;
3158
-        }
3159
-        
3160
-        //get all installed messengers and message_types
3161
-        /** @type EE_messenger[] $messengers */
3162
-        $messengers = $this->_message_resource_manager->installed_messengers();
3163
-        /** @type EE_message_type[] $message_types */
3164
-        $message_types = $this->_message_resource_manager->installed_message_types();
3165
-        
3166
-        
3167
-        //assemble the array for the _tab_text_links helper
3168
-        
3169
-        foreach ($messengers as $messenger) {
3170
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3171
-                'label' => ucwords($messenger->label['singular']),
3172
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3173
-                    ? 'messenger-active'
3174
-                    : '',
3175
-                'href'  => $messenger->name,
3176
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3177
-                'slug'  => $messenger->name,
3178
-                'obj'   => $messenger
3179
-            );
3146
+	/**
3147
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3148
+	 *
3149
+	 * @access protected
3150
+	 * @return void
3151
+	 * @throws DomainException
3152
+	 */
3153
+	protected function _set_m_mt_settings()
3154
+	{
3155
+		//first if this is already set then lets get out no need to regenerate data.
3156
+		if ( ! empty($this->_m_mt_settings)) {
3157
+			return;
3158
+		}
3159
+        
3160
+		//get all installed messengers and message_types
3161
+		/** @type EE_messenger[] $messengers */
3162
+		$messengers = $this->_message_resource_manager->installed_messengers();
3163
+		/** @type EE_message_type[] $message_types */
3164
+		$message_types = $this->_message_resource_manager->installed_message_types();
3165
+        
3166
+        
3167
+		//assemble the array for the _tab_text_links helper
3168
+        
3169
+		foreach ($messengers as $messenger) {
3170
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3171
+				'label' => ucwords($messenger->label['singular']),
3172
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3173
+					? 'messenger-active'
3174
+					: '',
3175
+				'href'  => $messenger->name,
3176
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3177
+				'slug'  => $messenger->name,
3178
+				'obj'   => $messenger
3179
+			);
3180 3180
             
3181 3181
             
3182
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3182
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3183 3183
             
3184
-            foreach ($message_types as $message_type) {
3185
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3186
-                // it shouldn't show in either the inactive OR active metabox.
3187
-                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3188
-                    continue;
3189
-                }
3184
+			foreach ($message_types as $message_type) {
3185
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3186
+				// it shouldn't show in either the inactive OR active metabox.
3187
+				if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3188
+					continue;
3189
+				}
3190 3190
                 
3191
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3192
-                    $messenger->name,
3193
-                    $message_type->name
3194
-                )
3195
-                    ? 'active'
3196
-                    : 'inactive';
3191
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3192
+					$messenger->name,
3193
+					$message_type->name
3194
+				)
3195
+					? 'active'
3196
+					: 'inactive';
3197 3197
                 
3198
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3199
-                    'label'    => ucwords($message_type->label['singular']),
3200
-                    'class'    => 'message-type-' . $a_or_i,
3201
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3202
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3203
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3204
-                    'title'    => $a_or_i === 'active'
3205
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3206
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3207
-                    'content'  => $a_or_i === 'active'
3208
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3209
-                        : $this->_message_type_settings_content($message_type, $messenger),
3210
-                    'slug'     => $message_type->name,
3211
-                    'active'   => $a_or_i === 'active',
3212
-                    'obj'      => $message_type
3213
-                );
3214
-            }
3215
-        }
3216
-    }
3198
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3199
+					'label'    => ucwords($message_type->label['singular']),
3200
+					'class'    => 'message-type-' . $a_or_i,
3201
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3202
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3203
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3204
+					'title'    => $a_or_i === 'active'
3205
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3206
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3207
+					'content'  => $a_or_i === 'active'
3208
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3209
+						: $this->_message_type_settings_content($message_type, $messenger),
3210
+					'slug'     => $message_type->name,
3211
+					'active'   => $a_or_i === 'active',
3212
+					'obj'      => $message_type
3213
+				);
3214
+			}
3215
+		}
3216
+	}
3217 3217
 
3218 3218
 
3219
-    /**
3220
-     * This just prepares the content for the message type settings
3221
-     *
3222
-     * @param  EE_message_type  $message_type The message type object
3223
-     * @param  EE_messenger  $messenger    The messenger object
3224
-     * @param  boolean $active       Whether the message type is active or not
3225
-     * @return string html output for the content
3226
-     * @throws DomainException
3227
-     */
3228
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3229
-    {
3230
-        //get message type fields
3231
-        $fields                                         = $message_type->get_admin_settings_fields();
3232
-        $settings_template_args['template_form_fields'] = '';
3233
-        
3234
-        if ( ! empty($fields) && $active) {
3219
+	/**
3220
+	 * This just prepares the content for the message type settings
3221
+	 *
3222
+	 * @param  EE_message_type  $message_type The message type object
3223
+	 * @param  EE_messenger  $messenger    The messenger object
3224
+	 * @param  boolean $active       Whether the message type is active or not
3225
+	 * @return string html output for the content
3226
+	 * @throws DomainException
3227
+	 */
3228
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3229
+	{
3230
+		//get message type fields
3231
+		$fields                                         = $message_type->get_admin_settings_fields();
3232
+		$settings_template_args['template_form_fields'] = '';
3233
+        
3234
+		if ( ! empty($fields) && $active) {
3235 3235
             
3236
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3236
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3237 3237
             
3238
-            foreach ($fields as $fldname => $fldprops) {
3239
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3240
-                $template_form_field[$field_id] = array(
3241
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3242
-                    'label'      => $fldprops['label'],
3243
-                    'input'      => $fldprops['field_type'],
3244
-                    'type'       => $fldprops['value_type'],
3245
-                    'required'   => $fldprops['required'],
3246
-                    'validation' => $fldprops['validation'],
3247
-                    'value'      => isset($existing_settings[$fldname])
3248
-                        ? $existing_settings[$fldname]
3249
-                        : $fldprops['default'],
3250
-                    'options'    => isset($fldprops['options'])
3251
-                        ? $fldprops['options']
3252
-                        : array(),
3253
-                    'default'    => isset($existing_settings[$fldname])
3254
-                        ? $existing_settings[$fldname]
3255
-                        : $fldprops['default'],
3256
-                    'css_class'  => 'no-drag',
3257
-                    'format'     => $fldprops['format']
3258
-                );
3259
-            }
3238
+			foreach ($fields as $fldname => $fldprops) {
3239
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3240
+				$template_form_field[$field_id] = array(
3241
+					'name'       => 'message_type_settings[' . $fldname . ']',
3242
+					'label'      => $fldprops['label'],
3243
+					'input'      => $fldprops['field_type'],
3244
+					'type'       => $fldprops['value_type'],
3245
+					'required'   => $fldprops['required'],
3246
+					'validation' => $fldprops['validation'],
3247
+					'value'      => isset($existing_settings[$fldname])
3248
+						? $existing_settings[$fldname]
3249
+						: $fldprops['default'],
3250
+					'options'    => isset($fldprops['options'])
3251
+						? $fldprops['options']
3252
+						: array(),
3253
+					'default'    => isset($existing_settings[$fldname])
3254
+						? $existing_settings[$fldname]
3255
+						: $fldprops['default'],
3256
+					'css_class'  => 'no-drag',
3257
+					'format'     => $fldprops['format']
3258
+				);
3259
+			}
3260 3260
             
3261 3261
             
3262
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3263
-                ? $this->_generate_admin_form_fields(
3264
-                    $template_form_field,
3265
-                    'string',
3266
-                    'ee_mt_activate_form'
3267
-                )
3268
-                : '';
3269
-        }
3270
-        
3271
-        $settings_template_args['description'] = $message_type->description;
3272
-        //we also need some hidden fields
3273
-        $settings_template_args['hidden_fields'] = array(
3274
-            'message_type_settings[messenger]'    => array(
3275
-                'type'  => 'hidden',
3276
-                'value' => $messenger->name
3277
-            ),
3278
-            'message_type_settings[message_type]' => array(
3279
-                'type'  => 'hidden',
3280
-                'value' => $message_type->name
3281
-            ),
3282
-            'type'                                => array(
3283
-                'type'  => 'hidden',
3284
-                'value' => 'message_type'
3285
-            )
3286
-        );
3287
-        
3288
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3289
-            $settings_template_args['hidden_fields'],
3290
-            'array'
3291
-        );
3292
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3293
-            ? ' hidden'
3294
-            : '';
3295
-        
3296
-        
3297
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3298
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
3299
-        
3300
-        return $content;
3301
-    }
3262
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3263
+				? $this->_generate_admin_form_fields(
3264
+					$template_form_field,
3265
+					'string',
3266
+					'ee_mt_activate_form'
3267
+				)
3268
+				: '';
3269
+		}
3270
+        
3271
+		$settings_template_args['description'] = $message_type->description;
3272
+		//we also need some hidden fields
3273
+		$settings_template_args['hidden_fields'] = array(
3274
+			'message_type_settings[messenger]'    => array(
3275
+				'type'  => 'hidden',
3276
+				'value' => $messenger->name
3277
+			),
3278
+			'message_type_settings[message_type]' => array(
3279
+				'type'  => 'hidden',
3280
+				'value' => $message_type->name
3281
+			),
3282
+			'type'                                => array(
3283
+				'type'  => 'hidden',
3284
+				'value' => 'message_type'
3285
+			)
3286
+		);
3287
+        
3288
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3289
+			$settings_template_args['hidden_fields'],
3290
+			'array'
3291
+		);
3292
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3293
+			? ' hidden'
3294
+			: '';
3295
+        
3296
+        
3297
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3298
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
3299
+        
3300
+		return $content;
3301
+	}
3302 3302
 
3303 3303
 
3304
-    /**
3305
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3306
-     *
3307
-     * @access protected
3308
-     * @return void
3309
-     * @throws DomainException
3310
-     */
3311
-    protected function _messages_settings_metaboxes()
3312
-    {
3313
-        $this->_set_m_mt_settings();
3314
-        $m_boxes         = $mt_boxes = array();
3315
-        $m_template_args = $mt_template_args = array();
3316
-        
3317
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3318
-            ? $this->_req_data['selected_messenger']
3319
-            : 'email';
3320
-        
3321
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3322
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3323
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3324
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3325
-                //messenger meta boxes
3326
-                $active                                 = $selected_messenger === $messenger;
3327
-                $active_mt_tabs                         = isset(
3328
-                    $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3329
-                )
3330
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3331
-                    : '';
3332
-                $m_boxes[$messenger . '_a_box']         = sprintf(
3333
-                    esc_html__('%s Settings', 'event_espresso'),
3334
-                    $tab_array['label']
3335
-                );
3336
-                $m_template_args[$messenger . '_a_box'] = array(
3337
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3338
-                    'inactive_message_types' => isset(
3339
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3340
-                    )
3341
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3342
-                        : '',
3343
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3344
-                    'hidden'                 => $active ? '' : ' hidden',
3345
-                    'hide_on_message'        => $hide_on_message,
3346
-                    'messenger'              => $messenger,
3347
-                    'active'                 => $active
3348
-                );
3349
-                // message type meta boxes
3350
-                // (which is really just the inactive container for each messenger
3351
-                // showing inactive message types for that messenger)
3352
-                $mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3353
-                $mt_template_args[$messenger . '_i_box'] = array(
3354
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3355
-                    'inactive_message_types' => isset(
3356
-                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3357
-                    )
3358
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3359
-                        : '',
3360
-                    'hidden'                 => $active ? '' : ' hidden',
3361
-                    'hide_on_message'        => $hide_on_message,
3362
-                    'hide_off_message'       => $hide_off_message,
3363
-                    'messenger'              => $messenger,
3364
-                    'active'                 => $active
3365
-                );
3366
-            }
3367
-        }
3368
-        
3369
-        
3370
-        //register messenger metaboxes
3371
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3372
-        foreach ($m_boxes as $box => $label) {
3373
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3374
-            $msgr          = str_replace('_a_box', '', $box);
3375
-            add_meta_box(
3376
-                'espresso_' . $msgr . '_settings',
3377
-                $label,
3378
-                function ($post, $metabox) {
3379
-                    echo EEH_Template::display_template(
3380
-                            $metabox["args"]["template_path"],
3381
-                            $metabox["args"]["template_args"],
3382
-                            true
3383
-                    );
3384
-                },
3385
-                $this->_current_screen->id,
3386
-                'normal',
3387
-                'high',
3388
-                $callback_args
3389
-            );
3390
-        }
3391
-        
3392
-        //register message type metaboxes
3393
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3394
-        foreach ($mt_boxes as $box => $label) {
3395
-            $callback_args = array(
3396
-                'template_path' => $mt_template_path,
3397
-                'template_args' => $mt_template_args[$box]
3398
-            );
3399
-            $mt            = str_replace('_i_box', '', $box);
3400
-            add_meta_box(
3401
-                'espresso_' . $mt . '_inactive_mts',
3402
-                $label,
3403
-                function ($post, $metabox) {
3404
-                    echo EEH_Template::display_template(
3405
-                            $metabox["args"]["template_path"],
3406
-                            $metabox["args"]["template_args"],
3407
-                            true
3408
-                    );
3409
-                },
3410
-                $this->_current_screen->id,
3411
-                'side',
3412
-                'high',
3413
-                $callback_args
3414
-            );
3415
-        }
3416
-        
3417
-        //register metabox for global messages settings but only when on the main site.  On single site installs this
3418
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3419
-        if (is_main_site()) {
3420
-            add_meta_box(
3421
-                'espresso_global_message_settings',
3422
-                esc_html__('Global Message Settings', 'event_espresso'),
3423
-                array($this, 'global_messages_settings_metabox_content'),
3424
-                $this->_current_screen->id,
3425
-                'normal',
3426
-                'low',
3427
-                array()
3428
-            );
3429
-        }
3430
-        
3431
-    }
3304
+	/**
3305
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3306
+	 *
3307
+	 * @access protected
3308
+	 * @return void
3309
+	 * @throws DomainException
3310
+	 */
3311
+	protected function _messages_settings_metaboxes()
3312
+	{
3313
+		$this->_set_m_mt_settings();
3314
+		$m_boxes         = $mt_boxes = array();
3315
+		$m_template_args = $mt_template_args = array();
3316
+        
3317
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3318
+			? $this->_req_data['selected_messenger']
3319
+			: 'email';
3320
+        
3321
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3322
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3323
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3324
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3325
+				//messenger meta boxes
3326
+				$active                                 = $selected_messenger === $messenger;
3327
+				$active_mt_tabs                         = isset(
3328
+					$this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3329
+				)
3330
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3331
+					: '';
3332
+				$m_boxes[$messenger . '_a_box']         = sprintf(
3333
+					esc_html__('%s Settings', 'event_espresso'),
3334
+					$tab_array['label']
3335
+				);
3336
+				$m_template_args[$messenger . '_a_box'] = array(
3337
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3338
+					'inactive_message_types' => isset(
3339
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3340
+					)
3341
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3342
+						: '',
3343
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3344
+					'hidden'                 => $active ? '' : ' hidden',
3345
+					'hide_on_message'        => $hide_on_message,
3346
+					'messenger'              => $messenger,
3347
+					'active'                 => $active
3348
+				);
3349
+				// message type meta boxes
3350
+				// (which is really just the inactive container for each messenger
3351
+				// showing inactive message types for that messenger)
3352
+				$mt_boxes[$messenger . '_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3353
+				$mt_template_args[$messenger . '_i_box'] = array(
3354
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3355
+					'inactive_message_types' => isset(
3356
+						$this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3357
+					)
3358
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3359
+						: '',
3360
+					'hidden'                 => $active ? '' : ' hidden',
3361
+					'hide_on_message'        => $hide_on_message,
3362
+					'hide_off_message'       => $hide_off_message,
3363
+					'messenger'              => $messenger,
3364
+					'active'                 => $active
3365
+				);
3366
+			}
3367
+		}
3368
+        
3369
+        
3370
+		//register messenger metaboxes
3371
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3372
+		foreach ($m_boxes as $box => $label) {
3373
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3374
+			$msgr          = str_replace('_a_box', '', $box);
3375
+			add_meta_box(
3376
+				'espresso_' . $msgr . '_settings',
3377
+				$label,
3378
+				function ($post, $metabox) {
3379
+					echo EEH_Template::display_template(
3380
+							$metabox["args"]["template_path"],
3381
+							$metabox["args"]["template_args"],
3382
+							true
3383
+					);
3384
+				},
3385
+				$this->_current_screen->id,
3386
+				'normal',
3387
+				'high',
3388
+				$callback_args
3389
+			);
3390
+		}
3391
+        
3392
+		//register message type metaboxes
3393
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3394
+		foreach ($mt_boxes as $box => $label) {
3395
+			$callback_args = array(
3396
+				'template_path' => $mt_template_path,
3397
+				'template_args' => $mt_template_args[$box]
3398
+			);
3399
+			$mt            = str_replace('_i_box', '', $box);
3400
+			add_meta_box(
3401
+				'espresso_' . $mt . '_inactive_mts',
3402
+				$label,
3403
+				function ($post, $metabox) {
3404
+					echo EEH_Template::display_template(
3405
+							$metabox["args"]["template_path"],
3406
+							$metabox["args"]["template_args"],
3407
+							true
3408
+					);
3409
+				},
3410
+				$this->_current_screen->id,
3411
+				'side',
3412
+				'high',
3413
+				$callback_args
3414
+			);
3415
+		}
3416
+        
3417
+		//register metabox for global messages settings but only when on the main site.  On single site installs this
3418
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3419
+		if (is_main_site()) {
3420
+			add_meta_box(
3421
+				'espresso_global_message_settings',
3422
+				esc_html__('Global Message Settings', 'event_espresso'),
3423
+				array($this, 'global_messages_settings_metabox_content'),
3424
+				$this->_current_screen->id,
3425
+				'normal',
3426
+				'low',
3427
+				array()
3428
+			);
3429
+		}
3430
+        
3431
+	}
3432 3432
 
3433 3433
 
3434
-    /**
3435
-     *  This generates the content for the global messages settings metabox.
3436
-     *
3437
-     * @return string
3438
-     * @throws EE_Error
3439
-     * @throws InvalidArgumentException
3440
-     * @throws ReflectionException
3441
-     * @throws InvalidDataTypeException
3442
-     * @throws InvalidInterfaceException
3443
-     */
3444
-    public function global_messages_settings_metabox_content()
3445
-    {
3446
-        $form = $this->_generate_global_settings_form();
3447
-        echo $form->form_open(
3448
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3449
-                'POST'
3450
-            )
3451
-             . $form->get_html()
3452
-             . $form->form_close();
3453
-    }
3434
+	/**
3435
+	 *  This generates the content for the global messages settings metabox.
3436
+	 *
3437
+	 * @return string
3438
+	 * @throws EE_Error
3439
+	 * @throws InvalidArgumentException
3440
+	 * @throws ReflectionException
3441
+	 * @throws InvalidDataTypeException
3442
+	 * @throws InvalidInterfaceException
3443
+	 */
3444
+	public function global_messages_settings_metabox_content()
3445
+	{
3446
+		$form = $this->_generate_global_settings_form();
3447
+		echo $form->form_open(
3448
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3449
+				'POST'
3450
+			)
3451
+			 . $form->get_html()
3452
+			 . $form->form_close();
3453
+	}
3454 3454
 
3455 3455
 
3456
-    /**
3457
-     * This generates and returns the form object for the global messages settings.
3458
-     *
3459
-     * @return EE_Form_Section_Proper
3460
-     * @throws EE_Error
3461
-     * @throws InvalidArgumentException
3462
-     * @throws ReflectionException
3463
-     * @throws InvalidDataTypeException
3464
-     * @throws InvalidInterfaceException
3465
-     */
3466
-    protected function _generate_global_settings_form()
3467
-    {
3468
-        EE_Registry::instance()->load_helper('HTML');
3469
-        /** @var EE_Network_Core_Config $network_config */
3470
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3471
-        
3472
-        return new EE_Form_Section_Proper(
3473
-            array(
3474
-                'name'            => 'global_messages_settings',
3475
-                'html_id'         => 'global_messages_settings',
3476
-                'html_class'      => 'form-table',
3477
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3478
-                'subsections'     => apply_filters(
3479
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3480
-                    array(
3481
-                        'do_messages_on_same_request' => new EE_Select_Input(
3482
-                            array(
3483
-                                true  => esc_html__("On the same request", "event_espresso"),
3484
-                                false => esc_html__("On a separate request", "event_espresso")
3485
-                            ),
3486
-                            array(
3487
-                                'default'         => $network_config->do_messages_on_same_request,
3488
-                                'html_label_text' => esc_html__(
3489
-                                    'Generate and send all messages:',
3490
-                                    'event_espresso'
3491
-                                ),
3492
-                                'html_help_text'  => esc_html__(
3493
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3494
-                                    'event_espresso'
3495
-                                ),
3496
-                            )
3497
-                        ),
3498
-                        'delete_threshold' => new EE_Select_Input(
3499
-                            array(
3500
-                                0 => esc_html__('Forever', 'event_espresso'),
3501
-                                3 => esc_html__('3 Months', 'event_espresso'),
3502
-                                6 => esc_html__('6 Months', 'event_espresso'),
3503
-                                9 => esc_html__('9 Months', 'event_espresso'),
3504
-                                12 => esc_html__('12 Months', 'event_espresso'),
3505
-                                24 => esc_html__('24 Months', 'event_espresso'),
3506
-                                36 => esc_html__('36 Months', 'event_espresso')
3507
-                            ),
3508
-                            array(
3509
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3510
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3511
-                                'html_help_text' => esc_html__(
3512
-                                    'You can control how long a record of processed messages is kept via this option.',
3513
-                                    'event_espresso'
3514
-                                ),
3515
-                            )
3516
-                        ),
3517
-                        'update_settings'             => new EE_Submit_Input(
3518
-                            array(
3519
-                                'default'         => esc_html__('Update', 'event_espresso'),
3520
-                                'html_label_text' => '&nbsp'
3521
-                            )
3522
-                        )
3523
-                    )
3524
-                )
3525
-            )
3526
-        );
3527
-    }
3456
+	/**
3457
+	 * This generates and returns the form object for the global messages settings.
3458
+	 *
3459
+	 * @return EE_Form_Section_Proper
3460
+	 * @throws EE_Error
3461
+	 * @throws InvalidArgumentException
3462
+	 * @throws ReflectionException
3463
+	 * @throws InvalidDataTypeException
3464
+	 * @throws InvalidInterfaceException
3465
+	 */
3466
+	protected function _generate_global_settings_form()
3467
+	{
3468
+		EE_Registry::instance()->load_helper('HTML');
3469
+		/** @var EE_Network_Core_Config $network_config */
3470
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3471
+        
3472
+		return new EE_Form_Section_Proper(
3473
+			array(
3474
+				'name'            => 'global_messages_settings',
3475
+				'html_id'         => 'global_messages_settings',
3476
+				'html_class'      => 'form-table',
3477
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3478
+				'subsections'     => apply_filters(
3479
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3480
+					array(
3481
+						'do_messages_on_same_request' => new EE_Select_Input(
3482
+							array(
3483
+								true  => esc_html__("On the same request", "event_espresso"),
3484
+								false => esc_html__("On a separate request", "event_espresso")
3485
+							),
3486
+							array(
3487
+								'default'         => $network_config->do_messages_on_same_request,
3488
+								'html_label_text' => esc_html__(
3489
+									'Generate and send all messages:',
3490
+									'event_espresso'
3491
+								),
3492
+								'html_help_text'  => esc_html__(
3493
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3494
+									'event_espresso'
3495
+								),
3496
+							)
3497
+						),
3498
+						'delete_threshold' => new EE_Select_Input(
3499
+							array(
3500
+								0 => esc_html__('Forever', 'event_espresso'),
3501
+								3 => esc_html__('3 Months', 'event_espresso'),
3502
+								6 => esc_html__('6 Months', 'event_espresso'),
3503
+								9 => esc_html__('9 Months', 'event_espresso'),
3504
+								12 => esc_html__('12 Months', 'event_espresso'),
3505
+								24 => esc_html__('24 Months', 'event_espresso'),
3506
+								36 => esc_html__('36 Months', 'event_espresso')
3507
+							),
3508
+							array(
3509
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3510
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3511
+								'html_help_text' => esc_html__(
3512
+									'You can control how long a record of processed messages is kept via this option.',
3513
+									'event_espresso'
3514
+								),
3515
+							)
3516
+						),
3517
+						'update_settings'             => new EE_Submit_Input(
3518
+							array(
3519
+								'default'         => esc_html__('Update', 'event_espresso'),
3520
+								'html_label_text' => '&nbsp'
3521
+							)
3522
+						)
3523
+					)
3524
+				)
3525
+			)
3526
+		);
3527
+	}
3528 3528
 
3529 3529
 
3530
-    /**
3531
-     * This handles updating the global settings set on the admin page.
3532
-     *
3533
-     * @throws EE_Error
3534
-     * @throws InvalidDataTypeException
3535
-     * @throws InvalidInterfaceException
3536
-     * @throws InvalidArgumentException
3537
-     * @throws ReflectionException
3538
-     */
3539
-    protected function _update_global_settings()
3540
-    {
3541
-        /** @var EE_Network_Core_Config $network_config */
3542
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3543
-        $messages_config = EE_Registry::instance()->CFG->messages;
3544
-        $form           = $this->_generate_global_settings_form();
3545
-        if ($form->was_submitted()) {
3546
-            $form->receive_form_submission();
3547
-            if ($form->is_valid()) {
3548
-                $valid_data = $form->valid_data();
3549
-                foreach ($valid_data as $property => $value) {
3550
-                    $setter = 'set_' . $property;
3551
-                    if (method_exists($network_config, $setter)) {
3552
-                        $network_config->{$setter}($value);
3553
-                    } else if (
3554
-                        property_exists($network_config, $property)
3555
-                        && $network_config->{$property} !== $value
3556
-                    ) {
3557
-                        $network_config->{$property} = $value;
3558
-                    } else if (
3559
-                        property_exists($messages_config, $property)
3560
-                        && $messages_config->{$property} !== $value
3561
-                    ) {
3562
-                        $messages_config->{$property} = $value;
3563
-                    }
3564
-                }
3565
-                //only update if the form submission was valid!
3566
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3567
-                EE_Registry::instance()->CFG->update_espresso_config();
3568
-                EE_Error::overwrite_success();
3569
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3570
-            }
3571
-        }
3572
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3573
-    }
3530
+	/**
3531
+	 * This handles updating the global settings set on the admin page.
3532
+	 *
3533
+	 * @throws EE_Error
3534
+	 * @throws InvalidDataTypeException
3535
+	 * @throws InvalidInterfaceException
3536
+	 * @throws InvalidArgumentException
3537
+	 * @throws ReflectionException
3538
+	 */
3539
+	protected function _update_global_settings()
3540
+	{
3541
+		/** @var EE_Network_Core_Config $network_config */
3542
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3543
+		$messages_config = EE_Registry::instance()->CFG->messages;
3544
+		$form           = $this->_generate_global_settings_form();
3545
+		if ($form->was_submitted()) {
3546
+			$form->receive_form_submission();
3547
+			if ($form->is_valid()) {
3548
+				$valid_data = $form->valid_data();
3549
+				foreach ($valid_data as $property => $value) {
3550
+					$setter = 'set_' . $property;
3551
+					if (method_exists($network_config, $setter)) {
3552
+						$network_config->{$setter}($value);
3553
+					} else if (
3554
+						property_exists($network_config, $property)
3555
+						&& $network_config->{$property} !== $value
3556
+					) {
3557
+						$network_config->{$property} = $value;
3558
+					} else if (
3559
+						property_exists($messages_config, $property)
3560
+						&& $messages_config->{$property} !== $value
3561
+					) {
3562
+						$messages_config->{$property} = $value;
3563
+					}
3564
+				}
3565
+				//only update if the form submission was valid!
3566
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3567
+				EE_Registry::instance()->CFG->update_espresso_config();
3568
+				EE_Error::overwrite_success();
3569
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3570
+			}
3571
+		}
3572
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3573
+	}
3574 3574
 
3575 3575
 
3576
-    /**
3577
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3578
-     *
3579
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3580
-     * @return string html formatted tabs
3581
-     * @throws DomainException
3582
-     */
3583
-    protected function _get_mt_tabs($tab_array)
3584
-    {
3585
-        $tab_array = (array)$tab_array;
3586
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3587
-        $tabs      = '';
3588
-        
3589
-        foreach ($tab_array as $tab) {
3590
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3591
-        }
3592
-        
3593
-        return $tabs;
3594
-    }
3576
+	/**
3577
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3578
+	 *
3579
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3580
+	 * @return string html formatted tabs
3581
+	 * @throws DomainException
3582
+	 */
3583
+	protected function _get_mt_tabs($tab_array)
3584
+	{
3585
+		$tab_array = (array)$tab_array;
3586
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3587
+		$tabs      = '';
3588
+        
3589
+		foreach ($tab_array as $tab) {
3590
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3591
+		}
3592
+        
3593
+		return $tabs;
3594
+	}
3595 3595
 
3596 3596
 
3597
-    /**
3598
-     * This prepares the content of the messenger meta box admin settings
3599
-     *
3600
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3601
-     * @return string html formatted content
3602
-     * @throws DomainException
3603
-     */
3604
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3605
-    {
3597
+	/**
3598
+	 * This prepares the content of the messenger meta box admin settings
3599
+	 *
3600
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3601
+	 * @return string html formatted content
3602
+	 * @throws DomainException
3603
+	 */
3604
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3605
+	{
3606 3606
         
3607
-        $fields                                         = $messenger->get_admin_settings_fields();
3608
-        $settings_template_args['template_form_fields'] = '';
3607
+		$fields                                         = $messenger->get_admin_settings_fields();
3608
+		$settings_template_args['template_form_fields'] = '';
3609 3609
         
3610
-        //is $messenger active?
3611
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3610
+		//is $messenger active?
3611
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3612 3612
         
3613 3613
         
3614
-        if ( ! empty($fields)) {
3614
+		if ( ! empty($fields)) {
3615 3615
             
3616
-            $existing_settings = $messenger->get_existing_admin_settings();
3616
+			$existing_settings = $messenger->get_existing_admin_settings();
3617 3617
             
3618
-            foreach ($fields as $fldname => $fldprops) {
3619
-                $field_id                       = $messenger->name . '-' . $fldname;
3620
-                $template_form_field[$field_id] = array(
3621
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3622
-                    'label'      => $fldprops['label'],
3623
-                    'input'      => $fldprops['field_type'],
3624
-                    'type'       => $fldprops['value_type'],
3625
-                    'required'   => $fldprops['required'],
3626
-                    'validation' => $fldprops['validation'],
3627
-                    'value'      => isset($existing_settings[$field_id])
3628
-                        ? $existing_settings[$field_id]
3629
-                        : $fldprops['default'],
3630
-                    'css_class'  => '',
3631
-                    'format'     => $fldprops['format']
3632
-                );
3633
-            }
3618
+			foreach ($fields as $fldname => $fldprops) {
3619
+				$field_id                       = $messenger->name . '-' . $fldname;
3620
+				$template_form_field[$field_id] = array(
3621
+					'name'       => 'messenger_settings[' . $field_id . ']',
3622
+					'label'      => $fldprops['label'],
3623
+					'input'      => $fldprops['field_type'],
3624
+					'type'       => $fldprops['value_type'],
3625
+					'required'   => $fldprops['required'],
3626
+					'validation' => $fldprops['validation'],
3627
+					'value'      => isset($existing_settings[$field_id])
3628
+						? $existing_settings[$field_id]
3629
+						: $fldprops['default'],
3630
+					'css_class'  => '',
3631
+					'format'     => $fldprops['format']
3632
+				);
3633
+			}
3634 3634
             
3635 3635
             
3636
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3637
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3638
-                : '';
3639
-        }
3640
-        
3641
-        //we also need some hidden fields
3642
-        $settings_template_args['hidden_fields'] = array(
3643
-            'messenger_settings[messenger]' => array(
3644
-                'type'  => 'hidden',
3645
-                'value' => $messenger->name
3646
-            ),
3647
-            'type'                          => array(
3648
-                'type'  => 'hidden',
3649
-                'value' => 'messenger'
3650
-            )
3651
-        );
3652
-        
3653
-        //make sure any active message types that are existing are included in the hidden fields
3654
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3655
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3656
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3657
-                    'type'  => 'hidden',
3658
-                    'value' => $mt
3659
-                );
3660
-            }
3661
-        }
3662
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3663
-            $settings_template_args['hidden_fields'],
3664
-            'array'
3665
-        );
3666
-        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3667
-        
3668
-        $settings_template_args['messenger']           = $messenger->name;
3669
-        $settings_template_args['description']         = $messenger->description;
3670
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3671
-        
3672
-        
3673
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3674
-            $messenger->name
3675
-        )
3676
-            ? $settings_template_args['show_hide_edit_form']
3677
-            : ' hidden';
3678
-        
3679
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3680
-            ? ' hidden'
3681
-            : $settings_template_args['show_hide_edit_form'];
3682
-        
3683
-        
3684
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3685
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3686
-        $settings_template_args['on_off_status'] = $active ? true : false;
3687
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3688
-        $content                                 = EEH_Template::display_template(
3689
-            $template,
3690
-            $settings_template_args,
3691
-            true
3692
-        );
3693
-        
3694
-        return $content;
3695
-    }
3636
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3637
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3638
+				: '';
3639
+		}
3640
+        
3641
+		//we also need some hidden fields
3642
+		$settings_template_args['hidden_fields'] = array(
3643
+			'messenger_settings[messenger]' => array(
3644
+				'type'  => 'hidden',
3645
+				'value' => $messenger->name
3646
+			),
3647
+			'type'                          => array(
3648
+				'type'  => 'hidden',
3649
+				'value' => 'messenger'
3650
+			)
3651
+		);
3652
+        
3653
+		//make sure any active message types that are existing are included in the hidden fields
3654
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3655
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3656
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3657
+					'type'  => 'hidden',
3658
+					'value' => $mt
3659
+				);
3660
+			}
3661
+		}
3662
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3663
+			$settings_template_args['hidden_fields'],
3664
+			'array'
3665
+		);
3666
+		$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3667
+        
3668
+		$settings_template_args['messenger']           = $messenger->name;
3669
+		$settings_template_args['description']         = $messenger->description;
3670
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3671
+        
3672
+        
3673
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3674
+			$messenger->name
3675
+		)
3676
+			? $settings_template_args['show_hide_edit_form']
3677
+			: ' hidden';
3678
+        
3679
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3680
+			? ' hidden'
3681
+			: $settings_template_args['show_hide_edit_form'];
3682
+        
3683
+        
3684
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3685
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3686
+		$settings_template_args['on_off_status'] = $active ? true : false;
3687
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3688
+		$content                                 = EEH_Template::display_template(
3689
+			$template,
3690
+			$settings_template_args,
3691
+			true
3692
+		);
3693
+        
3694
+		return $content;
3695
+	}
3696 3696
 
3697 3697
 
3698
-    /**
3699
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3700
-     *
3701
-     * @throws DomainException
3702
-     * @throws EE_Error
3703
-     * @throws InvalidDataTypeException
3704
-     * @throws InvalidInterfaceException
3705
-     * @throws InvalidArgumentException
3706
-     * @throws ReflectionException
3707
-     */
3708
-    public function activate_messenger_toggle()
3709
-    {
3710
-        $success = true;
3711
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3712
-        //let's check that we have required data
3713
-        if ( ! isset($this->_req_data['messenger'])) {
3714
-            EE_Error::add_error(
3715
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3716
-                __FILE__,
3717
-                __FUNCTION__,
3718
-                __LINE__
3719
-            );
3720
-            $success = false;
3721
-        }
3722
-        
3723
-        //do a nonce check here since we're not arriving via a normal route
3724
-        $nonce     = isset($this->_req_data['activate_nonce'])
3725
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3726
-            : '';
3727
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3728
-        
3729
-        $this->_verify_nonce($nonce, $nonce_ref);
3730
-        
3731
-        
3732
-        if ( ! isset($this->_req_data['status'])) {
3733
-            EE_Error::add_error(
3734
-                esc_html__(
3735
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3736
-                    'event_espresso'
3737
-                ),
3738
-                __FILE__,
3739
-                __FUNCTION__,
3740
-                __LINE__
3741
-            );
3742
-            $success = false;
3743
-        }
3744
-        
3745
-        //do check to verify we have a valid status.
3746
-        $status = $this->_req_data['status'];
3747
-        
3748
-        if ($status !== 'off' && $status !== 'on') {
3749
-            EE_Error::add_error(
3750
-                sprintf(
3751
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3752
-                    $this->_req_data['status']
3753
-                ),
3754
-                __FILE__,
3755
-                __FUNCTION__,
3756
-                __LINE__
3757
-            );
3758
-            $success = false;
3759
-        }
3760
-        
3761
-        if ($success) {
3762
-            //made it here?  Stop dawdling then!!
3763
-            $success = $status === 'off'
3764
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3765
-                : $this->_activate_messenger($this->_req_data['messenger']);
3766
-        }
3767
-        
3768
-        $this->_template_args['success'] = $success;
3769
-        
3770
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3771
-        $this->_return_json();
3772
-        
3773
-    }
3698
+	/**
3699
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3700
+	 *
3701
+	 * @throws DomainException
3702
+	 * @throws EE_Error
3703
+	 * @throws InvalidDataTypeException
3704
+	 * @throws InvalidInterfaceException
3705
+	 * @throws InvalidArgumentException
3706
+	 * @throws ReflectionException
3707
+	 */
3708
+	public function activate_messenger_toggle()
3709
+	{
3710
+		$success = true;
3711
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3712
+		//let's check that we have required data
3713
+		if ( ! isset($this->_req_data['messenger'])) {
3714
+			EE_Error::add_error(
3715
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3716
+				__FILE__,
3717
+				__FUNCTION__,
3718
+				__LINE__
3719
+			);
3720
+			$success = false;
3721
+		}
3722
+        
3723
+		//do a nonce check here since we're not arriving via a normal route
3724
+		$nonce     = isset($this->_req_data['activate_nonce'])
3725
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3726
+			: '';
3727
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3728
+        
3729
+		$this->_verify_nonce($nonce, $nonce_ref);
3730
+        
3731
+        
3732
+		if ( ! isset($this->_req_data['status'])) {
3733
+			EE_Error::add_error(
3734
+				esc_html__(
3735
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3736
+					'event_espresso'
3737
+				),
3738
+				__FILE__,
3739
+				__FUNCTION__,
3740
+				__LINE__
3741
+			);
3742
+			$success = false;
3743
+		}
3744
+        
3745
+		//do check to verify we have a valid status.
3746
+		$status = $this->_req_data['status'];
3747
+        
3748
+		if ($status !== 'off' && $status !== 'on') {
3749
+			EE_Error::add_error(
3750
+				sprintf(
3751
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3752
+					$this->_req_data['status']
3753
+				),
3754
+				__FILE__,
3755
+				__FUNCTION__,
3756
+				__LINE__
3757
+			);
3758
+			$success = false;
3759
+		}
3760
+        
3761
+		if ($success) {
3762
+			//made it here?  Stop dawdling then!!
3763
+			$success = $status === 'off'
3764
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3765
+				: $this->_activate_messenger($this->_req_data['messenger']);
3766
+		}
3767
+        
3768
+		$this->_template_args['success'] = $success;
3769
+        
3770
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3771
+		$this->_return_json();
3772
+        
3773
+	}
3774 3774
 
3775 3775
 
3776
-    /**
3777
-     * used by ajax from the messages settings page to activate|deactivate a message type
3778
-     *
3779
-     * @throws DomainException
3780
-     * @throws EE_Error
3781
-     * @throws ReflectionException
3782
-     * @throws InvalidDataTypeException
3783
-     * @throws InvalidInterfaceException
3784
-     * @throws InvalidArgumentException
3785
-     */
3786
-    public function activate_mt_toggle()
3787
-    {
3788
-        $success = true;
3789
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3790
-        
3791
-        //let's make sure we have the necessary data
3792
-        if ( ! isset($this->_req_data['message_type'])) {
3793
-            EE_Error::add_error(
3794
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3795
-                __FILE__,
3796
-                __FUNCTION__,
3797
-                __LINE__
3798
-            );
3799
-            $success = false;
3800
-        }
3801
-        
3802
-        if ( ! isset($this->_req_data['messenger'])) {
3803
-            EE_Error::add_error(
3804
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3805
-                __FILE__,
3806
-                __FUNCTION__,
3807
-                __LINE__
3808
-            );
3809
-            $success = false;
3810
-        }
3811
-        
3812
-        if ( ! isset($this->_req_data['status'])) {
3813
-            EE_Error::add_error(
3814
-                esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3815
-                    'event_espresso'),
3816
-                __FILE__,
3817
-                __FUNCTION__,
3818
-                __LINE__
3819
-            );
3820
-            $success = false;
3821
-        }
3822
-        
3823
-        
3824
-        //do check to verify we have a valid status.
3825
-        $status = $this->_req_data['status'];
3826
-        
3827
-        if ($status !== 'activate' && $status !== 'deactivate') {
3828
-            EE_Error::add_error(
3829
-                sprintf(
3830
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3831
-                    $this->_req_data['status']
3832
-                ),
3833
-                __FILE__,
3834
-                __FUNCTION__,
3835
-                __LINE__
3836
-            );
3837
-            $success = false;
3838
-        }
3839
-        
3840
-        
3841
-        //do a nonce check here since we're not arriving via a normal route
3842
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3843
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3844
-        
3845
-        $this->_verify_nonce($nonce, $nonce_ref);
3846
-        
3847
-        if ($success) {
3848
-            //made it here? um, what are you waiting for then?
3849
-            $success = $status === 'deactivate'
3850
-                ? $this->_deactivate_message_type_for_messenger(
3851
-                    $this->_req_data['messenger'],
3852
-                    $this->_req_data['message_type']
3853
-                )
3854
-                : $this->_activate_message_type_for_messenger(
3855
-                    $this->_req_data['messenger'],
3856
-                    $this->_req_data['message_type']
3857
-                );
3858
-        }
3859
-        
3860
-        $this->_template_args['success'] = $success;
3861
-        $this->_return_json();
3862
-    }
3776
+	/**
3777
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3778
+	 *
3779
+	 * @throws DomainException
3780
+	 * @throws EE_Error
3781
+	 * @throws ReflectionException
3782
+	 * @throws InvalidDataTypeException
3783
+	 * @throws InvalidInterfaceException
3784
+	 * @throws InvalidArgumentException
3785
+	 */
3786
+	public function activate_mt_toggle()
3787
+	{
3788
+		$success = true;
3789
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3790
+        
3791
+		//let's make sure we have the necessary data
3792
+		if ( ! isset($this->_req_data['message_type'])) {
3793
+			EE_Error::add_error(
3794
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3795
+				__FILE__,
3796
+				__FUNCTION__,
3797
+				__LINE__
3798
+			);
3799
+			$success = false;
3800
+		}
3801
+        
3802
+		if ( ! isset($this->_req_data['messenger'])) {
3803
+			EE_Error::add_error(
3804
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3805
+				__FILE__,
3806
+				__FUNCTION__,
3807
+				__LINE__
3808
+			);
3809
+			$success = false;
3810
+		}
3811
+        
3812
+		if ( ! isset($this->_req_data['status'])) {
3813
+			EE_Error::add_error(
3814
+				esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3815
+					'event_espresso'),
3816
+				__FILE__,
3817
+				__FUNCTION__,
3818
+				__LINE__
3819
+			);
3820
+			$success = false;
3821
+		}
3822
+        
3823
+        
3824
+		//do check to verify we have a valid status.
3825
+		$status = $this->_req_data['status'];
3826
+        
3827
+		if ($status !== 'activate' && $status !== 'deactivate') {
3828
+			EE_Error::add_error(
3829
+				sprintf(
3830
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3831
+					$this->_req_data['status']
3832
+				),
3833
+				__FILE__,
3834
+				__FUNCTION__,
3835
+				__LINE__
3836
+			);
3837
+			$success = false;
3838
+		}
3839
+        
3840
+        
3841
+		//do a nonce check here since we're not arriving via a normal route
3842
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3843
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3844
+        
3845
+		$this->_verify_nonce($nonce, $nonce_ref);
3846
+        
3847
+		if ($success) {
3848
+			//made it here? um, what are you waiting for then?
3849
+			$success = $status === 'deactivate'
3850
+				? $this->_deactivate_message_type_for_messenger(
3851
+					$this->_req_data['messenger'],
3852
+					$this->_req_data['message_type']
3853
+				)
3854
+				: $this->_activate_message_type_for_messenger(
3855
+					$this->_req_data['messenger'],
3856
+					$this->_req_data['message_type']
3857
+				);
3858
+		}
3859
+        
3860
+		$this->_template_args['success'] = $success;
3861
+		$this->_return_json();
3862
+	}
3863 3863
 
3864 3864
 
3865
-    /**
3866
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3867
-     *
3868
-     * @param string $messenger_name The name of the messenger being activated
3869
-     * @return bool
3870
-     * @throws DomainException
3871
-     * @throws EE_Error
3872
-     * @throws InvalidArgumentException
3873
-     * @throws ReflectionException
3874
-     * @throws InvalidDataTypeException
3875
-     * @throws InvalidInterfaceException
3876
-     */
3877
-    protected function _activate_messenger($messenger_name)
3878
-    {
3879
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3880
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3881
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3882
-            ? $active_messenger->get_default_message_types()
3883
-            : array();
3884
-        
3885
-        //ensure is active
3886
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3887
-        
3888
-        //set response_data for reload
3889
-        foreach ($message_types_to_activate as $message_type_name) {
3890
-            /** @var EE_message_type $message_type */
3891
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3892
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3893
-                    $messenger_name,
3894
-                    $message_type_name
3895
-                )
3896
-                && $message_type instanceof EE_message_type
3897
-            ) {
3898
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3899
-                if ($message_type->get_admin_settings_fields()) {
3900
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3901
-                }
3902
-            }
3903
-        }
3904
-        
3905
-        //add success message for activating messenger
3906
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3907
-        
3908
-    }
3865
+	/**
3866
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3867
+	 *
3868
+	 * @param string $messenger_name The name of the messenger being activated
3869
+	 * @return bool
3870
+	 * @throws DomainException
3871
+	 * @throws EE_Error
3872
+	 * @throws InvalidArgumentException
3873
+	 * @throws ReflectionException
3874
+	 * @throws InvalidDataTypeException
3875
+	 * @throws InvalidInterfaceException
3876
+	 */
3877
+	protected function _activate_messenger($messenger_name)
3878
+	{
3879
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3880
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3881
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3882
+			? $active_messenger->get_default_message_types()
3883
+			: array();
3884
+        
3885
+		//ensure is active
3886
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3887
+        
3888
+		//set response_data for reload
3889
+		foreach ($message_types_to_activate as $message_type_name) {
3890
+			/** @var EE_message_type $message_type */
3891
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3892
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger(
3893
+					$messenger_name,
3894
+					$message_type_name
3895
+				)
3896
+				&& $message_type instanceof EE_message_type
3897
+			) {
3898
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3899
+				if ($message_type->get_admin_settings_fields()) {
3900
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3901
+				}
3902
+			}
3903
+		}
3904
+        
3905
+		//add success message for activating messenger
3906
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3907
+        
3908
+	}
3909 3909
 
3910 3910
 
3911
-    /**
3912
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3913
-     *
3914
-     * @param string $messenger_name The name of the messenger being activated
3915
-     * @return bool
3916
-     * @throws DomainException
3917
-     * @throws EE_Error
3918
-     * @throws InvalidArgumentException
3919
-     * @throws ReflectionException
3920
-     * @throws InvalidDataTypeException
3921
-     * @throws InvalidInterfaceException
3922
-     */
3923
-    protected function _deactivate_messenger($messenger_name)
3924
-    {
3925
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3926
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3927
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3928
-        
3929
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3930
-    }
3911
+	/**
3912
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3913
+	 *
3914
+	 * @param string $messenger_name The name of the messenger being activated
3915
+	 * @return bool
3916
+	 * @throws DomainException
3917
+	 * @throws EE_Error
3918
+	 * @throws InvalidArgumentException
3919
+	 * @throws ReflectionException
3920
+	 * @throws InvalidDataTypeException
3921
+	 * @throws InvalidInterfaceException
3922
+	 */
3923
+	protected function _deactivate_messenger($messenger_name)
3924
+	{
3925
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3926
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3927
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3928
+        
3929
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3930
+	}
3931 3931
 
3932 3932
 
3933
-    /**
3934
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3935
-     *
3936
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3937
-     * @param string $message_type_name The name of the message type being activated for the messenger
3938
-     * @return bool
3939
-     * @throws DomainException
3940
-     * @throws EE_Error
3941
-     * @throws InvalidArgumentException
3942
-     * @throws ReflectionException
3943
-     * @throws InvalidDataTypeException
3944
-     * @throws InvalidInterfaceException
3945
-     */
3946
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3947
-    {
3948
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3949
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3950
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3951
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3952
-        
3953
-        //ensure is active
3954
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3955
-        
3956
-        //set response for load
3957
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3958
-            $message_type_name)
3959
-        ) {
3960
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3961
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3962
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3963
-            }
3964
-        }
3965
-        
3966
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3967
-            $message_type_to_activate);
3968
-    }
3933
+	/**
3934
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3935
+	 *
3936
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3937
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3938
+	 * @return bool
3939
+	 * @throws DomainException
3940
+	 * @throws EE_Error
3941
+	 * @throws InvalidArgumentException
3942
+	 * @throws ReflectionException
3943
+	 * @throws InvalidDataTypeException
3944
+	 * @throws InvalidInterfaceException
3945
+	 */
3946
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3947
+	{
3948
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3949
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3950
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3951
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3952
+        
3953
+		//ensure is active
3954
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3955
+        
3956
+		//set response for load
3957
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3958
+			$message_type_name)
3959
+		) {
3960
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3961
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3962
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3963
+			}
3964
+		}
3965
+        
3966
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3967
+			$message_type_to_activate);
3968
+	}
3969 3969
 
3970 3970
 
3971
-    /**
3972
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3973
-     *
3974
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3975
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3976
-     * @return bool
3977
-     * @throws DomainException
3978
-     * @throws EE_Error
3979
-     * @throws InvalidArgumentException
3980
-     * @throws ReflectionException
3981
-     * @throws InvalidDataTypeException
3982
-     * @throws InvalidInterfaceException
3983
-     */
3984
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3985
-    {
3986
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3987
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3988
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3989
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3990
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3991
-        
3992
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3993
-            $message_type_to_deactivate);
3994
-    }
3971
+	/**
3972
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3973
+	 *
3974
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3975
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3976
+	 * @return bool
3977
+	 * @throws DomainException
3978
+	 * @throws EE_Error
3979
+	 * @throws InvalidArgumentException
3980
+	 * @throws ReflectionException
3981
+	 * @throws InvalidDataTypeException
3982
+	 * @throws InvalidInterfaceException
3983
+	 */
3984
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3985
+	{
3986
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3987
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3988
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3989
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3990
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3991
+        
3992
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3993
+			$message_type_to_deactivate);
3994
+	}
3995 3995
     
3996 3996
     
3997
-    /**
3998
-     * This just initializes the defaults for activating messenger and message type responses.
3999
-     */
4000
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4001
-    {
4002
-        $this->_template_args['data']['active_mts'] = array();
4003
-        $this->_template_args['data']['mt_reload']  = array();
4004
-    }
3997
+	/**
3998
+	 * This just initializes the defaults for activating messenger and message type responses.
3999
+	 */
4000
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4001
+	{
4002
+		$this->_template_args['data']['active_mts'] = array();
4003
+		$this->_template_args['data']['mt_reload']  = array();
4004
+	}
4005 4005
 
4006 4006
 
4007
-    /**
4008
-     * Setup appropriate response for activating a messenger and/or message types
4009
-     *
4010
-     * @param EE_messenger         $messenger
4011
-     * @param EE_message_type|null $message_type
4012
-     * @return bool
4013
-     * @throws DomainException
4014
-     * @throws EE_Error
4015
-     * @throws InvalidArgumentException
4016
-     * @throws ReflectionException
4017
-     * @throws InvalidDataTypeException
4018
-     * @throws InvalidInterfaceException
4019
-     */
4020
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4021
-        $messenger,
4022
-        EE_Message_Type $message_type = null
4023
-    ) {
4024
-        //if $messenger isn't a valid messenger object then get out.
4025
-        if ( ! $messenger instanceof EE_Messenger) {
4026
-            EE_Error::add_error(
4027
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4028
-                __FILE__,
4029
-                __FUNCTION__,
4030
-                __LINE__
4031
-            );
4007
+	/**
4008
+	 * Setup appropriate response for activating a messenger and/or message types
4009
+	 *
4010
+	 * @param EE_messenger         $messenger
4011
+	 * @param EE_message_type|null $message_type
4012
+	 * @return bool
4013
+	 * @throws DomainException
4014
+	 * @throws EE_Error
4015
+	 * @throws InvalidArgumentException
4016
+	 * @throws ReflectionException
4017
+	 * @throws InvalidDataTypeException
4018
+	 * @throws InvalidInterfaceException
4019
+	 */
4020
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4021
+		$messenger,
4022
+		EE_Message_Type $message_type = null
4023
+	) {
4024
+		//if $messenger isn't a valid messenger object then get out.
4025
+		if ( ! $messenger instanceof EE_Messenger) {
4026
+			EE_Error::add_error(
4027
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4028
+				__FILE__,
4029
+				__FUNCTION__,
4030
+				__LINE__
4031
+			);
4032 4032
             
4033
-            return false;
4034
-        }
4035
-        //activated
4036
-        if ($this->_template_args['data']['active_mts']) {
4037
-            EE_Error::overwrite_success();
4038
-            //activated a message type with the messenger
4039
-            if ($message_type instanceof EE_message_type) {
4040
-                EE_Error::add_success(
4041
-                    sprintf(
4042
-                        esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4043
-                        ucwords($message_type->label['singular']),
4044
-                        ucwords($messenger->label['singular'])
4045
-                    )
4046
-                );
4033
+			return false;
4034
+		}
4035
+		//activated
4036
+		if ($this->_template_args['data']['active_mts']) {
4037
+			EE_Error::overwrite_success();
4038
+			//activated a message type with the messenger
4039
+			if ($message_type instanceof EE_message_type) {
4040
+				EE_Error::add_success(
4041
+					sprintf(
4042
+						esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
4043
+						ucwords($message_type->label['singular']),
4044
+						ucwords($messenger->label['singular'])
4045
+					)
4046
+				);
4047 4047
                 
4048
-                //if message type was invoice then let's make sure we activate the invoice payment method.
4049
-                if ($message_type->name === 'invoice') {
4050
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4051
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4052
-                    if ($pm instanceof EE_Payment_Method) {
4053
-                        EE_Error::add_attention(
4054
-                            esc_html__(
4055
-                                'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4056
-                                'event_espresso'
4057
-                            )
4058
-                        );
4059
-                    }
4060
-                }
4061
-                //just toggles the entire messenger
4062
-            } else {
4063
-                EE_Error::add_success(
4064
-                    sprintf(
4065
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4066
-                        ucwords($messenger->label['singular'])
4067
-                    )
4068
-                );
4069
-            }
4048
+				//if message type was invoice then let's make sure we activate the invoice payment method.
4049
+				if ($message_type->name === 'invoice') {
4050
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4051
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4052
+					if ($pm instanceof EE_Payment_Method) {
4053
+						EE_Error::add_attention(
4054
+							esc_html__(
4055
+								'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4056
+								'event_espresso'
4057
+							)
4058
+						);
4059
+					}
4060
+				}
4061
+				//just toggles the entire messenger
4062
+			} else {
4063
+				EE_Error::add_success(
4064
+					sprintf(
4065
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4066
+						ucwords($messenger->label['singular'])
4067
+					)
4068
+				);
4069
+			}
4070 4070
             
4071
-            return true;
4071
+			return true;
4072 4072
             
4073
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4074
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4075
-            //in which case we just give a success message for the messenger being successfully activated.
4076
-        } else {
4077
-            if ( ! $messenger->get_default_message_types()) {
4078
-                //messenger doesn't have any default message types so still a success.
4079
-                EE_Error::add_success(
4080
-                    sprintf(
4081
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4082
-                        ucwords($messenger->label['singular'])
4083
-                    )
4084
-                );
4073
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4074
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4075
+			//in which case we just give a success message for the messenger being successfully activated.
4076
+		} else {
4077
+			if ( ! $messenger->get_default_message_types()) {
4078
+				//messenger doesn't have any default message types so still a success.
4079
+				EE_Error::add_success(
4080
+					sprintf(
4081
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4082
+						ucwords($messenger->label['singular'])
4083
+					)
4084
+				);
4085 4085
                 
4086
-                return true;
4087
-            } else {
4088
-                EE_Error::add_error(
4089
-                    $message_type instanceof EE_message_type
4090
-                        ? sprintf(
4091
-                        esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4092
-                        ucwords($message_type->label['singular']),
4093
-                        ucwords($messenger->label['singular'])
4094
-                    )
4095
-                        : sprintf(
4096
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4097
-                        ucwords($messenger->label['singular'])
4098
-                    ),
4099
-                    __FILE__,
4100
-                    __FUNCTION__,
4101
-                    __LINE__
4102
-                );
4086
+				return true;
4087
+			} else {
4088
+				EE_Error::add_error(
4089
+					$message_type instanceof EE_message_type
4090
+						? sprintf(
4091
+						esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
4092
+						ucwords($message_type->label['singular']),
4093
+						ucwords($messenger->label['singular'])
4094
+					)
4095
+						: sprintf(
4096
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4097
+						ucwords($messenger->label['singular'])
4098
+					),
4099
+					__FILE__,
4100
+					__FUNCTION__,
4101
+					__LINE__
4102
+				);
4103 4103
                 
4104
-                return false;
4105
-            }
4106
-        }
4107
-    }
4104
+				return false;
4105
+			}
4106
+		}
4107
+	}
4108 4108
 
4109 4109
 
4110
-    /**
4111
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4112
-     *
4113
-     * @param EE_messenger         $messenger
4114
-     * @param EE_message_type|null $message_type
4115
-     * @return bool
4116
-     * @throws DomainException
4117
-     * @throws EE_Error
4118
-     * @throws InvalidArgumentException
4119
-     * @throws ReflectionException
4120
-     * @throws InvalidDataTypeException
4121
-     * @throws InvalidInterfaceException
4122
-     */
4123
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4124
-        $messenger,
4125
-        EE_message_type $message_type = null
4126
-    ) {
4127
-        EE_Error::overwrite_success();
4128
-        
4129
-        //if $messenger isn't a valid messenger object then get out.
4130
-        if ( ! $messenger instanceof EE_Messenger) {
4131
-            EE_Error::add_error(
4132
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4133
-                __FILE__,
4134
-                __FUNCTION__,
4135
-                __LINE__
4136
-            );
4110
+	/**
4111
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4112
+	 *
4113
+	 * @param EE_messenger         $messenger
4114
+	 * @param EE_message_type|null $message_type
4115
+	 * @return bool
4116
+	 * @throws DomainException
4117
+	 * @throws EE_Error
4118
+	 * @throws InvalidArgumentException
4119
+	 * @throws ReflectionException
4120
+	 * @throws InvalidDataTypeException
4121
+	 * @throws InvalidInterfaceException
4122
+	 */
4123
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4124
+		$messenger,
4125
+		EE_message_type $message_type = null
4126
+	) {
4127
+		EE_Error::overwrite_success();
4128
+        
4129
+		//if $messenger isn't a valid messenger object then get out.
4130
+		if ( ! $messenger instanceof EE_Messenger) {
4131
+			EE_Error::add_error(
4132
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4133
+				__FILE__,
4134
+				__FUNCTION__,
4135
+				__LINE__
4136
+			);
4137 4137
             
4138
-            return false;
4139
-        }
4140
-        
4141
-        if ($message_type instanceof EE_message_type) {
4142
-            $message_type_name = $message_type->name;
4143
-            EE_Error::add_success(
4144
-                sprintf(
4145
-                    esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4146
-                    ucwords($message_type->label['singular']),
4147
-                    ucwords($messenger->label['singular'])
4148
-                )
4149
-            );
4150
-        } else {
4151
-            $message_type_name = '';
4152
-            EE_Error::add_success(
4153
-                sprintf(
4154
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4155
-                    ucwords($messenger->label['singular'])
4156
-                )
4157
-            );
4158
-        }
4159
-        
4160
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4161
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4162
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4163
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4164
-            if ($count_updated > 0) {
4165
-                $msg = $message_type_name === 'invoice'
4166
-                    ? esc_html__(
4167
-                        'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4168
-                        'event_espresso'
4169
-                    )
4170
-                    : esc_html__(
4171
-                        'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4172
-                        'event_espresso'
4173
-                    );
4174
-                EE_Error::add_attention($msg);
4175
-            }
4176
-        }
4177
-        
4178
-        return true;
4179
-    }
4138
+			return false;
4139
+		}
4140
+        
4141
+		if ($message_type instanceof EE_message_type) {
4142
+			$message_type_name = $message_type->name;
4143
+			EE_Error::add_success(
4144
+				sprintf(
4145
+					esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
4146
+					ucwords($message_type->label['singular']),
4147
+					ucwords($messenger->label['singular'])
4148
+				)
4149
+			);
4150
+		} else {
4151
+			$message_type_name = '';
4152
+			EE_Error::add_success(
4153
+				sprintf(
4154
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4155
+					ucwords($messenger->label['singular'])
4156
+				)
4157
+			);
4158
+		}
4159
+        
4160
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4161
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4162
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4163
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4164
+			if ($count_updated > 0) {
4165
+				$msg = $message_type_name === 'invoice'
4166
+					? esc_html__(
4167
+						'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4168
+						'event_espresso'
4169
+					)
4170
+					: esc_html__(
4171
+						'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4172
+						'event_espresso'
4173
+					);
4174
+				EE_Error::add_attention($msg);
4175
+			}
4176
+		}
4177
+        
4178
+		return true;
4179
+	}
4180 4180
 
4181 4181
 
4182
-    /**
4183
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4184
-     *
4185
-     * @throws DomainException
4186
-     */
4187
-    public function update_mt_form()
4188
-    {
4189
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4190
-            EE_Error::add_error(
4191
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4192
-                __FILE__,
4193
-                __FUNCTION__,
4194
-                __LINE__
4195
-            );
4196
-            $this->_return_json();
4197
-        }
4198
-        
4199
-        $message_types = $this->get_installed_message_types();
4200
-        
4201
-        $message_type = $message_types[$this->_req_data['message_type']];
4202
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4203
-        
4204
-        $content                         = $this->_message_type_settings_content(
4205
-            $message_type,
4206
-            $messenger,
4207
-            true
4208
-        );
4209
-        $this->_template_args['success'] = true;
4210
-        $this->_template_args['content'] = $content;
4211
-        $this->_return_json();
4212
-    }
4182
+	/**
4183
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4184
+	 *
4185
+	 * @throws DomainException
4186
+	 */
4187
+	public function update_mt_form()
4188
+	{
4189
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4190
+			EE_Error::add_error(
4191
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4192
+				__FILE__,
4193
+				__FUNCTION__,
4194
+				__LINE__
4195
+			);
4196
+			$this->_return_json();
4197
+		}
4198
+        
4199
+		$message_types = $this->get_installed_message_types();
4200
+        
4201
+		$message_type = $message_types[$this->_req_data['message_type']];
4202
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4203
+        
4204
+		$content                         = $this->_message_type_settings_content(
4205
+			$message_type,
4206
+			$messenger,
4207
+			true
4208
+		);
4209
+		$this->_template_args['success'] = true;
4210
+		$this->_template_args['content'] = $content;
4211
+		$this->_return_json();
4212
+	}
4213 4213
     
4214 4214
     
4215
-    /**
4216
-     * this handles saving the settings for a messenger or message type
4217
-     *
4218
-     */
4219
-    public function save_settings()
4220
-    {
4221
-        if ( ! isset($this->_req_data['type'])) {
4222
-            EE_Error::add_error(
4223
-                esc_html__(
4224
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4225
-                    'event_espresso'
4226
-                ),
4227
-                __FILE__,
4228
-                __FUNCTION__,
4229
-                __LINE__
4230
-            );
4231
-            $this->_template_args['error'] = true;
4232
-            $this->_return_json();
4233
-        }
4234
-        
4235
-        
4236
-        if ($this->_req_data['type'] === 'messenger') {
4237
-            //this should be an array.
4238
-            $settings  = $this->_req_data['messenger_settings'];
4239
-            $messenger = $settings['messenger'];
4240
-            //let's setup the settings data
4241
-            foreach ($settings as $key => $value) {
4242
-                switch ($key) {
4243
-                    case 'messenger' :
4244
-                        unset($settings['messenger']);
4245
-                        break;
4246
-                    case 'message_types' :
4247
-                        unset($settings['message_types']);
4248
-                        break;
4249
-                    default :
4250
-                        $settings[$key] = $value;
4251
-                        break;
4252
-                }
4253
-            }
4254
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4255
-        } elseif ($this->_req_data['type'] === 'message_type') {
4256
-            $settings     = $this->_req_data['message_type_settings'];
4257
-            $messenger    = $settings['messenger'];
4258
-            $message_type = $settings['message_type'];
4215
+	/**
4216
+	 * this handles saving the settings for a messenger or message type
4217
+	 *
4218
+	 */
4219
+	public function save_settings()
4220
+	{
4221
+		if ( ! isset($this->_req_data['type'])) {
4222
+			EE_Error::add_error(
4223
+				esc_html__(
4224
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4225
+					'event_espresso'
4226
+				),
4227
+				__FILE__,
4228
+				__FUNCTION__,
4229
+				__LINE__
4230
+			);
4231
+			$this->_template_args['error'] = true;
4232
+			$this->_return_json();
4233
+		}
4234
+        
4235
+        
4236
+		if ($this->_req_data['type'] === 'messenger') {
4237
+			//this should be an array.
4238
+			$settings  = $this->_req_data['messenger_settings'];
4239
+			$messenger = $settings['messenger'];
4240
+			//let's setup the settings data
4241
+			foreach ($settings as $key => $value) {
4242
+				switch ($key) {
4243
+					case 'messenger' :
4244
+						unset($settings['messenger']);
4245
+						break;
4246
+					case 'message_types' :
4247
+						unset($settings['message_types']);
4248
+						break;
4249
+					default :
4250
+						$settings[$key] = $value;
4251
+						break;
4252
+				}
4253
+			}
4254
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4255
+		} elseif ($this->_req_data['type'] === 'message_type') {
4256
+			$settings     = $this->_req_data['message_type_settings'];
4257
+			$messenger    = $settings['messenger'];
4258
+			$message_type = $settings['message_type'];
4259 4259
             
4260
-            foreach ($settings as $key => $value) {
4261
-                switch ($key) {
4262
-                    case 'messenger' :
4263
-                        unset($settings['messenger']);
4264
-                        break;
4265
-                    case 'message_type' :
4266
-                        unset($settings['message_type']);
4267
-                        break;
4268
-                    default :
4269
-                        $settings[$key] = $value;
4270
-                        break;
4271
-                }
4272
-            }
4260
+			foreach ($settings as $key => $value) {
4261
+				switch ($key) {
4262
+					case 'messenger' :
4263
+						unset($settings['messenger']);
4264
+						break;
4265
+					case 'message_type' :
4266
+						unset($settings['message_type']);
4267
+						break;
4268
+					default :
4269
+						$settings[$key] = $value;
4270
+						break;
4271
+				}
4272
+			}
4273 4273
             
4274
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4275
-        }
4276
-        
4277
-        //okay we should have the data all setup.  Now we just update!
4278
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4279
-        
4280
-        if ($success) {
4281
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
4282
-        } else {
4283
-            EE_Error::add_error(
4284
-                esc_html__(
4285
-                    'Settings did not get updated',
4286
-                    'event_espresso'
4287
-                ),
4288
-                __FILE__,
4289
-                __FUNCTION__,
4290
-                __LINE__
4291
-            );
4292
-        }
4293
-        
4294
-        $this->_template_args['success'] = $success;
4295
-        $this->_return_json();
4296
-    }
4274
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4275
+		}
4276
+        
4277
+		//okay we should have the data all setup.  Now we just update!
4278
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4279
+        
4280
+		if ($success) {
4281
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
4282
+		} else {
4283
+			EE_Error::add_error(
4284
+				esc_html__(
4285
+					'Settings did not get updated',
4286
+					'event_espresso'
4287
+				),
4288
+				__FILE__,
4289
+				__FUNCTION__,
4290
+				__LINE__
4291
+			);
4292
+		}
4293
+        
4294
+		$this->_template_args['success'] = $success;
4295
+		$this->_return_json();
4296
+	}
4297 4297
     
4298 4298
     
4299 4299
     
4300 4300
     
4301
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4301
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4302 4302
     
4303 4303
     
4304
-    /**
4305
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4306
-     * However, this does not send immediately, it just queues for sending.
4307
-     *
4308
-     * @since 4.9.0
4309
-     */
4310
-    protected function _generate_now()
4311
-    {
4312
-        $msg_ids = $this->_get_msg_ids_from_request();
4313
-        EED_Messages::generate_now($msg_ids);
4314
-        $this->_redirect_after_action(false, '', '', array(), true);
4315
-    }
4304
+	/**
4305
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4306
+	 * However, this does not send immediately, it just queues for sending.
4307
+	 *
4308
+	 * @since 4.9.0
4309
+	 */
4310
+	protected function _generate_now()
4311
+	{
4312
+		$msg_ids = $this->_get_msg_ids_from_request();
4313
+		EED_Messages::generate_now($msg_ids);
4314
+		$this->_redirect_after_action(false, '', '', array(), true);
4315
+	}
4316 4316
     
4317 4317
     
4318
-    /**
4319
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4320
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4321
-     *
4322
-     * @since 4.9.0
4323
-     *
4324
-     */
4325
-    protected function _generate_and_send_now()
4326
-    {
4327
-        $this->_generate_now();
4328
-        $this->_send_now();
4329
-        $this->_redirect_after_action(false, '', '', array(), true);
4330
-    }
4318
+	/**
4319
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4320
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4321
+	 *
4322
+	 * @since 4.9.0
4323
+	 *
4324
+	 */
4325
+	protected function _generate_and_send_now()
4326
+	{
4327
+		$this->_generate_now();
4328
+		$this->_send_now();
4329
+		$this->_redirect_after_action(false, '', '', array(), true);
4330
+	}
4331 4331
     
4332 4332
     
4333
-    /**
4334
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4335
-     *
4336
-     * @since 4.9.0
4337
-     */
4338
-    protected function _queue_for_resending()
4339
-    {
4340
-        $msg_ids = $this->_get_msg_ids_from_request();
4341
-        EED_Messages::queue_for_resending($msg_ids);
4342
-        $this->_redirect_after_action(false, '', '', array(), true);
4343
-    }
4333
+	/**
4334
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4335
+	 *
4336
+	 * @since 4.9.0
4337
+	 */
4338
+	protected function _queue_for_resending()
4339
+	{
4340
+		$msg_ids = $this->_get_msg_ids_from_request();
4341
+		EED_Messages::queue_for_resending($msg_ids);
4342
+		$this->_redirect_after_action(false, '', '', array(), true);
4343
+	}
4344 4344
     
4345 4345
     
4346
-    /**
4347
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4348
-     *
4349
-     * @since 4.9.0
4350
-     */
4351
-    protected function _send_now()
4352
-    {
4353
-        $msg_ids = $this->_get_msg_ids_from_request();
4354
-        EED_Messages::send_now($msg_ids);
4355
-        $this->_redirect_after_action(false, '', '', array(), true);
4356
-    }
4346
+	/**
4347
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4348
+	 *
4349
+	 * @since 4.9.0
4350
+	 */
4351
+	protected function _send_now()
4352
+	{
4353
+		$msg_ids = $this->_get_msg_ids_from_request();
4354
+		EED_Messages::send_now($msg_ids);
4355
+		$this->_redirect_after_action(false, '', '', array(), true);
4356
+	}
4357 4357
 
4358 4358
 
4359
-    /**
4360
-     * Deletes EE_messages for IDs in the request.
4361
-     *
4362
-     * @since 4.9.0
4363
-     * @throws EE_Error
4364
-     * @throws InvalidDataTypeException
4365
-     * @throws InvalidInterfaceException
4366
-     * @throws InvalidArgumentException
4367
-     */
4368
-    protected function _delete_ee_messages()
4369
-    {
4370
-        $msg_ids       = $this->_get_msg_ids_from_request();
4371
-        $deleted_count = 0;
4372
-        foreach ($msg_ids as $msg_id) {
4373
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4374
-                $deleted_count++;
4375
-            }
4376
-        }
4377
-        if ($deleted_count) {
4378
-            $this->_redirect_after_action(
4379
-                true,
4380
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
4381
-                esc_html__('deleted', 'event_espresso')
4382
-            );
4383
-        } else {
4384
-            EE_Error::add_error(
4385
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4386
-                __FILE__, __FUNCTION__, __LINE__
4387
-            );
4388
-            $this->_redirect_after_action(false, '', '', array(), true);
4389
-        }
4390
-    }
4359
+	/**
4360
+	 * Deletes EE_messages for IDs in the request.
4361
+	 *
4362
+	 * @since 4.9.0
4363
+	 * @throws EE_Error
4364
+	 * @throws InvalidDataTypeException
4365
+	 * @throws InvalidInterfaceException
4366
+	 * @throws InvalidArgumentException
4367
+	 */
4368
+	protected function _delete_ee_messages()
4369
+	{
4370
+		$msg_ids       = $this->_get_msg_ids_from_request();
4371
+		$deleted_count = 0;
4372
+		foreach ($msg_ids as $msg_id) {
4373
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4374
+				$deleted_count++;
4375
+			}
4376
+		}
4377
+		if ($deleted_count) {
4378
+			$this->_redirect_after_action(
4379
+				true,
4380
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
4381
+				esc_html__('deleted', 'event_espresso')
4382
+			);
4383
+		} else {
4384
+			EE_Error::add_error(
4385
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4386
+				__FILE__, __FUNCTION__, __LINE__
4387
+			);
4388
+			$this->_redirect_after_action(false, '', '', array(), true);
4389
+		}
4390
+	}
4391 4391
     
4392 4392
     
4393
-    /**
4394
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4395
-     * @since 4.9.0
4396
-     * @return array
4397
-     */
4398
-    protected function _get_msg_ids_from_request()
4399
-    {
4400
-        if ( ! isset($this->_req_data['MSG_ID'])) {
4401
-            return array();
4402
-        }
4403
-        
4404
-        return is_array($this->_req_data['MSG_ID'])
4405
-            ? array_keys($this->_req_data['MSG_ID'])
4406
-            : array($this->_req_data['MSG_ID']);
4407
-    }
4393
+	/**
4394
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4395
+	 * @since 4.9.0
4396
+	 * @return array
4397
+	 */
4398
+	protected function _get_msg_ids_from_request()
4399
+	{
4400
+		if ( ! isset($this->_req_data['MSG_ID'])) {
4401
+			return array();
4402
+		}
4403
+        
4404
+		return is_array($this->_req_data['MSG_ID'])
4405
+			? array_keys($this->_req_data['MSG_ID'])
4406
+			: array($this->_req_data['MSG_ID']);
4407
+	}
4408 4408
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Message_Template_Group.class.php 2 patches
Indentation   +482 added lines, -482 removed lines patch added patch discarded remove patch
@@ -15,486 +15,486 @@
 block discarded – undo
15 15
 class EE_Message_Template_Group extends EE_Soft_Delete_Base_Class
16 16
 {
17 17
 
18
-    /**
19
-     * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not.
20
-     */
21
-    const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_';
22
-
23
-    /**
24
-     * @param array  $props_n_values
25
-     * @param string $timezone
26
-     * @return EE_Message_Template_Group|mixed
27
-     * @throws EE_Error
28
-     */
29
-    public static function new_instance($props_n_values = array(), $timezone = '')
30
-    {
31
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
32
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone);
33
-    }
34
-
35
-
36
-    /**
37
-     * @param array  $props_n_values
38
-     * @param string $timezone
39
-     * @return EE_Message_Template_Group
40
-     */
41
-    public static function new_instance_from_db($props_n_values = array(), $timezone = '')
42
-    {
43
-        return new self($props_n_values, true, $timezone);
44
-    }
45
-
46
-
47
-    /**
48
-     * @param bool $message_type
49
-     * @throws EE_Error
50
-     */
51
-    public function set_message_type($message_type = false)
52
-    {
53
-        if (! $message_type) {
54
-            throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso'));
55
-        }
56
-        $this->set('MTP_message_type', $message_type);
57
-    }
58
-
59
-
60
-    /**
61
-     * @param bool $messenger
62
-     * @throws EE_Error
63
-     */
64
-    public function set_messenger($messenger = false)
65
-    {
66
-        if (! $messenger) {
67
-            throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso'));
68
-        }
69
-        $this->set('MTP_messenger', $messenger);
70
-    }
71
-
72
-
73
-    /**
74
-     * @param bool $GRP_ID
75
-     * @throws EE_Error
76
-     */
77
-    public function set_group_template_id($GRP_ID = false)
78
-    {
79
-        if (! $GRP_ID) {
80
-            throw new EE_Error(
81
-                esc_html__(
82
-                    'Missing required value for the message template group id',
83
-                    'event_espresso'
84
-                )
85
-            );
86
-        }
87
-        $this->set('GRP_ID', $GRP_ID);
88
-    }
89
-
90
-
91
-    /**
92
-     * get Group ID
93
-     *
94
-     * @access public
95
-     * @return int
96
-     * @throws EE_Error
97
-     */
98
-    public function GRP_ID()
99
-    {
100
-        return $this->get('GRP_ID');
101
-    }
102
-
103
-
104
-    /**
105
-     * get User ID
106
-     *
107
-     * @access public
108
-     * @return int
109
-     * @throws EE_Error
110
-     */
111
-    public function user()
112
-    {
113
-        $user_id = $this->get('MTP_user_id');
114
-        return empty($user_id) ? get_current_user_id() : $user_id;
115
-    }
116
-
117
-
118
-    /**
119
-     * Wrapper for the user function() (preserve backward compat)
120
-     *
121
-     * @since  4.5.0
122
-     * @return int
123
-     * @throws EE_Error
124
-     */
125
-    public function wp_user()
126
-    {
127
-        return $this->user();
128
-    }
129
-
130
-
131
-    /**
132
-     * This simply returns a count of all related events to this message template group
133
-     *
134
-     * @return int
135
-     */
136
-    public function count_events()
137
-    {
138
-        return $this->count_related('Event');
139
-    }
140
-
141
-
142
-    /**
143
-     * returns the name saved in the db for this template
144
-     *
145
-     * @return string
146
-     * @throws EE_Error
147
-     */
148
-    public function name()
149
-    {
150
-        return $this->get('MTP_name');
151
-    }
152
-
153
-
154
-    /**
155
-     * Returns the description saved in the db for this template group
156
-     *
157
-     * @return string
158
-     * @throws EE_Error
159
-     */
160
-    public function description()
161
-    {
162
-        return $this->get('MTP_description');
163
-    }
164
-
165
-
166
-    /**
167
-     * returns all related EE_Message_Template objects
168
-     *
169
-     * @param  array $query_params like EEM_Base::get_all()
170
-     * @return EE_Message_Template[]
171
-     * @throws EE_Error
172
-     */
173
-    public function message_templates($query_params = array())
174
-    {
175
-        return $this->get_many_related('Message_Template', $query_params);
176
-    }
177
-
178
-
179
-    /**
180
-     * get Message Messenger
181
-     *
182
-     * @access public
183
-     * @return string
184
-     * @throws EE_Error
185
-     */
186
-    public function messenger()
187
-    {
188
-        return $this->get('MTP_messenger');
189
-    }
190
-
191
-
192
-    /**
193
-     * get Message Messenger OBJECT
194
-     * If an attempt to get the corresponding messenger object fails, then we set this message
195
-     * template group to inactive, and save to db.  Then return null so client code can handle
196
-     * appropriately.
197
-     *
198
-     * @return EE_messenger
199
-     * @throws EE_Error
200
-     */
201
-    public function messenger_obj()
202
-    {
203
-        $messenger = $this->messenger();
204
-        try {
205
-            $messenger = EEH_MSG_Template::messenger_obj($messenger);
206
-        } catch (EE_Error $e) {
207
-            //if an exception was thrown then let's deactivate this message template group because it means there is no
208
-            // class for this messenger in this group.
209
-            $this->set('MTP_is_active', false);
210
-            $this->save();
211
-            return null;
212
-        }
213
-        return $messenger;
214
-    }
215
-
216
-
217
-    /**
218
-     * get Message Type
219
-     *
220
-     * @access public
221
-     * @return string
222
-     * @throws EE_Error
223
-     */
224
-    public function message_type()
225
-    {
226
-        return $this->get('MTP_message_type');
227
-    }
228
-
229
-
230
-    /**
231
-     * get Message type OBJECT
232
-     * If an attempt to get the corresponding message type object fails, then we set this message
233
-     * template group to inactive, and save to db.  Then return null so client code can handle
234
-     * appropriately.
235
-     *
236
-     * @throws EE_Error
237
-     * @return EE_message_type|false if exception thrown.
238
-     */
239
-    public function message_type_obj()
240
-    {
241
-        $message_type = $this->message_type();
242
-        try {
243
-            $message_type = EEH_MSG_Template::message_type_obj($message_type);
244
-        } catch (EE_Error $e) {
245
-            //if an exception was thrown then let's deactivate this message template group because it means there is no
246
-            // class for the message type in this group.
247
-            $this->set('MTP_is_active', false);
248
-            $this->save();
249
-            return null;
250
-        }
251
-        return $message_type;
252
-    }
253
-
254
-
255
-    /**
256
-     * @return array
257
-     * @throws EE_Error
258
-     */
259
-    public function contexts_config()
260
-    {
261
-        return $this->message_type_obj()->get_contexts();
262
-    }
263
-
264
-
265
-    /**
266
-     * This returns the context_label for contexts as set in the message type object
267
-     * Note this is an array with singular and plural keys
268
-     *
269
-     * @access public
270
-     * @return array labels for "context"
271
-     * @throws EE_Error
272
-     */
273
-    public function context_label()
274
-    {
275
-        $obj = $this->message_type_obj();
276
-        return $obj->get_context_label();
277
-    }
278
-
279
-
280
-    /**
281
-     * This returns an array of EE_Message_Template objects indexed by context and field.
282
-     *
283
-     * @return array ()
284
-     * @throws EE_Error
285
-     */
286
-    public function context_templates()
287
-    {
288
-        $mtps_arr = array();
289
-        $mtps     = $this->get_many_related('Message_Template');
290
-        if (empty($mtps)) {
291
-            return array();
292
-        }
293
-        //note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field.
294
-        foreach ($mtps as $mtp) {
295
-            $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp;
296
-        }
297
-        return $mtps_arr;
298
-    }
299
-
300
-
301
-    /**
302
-     * this returns if the template group this template belongs to is global
303
-     *
304
-     * @return bool true if it is, false if it isn't
305
-     * @throws EE_Error
306
-     */
307
-    public function is_global()
308
-    {
309
-        return $this->get('MTP_is_global');
310
-    }
311
-
312
-
313
-    /**
314
-     * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
315
-     *
316
-     * @return bool true if it is, false if it isn't
317
-     * @throws EE_Error
318
-     */
319
-    public function is_active()
320
-    {
321
-        return $this->get('MTP_is_active');
322
-    }
323
-
324
-
325
-    /**
326
-     * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
327
-     * this template.
328
-     *
329
-     * @since 4.3.0
330
-     * @uses  EEH_MSG_Template::get_shortcodes()
331
-     * @param string $context what context we're going to return shortcodes for
332
-     * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
333
-     *                        to be returned.
334
-     * @param bool   $merged  If TRUE then we don't return shortcodes indexed by field but instead an array of the
335
-     *                        unique shortcodes for all the given (or all) fields.
336
-     * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
337
-     *                        shortcodes found.
338
-     * @throws EE_Error
339
-     */
340
-    public function get_shortcodes($context, $fields = array(), $merged = false)
341
-    {
342
-        $messenger    = $this->messenger();
343
-        $message_type = $this->message_type();
344
-        return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged);
345
-    }
346
-
347
-
348
-    /**
349
-     * This just gets the template pack name assigned to this message template group.  If it's not set, then we just
350
-     * use the default template pack.
351
-     *
352
-     * @since 4.5.0
353
-     * @return string
354
-     * @throws EE_Error
355
-     */
356
-    public function get_template_pack_name()
357
-    {
358
-        return $this->get_extra_meta('MTP_template_pack', true, 'default');
359
-    }
360
-
361
-
362
-    /**
363
-     * This returns the specific template pack object referenced by the template pack name attached to this message
364
-     * template group.  If no template pack is assigned then the default template pack is retrieved.
365
-     *
366
-     * @since 4.5.0
367
-     * @return EE_Messages_Template_Pack
368
-     * @throws EE_Error
369
-     * @throws InvalidArgumentException
370
-     * @throws ReflectionException
371
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
372
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
373
-     */
374
-    public function get_template_pack()
375
-    {
376
-        $pack_name = $this->get_template_pack_name();
377
-        EE_Registry::instance()->load_helper('MSG_Template');
378
-        return EEH_MSG_Template::get_template_pack($pack_name);
379
-    }
380
-
381
-
382
-    /**
383
-     * This retrieves the template variation assigned to this message template group.  If it's not set, then we just
384
-     * use the default template variation.
385
-     *
386
-     * @since 4.5.0
387
-     * @return string
388
-     * @throws EE_Error
389
-     */
390
-    public function get_template_pack_variation()
391
-    {
392
-        return $this->get_extra_meta('MTP_variation', true, 'default');
393
-    }
394
-
395
-
396
-    /**
397
-     * This just sets the template pack name attached to this message template group.
398
-     *
399
-     * @since 4.5.0
400
-     * @param string $template_pack_name What message template pack is assigned.
401
-     * @return int
402
-     * @throws EE_Error
403
-     */
404
-    public function set_template_pack_name($template_pack_name)
405
-    {
406
-        return $this->update_extra_meta('MTP_template_pack', $template_pack_name);
407
-    }
408
-
409
-
410
-    /**
411
-     * This just sets the template pack variation attached to this message template group.
412
-     *
413
-     * @since 4.5.0
414
-     * @param string $variation What variation is being set on the message template group.
415
-     * @return int
416
-     * @throws EE_Error
417
-     */
418
-    public function set_template_pack_variation($variation)
419
-    {
420
-        return $this->update_extra_meta('MTP_variation', $variation);
421
-    }
422
-
423
-
424
-    /**
425
-     * Deactivates the given context.
426
-     *
427
-     * @param $context
428
-     * @return bool|int
429
-     * @throws EE_Error
430
-     * @throws InvalidIdentifierException
431
-     */
432
-    public function deactivate_context($context)
433
-    {
434
-        $this->validate_context($context);
435
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false);
436
-    }
437
-
438
-
439
-    /**
440
-     * Activates the given context.
441
-     *
442
-     * @param $context
443
-     * @return bool|int
444
-     * @throws EE_Error
445
-     * @throws InvalidIdentifierException
446
-     */
447
-    public function activate_context($context)
448
-    {
449
-        $this->validate_context($context);
450
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true);
451
-    }
452
-
453
-
454
-    /**
455
-     * Returns whether the context is active or not.
456
-     * Note, this will default to true if the extra meta record doesn't exist.
457
-     * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field
458
-     * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of
459
-     * whether a context is "active" or not.
460
-     *
461
-     * @param $context
462
-     * @return bool
463
-     * @throws EE_Error
464
-     * @throws InvalidIdentifierException
465
-     */
466
-    public function is_context_active($context)
467
-    {
468
-        $this->validate_context($context);
469
-        return filter_var(
470
-            $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true),
471
-            FILTER_VALIDATE_BOOLEAN
472
-        );
473
-    }
474
-
475
-
476
-    /**
477
-     * Validates the incoming context to verify it matches a registered context for the related message type.
478
-     * @param string $context
479
-     * @throws EE_Error
480
-     * @throws InvalidIdentifierException
481
-     */
482
-    public function validate_context($context)
483
-    {
484
-        $contexts = $this->contexts_config();
485
-        if (! isset($contexts[$context])) {
486
-            throw new InvalidIdentifierException(
487
-                '',
488
-                '',
489
-                sprintf(
490
-                    esc_html__(
491
-                        'An invalid string identifying a context was provided.  "%1$s" was received, and one of "%2$s" was expected.',
492
-                        'event_espresso'
493
-                    ),
494
-                    $context,
495
-                    implode(',', array_keys($contexts))
496
-                )
497
-            );
498
-        }
499
-    }
18
+	/**
19
+	 * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not.
20
+	 */
21
+	const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_';
22
+
23
+	/**
24
+	 * @param array  $props_n_values
25
+	 * @param string $timezone
26
+	 * @return EE_Message_Template_Group|mixed
27
+	 * @throws EE_Error
28
+	 */
29
+	public static function new_instance($props_n_values = array(), $timezone = '')
30
+	{
31
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
32
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone);
33
+	}
34
+
35
+
36
+	/**
37
+	 * @param array  $props_n_values
38
+	 * @param string $timezone
39
+	 * @return EE_Message_Template_Group
40
+	 */
41
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '')
42
+	{
43
+		return new self($props_n_values, true, $timezone);
44
+	}
45
+
46
+
47
+	/**
48
+	 * @param bool $message_type
49
+	 * @throws EE_Error
50
+	 */
51
+	public function set_message_type($message_type = false)
52
+	{
53
+		if (! $message_type) {
54
+			throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso'));
55
+		}
56
+		$this->set('MTP_message_type', $message_type);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @param bool $messenger
62
+	 * @throws EE_Error
63
+	 */
64
+	public function set_messenger($messenger = false)
65
+	{
66
+		if (! $messenger) {
67
+			throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso'));
68
+		}
69
+		$this->set('MTP_messenger', $messenger);
70
+	}
71
+
72
+
73
+	/**
74
+	 * @param bool $GRP_ID
75
+	 * @throws EE_Error
76
+	 */
77
+	public function set_group_template_id($GRP_ID = false)
78
+	{
79
+		if (! $GRP_ID) {
80
+			throw new EE_Error(
81
+				esc_html__(
82
+					'Missing required value for the message template group id',
83
+					'event_espresso'
84
+				)
85
+			);
86
+		}
87
+		$this->set('GRP_ID', $GRP_ID);
88
+	}
89
+
90
+
91
+	/**
92
+	 * get Group ID
93
+	 *
94
+	 * @access public
95
+	 * @return int
96
+	 * @throws EE_Error
97
+	 */
98
+	public function GRP_ID()
99
+	{
100
+		return $this->get('GRP_ID');
101
+	}
102
+
103
+
104
+	/**
105
+	 * get User ID
106
+	 *
107
+	 * @access public
108
+	 * @return int
109
+	 * @throws EE_Error
110
+	 */
111
+	public function user()
112
+	{
113
+		$user_id = $this->get('MTP_user_id');
114
+		return empty($user_id) ? get_current_user_id() : $user_id;
115
+	}
116
+
117
+
118
+	/**
119
+	 * Wrapper for the user function() (preserve backward compat)
120
+	 *
121
+	 * @since  4.5.0
122
+	 * @return int
123
+	 * @throws EE_Error
124
+	 */
125
+	public function wp_user()
126
+	{
127
+		return $this->user();
128
+	}
129
+
130
+
131
+	/**
132
+	 * This simply returns a count of all related events to this message template group
133
+	 *
134
+	 * @return int
135
+	 */
136
+	public function count_events()
137
+	{
138
+		return $this->count_related('Event');
139
+	}
140
+
141
+
142
+	/**
143
+	 * returns the name saved in the db for this template
144
+	 *
145
+	 * @return string
146
+	 * @throws EE_Error
147
+	 */
148
+	public function name()
149
+	{
150
+		return $this->get('MTP_name');
151
+	}
152
+
153
+
154
+	/**
155
+	 * Returns the description saved in the db for this template group
156
+	 *
157
+	 * @return string
158
+	 * @throws EE_Error
159
+	 */
160
+	public function description()
161
+	{
162
+		return $this->get('MTP_description');
163
+	}
164
+
165
+
166
+	/**
167
+	 * returns all related EE_Message_Template objects
168
+	 *
169
+	 * @param  array $query_params like EEM_Base::get_all()
170
+	 * @return EE_Message_Template[]
171
+	 * @throws EE_Error
172
+	 */
173
+	public function message_templates($query_params = array())
174
+	{
175
+		return $this->get_many_related('Message_Template', $query_params);
176
+	}
177
+
178
+
179
+	/**
180
+	 * get Message Messenger
181
+	 *
182
+	 * @access public
183
+	 * @return string
184
+	 * @throws EE_Error
185
+	 */
186
+	public function messenger()
187
+	{
188
+		return $this->get('MTP_messenger');
189
+	}
190
+
191
+
192
+	/**
193
+	 * get Message Messenger OBJECT
194
+	 * If an attempt to get the corresponding messenger object fails, then we set this message
195
+	 * template group to inactive, and save to db.  Then return null so client code can handle
196
+	 * appropriately.
197
+	 *
198
+	 * @return EE_messenger
199
+	 * @throws EE_Error
200
+	 */
201
+	public function messenger_obj()
202
+	{
203
+		$messenger = $this->messenger();
204
+		try {
205
+			$messenger = EEH_MSG_Template::messenger_obj($messenger);
206
+		} catch (EE_Error $e) {
207
+			//if an exception was thrown then let's deactivate this message template group because it means there is no
208
+			// class for this messenger in this group.
209
+			$this->set('MTP_is_active', false);
210
+			$this->save();
211
+			return null;
212
+		}
213
+		return $messenger;
214
+	}
215
+
216
+
217
+	/**
218
+	 * get Message Type
219
+	 *
220
+	 * @access public
221
+	 * @return string
222
+	 * @throws EE_Error
223
+	 */
224
+	public function message_type()
225
+	{
226
+		return $this->get('MTP_message_type');
227
+	}
228
+
229
+
230
+	/**
231
+	 * get Message type OBJECT
232
+	 * If an attempt to get the corresponding message type object fails, then we set this message
233
+	 * template group to inactive, and save to db.  Then return null so client code can handle
234
+	 * appropriately.
235
+	 *
236
+	 * @throws EE_Error
237
+	 * @return EE_message_type|false if exception thrown.
238
+	 */
239
+	public function message_type_obj()
240
+	{
241
+		$message_type = $this->message_type();
242
+		try {
243
+			$message_type = EEH_MSG_Template::message_type_obj($message_type);
244
+		} catch (EE_Error $e) {
245
+			//if an exception was thrown then let's deactivate this message template group because it means there is no
246
+			// class for the message type in this group.
247
+			$this->set('MTP_is_active', false);
248
+			$this->save();
249
+			return null;
250
+		}
251
+		return $message_type;
252
+	}
253
+
254
+
255
+	/**
256
+	 * @return array
257
+	 * @throws EE_Error
258
+	 */
259
+	public function contexts_config()
260
+	{
261
+		return $this->message_type_obj()->get_contexts();
262
+	}
263
+
264
+
265
+	/**
266
+	 * This returns the context_label for contexts as set in the message type object
267
+	 * Note this is an array with singular and plural keys
268
+	 *
269
+	 * @access public
270
+	 * @return array labels for "context"
271
+	 * @throws EE_Error
272
+	 */
273
+	public function context_label()
274
+	{
275
+		$obj = $this->message_type_obj();
276
+		return $obj->get_context_label();
277
+	}
278
+
279
+
280
+	/**
281
+	 * This returns an array of EE_Message_Template objects indexed by context and field.
282
+	 *
283
+	 * @return array ()
284
+	 * @throws EE_Error
285
+	 */
286
+	public function context_templates()
287
+	{
288
+		$mtps_arr = array();
289
+		$mtps     = $this->get_many_related('Message_Template');
290
+		if (empty($mtps)) {
291
+			return array();
292
+		}
293
+		//note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field.
294
+		foreach ($mtps as $mtp) {
295
+			$mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp;
296
+		}
297
+		return $mtps_arr;
298
+	}
299
+
300
+
301
+	/**
302
+	 * this returns if the template group this template belongs to is global
303
+	 *
304
+	 * @return bool true if it is, false if it isn't
305
+	 * @throws EE_Error
306
+	 */
307
+	public function is_global()
308
+	{
309
+		return $this->get('MTP_is_global');
310
+	}
311
+
312
+
313
+	/**
314
+	 * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
315
+	 *
316
+	 * @return bool true if it is, false if it isn't
317
+	 * @throws EE_Error
318
+	 */
319
+	public function is_active()
320
+	{
321
+		return $this->get('MTP_is_active');
322
+	}
323
+
324
+
325
+	/**
326
+	 * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
327
+	 * this template.
328
+	 *
329
+	 * @since 4.3.0
330
+	 * @uses  EEH_MSG_Template::get_shortcodes()
331
+	 * @param string $context what context we're going to return shortcodes for
332
+	 * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
333
+	 *                        to be returned.
334
+	 * @param bool   $merged  If TRUE then we don't return shortcodes indexed by field but instead an array of the
335
+	 *                        unique shortcodes for all the given (or all) fields.
336
+	 * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
337
+	 *                        shortcodes found.
338
+	 * @throws EE_Error
339
+	 */
340
+	public function get_shortcodes($context, $fields = array(), $merged = false)
341
+	{
342
+		$messenger    = $this->messenger();
343
+		$message_type = $this->message_type();
344
+		return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged);
345
+	}
346
+
347
+
348
+	/**
349
+	 * This just gets the template pack name assigned to this message template group.  If it's not set, then we just
350
+	 * use the default template pack.
351
+	 *
352
+	 * @since 4.5.0
353
+	 * @return string
354
+	 * @throws EE_Error
355
+	 */
356
+	public function get_template_pack_name()
357
+	{
358
+		return $this->get_extra_meta('MTP_template_pack', true, 'default');
359
+	}
360
+
361
+
362
+	/**
363
+	 * This returns the specific template pack object referenced by the template pack name attached to this message
364
+	 * template group.  If no template pack is assigned then the default template pack is retrieved.
365
+	 *
366
+	 * @since 4.5.0
367
+	 * @return EE_Messages_Template_Pack
368
+	 * @throws EE_Error
369
+	 * @throws InvalidArgumentException
370
+	 * @throws ReflectionException
371
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
372
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
373
+	 */
374
+	public function get_template_pack()
375
+	{
376
+		$pack_name = $this->get_template_pack_name();
377
+		EE_Registry::instance()->load_helper('MSG_Template');
378
+		return EEH_MSG_Template::get_template_pack($pack_name);
379
+	}
380
+
381
+
382
+	/**
383
+	 * This retrieves the template variation assigned to this message template group.  If it's not set, then we just
384
+	 * use the default template variation.
385
+	 *
386
+	 * @since 4.5.0
387
+	 * @return string
388
+	 * @throws EE_Error
389
+	 */
390
+	public function get_template_pack_variation()
391
+	{
392
+		return $this->get_extra_meta('MTP_variation', true, 'default');
393
+	}
394
+
395
+
396
+	/**
397
+	 * This just sets the template pack name attached to this message template group.
398
+	 *
399
+	 * @since 4.5.0
400
+	 * @param string $template_pack_name What message template pack is assigned.
401
+	 * @return int
402
+	 * @throws EE_Error
403
+	 */
404
+	public function set_template_pack_name($template_pack_name)
405
+	{
406
+		return $this->update_extra_meta('MTP_template_pack', $template_pack_name);
407
+	}
408
+
409
+
410
+	/**
411
+	 * This just sets the template pack variation attached to this message template group.
412
+	 *
413
+	 * @since 4.5.0
414
+	 * @param string $variation What variation is being set on the message template group.
415
+	 * @return int
416
+	 * @throws EE_Error
417
+	 */
418
+	public function set_template_pack_variation($variation)
419
+	{
420
+		return $this->update_extra_meta('MTP_variation', $variation);
421
+	}
422
+
423
+
424
+	/**
425
+	 * Deactivates the given context.
426
+	 *
427
+	 * @param $context
428
+	 * @return bool|int
429
+	 * @throws EE_Error
430
+	 * @throws InvalidIdentifierException
431
+	 */
432
+	public function deactivate_context($context)
433
+	{
434
+		$this->validate_context($context);
435
+		return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false);
436
+	}
437
+
438
+
439
+	/**
440
+	 * Activates the given context.
441
+	 *
442
+	 * @param $context
443
+	 * @return bool|int
444
+	 * @throws EE_Error
445
+	 * @throws InvalidIdentifierException
446
+	 */
447
+	public function activate_context($context)
448
+	{
449
+		$this->validate_context($context);
450
+		return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true);
451
+	}
452
+
453
+
454
+	/**
455
+	 * Returns whether the context is active or not.
456
+	 * Note, this will default to true if the extra meta record doesn't exist.
457
+	 * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field
458
+	 * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of
459
+	 * whether a context is "active" or not.
460
+	 *
461
+	 * @param $context
462
+	 * @return bool
463
+	 * @throws EE_Error
464
+	 * @throws InvalidIdentifierException
465
+	 */
466
+	public function is_context_active($context)
467
+	{
468
+		$this->validate_context($context);
469
+		return filter_var(
470
+			$this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true),
471
+			FILTER_VALIDATE_BOOLEAN
472
+		);
473
+	}
474
+
475
+
476
+	/**
477
+	 * Validates the incoming context to verify it matches a registered context for the related message type.
478
+	 * @param string $context
479
+	 * @throws EE_Error
480
+	 * @throws InvalidIdentifierException
481
+	 */
482
+	public function validate_context($context)
483
+	{
484
+		$contexts = $this->contexts_config();
485
+		if (! isset($contexts[$context])) {
486
+			throw new InvalidIdentifierException(
487
+				'',
488
+				'',
489
+				sprintf(
490
+					esc_html__(
491
+						'An invalid string identifying a context was provided.  "%1$s" was received, and one of "%2$s" was expected.',
492
+						'event_espresso'
493
+					),
494
+					$context,
495
+					implode(',', array_keys($contexts))
496
+				)
497
+			);
498
+		}
499
+	}
500 500
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      */
51 51
     public function set_message_type($message_type = false)
52 52
     {
53
-        if (! $message_type) {
53
+        if ( ! $message_type) {
54 54
             throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso'));
55 55
         }
56 56
         $this->set('MTP_message_type', $message_type);
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public function set_messenger($messenger = false)
65 65
     {
66
-        if (! $messenger) {
66
+        if ( ! $messenger) {
67 67
             throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso'));
68 68
         }
69 69
         $this->set('MTP_messenger', $messenger);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function set_group_template_id($GRP_ID = false)
78 78
     {
79
-        if (! $GRP_ID) {
79
+        if ( ! $GRP_ID) {
80 80
             throw new EE_Error(
81 81
                 esc_html__(
82 82
                     'Missing required value for the message template group id',
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
     public function deactivate_context($context)
433 433
     {
434 434
         $this->validate_context($context);
435
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false);
435
+        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, false);
436 436
     }
437 437
 
438 438
 
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
     public function activate_context($context)
448 448
     {
449 449
         $this->validate_context($context);
450
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true);
450
+        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true);
451 451
     }
452 452
 
453 453
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
     {
468 468
         $this->validate_context($context);
469 469
         return filter_var(
470
-            $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true),
470
+            $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true, true),
471 471
             FILTER_VALIDATE_BOOLEAN
472 472
         );
473 473
     }
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
     public function validate_context($context)
483 483
     {
484 484
         $contexts = $this->contexts_config();
485
-        if (! isset($contexts[$context])) {
485
+        if ( ! isset($contexts[$context])) {
486 486
             throw new InvalidIdentifierException(
487 487
                 '',
488 488
                 '',
Please login to merge, or discard this patch.
admin_pages/messages/help_tabs/messages_settings_messengers.help_tab.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,79 +3,79 @@
 block discarded – undo
3 3
 </p>
4 4
 <p>
5 5
     <?php esc_html_e(
6
-        'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
-        'event_espresso'
8
-    ); ?>
6
+		'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
+		'event_espresso'
8
+	); ?>
9 9
 </p>
10 10
 <p>
11 11
     <?php esc_html_e(
12
-        'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
-        'event_espresso'
14
-    ); ?>
12
+		'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
+		'event_espresso'
14
+	); ?>
15 15
 </p>
16 16
 <p>
17 17
     <?php printf(
18
-        esc_html__(
19
-            'The green colored gear %s indicates that this messenger is currently active.',
20
-            'event_espresso'
21
-        ),
22
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
-        . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
-    );
25
-    printf(
26
-        esc_html__(
27
-            ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
-            'event_espresso'
29
-        ),
30
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
-        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
-    ); ?>
18
+		esc_html__(
19
+			'The green colored gear %s indicates that this messenger is currently active.',
20
+			'event_espresso'
21
+		),
22
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
+		. ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
+	);
25
+	printf(
26
+		esc_html__(
27
+			' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
+			'event_espresso'
29
+		),
30
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
+		. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
+	); ?>
33 33
 </p>
34 34
 <p>
35 35
     <?php esc_html_e(
36
-        'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
-        'event_espresso'
38
-    ); ?>
36
+		'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
+		'event_espresso'
38
+	); ?>
39 39
 </p>
40 40
 <p>
41 41
     <?php printf(
42
-        esc_html__(
43
-            '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
-            'event_espresso'
45
-        ),
46
-        '<div class="switch">'
47
-            . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>'
48
-            . '<label for="ee-on-off-toggle-on"></label>'
49
-        . '</div>',
50
-        '<div class="switch">'
51
-            . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
-            . '<label for="ee-on-off-toggle-on"></label>'
53
-        . '</div>'
54
-    ); ?>
42
+		esc_html__(
43
+			'%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
+			'event_espresso'
45
+		),
46
+		'<div class="switch">'
47
+			. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>'
48
+			. '<label for="ee-on-off-toggle-on"></label>'
49
+		. '</div>',
50
+		'<div class="switch">'
51
+			. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
+			. '<label for="ee-on-off-toggle-on"></label>'
53
+		. '</div>'
54
+	); ?>
55 55
 </p>
56 56
 <p>
57 57
     <?php
58
-        esc_html_e(
59
-            'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
-            'event_espresso'
61
-        ); ?>
58
+		esc_html_e(
59
+			'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
+			'event_espresso'
61
+		); ?>
62 62
 </p>
63 63
 <p>
64 64
     <?php esc_html_e(
65
-        'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
-        'event_espresso'
67
-    ); ?>
65
+		'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
+		'event_espresso'
67
+	); ?>
68 68
 </p>
69 69
 <p>
70 70
     <?php esc_html_e(
71
-        'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
-        'event_espresso'
73
-    ); ?>
71
+		'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
+		'event_espresso'
73
+	); ?>
74 74
 </p>
75 75
 <p>
76 76
     <strong><?php esc_html_e('Important', 'event_espresso'); ?></strong><br/>
77 77
     <?php esc_html_e(
78
-        'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
-        'event_espresso'
80
-    ); ?>
78
+		'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
+		'event_espresso'
80
+	); ?>
81 81
 </p>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@
 block discarded – undo
19 19
             'The green colored gear %s indicates that this messenger is currently active.',
20 20
             'event_espresso'
21 21
         ),
22
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
-        . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
22
+        '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'"'
23
+        . ' alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />'
24 24
     );
25 25
     printf(
26 26
         esc_html__(
27 27
             ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28 28
             'event_espresso'
29 29
         ),
30
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
-        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
30
+        '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
31
+        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />'
32 32
     ); ?>
33 33
 </p>
34 34
 <p>
Please login to merge, or discard this patch.