Completed
Branch fix-message-active-toggle (c2556b)
by
unknown
36:41 queued 26:55
created
admin_pages/messages/templates/ee_msg_editor_context_switcher.template.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -13,40 +13,40 @@
 block discarded – undo
13 13
 
14 14
 <div class='ee-msg-switcher-container'>
15 15
     <?php
16
-    foreach ($args as $name => $value) {
17
-        if ($name === 'context' || empty($value) || $name === 'extra') {
18
-            continue;
19
-        }
20
-        ?>
16
+	foreach ($args as $name => $value) {
17
+		if ($name === 'context' || empty($value) || $name === 'extra') {
18
+			continue;
19
+		}
20
+		?>
21 21
         <input type="hidden"
22 22
                name="<?php echo esc_attr($name); ?>"
23 23
                value="<?php echo esc_attr($value); ?>"
24 24
         />
25 25
         <?php
26
-    }
27
-    // setup nonce_url
28
-    wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
29
-    $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
30
-    ?>
26
+	}
27
+	// setup nonce_url
28
+	wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
29
+	$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
30
+	?>
31 31
     <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
32 32
         <?php esc_html_e('message context options', 'event_espresso'); ?>
33 33
     </label>
34 34
     <select id="<?php echo esc_attr($id); ?>" name="context">
35 35
         <?php
36
-        if (is_array($context_templates)) :
37
-            foreach ($context_templates as $context => $template_fields) :
38
-                $checked = ($context === $args['context']) ? 'selected' : '';
39
-                ?>
36
+		if (is_array($context_templates)) :
37
+			foreach ($context_templates as $context => $template_fields) :
38
+				$checked = ($context === $args['context']) ? 'selected' : '';
39
+				?>
40 40
                 <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
41 41
                     <?php echo esc_html($context_details[ $context ]['label']); ?>
42 42
                 </option>
43 43
             <?php endforeach;
44
-        endif; ?>
44
+		endif; ?>
45 45
     </select>
46 46
     <?php $button_text = sprintf(
47
-        esc_html__('Switch %s', 'event_espresso'),
48
-        ucwords($context_label['label'])
49
-    ); ?>
47
+		esc_html__('Switch %s', 'event_espresso'),
48
+		ucwords($context_label['label'])
49
+	); ?>
50 50
     <input class='button--secondary'
51 51
            id="submit-msg-context-switcher-sbmt"
52 52
            type="submit"
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
         <?php
26 26
     }
27 27
     // setup nonce_url
28
-    wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
29
-    $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
28
+    wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
29
+    $id = 'ee-'.sanitize_key($context_label['label']).'-select';
30 30
     ?>
31 31
     <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
32 32
         <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
                 $checked = ($context === $args['context']) ? 'selected' : '';
39 39
                 ?>
40 40
                 <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
41
-                    <?php echo esc_html($context_details[ $context ]['label']); ?>
41
+                    <?php echo esc_html($context_details[$context]['label']); ?>
42 42
                 </option>
43 43
             <?php endforeach;
44 44
         endif; ?>
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4628 added lines, -4628 removed lines patch added patch discarded remove patch
@@ -17,4639 +17,4639 @@
 block discarded – undo
17 17
  */
18 18
 class Messages_Admin_Page extends EE_Admin_Page
19 19
 {
20
-    /**
21
-     * @var EEM_Message
22
-     */
23
-    private $MSG_MODEL;
24
-
25
-    /**
26
-     * @var EEM_Message_Template
27
-     */
28
-    private $MTP_MODEL;
29
-
30
-    /**
31
-     * @var EEM_Message_Template_Group
32
-     */
33
-    private $MTG_MODEL;
34
-
35
-    /**
36
-     * @var EE_Message_Resource_Manager $_message_resource_manager
37
-     */
38
-    protected $_message_resource_manager;
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    protected $_active_message_type_name = '';
44
-
45
-    /**
46
-     * @var string
47
-     */
48
-    protected $_active_messenger_name = '';
49
-
50
-    /**
51
-     * @var EE_messenger $_active_messenger
52
-     */
53
-    protected $_active_messenger;
54
-
55
-    protected $_activate_meta_box_type;
56
-
57
-    protected $_current_message_meta_box;
58
-
59
-    protected $_current_message_meta_box_object;
60
-
61
-    protected $_shortcodes           = [];
62
-
63
-    protected $_active_messengers    = [];
64
-
65
-    protected $_active_message_types = [];
66
-
67
-    /**
68
-     * @var EE_Message_Template_Group $_message_template_group
69
-     */
70
-    protected $_message_template_group;
71
-
72
-    protected $_m_mt_settings = [];
73
-
74
-
75
-    /**
76
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
77
-     * IF there is no group then it gets automatically set to the Default template pack.
78
-     *
79
-     * @since 4.5.0
80
-     *
81
-     * @var EE_Messages_Template_Pack
82
-     */
83
-    protected $_template_pack;
84
-
85
-
86
-    /**
87
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
88
-     * group is.  If there is no group then it automatically gets set to default.
89
-     *
90
-     * @since 4.5.0
91
-     *
92
-     * @var string
93
-     */
94
-    protected $_variation;
95
-
96
-
97
-    /**
98
-     * @param bool $routing
99
-     * @throws EE_Error
100
-     * @throws ReflectionException
101
-     */
102
-    public function __construct($routing = true)
103
-    {
104
-        // make sure messages autoloader is running
105
-        EED_Messages::set_autoloaders();
106
-        parent::__construct($routing);
107
-    }
108
-
109
-
110
-    /**
111
-     * @return EEM_Message
112
-     * @throws EE_Error
113
-     */
114
-    public function getMsgModel()
115
-    {
116
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
117
-            $this->MSG_MODEL = EEM_Message::instance();
118
-        }
119
-        return $this->MSG_MODEL;
120
-    }
121
-
122
-
123
-    /**
124
-     * @return EEM_Message_Template
125
-     * @throws EE_Error
126
-     */
127
-    public function getMtpModel()
128
-    {
129
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
130
-            $this->MTP_MODEL = EEM_Message_Template::instance();
131
-        }
132
-        return $this->MTP_MODEL;
133
-    }
134
-
135
-
136
-    /**
137
-     * @return EEM_Message_Template_Group
138
-     * @throws EE_Error
139
-     */
140
-    public function getMtgModel()
141
-    {
142
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
143
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
144
-        }
145
-        return $this->MTG_MODEL;
146
-    }
147
-
148
-
149
-    /**
150
-     * @throws EE_Error
151
-     * @throws ReflectionException
152
-     */
153
-    protected function _init_page_props()
154
-    {
155
-        $this->page_slug        = EE_MSG_PG_SLUG;
156
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
157
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
158
-        $this->_admin_base_path = EE_MSG_ADMIN;
159
-
160
-        $messenger    = $this->request->getRequestParam('messenger', '');
161
-        $message_type = $this->request->getRequestParam('message_type', '');
162
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
163
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
164
-
165
-        $this->_load_message_resource_manager();
166
-    }
167
-
168
-
169
-    /**
170
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
171
-     *
172
-     * @throws EE_Error
173
-     * @throws InvalidDataTypeException
174
-     * @throws InvalidInterfaceException
175
-     * @throws InvalidArgumentException
176
-     * @throws ReflectionException
177
-     */
178
-    protected function _load_message_resource_manager()
179
-    {
180
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
181
-    }
182
-
183
-
184
-    /**
185
-     * @return array
186
-     * @throws EE_Error
187
-     * @throws InvalidArgumentException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidInterfaceException
190
-     * @deprecated 4.9.9.rc.014
191
-     */
192
-    public function get_messengers_for_list_table()
193
-    {
194
-        EE_Error::doing_it_wrong(
195
-            __METHOD__,
196
-            sprintf(
197
-                esc_html__(
198
-                    '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',
199
-                    'event_espresso'
200
-                ),
201
-                'Messages_Admin_Page::get_messengers_select_input()'
202
-            ),
203
-            '4.9.9.rc.014'
204
-        );
205
-
206
-        $m_values          = [];
207
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
208
-        // setup messengers for selects
209
-        $i = 1;
210
-        foreach ($active_messengers as $active_messenger) {
211
-            if ($active_messenger instanceof EE_Message) {
212
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
213
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
214
-                $i++;
215
-            }
216
-        }
217
-
218
-        return $m_values;
219
-    }
220
-
221
-
222
-    /**
223
-     * @return array
224
-     * @throws EE_Error
225
-     * @throws InvalidArgumentException
226
-     * @throws InvalidDataTypeException
227
-     * @throws InvalidInterfaceException
228
-     * @deprecated 4.9.9.rc.014
229
-     */
230
-    public function get_message_types_for_list_table()
231
-    {
232
-        EE_Error::doing_it_wrong(
233
-            __METHOD__,
234
-            sprintf(
235
-                esc_html__(
236
-                    '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',
237
-                    'event_espresso'
238
-                ),
239
-                'Messages_Admin_Page::get_message_types_select_input()'
240
-            ),
241
-            '4.9.9.rc.014'
242
-        );
243
-
244
-        $mt_values       = [];
245
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
246
-        $i               = 1;
247
-        foreach ($active_messages as $active_message) {
248
-            if ($active_message instanceof EE_Message) {
249
-                $mt_values[ $i ]['id']   = $active_message->message_type();
250
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
251
-                $i++;
252
-            }
253
-        }
254
-
255
-        return $mt_values;
256
-    }
257
-
258
-
259
-    /**
260
-     * @return array
261
-     * @throws EE_Error
262
-     * @throws InvalidArgumentException
263
-     * @throws InvalidDataTypeException
264
-     * @throws InvalidInterfaceException
265
-     * @deprecated 4.9.9.rc.014
266
-     */
267
-    public function get_contexts_for_message_types_for_list_table()
268
-    {
269
-        EE_Error::doing_it_wrong(
270
-            __METHOD__,
271
-            sprintf(
272
-                esc_html__(
273
-                    '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',
274
-                    'event_espresso'
275
-                ),
276
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
277
-            ),
278
-            '4.9.9.rc.014'
279
-        );
280
-
281
-        $contexts                = [];
282
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
283
-        foreach ($active_message_contexts as $active_message) {
284
-            if ($active_message instanceof EE_Message) {
285
-                $message_type = $active_message->message_type_object();
286
-                if ($message_type instanceof EE_message_type) {
287
-                    $message_type_contexts = $message_type->get_contexts();
288
-                    foreach ($message_type_contexts as $context => $context_details) {
289
-                        $contexts[ $context ] = $context_details['label'];
290
-                    }
291
-                }
292
-            }
293
-        }
294
-
295
-        return $contexts;
296
-    }
297
-
298
-
299
-    /**
300
-     * Generate select input with provided messenger options array.
301
-     *
302
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
303
-     *                                 labels.
304
-     * @return string
305
-     * @throws EE_Error
306
-     */
307
-    public function get_messengers_select_input($messenger_options)
308
-    {
309
-        // if empty or just one value then just return an empty string
310
-        if (
311
-            empty($messenger_options)
312
-            || ! is_array($messenger_options)
313
-            || count($messenger_options) === 1
314
-        ) {
315
-            return '';
316
-        }
317
-        // merge in default
318
-        $messenger_options = array_merge(
319
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
320
-            $messenger_options
321
-        );
322
-        $input             = new EE_Select_Input(
323
-            $messenger_options,
324
-            [
325
-                'html_name'  => 'ee_messenger_filter_by',
326
-                'html_id'    => 'ee_messenger_filter_by',
327
-                'html_class' => 'wide',
328
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
329
-            ]
330
-        );
331
-
332
-        return $input->get_html_for_input();
333
-    }
334
-
335
-
336
-    /**
337
-     * Generate select input with provided message type options array.
338
-     *
339
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
340
-     *                                    message type labels
341
-     * @return string
342
-     * @throws EE_Error
343
-     */
344
-    public function get_message_types_select_input($message_type_options)
345
-    {
346
-        // if empty or count of options is 1 then just return an empty string
347
-        if (
348
-            empty($message_type_options)
349
-            || ! is_array($message_type_options)
350
-            || count($message_type_options) === 1
351
-        ) {
352
-            return '';
353
-        }
354
-        // merge in default
355
-        $message_type_options = array_merge(
356
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
357
-            $message_type_options
358
-        );
359
-        $input                = new EE_Select_Input(
360
-            $message_type_options,
361
-            [
362
-                'html_name'  => 'ee_message_type_filter_by',
363
-                'html_id'    => 'ee_message_type_filter_by',
364
-                'html_class' => 'wide',
365
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
366
-            ]
367
-        );
368
-
369
-        return $input->get_html_for_input();
370
-    }
371
-
372
-
373
-    /**
374
-     * Generate select input with provide message type contexts array.
375
-     *
376
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
377
-     *                               context label.
378
-     * @return string
379
-     * @throws EE_Error
380
-     */
381
-    public function get_contexts_for_message_types_select_input($context_options)
382
-    {
383
-        // if empty or count of options is one then just return empty string
384
-        if (
385
-            empty($context_options)
386
-            || ! is_array($context_options)
387
-            || count($context_options) === 1
388
-        ) {
389
-            return '';
390
-        }
391
-        // merge in default
392
-        $context_options = array_merge(
393
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
394
-            $context_options
395
-        );
396
-        $input           = new EE_Select_Input(
397
-            $context_options,
398
-            [
399
-                'html_name'  => 'ee_context_filter_by',
400
-                'html_id'    => 'ee_context_filter_by',
401
-                'html_class' => 'wide',
402
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
403
-            ]
404
-        );
405
-
406
-        return $input->get_html_for_input();
407
-    }
408
-
409
-
410
-    protected function _ajax_hooks()
411
-    {
412
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
413
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
414
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
415
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
416
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
417
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
418
-    }
419
-
420
-
421
-    protected function _define_page_props()
422
-    {
423
-        $this->_admin_page_title = $this->page_label;
424
-        $this->_labels           = [
425
-            'buttons'    => [
426
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
427
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
428
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
429
-            ],
430
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
431
-        ];
432
-    }
433
-
434
-
435
-    /**
436
-     *        an array for storing key => value pairs of request actions and their corresponding methods
437
-     *
438
-     * @access protected
439
-     * @return void
440
-     */
441
-    protected function _set_page_routes()
442
-    {
443
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
444
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
445
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
446
-
447
-        $this->_page_routes = [
448
-            'default'                          => [
449
-                'func'       => '_message_queue_list_table',
450
-                'capability' => 'ee_read_global_messages',
451
-            ],
452
-            'global_mtps'                      => [
453
-                'func'       => '_ee_default_messages_overview_list_table',
454
-                'capability' => 'ee_read_global_messages',
455
-            ],
456
-            'custom_mtps'                      => [
457
-                'func'       => '_custom_mtps_preview',
458
-                'capability' => 'ee_read_messages',
459
-            ],
460
-            'add_new_message_template'         => [
461
-                'func'       => 'add_message_template',
462
-                'capability' => 'ee_edit_messages',
463
-                'noheader'   => true,
464
-            ],
465
-            'edit_message_template'            => [
466
-                'func'       => '_edit_message_template',
467
-                'capability' => 'ee_edit_message',
468
-                'obj_id'     => $GRP_ID,
469
-            ],
470
-            'preview_message'                  => [
471
-                'func'               => '_preview_message',
472
-                'capability'         => 'ee_read_message',
473
-                'obj_id'             => $GRP_ID,
474
-                'noheader'           => true,
475
-                'headers_sent_route' => 'display_preview_message',
476
-            ],
477
-            'display_preview_message'          => [
478
-                'func'       => '_display_preview_message',
479
-                'capability' => 'ee_read_message',
480
-                'obj_id'     => $GRP_ID,
481
-            ],
482
-            'insert_message_template'          => [
483
-                'func'       => '_insert_or_update_message_template',
484
-                'capability' => 'ee_edit_messages',
485
-                'args'       => ['new' => true],
486
-                'noheader'   => true,
487
-            ],
488
-            'update_message_template'          => [
489
-                'func'       => '_insert_or_update_message_template',
490
-                'capability' => 'ee_edit_message',
491
-                'obj_id'     => $GRP_ID,
492
-                'args'       => ['new' => false],
493
-                'noheader'   => true,
494
-            ],
495
-            'trash_message_template'           => [
496
-                'func'       => '_trash_or_restore_message_template',
497
-                'capability' => 'ee_delete_message',
498
-                'obj_id'     => $GRP_ID,
499
-                'args'       => ['trash' => true, 'all' => true],
500
-                'noheader'   => true,
501
-            ],
502
-            'trash_message_template_context'   => [
503
-                'func'       => '_trash_or_restore_message_template',
504
-                'capability' => 'ee_delete_message',
505
-                'obj_id'     => $GRP_ID,
506
-                'args'       => ['trash' => true],
507
-                'noheader'   => true,
508
-            ],
509
-            'restore_message_template'         => [
510
-                'func'       => '_trash_or_restore_message_template',
511
-                'capability' => 'ee_delete_message',
512
-                'obj_id'     => $GRP_ID,
513
-                'args'       => ['trash' => false, 'all' => true],
514
-                'noheader'   => true,
515
-            ],
516
-            'restore_message_template_context' => [
517
-                'func'       => '_trash_or_restore_message_template',
518
-                'capability' => 'ee_delete_message',
519
-                'obj_id'     => $GRP_ID,
520
-                'args'       => ['trash' => false],
521
-                'noheader'   => true,
522
-            ],
523
-            'delete_message_template'          => [
524
-                'func'       => '_delete_message_template',
525
-                'capability' => 'ee_delete_message',
526
-                'obj_id'     => $GRP_ID,
527
-                'noheader'   => true,
528
-            ],
529
-            'reset_to_default'                 => [
530
-                'func'       => '_reset_to_default_template',
531
-                'capability' => 'ee_edit_message',
532
-                'obj_id'     => $GRP_ID,
533
-                'noheader'   => true,
534
-            ],
535
-            'settings'                         => [
536
-                'func'       => '_settings',
537
-                'capability' => 'manage_options',
538
-            ],
539
-            'update_global_settings'           => [
540
-                'func'       => '_update_global_settings',
541
-                'capability' => 'manage_options',
542
-                'noheader'   => true,
543
-            ],
544
-            'generate_now'                     => [
545
-                'func'       => '_generate_now',
546
-                'capability' => 'ee_send_message',
547
-                'noheader'   => true,
548
-            ],
549
-            'generate_and_send_now'            => [
550
-                'func'       => '_generate_and_send_now',
551
-                'capability' => 'ee_send_message',
552
-                'noheader'   => true,
553
-            ],
554
-            'queue_for_resending'              => [
555
-                'func'       => '_queue_for_resending',
556
-                'capability' => 'ee_send_message',
557
-                'noheader'   => true,
558
-            ],
559
-            'send_now'                         => [
560
-                'func'       => '_send_now',
561
-                'capability' => 'ee_send_message',
562
-                'noheader'   => true,
563
-            ],
564
-            'delete_ee_message'                => [
565
-                'func'       => '_delete_ee_messages',
566
-                'capability' => 'ee_delete_messages',
567
-                'noheader'   => true,
568
-            ],
569
-            'delete_ee_messages'               => [
570
-                'func'       => '_delete_ee_messages',
571
-                'capability' => 'ee_delete_messages',
572
-                'noheader'   => true,
573
-                'obj_id'     => $MSG_ID,
574
-            ],
575
-        ];
576
-    }
577
-
578
-
579
-    protected function _set_page_config()
580
-    {
581
-        $this->_page_config = [
582
-            'default'                  => [
583
-                'nav'           => [
584
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
585
-                    'icon' => 'dashicons-email',
586
-                    'order' => 10,
587
-                ],
588
-                'list_table'    => 'EE_Message_List_Table',
589
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
590
-                'require_nonce' => false,
591
-            ],
592
-            'global_mtps'              => [
593
-                'nav'           => [
594
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
595
-                    'icon' => 'dashicons-layout',
596
-                    'order' => 20,
597
-                ],
598
-                'list_table'    => 'Messages_Template_List_Table',
599
-                'help_tabs'     => [
600
-                    'messages_overview_help_tab'                                => [
601
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
-                        'filename' => 'messages_overview',
603
-                    ],
604
-                    'messages_overview_messages_table_column_headings_help_tab' => [
605
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
-                        'filename' => 'messages_overview_table_column_headings',
607
-                    ],
608
-                    'messages_overview_messages_filters_help_tab'               => [
609
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
610
-                        'filename' => 'messages_overview_filters',
611
-                    ],
612
-                    'messages_overview_messages_views_help_tab'                 => [
613
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
614
-                        'filename' => 'messages_overview_views',
615
-                    ],
616
-                    'message_overview_message_types_help_tab'                   => [
617
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
618
-                        'filename' => 'messages_overview_types',
619
-                    ],
620
-                    'messages_overview_messengers_help_tab'                     => [
621
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
622
-                        'filename' => 'messages_overview_messengers',
623
-                    ],
624
-                ],
625
-                'require_nonce' => false,
626
-            ],
627
-            'custom_mtps'              => [
628
-                'nav'           => [
629
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
-                    'icon' => 'dashicons-admin-customizer',
631
-                    'order' => 30,
632
-                ],
633
-                'help_tabs'     => [],
634
-                'require_nonce' => false,
635
-            ],
636
-            'add_new_message_template' => [
637
-                'nav'           => [
638
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
639
-                    'icon' => 'dashicons-plus-alt',
640
-                    'order'      => 5,
641
-                    'persistent' => false,
642
-                ],
643
-                'require_nonce' => false,
644
-            ],
645
-            'edit_message_template'    => [
646
-                'labels'        => [
647
-                    'buttons'    => [
648
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
649
-                    ],
650
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
651
-                ],
652
-                'nav'           => [
653
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
654
-                    'icon' => 'dashicons-edit-large',
655
-                    'order'      => 5,
656
-                    'persistent' => false,
657
-                    'url'        => '',
658
-                ],
659
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
660
-                'has_metaboxes' => true,
661
-                'help_tabs'     => [
662
-                    'edit_message_template'            => [
663
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
664
-                        'callback' => 'edit_message_template_help_tab',
665
-                    ],
666
-                    'message_templates_help_tab'       => [
667
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
668
-                        'filename' => 'messages_templates',
669
-                    ],
670
-                    'message_template_shortcodes'      => [
671
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
672
-                        'callback' => 'message_template_shortcodes_help_tab',
673
-                    ],
674
-                    'message_preview_help_tab'         => [
675
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
676
-                        'filename' => 'messages_preview',
677
-                    ],
678
-                    'messages_overview_other_help_tab' => [
679
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
680
-                        'filename' => 'messages_overview_other',
681
-                    ],
682
-                ],
683
-                'require_nonce' => false,
684
-            ],
685
-            'display_preview_message'  => [
686
-                'nav'           => [
687
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
688
-                    'icon' => 'dashicons-visibility-bar',
689
-                    'order'      => 5,
690
-                    'url'        => '',
691
-                    'persistent' => false,
692
-                ],
693
-                'help_tabs'     => [
694
-                    'preview_message' => [
695
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
696
-                        'callback' => 'preview_message_help_tab',
697
-                    ],
698
-                ],
699
-                'require_nonce' => false,
700
-            ],
701
-            'settings'                 => [
702
-                'nav'           => [
703
-                    'label' => esc_html__('Settings', 'event_espresso'),
704
-                    'icon' => 'dashicons-admin-generic',
705
-                    'order' => 40,
706
-                ],
707
-                'metaboxes'     => ['_messages_settings_metaboxes'],
708
-                'help_tabs'     => [
709
-                    'messages_settings_help_tab'               => [
710
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
711
-                        'filename' => 'messages_settings',
712
-                    ],
713
-                    'messages_settings_message_types_help_tab' => [
714
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
715
-                        'filename' => 'messages_settings_message_types',
716
-                    ],
717
-                    'messages_settings_messengers_help_tab'    => [
718
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
719
-                        'filename' => 'messages_settings_messengers',
720
-                    ],
721
-                ],
722
-                'require_nonce' => false,
723
-            ],
724
-        ];
725
-    }
726
-
727
-
728
-    protected function _add_screen_options()
729
-    {
730
-        // todo
731
-    }
732
-
733
-
734
-    protected function _add_screen_options_global_mtps()
735
-    {
736
-        /**
737
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
738
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
739
-         */
740
-        $page_title              = $this->_admin_page_title;
741
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
742
-        $this->_per_page_screen_option();
743
-        $this->_admin_page_title = $page_title;
744
-    }
745
-
746
-
747
-    protected function _add_screen_options_default()
748
-    {
749
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
750
-        $this->_per_page_screen_option();
751
-    }
752
-
753
-
754
-    // none of the below group are currently used for Messages
755
-    protected function _add_feature_pointers()
756
-    {
757
-    }
758
-
759
-
760
-    public function admin_init()
761
-    {
762
-    }
763
-
764
-
765
-    public function admin_notices()
766
-    {
767
-    }
768
-
769
-
770
-    public function admin_footer_scripts()
771
-    {
772
-    }
773
-
774
-
775
-    public function messages_help_tab()
776
-    {
777
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
778
-    }
779
-
780
-
781
-    public function messengers_help_tab()
782
-    {
783
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
784
-    }
785
-
786
-
787
-    public function message_types_help_tab()
788
-    {
789
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
790
-    }
791
-
792
-
793
-    public function messages_overview_help_tab()
794
-    {
795
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
796
-    }
797
-
798
-
799
-    public function message_templates_help_tab()
800
-    {
801
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
802
-    }
803
-
804
-
805
-    public function edit_message_template_help_tab()
806
-    {
807
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
808
-                        . esc_attr__('Editor Title', 'event_espresso')
809
-                        . '" />';
810
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
811
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
812
-                        . '" />';
813
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
814
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
815
-                        . '" />';
816
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
817
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
818
-                        . '" />';
819
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
820
-                        . esc_attr__('Publish Metabox', 'event_espresso')
821
-                        . '" />';
822
-        EEH_Template::display_template(
823
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
824
-            $args
825
-        );
826
-    }
827
-
828
-
829
-    /**
830
-     * @throws ReflectionException
831
-     * @throws EE_Error
832
-     */
833
-    public function message_template_shortcodes_help_tab()
834
-    {
835
-        $this->_set_shortcodes();
836
-        $args['shortcodes'] = $this->_shortcodes;
837
-        EEH_Template::display_template(
838
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
839
-            $args
840
-        );
841
-    }
842
-
843
-
844
-    public function preview_message_help_tab()
845
-    {
846
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
847
-    }
848
-
849
-
850
-    public function settings_help_tab()
851
-    {
852
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
853
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
854
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
855
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
856
-        $args['img3'] = '<div class="ee-switch">'
857
-                        . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
858
-                        . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
859
-                        . '</div>';
860
-        $args['img4'] = '<div class="switch">'
861
-                        . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
862
-                        . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
863
-                        . '</div>';
864
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
865
-    }
866
-
867
-
868
-    public function load_scripts_styles()
869
-    {
870
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
871
-        wp_enqueue_style('espresso_ee_msg');
872
-
873
-        wp_register_script(
874
-            'ee-messages-settings',
875
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
876
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
877
-            EVENT_ESPRESSO_VERSION,
878
-            true
879
-        );
880
-        wp_register_script(
881
-            'ee-msg-list-table-js',
882
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
883
-            ['ee-dialog'],
884
-            EVENT_ESPRESSO_VERSION
885
-        );
886
-    }
887
-
888
-
889
-    public function load_scripts_styles_default()
890
-    {
891
-        wp_enqueue_script('ee-msg-list-table-js');
892
-    }
893
-
894
-
895
-    public function wp_editor_css($mce_css)
896
-    {
897
-        // if we're on the edit_message_template route
898
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
899
-            $message_type_name = $this->_active_message_type_name;
900
-
901
-            // we're going to REPLACE the existing mce css
902
-            // we need to get the css file location from the active messenger
903
-            $mce_css = $this->_active_messenger->get_variation(
904
-                $this->_template_pack,
905
-                $message_type_name,
906
-                true,
907
-                'wpeditor',
908
-                $this->_variation
909
-            );
910
-        }
911
-
912
-        return $mce_css;
913
-    }
914
-
915
-
916
-    /**
917
-     * @throws EE_Error
918
-     * @throws ReflectionException
919
-     */
920
-    public function load_scripts_styles_edit_message_template()
921
-    {
922
-
923
-        $this->_set_shortcodes();
924
-
925
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
926
-            esc_html__(
927
-                '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.',
928
-                'event_espresso'
929
-            ),
930
-            $this->_message_template_group->messenger_obj()->label['singular'],
931
-            $this->_message_template_group->message_type_obj()->label['singular']
932
-        );
933
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
934
-            '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?',
935
-            'event_espresso'
936
-        );
937
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
938
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
939
-            'event_espresso'
940
-        );
941
-
942
-        wp_register_script(
943
-            'ee_msgs_edit_js',
944
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
945
-            ['jquery'],
946
-            EVENT_ESPRESSO_VERSION
947
-        );
948
-
949
-        wp_enqueue_script('ee_admin_js');
950
-        wp_enqueue_script('ee_msgs_edit_js');
951
-
952
-        // add in special css for tiny_mce
953
-        add_filter('mce_css', [$this, 'wp_editor_css']);
954
-    }
955
-
956
-
957
-    /**
958
-     * @throws EE_Error
959
-     * @throws ReflectionException
960
-     */
961
-    public function load_scripts_styles_display_preview_message()
962
-    {
963
-        $this->_set_message_template_group();
964
-        if ($this->_active_messenger_name) {
965
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
966
-                $this->_active_messenger_name
967
-            );
968
-        }
969
-
970
-        wp_enqueue_style(
971
-            'espresso_preview_css',
972
-            $this->_active_messenger->get_variation(
973
-                $this->_template_pack,
974
-                $this->_active_message_type_name,
975
-                true,
976
-                'preview',
977
-                $this->_variation
978
-            )
979
-        );
980
-    }
981
-
982
-
983
-    public function load_scripts_styles_settings()
984
-    {
985
-        wp_register_style(
986
-            'ee-message-settings',
987
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
988
-            [],
989
-            EVENT_ESPRESSO_VERSION
990
-        );
991
-        wp_enqueue_style('ee-text-links');
992
-        wp_enqueue_style('ee-message-settings');
993
-        wp_enqueue_script('ee-messages-settings');
994
-    }
995
-
996
-
997
-    /**
998
-     * set views array for List Table
999
-     */
1000
-    public function _set_list_table_views_global_mtps()
1001
-    {
1002
-        $this->_views = [
1003
-            'in_use' => [
1004
-                'slug'  => 'in_use',
1005
-                'label' => esc_html__('In Use', 'event_espresso'),
1006
-                'count' => 0,
1007
-            ],
1008
-        ];
1009
-    }
1010
-
1011
-
1012
-    /**
1013
-     * Set views array for the Custom Template List Table
1014
-     */
1015
-    public function _set_list_table_views_custom_mtps()
1016
-    {
1017
-        $this->_set_list_table_views_global_mtps();
1018
-        $this->_views['in_use']['bulk_action'] = [
1019
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1020
-        ];
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * set views array for message queue list table
1026
-     *
1027
-     * @throws InvalidDataTypeException
1028
-     * @throws InvalidInterfaceException
1029
-     * @throws InvalidArgumentException
1030
-     * @throws EE_Error
1031
-     * @throws ReflectionException
1032
-     */
1033
-    public function _set_list_table_views_default()
1034
-    {
1035
-        EE_Registry::instance()->load_helper('Template');
1036
-
1037
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1038
-            'ee_send_message',
1039
-            'message_list_table_bulk_actions'
1040
-        )
1041
-            ? [
1042
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1043
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1044
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1045
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1046
-            ]
1047
-            : [];
1048
-
1049
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1050
-            'ee_delete_messages',
1051
-            'message_list_table_bulk_actions'
1052
-        )
1053
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1054
-            : [];
1055
-
1056
-
1057
-        $this->_views = [
1058
-            'all' => [
1059
-                'slug'        => 'all',
1060
-                'label'       => esc_html__('All', 'event_espresso'),
1061
-                'count'       => 0,
1062
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1063
-            ],
1064
-        ];
1065
-
1066
-
1067
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1068
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1069
-                continue;
1070
-            }
1071
-            $status_bulk_actions = $common_bulk_actions;
1072
-            // unset bulk actions not applying to status
1073
-            if (! empty($status_bulk_actions)) {
1074
-                switch ($status) {
1075
-                    case EEM_Message::status_idle:
1076
-                    case EEM_Message::status_resend:
1077
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1078
-                        break;
1079
-
1080
-                    case EEM_Message::status_failed:
1081
-                    case EEM_Message::status_debug_only:
1082
-                    case EEM_Message::status_messenger_executing:
1083
-                        $status_bulk_actions = [];
1084
-                        break;
1085
-
1086
-                    case EEM_Message::status_incomplete:
1087
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1088
-                        break;
1089
-
1090
-                    case EEM_Message::status_retry:
1091
-                    case EEM_Message::status_sent:
1092
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1093
-                        break;
1094
-                }
1095
-            }
1096
-
1097
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1098
-            if ($status === EEM_Message::status_messenger_executing) {
1099
-                continue;
1100
-            }
1101
-
1102
-            $this->_views[ strtolower($status) ] = [
1103
-                'slug'        => strtolower($status),
1104
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1105
-                'count'       => 0,
1106
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1107
-            ];
1108
-        }
1109
-    }
1110
-
1111
-
1112
-    /**
1113
-     * @throws EE_Error
1114
-     */
1115
-    protected function _ee_default_messages_overview_list_table()
1116
-    {
1117
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1118
-        $this->display_admin_list_table_page_with_no_sidebar();
1119
-    }
1120
-
1121
-
1122
-    /**
1123
-     * @throws EE_Error
1124
-     * @throws ReflectionException
1125
-     */
1126
-    protected function _message_queue_list_table()
1127
-    {
1128
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1129
-        $this->_template_args['per_column']        = 6;
1130
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1131
-        $message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1132
-        $this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1133
-        $this->display_admin_list_table_page_with_no_sidebar();
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * @throws EE_Error
1139
-     */
1140
-    protected function _message_legend_items()
1141
-    {
1142
-
1143
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1144
-        $action_items       = [];
1145
-
1146
-        foreach ($action_css_classes as $action_item => $action_details) {
1147
-            if ($action_item === 'see_notifications_for') {
1148
-                continue;
1149
-            }
1150
-            $action_items[ $action_item ] = [
1151
-                'class' => $action_details['css_class'],
1152
-                'desc'  => $action_details['label'],
1153
-            ];
1154
-        }
1155
-
1156
-        /** @var array $status_items status legend setup */
1157
-        $status_items = [
1158
-            'sent_status'                => [
1159
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1160
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1161
-            ],
1162
-            'idle_status'                => [
1163
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1164
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1165
-            ],
1166
-            'failed_status'              => [
1167
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1168
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1169
-            ],
1170
-            'messenger_executing_status' => [
1171
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1172
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1173
-            ],
1174
-            'resend_status'              => [
1175
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1176
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1177
-            ],
1178
-            'incomplete_status'          => [
1179
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1180
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1181
-            ],
1182
-            'retry_status'               => [
1183
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1184
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1185
-            ],
1186
-        ];
1187
-        if (EEM_Message::debug()) {
1188
-            $status_items['debug_only_status'] = [
1189
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1190
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1191
-            ];
1192
-        }
1193
-
1194
-        return array_merge($action_items, $status_items);
1195
-    }
1196
-
1197
-
1198
-    /**
1199
-     * @throws EE_Error
1200
-     */
1201
-    protected function _custom_mtps_preview()
1202
-    {
1203
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1204
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1205
-                                                . ' alt="' . esc_attr__(
1206
-                                                    'Preview Custom Message Templates screenshot',
1207
-                                                    'event_espresso'
1208
-                                                ) . '" />';
1209
-        $this->_template_args['preview_text'] = '<strong>'
1210
-                                                . esc_html__(
1211
-                                                    '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.',
1212
-                                                    'event_espresso'
1213
-                                                )
1214
-                                                . '</strong>';
1215
-
1216
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1217
-    }
1218
-
1219
-
1220
-    /**
1221
-     * get_message_templates
1222
-     * This gets all the message templates for listing on the overview list.
1223
-     *
1224
-     * @access public
1225
-     * @param int    $per_page the amount of templates groups to show per page
1226
-     * @param string $type     the current _view we're getting templates for
1227
-     * @param bool   $count    return count?
1228
-     * @param bool   $all      disregard any paging info (get all data);
1229
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1230
-     * @return array
1231
-     * @throws EE_Error
1232
-     * @throws InvalidArgumentException
1233
-     * @throws InvalidDataTypeException
1234
-     * @throws InvalidInterfaceException
1235
-     */
1236
-    public function get_message_templates(
1237
-        $per_page = 10,
1238
-        $type = 'in_use',
1239
-        $count = false,
1240
-        $all = false,
1241
-        $global = true
1242
-    ) {
1243
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1244
-        $this->request->setRequestParam('orderby', $orderby);
1245
-
1246
-        $order        = $this->request->getRequestParam('order', 'ASC');
1247
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1248
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1249
-
1250
-        $offset = ($current_page - 1) * $per_page;
1251
-        $limit  = $all ? null : [$offset, $per_page];
1252
-
1253
-        // options will match what is in the _views array property
1254
-        return $type === 'in_use'
1255
-            ? $this->getMtgModel()->get_all_active_message_templates(
1256
-                $orderby,
1257
-                $order,
1258
-                $limit,
1259
-                $count,
1260
-                $global,
1261
-                true
1262
-            )
1263
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1264
-                $orderby,
1265
-                $order,
1266
-                $limit,
1267
-                $count,
1268
-                $global
1269
-            );
1270
-    }
1271
-
1272
-
1273
-    /**
1274
-     * filters etc might need a list of installed message_types
1275
-     *
1276
-     * @return array an array of message type objects
1277
-     */
1278
-    public function get_installed_message_types()
1279
-    {
1280
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1281
-        $installed               = [];
1282
-
1283
-        foreach ($installed_message_types as $message_type) {
1284
-            $installed[ $message_type->name ] = $message_type;
1285
-        }
1286
-
1287
-        return $installed;
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1293
-     *
1294
-     * @param string $message_type
1295
-     * @param string $messenger
1296
-     * @param string $GRP_ID
1297
-     *
1298
-     * @throws EE_error
1299
-     * @throws ReflectionException
1300
-     */
1301
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1302
-    {
1303
-        // set values override any request data
1304
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1305
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1306
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1307
-
1308
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1309
-        if (empty($message_type) || empty($messenger)) {
1310
-            throw new EE_Error(
1311
-                esc_html__(
1312
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1313
-                    'event_espresso'
1314
-                )
1315
-            );
1316
-        }
1317
-
1318
-        // we need the GRP_ID for the template being used as the base for the new template
1319
-        if (empty($GRP_ID)) {
1320
-            throw new EE_Error(
1321
-                esc_html__(
1322
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1323
-                    'event_espresso'
1324
-                )
1325
-            );
1326
-        }
1327
-
1328
-        // let's just make sure the template gets generated!
1329
-
1330
-        // we need to reassign some variables for what the insert is expecting
1331
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1332
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1333
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1334
-
1335
-        $this->_insert_or_update_message_template(true);
1336
-    }
1337
-
1338
-
1339
-    /**
1340
-     * @param string $message_type     message type slug
1341
-     * @param string $messenger        messenger slug
1342
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1343
-     *                                 off of.
1344
-     * @throws EE_error
1345
-     * @throws ReflectionException
1346
-     * @deprecated 4.10.29.p
1347
-     */
1348
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1349
-    {
1350
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1351
-    }
1352
-
1353
-
1354
-    /**
1355
-     * _edit_message_template
1356
-     *
1357
-     * @access protected
1358
-     * @return void
1359
-     * @throws InvalidIdentifierException
1360
-     * @throws DomainException
1361
-     * @throws EE_Error
1362
-     * @throws InvalidArgumentException
1363
-     * @throws ReflectionException
1364
-     * @throws InvalidDataTypeException
1365
-     * @throws InvalidInterfaceException
1366
-     */
1367
-    protected function _edit_message_template()
1368
-    {
1369
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1370
-        $template_fields = '';
1371
-        $sidebar_fields  = '';
1372
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1373
-        // valid html in the templates.
1374
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1375
-
1376
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1377
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1378
-
1379
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1380
-        $message_template_group = $this->_message_template_group;
1381
-        $c_label                = $message_template_group->context_label();
1382
-        $c_config               = $message_template_group->contexts_config();
1383
-
1384
-        reset($c_config);
1385
-        $context = $this->request->getRequestParam('context', key($c_config));
1386
-        $context = strtolower($context);
1387
-
1388
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1389
-
1390
-        $edit_message_template_form_url = add_query_arg(
1391
-            ['action' => $action, 'noheader' => true],
1392
-            EE_MSG_ADMIN_URL
1393
-        );
1394
-
1395
-        // set active messenger for this view
1396
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1397
-            $message_template_group->messenger()
1398
-        );
1399
-        $this->_active_message_type_name = $message_template_group->message_type();
1400
-
1401
-
1402
-        // Do we have any validation errors?
1403
-        $validators = $this->_get_transient();
1404
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1405
-
1406
-
1407
-        // we need to assemble the title from Various details
1408
-        $context_label = sprintf(
1409
-            esc_html__('(%s %s)', 'event_espresso'),
1410
-            $c_config[ $context ]['label'],
1411
-            ucwords($c_label['label'])
1412
-        );
1413
-
1414
-        $title = sprintf(
1415
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1416
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1417
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1418
-            $context_label
1419
-        );
1420
-
1421
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1422
-        $this->_template_args['message_template'] = $message_template_group;
1423
-        $this->_template_args['is_extra_fields']  = false;
1424
-
1425
-
1426
-        // let's get EEH_MSG_Template so we can get template form fields
1427
-        $template_field_structure = EEH_MSG_Template::get_fields(
1428
-            $message_template_group->messenger(),
1429
-            $message_template_group->message_type()
1430
-        );
1431
-
1432
-        if (! $template_field_structure) {
1433
-            $template_field_structure = false;
1434
-            $template_fields          = esc_html__(
1435
-                'There was an error in assembling the fields for this display (you should see an error message)',
1436
-                'event_espresso'
1437
-            );
1438
-        }
1439
-
1440
-
1441
-        $message_templates = $message_template_group->context_templates();
1442
-
1443
-
1444
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1445
-        // will get handled in the "extra" array.
1446
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1447
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1448
-                unset($template_field_structure[ $context ][ $reference_field ]);
1449
-            }
1450
-        }
1451
-
1452
-        // let's loop through the template_field_structure and actually assemble the input fields!
1453
-        if (! empty($template_field_structure)) {
1454
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1455
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1456
-                // the extra array and reset them.
1457
-                if ($template_field === 'extra') {
1458
-                    $this->_template_args['is_extra_fields'] = true;
1459
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1460
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1461
-                        $content          = $message_template instanceof EE_Message_Template
1462
-                            ? $message_template->get('MTP_content')
1463
-                            : '';
1464
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1465
-                            // let's verify if we need this extra field via the shortcodes parameter.
1466
-                            $continue = false;
1467
-                            if (isset($extra_array['shortcodes_required'])) {
1468
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1469
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1470
-                                        $continue = true;
1471
-                                    }
1472
-                                }
1473
-                                if ($continue) {
1474
-                                    continue;
1475
-                                }
1476
-                            }
1477
-
1478
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1479
-
1480
-                            $template_form_fields[ $field_id ]         = $extra_array;
1481
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1482
-                                                                         . $reference_field
1483
-                                                                         . '][content]['
1484
-                                                                         . $extra_field . ']';
1485
-                            $css_class                                 = isset($extra_array['css_class'])
1486
-                                ? $extra_array['css_class']
1487
-                                : '';
1488
-
1489
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1490
-                                                                              && in_array($extra_field, $v_fields, true)
1491
-                                                                              && (
1492
-                                                                                  is_array($validators[ $extra_field ])
1493
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1494
-                                                                              )
1495
-                                ? 'validate-error ' . $css_class
1496
-                                : $css_class;
1497
-
1498
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1499
-                                                                          && isset($content[ $extra_field ])
1500
-                                ? $content[ $extra_field ]
1501
-                                : '';
1502
-
1503
-                            // do we have a validation error?  if we do then let's use that value instead
1504
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1505
-                                ? $validators[ $extra_field ]['value']
1506
-                                : $template_form_fields[ $field_id ]['value'];
1507
-
1508
-
1509
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1510
-
1511
-                            // shortcode selector
1512
-                            $field_name_to_use                                   = $extra_field === 'main'
1513
-                                ? 'content'
1514
-                                : $extra_field;
1515
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1516
-                                $field_name_to_use,
1517
-                                $field_id
1518
-                            );
1519
-                        }
1520
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1521
-                        $template_field_template_name_id = $reference_field . '-name';
1522
-
1523
-                        $template_form_fields[ $template_field_MTP_id ] = [
1524
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1525
-                            'label'      => null,
1526
-                            'input'      => 'hidden',
1527
-                            'type'       => 'int',
1528
-                            'required'   => false,
1529
-                            'validation' => false,
1530
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1531
-                            'css_class'  => '',
1532
-                            'format'     => '%d',
1533
-                            'db-col'     => 'MTP_ID',
1534
-                        ];
1535
-
1536
-                        $template_form_fields[ $template_field_template_name_id ] = [
1537
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1538
-                            'label'      => null,
1539
-                            'input'      => 'hidden',
1540
-                            'type'       => 'string',
1541
-                            'required'   => false,
1542
-                            'validation' => true,
1543
-                            'value'      => $reference_field,
1544
-                            'css_class'  => '',
1545
-                            'format'     => '%s',
1546
-                            'db-col'     => 'MTP_template_field',
1547
-                        ];
1548
-                    }
1549
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1550
-                } else {
1551
-                    $field_id                                   = $template_field . '-content';
1552
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1553
-                    $template_form_fields[ $field_id ]['name']  =
1554
-                        'MTP_template_fields[' . $template_field . '][content]';
1555
-                    $message_template                           =
1556
-                        isset($message_templates[ $context ][ $template_field ])
1557
-                            ? $message_templates[ $context ][ $template_field ]
1558
-                            : null;
1559
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1560
-                                                                  && is_array($message_templates[ $context ])
1561
-                                                                  && $message_template instanceof EE_Message_Template
1562
-                        ? $message_template->get('MTP_content')
1563
-                        : '';
1564
-
1565
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1566
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1567
-                        ? $validators[ $template_field ]['value']
1568
-                        : $template_form_fields[ $field_id ]['value'];
1569
-
1570
-
1571
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1572
-                    $css_class                                      = isset($field_setup_array['css_class'])
1573
-                        ? $field_setup_array['css_class']
1574
-                        : '';
1575
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1576
-                                                                      && in_array($template_field, $v_fields, true)
1577
-                                                                      && isset($validators[ $template_field ]['msg'])
1578
-                        ? 'validate-error ' . $css_class
1579
-                        : $css_class;
1580
-
1581
-                    // shortcode selector
1582
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1583
-                        $template_field,
1584
-                        $field_id
1585
-                    );
1586
-                }
1587
-
1588
-                // k took care of content field(s) now let's take care of others.
1589
-
1590
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1591
-                $template_field_field_template_name_id = $template_field . '-name';
1592
-
1593
-                // foreach template field there are actually two form fields created
1594
-                $template_form_fields[ $template_field_MTP_id ] = [
1595
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1596
-                    'label'      => null,
1597
-                    'input'      => 'hidden',
1598
-                    'type'       => 'int',
1599
-                    'required'   => false,
1600
-                    'validation' => true,
1601
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1602
-                    'css_class'  => '',
1603
-                    'format'     => '%d',
1604
-                    'db-col'     => 'MTP_ID',
1605
-                ];
1606
-
1607
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1608
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1609
-                    'label'      => null,
1610
-                    'input'      => 'hidden',
1611
-                    'type'       => 'string',
1612
-                    'required'   => false,
1613
-                    'validation' => true,
1614
-                    'value'      => $template_field,
1615
-                    'css_class'  => '',
1616
-                    'format'     => '%s',
1617
-                    'db-col'     => 'MTP_template_field',
1618
-                ];
1619
-            }
1620
-
1621
-            // add other fields
1622
-            $template_form_fields['ee-msg-current-context'] = [
1623
-                'name'       => 'MTP_context',
1624
-                'label'      => null,
1625
-                'input'      => 'hidden',
1626
-                'type'       => 'string',
1627
-                'required'   => false,
1628
-                'validation' => true,
1629
-                'value'      => $context,
1630
-                'css_class'  => '',
1631
-                'format'     => '%s',
1632
-                'db-col'     => 'MTP_context',
1633
-            ];
1634
-
1635
-            $template_form_fields['ee-msg-grp-id'] = [
1636
-                'name'       => 'GRP_ID',
1637
-                'label'      => null,
1638
-                'input'      => 'hidden',
1639
-                'type'       => 'int',
1640
-                'required'   => false,
1641
-                'validation' => true,
1642
-                'value'      => $GRP_ID,
1643
-                'css_class'  => '',
1644
-                'format'     => '%d',
1645
-                'db-col'     => 'GRP_ID',
1646
-            ];
1647
-
1648
-            $template_form_fields['ee-msg-messenger'] = [
1649
-                'name'       => 'MTP_messenger',
1650
-                'label'      => null,
1651
-                'input'      => 'hidden',
1652
-                'type'       => 'string',
1653
-                'required'   => false,
1654
-                'validation' => true,
1655
-                'value'      => $message_template_group->messenger(),
1656
-                'css_class'  => '',
1657
-                'format'     => '%s',
1658
-                'db-col'     => 'MTP_messenger',
1659
-            ];
1660
-
1661
-            $template_form_fields['ee-msg-message-type'] = [
1662
-                'name'       => 'MTP_message_type',
1663
-                'label'      => null,
1664
-                'input'      => 'hidden',
1665
-                'type'       => 'string',
1666
-                'required'   => false,
1667
-                'validation' => true,
1668
-                'value'      => $message_template_group->message_type(),
1669
-                'css_class'  => '',
1670
-                'format'     => '%s',
1671
-                'db-col'     => 'MTP_message_type',
1672
-            ];
1673
-
1674
-            $sidebar_form_fields['ee-msg-is-global'] = [
1675
-                'name'       => 'MTP_is_global',
1676
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1677
-                'input'      => 'hidden',
1678
-                'type'       => 'int',
1679
-                'required'   => false,
1680
-                'validation' => true,
1681
-                'value'      => $message_template_group->get('MTP_is_global'),
1682
-                'css_class'  => '',
1683
-                'format'     => '%d',
1684
-                'db-col'     => 'MTP_is_global',
1685
-            ];
1686
-
1687
-            $sidebar_form_fields['ee-msg-is-override'] = [
1688
-                'name'       => 'MTP_is_override',
1689
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1690
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1691
-                'type'       => 'int',
1692
-                'required'   => false,
1693
-                'validation' => true,
1694
-                'value'      => $message_template_group->get('MTP_is_override'),
1695
-                'css_class'  => '',
1696
-                'format'     => '%d',
1697
-                'db-col'     => 'MTP_is_override',
1698
-            ];
1699
-
1700
-            $sidebar_form_fields['ee-msg-is-active'] = [
1701
-                'name'       => 'MTP_is_active',
1702
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1703
-                'input'      => 'hidden',
1704
-                'type'       => 'int',
1705
-                'required'   => false,
1706
-                'validation' => true,
1707
-                'value'      => $message_template_group->is_active(),
1708
-                'css_class'  => '',
1709
-                'format'     => '%d',
1710
-                'db-col'     => 'MTP_is_active',
1711
-            ];
1712
-
1713
-            $sidebar_form_fields['ee-msg-deleted'] = [
1714
-                'name'       => 'MTP_deleted',
1715
-                'label'      => null,
1716
-                'input'      => 'hidden',
1717
-                'type'       => 'int',
1718
-                'required'   => false,
1719
-                'validation' => true,
1720
-                'value'      => $message_template_group->get('MTP_deleted'),
1721
-                'css_class'  => '',
1722
-                'format'     => '%d',
1723
-                'db-col'     => 'MTP_deleted',
1724
-            ];
1725
-            $sidebar_form_fields['ee-msg-author']  = [
1726
-                'name'       => 'MTP_user_id',
1727
-                'label'      => esc_html__('Author', 'event_espresso'),
1728
-                'input'      => 'hidden',
1729
-                'type'       => 'int',
1730
-                'required'   => false,
1731
-                'validation' => false,
1732
-                'value'      => $message_template_group->user(),
1733
-                'format'     => '%d',
1734
-                'db-col'     => 'MTP_user_id',
1735
-            ];
1736
-
1737
-            $sidebar_form_fields['ee-msg-route'] = [
1738
-                'name'  => 'action',
1739
-                'input' => 'hidden',
1740
-                'type'  => 'string',
1741
-                'value' => $action,
1742
-            ];
1743
-
1744
-            $sidebar_form_fields['ee-msg-id']        = [
1745
-                'name'  => 'id',
1746
-                'input' => 'hidden',
1747
-                'type'  => 'int',
1748
-                'value' => $GRP_ID,
1749
-            ];
1750
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1751
-                'name'  => $action . '_nonce',
1752
-                'input' => 'hidden',
1753
-                'type'  => 'string',
1754
-                'value' => wp_create_nonce($action . '_nonce'),
1755
-            ];
1756
-
1757
-            $template_switch = $this->request->getRequestParam('template_switch');
1758
-            if ($template_switch) {
1759
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1760
-                    'name'  => 'template_switch',
1761
-                    'input' => 'hidden',
1762
-                    'type'  => 'int',
1763
-                    'value' => 1,
1764
-                ];
1765
-            }
1766
-
1767
-
1768
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1769
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1770
-        } //end if ( !empty($template_field_structure) )
1771
-
1772
-        // set extra content for publish box
1773
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1774
-        $this->_set_publish_post_box_vars(
1775
-            'id',
1776
-            $GRP_ID,
1777
-            false,
1778
-            add_query_arg(
1779
-                ['action' => 'global_mtps'],
1780
-                $this->_admin_base_url
1781
-            )
1782
-        );
1783
-
1784
-        // add preview button
1785
-        $preview_url    = parent::add_query_args_and_nonce(
1786
-            [
1787
-                'message_type' => $message_template_group->message_type(),
1788
-                'messenger'    => $message_template_group->messenger(),
1789
-                'context'      => $context,
1790
-                'GRP_ID'       => $GRP_ID,
1791
-                'evt_id'       => $EVT_ID ?: false,
1792
-                'action'       => 'preview_message',
1793
-            ],
1794
-            $this->_admin_base_url
1795
-        );
1796
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1797
-                          . esc_html__('Preview', 'event_espresso')
1798
-                          . '</a>';
1799
-
1800
-
1801
-
1802
-
1803
-        // main box
1804
-        $this->_template_args['template_fields']                         = $template_fields;
1805
-        $this->_template_args['sidebar_box_id']                          = 'details';
1806
-        $this->_template_args['action']                                  = $action;
1807
-        $this->_template_args['context']                                 = $context;
1808
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1809
-        $this->_template_args['learn_more_about_message_templates_link'] =
1810
-            $this->_learn_more_about_message_templates_link();
1811
-
1812
-
1813
-        $this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1814
-        $this->_template_args['before_admin_page_content'] .= $this->headerFormStart();
1815
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1816
-            $message_template_group,
1817
-            $context,
1818
-            $context_label
1819
-        );
1820
-        $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher(
1821
-            $message_template_group,
1822
-            [
1823
-                'page'    => 'espresso_messages',
1824
-                'action'  => 'edit_message_template',
1825
-                'id'      => $GRP_ID,
1826
-                'evt_id'  => $EVT_ID,
1827
-                'context' => $context,
1828
-                'extra'   => $preview_button,
1829
-            ]
1830
-        );
1831
-        $this->_template_args['before_admin_page_content'] .= $this->formEnd();
1832
-        $this->_template_args['before_admin_page_content'] .= '</div>';
1833
-        $this->_template_args['before_admin_page_content'] .= $this->editMessageFormStart();
1834
-        $this->_template_args['after_admin_page_content']  = $this->formEnd();
1835
-
1836
-        $this->_template_path = $this->_template_args['GRP_ID']
1837
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1838
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1839
-
1840
-        // send along EE_Message_Template_Group object for further template use.
1841
-        $this->_template_args['MTP'] = $message_template_group;
1842
-
1843
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1844
-            $this->_template_path,
1845
-            $this->_template_args,
1846
-            true
1847
-        );
1848
-
1849
-
1850
-        // finally, let's set the admin_page title
1851
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1852
-
1853
-
1854
-        // we need to take care of setting the shortcodes property for use elsewhere.
1855
-        $this->_set_shortcodes();
1856
-
1857
-
1858
-        // final template wrapper
1859
-        $this->display_admin_page_with_sidebar();
1860
-    }
1861
-
1862
-
1863
-    public function filter_tinymce_init($mceInit, $editor_id)
1864
-    {
1865
-        return $mceInit;
1866
-    }
1867
-
1868
-
1869
-    /**
1870
-     * Adds the activation/deactivation toggle for the message template context.
1871
-     *
1872
-     * @param EE_Message_Template_Group $message_template_group
1873
-     * @param string                    $context
1874
-     * @param string                    $context_label
1875
-     * @return string
1876
-     * @throws DomainException
1877
-     * @throws EE_Error
1878
-     * @throws InvalidIdentifierException
1879
-     * @throws ReflectionException
1880
-     */
1881
-    protected function add_active_context_element(
1882
-        EE_Message_Template_Group $message_template_group,
1883
-        $context,
1884
-        $context_label
1885
-    ): string {
1886
-        return EEH_Template::display_template(
1887
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1888
-            [
1889
-                'context'                   => $context,
1890
-                'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
-                'is_active'                 => $message_template_group->is_context_active($context),
1892
-                'on_off_action'             => $message_template_group->is_context_active($context)
1893
-                    ? 'context-off'
1894
-                    : 'context-on',
1895
-                'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
-                'message_template_group_id' => $message_template_group->ID(),
1897
-            ],
1898
-            true
1899
-        );
1900
-    }
1901
-
1902
-
1903
-    /**
1904
-     * sets up a context switcher for edit forms
1905
-     *
1906
-     * @access  protected
1907
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
1908
-     * @param array                     $args                  various things the context switcher needs.
1909
-     * @throws EE_Error
1910
-     */
1911
-    protected function add_context_switcher(EE_Message_Template_Group $template_group_object, array $args): string
1912
-    {
1913
-        return EEH_Template::display_template(
1914
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_context_switcher.template.php',
1915
-            [
1916
-                'args'              => $args,
1917
-                'context_details'   => $template_group_object->contexts_config(),
1918
-                'context_label'     => $template_group_object->context_label(),
1919
-                'context_templates' => $template_group_object->context_templates(),
1920
-            ],
1921
-            true
1922
-        );
1923
-    }
1924
-
1925
-
1926
-    /**
1927
-     * Ajax callback for `toggle_context_template` ajax action.
1928
-     * Handles toggling the message context on or off.
1929
-     *
1930
-     * @throws EE_Error
1931
-     * @throws InvalidArgumentException
1932
-     * @throws InvalidDataTypeException
1933
-     * @throws InvalidIdentifierException
1934
-     * @throws InvalidInterfaceException
1935
-     */
1936
-    public function toggle_context_template()
1937
-    {
1938
-        $success = true;
1939
-        // check for required data
1940
-        if (
1941
-            ! (
1942
-                $this->request->requestParamIsSet('message_template_group_id')
1943
-                && $this->request->requestParamIsSet('context')
1944
-                && $this->request->requestParamIsSet('status')
1945
-            )
1946
-        ) {
1947
-            EE_Error::add_error(
1948
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1949
-                __FILE__,
1950
-                __FUNCTION__,
1951
-                __LINE__
1952
-            );
1953
-            $success = false;
1954
-        }
1955
-
1956
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1957
-        $context = $this->request->getRequestParam('context', '');
1958
-        $status  = $this->request->getRequestParam('status', '');
1959
-
1960
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1961
-
1962
-        if ($status !== 'off' && $status !== 'on') {
1963
-            EE_Error::add_error(
1964
-                sprintf(
1965
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1966
-                    $status
1967
-                ),
1968
-                __FILE__,
1969
-                __FUNCTION__,
1970
-                __LINE__
1971
-            );
1972
-            $success = false;
1973
-        }
1974
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1975
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1976
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1977
-            EE_Error::add_error(
1978
-                sprintf(
1979
-                    esc_html__(
1980
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1981
-                        'event_espresso'
1982
-                    ),
1983
-                    $message_template_group_id,
1984
-                    'EE_Message_Template_Group'
1985
-                ),
1986
-                __FILE__,
1987
-                __FUNCTION__,
1988
-                __LINE__
1989
-            );
1990
-            $success = false;
1991
-        }
1992
-        if ($success) {
1993
-            $success = $status === 'off'
1994
-                ? $message_template_group->deactivate_context($context)
1995
-                : $message_template_group->activate_context($context);
1996
-        }
1997
-        $this->_template_args['success'] = $success;
1998
-        $this->_return_json();
1999
-    }
2000
-
2001
-
2002
-    public function headerFormStart(): string
2003
-    {
2004
-        $action = esc_url_raw(EE_MSG_ADMIN_URL);
2005
-        return "<form method='get' action='$action' id='ee-msg-context-switcher-frm'>";
2006
-    }
2007
-
2008
-
2009
-    public function editMessageFormStart(): string
2010
-    {
2011
-        $action = $this->_template_args['edit_message_template_form_url'];
2012
-        return "<form method ='post' action='$action' id='ee-msg-edit-frm'>";
2013
-    }
2014
-
2015
-
2016
-    public function formEnd(): string
2017
-    {
2018
-        return '</form>';
2019
-    }
2020
-
2021
-
2022
-    /**
2023
-     * This executes switching the template pack for a message template.
2024
-     *
2025
-     * @throws EE_Error
2026
-     * @throws InvalidDataTypeException
2027
-     * @throws InvalidInterfaceException
2028
-     * @throws InvalidArgumentException
2029
-     * @throws ReflectionException
2030
-     * @since 4.5.0
2031
-     */
2032
-    public function switch_template_pack()
2033
-    {
2034
-
2035
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2036
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2037
-
2038
-        // verify we have needed values.
2039
-        if (empty($GRP_ID) || empty($template_pack)) {
2040
-            $this->_template_args['error'] = true;
2041
-            EE_Error::add_error(
2042
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2043
-                __FILE__,
2044
-                __FUNCTION__,
2045
-                __LINE__
2046
-            );
2047
-        } else {
2048
-            // get template, set the new template_pack and then reset to default
2049
-            /** @var EE_Message_Template_Group $message_template_group */
2050
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2051
-
2052
-            $message_template_group->set_template_pack_name($template_pack);
2053
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2054
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2055
-
2056
-            $query_args = $this->_reset_to_default_template();
2057
-
2058
-            if (empty($query_args['id'])) {
2059
-                EE_Error::add_error(
2060
-                    esc_html__(
2061
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2062
-                        'event_espresso'
2063
-                    ),
2064
-                    __FILE__,
2065
-                    __FUNCTION__,
2066
-                    __LINE__
2067
-                );
2068
-                $this->_template_args['error'] = true;
2069
-            } else {
2070
-                $template_label       = $message_template_group->get_template_pack()->label;
2071
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2072
-                EE_Error::add_success(
2073
-                    sprintf(
2074
-                        esc_html__(
2075
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2076
-                            'event_espresso'
2077
-                        ),
2078
-                        $template_label,
2079
-                        $template_pack_labels->template_pack
2080
-                    )
2081
-                );
2082
-                // generate the redirect url for js.
2083
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2084
-
2085
-                $this->_template_args['data']['redirect_url'] = $url;
2086
-                $this->_template_args['success']              = true;
2087
-            }
2088
-
2089
-            $this->_return_json();
2090
-        }
2091
-    }
2092
-
2093
-
2094
-    /**
2095
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2096
-     * they want.
2097
-     *
2098
-     * @access protected
2099
-     * @return array|void
2100
-     * @throws EE_Error
2101
-     * @throws InvalidArgumentException
2102
-     * @throws InvalidDataTypeException
2103
-     * @throws InvalidInterfaceException
2104
-     * @throws ReflectionException
2105
-     */
2106
-    protected function _reset_to_default_template()
2107
-    {
2108
-        $templates    = [];
2109
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2110
-        $messenger    = $this->request->getRequestParam('msgr');
2111
-        $message_type = $this->request->getRequestParam('mt');
2112
-        // we need to make sure we've got the info we need.
2113
-        if (! ($GRP_ID && $messenger && $message_type)) {
2114
-            EE_Error::add_error(
2115
-                esc_html__(
2116
-                    '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.',
2117
-                    'event_espresso'
2118
-                ),
2119
-                __FILE__,
2120
-                __FUNCTION__,
2121
-                __LINE__
2122
-            );
2123
-        }
2124
-
2125
-        // all templates will be reset to whatever the defaults are
2126
-        // for the global template matching the messenger and message type.
2127
-        $success = ! empty($GRP_ID);
2128
-
2129
-        if ($success) {
2130
-            // let's first determine if the incoming template is a global template,
2131
-            // if it isn't then we need to get the global template matching messenger and message type.
2132
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2133
-
2134
-
2135
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2136
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2137
-
2138
-            if ($success) {
2139
-                // if successfully deleted, lets generate the new ones.
2140
-                // Note. We set GLOBAL to true, because resets on ANY template
2141
-                // will use the related global template defaults for regeneration.
2142
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2143
-                // HOWEVER, we DO keep the template pack and template variation set
2144
-                // for the current custom template when resetting.
2145
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2146
-            }
2147
-        }
2148
-
2149
-        // any error messages?
2150
-        if (! $success) {
2151
-            EE_Error::add_error(
2152
-                esc_html__(
2153
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2154
-                    'event_espresso'
2155
-                ),
2156
-                __FILE__,
2157
-                __FUNCTION__,
2158
-                __LINE__
2159
-            );
2160
-        }
2161
-
2162
-        // all good, let's add a success message!
2163
-        if ($success && ! empty($templates)) {
2164
-            // the info for the template we generated is the first element in the returned array
2165
-            EE_Error::overwrite_success();
2166
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2167
-        }
2168
-
2169
-
2170
-        $query_args = [
2171
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2172
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2173
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2174
-        ];
2175
-
2176
-        // if called via ajax then we return query args otherwise redirect
2177
-        if ($this->request->isAjax()) {
2178
-            return $query_args;
2179
-        }
2180
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2181
-    }
2182
-
2183
-
2184
-    /**
2185
-     * Retrieve and set the message preview for display.
2186
-     *
2187
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2188
-     * @return string
2189
-     * @throws ReflectionException
2190
-     * @throws EE_Error
2191
-     * @throws InvalidArgumentException
2192
-     * @throws InvalidDataTypeException
2193
-     * @throws InvalidInterfaceException
2194
-     */
2195
-    public function _preview_message($send = false)
2196
-    {
2197
-        // first make sure we've got the necessary parameters
2198
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2199
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2200
-            EE_Error::add_error(
2201
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2202
-                __FILE__,
2203
-                __FUNCTION__,
2204
-                __LINE__
2205
-            );
2206
-        }
2207
-
2208
-        $context = $this->request->getRequestParam('context');
2209
-        // get the preview!
2210
-        $preview = EED_Messages::preview_message(
2211
-            $this->_active_message_type_name,
2212
-            $context,
2213
-            $this->_active_messenger_name,
2214
-            $send
2215
-        );
2216
-
2217
-        if ($send) {
2218
-            return $preview;
2219
-        }
2220
-
2221
-        // if we have an evt_id set on the request, use it.
2222
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2223
-
2224
-        // let's add a button to go back to the edit view
2225
-        $query_args             = [
2226
-            'id'      => $GRP_ID,
2227
-            'evt_id'  => $EVT_ID,
2228
-            'context' => $context,
2229
-            'action'  => 'edit_message_template',
2230
-        ];
2231
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2232
-        $preview_button         = '<a href="'
2233
-                                  . $go_back_url
2234
-                                  . '" class="button--secondary messages-preview-go-back-button">'
2235
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2236
-                                  . '</a>';
2237
-        $message_types          = $this->get_installed_message_types();
2238
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2239
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2240
-            ? ucwords($active_messenger->label['singular'])
2241
-            : esc_html__('Unknown Messenger', 'event_espresso');
2242
-        // let's provide a helpful title for context
2243
-        $preview_title = sprintf(
2244
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2245
-            $active_messenger_label,
2246
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2247
-        );
2248
-        if (empty($preview)) {
2249
-            $this->noEventsErrorMessage();
2250
-        }
2251
-        // setup display of preview.
2252
-        $this->_admin_page_title                    = $preview_title;
2253
-        $this->_template_args['admin_page_title']   = $preview_title;
2254
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2255
-        $this->_template_args['data']['force_json'] = true;
2256
-
2257
-        return '';
2258
-    }
2259
-
2260
-
2261
-    /**
2262
-     * Used to set an error if there are no events available for generating a preview/test send.
2263
-     *
2264
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2265
-     */
2266
-    protected function noEventsErrorMessage($test_send = false)
2267
-    {
2268
-        $events_url = parent::add_query_args_and_nonce(
2269
-            [
2270
-                'action' => 'default',
2271
-                'page'   => 'espresso_events',
2272
-            ],
2273
-            admin_url('admin.php')
2274
-        );
2275
-        $message    = $test_send
2276
-            ? esc_html__(
2277
-                'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2278
-                'event_espresso'
2279
-            )
2280
-            : esc_html__(
2281
-                'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2282
-                'event_espresso'
2283
-            );
2284
-
2285
-        EE_Error::add_attention(
2286
-            sprintf(
2287
-                $message,
2288
-                "<a href='{$events_url}'>",
2289
-                '</a>'
2290
-            )
2291
-        );
2292
-    }
2293
-
2294
-
2295
-    /**
2296
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2297
-     * gets called automatically.
2298
-     *
2299
-     * @return void
2300
-     * @throws EE_Error
2301
-     * @since 4.5.0
2302
-     *
2303
-     */
2304
-    protected function _display_preview_message()
2305
-    {
2306
-        $this->display_admin_page_with_no_sidebar();
2307
-    }
2308
-
2309
-
2310
-    /**
2311
-     * registers metaboxes that should show up on the "edit_message_template" page
2312
-     *
2313
-     * @access protected
2314
-     * @return void
2315
-     */
2316
-    protected function _register_edit_meta_boxes()
2317
-    {
2318
-        $this->addMetaBox(
2319
-            'mtp_valid_shortcodes',
2320
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2321
-            [$this, 'shortcode_meta_box'],
2322
-            $this->_current_screen->id,
2323
-            'side'
2324
-        );
2325
-        $this->addMetaBox(
2326
-            'mtp_extra_actions',
2327
-            esc_html__('Extra Actions', 'event_espresso'),
2328
-            [$this, 'extra_actions_meta_box'],
2329
-            $this->_current_screen->id,
2330
-            'side',
2331
-            'high'
2332
-        );
2333
-        $this->addMetaBox(
2334
-            'mtp_templates',
2335
-            esc_html__('Template Styles', 'event_espresso'),
2336
-            [$this, 'template_pack_meta_box'],
2337
-            $this->_current_screen->id,
2338
-            'side',
2339
-            'high'
2340
-        );
2341
-    }
2342
-
2343
-
2344
-    /**
2345
-     * metabox content for all template pack and variation selection.
2346
-     *
2347
-     * @return void
2348
-     * @throws DomainException
2349
-     * @throws EE_Error
2350
-     * @throws InvalidArgumentException
2351
-     * @throws ReflectionException
2352
-     * @throws InvalidDataTypeException
2353
-     * @throws InvalidInterfaceException
2354
-     * @since 4.5.0
2355
-     */
2356
-    public function template_pack_meta_box()
2357
-    {
2358
-        $this->_set_message_template_group();
2359
-
2360
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2361
-
2362
-        $tp_select_values = [];
2363
-
2364
-        foreach ($tp_collection as $tp) {
2365
-            // only include template packs that support this messenger and message type!
2366
-            $supports = $tp->get_supports();
2367
-            if (
2368
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2369
-                || ! in_array(
2370
-                    $this->_message_template_group->message_type(),
2371
-                    $supports[ $this->_message_template_group->messenger() ],
2372
-                    true
2373
-                )
2374
-            ) {
2375
-                // not supported
2376
-                continue;
2377
-            }
2378
-
2379
-            $tp_select_values[] = [
2380
-                'text' => $tp->label,
2381
-                'id'   => $tp->dbref,
2382
-            ];
2383
-        }
2384
-
2385
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2386
-        // the default template pack.  This still allows for the odd template pack to override.
2387
-        if (empty($tp_select_values)) {
2388
-            $tp_select_values[] = [
2389
-                'text' => esc_html__('Default', 'event_espresso'),
2390
-                'id'   => 'default',
2391
-            ];
2392
-        }
2393
-
2394
-        // setup variation select values for the currently selected template.
2395
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2396
-            $this->_message_template_group->messenger(),
2397
-            $this->_message_template_group->message_type()
2398
-        );
2399
-        $variations_select_values = [];
2400
-        foreach ($variations as $variation => $label) {
2401
-            $variations_select_values[] = [
2402
-                'text' => $label,
2403
-                'id'   => $variation,
2404
-            ];
2405
-        }
2406
-
2407
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2408
-
2409
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2410
-            'MTP_template_pack',
2411
-            $tp_select_values,
2412
-            $this->_message_template_group->get_template_pack_name()
2413
-        );
2414
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2415
-            'MTP_template_variation',
2416
-            $variations_select_values,
2417
-            $this->_message_template_group->get_template_pack_variation()
2418
-        );
2419
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2420
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2421
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2422
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2423
-
2424
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2425
-
2426
-        EEH_Template::display_template($template, $template_args);
2427
-    }
2428
-
2429
-
2430
-    /**
2431
-     * This meta box holds any extra actions related to Message Templates
2432
-     * For now, this includes Resetting templates to defaults and sending a test email.
2433
-     *
2434
-     * @access  public
2435
-     * @return void
2436
-     * @throws EE_Error
2437
-     */
2438
-    public function extra_actions_meta_box()
2439
-    {
2440
-        $template_form_fields = [];
2441
-
2442
-        $extra_args = [
2443
-            'msgr'   => $this->_message_template_group->messenger(),
2444
-            'mt'     => $this->_message_template_group->message_type(),
2445
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2446
-        ];
2447
-        // first we need to see if there are any fields
2448
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2449
-
2450
-        if (! empty($fields)) {
2451
-            // yup there be fields
2452
-            foreach ($fields as $field => $config) {
2453
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2454
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2455
-                $default  = isset($config['default']) ? $config['default'] : '';
2456
-                $default  = isset($config['value']) ? $config['value'] : $default;
2457
-
2458
-                // if type is hidden and the value is empty
2459
-                // something may have gone wrong so let's correct with the defaults
2460
-                $fix                = $config['input'] === 'hidden'
2461
-                                      && isset($existing[ $field ])
2462
-                                      && empty($existing[ $field ])
2463
-                    ? $default
2464
-                    : '';
2465
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2466
-                    ? $existing[ $field ]
2467
-                    : $fix;
2468
-
2469
-                $template_form_fields[ $field_id ] = [
2470
-                    'name'       => 'test_settings_fld[' . $field . ']',
2471
-                    'label'      => $config['label'],
2472
-                    'input'      => $config['input'],
2473
-                    'type'       => $config['type'],
2474
-                    'required'   => $config['required'],
2475
-                    'validation' => $config['validation'],
2476
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2477
-                    'css_class'  => $config['css_class'],
2478
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2479
-                    'default'    => $default,
2480
-                    'format'     => $config['format'],
2481
-                ];
2482
-            }
2483
-        }
2484
-
2485
-        $test_settings_html = ! empty($template_form_fields)
2486
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2487
-            : '';
2488
-
2489
-        // print out $test_settings_fields
2490
-        if (! empty($test_settings_html)) {
2491
-            $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2492
-            $test_settings_html .= 'name="test_button" value="';
2493
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2494
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2495
-        }
2496
-
2497
-        // and button
2498
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2499
-        $test_settings_html .= '<p>';
2500
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2501
-        $test_settings_html .= '</p>';
2502
-        $test_settings_html .= $this->get_action_link_or_button(
2503
-            'reset_to_default',
2504
-            'reset',
2505
-            $extra_args,
2506
-            'button--primary reset-default-button'
2507
-        );
2508
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2509
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2510
-    }
2511
-
2512
-
2513
-    /**
2514
-     * This returns the shortcode selector skeleton for a given context and field.
2515
-     *
2516
-     * @param string $field           The name of the field retrieving shortcodes for.
2517
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2518
-     * @return string
2519
-     * @throws DomainException
2520
-     * @throws EE_Error
2521
-     * @throws InvalidArgumentException
2522
-     * @throws ReflectionException
2523
-     * @throws InvalidDataTypeException
2524
-     * @throws InvalidInterfaceException
2525
-     * @since 4.9.rc.000
2526
-     */
2527
-    protected function _get_shortcode_selector($field, $linked_input_id)
2528
-    {
2529
-        $template_args = [
2530
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2531
-            'fieldname'       => $field,
2532
-            'linked_input_id' => $linked_input_id,
2533
-        ];
2534
-
2535
-        return EEH_Template::display_template(
2536
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2537
-            $template_args,
2538
-            true
2539
-        );
2540
-    }
2541
-
2542
-
2543
-    /**
2544
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2545
-     * page)
2546
-     *
2547
-     * @access public
2548
-     * @return void
2549
-     * @throws EE_Error
2550
-     * @throws InvalidArgumentException
2551
-     * @throws ReflectionException
2552
-     * @throws InvalidDataTypeException
2553
-     * @throws InvalidInterfaceException
2554
-     */
2555
-    public function shortcode_meta_box()
2556
-    {
2557
-        $shortcodes = $this->_get_shortcodes([], false);
2558
-        // just make sure the shortcodes property is set
2559
-        // $messenger = $this->_message_template_group->messenger_obj();
2560
-        // now let's set the content depending on the status of the shortcodes array
2561
-        if (empty($shortcodes)) {
2562
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2563
-            return;
2564
-        }
2565
-        ?>
20
+	/**
21
+	 * @var EEM_Message
22
+	 */
23
+	private $MSG_MODEL;
24
+
25
+	/**
26
+	 * @var EEM_Message_Template
27
+	 */
28
+	private $MTP_MODEL;
29
+
30
+	/**
31
+	 * @var EEM_Message_Template_Group
32
+	 */
33
+	private $MTG_MODEL;
34
+
35
+	/**
36
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
37
+	 */
38
+	protected $_message_resource_manager;
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	protected $_active_message_type_name = '';
44
+
45
+	/**
46
+	 * @var string
47
+	 */
48
+	protected $_active_messenger_name = '';
49
+
50
+	/**
51
+	 * @var EE_messenger $_active_messenger
52
+	 */
53
+	protected $_active_messenger;
54
+
55
+	protected $_activate_meta_box_type;
56
+
57
+	protected $_current_message_meta_box;
58
+
59
+	protected $_current_message_meta_box_object;
60
+
61
+	protected $_shortcodes           = [];
62
+
63
+	protected $_active_messengers    = [];
64
+
65
+	protected $_active_message_types = [];
66
+
67
+	/**
68
+	 * @var EE_Message_Template_Group $_message_template_group
69
+	 */
70
+	protected $_message_template_group;
71
+
72
+	protected $_m_mt_settings = [];
73
+
74
+
75
+	/**
76
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
77
+	 * IF there is no group then it gets automatically set to the Default template pack.
78
+	 *
79
+	 * @since 4.5.0
80
+	 *
81
+	 * @var EE_Messages_Template_Pack
82
+	 */
83
+	protected $_template_pack;
84
+
85
+
86
+	/**
87
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
88
+	 * group is.  If there is no group then it automatically gets set to default.
89
+	 *
90
+	 * @since 4.5.0
91
+	 *
92
+	 * @var string
93
+	 */
94
+	protected $_variation;
95
+
96
+
97
+	/**
98
+	 * @param bool $routing
99
+	 * @throws EE_Error
100
+	 * @throws ReflectionException
101
+	 */
102
+	public function __construct($routing = true)
103
+	{
104
+		// make sure messages autoloader is running
105
+		EED_Messages::set_autoloaders();
106
+		parent::__construct($routing);
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return EEM_Message
112
+	 * @throws EE_Error
113
+	 */
114
+	public function getMsgModel()
115
+	{
116
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
117
+			$this->MSG_MODEL = EEM_Message::instance();
118
+		}
119
+		return $this->MSG_MODEL;
120
+	}
121
+
122
+
123
+	/**
124
+	 * @return EEM_Message_Template
125
+	 * @throws EE_Error
126
+	 */
127
+	public function getMtpModel()
128
+	{
129
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
130
+			$this->MTP_MODEL = EEM_Message_Template::instance();
131
+		}
132
+		return $this->MTP_MODEL;
133
+	}
134
+
135
+
136
+	/**
137
+	 * @return EEM_Message_Template_Group
138
+	 * @throws EE_Error
139
+	 */
140
+	public function getMtgModel()
141
+	{
142
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
143
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
144
+		}
145
+		return $this->MTG_MODEL;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @throws EE_Error
151
+	 * @throws ReflectionException
152
+	 */
153
+	protected function _init_page_props()
154
+	{
155
+		$this->page_slug        = EE_MSG_PG_SLUG;
156
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
157
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
158
+		$this->_admin_base_path = EE_MSG_ADMIN;
159
+
160
+		$messenger    = $this->request->getRequestParam('messenger', '');
161
+		$message_type = $this->request->getRequestParam('message_type', '');
162
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
163
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
164
+
165
+		$this->_load_message_resource_manager();
166
+	}
167
+
168
+
169
+	/**
170
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
171
+	 *
172
+	 * @throws EE_Error
173
+	 * @throws InvalidDataTypeException
174
+	 * @throws InvalidInterfaceException
175
+	 * @throws InvalidArgumentException
176
+	 * @throws ReflectionException
177
+	 */
178
+	protected function _load_message_resource_manager()
179
+	{
180
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
181
+	}
182
+
183
+
184
+	/**
185
+	 * @return array
186
+	 * @throws EE_Error
187
+	 * @throws InvalidArgumentException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidInterfaceException
190
+	 * @deprecated 4.9.9.rc.014
191
+	 */
192
+	public function get_messengers_for_list_table()
193
+	{
194
+		EE_Error::doing_it_wrong(
195
+			__METHOD__,
196
+			sprintf(
197
+				esc_html__(
198
+					'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',
199
+					'event_espresso'
200
+				),
201
+				'Messages_Admin_Page::get_messengers_select_input()'
202
+			),
203
+			'4.9.9.rc.014'
204
+		);
205
+
206
+		$m_values          = [];
207
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
208
+		// setup messengers for selects
209
+		$i = 1;
210
+		foreach ($active_messengers as $active_messenger) {
211
+			if ($active_messenger instanceof EE_Message) {
212
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
213
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
214
+				$i++;
215
+			}
216
+		}
217
+
218
+		return $m_values;
219
+	}
220
+
221
+
222
+	/**
223
+	 * @return array
224
+	 * @throws EE_Error
225
+	 * @throws InvalidArgumentException
226
+	 * @throws InvalidDataTypeException
227
+	 * @throws InvalidInterfaceException
228
+	 * @deprecated 4.9.9.rc.014
229
+	 */
230
+	public function get_message_types_for_list_table()
231
+	{
232
+		EE_Error::doing_it_wrong(
233
+			__METHOD__,
234
+			sprintf(
235
+				esc_html__(
236
+					'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',
237
+					'event_espresso'
238
+				),
239
+				'Messages_Admin_Page::get_message_types_select_input()'
240
+			),
241
+			'4.9.9.rc.014'
242
+		);
243
+
244
+		$mt_values       = [];
245
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
246
+		$i               = 1;
247
+		foreach ($active_messages as $active_message) {
248
+			if ($active_message instanceof EE_Message) {
249
+				$mt_values[ $i ]['id']   = $active_message->message_type();
250
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
251
+				$i++;
252
+			}
253
+		}
254
+
255
+		return $mt_values;
256
+	}
257
+
258
+
259
+	/**
260
+	 * @return array
261
+	 * @throws EE_Error
262
+	 * @throws InvalidArgumentException
263
+	 * @throws InvalidDataTypeException
264
+	 * @throws InvalidInterfaceException
265
+	 * @deprecated 4.9.9.rc.014
266
+	 */
267
+	public function get_contexts_for_message_types_for_list_table()
268
+	{
269
+		EE_Error::doing_it_wrong(
270
+			__METHOD__,
271
+			sprintf(
272
+				esc_html__(
273
+					'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',
274
+					'event_espresso'
275
+				),
276
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
277
+			),
278
+			'4.9.9.rc.014'
279
+		);
280
+
281
+		$contexts                = [];
282
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
283
+		foreach ($active_message_contexts as $active_message) {
284
+			if ($active_message instanceof EE_Message) {
285
+				$message_type = $active_message->message_type_object();
286
+				if ($message_type instanceof EE_message_type) {
287
+					$message_type_contexts = $message_type->get_contexts();
288
+					foreach ($message_type_contexts as $context => $context_details) {
289
+						$contexts[ $context ] = $context_details['label'];
290
+					}
291
+				}
292
+			}
293
+		}
294
+
295
+		return $contexts;
296
+	}
297
+
298
+
299
+	/**
300
+	 * Generate select input with provided messenger options array.
301
+	 *
302
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
303
+	 *                                 labels.
304
+	 * @return string
305
+	 * @throws EE_Error
306
+	 */
307
+	public function get_messengers_select_input($messenger_options)
308
+	{
309
+		// if empty or just one value then just return an empty string
310
+		if (
311
+			empty($messenger_options)
312
+			|| ! is_array($messenger_options)
313
+			|| count($messenger_options) === 1
314
+		) {
315
+			return '';
316
+		}
317
+		// merge in default
318
+		$messenger_options = array_merge(
319
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
320
+			$messenger_options
321
+		);
322
+		$input             = new EE_Select_Input(
323
+			$messenger_options,
324
+			[
325
+				'html_name'  => 'ee_messenger_filter_by',
326
+				'html_id'    => 'ee_messenger_filter_by',
327
+				'html_class' => 'wide',
328
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
329
+			]
330
+		);
331
+
332
+		return $input->get_html_for_input();
333
+	}
334
+
335
+
336
+	/**
337
+	 * Generate select input with provided message type options array.
338
+	 *
339
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
340
+	 *                                    message type labels
341
+	 * @return string
342
+	 * @throws EE_Error
343
+	 */
344
+	public function get_message_types_select_input($message_type_options)
345
+	{
346
+		// if empty or count of options is 1 then just return an empty string
347
+		if (
348
+			empty($message_type_options)
349
+			|| ! is_array($message_type_options)
350
+			|| count($message_type_options) === 1
351
+		) {
352
+			return '';
353
+		}
354
+		// merge in default
355
+		$message_type_options = array_merge(
356
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
357
+			$message_type_options
358
+		);
359
+		$input                = new EE_Select_Input(
360
+			$message_type_options,
361
+			[
362
+				'html_name'  => 'ee_message_type_filter_by',
363
+				'html_id'    => 'ee_message_type_filter_by',
364
+				'html_class' => 'wide',
365
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
366
+			]
367
+		);
368
+
369
+		return $input->get_html_for_input();
370
+	}
371
+
372
+
373
+	/**
374
+	 * Generate select input with provide message type contexts array.
375
+	 *
376
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
377
+	 *                               context label.
378
+	 * @return string
379
+	 * @throws EE_Error
380
+	 */
381
+	public function get_contexts_for_message_types_select_input($context_options)
382
+	{
383
+		// if empty or count of options is one then just return empty string
384
+		if (
385
+			empty($context_options)
386
+			|| ! is_array($context_options)
387
+			|| count($context_options) === 1
388
+		) {
389
+			return '';
390
+		}
391
+		// merge in default
392
+		$context_options = array_merge(
393
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
394
+			$context_options
395
+		);
396
+		$input           = new EE_Select_Input(
397
+			$context_options,
398
+			[
399
+				'html_name'  => 'ee_context_filter_by',
400
+				'html_id'    => 'ee_context_filter_by',
401
+				'html_class' => 'wide',
402
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
403
+			]
404
+		);
405
+
406
+		return $input->get_html_for_input();
407
+	}
408
+
409
+
410
+	protected function _ajax_hooks()
411
+	{
412
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
413
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
414
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
415
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
416
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
417
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
418
+	}
419
+
420
+
421
+	protected function _define_page_props()
422
+	{
423
+		$this->_admin_page_title = $this->page_label;
424
+		$this->_labels           = [
425
+			'buttons'    => [
426
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
427
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
428
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
429
+			],
430
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
431
+		];
432
+	}
433
+
434
+
435
+	/**
436
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
437
+	 *
438
+	 * @access protected
439
+	 * @return void
440
+	 */
441
+	protected function _set_page_routes()
442
+	{
443
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
444
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
445
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
446
+
447
+		$this->_page_routes = [
448
+			'default'                          => [
449
+				'func'       => '_message_queue_list_table',
450
+				'capability' => 'ee_read_global_messages',
451
+			],
452
+			'global_mtps'                      => [
453
+				'func'       => '_ee_default_messages_overview_list_table',
454
+				'capability' => 'ee_read_global_messages',
455
+			],
456
+			'custom_mtps'                      => [
457
+				'func'       => '_custom_mtps_preview',
458
+				'capability' => 'ee_read_messages',
459
+			],
460
+			'add_new_message_template'         => [
461
+				'func'       => 'add_message_template',
462
+				'capability' => 'ee_edit_messages',
463
+				'noheader'   => true,
464
+			],
465
+			'edit_message_template'            => [
466
+				'func'       => '_edit_message_template',
467
+				'capability' => 'ee_edit_message',
468
+				'obj_id'     => $GRP_ID,
469
+			],
470
+			'preview_message'                  => [
471
+				'func'               => '_preview_message',
472
+				'capability'         => 'ee_read_message',
473
+				'obj_id'             => $GRP_ID,
474
+				'noheader'           => true,
475
+				'headers_sent_route' => 'display_preview_message',
476
+			],
477
+			'display_preview_message'          => [
478
+				'func'       => '_display_preview_message',
479
+				'capability' => 'ee_read_message',
480
+				'obj_id'     => $GRP_ID,
481
+			],
482
+			'insert_message_template'          => [
483
+				'func'       => '_insert_or_update_message_template',
484
+				'capability' => 'ee_edit_messages',
485
+				'args'       => ['new' => true],
486
+				'noheader'   => true,
487
+			],
488
+			'update_message_template'          => [
489
+				'func'       => '_insert_or_update_message_template',
490
+				'capability' => 'ee_edit_message',
491
+				'obj_id'     => $GRP_ID,
492
+				'args'       => ['new' => false],
493
+				'noheader'   => true,
494
+			],
495
+			'trash_message_template'           => [
496
+				'func'       => '_trash_or_restore_message_template',
497
+				'capability' => 'ee_delete_message',
498
+				'obj_id'     => $GRP_ID,
499
+				'args'       => ['trash' => true, 'all' => true],
500
+				'noheader'   => true,
501
+			],
502
+			'trash_message_template_context'   => [
503
+				'func'       => '_trash_or_restore_message_template',
504
+				'capability' => 'ee_delete_message',
505
+				'obj_id'     => $GRP_ID,
506
+				'args'       => ['trash' => true],
507
+				'noheader'   => true,
508
+			],
509
+			'restore_message_template'         => [
510
+				'func'       => '_trash_or_restore_message_template',
511
+				'capability' => 'ee_delete_message',
512
+				'obj_id'     => $GRP_ID,
513
+				'args'       => ['trash' => false, 'all' => true],
514
+				'noheader'   => true,
515
+			],
516
+			'restore_message_template_context' => [
517
+				'func'       => '_trash_or_restore_message_template',
518
+				'capability' => 'ee_delete_message',
519
+				'obj_id'     => $GRP_ID,
520
+				'args'       => ['trash' => false],
521
+				'noheader'   => true,
522
+			],
523
+			'delete_message_template'          => [
524
+				'func'       => '_delete_message_template',
525
+				'capability' => 'ee_delete_message',
526
+				'obj_id'     => $GRP_ID,
527
+				'noheader'   => true,
528
+			],
529
+			'reset_to_default'                 => [
530
+				'func'       => '_reset_to_default_template',
531
+				'capability' => 'ee_edit_message',
532
+				'obj_id'     => $GRP_ID,
533
+				'noheader'   => true,
534
+			],
535
+			'settings'                         => [
536
+				'func'       => '_settings',
537
+				'capability' => 'manage_options',
538
+			],
539
+			'update_global_settings'           => [
540
+				'func'       => '_update_global_settings',
541
+				'capability' => 'manage_options',
542
+				'noheader'   => true,
543
+			],
544
+			'generate_now'                     => [
545
+				'func'       => '_generate_now',
546
+				'capability' => 'ee_send_message',
547
+				'noheader'   => true,
548
+			],
549
+			'generate_and_send_now'            => [
550
+				'func'       => '_generate_and_send_now',
551
+				'capability' => 'ee_send_message',
552
+				'noheader'   => true,
553
+			],
554
+			'queue_for_resending'              => [
555
+				'func'       => '_queue_for_resending',
556
+				'capability' => 'ee_send_message',
557
+				'noheader'   => true,
558
+			],
559
+			'send_now'                         => [
560
+				'func'       => '_send_now',
561
+				'capability' => 'ee_send_message',
562
+				'noheader'   => true,
563
+			],
564
+			'delete_ee_message'                => [
565
+				'func'       => '_delete_ee_messages',
566
+				'capability' => 'ee_delete_messages',
567
+				'noheader'   => true,
568
+			],
569
+			'delete_ee_messages'               => [
570
+				'func'       => '_delete_ee_messages',
571
+				'capability' => 'ee_delete_messages',
572
+				'noheader'   => true,
573
+				'obj_id'     => $MSG_ID,
574
+			],
575
+		];
576
+	}
577
+
578
+
579
+	protected function _set_page_config()
580
+	{
581
+		$this->_page_config = [
582
+			'default'                  => [
583
+				'nav'           => [
584
+					'label' => esc_html__('Message Activity', 'event_espresso'),
585
+					'icon' => 'dashicons-email',
586
+					'order' => 10,
587
+				],
588
+				'list_table'    => 'EE_Message_List_Table',
589
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
590
+				'require_nonce' => false,
591
+			],
592
+			'global_mtps'              => [
593
+				'nav'           => [
594
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
595
+					'icon' => 'dashicons-layout',
596
+					'order' => 20,
597
+				],
598
+				'list_table'    => 'Messages_Template_List_Table',
599
+				'help_tabs'     => [
600
+					'messages_overview_help_tab'                                => [
601
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
+						'filename' => 'messages_overview',
603
+					],
604
+					'messages_overview_messages_table_column_headings_help_tab' => [
605
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
+						'filename' => 'messages_overview_table_column_headings',
607
+					],
608
+					'messages_overview_messages_filters_help_tab'               => [
609
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
610
+						'filename' => 'messages_overview_filters',
611
+					],
612
+					'messages_overview_messages_views_help_tab'                 => [
613
+						'title'    => esc_html__('Message Views', 'event_espresso'),
614
+						'filename' => 'messages_overview_views',
615
+					],
616
+					'message_overview_message_types_help_tab'                   => [
617
+						'title'    => esc_html__('Message Types', 'event_espresso'),
618
+						'filename' => 'messages_overview_types',
619
+					],
620
+					'messages_overview_messengers_help_tab'                     => [
621
+						'title'    => esc_html__('Messengers', 'event_espresso'),
622
+						'filename' => 'messages_overview_messengers',
623
+					],
624
+				],
625
+				'require_nonce' => false,
626
+			],
627
+			'custom_mtps'              => [
628
+				'nav'           => [
629
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
+					'icon' => 'dashicons-admin-customizer',
631
+					'order' => 30,
632
+				],
633
+				'help_tabs'     => [],
634
+				'require_nonce' => false,
635
+			],
636
+			'add_new_message_template' => [
637
+				'nav'           => [
638
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
639
+					'icon' => 'dashicons-plus-alt',
640
+					'order'      => 5,
641
+					'persistent' => false,
642
+				],
643
+				'require_nonce' => false,
644
+			],
645
+			'edit_message_template'    => [
646
+				'labels'        => [
647
+					'buttons'    => [
648
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
649
+					],
650
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
651
+				],
652
+				'nav'           => [
653
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
654
+					'icon' => 'dashicons-edit-large',
655
+					'order'      => 5,
656
+					'persistent' => false,
657
+					'url'        => '',
658
+				],
659
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
660
+				'has_metaboxes' => true,
661
+				'help_tabs'     => [
662
+					'edit_message_template'            => [
663
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
664
+						'callback' => 'edit_message_template_help_tab',
665
+					],
666
+					'message_templates_help_tab'       => [
667
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
668
+						'filename' => 'messages_templates',
669
+					],
670
+					'message_template_shortcodes'      => [
671
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
672
+						'callback' => 'message_template_shortcodes_help_tab',
673
+					],
674
+					'message_preview_help_tab'         => [
675
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
676
+						'filename' => 'messages_preview',
677
+					],
678
+					'messages_overview_other_help_tab' => [
679
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
680
+						'filename' => 'messages_overview_other',
681
+					],
682
+				],
683
+				'require_nonce' => false,
684
+			],
685
+			'display_preview_message'  => [
686
+				'nav'           => [
687
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
688
+					'icon' => 'dashicons-visibility-bar',
689
+					'order'      => 5,
690
+					'url'        => '',
691
+					'persistent' => false,
692
+				],
693
+				'help_tabs'     => [
694
+					'preview_message' => [
695
+						'title'    => esc_html__('About Previews', 'event_espresso'),
696
+						'callback' => 'preview_message_help_tab',
697
+					],
698
+				],
699
+				'require_nonce' => false,
700
+			],
701
+			'settings'                 => [
702
+				'nav'           => [
703
+					'label' => esc_html__('Settings', 'event_espresso'),
704
+					'icon' => 'dashicons-admin-generic',
705
+					'order' => 40,
706
+				],
707
+				'metaboxes'     => ['_messages_settings_metaboxes'],
708
+				'help_tabs'     => [
709
+					'messages_settings_help_tab'               => [
710
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
711
+						'filename' => 'messages_settings',
712
+					],
713
+					'messages_settings_message_types_help_tab' => [
714
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
715
+						'filename' => 'messages_settings_message_types',
716
+					],
717
+					'messages_settings_messengers_help_tab'    => [
718
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
719
+						'filename' => 'messages_settings_messengers',
720
+					],
721
+				],
722
+				'require_nonce' => false,
723
+			],
724
+		];
725
+	}
726
+
727
+
728
+	protected function _add_screen_options()
729
+	{
730
+		// todo
731
+	}
732
+
733
+
734
+	protected function _add_screen_options_global_mtps()
735
+	{
736
+		/**
737
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
738
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
739
+		 */
740
+		$page_title              = $this->_admin_page_title;
741
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
742
+		$this->_per_page_screen_option();
743
+		$this->_admin_page_title = $page_title;
744
+	}
745
+
746
+
747
+	protected function _add_screen_options_default()
748
+	{
749
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
750
+		$this->_per_page_screen_option();
751
+	}
752
+
753
+
754
+	// none of the below group are currently used for Messages
755
+	protected function _add_feature_pointers()
756
+	{
757
+	}
758
+
759
+
760
+	public function admin_init()
761
+	{
762
+	}
763
+
764
+
765
+	public function admin_notices()
766
+	{
767
+	}
768
+
769
+
770
+	public function admin_footer_scripts()
771
+	{
772
+	}
773
+
774
+
775
+	public function messages_help_tab()
776
+	{
777
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
778
+	}
779
+
780
+
781
+	public function messengers_help_tab()
782
+	{
783
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
784
+	}
785
+
786
+
787
+	public function message_types_help_tab()
788
+	{
789
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
790
+	}
791
+
792
+
793
+	public function messages_overview_help_tab()
794
+	{
795
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
796
+	}
797
+
798
+
799
+	public function message_templates_help_tab()
800
+	{
801
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
802
+	}
803
+
804
+
805
+	public function edit_message_template_help_tab()
806
+	{
807
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
808
+						. esc_attr__('Editor Title', 'event_espresso')
809
+						. '" />';
810
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
811
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
812
+						. '" />';
813
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
814
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
815
+						. '" />';
816
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
817
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
818
+						. '" />';
819
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
820
+						. esc_attr__('Publish Metabox', 'event_espresso')
821
+						. '" />';
822
+		EEH_Template::display_template(
823
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
824
+			$args
825
+		);
826
+	}
827
+
828
+
829
+	/**
830
+	 * @throws ReflectionException
831
+	 * @throws EE_Error
832
+	 */
833
+	public function message_template_shortcodes_help_tab()
834
+	{
835
+		$this->_set_shortcodes();
836
+		$args['shortcodes'] = $this->_shortcodes;
837
+		EEH_Template::display_template(
838
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
839
+			$args
840
+		);
841
+	}
842
+
843
+
844
+	public function preview_message_help_tab()
845
+	{
846
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
847
+	}
848
+
849
+
850
+	public function settings_help_tab()
851
+	{
852
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
853
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
854
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
855
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
856
+		$args['img3'] = '<div class="ee-switch">'
857
+						. '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
858
+						. '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
859
+						. '</div>';
860
+		$args['img4'] = '<div class="switch">'
861
+						. '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
862
+						. '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
863
+						. '</div>';
864
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
865
+	}
866
+
867
+
868
+	public function load_scripts_styles()
869
+	{
870
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
871
+		wp_enqueue_style('espresso_ee_msg');
872
+
873
+		wp_register_script(
874
+			'ee-messages-settings',
875
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
876
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
877
+			EVENT_ESPRESSO_VERSION,
878
+			true
879
+		);
880
+		wp_register_script(
881
+			'ee-msg-list-table-js',
882
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
883
+			['ee-dialog'],
884
+			EVENT_ESPRESSO_VERSION
885
+		);
886
+	}
887
+
888
+
889
+	public function load_scripts_styles_default()
890
+	{
891
+		wp_enqueue_script('ee-msg-list-table-js');
892
+	}
893
+
894
+
895
+	public function wp_editor_css($mce_css)
896
+	{
897
+		// if we're on the edit_message_template route
898
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
899
+			$message_type_name = $this->_active_message_type_name;
900
+
901
+			// we're going to REPLACE the existing mce css
902
+			// we need to get the css file location from the active messenger
903
+			$mce_css = $this->_active_messenger->get_variation(
904
+				$this->_template_pack,
905
+				$message_type_name,
906
+				true,
907
+				'wpeditor',
908
+				$this->_variation
909
+			);
910
+		}
911
+
912
+		return $mce_css;
913
+	}
914
+
915
+
916
+	/**
917
+	 * @throws EE_Error
918
+	 * @throws ReflectionException
919
+	 */
920
+	public function load_scripts_styles_edit_message_template()
921
+	{
922
+
923
+		$this->_set_shortcodes();
924
+
925
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
926
+			esc_html__(
927
+				'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.',
928
+				'event_espresso'
929
+			),
930
+			$this->_message_template_group->messenger_obj()->label['singular'],
931
+			$this->_message_template_group->message_type_obj()->label['singular']
932
+		);
933
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
934
+			'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?',
935
+			'event_espresso'
936
+		);
937
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
938
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
939
+			'event_espresso'
940
+		);
941
+
942
+		wp_register_script(
943
+			'ee_msgs_edit_js',
944
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
945
+			['jquery'],
946
+			EVENT_ESPRESSO_VERSION
947
+		);
948
+
949
+		wp_enqueue_script('ee_admin_js');
950
+		wp_enqueue_script('ee_msgs_edit_js');
951
+
952
+		// add in special css for tiny_mce
953
+		add_filter('mce_css', [$this, 'wp_editor_css']);
954
+	}
955
+
956
+
957
+	/**
958
+	 * @throws EE_Error
959
+	 * @throws ReflectionException
960
+	 */
961
+	public function load_scripts_styles_display_preview_message()
962
+	{
963
+		$this->_set_message_template_group();
964
+		if ($this->_active_messenger_name) {
965
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
966
+				$this->_active_messenger_name
967
+			);
968
+		}
969
+
970
+		wp_enqueue_style(
971
+			'espresso_preview_css',
972
+			$this->_active_messenger->get_variation(
973
+				$this->_template_pack,
974
+				$this->_active_message_type_name,
975
+				true,
976
+				'preview',
977
+				$this->_variation
978
+			)
979
+		);
980
+	}
981
+
982
+
983
+	public function load_scripts_styles_settings()
984
+	{
985
+		wp_register_style(
986
+			'ee-message-settings',
987
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
988
+			[],
989
+			EVENT_ESPRESSO_VERSION
990
+		);
991
+		wp_enqueue_style('ee-text-links');
992
+		wp_enqueue_style('ee-message-settings');
993
+		wp_enqueue_script('ee-messages-settings');
994
+	}
995
+
996
+
997
+	/**
998
+	 * set views array for List Table
999
+	 */
1000
+	public function _set_list_table_views_global_mtps()
1001
+	{
1002
+		$this->_views = [
1003
+			'in_use' => [
1004
+				'slug'  => 'in_use',
1005
+				'label' => esc_html__('In Use', 'event_espresso'),
1006
+				'count' => 0,
1007
+			],
1008
+		];
1009
+	}
1010
+
1011
+
1012
+	/**
1013
+	 * Set views array for the Custom Template List Table
1014
+	 */
1015
+	public function _set_list_table_views_custom_mtps()
1016
+	{
1017
+		$this->_set_list_table_views_global_mtps();
1018
+		$this->_views['in_use']['bulk_action'] = [
1019
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1020
+		];
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * set views array for message queue list table
1026
+	 *
1027
+	 * @throws InvalidDataTypeException
1028
+	 * @throws InvalidInterfaceException
1029
+	 * @throws InvalidArgumentException
1030
+	 * @throws EE_Error
1031
+	 * @throws ReflectionException
1032
+	 */
1033
+	public function _set_list_table_views_default()
1034
+	{
1035
+		EE_Registry::instance()->load_helper('Template');
1036
+
1037
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1038
+			'ee_send_message',
1039
+			'message_list_table_bulk_actions'
1040
+		)
1041
+			? [
1042
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1043
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1044
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1045
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1046
+			]
1047
+			: [];
1048
+
1049
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1050
+			'ee_delete_messages',
1051
+			'message_list_table_bulk_actions'
1052
+		)
1053
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1054
+			: [];
1055
+
1056
+
1057
+		$this->_views = [
1058
+			'all' => [
1059
+				'slug'        => 'all',
1060
+				'label'       => esc_html__('All', 'event_espresso'),
1061
+				'count'       => 0,
1062
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1063
+			],
1064
+		];
1065
+
1066
+
1067
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1068
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1069
+				continue;
1070
+			}
1071
+			$status_bulk_actions = $common_bulk_actions;
1072
+			// unset bulk actions not applying to status
1073
+			if (! empty($status_bulk_actions)) {
1074
+				switch ($status) {
1075
+					case EEM_Message::status_idle:
1076
+					case EEM_Message::status_resend:
1077
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1078
+						break;
1079
+
1080
+					case EEM_Message::status_failed:
1081
+					case EEM_Message::status_debug_only:
1082
+					case EEM_Message::status_messenger_executing:
1083
+						$status_bulk_actions = [];
1084
+						break;
1085
+
1086
+					case EEM_Message::status_incomplete:
1087
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1088
+						break;
1089
+
1090
+					case EEM_Message::status_retry:
1091
+					case EEM_Message::status_sent:
1092
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1093
+						break;
1094
+				}
1095
+			}
1096
+
1097
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1098
+			if ($status === EEM_Message::status_messenger_executing) {
1099
+				continue;
1100
+			}
1101
+
1102
+			$this->_views[ strtolower($status) ] = [
1103
+				'slug'        => strtolower($status),
1104
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1105
+				'count'       => 0,
1106
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1107
+			];
1108
+		}
1109
+	}
1110
+
1111
+
1112
+	/**
1113
+	 * @throws EE_Error
1114
+	 */
1115
+	protected function _ee_default_messages_overview_list_table()
1116
+	{
1117
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1118
+		$this->display_admin_list_table_page_with_no_sidebar();
1119
+	}
1120
+
1121
+
1122
+	/**
1123
+	 * @throws EE_Error
1124
+	 * @throws ReflectionException
1125
+	 */
1126
+	protected function _message_queue_list_table()
1127
+	{
1128
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1129
+		$this->_template_args['per_column']        = 6;
1130
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1131
+		$message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1132
+		$this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1133
+		$this->display_admin_list_table_page_with_no_sidebar();
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * @throws EE_Error
1139
+	 */
1140
+	protected function _message_legend_items()
1141
+	{
1142
+
1143
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1144
+		$action_items       = [];
1145
+
1146
+		foreach ($action_css_classes as $action_item => $action_details) {
1147
+			if ($action_item === 'see_notifications_for') {
1148
+				continue;
1149
+			}
1150
+			$action_items[ $action_item ] = [
1151
+				'class' => $action_details['css_class'],
1152
+				'desc'  => $action_details['label'],
1153
+			];
1154
+		}
1155
+
1156
+		/** @var array $status_items status legend setup */
1157
+		$status_items = [
1158
+			'sent_status'                => [
1159
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1160
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1161
+			],
1162
+			'idle_status'                => [
1163
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1164
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1165
+			],
1166
+			'failed_status'              => [
1167
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1168
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1169
+			],
1170
+			'messenger_executing_status' => [
1171
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1172
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1173
+			],
1174
+			'resend_status'              => [
1175
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1176
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1177
+			],
1178
+			'incomplete_status'          => [
1179
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1180
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1181
+			],
1182
+			'retry_status'               => [
1183
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1184
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1185
+			],
1186
+		];
1187
+		if (EEM_Message::debug()) {
1188
+			$status_items['debug_only_status'] = [
1189
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1190
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1191
+			];
1192
+		}
1193
+
1194
+		return array_merge($action_items, $status_items);
1195
+	}
1196
+
1197
+
1198
+	/**
1199
+	 * @throws EE_Error
1200
+	 */
1201
+	protected function _custom_mtps_preview()
1202
+	{
1203
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1204
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1205
+												. ' alt="' . esc_attr__(
1206
+													'Preview Custom Message Templates screenshot',
1207
+													'event_espresso'
1208
+												) . '" />';
1209
+		$this->_template_args['preview_text'] = '<strong>'
1210
+												. esc_html__(
1211
+													'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.',
1212
+													'event_espresso'
1213
+												)
1214
+												. '</strong>';
1215
+
1216
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1217
+	}
1218
+
1219
+
1220
+	/**
1221
+	 * get_message_templates
1222
+	 * This gets all the message templates for listing on the overview list.
1223
+	 *
1224
+	 * @access public
1225
+	 * @param int    $per_page the amount of templates groups to show per page
1226
+	 * @param string $type     the current _view we're getting templates for
1227
+	 * @param bool   $count    return count?
1228
+	 * @param bool   $all      disregard any paging info (get all data);
1229
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1230
+	 * @return array
1231
+	 * @throws EE_Error
1232
+	 * @throws InvalidArgumentException
1233
+	 * @throws InvalidDataTypeException
1234
+	 * @throws InvalidInterfaceException
1235
+	 */
1236
+	public function get_message_templates(
1237
+		$per_page = 10,
1238
+		$type = 'in_use',
1239
+		$count = false,
1240
+		$all = false,
1241
+		$global = true
1242
+	) {
1243
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1244
+		$this->request->setRequestParam('orderby', $orderby);
1245
+
1246
+		$order        = $this->request->getRequestParam('order', 'ASC');
1247
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1248
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1249
+
1250
+		$offset = ($current_page - 1) * $per_page;
1251
+		$limit  = $all ? null : [$offset, $per_page];
1252
+
1253
+		// options will match what is in the _views array property
1254
+		return $type === 'in_use'
1255
+			? $this->getMtgModel()->get_all_active_message_templates(
1256
+				$orderby,
1257
+				$order,
1258
+				$limit,
1259
+				$count,
1260
+				$global,
1261
+				true
1262
+			)
1263
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1264
+				$orderby,
1265
+				$order,
1266
+				$limit,
1267
+				$count,
1268
+				$global
1269
+			);
1270
+	}
1271
+
1272
+
1273
+	/**
1274
+	 * filters etc might need a list of installed message_types
1275
+	 *
1276
+	 * @return array an array of message type objects
1277
+	 */
1278
+	public function get_installed_message_types()
1279
+	{
1280
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1281
+		$installed               = [];
1282
+
1283
+		foreach ($installed_message_types as $message_type) {
1284
+			$installed[ $message_type->name ] = $message_type;
1285
+		}
1286
+
1287
+		return $installed;
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1293
+	 *
1294
+	 * @param string $message_type
1295
+	 * @param string $messenger
1296
+	 * @param string $GRP_ID
1297
+	 *
1298
+	 * @throws EE_error
1299
+	 * @throws ReflectionException
1300
+	 */
1301
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1302
+	{
1303
+		// set values override any request data
1304
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1305
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1306
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1307
+
1308
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1309
+		if (empty($message_type) || empty($messenger)) {
1310
+			throw new EE_Error(
1311
+				esc_html__(
1312
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1313
+					'event_espresso'
1314
+				)
1315
+			);
1316
+		}
1317
+
1318
+		// we need the GRP_ID for the template being used as the base for the new template
1319
+		if (empty($GRP_ID)) {
1320
+			throw new EE_Error(
1321
+				esc_html__(
1322
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1323
+					'event_espresso'
1324
+				)
1325
+			);
1326
+		}
1327
+
1328
+		// let's just make sure the template gets generated!
1329
+
1330
+		// we need to reassign some variables for what the insert is expecting
1331
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1332
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1333
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1334
+
1335
+		$this->_insert_or_update_message_template(true);
1336
+	}
1337
+
1338
+
1339
+	/**
1340
+	 * @param string $message_type     message type slug
1341
+	 * @param string $messenger        messenger slug
1342
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1343
+	 *                                 off of.
1344
+	 * @throws EE_error
1345
+	 * @throws ReflectionException
1346
+	 * @deprecated 4.10.29.p
1347
+	 */
1348
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1349
+	{
1350
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1351
+	}
1352
+
1353
+
1354
+	/**
1355
+	 * _edit_message_template
1356
+	 *
1357
+	 * @access protected
1358
+	 * @return void
1359
+	 * @throws InvalidIdentifierException
1360
+	 * @throws DomainException
1361
+	 * @throws EE_Error
1362
+	 * @throws InvalidArgumentException
1363
+	 * @throws ReflectionException
1364
+	 * @throws InvalidDataTypeException
1365
+	 * @throws InvalidInterfaceException
1366
+	 */
1367
+	protected function _edit_message_template()
1368
+	{
1369
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1370
+		$template_fields = '';
1371
+		$sidebar_fields  = '';
1372
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1373
+		// valid html in the templates.
1374
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1375
+
1376
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1377
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1378
+
1379
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1380
+		$message_template_group = $this->_message_template_group;
1381
+		$c_label                = $message_template_group->context_label();
1382
+		$c_config               = $message_template_group->contexts_config();
1383
+
1384
+		reset($c_config);
1385
+		$context = $this->request->getRequestParam('context', key($c_config));
1386
+		$context = strtolower($context);
1387
+
1388
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1389
+
1390
+		$edit_message_template_form_url = add_query_arg(
1391
+			['action' => $action, 'noheader' => true],
1392
+			EE_MSG_ADMIN_URL
1393
+		);
1394
+
1395
+		// set active messenger for this view
1396
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1397
+			$message_template_group->messenger()
1398
+		);
1399
+		$this->_active_message_type_name = $message_template_group->message_type();
1400
+
1401
+
1402
+		// Do we have any validation errors?
1403
+		$validators = $this->_get_transient();
1404
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1405
+
1406
+
1407
+		// we need to assemble the title from Various details
1408
+		$context_label = sprintf(
1409
+			esc_html__('(%s %s)', 'event_espresso'),
1410
+			$c_config[ $context ]['label'],
1411
+			ucwords($c_label['label'])
1412
+		);
1413
+
1414
+		$title = sprintf(
1415
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1416
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1417
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1418
+			$context_label
1419
+		);
1420
+
1421
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1422
+		$this->_template_args['message_template'] = $message_template_group;
1423
+		$this->_template_args['is_extra_fields']  = false;
1424
+
1425
+
1426
+		// let's get EEH_MSG_Template so we can get template form fields
1427
+		$template_field_structure = EEH_MSG_Template::get_fields(
1428
+			$message_template_group->messenger(),
1429
+			$message_template_group->message_type()
1430
+		);
1431
+
1432
+		if (! $template_field_structure) {
1433
+			$template_field_structure = false;
1434
+			$template_fields          = esc_html__(
1435
+				'There was an error in assembling the fields for this display (you should see an error message)',
1436
+				'event_espresso'
1437
+			);
1438
+		}
1439
+
1440
+
1441
+		$message_templates = $message_template_group->context_templates();
1442
+
1443
+
1444
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1445
+		// will get handled in the "extra" array.
1446
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1447
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1448
+				unset($template_field_structure[ $context ][ $reference_field ]);
1449
+			}
1450
+		}
1451
+
1452
+		// let's loop through the template_field_structure and actually assemble the input fields!
1453
+		if (! empty($template_field_structure)) {
1454
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1455
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1456
+				// the extra array and reset them.
1457
+				if ($template_field === 'extra') {
1458
+					$this->_template_args['is_extra_fields'] = true;
1459
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1460
+						$message_template = $message_templates[ $context ][ $reference_field ];
1461
+						$content          = $message_template instanceof EE_Message_Template
1462
+							? $message_template->get('MTP_content')
1463
+							: '';
1464
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1465
+							// let's verify if we need this extra field via the shortcodes parameter.
1466
+							$continue = false;
1467
+							if (isset($extra_array['shortcodes_required'])) {
1468
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1469
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1470
+										$continue = true;
1471
+									}
1472
+								}
1473
+								if ($continue) {
1474
+									continue;
1475
+								}
1476
+							}
1477
+
1478
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1479
+
1480
+							$template_form_fields[ $field_id ]         = $extra_array;
1481
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1482
+																		 . $reference_field
1483
+																		 . '][content]['
1484
+																		 . $extra_field . ']';
1485
+							$css_class                                 = isset($extra_array['css_class'])
1486
+								? $extra_array['css_class']
1487
+								: '';
1488
+
1489
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1490
+																			  && in_array($extra_field, $v_fields, true)
1491
+																			  && (
1492
+																				  is_array($validators[ $extra_field ])
1493
+																				  && isset($validators[ $extra_field ]['msg'])
1494
+																			  )
1495
+								? 'validate-error ' . $css_class
1496
+								: $css_class;
1497
+
1498
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1499
+																		  && isset($content[ $extra_field ])
1500
+								? $content[ $extra_field ]
1501
+								: '';
1502
+
1503
+							// do we have a validation error?  if we do then let's use that value instead
1504
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1505
+								? $validators[ $extra_field ]['value']
1506
+								: $template_form_fields[ $field_id ]['value'];
1507
+
1508
+
1509
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1510
+
1511
+							// shortcode selector
1512
+							$field_name_to_use                                   = $extra_field === 'main'
1513
+								? 'content'
1514
+								: $extra_field;
1515
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1516
+								$field_name_to_use,
1517
+								$field_id
1518
+							);
1519
+						}
1520
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1521
+						$template_field_template_name_id = $reference_field . '-name';
1522
+
1523
+						$template_form_fields[ $template_field_MTP_id ] = [
1524
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1525
+							'label'      => null,
1526
+							'input'      => 'hidden',
1527
+							'type'       => 'int',
1528
+							'required'   => false,
1529
+							'validation' => false,
1530
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1531
+							'css_class'  => '',
1532
+							'format'     => '%d',
1533
+							'db-col'     => 'MTP_ID',
1534
+						];
1535
+
1536
+						$template_form_fields[ $template_field_template_name_id ] = [
1537
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1538
+							'label'      => null,
1539
+							'input'      => 'hidden',
1540
+							'type'       => 'string',
1541
+							'required'   => false,
1542
+							'validation' => true,
1543
+							'value'      => $reference_field,
1544
+							'css_class'  => '',
1545
+							'format'     => '%s',
1546
+							'db-col'     => 'MTP_template_field',
1547
+						];
1548
+					}
1549
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1550
+				} else {
1551
+					$field_id                                   = $template_field . '-content';
1552
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1553
+					$template_form_fields[ $field_id ]['name']  =
1554
+						'MTP_template_fields[' . $template_field . '][content]';
1555
+					$message_template                           =
1556
+						isset($message_templates[ $context ][ $template_field ])
1557
+							? $message_templates[ $context ][ $template_field ]
1558
+							: null;
1559
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1560
+																  && is_array($message_templates[ $context ])
1561
+																  && $message_template instanceof EE_Message_Template
1562
+						? $message_template->get('MTP_content')
1563
+						: '';
1564
+
1565
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1566
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1567
+						? $validators[ $template_field ]['value']
1568
+						: $template_form_fields[ $field_id ]['value'];
1569
+
1570
+
1571
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1572
+					$css_class                                      = isset($field_setup_array['css_class'])
1573
+						? $field_setup_array['css_class']
1574
+						: '';
1575
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1576
+																	  && in_array($template_field, $v_fields, true)
1577
+																	  && isset($validators[ $template_field ]['msg'])
1578
+						? 'validate-error ' . $css_class
1579
+						: $css_class;
1580
+
1581
+					// shortcode selector
1582
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1583
+						$template_field,
1584
+						$field_id
1585
+					);
1586
+				}
1587
+
1588
+				// k took care of content field(s) now let's take care of others.
1589
+
1590
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1591
+				$template_field_field_template_name_id = $template_field . '-name';
1592
+
1593
+				// foreach template field there are actually two form fields created
1594
+				$template_form_fields[ $template_field_MTP_id ] = [
1595
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1596
+					'label'      => null,
1597
+					'input'      => 'hidden',
1598
+					'type'       => 'int',
1599
+					'required'   => false,
1600
+					'validation' => true,
1601
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1602
+					'css_class'  => '',
1603
+					'format'     => '%d',
1604
+					'db-col'     => 'MTP_ID',
1605
+				];
1606
+
1607
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1608
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1609
+					'label'      => null,
1610
+					'input'      => 'hidden',
1611
+					'type'       => 'string',
1612
+					'required'   => false,
1613
+					'validation' => true,
1614
+					'value'      => $template_field,
1615
+					'css_class'  => '',
1616
+					'format'     => '%s',
1617
+					'db-col'     => 'MTP_template_field',
1618
+				];
1619
+			}
1620
+
1621
+			// add other fields
1622
+			$template_form_fields['ee-msg-current-context'] = [
1623
+				'name'       => 'MTP_context',
1624
+				'label'      => null,
1625
+				'input'      => 'hidden',
1626
+				'type'       => 'string',
1627
+				'required'   => false,
1628
+				'validation' => true,
1629
+				'value'      => $context,
1630
+				'css_class'  => '',
1631
+				'format'     => '%s',
1632
+				'db-col'     => 'MTP_context',
1633
+			];
1634
+
1635
+			$template_form_fields['ee-msg-grp-id'] = [
1636
+				'name'       => 'GRP_ID',
1637
+				'label'      => null,
1638
+				'input'      => 'hidden',
1639
+				'type'       => 'int',
1640
+				'required'   => false,
1641
+				'validation' => true,
1642
+				'value'      => $GRP_ID,
1643
+				'css_class'  => '',
1644
+				'format'     => '%d',
1645
+				'db-col'     => 'GRP_ID',
1646
+			];
1647
+
1648
+			$template_form_fields['ee-msg-messenger'] = [
1649
+				'name'       => 'MTP_messenger',
1650
+				'label'      => null,
1651
+				'input'      => 'hidden',
1652
+				'type'       => 'string',
1653
+				'required'   => false,
1654
+				'validation' => true,
1655
+				'value'      => $message_template_group->messenger(),
1656
+				'css_class'  => '',
1657
+				'format'     => '%s',
1658
+				'db-col'     => 'MTP_messenger',
1659
+			];
1660
+
1661
+			$template_form_fields['ee-msg-message-type'] = [
1662
+				'name'       => 'MTP_message_type',
1663
+				'label'      => null,
1664
+				'input'      => 'hidden',
1665
+				'type'       => 'string',
1666
+				'required'   => false,
1667
+				'validation' => true,
1668
+				'value'      => $message_template_group->message_type(),
1669
+				'css_class'  => '',
1670
+				'format'     => '%s',
1671
+				'db-col'     => 'MTP_message_type',
1672
+			];
1673
+
1674
+			$sidebar_form_fields['ee-msg-is-global'] = [
1675
+				'name'       => 'MTP_is_global',
1676
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1677
+				'input'      => 'hidden',
1678
+				'type'       => 'int',
1679
+				'required'   => false,
1680
+				'validation' => true,
1681
+				'value'      => $message_template_group->get('MTP_is_global'),
1682
+				'css_class'  => '',
1683
+				'format'     => '%d',
1684
+				'db-col'     => 'MTP_is_global',
1685
+			];
1686
+
1687
+			$sidebar_form_fields['ee-msg-is-override'] = [
1688
+				'name'       => 'MTP_is_override',
1689
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1690
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1691
+				'type'       => 'int',
1692
+				'required'   => false,
1693
+				'validation' => true,
1694
+				'value'      => $message_template_group->get('MTP_is_override'),
1695
+				'css_class'  => '',
1696
+				'format'     => '%d',
1697
+				'db-col'     => 'MTP_is_override',
1698
+			];
1699
+
1700
+			$sidebar_form_fields['ee-msg-is-active'] = [
1701
+				'name'       => 'MTP_is_active',
1702
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1703
+				'input'      => 'hidden',
1704
+				'type'       => 'int',
1705
+				'required'   => false,
1706
+				'validation' => true,
1707
+				'value'      => $message_template_group->is_active(),
1708
+				'css_class'  => '',
1709
+				'format'     => '%d',
1710
+				'db-col'     => 'MTP_is_active',
1711
+			];
1712
+
1713
+			$sidebar_form_fields['ee-msg-deleted'] = [
1714
+				'name'       => 'MTP_deleted',
1715
+				'label'      => null,
1716
+				'input'      => 'hidden',
1717
+				'type'       => 'int',
1718
+				'required'   => false,
1719
+				'validation' => true,
1720
+				'value'      => $message_template_group->get('MTP_deleted'),
1721
+				'css_class'  => '',
1722
+				'format'     => '%d',
1723
+				'db-col'     => 'MTP_deleted',
1724
+			];
1725
+			$sidebar_form_fields['ee-msg-author']  = [
1726
+				'name'       => 'MTP_user_id',
1727
+				'label'      => esc_html__('Author', 'event_espresso'),
1728
+				'input'      => 'hidden',
1729
+				'type'       => 'int',
1730
+				'required'   => false,
1731
+				'validation' => false,
1732
+				'value'      => $message_template_group->user(),
1733
+				'format'     => '%d',
1734
+				'db-col'     => 'MTP_user_id',
1735
+			];
1736
+
1737
+			$sidebar_form_fields['ee-msg-route'] = [
1738
+				'name'  => 'action',
1739
+				'input' => 'hidden',
1740
+				'type'  => 'string',
1741
+				'value' => $action,
1742
+			];
1743
+
1744
+			$sidebar_form_fields['ee-msg-id']        = [
1745
+				'name'  => 'id',
1746
+				'input' => 'hidden',
1747
+				'type'  => 'int',
1748
+				'value' => $GRP_ID,
1749
+			];
1750
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1751
+				'name'  => $action . '_nonce',
1752
+				'input' => 'hidden',
1753
+				'type'  => 'string',
1754
+				'value' => wp_create_nonce($action . '_nonce'),
1755
+			];
1756
+
1757
+			$template_switch = $this->request->getRequestParam('template_switch');
1758
+			if ($template_switch) {
1759
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1760
+					'name'  => 'template_switch',
1761
+					'input' => 'hidden',
1762
+					'type'  => 'int',
1763
+					'value' => 1,
1764
+				];
1765
+			}
1766
+
1767
+
1768
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1769
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1770
+		} //end if ( !empty($template_field_structure) )
1771
+
1772
+		// set extra content for publish box
1773
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1774
+		$this->_set_publish_post_box_vars(
1775
+			'id',
1776
+			$GRP_ID,
1777
+			false,
1778
+			add_query_arg(
1779
+				['action' => 'global_mtps'],
1780
+				$this->_admin_base_url
1781
+			)
1782
+		);
1783
+
1784
+		// add preview button
1785
+		$preview_url    = parent::add_query_args_and_nonce(
1786
+			[
1787
+				'message_type' => $message_template_group->message_type(),
1788
+				'messenger'    => $message_template_group->messenger(),
1789
+				'context'      => $context,
1790
+				'GRP_ID'       => $GRP_ID,
1791
+				'evt_id'       => $EVT_ID ?: false,
1792
+				'action'       => 'preview_message',
1793
+			],
1794
+			$this->_admin_base_url
1795
+		);
1796
+		$preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1797
+						  . esc_html__('Preview', 'event_espresso')
1798
+						  . '</a>';
1799
+
1800
+
1801
+
1802
+
1803
+		// main box
1804
+		$this->_template_args['template_fields']                         = $template_fields;
1805
+		$this->_template_args['sidebar_box_id']                          = 'details';
1806
+		$this->_template_args['action']                                  = $action;
1807
+		$this->_template_args['context']                                 = $context;
1808
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1809
+		$this->_template_args['learn_more_about_message_templates_link'] =
1810
+			$this->_learn_more_about_message_templates_link();
1811
+
1812
+
1813
+		$this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1814
+		$this->_template_args['before_admin_page_content'] .= $this->headerFormStart();
1815
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1816
+			$message_template_group,
1817
+			$context,
1818
+			$context_label
1819
+		);
1820
+		$this->_template_args['before_admin_page_content'] .= $this->add_context_switcher(
1821
+			$message_template_group,
1822
+			[
1823
+				'page'    => 'espresso_messages',
1824
+				'action'  => 'edit_message_template',
1825
+				'id'      => $GRP_ID,
1826
+				'evt_id'  => $EVT_ID,
1827
+				'context' => $context,
1828
+				'extra'   => $preview_button,
1829
+			]
1830
+		);
1831
+		$this->_template_args['before_admin_page_content'] .= $this->formEnd();
1832
+		$this->_template_args['before_admin_page_content'] .= '</div>';
1833
+		$this->_template_args['before_admin_page_content'] .= $this->editMessageFormStart();
1834
+		$this->_template_args['after_admin_page_content']  = $this->formEnd();
1835
+
1836
+		$this->_template_path = $this->_template_args['GRP_ID']
1837
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1838
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1839
+
1840
+		// send along EE_Message_Template_Group object for further template use.
1841
+		$this->_template_args['MTP'] = $message_template_group;
1842
+
1843
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1844
+			$this->_template_path,
1845
+			$this->_template_args,
1846
+			true
1847
+		);
1848
+
1849
+
1850
+		// finally, let's set the admin_page title
1851
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1852
+
1853
+
1854
+		// we need to take care of setting the shortcodes property for use elsewhere.
1855
+		$this->_set_shortcodes();
1856
+
1857
+
1858
+		// final template wrapper
1859
+		$this->display_admin_page_with_sidebar();
1860
+	}
1861
+
1862
+
1863
+	public function filter_tinymce_init($mceInit, $editor_id)
1864
+	{
1865
+		return $mceInit;
1866
+	}
1867
+
1868
+
1869
+	/**
1870
+	 * Adds the activation/deactivation toggle for the message template context.
1871
+	 *
1872
+	 * @param EE_Message_Template_Group $message_template_group
1873
+	 * @param string                    $context
1874
+	 * @param string                    $context_label
1875
+	 * @return string
1876
+	 * @throws DomainException
1877
+	 * @throws EE_Error
1878
+	 * @throws InvalidIdentifierException
1879
+	 * @throws ReflectionException
1880
+	 */
1881
+	protected function add_active_context_element(
1882
+		EE_Message_Template_Group $message_template_group,
1883
+		$context,
1884
+		$context_label
1885
+	): string {
1886
+		return EEH_Template::display_template(
1887
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1888
+			[
1889
+				'context'                   => $context,
1890
+				'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
+				'is_active'                 => $message_template_group->is_context_active($context),
1892
+				'on_off_action'             => $message_template_group->is_context_active($context)
1893
+					? 'context-off'
1894
+					: 'context-on',
1895
+				'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
+				'message_template_group_id' => $message_template_group->ID(),
1897
+			],
1898
+			true
1899
+		);
1900
+	}
1901
+
1902
+
1903
+	/**
1904
+	 * sets up a context switcher for edit forms
1905
+	 *
1906
+	 * @access  protected
1907
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
1908
+	 * @param array                     $args                  various things the context switcher needs.
1909
+	 * @throws EE_Error
1910
+	 */
1911
+	protected function add_context_switcher(EE_Message_Template_Group $template_group_object, array $args): string
1912
+	{
1913
+		return EEH_Template::display_template(
1914
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_context_switcher.template.php',
1915
+			[
1916
+				'args'              => $args,
1917
+				'context_details'   => $template_group_object->contexts_config(),
1918
+				'context_label'     => $template_group_object->context_label(),
1919
+				'context_templates' => $template_group_object->context_templates(),
1920
+			],
1921
+			true
1922
+		);
1923
+	}
1924
+
1925
+
1926
+	/**
1927
+	 * Ajax callback for `toggle_context_template` ajax action.
1928
+	 * Handles toggling the message context on or off.
1929
+	 *
1930
+	 * @throws EE_Error
1931
+	 * @throws InvalidArgumentException
1932
+	 * @throws InvalidDataTypeException
1933
+	 * @throws InvalidIdentifierException
1934
+	 * @throws InvalidInterfaceException
1935
+	 */
1936
+	public function toggle_context_template()
1937
+	{
1938
+		$success = true;
1939
+		// check for required data
1940
+		if (
1941
+			! (
1942
+				$this->request->requestParamIsSet('message_template_group_id')
1943
+				&& $this->request->requestParamIsSet('context')
1944
+				&& $this->request->requestParamIsSet('status')
1945
+			)
1946
+		) {
1947
+			EE_Error::add_error(
1948
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1949
+				__FILE__,
1950
+				__FUNCTION__,
1951
+				__LINE__
1952
+			);
1953
+			$success = false;
1954
+		}
1955
+
1956
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1957
+		$context = $this->request->getRequestParam('context', '');
1958
+		$status  = $this->request->getRequestParam('status', '');
1959
+
1960
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1961
+
1962
+		if ($status !== 'off' && $status !== 'on') {
1963
+			EE_Error::add_error(
1964
+				sprintf(
1965
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1966
+					$status
1967
+				),
1968
+				__FILE__,
1969
+				__FUNCTION__,
1970
+				__LINE__
1971
+			);
1972
+			$success = false;
1973
+		}
1974
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1975
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1976
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1977
+			EE_Error::add_error(
1978
+				sprintf(
1979
+					esc_html__(
1980
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1981
+						'event_espresso'
1982
+					),
1983
+					$message_template_group_id,
1984
+					'EE_Message_Template_Group'
1985
+				),
1986
+				__FILE__,
1987
+				__FUNCTION__,
1988
+				__LINE__
1989
+			);
1990
+			$success = false;
1991
+		}
1992
+		if ($success) {
1993
+			$success = $status === 'off'
1994
+				? $message_template_group->deactivate_context($context)
1995
+				: $message_template_group->activate_context($context);
1996
+		}
1997
+		$this->_template_args['success'] = $success;
1998
+		$this->_return_json();
1999
+	}
2000
+
2001
+
2002
+	public function headerFormStart(): string
2003
+	{
2004
+		$action = esc_url_raw(EE_MSG_ADMIN_URL);
2005
+		return "<form method='get' action='$action' id='ee-msg-context-switcher-frm'>";
2006
+	}
2007
+
2008
+
2009
+	public function editMessageFormStart(): string
2010
+	{
2011
+		$action = $this->_template_args['edit_message_template_form_url'];
2012
+		return "<form method ='post' action='$action' id='ee-msg-edit-frm'>";
2013
+	}
2014
+
2015
+
2016
+	public function formEnd(): string
2017
+	{
2018
+		return '</form>';
2019
+	}
2020
+
2021
+
2022
+	/**
2023
+	 * This executes switching the template pack for a message template.
2024
+	 *
2025
+	 * @throws EE_Error
2026
+	 * @throws InvalidDataTypeException
2027
+	 * @throws InvalidInterfaceException
2028
+	 * @throws InvalidArgumentException
2029
+	 * @throws ReflectionException
2030
+	 * @since 4.5.0
2031
+	 */
2032
+	public function switch_template_pack()
2033
+	{
2034
+
2035
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2036
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2037
+
2038
+		// verify we have needed values.
2039
+		if (empty($GRP_ID) || empty($template_pack)) {
2040
+			$this->_template_args['error'] = true;
2041
+			EE_Error::add_error(
2042
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2043
+				__FILE__,
2044
+				__FUNCTION__,
2045
+				__LINE__
2046
+			);
2047
+		} else {
2048
+			// get template, set the new template_pack and then reset to default
2049
+			/** @var EE_Message_Template_Group $message_template_group */
2050
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2051
+
2052
+			$message_template_group->set_template_pack_name($template_pack);
2053
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2054
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2055
+
2056
+			$query_args = $this->_reset_to_default_template();
2057
+
2058
+			if (empty($query_args['id'])) {
2059
+				EE_Error::add_error(
2060
+					esc_html__(
2061
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2062
+						'event_espresso'
2063
+					),
2064
+					__FILE__,
2065
+					__FUNCTION__,
2066
+					__LINE__
2067
+				);
2068
+				$this->_template_args['error'] = true;
2069
+			} else {
2070
+				$template_label       = $message_template_group->get_template_pack()->label;
2071
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2072
+				EE_Error::add_success(
2073
+					sprintf(
2074
+						esc_html__(
2075
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2076
+							'event_espresso'
2077
+						),
2078
+						$template_label,
2079
+						$template_pack_labels->template_pack
2080
+					)
2081
+				);
2082
+				// generate the redirect url for js.
2083
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2084
+
2085
+				$this->_template_args['data']['redirect_url'] = $url;
2086
+				$this->_template_args['success']              = true;
2087
+			}
2088
+
2089
+			$this->_return_json();
2090
+		}
2091
+	}
2092
+
2093
+
2094
+	/**
2095
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2096
+	 * they want.
2097
+	 *
2098
+	 * @access protected
2099
+	 * @return array|void
2100
+	 * @throws EE_Error
2101
+	 * @throws InvalidArgumentException
2102
+	 * @throws InvalidDataTypeException
2103
+	 * @throws InvalidInterfaceException
2104
+	 * @throws ReflectionException
2105
+	 */
2106
+	protected function _reset_to_default_template()
2107
+	{
2108
+		$templates    = [];
2109
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2110
+		$messenger    = $this->request->getRequestParam('msgr');
2111
+		$message_type = $this->request->getRequestParam('mt');
2112
+		// we need to make sure we've got the info we need.
2113
+		if (! ($GRP_ID && $messenger && $message_type)) {
2114
+			EE_Error::add_error(
2115
+				esc_html__(
2116
+					'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.',
2117
+					'event_espresso'
2118
+				),
2119
+				__FILE__,
2120
+				__FUNCTION__,
2121
+				__LINE__
2122
+			);
2123
+		}
2124
+
2125
+		// all templates will be reset to whatever the defaults are
2126
+		// for the global template matching the messenger and message type.
2127
+		$success = ! empty($GRP_ID);
2128
+
2129
+		if ($success) {
2130
+			// let's first determine if the incoming template is a global template,
2131
+			// if it isn't then we need to get the global template matching messenger and message type.
2132
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2133
+
2134
+
2135
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2136
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2137
+
2138
+			if ($success) {
2139
+				// if successfully deleted, lets generate the new ones.
2140
+				// Note. We set GLOBAL to true, because resets on ANY template
2141
+				// will use the related global template defaults for regeneration.
2142
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2143
+				// HOWEVER, we DO keep the template pack and template variation set
2144
+				// for the current custom template when resetting.
2145
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2146
+			}
2147
+		}
2148
+
2149
+		// any error messages?
2150
+		if (! $success) {
2151
+			EE_Error::add_error(
2152
+				esc_html__(
2153
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2154
+					'event_espresso'
2155
+				),
2156
+				__FILE__,
2157
+				__FUNCTION__,
2158
+				__LINE__
2159
+			);
2160
+		}
2161
+
2162
+		// all good, let's add a success message!
2163
+		if ($success && ! empty($templates)) {
2164
+			// the info for the template we generated is the first element in the returned array
2165
+			EE_Error::overwrite_success();
2166
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2167
+		}
2168
+
2169
+
2170
+		$query_args = [
2171
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2172
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2173
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2174
+		];
2175
+
2176
+		// if called via ajax then we return query args otherwise redirect
2177
+		if ($this->request->isAjax()) {
2178
+			return $query_args;
2179
+		}
2180
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2181
+	}
2182
+
2183
+
2184
+	/**
2185
+	 * Retrieve and set the message preview for display.
2186
+	 *
2187
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2188
+	 * @return string
2189
+	 * @throws ReflectionException
2190
+	 * @throws EE_Error
2191
+	 * @throws InvalidArgumentException
2192
+	 * @throws InvalidDataTypeException
2193
+	 * @throws InvalidInterfaceException
2194
+	 */
2195
+	public function _preview_message($send = false)
2196
+	{
2197
+		// first make sure we've got the necessary parameters
2198
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2199
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2200
+			EE_Error::add_error(
2201
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2202
+				__FILE__,
2203
+				__FUNCTION__,
2204
+				__LINE__
2205
+			);
2206
+		}
2207
+
2208
+		$context = $this->request->getRequestParam('context');
2209
+		// get the preview!
2210
+		$preview = EED_Messages::preview_message(
2211
+			$this->_active_message_type_name,
2212
+			$context,
2213
+			$this->_active_messenger_name,
2214
+			$send
2215
+		);
2216
+
2217
+		if ($send) {
2218
+			return $preview;
2219
+		}
2220
+
2221
+		// if we have an evt_id set on the request, use it.
2222
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2223
+
2224
+		// let's add a button to go back to the edit view
2225
+		$query_args             = [
2226
+			'id'      => $GRP_ID,
2227
+			'evt_id'  => $EVT_ID,
2228
+			'context' => $context,
2229
+			'action'  => 'edit_message_template',
2230
+		];
2231
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2232
+		$preview_button         = '<a href="'
2233
+								  . $go_back_url
2234
+								  . '" class="button--secondary messages-preview-go-back-button">'
2235
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2236
+								  . '</a>';
2237
+		$message_types          = $this->get_installed_message_types();
2238
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2239
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2240
+			? ucwords($active_messenger->label['singular'])
2241
+			: esc_html__('Unknown Messenger', 'event_espresso');
2242
+		// let's provide a helpful title for context
2243
+		$preview_title = sprintf(
2244
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2245
+			$active_messenger_label,
2246
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2247
+		);
2248
+		if (empty($preview)) {
2249
+			$this->noEventsErrorMessage();
2250
+		}
2251
+		// setup display of preview.
2252
+		$this->_admin_page_title                    = $preview_title;
2253
+		$this->_template_args['admin_page_title']   = $preview_title;
2254
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2255
+		$this->_template_args['data']['force_json'] = true;
2256
+
2257
+		return '';
2258
+	}
2259
+
2260
+
2261
+	/**
2262
+	 * Used to set an error if there are no events available for generating a preview/test send.
2263
+	 *
2264
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2265
+	 */
2266
+	protected function noEventsErrorMessage($test_send = false)
2267
+	{
2268
+		$events_url = parent::add_query_args_and_nonce(
2269
+			[
2270
+				'action' => 'default',
2271
+				'page'   => 'espresso_events',
2272
+			],
2273
+			admin_url('admin.php')
2274
+		);
2275
+		$message    = $test_send
2276
+			? esc_html__(
2277
+				'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2278
+				'event_espresso'
2279
+			)
2280
+			: esc_html__(
2281
+				'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2282
+				'event_espresso'
2283
+			);
2284
+
2285
+		EE_Error::add_attention(
2286
+			sprintf(
2287
+				$message,
2288
+				"<a href='{$events_url}'>",
2289
+				'</a>'
2290
+			)
2291
+		);
2292
+	}
2293
+
2294
+
2295
+	/**
2296
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2297
+	 * gets called automatically.
2298
+	 *
2299
+	 * @return void
2300
+	 * @throws EE_Error
2301
+	 * @since 4.5.0
2302
+	 *
2303
+	 */
2304
+	protected function _display_preview_message()
2305
+	{
2306
+		$this->display_admin_page_with_no_sidebar();
2307
+	}
2308
+
2309
+
2310
+	/**
2311
+	 * registers metaboxes that should show up on the "edit_message_template" page
2312
+	 *
2313
+	 * @access protected
2314
+	 * @return void
2315
+	 */
2316
+	protected function _register_edit_meta_boxes()
2317
+	{
2318
+		$this->addMetaBox(
2319
+			'mtp_valid_shortcodes',
2320
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2321
+			[$this, 'shortcode_meta_box'],
2322
+			$this->_current_screen->id,
2323
+			'side'
2324
+		);
2325
+		$this->addMetaBox(
2326
+			'mtp_extra_actions',
2327
+			esc_html__('Extra Actions', 'event_espresso'),
2328
+			[$this, 'extra_actions_meta_box'],
2329
+			$this->_current_screen->id,
2330
+			'side',
2331
+			'high'
2332
+		);
2333
+		$this->addMetaBox(
2334
+			'mtp_templates',
2335
+			esc_html__('Template Styles', 'event_espresso'),
2336
+			[$this, 'template_pack_meta_box'],
2337
+			$this->_current_screen->id,
2338
+			'side',
2339
+			'high'
2340
+		);
2341
+	}
2342
+
2343
+
2344
+	/**
2345
+	 * metabox content for all template pack and variation selection.
2346
+	 *
2347
+	 * @return void
2348
+	 * @throws DomainException
2349
+	 * @throws EE_Error
2350
+	 * @throws InvalidArgumentException
2351
+	 * @throws ReflectionException
2352
+	 * @throws InvalidDataTypeException
2353
+	 * @throws InvalidInterfaceException
2354
+	 * @since 4.5.0
2355
+	 */
2356
+	public function template_pack_meta_box()
2357
+	{
2358
+		$this->_set_message_template_group();
2359
+
2360
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2361
+
2362
+		$tp_select_values = [];
2363
+
2364
+		foreach ($tp_collection as $tp) {
2365
+			// only include template packs that support this messenger and message type!
2366
+			$supports = $tp->get_supports();
2367
+			if (
2368
+				! isset($supports[ $this->_message_template_group->messenger() ])
2369
+				|| ! in_array(
2370
+					$this->_message_template_group->message_type(),
2371
+					$supports[ $this->_message_template_group->messenger() ],
2372
+					true
2373
+				)
2374
+			) {
2375
+				// not supported
2376
+				continue;
2377
+			}
2378
+
2379
+			$tp_select_values[] = [
2380
+				'text' => $tp->label,
2381
+				'id'   => $tp->dbref,
2382
+			];
2383
+		}
2384
+
2385
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2386
+		// the default template pack.  This still allows for the odd template pack to override.
2387
+		if (empty($tp_select_values)) {
2388
+			$tp_select_values[] = [
2389
+				'text' => esc_html__('Default', 'event_espresso'),
2390
+				'id'   => 'default',
2391
+			];
2392
+		}
2393
+
2394
+		// setup variation select values for the currently selected template.
2395
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2396
+			$this->_message_template_group->messenger(),
2397
+			$this->_message_template_group->message_type()
2398
+		);
2399
+		$variations_select_values = [];
2400
+		foreach ($variations as $variation => $label) {
2401
+			$variations_select_values[] = [
2402
+				'text' => $label,
2403
+				'id'   => $variation,
2404
+			];
2405
+		}
2406
+
2407
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2408
+
2409
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2410
+			'MTP_template_pack',
2411
+			$tp_select_values,
2412
+			$this->_message_template_group->get_template_pack_name()
2413
+		);
2414
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2415
+			'MTP_template_variation',
2416
+			$variations_select_values,
2417
+			$this->_message_template_group->get_template_pack_variation()
2418
+		);
2419
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2420
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2421
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2422
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2423
+
2424
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2425
+
2426
+		EEH_Template::display_template($template, $template_args);
2427
+	}
2428
+
2429
+
2430
+	/**
2431
+	 * This meta box holds any extra actions related to Message Templates
2432
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2433
+	 *
2434
+	 * @access  public
2435
+	 * @return void
2436
+	 * @throws EE_Error
2437
+	 */
2438
+	public function extra_actions_meta_box()
2439
+	{
2440
+		$template_form_fields = [];
2441
+
2442
+		$extra_args = [
2443
+			'msgr'   => $this->_message_template_group->messenger(),
2444
+			'mt'     => $this->_message_template_group->message_type(),
2445
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2446
+		];
2447
+		// first we need to see if there are any fields
2448
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2449
+
2450
+		if (! empty($fields)) {
2451
+			// yup there be fields
2452
+			foreach ($fields as $field => $config) {
2453
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2454
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2455
+				$default  = isset($config['default']) ? $config['default'] : '';
2456
+				$default  = isset($config['value']) ? $config['value'] : $default;
2457
+
2458
+				// if type is hidden and the value is empty
2459
+				// something may have gone wrong so let's correct with the defaults
2460
+				$fix                = $config['input'] === 'hidden'
2461
+									  && isset($existing[ $field ])
2462
+									  && empty($existing[ $field ])
2463
+					? $default
2464
+					: '';
2465
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2466
+					? $existing[ $field ]
2467
+					: $fix;
2468
+
2469
+				$template_form_fields[ $field_id ] = [
2470
+					'name'       => 'test_settings_fld[' . $field . ']',
2471
+					'label'      => $config['label'],
2472
+					'input'      => $config['input'],
2473
+					'type'       => $config['type'],
2474
+					'required'   => $config['required'],
2475
+					'validation' => $config['validation'],
2476
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2477
+					'css_class'  => $config['css_class'],
2478
+					'options'    => isset($config['options']) ? $config['options'] : [],
2479
+					'default'    => $default,
2480
+					'format'     => $config['format'],
2481
+				];
2482
+			}
2483
+		}
2484
+
2485
+		$test_settings_html = ! empty($template_form_fields)
2486
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2487
+			: '';
2488
+
2489
+		// print out $test_settings_fields
2490
+		if (! empty($test_settings_html)) {
2491
+			$test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2492
+			$test_settings_html .= 'name="test_button" value="';
2493
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2494
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2495
+		}
2496
+
2497
+		// and button
2498
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2499
+		$test_settings_html .= '<p>';
2500
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2501
+		$test_settings_html .= '</p>';
2502
+		$test_settings_html .= $this->get_action_link_or_button(
2503
+			'reset_to_default',
2504
+			'reset',
2505
+			$extra_args,
2506
+			'button--primary reset-default-button'
2507
+		);
2508
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2509
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2510
+	}
2511
+
2512
+
2513
+	/**
2514
+	 * This returns the shortcode selector skeleton for a given context and field.
2515
+	 *
2516
+	 * @param string $field           The name of the field retrieving shortcodes for.
2517
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2518
+	 * @return string
2519
+	 * @throws DomainException
2520
+	 * @throws EE_Error
2521
+	 * @throws InvalidArgumentException
2522
+	 * @throws ReflectionException
2523
+	 * @throws InvalidDataTypeException
2524
+	 * @throws InvalidInterfaceException
2525
+	 * @since 4.9.rc.000
2526
+	 */
2527
+	protected function _get_shortcode_selector($field, $linked_input_id)
2528
+	{
2529
+		$template_args = [
2530
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2531
+			'fieldname'       => $field,
2532
+			'linked_input_id' => $linked_input_id,
2533
+		];
2534
+
2535
+		return EEH_Template::display_template(
2536
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2537
+			$template_args,
2538
+			true
2539
+		);
2540
+	}
2541
+
2542
+
2543
+	/**
2544
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2545
+	 * page)
2546
+	 *
2547
+	 * @access public
2548
+	 * @return void
2549
+	 * @throws EE_Error
2550
+	 * @throws InvalidArgumentException
2551
+	 * @throws ReflectionException
2552
+	 * @throws InvalidDataTypeException
2553
+	 * @throws InvalidInterfaceException
2554
+	 */
2555
+	public function shortcode_meta_box()
2556
+	{
2557
+		$shortcodes = $this->_get_shortcodes([], false);
2558
+		// just make sure the shortcodes property is set
2559
+		// $messenger = $this->_message_template_group->messenger_obj();
2560
+		// now let's set the content depending on the status of the shortcodes array
2561
+		if (empty($shortcodes)) {
2562
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2563
+			return;
2564
+		}
2565
+		?>
2566 2566
         <div style="float:right; margin-top:10px">
2567 2567
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2568
-            ?>
2568
+			?>
2569 2569
         </div>
2570 2570
         <p class="small-text">
2571 2571
             <?php printf(
2572
-                esc_html__(
2573
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2574
-                    'event_espresso'
2575
-                ),
2576
-                '<span class="dashicons dashicons-shortcode"></span>'
2577
-            ); ?>
2572
+				esc_html__(
2573
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2574
+					'event_espresso'
2575
+				),
2576
+				'<span class="dashicons dashicons-shortcode"></span>'
2577
+			); ?>
2578 2578
         </p>
2579 2579
         <?php
2580
-    }
2581
-
2582
-
2583
-    /**
2584
-     * used to set the $_shortcodes property for when its needed elsewhere.
2585
-     *
2586
-     * @access protected
2587
-     * @return void
2588
-     * @throws EE_Error
2589
-     * @throws InvalidArgumentException
2590
-     * @throws ReflectionException
2591
-     * @throws InvalidDataTypeException
2592
-     * @throws InvalidInterfaceException
2593
-     */
2594
-    protected function _set_shortcodes()
2595
-    {
2596
-
2597
-        // no need to run this if the property is already set
2598
-        if (! empty($this->_shortcodes)) {
2599
-            return;
2600
-        }
2601
-
2602
-        $this->_shortcodes = $this->_get_shortcodes();
2603
-    }
2604
-
2605
-
2606
-    /**
2607
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2608
-     * property)
2609
-     *
2610
-     * @access  protected
2611
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2612
-     *                         for. Defaults to all (for the given context)
2613
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2614
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2615
-     *                         true just an array of shortcode/label pairs.
2616
-     * @throws EE_Error
2617
-     * @throws InvalidArgumentException
2618
-     * @throws ReflectionException
2619
-     * @throws InvalidDataTypeException
2620
-     * @throws InvalidInterfaceException
2621
-     */
2622
-    protected function _get_shortcodes($fields = [], $merged = true)
2623
-    {
2624
-        $this->_set_message_template_group();
2625
-
2626
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2627
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2628
-        if (empty($GRP_ID)) {
2629
-            return [];
2630
-        }
2631
-        $context = $this->request->getRequestParam(
2632
-            'messenger',
2633
-            key($this->_message_template_group->contexts_config())
2634
-        );
2635
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2636
-    }
2637
-
2638
-
2639
-    /**
2640
-     * This sets the _message_template property (containing the called message_template object)
2641
-     *
2642
-     * @access protected
2643
-     * @return void
2644
-     * @throws EE_Error
2645
-     * @throws InvalidArgumentException
2646
-     * @throws ReflectionException
2647
-     * @throws InvalidDataTypeException
2648
-     * @throws InvalidInterfaceException
2649
-     */
2650
-    protected function _set_message_template_group()
2651
-    {
2652
-        // get out if this is already set.
2653
-        if (! empty($this->_message_template_group)) {
2654
-            return;
2655
-        }
2656
-
2657
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2658
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2659
-
2660
-        // let's get the message templates
2661
-        $this->_message_template_group = ! empty($GRP_ID)
2662
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2663
-            : $this->getMtgModel()->create_default_object();
2664
-
2665
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2666
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2667
-    }
2668
-
2669
-    /**
2670
-     * @param bool $new
2671
-     * @throws EE_Error
2672
-     * @throws ReflectionException
2673
-     */
2674
-    protected function _insert_or_update_message_template($new = false)
2675
-    {
2676
-        $form_data    = $this->getMessageTemplateFormData();
2677
-        $GRP_ID       = $form_data['GRP_ID'];
2678
-        $messenger    = $form_data['MTP_messenger'];
2679
-        $message_type = $form_data['MTP_message_type'];
2680
-        $context      = $form_data['MTP_context'];
2681
-
2682
-        // if this is "new" then we need to generate the default contexts
2683
-        // for the selected messenger/message_type for user to edit.
2684
-        [$success, $query_args] = $new
2685
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2686
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2687
-
2688
-        $success     = $success ? 1 : 0;
2689
-        $action_desc = $new ? 'created' : 'updated';
2690
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2691
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2692
-
2693
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2694
-    }
2695
-
2696
-
2697
-    /**
2698
-     * retrieve and sanitize form data
2699
-     *
2700
-     * @return array
2701
-     * @since 4.10.29.p
2702
-     */
2703
-    protected function getMessageTemplateFormData()
2704
-    {
2705
-        return [
2706
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2707
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2708
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2709
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2710
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2711
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2712
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2713
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2714
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2715
-        ];
2716
-    }
2717
-
2718
-
2719
-    /**
2720
-     * @param int    $GRP_ID
2721
-     * @param string $messenger
2722
-     * @param string $message_type
2723
-     * @return array no return on AJAX requests
2724
-     * @throws EE_Error
2725
-     * @throws ReflectionException
2726
-     * @since 4.10.29.p
2727
-     */
2728
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2729
-    {
2730
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2731
-        $success       = ! empty($new_templates);
2732
-
2733
-        // we return things differently if doing ajax
2734
-        if ($this->request->isAjax()) {
2735
-            $this->_template_args['success'] = $success;
2736
-            $this->_template_args['error']   = ! $success;
2737
-            $this->_template_args['content'] = '';
2738
-            $this->_template_args['data']    = [
2739
-                'grpID'        => $new_templates['GRP_ID'],
2740
-                'templateName' => $new_templates['template_name'],
2741
-            ];
2742
-            if ($success) {
2743
-                EE_Error::overwrite_success();
2744
-                EE_Error::add_success(
2745
-                    esc_html__(
2746
-                        '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.',
2747
-                        'event_espresso'
2748
-                    )
2749
-                );
2750
-            }
2751
-            $this->_return_json();
2752
-        }
2753
-        return [
2754
-            $success,
2755
-            // 'query_args'
2756
-            [
2757
-                'id'      => $new_templates['GRP_ID'],
2758
-                'context' => $new_templates['MTP_context'],
2759
-                'action'  => 'edit_message_template',
2760
-            ],
2761
-        ];
2762
-    }
2763
-
2764
-
2765
-    /**
2766
-     * @param int    $GRP_ID
2767
-     * @param string $messenger
2768
-     * @param string $message_type
2769
-     * @param string $context
2770
-     * @param array  $form_data
2771
-     * @return array
2772
-     * @throws EE_Error
2773
-     * @since 4.10.29.p
2774
-     */
2775
-    private function updateExistingTemplates(
2776
-        $GRP_ID,
2777
-        $messenger,
2778
-        $message_type,
2779
-        $context,
2780
-        array $form_data
2781
-    ) {
2782
-        $success         = false;
2783
-        $template_fields = $this->getTemplateFields();
2784
-        if ($template_fields) {
2785
-            // if field data is valid, then success will be true
2786
-            $success = $this->validateTemplateFields(
2787
-                $messenger,
2788
-                $message_type,
2789
-                $context,
2790
-                $template_fields
2791
-            );
2792
-            if ($success) {
2793
-                $field_data = [];
2794
-                foreach ($template_fields as $template_field => $content) {
2795
-                    // combine top-level form data with content for this field
2796
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2797
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2798
-                }
2799
-                // we can use the last set_column_values for the MTPG update
2800
-                // (because its the same for all of these specific MTPs)
2801
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2802
-            }
2803
-        }
2804
-
2805
-        return [
2806
-            $success,
2807
-            // 'query_args'
2808
-            [
2809
-                'id'      => $GRP_ID,
2810
-                'context' => $context,
2811
-                'action'  => 'edit_message_template',
2812
-            ],
2813
-        ];
2814
-    }
2815
-
2816
-
2817
-    /**
2818
-     * @return array
2819
-     * @since 4.10.29.p
2820
-     */
2821
-    private function getTemplateFields()
2822
-    {
2823
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2824
-        if (empty($template_fields)) {
2825
-            EE_Error::add_error(
2826
-                esc_html__(
2827
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2828
-                    'event_espresso'
2829
-                ),
2830
-                __FILE__,
2831
-                __FUNCTION__,
2832
-                __LINE__
2833
-            );
2834
-            return null;
2835
-        }
2836
-        // messages content is expected to be escaped
2837
-        return EEH_Array::addSlashesRecursively($template_fields);
2838
-    }
2839
-
2840
-
2841
-    /**
2842
-     * @param string $messenger
2843
-     * @param string $message_type
2844
-     * @param string $context
2845
-     * @param array  $template_fields
2846
-     * @return bool
2847
-     * @throws EE_Error
2848
-     * @since   4.10.29.p
2849
-     */
2850
-    private function validateTemplateFields(
2851
-        $messenger,
2852
-        $message_type,
2853
-        $context,
2854
-        array $template_fields
2855
-    ) {
2856
-        // first validate all fields!
2857
-        // this filter allows client code to add its own validation to the template fields as well.
2858
-        // returning an empty array means everything passed validation.
2859
-        // errors in validation should be represented in an array with the following shape:
2860
-        // array(
2861
-        //   'fieldname' => array(
2862
-        //          'msg' => 'error message'
2863
-        //          'value' => 'value for field producing error'
2864
-        // )
2865
-        $custom_validation = (array) apply_filters(
2866
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2867
-            [],
2868
-            $template_fields,
2869
-            $context,
2870
-            $messenger,
2871
-            $message_type
2872
-        );
2873
-
2874
-        $system_validation = $this->getMtgModel()->validate(
2875
-            $template_fields,
2876
-            $context,
2877
-            $messenger,
2878
-            $message_type
2879
-        );
2880
-
2881
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2882
-        $validates         = array_merge($custom_validation, $system_validation);
2883
-
2884
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2885
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2886
-        //  WE need to make sure there is no actual error messages in validates.
2887
-        if (empty($validates)) {
2888
-            return true;
2889
-        }
2890
-
2891
-        // add the transient so when the form loads we know which fields to highlight
2892
-        $this->_add_transient('edit_message_template', $validates);
2893
-        // setup notices
2894
-        foreach ($validates as $error) {
2895
-            if (isset($error['msg'])) {
2896
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2897
-            }
2898
-        }
2899
-        return false;
2900
-    }
2901
-
2902
-
2903
-    /**
2904
-     * @param array $field_data
2905
-     * @param array $form_data
2906
-     * @return array
2907
-     * @since   4.10.29.p
2908
-     */
2909
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2910
-    {
2911
-        return $form_data + [
2912
-                'MTP_ID'             => $field_data['MTP_ID'],
2913
-                'MTP_template_field' => $field_data['name'],
2914
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2915
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2916
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2917
-                    : $field_data['content'],
2918
-            ];
2919
-    }
2920
-
2921
-
2922
-    /**
2923
-     * @param string $template_field
2924
-     * @param array  $form_data
2925
-     * @return bool
2926
-     * @throws EE_Error
2927
-     * @since 4.10.29.p
2928
-     */
2929
-    private function updateMessageTemplates($template_field, array $form_data)
2930
-    {
2931
-        $MTP_ID                  = $form_data['MTP_ID'];
2932
-        $message_template_fields = [
2933
-            'GRP_ID'             => $form_data['GRP_ID'],
2934
-            'MTP_template_field' => $form_data['MTP_template_field'],
2935
-            'MTP_context'        => $form_data['MTP_context'],
2936
-            'MTP_content'        => $form_data['MTP_content'],
2937
-        ];
2938
-
2939
-        $hasMtpID = ! empty($MTP_ID);
2940
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2941
-        // this has already been through the template field validator and sanitized, so it will be
2942
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2943
-        // message template field in a messenger/message type and existing users don't have the
2944
-        // default setup for it.
2945
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2946
-        $updated = $hasMtpID
2947
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2948
-            : $this->getMtpModel()->insert($message_template_fields);
2949
-
2950
-        $insert_failed = ! $hasMtpID && ! $updated;
2951
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2952
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
2953
-        $update_failed = $hasMtpID && $updated === false;
2954
-
2955
-        if ($insert_failed || $update_failed) {
2956
-            EE_Error::add_error(
2957
-                sprintf(
2958
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2959
-                    $template_field
2960
-                ),
2961
-                __FILE__,
2962
-                __FUNCTION__,
2963
-                __LINE__
2964
-            );
2965
-            return false;
2966
-        }
2967
-        return true;
2968
-    }
2969
-
2970
-
2971
-    /**
2972
-     * @param array $form_data
2973
-     * @return bool
2974
-     * @throws EE_Error
2975
-     * @since 4.10.29.p
2976
-     */
2977
-    private function updateMessageTemplateGroup(array $form_data)
2978
-    {
2979
-        $GRP_ID  = $form_data['GRP_ID'];
2980
-        $updated = $this->getMtgModel()->update(
2981
-        // fields and values
2982
-            [
2983
-                'MTP_user_id'      => $form_data['MTP_user_id'],
2984
-                'MTP_messenger'    => $form_data['MTP_messenger'],
2985
-                'MTP_message_type' => $form_data['MTP_message_type'],
2986
-                'MTP_is_global'    => $form_data['MTP_is_global'],
2987
-                'MTP_is_override'  => $form_data['MTP_is_override'],
2988
-                'MTP_deleted'      => $form_data['MTP_deleted'],
2989
-                'MTP_is_active'    => $form_data['MTP_is_active'],
2990
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
2991
-                'MTP_description'  => $this->request->getRequestParam(
2992
-                    'ee_msg_non_global_fields[MTP_description]',
2993
-                    ''
2994
-                ),
2995
-            ],
2996
-            // where
2997
-            [['GRP_ID' => $GRP_ID]]
2998
-        );
2999
-
3000
-        if ($updated === false) {
3001
-            EE_Error::add_error(
3002
-                sprintf(
3003
-                    esc_html__(
3004
-                        'The Message Template Group (%d) was NOT updated for some reason',
3005
-                        'event_espresso'
3006
-                    ),
3007
-                    $form_data['GRP_ID']
3008
-                ),
3009
-                __FILE__,
3010
-                __FUNCTION__,
3011
-                __LINE__
3012
-            );
3013
-            return false;
3014
-        }
3015
-        // k now we need to ensure the template_pack and template_variation fields are set.
3016
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3017
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3018
-
3019
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3020
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3021
-            $message_template_group->set_template_pack_name($template_pack);
3022
-            $message_template_group->set_template_pack_variation($template_variation);
3023
-        }
3024
-        return true;
3025
-    }
3026
-
3027
-
3028
-    /**
3029
-     * recursively runs wp_kses() on message template content in a model safe manner
3030
-     *
3031
-     * @param array|string $content
3032
-     * @return array|string
3033
-     * @since   4.10.29.p
3034
-     */
3035
-    private function sanitizeMessageTemplateContent($content)
3036
-    {
3037
-        if (is_array($content)) {
3038
-            foreach ($content as $key => $value) {
3039
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3040
-            }
3041
-            return $content;
3042
-        }
3043
-        // remove slashes so wp_kses() works properly
3044
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3045
-        // so attributes using single quotes always appear invalid.
3046
-        $content = stripslashes($content);
3047
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3048
-        // But currently the models expect slashed data, so after wp_kses()
3049
-        // runs we need to re-slash the data. Sheesh.
3050
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3051
-        return addslashes($content);
3052
-    }
3053
-
3054
-
3055
-    /**
3056
-     * @param string $messenger
3057
-     * @param string $message_type
3058
-     * @param string $context
3059
-     * @return string
3060
-     * @since 4.10.29.p
3061
-     */
3062
-    private function generateUpdateDescription($messenger, $message_type, $context)
3063
-    {
3064
-        // need the message type and messenger objects to be able to use the labels for the notices
3065
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3066
-        $messenger_label  = $messenger_object instanceof EE_messenger
3067
-            ? ucwords($messenger_object->label['singular'])
3068
-            : '';
3069
-
3070
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3071
-        $message_type_label  = $message_type_object instanceof EE_message_type
3072
-            ? ucwords($message_type_object->label['singular'])
3073
-            : '';
3074
-
3075
-        $context   = ucwords(str_replace('_', ' ', $context));
3076
-        $item_desc = $messenger_label && $message_type_label
3077
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3078
-            : '';
3079
-        $item_desc .= 'Message Template';
3080
-        return $item_desc;
3081
-    }
3082
-
3083
-
3084
-    /**
3085
-     * @param string $messenger
3086
-     * @param string $message_type
3087
-     * @param string $context
3088
-     * @return bool
3089
-     * @throws EE_Error
3090
-     * @throws ReflectionException
3091
-     * @since 4.10.29.p
3092
-     */
3093
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3094
-    {
3095
-        // was a test send triggered?
3096
-        if ($this->request->requestParamIsSet('test_button')) {
3097
-            EE_Error::overwrite_success();
3098
-            $this->_do_test_send($context, $messenger, $message_type);
3099
-            return true;
3100
-        }
3101
-        return false;
3102
-    }
3103
-
3104
-
3105
-    /**
3106
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3107
-     *
3108
-     * @param string $context      what context being tested
3109
-     * @param string $messenger    messenger being tested
3110
-     * @param string $message_type message type being tested
3111
-     * @throws EE_Error
3112
-     * @throws InvalidArgumentException
3113
-     * @throws InvalidDataTypeException
3114
-     * @throws InvalidInterfaceException
3115
-     * @throws ReflectionException
3116
-     */
3117
-    protected function _do_test_send($context, $messenger, $message_type)
3118
-    {
3119
-        // set things up for preview
3120
-        $this->request->setRequestParam('messenger', $messenger);
3121
-        $this->request->setRequestParam('message_type', $message_type);
3122
-        $this->request->setRequestParam('context', $context);
3123
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3124
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3125
-
3126
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3127
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3128
-
3129
-        // let's save any existing fields that might be required by the messenger
3130
-        if (
3131
-            ! empty($test_settings_fld)
3132
-            && $active_messenger instanceof EE_messenger
3133
-            && apply_filters(
3134
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3135
-                true,
3136
-                $test_settings_fld,
3137
-                $active_messenger
3138
-            )
3139
-        ) {
3140
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3141
-        }
3142
-
3143
-        /**
3144
-         * Use filter to add additional controls on whether message can send or not
3145
-         */
3146
-        if (
3147
-            apply_filters(
3148
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3149
-                true,
3150
-                $context,
3151
-                $this->request->requestParams(),
3152
-                $messenger,
3153
-                $message_type
3154
-            )
3155
-        ) {
3156
-            if (EEM_Event::instance()->count() > 0) {
3157
-                $success = $this->_preview_message(true);
3158
-                if ($success) {
3159
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3160
-                } else {
3161
-                    EE_Error::add_error(
3162
-                        esc_html__('The test message was not sent', 'event_espresso'),
3163
-                        __FILE__,
3164
-                        __FUNCTION__,
3165
-                        __LINE__
3166
-                    );
3167
-                }
3168
-            } else {
3169
-                $this->noEventsErrorMessage(true);
3170
-            }
3171
-        }
3172
-    }
3173
-
3174
-
3175
-    /**
3176
-     * _generate_new_templates
3177
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3178
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3179
-     * for the event.
3180
-     *
3181
-     *
3182
-     * @param string $messenger      the messenger we are generating templates for
3183
-     * @param array  $message_types  array of message types that the templates are generated for.
3184
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3185
-     *                               indicate the message_template_group being used as the base.
3186
-     *
3187
-     * @param bool   $global
3188
-     *
3189
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3190
-     *                               encountering problems.
3191
-     * @throws EE_Error
3192
-     * @throws ReflectionException
3193
-     */
3194
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3195
-    {
3196
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3197
-        // just don't generate any templates.
3198
-        if (empty($message_types)) {
3199
-            return [];
3200
-        }
3201
-
3202
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3203
-        return $templates[0];
3204
-    }
3205
-
3206
-
3207
-    /**
3208
-     * [_trash_or_restore_message_template]
3209
-     *
3210
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3211
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3212
-     *                        an individual context (FALSE).
3213
-     * @return void
3214
-     * @throws EE_Error
3215
-     * @throws InvalidArgumentException
3216
-     * @throws InvalidDataTypeException
3217
-     * @throws InvalidInterfaceException
3218
-     */
3219
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3220
-    {
3221
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3222
-
3223
-        $success = 1;
3224
-
3225
-        // incoming GRP_IDs
3226
-        if ($all) {
3227
-            // Checkboxes
3228
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3229
-            if (! empty($checkboxes)) {
3230
-                // if array has more than one element then success message should be plural.
3231
-                // todo: what about nonce?
3232
-                $success = count($checkboxes) > 1 ? 2 : 1;
3233
-
3234
-                // cycle through checkboxes
3235
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3236
-                    $trashed_or_restored = $trash
3237
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3238
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3239
-                    if (! $trashed_or_restored) {
3240
-                        $success = 0;
3241
-                    }
3242
-                }
3243
-            } else {
3244
-                // grab single GRP_ID and handle
3245
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3246
-                if (! empty($GRP_ID)) {
3247
-                    $trashed_or_restored = $trash
3248
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3249
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3250
-                    if (! $trashed_or_restored) {
3251
-                        $success = 0;
3252
-                    }
3253
-                } else {
3254
-                    $success = 0;
3255
-                }
3256
-            }
3257
-        }
3258
-
3259
-        $action_desc = $trash
3260
-            ? esc_html__('moved to the trash', 'event_espresso')
3261
-            : esc_html__('restored', 'event_espresso');
3262
-
3263
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3264
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3265
-
3266
-        $item_desc = $all ? _n(
3267
-            'Message Template Group',
3268
-            'Message Template Groups',
3269
-            $success,
3270
-            'event_espresso'
3271
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3272
-
3273
-        $item_desc = $template_switch
3274
-            ? _n('template', 'templates', $success, 'event_espresso')
3275
-            : $item_desc;
3276
-
3277
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3278
-    }
3279
-
3280
-
3281
-    /**
3282
-     * [_delete_message_template]
3283
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3284
-     *
3285
-     * @return void
3286
-     * @throws EE_Error
3287
-     * @throws InvalidArgumentException
3288
-     * @throws InvalidDataTypeException
3289
-     * @throws InvalidInterfaceException
3290
-     * @throws ReflectionException
3291
-     */
3292
-    protected function _delete_message_template()
3293
-    {
3294
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3295
-
3296
-        // checkboxes
3297
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3298
-        if (! empty($checkboxes)) {
3299
-            // if array has more than one element then success message should be plural
3300
-            $success = count($checkboxes) > 1 ? 2 : 1;
3301
-
3302
-            // cycle through bulk action checkboxes
3303
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3304
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3305
-            }
3306
-        } else {
3307
-            // grab single grp_id and delete
3308
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3309
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3310
-        }
3311
-
3312
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3313
-    }
3314
-
3315
-
3316
-    /**
3317
-     * helper for permanently deleting a mtP group and all related message_templates
3318
-     *
3319
-     * @param int  $GRP_ID        The group being deleted
3320
-     * @param bool $include_group whether to delete the Message Template Group as well.
3321
-     * @return bool boolean to indicate the success of the deletes or not.
3322
-     * @throws EE_Error
3323
-     * @throws InvalidArgumentException
3324
-     * @throws InvalidDataTypeException
3325
-     * @throws InvalidInterfaceException
3326
-     * @throws ReflectionException
3327
-     * @throws ReflectionException
3328
-     */
3329
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3330
-    {
3331
-        $success = true;
3332
-        // first let's GET this group
3333
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3334
-        // then delete permanently all the related Message Templates
3335
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3336
-
3337
-        if ($deleted === 0) {
3338
-            $success = false;
3339
-        }
3340
-
3341
-        // now delete permanently this particular group
3342
-
3343
-        if ($include_group && ! $MTG->delete_permanently()) {
3344
-            $success = false;
3345
-        }
3346
-
3347
-        return $success;
3348
-    }
3349
-
3350
-
3351
-    /**
3352
-     *    _learn_more_about_message_templates_link
3353
-     *
3354
-     * @access protected
3355
-     * @return string
3356
-     */
3357
-    protected function _learn_more_about_message_templates_link()
3358
-    {
3359
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3360
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3361
-               . '</a>';
3362
-    }
3363
-
3364
-
3365
-    /**
3366
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3367
-     * ajax and other routes.
3368
-     *
3369
-     * @return void
3370
-     * @throws DomainException
3371
-     * @throws EE_Error
3372
-     */
3373
-    protected function _settings()
3374
-    {
3375
-        $this->_set_m_mt_settings();
3376
-
3377
-        // let's setup the messenger tabs
3378
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3379
-            $this->_m_mt_settings['messenger_tabs'],
3380
-            'messenger_links',
3381
-            '|',
3382
-            $this->request->getRequestParam('selected_messenger', 'email')
3383
-        );
3384
-
3385
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3386
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3387
-
3388
-        $this->display_admin_page_with_sidebar();
3389
-    }
3390
-
3391
-
3392
-    /**
3393
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3394
-     *
3395
-     * @access protected
3396
-     * @return void
3397
-     * @throws DomainException
3398
-     */
3399
-    protected function _set_m_mt_settings()
3400
-    {
3401
-        // first if this is already set then lets get out no need to regenerate data.
3402
-        if (! empty($this->_m_mt_settings)) {
3403
-            return;
3404
-        }
3405
-
3406
-        // get all installed messengers and message_types
3407
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3408
-        $message_types = $this->_message_resource_manager->installed_message_types();
3409
-
3410
-
3411
-        // assemble the array for the _tab_text_links helper
3412
-
3413
-        foreach ($messengers as $messenger) {
3414
-            $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3415
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3416
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3417
-                'label' => ucwords($messenger->label['singular']),
3418
-                'class' => $active ? "{$class} messenger-active" : $class,
3419
-                'href'  => $messenger->name,
3420
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3421
-                'slug'  => $messenger->name,
3422
-                'obj'   => $messenger,
3423
-                'icon' => $active
3424
-                    ? '<span class="dashicons dashicons-yes-alt"></span>'
3425
-                    : '<span class="dashicons dashicons-remove"></span>',
3426
-            ];
3427
-
3428
-
3429
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3430
-
3431
-            foreach ($message_types as $message_type) {
3432
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3433
-                // it shouldn't show in either the inactive OR active metabox.
3434
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3435
-                    continue;
3436
-                }
3437
-
3438
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3439
-                    $messenger->name,
3440
-                    $message_type->name
3441
-                )
3442
-                    ? 'active'
3443
-                    : 'inactive';
3444
-
3445
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3446
-                    'label'    => ucwords($message_type->label['singular']),
3447
-                    'class'    => 'message-type-' . $a_or_i,
3448
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3449
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3450
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3451
-                    'title'    => $a_or_i === 'active'
3452
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3453
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3454
-                    'content'  => $a_or_i === 'active'
3455
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3456
-                        : $this->_message_type_settings_content($message_type, $messenger),
3457
-                    'slug'     => $message_type->name,
3458
-                    'active'   => $a_or_i === 'active',
3459
-                    'obj'      => $message_type,
3460
-                ];
3461
-            }
3462
-        }
3463
-    }
3464
-
3465
-
3466
-    /**
3467
-     * This just prepares the content for the message type settings
3468
-     *
3469
-     * @param EE_message_type $message_type The message type object
3470
-     * @param EE_messenger    $messenger    The messenger object
3471
-     * @param boolean         $active       Whether the message type is active or not
3472
-     * @return string html output for the content
3473
-     * @throws DomainException
3474
-     */
3475
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3476
-    {
3477
-        // get message type fields
3478
-        $fields                                         = $message_type->get_admin_settings_fields();
3479
-        $settings_template_args['template_form_fields'] = '';
3480
-
3481
-        if (! empty($fields) && $active) {
3482
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3483
-            foreach ($fields as $fldname => $fldprops) {
3484
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3485
-                $template_form_field[ $field_id ] = [
3486
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3487
-                    'label'      => $fldprops['label'],
3488
-                    'input'      => $fldprops['field_type'],
3489
-                    'type'       => $fldprops['value_type'],
3490
-                    'required'   => $fldprops['required'],
3491
-                    'validation' => $fldprops['validation'],
3492
-                    'value'      => isset($existing_settings[ $fldname ])
3493
-                        ? $existing_settings[ $fldname ]
3494
-                        : $fldprops['default'],
3495
-                    'options'    => isset($fldprops['options'])
3496
-                        ? $fldprops['options']
3497
-                        : [],
3498
-                    'default'    => isset($existing_settings[ $fldname ])
3499
-                        ? $existing_settings[ $fldname ]
3500
-                        : $fldprops['default'],
3501
-                    'css_class'  => 'no-drag',
3502
-                    'format'     => $fldprops['format'],
3503
-                ];
3504
-            }
3505
-
3506
-
3507
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3508
-                ? $this->_generate_admin_form_fields(
3509
-                    $template_form_field,
3510
-                    'string',
3511
-                    'ee_mt_activate_form'
3512
-                )
3513
-                : '';
3514
-        }
3515
-
3516
-        $settings_template_args['description'] = $message_type->description;
3517
-        // we also need some hidden fields
3518
-        $hidden_fields = [
3519
-            'message_type_settings[messenger]' . $message_type->name    => [
3520
-                'type'  => 'hidden',
3521
-                'value' => $messenger->name,
3522
-            ],
3523
-            'message_type_settings[message_type]' . $message_type->name => [
3524
-                'type'  => 'hidden',
3525
-                'value' => $message_type->name,
3526
-            ],
3527
-            'type' . $message_type->name                                => [
3528
-                'type'  => 'hidden',
3529
-                'value' => 'message_type',
3530
-            ],
3531
-        ];
3532
-
3533
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3534
-            $hidden_fields,
3535
-            'array'
3536
-        );
3537
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3538
-            ? ' hidden'
3539
-            : '';
3540
-
3541
-
3542
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3543
-        return EEH_Template::display_template($template, $settings_template_args, true);
3544
-    }
3545
-
3546
-
3547
-    /**
3548
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3549
-     *
3550
-     * @access protected
3551
-     * @return void
3552
-     * @throws DomainException
3553
-     */
3554
-    protected function _messages_settings_metaboxes()
3555
-    {
3556
-        $this->_set_m_mt_settings();
3557
-        $m_boxes         = $mt_boxes = [];
3558
-        $m_template_args = $mt_template_args = [];
3559
-
3560
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3561
-
3562
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3563
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3564
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3565
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3566
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3567
-
3568
-                // messenger meta boxes
3569
-                $active         = $selected_messenger === $messenger;
3570
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3571
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3572
-                    : '';
3573
-
3574
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3575
-                    esc_html__('%s Settings', 'event_espresso'),
3576
-                    $tab_array['label']
3577
-                );
3578
-
3579
-                $m_template_args[ $messenger . '_a_box' ] = [
3580
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3581
-                    'inactive_message_types' => isset(
3582
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3583
-                    )
3584
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3585
-                        : '',
3586
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3587
-                    'hidden'                 => $active ? '' : ' hidden',
3588
-                    'hide_on_message'        => $hide_on_message,
3589
-                    'messenger'              => $messenger,
3590
-                    'active'                 => $active,
3591
-                ];
3592
-
3593
-                // message type meta boxes
3594
-                // (which is really just the inactive container for each messenger
3595
-                // showing inactive message types for that messenger)
3596
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3597
-                $mt_template_args[ $messenger . '_i_box' ] = [
3598
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3599
-                    'inactive_message_types' => isset(
3600
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3601
-                    )
3602
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3603
-                        : '',
3604
-                    'hidden'                 => $active ? '' : ' hidden',
3605
-                    'hide_on_message'        => $hide_on_message,
3606
-                    'hide_off_message'       => $hide_off_message,
3607
-                    'messenger'              => $messenger,
3608
-                    'active'                 => $active,
3609
-                ];
3610
-            }
3611
-        }
3612
-
3613
-
3614
-        // register messenger metaboxes
3615
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3616
-        foreach ($m_boxes as $box => $label) {
3617
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3618
-            $msgr          = str_replace('_a_box', '', $box);
3619
-            $this->addMetaBox(
3620
-                'espresso_' . $msgr . '_settings',
3621
-                $label,
3622
-                function ($post, $metabox) {
3623
-                    EEH_Template::display_template(
3624
-                        $metabox['args']['template_path'],
3625
-                        $metabox['args']['template_args']
3626
-                    );
3627
-                },
3628
-                $this->_current_screen->id,
3629
-                'normal',
3630
-                'high',
3631
-                $callback_args
3632
-            );
3633
-        }
3634
-
3635
-        // register message type metaboxes
3636
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3637
-        foreach ($mt_boxes as $box => $label) {
3638
-            $callback_args = [
3639
-                'template_path' => $mt_template_path,
3640
-                'template_args' => $mt_template_args[ $box ],
3641
-            ];
3642
-            $mt            = str_replace('_i_box', '', $box);
3643
-            $this->addMetaBox(
3644
-                'espresso_' . $mt . '_inactive_mts',
3645
-                $label,
3646
-                function ($post, $metabox) {
3647
-                    EEH_Template::display_template(
3648
-                        $metabox['args']['template_path'],
3649
-                        $metabox['args']['template_args']
3650
-                    );
3651
-                },
3652
-                $this->_current_screen->id,
3653
-                'side',
3654
-                'high',
3655
-                $callback_args
3656
-            );
3657
-        }
3658
-
3659
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3660
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3661
-        if (is_main_site()) {
3662
-            $this->addMetaBox(
3663
-                'espresso_global_message_settings',
3664
-                esc_html__('Global Message Settings', 'event_espresso'),
3665
-                [$this, 'global_messages_settings_metabox_content'],
3666
-                $this->_current_screen->id,
3667
-                'normal',
3668
-                'low',
3669
-                []
3670
-            );
3671
-        }
3672
-    }
3673
-
3674
-
3675
-    /**
3676
-     *  This generates the content for the global messages settings metabox.
3677
-     *
3678
-     * @return void
3679
-     * @throws EE_Error
3680
-     * @throws InvalidArgumentException
3681
-     * @throws ReflectionException
3682
-     * @throws InvalidDataTypeException
3683
-     * @throws InvalidInterfaceException
3684
-     */
3685
-    public function global_messages_settings_metabox_content()
3686
-    {
3687
-        $form = $this->_generate_global_settings_form();
3688
-        echo wp_kses(
3689
-            $form->form_open(
3690
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3691
-                'POST'
3692
-            ),
3693
-            AllowedTags::getWithFormTags()
3694
-        );
3695
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3696
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3697
-    }
3698
-
3699
-
3700
-    /**
3701
-     * This generates and returns the form object for the global messages settings.
3702
-     *
3703
-     * @return EE_Form_Section_Proper
3704
-     * @throws EE_Error
3705
-     * @throws InvalidArgumentException
3706
-     * @throws ReflectionException
3707
-     * @throws InvalidDataTypeException
3708
-     * @throws InvalidInterfaceException
3709
-     */
3710
-    protected function _generate_global_settings_form()
3711
-    {
3712
-        /** @var EE_Network_Core_Config $network_config */
3713
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3714
-
3715
-        return new EE_Form_Section_Proper(
3716
-            [
3717
-                'name'            => 'global_messages_settings',
3718
-                'html_id'         => 'global_messages_settings',
3719
-                'html_class'      => 'form-table',
3720
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3721
-                'subsections'     => apply_filters(
3722
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3723
-                    [
3724
-                        'do_messages_on_same_request' => new EE_Select_Input(
3725
-                            [
3726
-                                true  => esc_html__('On the same request', 'event_espresso'),
3727
-                                false => esc_html__('On a separate request', 'event_espresso'),
3728
-                            ],
3729
-                            [
3730
-                                'default'         => $network_config->do_messages_on_same_request,
3731
-                                'html_label_text' => esc_html__(
3732
-                                    'Generate and send all messages:',
3733
-                                    'event_espresso'
3734
-                                ),
3735
-                                'html_help_text'  => esc_html__(
3736
-                                    '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.',
3737
-                                    'event_espresso'
3738
-                                ),
3739
-                            ]
3740
-                        ),
3741
-                        'delete_threshold'            => new EE_Select_Input(
3742
-                            [
3743
-                                0  => esc_html__('Forever', 'event_espresso'),
3744
-                                3  => esc_html__('3 Months', 'event_espresso'),
3745
-                                6  => esc_html__('6 Months', 'event_espresso'),
3746
-                                9  => esc_html__('9 Months', 'event_espresso'),
3747
-                                12 => esc_html__('12 Months', 'event_espresso'),
3748
-                                24 => esc_html__('24 Months', 'event_espresso'),
3749
-                                36 => esc_html__('36 Months', 'event_espresso'),
3750
-                            ],
3751
-                            [
3752
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3753
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3754
-                                'html_help_text'  => esc_html__(
3755
-                                    'You can control how long a record of processed messages is kept via this option.',
3756
-                                    'event_espresso'
3757
-                                ),
3758
-                            ]
3759
-                        ),
3760
-                        'update_settings'             => new EE_Submit_Input(
3761
-                            [
3762
-                                'default'         => esc_html__('Update', 'event_espresso'),
3763
-                                'html_label_text' => '',
3764
-                            ]
3765
-                        ),
3766
-                    ]
3767
-                ),
3768
-            ]
3769
-        );
3770
-    }
3771
-
3772
-
3773
-    /**
3774
-     * This handles updating the global settings set on the admin page.
3775
-     *
3776
-     * @throws EE_Error
3777
-     * @throws InvalidDataTypeException
3778
-     * @throws InvalidInterfaceException
3779
-     * @throws InvalidArgumentException
3780
-     * @throws ReflectionException
3781
-     */
3782
-    protected function _update_global_settings()
3783
-    {
3784
-        /** @var EE_Network_Core_Config $network_config */
3785
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3786
-        $messages_config = EE_Registry::instance()->CFG->messages;
3787
-        $form            = $this->_generate_global_settings_form();
3788
-        if ($form->was_submitted()) {
3789
-            $form->receive_form_submission();
3790
-            if ($form->is_valid()) {
3791
-                $valid_data = $form->valid_data();
3792
-                foreach ($valid_data as $property => $value) {
3793
-                    $setter = 'set_' . $property;
3794
-                    if (method_exists($network_config, $setter)) {
3795
-                        $network_config->{$setter}($value);
3796
-                    } elseif (
3797
-                        property_exists($network_config, $property)
3798
-                        && $network_config->{$property} !== $value
3799
-                    ) {
3800
-                        $network_config->{$property} = $value;
3801
-                    } elseif (
3802
-                        property_exists($messages_config, $property)
3803
-                        && $messages_config->{$property} !== $value
3804
-                    ) {
3805
-                        $messages_config->{$property} = $value;
3806
-                    }
3807
-                }
3808
-                // only update if the form submission was valid!
3809
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3810
-                EE_Registry::instance()->CFG->update_espresso_config();
3811
-                EE_Error::overwrite_success();
3812
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3813
-            }
3814
-        }
3815
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3816
-    }
3817
-
3818
-
3819
-    /**
3820
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3821
-     *
3822
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3823
-     * @return string html formatted tabs
3824
-     * @throws DomainException
3825
-     */
3826
-    protected function _get_mt_tabs($tab_array)
3827
-    {
3828
-        $tab_array = (array) $tab_array;
3829
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3830
-        $tabs      = '';
3831
-
3832
-        foreach ($tab_array as $tab) {
3833
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3834
-        }
3835
-
3836
-        return $tabs;
3837
-    }
3838
-
3839
-
3840
-    /**
3841
-     * This prepares the content of the messenger meta box admin settings
3842
-     *
3843
-     * @param EE_messenger $messenger The messenger we're setting up content for
3844
-     * @return string html formatted content
3845
-     * @throws DomainException
3846
-     */
3847
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3848
-    {
3849
-
3850
-        $fields = $messenger->get_admin_settings_fields();
3851
-
3852
-        $settings_template_args['template_form_fields'] = '';
3853
-        // is $messenger active?
3854
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3855
-
3856
-
3857
-        if (! empty($fields)) {
3858
-            $existing_settings = $messenger->get_existing_admin_settings();
3859
-
3860
-            foreach ($fields as $field_name => $field_props) {
3861
-                $field_id                         = $messenger->name . '-' . $field_name;
3862
-                $template_form_field[ $field_id ] = [
3863
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3864
-                    'label'      => $field_props['label'],
3865
-                    'input'      => $field_props['field_type'],
3866
-                    'type'       => $field_props['value_type'],
3867
-                    'required'   => $field_props['required'],
3868
-                    'validation' => $field_props['validation'],
3869
-                    'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3870
-                    'css_class'  => '',
3871
-                    'format'     => $field_props['format'],
3872
-                ];
3873
-            }
3874
-
3875
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3876
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3877
-                : '';
3878
-        }
3879
-
3880
-        // we also need some hidden fields
3881
-        $settings_template_args['hidden_fields'] = [
3882
-            'messenger_settings[messenger]' . $messenger->name => [
3883
-                'type'  => 'hidden',
3884
-                'value' => $messenger->name,
3885
-            ],
3886
-            'type' . $messenger->name                          => [
3887
-                'type'  => 'hidden',
3888
-                'value' => 'messenger',
3889
-            ],
3890
-        ];
3891
-
3892
-        // make sure any active message types that are existing are included in the hidden fields
3893
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3894
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3895
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3896
-                    'type'  => 'hidden',
3897
-                    'value' => $mt,
3898
-                ];
3899
-            }
3900
-        }
3901
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3902
-            $settings_template_args['hidden_fields'],
3903
-            'array'
3904
-        );
3905
-        $active                                  =
3906
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3907
-
3908
-        $settings_template_args['messenger']           = $messenger->name;
3909
-        $settings_template_args['description']         = $messenger->description;
3910
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3911
-
3912
-
3913
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3914
-            $messenger->name
3915
-        )
3916
-            ? $settings_template_args['show_hide_edit_form']
3917
-            : ' hidden';
3918
-
3919
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3920
-            ? ' hidden'
3921
-            : $settings_template_args['show_hide_edit_form'];
3922
-
3923
-
3924
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3925
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3926
-        $settings_template_args['on_off_status'] = $active;
3927
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3928
-        return EEH_Template::display_template(
3929
-            $template,
3930
-            $settings_template_args,
3931
-            true
3932
-        );
3933
-    }
3934
-
3935
-
3936
-    /**
3937
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3938
-     *
3939
-     * @throws DomainException
3940
-     * @throws EE_Error
3941
-     * @throws InvalidDataTypeException
3942
-     * @throws InvalidInterfaceException
3943
-     * @throws InvalidArgumentException
3944
-     * @throws ReflectionException
3945
-     */
3946
-    public function activate_messenger_toggle()
3947
-    {
3948
-        $success = true;
3949
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3950
-        // let's check that we have required data
3951
-
3952
-        if (! $this->_active_messenger_name) {
3953
-            EE_Error::add_error(
3954
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3955
-                __FILE__,
3956
-                __FUNCTION__,
3957
-                __LINE__
3958
-            );
3959
-            $success = false;
3960
-        }
3961
-
3962
-        // do a nonce check here since we're not arriving via a normal route
3963
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
3964
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
3965
-
3966
-        $this->_verify_nonce($nonce, $nonce_ref);
3967
-
3968
-
3969
-        $status = $this->request->getRequestParam('status');
3970
-        if (! $status) {
3971
-            EE_Error::add_error(
3972
-                esc_html__(
3973
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3974
-                    'event_espresso'
3975
-                ),
3976
-                __FILE__,
3977
-                __FUNCTION__,
3978
-                __LINE__
3979
-            );
3980
-            $success = false;
3981
-        }
3982
-
3983
-        // do check to verify we have a valid status.
3984
-        if ($status !== 'off' && $status !== 'on') {
3985
-            EE_Error::add_error(
3986
-                sprintf(
3987
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3988
-                    $status
3989
-                ),
3990
-                __FILE__,
3991
-                __FUNCTION__,
3992
-                __LINE__
3993
-            );
3994
-            $success = false;
3995
-        }
3996
-
3997
-        if ($success) {
3998
-            // made it here?  Stop dawdling then!!
3999
-            $success = $status === 'off'
4000
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4001
-                : $this->_activate_messenger($this->_active_messenger_name);
4002
-        }
4003
-
4004
-        $this->_template_args['success'] = $success;
4005
-
4006
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4007
-        $this->_return_json();
4008
-    }
4009
-
4010
-
4011
-    /**
4012
-     * used by ajax from the messages settings page to activate|deactivate a message type
4013
-     *
4014
-     * @throws DomainException
4015
-     * @throws EE_Error
4016
-     * @throws ReflectionException
4017
-     * @throws InvalidDataTypeException
4018
-     * @throws InvalidInterfaceException
4019
-     * @throws InvalidArgumentException
4020
-     */
4021
-    public function activate_mt_toggle()
4022
-    {
4023
-        $success = true;
4024
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4025
-
4026
-        // let's make sure we have the necessary data
4027
-        if (! $this->_active_message_type_name) {
4028
-            EE_Error::add_error(
4029
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4030
-                __FILE__,
4031
-                __FUNCTION__,
4032
-                __LINE__
4033
-            );
4034
-            $success = false;
4035
-        }
4036
-
4037
-        if (! $this->_active_messenger_name) {
4038
-            EE_Error::add_error(
4039
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4040
-                __FILE__,
4041
-                __FUNCTION__,
4042
-                __LINE__
4043
-            );
4044
-            $success = false;
4045
-        }
4046
-
4047
-        $status = $this->request->getRequestParam('status');
4048
-        if (! $status) {
4049
-            EE_Error::add_error(
4050
-                esc_html__(
4051
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4052
-                    'event_espresso'
4053
-                ),
4054
-                __FILE__,
4055
-                __FUNCTION__,
4056
-                __LINE__
4057
-            );
4058
-            $success = false;
4059
-        }
4060
-
4061
-
4062
-        // do check to verify we have a valid status.
4063
-        if ($status !== 'activate' && $status !== 'deactivate') {
4064
-            EE_Error::add_error(
4065
-                sprintf(
4066
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4067
-                    $status
4068
-                ),
4069
-                __FILE__,
4070
-                __FUNCTION__,
4071
-                __LINE__
4072
-            );
4073
-            $success = false;
4074
-        }
4075
-
4076
-
4077
-        // do a nonce check here since we're not arriving via a normal route
4078
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4079
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4080
-
4081
-        if ($success) {
4082
-            // made it here? um, what are you waiting for then?
4083
-            $success = $status === 'deactivate'
4084
-                ? $this->_deactivate_message_type_for_messenger(
4085
-                    $this->_active_messenger_name,
4086
-                    $this->_active_message_type_name
4087
-                )
4088
-                : $this->_activate_message_type_for_messenger(
4089
-                    $this->_active_messenger_name,
4090
-                    $this->_active_message_type_name
4091
-                );
4092
-        }
4093
-
4094
-        $this->_template_args['success'] = $success;
4095
-        $this->_return_json();
4096
-    }
4097
-
4098
-
4099
-    /**
4100
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4101
-     *
4102
-     * @param string $messenger_name The name of the messenger being activated
4103
-     * @return bool
4104
-     * @throws DomainException
4105
-     * @throws EE_Error
4106
-     * @throws InvalidArgumentException
4107
-     * @throws ReflectionException
4108
-     * @throws InvalidDataTypeException
4109
-     * @throws InvalidInterfaceException
4110
-     */
4111
-    protected function _activate_messenger($messenger_name)
4112
-    {
4113
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4114
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4115
-            ? $active_messenger->get_default_message_types()
4116
-            : [];
4117
-
4118
-        // ensure is active
4119
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4120
-
4121
-        // set response_data for reload
4122
-        foreach ($message_types_to_activate as $message_type_name) {
4123
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4124
-            if (
4125
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4126
-                    $messenger_name,
4127
-                    $message_type_name
4128
-                )
4129
-                && $message_type instanceof EE_message_type
4130
-            ) {
4131
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4132
-                if ($message_type->get_admin_settings_fields()) {
4133
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4134
-                }
4135
-            }
4136
-        }
4137
-
4138
-        // add success message for activating messenger
4139
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4140
-    }
4141
-
4142
-
4143
-    /**
4144
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4145
-     *
4146
-     * @param string $messenger_name The name of the messenger being activated
4147
-     * @return bool
4148
-     * @throws DomainException
4149
-     * @throws EE_Error
4150
-     * @throws InvalidArgumentException
4151
-     * @throws ReflectionException
4152
-     * @throws InvalidDataTypeException
4153
-     * @throws InvalidInterfaceException
4154
-     */
4155
-    protected function _deactivate_messenger($messenger_name)
4156
-    {
4157
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4158
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4159
-
4160
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4161
-    }
4162
-
4163
-
4164
-    /**
4165
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4166
-     *
4167
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4168
-     * @param string $message_type_name The name of the message type being activated for the messenger
4169
-     * @return bool
4170
-     * @throws DomainException
4171
-     * @throws EE_Error
4172
-     * @throws InvalidArgumentException
4173
-     * @throws ReflectionException
4174
-     * @throws InvalidDataTypeException
4175
-     * @throws InvalidInterfaceException
4176
-     */
4177
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4178
-    {
4179
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4180
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4181
-
4182
-        // ensure is active
4183
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4184
-
4185
-        // set response for load
4186
-        if (
4187
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4188
-                $messenger_name,
4189
-                $message_type_name
4190
-            )
4191
-        ) {
4192
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4193
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4194
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4195
-            }
4196
-        }
4197
-
4198
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4199
-            $active_messenger,
4200
-            $message_type_to_activate
4201
-        );
4202
-    }
4203
-
4204
-
4205
-    /**
4206
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4207
-     *
4208
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4209
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4210
-     * @return bool
4211
-     * @throws DomainException
4212
-     * @throws EE_Error
4213
-     * @throws InvalidArgumentException
4214
-     * @throws ReflectionException
4215
-     * @throws InvalidDataTypeException
4216
-     * @throws InvalidInterfaceException
4217
-     */
4218
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4219
-    {
4220
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4221
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4222
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4223
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4224
-
4225
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4226
-            $active_messenger,
4227
-            $message_type_to_deactivate
4228
-        );
4229
-    }
4230
-
4231
-
4232
-    /**
4233
-     * This just initializes the defaults for activating messenger and message type responses.
4234
-     */
4235
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4236
-    {
4237
-        $this->_template_args['data']['active_mts'] = [];
4238
-        $this->_template_args['data']['mt_reload']  = [];
4239
-    }
4240
-
4241
-
4242
-    /**
4243
-     * Setup appropriate response for activating a messenger and/or message types
4244
-     *
4245
-     * @param EE_messenger         $messenger
4246
-     * @param EE_message_type|null $message_type
4247
-     * @return bool
4248
-     * @throws DomainException
4249
-     * @throws EE_Error
4250
-     * @throws InvalidArgumentException
4251
-     * @throws ReflectionException
4252
-     * @throws InvalidDataTypeException
4253
-     * @throws InvalidInterfaceException
4254
-     */
4255
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4256
-        $messenger,
4257
-        EE_Message_Type $message_type = null
4258
-    ) {
4259
-        // if $messenger isn't a valid messenger object then get out.
4260
-        if (! $messenger instanceof EE_Messenger) {
4261
-            EE_Error::add_error(
4262
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4263
-                __FILE__,
4264
-                __FUNCTION__,
4265
-                __LINE__
4266
-            );
4267
-            return false;
4268
-        }
4269
-        // activated
4270
-        if ($this->_template_args['data']['active_mts']) {
4271
-            EE_Error::overwrite_success();
4272
-            // activated a message type with the messenger
4273
-            if ($message_type instanceof EE_message_type) {
4274
-                EE_Error::add_success(
4275
-                    sprintf(
4276
-                        esc_html__(
4277
-                            '%s message type has been successfully activated with the %s messenger',
4278
-                            'event_espresso'
4279
-                        ),
4280
-                        ucwords($message_type->label['singular']),
4281
-                        ucwords($messenger->label['singular'])
4282
-                    )
4283
-                );
4284
-
4285
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4286
-                if ($message_type->name === 'invoice') {
4287
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4288
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4289
-                    if ($pm instanceof EE_Payment_Method) {
4290
-                        EE_Error::add_attention(
4291
-                            esc_html__(
4292
-                                '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.',
4293
-                                'event_espresso'
4294
-                            )
4295
-                        );
4296
-                    }
4297
-                }
4298
-                // just toggles the entire messenger
4299
-            } else {
4300
-                EE_Error::add_success(
4301
-                    sprintf(
4302
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4303
-                        ucwords($messenger->label['singular'])
4304
-                    )
4305
-                );
4306
-            }
4307
-
4308
-            return true;
4309
-
4310
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4311
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4312
-            // in which case we just give a success message for the messenger being successfully activated.
4313
-        } else {
4314
-            if (! $messenger->get_default_message_types()) {
4315
-                // messenger doesn't have any default message types so still a success.
4316
-                EE_Error::add_success(
4317
-                    sprintf(
4318
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4319
-                        ucwords($messenger->label['singular'])
4320
-                    )
4321
-                );
4322
-
4323
-                return true;
4324
-            } else {
4325
-                EE_Error::add_error(
4326
-                    $message_type instanceof EE_message_type
4327
-                    ? sprintf(
4328
-                        esc_html__(
4329
-                            '%s message type was not successfully activated with the %s messenger',
4330
-                            'event_espresso'
4331
-                        ),
4332
-                        ucwords($message_type->label['singular']),
4333
-                        ucwords($messenger->label['singular'])
4334
-                    )
4335
-                    : sprintf(
4336
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4337
-                        ucwords($messenger->label['singular'])
4338
-                    ),
4339
-                    __FILE__,
4340
-                    __FUNCTION__,
4341
-                    __LINE__
4342
-                );
4343
-
4344
-                return false;
4345
-            }
4346
-        }
4347
-    }
4348
-
4349
-
4350
-    /**
4351
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4352
-     *
4353
-     * @param EE_messenger         $messenger
4354
-     * @param EE_message_type|null $message_type
4355
-     * @return bool
4356
-     * @throws DomainException
4357
-     * @throws EE_Error
4358
-     * @throws InvalidArgumentException
4359
-     * @throws ReflectionException
4360
-     * @throws InvalidDataTypeException
4361
-     * @throws InvalidInterfaceException
4362
-     */
4363
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4364
-        $messenger,
4365
-        EE_message_type $message_type = null
4366
-    ) {
4367
-        EE_Error::overwrite_success();
4368
-
4369
-        // if $messenger isn't a valid messenger object then get out.
4370
-        if (! $messenger instanceof EE_Messenger) {
4371
-            EE_Error::add_error(
4372
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4373
-                __FILE__,
4374
-                __FUNCTION__,
4375
-                __LINE__
4376
-            );
4377
-
4378
-            return false;
4379
-        }
4380
-
4381
-        if ($message_type instanceof EE_message_type) {
4382
-            $message_type_name = $message_type->name;
4383
-            EE_Error::add_success(
4384
-                sprintf(
4385
-                    esc_html__(
4386
-                        '%s message type has been successfully deactivated for the %s messenger.',
4387
-                        'event_espresso'
4388
-                    ),
4389
-                    ucwords($message_type->label['singular']),
4390
-                    ucwords($messenger->label['singular'])
4391
-                )
4392
-            );
4393
-        } else {
4394
-            $message_type_name = '';
4395
-            EE_Error::add_success(
4396
-                sprintf(
4397
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4398
-                    ucwords($messenger->label['singular'])
4399
-                )
4400
-            );
4401
-        }
4402
-
4403
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4404
-        if (
4405
-            $messenger->name === 'html'
4406
-            && (
4407
-                is_null($message_type)
4408
-                || $message_type_name === 'invoice'
4409
-            )
4410
-        ) {
4411
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4412
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4413
-            if ($count_updated > 0) {
4414
-                $msg = $message_type_name === 'invoice'
4415
-                    ? esc_html__(
4416
-                        '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.',
4417
-                        'event_espresso'
4418
-                    )
4419
-                    : esc_html__(
4420
-                        '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.',
4421
-                        'event_espresso'
4422
-                    );
4423
-                EE_Error::add_attention($msg);
4424
-            }
4425
-        }
4426
-
4427
-        return true;
4428
-    }
4429
-
4430
-
4431
-    /**
4432
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4433
-     *
4434
-     * @throws DomainException
4435
-     * @throws EE_Error
4436
-     * @throws EE_Error
4437
-     */
4438
-    public function update_mt_form()
4439
-    {
4440
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4441
-            EE_Error::add_error(
4442
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4443
-                __FILE__,
4444
-                __FUNCTION__,
4445
-                __LINE__
4446
-            );
4447
-            $this->_return_json();
4448
-        }
4449
-
4450
-        $message_types = $this->get_installed_message_types();
4451
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4452
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4453
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4454
-
4455
-        $this->_template_args['success'] = true;
4456
-        $this->_template_args['content'] = $content;
4457
-        $this->_return_json();
4458
-    }
4459
-
4460
-
4461
-    /**
4462
-     * this handles saving the settings for a messenger or message type
4463
-     *
4464
-     * @throws EE_Error
4465
-     * @throws EE_Error
4466
-     */
4467
-    public function save_settings()
4468
-    {
4469
-        $type = $this->request->getRequestParam('type');
4470
-        if (! $type) {
4471
-            EE_Error::add_error(
4472
-                esc_html__(
4473
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4474
-                    'event_espresso'
4475
-                ),
4476
-                __FILE__,
4477
-                __FUNCTION__,
4478
-                __LINE__
4479
-            );
4480
-            $this->_template_args['error'] = true;
4481
-            $this->_return_json();
4482
-        }
4483
-
4484
-
4485
-        if ($type === 'messenger') {
4486
-            // this should be an array.
4487
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4488
-            $messenger = $settings['messenger'];
4489
-            // remove messenger and message_types from settings array
4490
-            unset($settings['messenger'], $settings['message_types']);
4491
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4492
-        } elseif ($type === 'message_type') {
4493
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4494
-            $messenger    = $settings['messenger'];
4495
-            $message_type = $settings['message_type'];
4496
-            // remove messenger and message_types from settings array
4497
-            unset($settings['messenger'], $settings['message_types']);
4498
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4499
-        }
4500
-
4501
-        // okay we should have the data all setup.  Now we just update!
4502
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4503
-
4504
-        if ($success) {
4505
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4506
-        } else {
4507
-            EE_Error::add_error(
4508
-                esc_html__('Settings did not get updated', 'event_espresso'),
4509
-                __FILE__,
4510
-                __FUNCTION__,
4511
-                __LINE__
4512
-            );
4513
-        }
4514
-
4515
-        $this->_template_args['success'] = $success;
4516
-        $this->_return_json();
4517
-    }
4518
-
4519
-
4520
-
4521
-
4522
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4523
-
4524
-
4525
-    /**
4526
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4527
-     * However, this does not send immediately, it just queues for sending.
4528
-     *
4529
-     * @throws EE_Error
4530
-     * @throws InvalidDataTypeException
4531
-     * @throws InvalidInterfaceException
4532
-     * @throws InvalidArgumentException
4533
-     * @throws ReflectionException
4534
-     * @since 4.9.0
4535
-     */
4536
-    protected function _generate_now()
4537
-    {
4538
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4539
-        $this->_redirect_after_action(false, '', '', [], true);
4540
-    }
4541
-
4542
-
4543
-    /**
4544
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4545
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4546
-     *
4547
-     * @throws EE_Error
4548
-     * @throws InvalidDataTypeException
4549
-     * @throws InvalidInterfaceException
4550
-     * @throws InvalidArgumentException
4551
-     * @throws ReflectionException
4552
-     * @since 4.9.0
4553
-     */
4554
-    protected function _generate_and_send_now()
4555
-    {
4556
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4557
-        $this->_redirect_after_action(false, '', '', [], true);
4558
-    }
4559
-
4560
-
4561
-    /**
4562
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4563
-     *
4564
-     * @throws EE_Error
4565
-     * @throws InvalidDataTypeException
4566
-     * @throws InvalidInterfaceException
4567
-     * @throws InvalidArgumentException
4568
-     * @throws ReflectionException
4569
-     * @since 4.9.0
4570
-     */
4571
-    protected function _queue_for_resending()
4572
-    {
4573
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4574
-        $this->_redirect_after_action(false, '', '', [], true);
4575
-    }
4576
-
4577
-
4578
-    /**
4579
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4580
-     *
4581
-     * @throws EE_Error
4582
-     * @throws InvalidDataTypeException
4583
-     * @throws InvalidInterfaceException
4584
-     * @throws InvalidArgumentException
4585
-     * @throws ReflectionException
4586
-     * @since 4.9.0
4587
-     */
4588
-    protected function _send_now()
4589
-    {
4590
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4591
-        $this->_redirect_after_action(false, '', '', [], true);
4592
-    }
4593
-
4594
-
4595
-    /**
4596
-     * Deletes EE_messages for IDs in the request.
4597
-     *
4598
-     * @throws EE_Error
4599
-     * @throws InvalidDataTypeException
4600
-     * @throws InvalidInterfaceException
4601
-     * @throws InvalidArgumentException
4602
-     * @since 4.9.0
4603
-     */
4604
-    protected function _delete_ee_messages()
4605
-    {
4606
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4607
-        $deleted_count = 0;
4608
-        foreach ($MSG_IDs as $MSG_ID) {
4609
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4610
-                $deleted_count++;
4611
-            }
4612
-        }
4613
-        if ($deleted_count) {
4614
-            EE_Error::add_success(
4615
-                esc_html(
4616
-                    _n(
4617
-                        'Message successfully deleted',
4618
-                        'Messages successfully deleted',
4619
-                        $deleted_count,
4620
-                        'event_espresso'
4621
-                    )
4622
-                )
4623
-            );
4624
-        } else {
4625
-            EE_Error::add_error(
4626
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4627
-                __FILE__,
4628
-                __FUNCTION__,
4629
-                __LINE__
4630
-            );
4631
-        }
4632
-        $this->_redirect_after_action(false, '', '', [], true);
4633
-    }
4634
-
4635
-
4636
-    /**
4637
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4638
-     *
4639
-     * @return array
4640
-     * @since 4.9.0
4641
-     */
4642
-    protected function _get_msg_ids_from_request()
4643
-    {
4644
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4645
-        if (empty($MSG_IDs)) {
4646
-            return [];
4647
-        }
4648
-        // if 'MSG_ID' was just a single ID (not an array)
4649
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4650
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4651
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4652
-            ? $MSG_IDs
4653
-            : array_keys($MSG_IDs);
4654
-    }
2580
+	}
2581
+
2582
+
2583
+	/**
2584
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2585
+	 *
2586
+	 * @access protected
2587
+	 * @return void
2588
+	 * @throws EE_Error
2589
+	 * @throws InvalidArgumentException
2590
+	 * @throws ReflectionException
2591
+	 * @throws InvalidDataTypeException
2592
+	 * @throws InvalidInterfaceException
2593
+	 */
2594
+	protected function _set_shortcodes()
2595
+	{
2596
+
2597
+		// no need to run this if the property is already set
2598
+		if (! empty($this->_shortcodes)) {
2599
+			return;
2600
+		}
2601
+
2602
+		$this->_shortcodes = $this->_get_shortcodes();
2603
+	}
2604
+
2605
+
2606
+	/**
2607
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2608
+	 * property)
2609
+	 *
2610
+	 * @access  protected
2611
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2612
+	 *                         for. Defaults to all (for the given context)
2613
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2614
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2615
+	 *                         true just an array of shortcode/label pairs.
2616
+	 * @throws EE_Error
2617
+	 * @throws InvalidArgumentException
2618
+	 * @throws ReflectionException
2619
+	 * @throws InvalidDataTypeException
2620
+	 * @throws InvalidInterfaceException
2621
+	 */
2622
+	protected function _get_shortcodes($fields = [], $merged = true)
2623
+	{
2624
+		$this->_set_message_template_group();
2625
+
2626
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2627
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2628
+		if (empty($GRP_ID)) {
2629
+			return [];
2630
+		}
2631
+		$context = $this->request->getRequestParam(
2632
+			'messenger',
2633
+			key($this->_message_template_group->contexts_config())
2634
+		);
2635
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2636
+	}
2637
+
2638
+
2639
+	/**
2640
+	 * This sets the _message_template property (containing the called message_template object)
2641
+	 *
2642
+	 * @access protected
2643
+	 * @return void
2644
+	 * @throws EE_Error
2645
+	 * @throws InvalidArgumentException
2646
+	 * @throws ReflectionException
2647
+	 * @throws InvalidDataTypeException
2648
+	 * @throws InvalidInterfaceException
2649
+	 */
2650
+	protected function _set_message_template_group()
2651
+	{
2652
+		// get out if this is already set.
2653
+		if (! empty($this->_message_template_group)) {
2654
+			return;
2655
+		}
2656
+
2657
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2658
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2659
+
2660
+		// let's get the message templates
2661
+		$this->_message_template_group = ! empty($GRP_ID)
2662
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2663
+			: $this->getMtgModel()->create_default_object();
2664
+
2665
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2666
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2667
+	}
2668
+
2669
+	/**
2670
+	 * @param bool $new
2671
+	 * @throws EE_Error
2672
+	 * @throws ReflectionException
2673
+	 */
2674
+	protected function _insert_or_update_message_template($new = false)
2675
+	{
2676
+		$form_data    = $this->getMessageTemplateFormData();
2677
+		$GRP_ID       = $form_data['GRP_ID'];
2678
+		$messenger    = $form_data['MTP_messenger'];
2679
+		$message_type = $form_data['MTP_message_type'];
2680
+		$context      = $form_data['MTP_context'];
2681
+
2682
+		// if this is "new" then we need to generate the default contexts
2683
+		// for the selected messenger/message_type for user to edit.
2684
+		[$success, $query_args] = $new
2685
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2686
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2687
+
2688
+		$success     = $success ? 1 : 0;
2689
+		$action_desc = $new ? 'created' : 'updated';
2690
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2691
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2692
+
2693
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2694
+	}
2695
+
2696
+
2697
+	/**
2698
+	 * retrieve and sanitize form data
2699
+	 *
2700
+	 * @return array
2701
+	 * @since 4.10.29.p
2702
+	 */
2703
+	protected function getMessageTemplateFormData()
2704
+	{
2705
+		return [
2706
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2707
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2708
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2709
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2710
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2711
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2712
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2713
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2714
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2715
+		];
2716
+	}
2717
+
2718
+
2719
+	/**
2720
+	 * @param int    $GRP_ID
2721
+	 * @param string $messenger
2722
+	 * @param string $message_type
2723
+	 * @return array no return on AJAX requests
2724
+	 * @throws EE_Error
2725
+	 * @throws ReflectionException
2726
+	 * @since 4.10.29.p
2727
+	 */
2728
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2729
+	{
2730
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2731
+		$success       = ! empty($new_templates);
2732
+
2733
+		// we return things differently if doing ajax
2734
+		if ($this->request->isAjax()) {
2735
+			$this->_template_args['success'] = $success;
2736
+			$this->_template_args['error']   = ! $success;
2737
+			$this->_template_args['content'] = '';
2738
+			$this->_template_args['data']    = [
2739
+				'grpID'        => $new_templates['GRP_ID'],
2740
+				'templateName' => $new_templates['template_name'],
2741
+			];
2742
+			if ($success) {
2743
+				EE_Error::overwrite_success();
2744
+				EE_Error::add_success(
2745
+					esc_html__(
2746
+						'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.',
2747
+						'event_espresso'
2748
+					)
2749
+				);
2750
+			}
2751
+			$this->_return_json();
2752
+		}
2753
+		return [
2754
+			$success,
2755
+			// 'query_args'
2756
+			[
2757
+				'id'      => $new_templates['GRP_ID'],
2758
+				'context' => $new_templates['MTP_context'],
2759
+				'action'  => 'edit_message_template',
2760
+			],
2761
+		];
2762
+	}
2763
+
2764
+
2765
+	/**
2766
+	 * @param int    $GRP_ID
2767
+	 * @param string $messenger
2768
+	 * @param string $message_type
2769
+	 * @param string $context
2770
+	 * @param array  $form_data
2771
+	 * @return array
2772
+	 * @throws EE_Error
2773
+	 * @since 4.10.29.p
2774
+	 */
2775
+	private function updateExistingTemplates(
2776
+		$GRP_ID,
2777
+		$messenger,
2778
+		$message_type,
2779
+		$context,
2780
+		array $form_data
2781
+	) {
2782
+		$success         = false;
2783
+		$template_fields = $this->getTemplateFields();
2784
+		if ($template_fields) {
2785
+			// if field data is valid, then success will be true
2786
+			$success = $this->validateTemplateFields(
2787
+				$messenger,
2788
+				$message_type,
2789
+				$context,
2790
+				$template_fields
2791
+			);
2792
+			if ($success) {
2793
+				$field_data = [];
2794
+				foreach ($template_fields as $template_field => $content) {
2795
+					// combine top-level form data with content for this field
2796
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2797
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2798
+				}
2799
+				// we can use the last set_column_values for the MTPG update
2800
+				// (because its the same for all of these specific MTPs)
2801
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2802
+			}
2803
+		}
2804
+
2805
+		return [
2806
+			$success,
2807
+			// 'query_args'
2808
+			[
2809
+				'id'      => $GRP_ID,
2810
+				'context' => $context,
2811
+				'action'  => 'edit_message_template',
2812
+			],
2813
+		];
2814
+	}
2815
+
2816
+
2817
+	/**
2818
+	 * @return array
2819
+	 * @since 4.10.29.p
2820
+	 */
2821
+	private function getTemplateFields()
2822
+	{
2823
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2824
+		if (empty($template_fields)) {
2825
+			EE_Error::add_error(
2826
+				esc_html__(
2827
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2828
+					'event_espresso'
2829
+				),
2830
+				__FILE__,
2831
+				__FUNCTION__,
2832
+				__LINE__
2833
+			);
2834
+			return null;
2835
+		}
2836
+		// messages content is expected to be escaped
2837
+		return EEH_Array::addSlashesRecursively($template_fields);
2838
+	}
2839
+
2840
+
2841
+	/**
2842
+	 * @param string $messenger
2843
+	 * @param string $message_type
2844
+	 * @param string $context
2845
+	 * @param array  $template_fields
2846
+	 * @return bool
2847
+	 * @throws EE_Error
2848
+	 * @since   4.10.29.p
2849
+	 */
2850
+	private function validateTemplateFields(
2851
+		$messenger,
2852
+		$message_type,
2853
+		$context,
2854
+		array $template_fields
2855
+	) {
2856
+		// first validate all fields!
2857
+		// this filter allows client code to add its own validation to the template fields as well.
2858
+		// returning an empty array means everything passed validation.
2859
+		// errors in validation should be represented in an array with the following shape:
2860
+		// array(
2861
+		//   'fieldname' => array(
2862
+		//          'msg' => 'error message'
2863
+		//          'value' => 'value for field producing error'
2864
+		// )
2865
+		$custom_validation = (array) apply_filters(
2866
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2867
+			[],
2868
+			$template_fields,
2869
+			$context,
2870
+			$messenger,
2871
+			$message_type
2872
+		);
2873
+
2874
+		$system_validation = $this->getMtgModel()->validate(
2875
+			$template_fields,
2876
+			$context,
2877
+			$messenger,
2878
+			$message_type
2879
+		);
2880
+
2881
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2882
+		$validates         = array_merge($custom_validation, $system_validation);
2883
+
2884
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2885
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2886
+		//  WE need to make sure there is no actual error messages in validates.
2887
+		if (empty($validates)) {
2888
+			return true;
2889
+		}
2890
+
2891
+		// add the transient so when the form loads we know which fields to highlight
2892
+		$this->_add_transient('edit_message_template', $validates);
2893
+		// setup notices
2894
+		foreach ($validates as $error) {
2895
+			if (isset($error['msg'])) {
2896
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2897
+			}
2898
+		}
2899
+		return false;
2900
+	}
2901
+
2902
+
2903
+	/**
2904
+	 * @param array $field_data
2905
+	 * @param array $form_data
2906
+	 * @return array
2907
+	 * @since   4.10.29.p
2908
+	 */
2909
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2910
+	{
2911
+		return $form_data + [
2912
+				'MTP_ID'             => $field_data['MTP_ID'],
2913
+				'MTP_template_field' => $field_data['name'],
2914
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2915
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2916
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2917
+					: $field_data['content'],
2918
+			];
2919
+	}
2920
+
2921
+
2922
+	/**
2923
+	 * @param string $template_field
2924
+	 * @param array  $form_data
2925
+	 * @return bool
2926
+	 * @throws EE_Error
2927
+	 * @since 4.10.29.p
2928
+	 */
2929
+	private function updateMessageTemplates($template_field, array $form_data)
2930
+	{
2931
+		$MTP_ID                  = $form_data['MTP_ID'];
2932
+		$message_template_fields = [
2933
+			'GRP_ID'             => $form_data['GRP_ID'],
2934
+			'MTP_template_field' => $form_data['MTP_template_field'],
2935
+			'MTP_context'        => $form_data['MTP_context'],
2936
+			'MTP_content'        => $form_data['MTP_content'],
2937
+		];
2938
+
2939
+		$hasMtpID = ! empty($MTP_ID);
2940
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2941
+		// this has already been through the template field validator and sanitized, so it will be
2942
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2943
+		// message template field in a messenger/message type and existing users don't have the
2944
+		// default setup for it.
2945
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2946
+		$updated = $hasMtpID
2947
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2948
+			: $this->getMtpModel()->insert($message_template_fields);
2949
+
2950
+		$insert_failed = ! $hasMtpID && ! $updated;
2951
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2952
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
2953
+		$update_failed = $hasMtpID && $updated === false;
2954
+
2955
+		if ($insert_failed || $update_failed) {
2956
+			EE_Error::add_error(
2957
+				sprintf(
2958
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2959
+					$template_field
2960
+				),
2961
+				__FILE__,
2962
+				__FUNCTION__,
2963
+				__LINE__
2964
+			);
2965
+			return false;
2966
+		}
2967
+		return true;
2968
+	}
2969
+
2970
+
2971
+	/**
2972
+	 * @param array $form_data
2973
+	 * @return bool
2974
+	 * @throws EE_Error
2975
+	 * @since 4.10.29.p
2976
+	 */
2977
+	private function updateMessageTemplateGroup(array $form_data)
2978
+	{
2979
+		$GRP_ID  = $form_data['GRP_ID'];
2980
+		$updated = $this->getMtgModel()->update(
2981
+		// fields and values
2982
+			[
2983
+				'MTP_user_id'      => $form_data['MTP_user_id'],
2984
+				'MTP_messenger'    => $form_data['MTP_messenger'],
2985
+				'MTP_message_type' => $form_data['MTP_message_type'],
2986
+				'MTP_is_global'    => $form_data['MTP_is_global'],
2987
+				'MTP_is_override'  => $form_data['MTP_is_override'],
2988
+				'MTP_deleted'      => $form_data['MTP_deleted'],
2989
+				'MTP_is_active'    => $form_data['MTP_is_active'],
2990
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
2991
+				'MTP_description'  => $this->request->getRequestParam(
2992
+					'ee_msg_non_global_fields[MTP_description]',
2993
+					''
2994
+				),
2995
+			],
2996
+			// where
2997
+			[['GRP_ID' => $GRP_ID]]
2998
+		);
2999
+
3000
+		if ($updated === false) {
3001
+			EE_Error::add_error(
3002
+				sprintf(
3003
+					esc_html__(
3004
+						'The Message Template Group (%d) was NOT updated for some reason',
3005
+						'event_espresso'
3006
+					),
3007
+					$form_data['GRP_ID']
3008
+				),
3009
+				__FILE__,
3010
+				__FUNCTION__,
3011
+				__LINE__
3012
+			);
3013
+			return false;
3014
+		}
3015
+		// k now we need to ensure the template_pack and template_variation fields are set.
3016
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3017
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3018
+
3019
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3020
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3021
+			$message_template_group->set_template_pack_name($template_pack);
3022
+			$message_template_group->set_template_pack_variation($template_variation);
3023
+		}
3024
+		return true;
3025
+	}
3026
+
3027
+
3028
+	/**
3029
+	 * recursively runs wp_kses() on message template content in a model safe manner
3030
+	 *
3031
+	 * @param array|string $content
3032
+	 * @return array|string
3033
+	 * @since   4.10.29.p
3034
+	 */
3035
+	private function sanitizeMessageTemplateContent($content)
3036
+	{
3037
+		if (is_array($content)) {
3038
+			foreach ($content as $key => $value) {
3039
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3040
+			}
3041
+			return $content;
3042
+		}
3043
+		// remove slashes so wp_kses() works properly
3044
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3045
+		// so attributes using single quotes always appear invalid.
3046
+		$content = stripslashes($content);
3047
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3048
+		// But currently the models expect slashed data, so after wp_kses()
3049
+		// runs we need to re-slash the data. Sheesh.
3050
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3051
+		return addslashes($content);
3052
+	}
3053
+
3054
+
3055
+	/**
3056
+	 * @param string $messenger
3057
+	 * @param string $message_type
3058
+	 * @param string $context
3059
+	 * @return string
3060
+	 * @since 4.10.29.p
3061
+	 */
3062
+	private function generateUpdateDescription($messenger, $message_type, $context)
3063
+	{
3064
+		// need the message type and messenger objects to be able to use the labels for the notices
3065
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3066
+		$messenger_label  = $messenger_object instanceof EE_messenger
3067
+			? ucwords($messenger_object->label['singular'])
3068
+			: '';
3069
+
3070
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3071
+		$message_type_label  = $message_type_object instanceof EE_message_type
3072
+			? ucwords($message_type_object->label['singular'])
3073
+			: '';
3074
+
3075
+		$context   = ucwords(str_replace('_', ' ', $context));
3076
+		$item_desc = $messenger_label && $message_type_label
3077
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3078
+			: '';
3079
+		$item_desc .= 'Message Template';
3080
+		return $item_desc;
3081
+	}
3082
+
3083
+
3084
+	/**
3085
+	 * @param string $messenger
3086
+	 * @param string $message_type
3087
+	 * @param string $context
3088
+	 * @return bool
3089
+	 * @throws EE_Error
3090
+	 * @throws ReflectionException
3091
+	 * @since 4.10.29.p
3092
+	 */
3093
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3094
+	{
3095
+		// was a test send triggered?
3096
+		if ($this->request->requestParamIsSet('test_button')) {
3097
+			EE_Error::overwrite_success();
3098
+			$this->_do_test_send($context, $messenger, $message_type);
3099
+			return true;
3100
+		}
3101
+		return false;
3102
+	}
3103
+
3104
+
3105
+	/**
3106
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3107
+	 *
3108
+	 * @param string $context      what context being tested
3109
+	 * @param string $messenger    messenger being tested
3110
+	 * @param string $message_type message type being tested
3111
+	 * @throws EE_Error
3112
+	 * @throws InvalidArgumentException
3113
+	 * @throws InvalidDataTypeException
3114
+	 * @throws InvalidInterfaceException
3115
+	 * @throws ReflectionException
3116
+	 */
3117
+	protected function _do_test_send($context, $messenger, $message_type)
3118
+	{
3119
+		// set things up for preview
3120
+		$this->request->setRequestParam('messenger', $messenger);
3121
+		$this->request->setRequestParam('message_type', $message_type);
3122
+		$this->request->setRequestParam('context', $context);
3123
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3124
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3125
+
3126
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3127
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3128
+
3129
+		// let's save any existing fields that might be required by the messenger
3130
+		if (
3131
+			! empty($test_settings_fld)
3132
+			&& $active_messenger instanceof EE_messenger
3133
+			&& apply_filters(
3134
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3135
+				true,
3136
+				$test_settings_fld,
3137
+				$active_messenger
3138
+			)
3139
+		) {
3140
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3141
+		}
3142
+
3143
+		/**
3144
+		 * Use filter to add additional controls on whether message can send or not
3145
+		 */
3146
+		if (
3147
+			apply_filters(
3148
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3149
+				true,
3150
+				$context,
3151
+				$this->request->requestParams(),
3152
+				$messenger,
3153
+				$message_type
3154
+			)
3155
+		) {
3156
+			if (EEM_Event::instance()->count() > 0) {
3157
+				$success = $this->_preview_message(true);
3158
+				if ($success) {
3159
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3160
+				} else {
3161
+					EE_Error::add_error(
3162
+						esc_html__('The test message was not sent', 'event_espresso'),
3163
+						__FILE__,
3164
+						__FUNCTION__,
3165
+						__LINE__
3166
+					);
3167
+				}
3168
+			} else {
3169
+				$this->noEventsErrorMessage(true);
3170
+			}
3171
+		}
3172
+	}
3173
+
3174
+
3175
+	/**
3176
+	 * _generate_new_templates
3177
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3178
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3179
+	 * for the event.
3180
+	 *
3181
+	 *
3182
+	 * @param string $messenger      the messenger we are generating templates for
3183
+	 * @param array  $message_types  array of message types that the templates are generated for.
3184
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3185
+	 *                               indicate the message_template_group being used as the base.
3186
+	 *
3187
+	 * @param bool   $global
3188
+	 *
3189
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3190
+	 *                               encountering problems.
3191
+	 * @throws EE_Error
3192
+	 * @throws ReflectionException
3193
+	 */
3194
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3195
+	{
3196
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3197
+		// just don't generate any templates.
3198
+		if (empty($message_types)) {
3199
+			return [];
3200
+		}
3201
+
3202
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3203
+		return $templates[0];
3204
+	}
3205
+
3206
+
3207
+	/**
3208
+	 * [_trash_or_restore_message_template]
3209
+	 *
3210
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3211
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3212
+	 *                        an individual context (FALSE).
3213
+	 * @return void
3214
+	 * @throws EE_Error
3215
+	 * @throws InvalidArgumentException
3216
+	 * @throws InvalidDataTypeException
3217
+	 * @throws InvalidInterfaceException
3218
+	 */
3219
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3220
+	{
3221
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3222
+
3223
+		$success = 1;
3224
+
3225
+		// incoming GRP_IDs
3226
+		if ($all) {
3227
+			// Checkboxes
3228
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3229
+			if (! empty($checkboxes)) {
3230
+				// if array has more than one element then success message should be plural.
3231
+				// todo: what about nonce?
3232
+				$success = count($checkboxes) > 1 ? 2 : 1;
3233
+
3234
+				// cycle through checkboxes
3235
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3236
+					$trashed_or_restored = $trash
3237
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3238
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3239
+					if (! $trashed_or_restored) {
3240
+						$success = 0;
3241
+					}
3242
+				}
3243
+			} else {
3244
+				// grab single GRP_ID and handle
3245
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3246
+				if (! empty($GRP_ID)) {
3247
+					$trashed_or_restored = $trash
3248
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3249
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3250
+					if (! $trashed_or_restored) {
3251
+						$success = 0;
3252
+					}
3253
+				} else {
3254
+					$success = 0;
3255
+				}
3256
+			}
3257
+		}
3258
+
3259
+		$action_desc = $trash
3260
+			? esc_html__('moved to the trash', 'event_espresso')
3261
+			: esc_html__('restored', 'event_espresso');
3262
+
3263
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3264
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3265
+
3266
+		$item_desc = $all ? _n(
3267
+			'Message Template Group',
3268
+			'Message Template Groups',
3269
+			$success,
3270
+			'event_espresso'
3271
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3272
+
3273
+		$item_desc = $template_switch
3274
+			? _n('template', 'templates', $success, 'event_espresso')
3275
+			: $item_desc;
3276
+
3277
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3278
+	}
3279
+
3280
+
3281
+	/**
3282
+	 * [_delete_message_template]
3283
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3284
+	 *
3285
+	 * @return void
3286
+	 * @throws EE_Error
3287
+	 * @throws InvalidArgumentException
3288
+	 * @throws InvalidDataTypeException
3289
+	 * @throws InvalidInterfaceException
3290
+	 * @throws ReflectionException
3291
+	 */
3292
+	protected function _delete_message_template()
3293
+	{
3294
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3295
+
3296
+		// checkboxes
3297
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3298
+		if (! empty($checkboxes)) {
3299
+			// if array has more than one element then success message should be plural
3300
+			$success = count($checkboxes) > 1 ? 2 : 1;
3301
+
3302
+			// cycle through bulk action checkboxes
3303
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3304
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3305
+			}
3306
+		} else {
3307
+			// grab single grp_id and delete
3308
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3309
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3310
+		}
3311
+
3312
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3313
+	}
3314
+
3315
+
3316
+	/**
3317
+	 * helper for permanently deleting a mtP group and all related message_templates
3318
+	 *
3319
+	 * @param int  $GRP_ID        The group being deleted
3320
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3321
+	 * @return bool boolean to indicate the success of the deletes or not.
3322
+	 * @throws EE_Error
3323
+	 * @throws InvalidArgumentException
3324
+	 * @throws InvalidDataTypeException
3325
+	 * @throws InvalidInterfaceException
3326
+	 * @throws ReflectionException
3327
+	 * @throws ReflectionException
3328
+	 */
3329
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3330
+	{
3331
+		$success = true;
3332
+		// first let's GET this group
3333
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3334
+		// then delete permanently all the related Message Templates
3335
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3336
+
3337
+		if ($deleted === 0) {
3338
+			$success = false;
3339
+		}
3340
+
3341
+		// now delete permanently this particular group
3342
+
3343
+		if ($include_group && ! $MTG->delete_permanently()) {
3344
+			$success = false;
3345
+		}
3346
+
3347
+		return $success;
3348
+	}
3349
+
3350
+
3351
+	/**
3352
+	 *    _learn_more_about_message_templates_link
3353
+	 *
3354
+	 * @access protected
3355
+	 * @return string
3356
+	 */
3357
+	protected function _learn_more_about_message_templates_link()
3358
+	{
3359
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3360
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3361
+			   . '</a>';
3362
+	}
3363
+
3364
+
3365
+	/**
3366
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3367
+	 * ajax and other routes.
3368
+	 *
3369
+	 * @return void
3370
+	 * @throws DomainException
3371
+	 * @throws EE_Error
3372
+	 */
3373
+	protected function _settings()
3374
+	{
3375
+		$this->_set_m_mt_settings();
3376
+
3377
+		// let's setup the messenger tabs
3378
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3379
+			$this->_m_mt_settings['messenger_tabs'],
3380
+			'messenger_links',
3381
+			'|',
3382
+			$this->request->getRequestParam('selected_messenger', 'email')
3383
+		);
3384
+
3385
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3386
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3387
+
3388
+		$this->display_admin_page_with_sidebar();
3389
+	}
3390
+
3391
+
3392
+	/**
3393
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3394
+	 *
3395
+	 * @access protected
3396
+	 * @return void
3397
+	 * @throws DomainException
3398
+	 */
3399
+	protected function _set_m_mt_settings()
3400
+	{
3401
+		// first if this is already set then lets get out no need to regenerate data.
3402
+		if (! empty($this->_m_mt_settings)) {
3403
+			return;
3404
+		}
3405
+
3406
+		// get all installed messengers and message_types
3407
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3408
+		$message_types = $this->_message_resource_manager->installed_message_types();
3409
+
3410
+
3411
+		// assemble the array for the _tab_text_links helper
3412
+
3413
+		foreach ($messengers as $messenger) {
3414
+			$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3415
+			$class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3416
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3417
+				'label' => ucwords($messenger->label['singular']),
3418
+				'class' => $active ? "{$class} messenger-active" : $class,
3419
+				'href'  => $messenger->name,
3420
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3421
+				'slug'  => $messenger->name,
3422
+				'obj'   => $messenger,
3423
+				'icon' => $active
3424
+					? '<span class="dashicons dashicons-yes-alt"></span>'
3425
+					: '<span class="dashicons dashicons-remove"></span>',
3426
+			];
3427
+
3428
+
3429
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3430
+
3431
+			foreach ($message_types as $message_type) {
3432
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3433
+				// it shouldn't show in either the inactive OR active metabox.
3434
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3435
+					continue;
3436
+				}
3437
+
3438
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3439
+					$messenger->name,
3440
+					$message_type->name
3441
+				)
3442
+					? 'active'
3443
+					: 'inactive';
3444
+
3445
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3446
+					'label'    => ucwords($message_type->label['singular']),
3447
+					'class'    => 'message-type-' . $a_or_i,
3448
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3449
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3450
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3451
+					'title'    => $a_or_i === 'active'
3452
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3453
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3454
+					'content'  => $a_or_i === 'active'
3455
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3456
+						: $this->_message_type_settings_content($message_type, $messenger),
3457
+					'slug'     => $message_type->name,
3458
+					'active'   => $a_or_i === 'active',
3459
+					'obj'      => $message_type,
3460
+				];
3461
+			}
3462
+		}
3463
+	}
3464
+
3465
+
3466
+	/**
3467
+	 * This just prepares the content for the message type settings
3468
+	 *
3469
+	 * @param EE_message_type $message_type The message type object
3470
+	 * @param EE_messenger    $messenger    The messenger object
3471
+	 * @param boolean         $active       Whether the message type is active or not
3472
+	 * @return string html output for the content
3473
+	 * @throws DomainException
3474
+	 */
3475
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3476
+	{
3477
+		// get message type fields
3478
+		$fields                                         = $message_type->get_admin_settings_fields();
3479
+		$settings_template_args['template_form_fields'] = '';
3480
+
3481
+		if (! empty($fields) && $active) {
3482
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3483
+			foreach ($fields as $fldname => $fldprops) {
3484
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3485
+				$template_form_field[ $field_id ] = [
3486
+					'name'       => 'message_type_settings[' . $fldname . ']',
3487
+					'label'      => $fldprops['label'],
3488
+					'input'      => $fldprops['field_type'],
3489
+					'type'       => $fldprops['value_type'],
3490
+					'required'   => $fldprops['required'],
3491
+					'validation' => $fldprops['validation'],
3492
+					'value'      => isset($existing_settings[ $fldname ])
3493
+						? $existing_settings[ $fldname ]
3494
+						: $fldprops['default'],
3495
+					'options'    => isset($fldprops['options'])
3496
+						? $fldprops['options']
3497
+						: [],
3498
+					'default'    => isset($existing_settings[ $fldname ])
3499
+						? $existing_settings[ $fldname ]
3500
+						: $fldprops['default'],
3501
+					'css_class'  => 'no-drag',
3502
+					'format'     => $fldprops['format'],
3503
+				];
3504
+			}
3505
+
3506
+
3507
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3508
+				? $this->_generate_admin_form_fields(
3509
+					$template_form_field,
3510
+					'string',
3511
+					'ee_mt_activate_form'
3512
+				)
3513
+				: '';
3514
+		}
3515
+
3516
+		$settings_template_args['description'] = $message_type->description;
3517
+		// we also need some hidden fields
3518
+		$hidden_fields = [
3519
+			'message_type_settings[messenger]' . $message_type->name    => [
3520
+				'type'  => 'hidden',
3521
+				'value' => $messenger->name,
3522
+			],
3523
+			'message_type_settings[message_type]' . $message_type->name => [
3524
+				'type'  => 'hidden',
3525
+				'value' => $message_type->name,
3526
+			],
3527
+			'type' . $message_type->name                                => [
3528
+				'type'  => 'hidden',
3529
+				'value' => 'message_type',
3530
+			],
3531
+		];
3532
+
3533
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3534
+			$hidden_fields,
3535
+			'array'
3536
+		);
3537
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3538
+			? ' hidden'
3539
+			: '';
3540
+
3541
+
3542
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3543
+		return EEH_Template::display_template($template, $settings_template_args, true);
3544
+	}
3545
+
3546
+
3547
+	/**
3548
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3549
+	 *
3550
+	 * @access protected
3551
+	 * @return void
3552
+	 * @throws DomainException
3553
+	 */
3554
+	protected function _messages_settings_metaboxes()
3555
+	{
3556
+		$this->_set_m_mt_settings();
3557
+		$m_boxes         = $mt_boxes = [];
3558
+		$m_template_args = $mt_template_args = [];
3559
+
3560
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3561
+
3562
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3563
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3564
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3565
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3566
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3567
+
3568
+				// messenger meta boxes
3569
+				$active         = $selected_messenger === $messenger;
3570
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3571
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3572
+					: '';
3573
+
3574
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3575
+					esc_html__('%s Settings', 'event_espresso'),
3576
+					$tab_array['label']
3577
+				);
3578
+
3579
+				$m_template_args[ $messenger . '_a_box' ] = [
3580
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3581
+					'inactive_message_types' => isset(
3582
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3583
+					)
3584
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3585
+						: '',
3586
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3587
+					'hidden'                 => $active ? '' : ' hidden',
3588
+					'hide_on_message'        => $hide_on_message,
3589
+					'messenger'              => $messenger,
3590
+					'active'                 => $active,
3591
+				];
3592
+
3593
+				// message type meta boxes
3594
+				// (which is really just the inactive container for each messenger
3595
+				// showing inactive message types for that messenger)
3596
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3597
+				$mt_template_args[ $messenger . '_i_box' ] = [
3598
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3599
+					'inactive_message_types' => isset(
3600
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3601
+					)
3602
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3603
+						: '',
3604
+					'hidden'                 => $active ? '' : ' hidden',
3605
+					'hide_on_message'        => $hide_on_message,
3606
+					'hide_off_message'       => $hide_off_message,
3607
+					'messenger'              => $messenger,
3608
+					'active'                 => $active,
3609
+				];
3610
+			}
3611
+		}
3612
+
3613
+
3614
+		// register messenger metaboxes
3615
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3616
+		foreach ($m_boxes as $box => $label) {
3617
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3618
+			$msgr          = str_replace('_a_box', '', $box);
3619
+			$this->addMetaBox(
3620
+				'espresso_' . $msgr . '_settings',
3621
+				$label,
3622
+				function ($post, $metabox) {
3623
+					EEH_Template::display_template(
3624
+						$metabox['args']['template_path'],
3625
+						$metabox['args']['template_args']
3626
+					);
3627
+				},
3628
+				$this->_current_screen->id,
3629
+				'normal',
3630
+				'high',
3631
+				$callback_args
3632
+			);
3633
+		}
3634
+
3635
+		// register message type metaboxes
3636
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3637
+		foreach ($mt_boxes as $box => $label) {
3638
+			$callback_args = [
3639
+				'template_path' => $mt_template_path,
3640
+				'template_args' => $mt_template_args[ $box ],
3641
+			];
3642
+			$mt            = str_replace('_i_box', '', $box);
3643
+			$this->addMetaBox(
3644
+				'espresso_' . $mt . '_inactive_mts',
3645
+				$label,
3646
+				function ($post, $metabox) {
3647
+					EEH_Template::display_template(
3648
+						$metabox['args']['template_path'],
3649
+						$metabox['args']['template_args']
3650
+					);
3651
+				},
3652
+				$this->_current_screen->id,
3653
+				'side',
3654
+				'high',
3655
+				$callback_args
3656
+			);
3657
+		}
3658
+
3659
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3660
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3661
+		if (is_main_site()) {
3662
+			$this->addMetaBox(
3663
+				'espresso_global_message_settings',
3664
+				esc_html__('Global Message Settings', 'event_espresso'),
3665
+				[$this, 'global_messages_settings_metabox_content'],
3666
+				$this->_current_screen->id,
3667
+				'normal',
3668
+				'low',
3669
+				[]
3670
+			);
3671
+		}
3672
+	}
3673
+
3674
+
3675
+	/**
3676
+	 *  This generates the content for the global messages settings metabox.
3677
+	 *
3678
+	 * @return void
3679
+	 * @throws EE_Error
3680
+	 * @throws InvalidArgumentException
3681
+	 * @throws ReflectionException
3682
+	 * @throws InvalidDataTypeException
3683
+	 * @throws InvalidInterfaceException
3684
+	 */
3685
+	public function global_messages_settings_metabox_content()
3686
+	{
3687
+		$form = $this->_generate_global_settings_form();
3688
+		echo wp_kses(
3689
+			$form->form_open(
3690
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3691
+				'POST'
3692
+			),
3693
+			AllowedTags::getWithFormTags()
3694
+		);
3695
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3696
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3697
+	}
3698
+
3699
+
3700
+	/**
3701
+	 * This generates and returns the form object for the global messages settings.
3702
+	 *
3703
+	 * @return EE_Form_Section_Proper
3704
+	 * @throws EE_Error
3705
+	 * @throws InvalidArgumentException
3706
+	 * @throws ReflectionException
3707
+	 * @throws InvalidDataTypeException
3708
+	 * @throws InvalidInterfaceException
3709
+	 */
3710
+	protected function _generate_global_settings_form()
3711
+	{
3712
+		/** @var EE_Network_Core_Config $network_config */
3713
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3714
+
3715
+		return new EE_Form_Section_Proper(
3716
+			[
3717
+				'name'            => 'global_messages_settings',
3718
+				'html_id'         => 'global_messages_settings',
3719
+				'html_class'      => 'form-table',
3720
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3721
+				'subsections'     => apply_filters(
3722
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3723
+					[
3724
+						'do_messages_on_same_request' => new EE_Select_Input(
3725
+							[
3726
+								true  => esc_html__('On the same request', 'event_espresso'),
3727
+								false => esc_html__('On a separate request', 'event_espresso'),
3728
+							],
3729
+							[
3730
+								'default'         => $network_config->do_messages_on_same_request,
3731
+								'html_label_text' => esc_html__(
3732
+									'Generate and send all messages:',
3733
+									'event_espresso'
3734
+								),
3735
+								'html_help_text'  => esc_html__(
3736
+									'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.',
3737
+									'event_espresso'
3738
+								),
3739
+							]
3740
+						),
3741
+						'delete_threshold'            => new EE_Select_Input(
3742
+							[
3743
+								0  => esc_html__('Forever', 'event_espresso'),
3744
+								3  => esc_html__('3 Months', 'event_espresso'),
3745
+								6  => esc_html__('6 Months', 'event_espresso'),
3746
+								9  => esc_html__('9 Months', 'event_espresso'),
3747
+								12 => esc_html__('12 Months', 'event_espresso'),
3748
+								24 => esc_html__('24 Months', 'event_espresso'),
3749
+								36 => esc_html__('36 Months', 'event_espresso'),
3750
+							],
3751
+							[
3752
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3753
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3754
+								'html_help_text'  => esc_html__(
3755
+									'You can control how long a record of processed messages is kept via this option.',
3756
+									'event_espresso'
3757
+								),
3758
+							]
3759
+						),
3760
+						'update_settings'             => new EE_Submit_Input(
3761
+							[
3762
+								'default'         => esc_html__('Update', 'event_espresso'),
3763
+								'html_label_text' => '',
3764
+							]
3765
+						),
3766
+					]
3767
+				),
3768
+			]
3769
+		);
3770
+	}
3771
+
3772
+
3773
+	/**
3774
+	 * This handles updating the global settings set on the admin page.
3775
+	 *
3776
+	 * @throws EE_Error
3777
+	 * @throws InvalidDataTypeException
3778
+	 * @throws InvalidInterfaceException
3779
+	 * @throws InvalidArgumentException
3780
+	 * @throws ReflectionException
3781
+	 */
3782
+	protected function _update_global_settings()
3783
+	{
3784
+		/** @var EE_Network_Core_Config $network_config */
3785
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3786
+		$messages_config = EE_Registry::instance()->CFG->messages;
3787
+		$form            = $this->_generate_global_settings_form();
3788
+		if ($form->was_submitted()) {
3789
+			$form->receive_form_submission();
3790
+			if ($form->is_valid()) {
3791
+				$valid_data = $form->valid_data();
3792
+				foreach ($valid_data as $property => $value) {
3793
+					$setter = 'set_' . $property;
3794
+					if (method_exists($network_config, $setter)) {
3795
+						$network_config->{$setter}($value);
3796
+					} elseif (
3797
+						property_exists($network_config, $property)
3798
+						&& $network_config->{$property} !== $value
3799
+					) {
3800
+						$network_config->{$property} = $value;
3801
+					} elseif (
3802
+						property_exists($messages_config, $property)
3803
+						&& $messages_config->{$property} !== $value
3804
+					) {
3805
+						$messages_config->{$property} = $value;
3806
+					}
3807
+				}
3808
+				// only update if the form submission was valid!
3809
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3810
+				EE_Registry::instance()->CFG->update_espresso_config();
3811
+				EE_Error::overwrite_success();
3812
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3813
+			}
3814
+		}
3815
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3816
+	}
3817
+
3818
+
3819
+	/**
3820
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3821
+	 *
3822
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3823
+	 * @return string html formatted tabs
3824
+	 * @throws DomainException
3825
+	 */
3826
+	protected function _get_mt_tabs($tab_array)
3827
+	{
3828
+		$tab_array = (array) $tab_array;
3829
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3830
+		$tabs      = '';
3831
+
3832
+		foreach ($tab_array as $tab) {
3833
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3834
+		}
3835
+
3836
+		return $tabs;
3837
+	}
3838
+
3839
+
3840
+	/**
3841
+	 * This prepares the content of the messenger meta box admin settings
3842
+	 *
3843
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3844
+	 * @return string html formatted content
3845
+	 * @throws DomainException
3846
+	 */
3847
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3848
+	{
3849
+
3850
+		$fields = $messenger->get_admin_settings_fields();
3851
+
3852
+		$settings_template_args['template_form_fields'] = '';
3853
+		// is $messenger active?
3854
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3855
+
3856
+
3857
+		if (! empty($fields)) {
3858
+			$existing_settings = $messenger->get_existing_admin_settings();
3859
+
3860
+			foreach ($fields as $field_name => $field_props) {
3861
+				$field_id                         = $messenger->name . '-' . $field_name;
3862
+				$template_form_field[ $field_id ] = [
3863
+					'name'       => 'messenger_settings[' . $field_id . ']',
3864
+					'label'      => $field_props['label'],
3865
+					'input'      => $field_props['field_type'],
3866
+					'type'       => $field_props['value_type'],
3867
+					'required'   => $field_props['required'],
3868
+					'validation' => $field_props['validation'],
3869
+					'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3870
+					'css_class'  => '',
3871
+					'format'     => $field_props['format'],
3872
+				];
3873
+			}
3874
+
3875
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3876
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3877
+				: '';
3878
+		}
3879
+
3880
+		// we also need some hidden fields
3881
+		$settings_template_args['hidden_fields'] = [
3882
+			'messenger_settings[messenger]' . $messenger->name => [
3883
+				'type'  => 'hidden',
3884
+				'value' => $messenger->name,
3885
+			],
3886
+			'type' . $messenger->name                          => [
3887
+				'type'  => 'hidden',
3888
+				'value' => 'messenger',
3889
+			],
3890
+		];
3891
+
3892
+		// make sure any active message types that are existing are included in the hidden fields
3893
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3894
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3895
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3896
+					'type'  => 'hidden',
3897
+					'value' => $mt,
3898
+				];
3899
+			}
3900
+		}
3901
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3902
+			$settings_template_args['hidden_fields'],
3903
+			'array'
3904
+		);
3905
+		$active                                  =
3906
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3907
+
3908
+		$settings_template_args['messenger']           = $messenger->name;
3909
+		$settings_template_args['description']         = $messenger->description;
3910
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3911
+
3912
+
3913
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3914
+			$messenger->name
3915
+		)
3916
+			? $settings_template_args['show_hide_edit_form']
3917
+			: ' hidden';
3918
+
3919
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3920
+			? ' hidden'
3921
+			: $settings_template_args['show_hide_edit_form'];
3922
+
3923
+
3924
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3925
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3926
+		$settings_template_args['on_off_status'] = $active;
3927
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3928
+		return EEH_Template::display_template(
3929
+			$template,
3930
+			$settings_template_args,
3931
+			true
3932
+		);
3933
+	}
3934
+
3935
+
3936
+	/**
3937
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3938
+	 *
3939
+	 * @throws DomainException
3940
+	 * @throws EE_Error
3941
+	 * @throws InvalidDataTypeException
3942
+	 * @throws InvalidInterfaceException
3943
+	 * @throws InvalidArgumentException
3944
+	 * @throws ReflectionException
3945
+	 */
3946
+	public function activate_messenger_toggle()
3947
+	{
3948
+		$success = true;
3949
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3950
+		// let's check that we have required data
3951
+
3952
+		if (! $this->_active_messenger_name) {
3953
+			EE_Error::add_error(
3954
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3955
+				__FILE__,
3956
+				__FUNCTION__,
3957
+				__LINE__
3958
+			);
3959
+			$success = false;
3960
+		}
3961
+
3962
+		// do a nonce check here since we're not arriving via a normal route
3963
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
3964
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
3965
+
3966
+		$this->_verify_nonce($nonce, $nonce_ref);
3967
+
3968
+
3969
+		$status = $this->request->getRequestParam('status');
3970
+		if (! $status) {
3971
+			EE_Error::add_error(
3972
+				esc_html__(
3973
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3974
+					'event_espresso'
3975
+				),
3976
+				__FILE__,
3977
+				__FUNCTION__,
3978
+				__LINE__
3979
+			);
3980
+			$success = false;
3981
+		}
3982
+
3983
+		// do check to verify we have a valid status.
3984
+		if ($status !== 'off' && $status !== 'on') {
3985
+			EE_Error::add_error(
3986
+				sprintf(
3987
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3988
+					$status
3989
+				),
3990
+				__FILE__,
3991
+				__FUNCTION__,
3992
+				__LINE__
3993
+			);
3994
+			$success = false;
3995
+		}
3996
+
3997
+		if ($success) {
3998
+			// made it here?  Stop dawdling then!!
3999
+			$success = $status === 'off'
4000
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4001
+				: $this->_activate_messenger($this->_active_messenger_name);
4002
+		}
4003
+
4004
+		$this->_template_args['success'] = $success;
4005
+
4006
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4007
+		$this->_return_json();
4008
+	}
4009
+
4010
+
4011
+	/**
4012
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4013
+	 *
4014
+	 * @throws DomainException
4015
+	 * @throws EE_Error
4016
+	 * @throws ReflectionException
4017
+	 * @throws InvalidDataTypeException
4018
+	 * @throws InvalidInterfaceException
4019
+	 * @throws InvalidArgumentException
4020
+	 */
4021
+	public function activate_mt_toggle()
4022
+	{
4023
+		$success = true;
4024
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4025
+
4026
+		// let's make sure we have the necessary data
4027
+		if (! $this->_active_message_type_name) {
4028
+			EE_Error::add_error(
4029
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4030
+				__FILE__,
4031
+				__FUNCTION__,
4032
+				__LINE__
4033
+			);
4034
+			$success = false;
4035
+		}
4036
+
4037
+		if (! $this->_active_messenger_name) {
4038
+			EE_Error::add_error(
4039
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4040
+				__FILE__,
4041
+				__FUNCTION__,
4042
+				__LINE__
4043
+			);
4044
+			$success = false;
4045
+		}
4046
+
4047
+		$status = $this->request->getRequestParam('status');
4048
+		if (! $status) {
4049
+			EE_Error::add_error(
4050
+				esc_html__(
4051
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4052
+					'event_espresso'
4053
+				),
4054
+				__FILE__,
4055
+				__FUNCTION__,
4056
+				__LINE__
4057
+			);
4058
+			$success = false;
4059
+		}
4060
+
4061
+
4062
+		// do check to verify we have a valid status.
4063
+		if ($status !== 'activate' && $status !== 'deactivate') {
4064
+			EE_Error::add_error(
4065
+				sprintf(
4066
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4067
+					$status
4068
+				),
4069
+				__FILE__,
4070
+				__FUNCTION__,
4071
+				__LINE__
4072
+			);
4073
+			$success = false;
4074
+		}
4075
+
4076
+
4077
+		// do a nonce check here since we're not arriving via a normal route
4078
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4079
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4080
+
4081
+		if ($success) {
4082
+			// made it here? um, what are you waiting for then?
4083
+			$success = $status === 'deactivate'
4084
+				? $this->_deactivate_message_type_for_messenger(
4085
+					$this->_active_messenger_name,
4086
+					$this->_active_message_type_name
4087
+				)
4088
+				: $this->_activate_message_type_for_messenger(
4089
+					$this->_active_messenger_name,
4090
+					$this->_active_message_type_name
4091
+				);
4092
+		}
4093
+
4094
+		$this->_template_args['success'] = $success;
4095
+		$this->_return_json();
4096
+	}
4097
+
4098
+
4099
+	/**
4100
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4101
+	 *
4102
+	 * @param string $messenger_name The name of the messenger being activated
4103
+	 * @return bool
4104
+	 * @throws DomainException
4105
+	 * @throws EE_Error
4106
+	 * @throws InvalidArgumentException
4107
+	 * @throws ReflectionException
4108
+	 * @throws InvalidDataTypeException
4109
+	 * @throws InvalidInterfaceException
4110
+	 */
4111
+	protected function _activate_messenger($messenger_name)
4112
+	{
4113
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4114
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4115
+			? $active_messenger->get_default_message_types()
4116
+			: [];
4117
+
4118
+		// ensure is active
4119
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4120
+
4121
+		// set response_data for reload
4122
+		foreach ($message_types_to_activate as $message_type_name) {
4123
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4124
+			if (
4125
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4126
+					$messenger_name,
4127
+					$message_type_name
4128
+				)
4129
+				&& $message_type instanceof EE_message_type
4130
+			) {
4131
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4132
+				if ($message_type->get_admin_settings_fields()) {
4133
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4134
+				}
4135
+			}
4136
+		}
4137
+
4138
+		// add success message for activating messenger
4139
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4140
+	}
4141
+
4142
+
4143
+	/**
4144
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4145
+	 *
4146
+	 * @param string $messenger_name The name of the messenger being activated
4147
+	 * @return bool
4148
+	 * @throws DomainException
4149
+	 * @throws EE_Error
4150
+	 * @throws InvalidArgumentException
4151
+	 * @throws ReflectionException
4152
+	 * @throws InvalidDataTypeException
4153
+	 * @throws InvalidInterfaceException
4154
+	 */
4155
+	protected function _deactivate_messenger($messenger_name)
4156
+	{
4157
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4158
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4159
+
4160
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4161
+	}
4162
+
4163
+
4164
+	/**
4165
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4166
+	 *
4167
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4168
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4169
+	 * @return bool
4170
+	 * @throws DomainException
4171
+	 * @throws EE_Error
4172
+	 * @throws InvalidArgumentException
4173
+	 * @throws ReflectionException
4174
+	 * @throws InvalidDataTypeException
4175
+	 * @throws InvalidInterfaceException
4176
+	 */
4177
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4178
+	{
4179
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4180
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4181
+
4182
+		// ensure is active
4183
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4184
+
4185
+		// set response for load
4186
+		if (
4187
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4188
+				$messenger_name,
4189
+				$message_type_name
4190
+			)
4191
+		) {
4192
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4193
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4194
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4195
+			}
4196
+		}
4197
+
4198
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4199
+			$active_messenger,
4200
+			$message_type_to_activate
4201
+		);
4202
+	}
4203
+
4204
+
4205
+	/**
4206
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4207
+	 *
4208
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4209
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4210
+	 * @return bool
4211
+	 * @throws DomainException
4212
+	 * @throws EE_Error
4213
+	 * @throws InvalidArgumentException
4214
+	 * @throws ReflectionException
4215
+	 * @throws InvalidDataTypeException
4216
+	 * @throws InvalidInterfaceException
4217
+	 */
4218
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4219
+	{
4220
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4221
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4222
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4223
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4224
+
4225
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4226
+			$active_messenger,
4227
+			$message_type_to_deactivate
4228
+		);
4229
+	}
4230
+
4231
+
4232
+	/**
4233
+	 * This just initializes the defaults for activating messenger and message type responses.
4234
+	 */
4235
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4236
+	{
4237
+		$this->_template_args['data']['active_mts'] = [];
4238
+		$this->_template_args['data']['mt_reload']  = [];
4239
+	}
4240
+
4241
+
4242
+	/**
4243
+	 * Setup appropriate response for activating a messenger and/or message types
4244
+	 *
4245
+	 * @param EE_messenger         $messenger
4246
+	 * @param EE_message_type|null $message_type
4247
+	 * @return bool
4248
+	 * @throws DomainException
4249
+	 * @throws EE_Error
4250
+	 * @throws InvalidArgumentException
4251
+	 * @throws ReflectionException
4252
+	 * @throws InvalidDataTypeException
4253
+	 * @throws InvalidInterfaceException
4254
+	 */
4255
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4256
+		$messenger,
4257
+		EE_Message_Type $message_type = null
4258
+	) {
4259
+		// if $messenger isn't a valid messenger object then get out.
4260
+		if (! $messenger instanceof EE_Messenger) {
4261
+			EE_Error::add_error(
4262
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4263
+				__FILE__,
4264
+				__FUNCTION__,
4265
+				__LINE__
4266
+			);
4267
+			return false;
4268
+		}
4269
+		// activated
4270
+		if ($this->_template_args['data']['active_mts']) {
4271
+			EE_Error::overwrite_success();
4272
+			// activated a message type with the messenger
4273
+			if ($message_type instanceof EE_message_type) {
4274
+				EE_Error::add_success(
4275
+					sprintf(
4276
+						esc_html__(
4277
+							'%s message type has been successfully activated with the %s messenger',
4278
+							'event_espresso'
4279
+						),
4280
+						ucwords($message_type->label['singular']),
4281
+						ucwords($messenger->label['singular'])
4282
+					)
4283
+				);
4284
+
4285
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4286
+				if ($message_type->name === 'invoice') {
4287
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4288
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4289
+					if ($pm instanceof EE_Payment_Method) {
4290
+						EE_Error::add_attention(
4291
+							esc_html__(
4292
+								'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.',
4293
+								'event_espresso'
4294
+							)
4295
+						);
4296
+					}
4297
+				}
4298
+				// just toggles the entire messenger
4299
+			} else {
4300
+				EE_Error::add_success(
4301
+					sprintf(
4302
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4303
+						ucwords($messenger->label['singular'])
4304
+					)
4305
+				);
4306
+			}
4307
+
4308
+			return true;
4309
+
4310
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4311
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4312
+			// in which case we just give a success message for the messenger being successfully activated.
4313
+		} else {
4314
+			if (! $messenger->get_default_message_types()) {
4315
+				// messenger doesn't have any default message types so still a success.
4316
+				EE_Error::add_success(
4317
+					sprintf(
4318
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4319
+						ucwords($messenger->label['singular'])
4320
+					)
4321
+				);
4322
+
4323
+				return true;
4324
+			} else {
4325
+				EE_Error::add_error(
4326
+					$message_type instanceof EE_message_type
4327
+					? sprintf(
4328
+						esc_html__(
4329
+							'%s message type was not successfully activated with the %s messenger',
4330
+							'event_espresso'
4331
+						),
4332
+						ucwords($message_type->label['singular']),
4333
+						ucwords($messenger->label['singular'])
4334
+					)
4335
+					: sprintf(
4336
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4337
+						ucwords($messenger->label['singular'])
4338
+					),
4339
+					__FILE__,
4340
+					__FUNCTION__,
4341
+					__LINE__
4342
+				);
4343
+
4344
+				return false;
4345
+			}
4346
+		}
4347
+	}
4348
+
4349
+
4350
+	/**
4351
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4352
+	 *
4353
+	 * @param EE_messenger         $messenger
4354
+	 * @param EE_message_type|null $message_type
4355
+	 * @return bool
4356
+	 * @throws DomainException
4357
+	 * @throws EE_Error
4358
+	 * @throws InvalidArgumentException
4359
+	 * @throws ReflectionException
4360
+	 * @throws InvalidDataTypeException
4361
+	 * @throws InvalidInterfaceException
4362
+	 */
4363
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4364
+		$messenger,
4365
+		EE_message_type $message_type = null
4366
+	) {
4367
+		EE_Error::overwrite_success();
4368
+
4369
+		// if $messenger isn't a valid messenger object then get out.
4370
+		if (! $messenger instanceof EE_Messenger) {
4371
+			EE_Error::add_error(
4372
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4373
+				__FILE__,
4374
+				__FUNCTION__,
4375
+				__LINE__
4376
+			);
4377
+
4378
+			return false;
4379
+		}
4380
+
4381
+		if ($message_type instanceof EE_message_type) {
4382
+			$message_type_name = $message_type->name;
4383
+			EE_Error::add_success(
4384
+				sprintf(
4385
+					esc_html__(
4386
+						'%s message type has been successfully deactivated for the %s messenger.',
4387
+						'event_espresso'
4388
+					),
4389
+					ucwords($message_type->label['singular']),
4390
+					ucwords($messenger->label['singular'])
4391
+				)
4392
+			);
4393
+		} else {
4394
+			$message_type_name = '';
4395
+			EE_Error::add_success(
4396
+				sprintf(
4397
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4398
+					ucwords($messenger->label['singular'])
4399
+				)
4400
+			);
4401
+		}
4402
+
4403
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4404
+		if (
4405
+			$messenger->name === 'html'
4406
+			&& (
4407
+				is_null($message_type)
4408
+				|| $message_type_name === 'invoice'
4409
+			)
4410
+		) {
4411
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4412
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4413
+			if ($count_updated > 0) {
4414
+				$msg = $message_type_name === 'invoice'
4415
+					? esc_html__(
4416
+						'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.',
4417
+						'event_espresso'
4418
+					)
4419
+					: esc_html__(
4420
+						'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.',
4421
+						'event_espresso'
4422
+					);
4423
+				EE_Error::add_attention($msg);
4424
+			}
4425
+		}
4426
+
4427
+		return true;
4428
+	}
4429
+
4430
+
4431
+	/**
4432
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4433
+	 *
4434
+	 * @throws DomainException
4435
+	 * @throws EE_Error
4436
+	 * @throws EE_Error
4437
+	 */
4438
+	public function update_mt_form()
4439
+	{
4440
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4441
+			EE_Error::add_error(
4442
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4443
+				__FILE__,
4444
+				__FUNCTION__,
4445
+				__LINE__
4446
+			);
4447
+			$this->_return_json();
4448
+		}
4449
+
4450
+		$message_types = $this->get_installed_message_types();
4451
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4452
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4453
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4454
+
4455
+		$this->_template_args['success'] = true;
4456
+		$this->_template_args['content'] = $content;
4457
+		$this->_return_json();
4458
+	}
4459
+
4460
+
4461
+	/**
4462
+	 * this handles saving the settings for a messenger or message type
4463
+	 *
4464
+	 * @throws EE_Error
4465
+	 * @throws EE_Error
4466
+	 */
4467
+	public function save_settings()
4468
+	{
4469
+		$type = $this->request->getRequestParam('type');
4470
+		if (! $type) {
4471
+			EE_Error::add_error(
4472
+				esc_html__(
4473
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4474
+					'event_espresso'
4475
+				),
4476
+				__FILE__,
4477
+				__FUNCTION__,
4478
+				__LINE__
4479
+			);
4480
+			$this->_template_args['error'] = true;
4481
+			$this->_return_json();
4482
+		}
4483
+
4484
+
4485
+		if ($type === 'messenger') {
4486
+			// this should be an array.
4487
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4488
+			$messenger = $settings['messenger'];
4489
+			// remove messenger and message_types from settings array
4490
+			unset($settings['messenger'], $settings['message_types']);
4491
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4492
+		} elseif ($type === 'message_type') {
4493
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4494
+			$messenger    = $settings['messenger'];
4495
+			$message_type = $settings['message_type'];
4496
+			// remove messenger and message_types from settings array
4497
+			unset($settings['messenger'], $settings['message_types']);
4498
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4499
+		}
4500
+
4501
+		// okay we should have the data all setup.  Now we just update!
4502
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4503
+
4504
+		if ($success) {
4505
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4506
+		} else {
4507
+			EE_Error::add_error(
4508
+				esc_html__('Settings did not get updated', 'event_espresso'),
4509
+				__FILE__,
4510
+				__FUNCTION__,
4511
+				__LINE__
4512
+			);
4513
+		}
4514
+
4515
+		$this->_template_args['success'] = $success;
4516
+		$this->_return_json();
4517
+	}
4518
+
4519
+
4520
+
4521
+
4522
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4523
+
4524
+
4525
+	/**
4526
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4527
+	 * However, this does not send immediately, it just queues for sending.
4528
+	 *
4529
+	 * @throws EE_Error
4530
+	 * @throws InvalidDataTypeException
4531
+	 * @throws InvalidInterfaceException
4532
+	 * @throws InvalidArgumentException
4533
+	 * @throws ReflectionException
4534
+	 * @since 4.9.0
4535
+	 */
4536
+	protected function _generate_now()
4537
+	{
4538
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4539
+		$this->_redirect_after_action(false, '', '', [], true);
4540
+	}
4541
+
4542
+
4543
+	/**
4544
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4545
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4546
+	 *
4547
+	 * @throws EE_Error
4548
+	 * @throws InvalidDataTypeException
4549
+	 * @throws InvalidInterfaceException
4550
+	 * @throws InvalidArgumentException
4551
+	 * @throws ReflectionException
4552
+	 * @since 4.9.0
4553
+	 */
4554
+	protected function _generate_and_send_now()
4555
+	{
4556
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4557
+		$this->_redirect_after_action(false, '', '', [], true);
4558
+	}
4559
+
4560
+
4561
+	/**
4562
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4563
+	 *
4564
+	 * @throws EE_Error
4565
+	 * @throws InvalidDataTypeException
4566
+	 * @throws InvalidInterfaceException
4567
+	 * @throws InvalidArgumentException
4568
+	 * @throws ReflectionException
4569
+	 * @since 4.9.0
4570
+	 */
4571
+	protected function _queue_for_resending()
4572
+	{
4573
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4574
+		$this->_redirect_after_action(false, '', '', [], true);
4575
+	}
4576
+
4577
+
4578
+	/**
4579
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4580
+	 *
4581
+	 * @throws EE_Error
4582
+	 * @throws InvalidDataTypeException
4583
+	 * @throws InvalidInterfaceException
4584
+	 * @throws InvalidArgumentException
4585
+	 * @throws ReflectionException
4586
+	 * @since 4.9.0
4587
+	 */
4588
+	protected function _send_now()
4589
+	{
4590
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4591
+		$this->_redirect_after_action(false, '', '', [], true);
4592
+	}
4593
+
4594
+
4595
+	/**
4596
+	 * Deletes EE_messages for IDs in the request.
4597
+	 *
4598
+	 * @throws EE_Error
4599
+	 * @throws InvalidDataTypeException
4600
+	 * @throws InvalidInterfaceException
4601
+	 * @throws InvalidArgumentException
4602
+	 * @since 4.9.0
4603
+	 */
4604
+	protected function _delete_ee_messages()
4605
+	{
4606
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4607
+		$deleted_count = 0;
4608
+		foreach ($MSG_IDs as $MSG_ID) {
4609
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4610
+				$deleted_count++;
4611
+			}
4612
+		}
4613
+		if ($deleted_count) {
4614
+			EE_Error::add_success(
4615
+				esc_html(
4616
+					_n(
4617
+						'Message successfully deleted',
4618
+						'Messages successfully deleted',
4619
+						$deleted_count,
4620
+						'event_espresso'
4621
+					)
4622
+				)
4623
+			);
4624
+		} else {
4625
+			EE_Error::add_error(
4626
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4627
+				__FILE__,
4628
+				__FUNCTION__,
4629
+				__LINE__
4630
+			);
4631
+		}
4632
+		$this->_redirect_after_action(false, '', '', [], true);
4633
+	}
4634
+
4635
+
4636
+	/**
4637
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4638
+	 *
4639
+	 * @return array
4640
+	 * @since 4.9.0
4641
+	 */
4642
+	protected function _get_msg_ids_from_request()
4643
+	{
4644
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4645
+		if (empty($MSG_IDs)) {
4646
+			return [];
4647
+		}
4648
+		// if 'MSG_ID' was just a single ID (not an array)
4649
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4650
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4651
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4652
+			? $MSG_IDs
4653
+			: array_keys($MSG_IDs);
4654
+	}
4655 4655
 }
Please login to merge, or discard this patch.
Spacing   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function getMsgModel()
115 115
     {
116
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
116
+        if ( ! $this->MSG_MODEL instanceof EEM_Message) {
117 117
             $this->MSG_MODEL = EEM_Message::instance();
118 118
         }
119 119
         return $this->MSG_MODEL;
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      */
127 127
     public function getMtpModel()
128 128
     {
129
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
129
+        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) {
130 130
             $this->MTP_MODEL = EEM_Message_Template::instance();
131 131
         }
132 132
         return $this->MTP_MODEL;
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function getMtgModel()
141 141
     {
142
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
142
+        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
143 143
             $this->MTG_MODEL = EEM_Message_Template_Group::instance();
144 144
         }
145 145
         return $this->MTG_MODEL;
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
         $i = 1;
210 210
         foreach ($active_messengers as $active_messenger) {
211 211
             if ($active_messenger instanceof EE_Message) {
212
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
213
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
212
+                $m_values[$i]['id']   = $active_messenger->messenger();
213
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
214 214
                 $i++;
215 215
             }
216 216
         }
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
         $i               = 1;
247 247
         foreach ($active_messages as $active_message) {
248 248
             if ($active_message instanceof EE_Message) {
249
-                $mt_values[ $i ]['id']   = $active_message->message_type();
250
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
249
+                $mt_values[$i]['id']   = $active_message->message_type();
250
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
251 251
                 $i++;
252 252
             }
253 253
         }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
                 if ($message_type instanceof EE_message_type) {
287 287
                     $message_type_contexts = $message_type->get_contexts();
288 288
                     foreach ($message_type_contexts as $context => $context_details) {
289
-                        $contexts[ $context ] = $context_details['label'];
289
+                        $contexts[$context] = $context_details['label'];
290 290
                     }
291 291
                 }
292 292
             }
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
320 320
             $messenger_options
321 321
         );
322
-        $input             = new EE_Select_Input(
322
+        $input = new EE_Select_Input(
323 323
             $messenger_options,
324 324
             [
325 325
                 'html_name'  => 'ee_messenger_filter_by',
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
357 357
             $message_type_options
358 358
         );
359
-        $input                = new EE_Select_Input(
359
+        $input = new EE_Select_Input(
360 360
             $message_type_options,
361 361
             [
362 362
                 'html_name'  => 'ee_message_type_filter_by',
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
394 394
             $context_options
395 395
         );
396
-        $input           = new EE_Select_Input(
396
+        $input = new EE_Select_Input(
397 397
             $context_options,
398 398
             [
399 399
                 'html_name'  => 'ee_context_filter_by',
@@ -774,53 +774,53 @@  discard block
 block discarded – undo
774 774
 
775 775
     public function messages_help_tab()
776 776
     {
777
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
777
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
778 778
     }
779 779
 
780 780
 
781 781
     public function messengers_help_tab()
782 782
     {
783
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
783
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
784 784
     }
785 785
 
786 786
 
787 787
     public function message_types_help_tab()
788 788
     {
789
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
789
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
790 790
     }
791 791
 
792 792
 
793 793
     public function messages_overview_help_tab()
794 794
     {
795
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
795
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
796 796
     }
797 797
 
798 798
 
799 799
     public function message_templates_help_tab()
800 800
     {
801
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
801
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
802 802
     }
803 803
 
804 804
 
805 805
     public function edit_message_template_help_tab()
806 806
     {
807
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
807
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
808 808
                         . esc_attr__('Editor Title', 'event_espresso')
809 809
                         . '" />';
810
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
810
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
811 811
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
812 812
                         . '" />';
813
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
813
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
814 814
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
815 815
                         . '" />';
816
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
816
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
817 817
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
818 818
                         . '" />';
819
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
819
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
820 820
                         . esc_attr__('Publish Metabox', 'event_espresso')
821 821
                         . '" />';
822 822
         EEH_Template::display_template(
823
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
823
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
824 824
             $args
825 825
         );
826 826
     }
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
         $this->_set_shortcodes();
836 836
         $args['shortcodes'] = $this->_shortcodes;
837 837
         EEH_Template::display_template(
838
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
838
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
839 839
             $args
840 840
         );
841 841
     }
@@ -843,16 +843,16 @@  discard block
 block discarded – undo
843 843
 
844 844
     public function preview_message_help_tab()
845 845
     {
846
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
846
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
847 847
     }
848 848
 
849 849
 
850 850
     public function settings_help_tab()
851 851
     {
852
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
853
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
854
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
855
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
852
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
853
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
854
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
855
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
856 856
         $args['img3'] = '<div class="ee-switch">'
857 857
                         . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
858 858
                         . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
@@ -861,25 +861,25 @@  discard block
 block discarded – undo
861 861
                         . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
862 862
                         . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
863 863
                         . '</div>';
864
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
864
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
865 865
     }
866 866
 
867 867
 
868 868
     public function load_scripts_styles()
869 869
     {
870
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
870
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
871 871
         wp_enqueue_style('espresso_ee_msg');
872 872
 
873 873
         wp_register_script(
874 874
             'ee-messages-settings',
875
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
875
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
876 876
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
877 877
             EVENT_ESPRESSO_VERSION,
878 878
             true
879 879
         );
880 880
         wp_register_script(
881 881
             'ee-msg-list-table-js',
882
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
882
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
883 883
             ['ee-dialog'],
884 884
             EVENT_ESPRESSO_VERSION
885 885
         );
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
 
923 923
         $this->_set_shortcodes();
924 924
 
925
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
925
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
926 926
             esc_html__(
927 927
                 '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.',
928 928
                 'event_espresso'
@@ -934,14 +934,14 @@  discard block
 block discarded – undo
934 934
             '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?',
935 935
             'event_espresso'
936 936
         );
937
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
937
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
938 938
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
939 939
             'event_espresso'
940 940
         );
941 941
 
942 942
         wp_register_script(
943 943
             'ee_msgs_edit_js',
944
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
944
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
945 945
             ['jquery'],
946 946
             EVENT_ESPRESSO_VERSION
947 947
         );
@@ -984,7 +984,7 @@  discard block
 block discarded – undo
984 984
     {
985 985
         wp_register_style(
986 986
             'ee-message-settings',
987
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
987
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
988 988
             [],
989 989
             EVENT_ESPRESSO_VERSION
990 990
         );
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
             }
1071 1071
             $status_bulk_actions = $common_bulk_actions;
1072 1072
             // unset bulk actions not applying to status
1073
-            if (! empty($status_bulk_actions)) {
1073
+            if ( ! empty($status_bulk_actions)) {
1074 1074
                 switch ($status) {
1075 1075
                     case EEM_Message::status_idle:
1076 1076
                     case EEM_Message::status_resend:
@@ -1099,7 +1099,7 @@  discard block
 block discarded – undo
1099 1099
                 continue;
1100 1100
             }
1101 1101
 
1102
-            $this->_views[ strtolower($status) ] = [
1102
+            $this->_views[strtolower($status)] = [
1103 1103
                 'slug'        => strtolower($status),
1104 1104
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1105 1105
                 'count'       => 0,
@@ -1147,7 +1147,7 @@  discard block
 block discarded – undo
1147 1147
             if ($action_item === 'see_notifications_for') {
1148 1148
                 continue;
1149 1149
             }
1150
-            $action_items[ $action_item ] = [
1150
+            $action_items[$action_item] = [
1151 1151
                 'class' => $action_details['css_class'],
1152 1152
                 'desc'  => $action_details['label'],
1153 1153
             ];
@@ -1156,37 +1156,37 @@  discard block
 block discarded – undo
1156 1156
         /** @var array $status_items status legend setup */
1157 1157
         $status_items = [
1158 1158
             'sent_status'                => [
1159
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1159
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_sent,
1160 1160
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1161 1161
             ],
1162 1162
             'idle_status'                => [
1163
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1163
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_idle,
1164 1164
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1165 1165
             ],
1166 1166
             'failed_status'              => [
1167
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1167
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_failed,
1168 1168
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1169 1169
             ],
1170 1170
             'messenger_executing_status' => [
1171
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1171
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_messenger_executing,
1172 1172
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1173 1173
             ],
1174 1174
             'resend_status'              => [
1175
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1175
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_resend,
1176 1176
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1177 1177
             ],
1178 1178
             'incomplete_status'          => [
1179
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1179
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_incomplete,
1180 1180
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1181 1181
             ],
1182 1182
             'retry_status'               => [
1183
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1183
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_retry,
1184 1184
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1185 1185
             ],
1186 1186
         ];
1187 1187
         if (EEM_Message::debug()) {
1188 1188
             $status_items['debug_only_status'] = [
1189
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1189
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_debug_only,
1190 1190
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1191 1191
             ];
1192 1192
         }
@@ -1201,11 +1201,11 @@  discard block
 block discarded – undo
1201 1201
     protected function _custom_mtps_preview()
1202 1202
     {
1203 1203
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1204
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1205
-                                                . ' alt="' . esc_attr__(
1204
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1205
+                                                . ' alt="'.esc_attr__(
1206 1206
                                                     'Preview Custom Message Templates screenshot',
1207 1207
                                                     'event_espresso'
1208
-                                                ) . '" />';
1208
+                                                ).'" />';
1209 1209
         $this->_template_args['preview_text'] = '<strong>'
1210 1210
                                                 . esc_html__(
1211 1211
                                                     '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.',
@@ -1281,7 +1281,7 @@  discard block
 block discarded – undo
1281 1281
         $installed               = [];
1282 1282
 
1283 1283
         foreach ($installed_message_types as $message_type) {
1284
-            $installed[ $message_type->name ] = $message_type;
1284
+            $installed[$message_type->name] = $message_type;
1285 1285
         }
1286 1286
 
1287 1287
         return $installed;
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
         // we need to assemble the title from Various details
1408 1408
         $context_label = sprintf(
1409 1409
             esc_html__('(%s %s)', 'event_espresso'),
1410
-            $c_config[ $context ]['label'],
1410
+            $c_config[$context]['label'],
1411 1411
             ucwords($c_label['label'])
1412 1412
         );
1413 1413
 
@@ -1429,7 +1429,7 @@  discard block
 block discarded – undo
1429 1429
             $message_template_group->message_type()
1430 1430
         );
1431 1431
 
1432
-        if (! $template_field_structure) {
1432
+        if ( ! $template_field_structure) {
1433 1433
             $template_field_structure = false;
1434 1434
             $template_fields          = esc_html__(
1435 1435
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1443,21 +1443,21 @@  discard block
 block discarded – undo
1443 1443
 
1444 1444
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1445 1445
         // will get handled in the "extra" array.
1446
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1447
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1448
-                unset($template_field_structure[ $context ][ $reference_field ]);
1446
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1447
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1448
+                unset($template_field_structure[$context][$reference_field]);
1449 1449
             }
1450 1450
         }
1451 1451
 
1452 1452
         // let's loop through the template_field_structure and actually assemble the input fields!
1453
-        if (! empty($template_field_structure)) {
1454
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1453
+        if ( ! empty($template_field_structure)) {
1454
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1455 1455
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1456 1456
                 // the extra array and reset them.
1457 1457
                 if ($template_field === 'extra') {
1458 1458
                     $this->_template_args['is_extra_fields'] = true;
1459 1459
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1460
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1460
+                        $message_template = $message_templates[$context][$reference_field];
1461 1461
                         $content          = $message_template instanceof EE_Message_Template
1462 1462
                             ? $message_template->get('MTP_content')
1463 1463
                             : '';
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
                             $continue = false;
1467 1467
                             if (isset($extra_array['shortcodes_required'])) {
1468 1468
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1469
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1469
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1470 1470
                                         $continue = true;
1471 1471
                                     }
1472 1472
                                 }
@@ -1475,53 +1475,53 @@  discard block
 block discarded – undo
1475 1475
                                 }
1476 1476
                             }
1477 1477
 
1478
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1478
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1479 1479
 
1480
-                            $template_form_fields[ $field_id ]         = $extra_array;
1481
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1480
+                            $template_form_fields[$field_id]         = $extra_array;
1481
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1482 1482
                                                                          . $reference_field
1483 1483
                                                                          . '][content]['
1484
-                                                                         . $extra_field . ']';
1485
-                            $css_class                                 = isset($extra_array['css_class'])
1484
+                                                                         . $extra_field.']';
1485
+                            $css_class = isset($extra_array['css_class'])
1486 1486
                                 ? $extra_array['css_class']
1487 1487
                                 : '';
1488 1488
 
1489
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1489
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1490 1490
                                                                               && in_array($extra_field, $v_fields, true)
1491 1491
                                                                               && (
1492
-                                                                                  is_array($validators[ $extra_field ])
1493
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1492
+                                                                                  is_array($validators[$extra_field])
1493
+                                                                                  && isset($validators[$extra_field]['msg'])
1494 1494
                                                                               )
1495
-                                ? 'validate-error ' . $css_class
1495
+                                ? 'validate-error '.$css_class
1496 1496
                                 : $css_class;
1497 1497
 
1498
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1499
-                                                                          && isset($content[ $extra_field ])
1500
-                                ? $content[ $extra_field ]
1498
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1499
+                                                                          && isset($content[$extra_field])
1500
+                                ? $content[$extra_field]
1501 1501
                                 : '';
1502 1502
 
1503 1503
                             // do we have a validation error?  if we do then let's use that value instead
1504
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1505
-                                ? $validators[ $extra_field ]['value']
1506
-                                : $template_form_fields[ $field_id ]['value'];
1504
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1505
+                                ? $validators[$extra_field]['value']
1506
+                                : $template_form_fields[$field_id]['value'];
1507 1507
 
1508 1508
 
1509
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1509
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1510 1510
 
1511 1511
                             // shortcode selector
1512 1512
                             $field_name_to_use                                   = $extra_field === 'main'
1513 1513
                                 ? 'content'
1514 1514
                                 : $extra_field;
1515
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1515
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1516 1516
                                 $field_name_to_use,
1517 1517
                                 $field_id
1518 1518
                             );
1519 1519
                         }
1520
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1521
-                        $template_field_template_name_id = $reference_field . '-name';
1520
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1521
+                        $template_field_template_name_id = $reference_field.'-name';
1522 1522
 
1523
-                        $template_form_fields[ $template_field_MTP_id ] = [
1524
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1523
+                        $template_form_fields[$template_field_MTP_id] = [
1524
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1525 1525
                             'label'      => null,
1526 1526
                             'input'      => 'hidden',
1527 1527
                             'type'       => 'int',
@@ -1533,8 +1533,8 @@  discard block
 block discarded – undo
1533 1533
                             'db-col'     => 'MTP_ID',
1534 1534
                         ];
1535 1535
 
1536
-                        $template_form_fields[ $template_field_template_name_id ] = [
1537
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1536
+                        $template_form_fields[$template_field_template_name_id] = [
1537
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1538 1538
                             'label'      => null,
1539 1539
                             'input'      => 'hidden',
1540 1540
                             'type'       => 'string',
@@ -1548,38 +1548,38 @@  discard block
 block discarded – undo
1548 1548
                     }
1549 1549
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1550 1550
                 } else {
1551
-                    $field_id                                   = $template_field . '-content';
1552
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1553
-                    $template_form_fields[ $field_id ]['name']  =
1554
-                        'MTP_template_fields[' . $template_field . '][content]';
1551
+                    $field_id                                   = $template_field.'-content';
1552
+                    $template_form_fields[$field_id]          = $field_setup_array;
1553
+                    $template_form_fields[$field_id]['name']  =
1554
+                        'MTP_template_fields['.$template_field.'][content]';
1555 1555
                     $message_template                           =
1556
-                        isset($message_templates[ $context ][ $template_field ])
1557
-                            ? $message_templates[ $context ][ $template_field ]
1556
+                        isset($message_templates[$context][$template_field])
1557
+                            ? $message_templates[$context][$template_field]
1558 1558
                             : null;
1559
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1560
-                                                                  && is_array($message_templates[ $context ])
1559
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1560
+                                                                  && is_array($message_templates[$context])
1561 1561
                                                                   && $message_template instanceof EE_Message_Template
1562 1562
                         ? $message_template->get('MTP_content')
1563 1563
                         : '';
1564 1564
 
1565 1565
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1566
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1567
-                        ? $validators[ $template_field ]['value']
1568
-                        : $template_form_fields[ $field_id ]['value'];
1566
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1567
+                        ? $validators[$template_field]['value']
1568
+                        : $template_form_fields[$field_id]['value'];
1569 1569
 
1570 1570
 
1571
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1571
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1572 1572
                     $css_class                                      = isset($field_setup_array['css_class'])
1573 1573
                         ? $field_setup_array['css_class']
1574 1574
                         : '';
1575
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1575
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1576 1576
                                                                       && in_array($template_field, $v_fields, true)
1577
-                                                                      && isset($validators[ $template_field ]['msg'])
1578
-                        ? 'validate-error ' . $css_class
1577
+                                                                      && isset($validators[$template_field]['msg'])
1578
+                        ? 'validate-error '.$css_class
1579 1579
                         : $css_class;
1580 1580
 
1581 1581
                     // shortcode selector
1582
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1582
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1583 1583
                         $template_field,
1584 1584
                         $field_id
1585 1585
                     );
@@ -1587,12 +1587,12 @@  discard block
 block discarded – undo
1587 1587
 
1588 1588
                 // k took care of content field(s) now let's take care of others.
1589 1589
 
1590
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1591
-                $template_field_field_template_name_id = $template_field . '-name';
1590
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1591
+                $template_field_field_template_name_id = $template_field.'-name';
1592 1592
 
1593 1593
                 // foreach template field there are actually two form fields created
1594
-                $template_form_fields[ $template_field_MTP_id ] = [
1595
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1594
+                $template_form_fields[$template_field_MTP_id] = [
1595
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1596 1596
                     'label'      => null,
1597 1597
                     'input'      => 'hidden',
1598 1598
                     'type'       => 'int',
@@ -1604,8 +1604,8 @@  discard block
 block discarded – undo
1604 1604
                     'db-col'     => 'MTP_ID',
1605 1605
                 ];
1606 1606
 
1607
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1608
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1607
+                $template_form_fields[$template_field_field_template_name_id] = [
1608
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1609 1609
                     'label'      => null,
1610 1610
                     'input'      => 'hidden',
1611 1611
                     'type'       => 'string',
@@ -1722,7 +1722,7 @@  discard block
 block discarded – undo
1722 1722
                 'format'     => '%d',
1723 1723
                 'db-col'     => 'MTP_deleted',
1724 1724
             ];
1725
-            $sidebar_form_fields['ee-msg-author']  = [
1725
+            $sidebar_form_fields['ee-msg-author'] = [
1726 1726
                 'name'       => 'MTP_user_id',
1727 1727
                 'label'      => esc_html__('Author', 'event_espresso'),
1728 1728
                 'input'      => 'hidden',
@@ -1741,17 +1741,17 @@  discard block
 block discarded – undo
1741 1741
                 'value' => $action,
1742 1742
             ];
1743 1743
 
1744
-            $sidebar_form_fields['ee-msg-id']        = [
1744
+            $sidebar_form_fields['ee-msg-id'] = [
1745 1745
                 'name'  => 'id',
1746 1746
                 'input' => 'hidden',
1747 1747
                 'type'  => 'int',
1748 1748
                 'value' => $GRP_ID,
1749 1749
             ];
1750 1750
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1751
-                'name'  => $action . '_nonce',
1751
+                'name'  => $action.'_nonce',
1752 1752
                 'input' => 'hidden',
1753 1753
                 'type'  => 'string',
1754
-                'value' => wp_create_nonce($action . '_nonce'),
1754
+                'value' => wp_create_nonce($action.'_nonce'),
1755 1755
             ];
1756 1756
 
1757 1757
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1782,7 +1782,7 @@  discard block
 block discarded – undo
1782 1782
         );
1783 1783
 
1784 1784
         // add preview button
1785
-        $preview_url    = parent::add_query_args_and_nonce(
1785
+        $preview_url = parent::add_query_args_and_nonce(
1786 1786
             [
1787 1787
                 'message_type' => $message_template_group->message_type(),
1788 1788
                 'messenger'    => $message_template_group->messenger(),
@@ -1793,7 +1793,7 @@  discard block
 block discarded – undo
1793 1793
             ],
1794 1794
             $this->_admin_base_url
1795 1795
         );
1796
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1796
+        $preview_button = '<a href="'.$preview_url.'" class="button--secondary messages-preview-button">'
1797 1797
                           . esc_html__('Preview', 'event_espresso')
1798 1798
                           . '</a>';
1799 1799
 
@@ -1831,11 +1831,11 @@  discard block
 block discarded – undo
1831 1831
         $this->_template_args['before_admin_page_content'] .= $this->formEnd();
1832 1832
         $this->_template_args['before_admin_page_content'] .= '</div>';
1833 1833
         $this->_template_args['before_admin_page_content'] .= $this->editMessageFormStart();
1834
-        $this->_template_args['after_admin_page_content']  = $this->formEnd();
1834
+        $this->_template_args['after_admin_page_content'] = $this->formEnd();
1835 1835
 
1836 1836
         $this->_template_path = $this->_template_args['GRP_ID']
1837 1837
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1838
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1838
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1839 1839
 
1840 1840
         // send along EE_Message_Template_Group object for further template use.
1841 1841
         $this->_template_args['MTP'] = $message_template_group;
@@ -1884,10 +1884,10 @@  discard block
 block discarded – undo
1884 1884
         $context_label
1885 1885
     ): string {
1886 1886
         return EEH_Template::display_template(
1887
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1887
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1888 1888
             [
1889 1889
                 'context'                   => $context,
1890
-                'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1890
+                'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1891 1891
                 'is_active'                 => $message_template_group->is_context_active($context),
1892 1892
                 'on_off_action'             => $message_template_group->is_context_active($context)
1893 1893
                     ? 'context-off'
@@ -1911,7 +1911,7 @@  discard block
 block discarded – undo
1911 1911
     protected function add_context_switcher(EE_Message_Template_Group $template_group_object, array $args): string
1912 1912
     {
1913 1913
         return EEH_Template::display_template(
1914
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_context_switcher.template.php',
1914
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_context_switcher.template.php',
1915 1915
             [
1916 1916
                 'args'              => $args,
1917 1917
                 'context_details'   => $template_group_object->contexts_config(),
@@ -1973,7 +1973,7 @@  discard block
 block discarded – undo
1973 1973
         }
1974 1974
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1975 1975
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1976
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1976
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1977 1977
             EE_Error::add_error(
1978 1978
                 sprintf(
1979 1979
                     esc_html__(
@@ -2110,7 +2110,7 @@  discard block
 block discarded – undo
2110 2110
         $messenger    = $this->request->getRequestParam('msgr');
2111 2111
         $message_type = $this->request->getRequestParam('mt');
2112 2112
         // we need to make sure we've got the info we need.
2113
-        if (! ($GRP_ID && $messenger && $message_type)) {
2113
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2114 2114
             EE_Error::add_error(
2115 2115
                 esc_html__(
2116 2116
                     '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.',
@@ -2147,7 +2147,7 @@  discard block
 block discarded – undo
2147 2147
         }
2148 2148
 
2149 2149
         // any error messages?
2150
-        if (! $success) {
2150
+        if ( ! $success) {
2151 2151
             EE_Error::add_error(
2152 2152
                 esc_html__(
2153 2153
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2196,7 +2196,7 @@  discard block
 block discarded – undo
2196 2196
     {
2197 2197
         // first make sure we've got the necessary parameters
2198 2198
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2199
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2199
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2200 2200
             EE_Error::add_error(
2201 2201
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2202 2202
                 __FILE__,
@@ -2222,7 +2222,7 @@  discard block
 block discarded – undo
2222 2222
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2223 2223
 
2224 2224
         // let's add a button to go back to the edit view
2225
-        $query_args             = [
2225
+        $query_args = [
2226 2226
             'id'      => $GRP_ID,
2227 2227
             'evt_id'  => $EVT_ID,
2228 2228
             'context' => $context,
@@ -2243,7 +2243,7 @@  discard block
 block discarded – undo
2243 2243
         $preview_title = sprintf(
2244 2244
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2245 2245
             $active_messenger_label,
2246
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2246
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2247 2247
         );
2248 2248
         if (empty($preview)) {
2249 2249
             $this->noEventsErrorMessage();
@@ -2251,7 +2251,7 @@  discard block
 block discarded – undo
2251 2251
         // setup display of preview.
2252 2252
         $this->_admin_page_title                    = $preview_title;
2253 2253
         $this->_template_args['admin_page_title']   = $preview_title;
2254
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2254
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2255 2255
         $this->_template_args['data']['force_json'] = true;
2256 2256
 
2257 2257
         return '';
@@ -2272,7 +2272,7 @@  discard block
 block discarded – undo
2272 2272
             ],
2273 2273
             admin_url('admin.php')
2274 2274
         );
2275
-        $message    = $test_send
2275
+        $message = $test_send
2276 2276
             ? esc_html__(
2277 2277
                 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2278 2278
                 'event_espresso'
@@ -2365,10 +2365,10 @@  discard block
 block discarded – undo
2365 2365
             // only include template packs that support this messenger and message type!
2366 2366
             $supports = $tp->get_supports();
2367 2367
             if (
2368
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2368
+                ! isset($supports[$this->_message_template_group->messenger()])
2369 2369
                 || ! in_array(
2370 2370
                     $this->_message_template_group->message_type(),
2371
-                    $supports[ $this->_message_template_group->messenger() ],
2371
+                    $supports[$this->_message_template_group->messenger()],
2372 2372
                     true
2373 2373
                 )
2374 2374
             ) {
@@ -2392,7 +2392,7 @@  discard block
 block discarded – undo
2392 2392
         }
2393 2393
 
2394 2394
         // setup variation select values for the currently selected template.
2395
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2395
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2396 2396
             $this->_message_template_group->messenger(),
2397 2397
             $this->_message_template_group->message_type()
2398 2398
         );
@@ -2406,12 +2406,12 @@  discard block
 block discarded – undo
2406 2406
 
2407 2407
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2408 2408
 
2409
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2409
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2410 2410
             'MTP_template_pack',
2411 2411
             $tp_select_values,
2412 2412
             $this->_message_template_group->get_template_pack_name()
2413 2413
         );
2414
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2414
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2415 2415
             'MTP_template_variation',
2416 2416
             $variations_select_values,
2417 2417
             $this->_message_template_group->get_template_pack_variation()
@@ -2421,7 +2421,7 @@  discard block
 block discarded – undo
2421 2421
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2422 2422
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2423 2423
 
2424
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2424
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2425 2425
 
2426 2426
         EEH_Template::display_template($template, $template_args);
2427 2427
     }
@@ -2447,33 +2447,33 @@  discard block
 block discarded – undo
2447 2447
         // first we need to see if there are any fields
2448 2448
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2449 2449
 
2450
-        if (! empty($fields)) {
2450
+        if ( ! empty($fields)) {
2451 2451
             // yup there be fields
2452 2452
             foreach ($fields as $field => $config) {
2453
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2453
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2454 2454
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2455 2455
                 $default  = isset($config['default']) ? $config['default'] : '';
2456 2456
                 $default  = isset($config['value']) ? $config['value'] : $default;
2457 2457
 
2458 2458
                 // if type is hidden and the value is empty
2459 2459
                 // something may have gone wrong so let's correct with the defaults
2460
-                $fix                = $config['input'] === 'hidden'
2461
-                                      && isset($existing[ $field ])
2462
-                                      && empty($existing[ $field ])
2460
+                $fix = $config['input'] === 'hidden'
2461
+                                      && isset($existing[$field])
2462
+                                      && empty($existing[$field])
2463 2463
                     ? $default
2464 2464
                     : '';
2465
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2466
-                    ? $existing[ $field ]
2465
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2466
+                    ? $existing[$field]
2467 2467
                     : $fix;
2468 2468
 
2469
-                $template_form_fields[ $field_id ] = [
2470
-                    'name'       => 'test_settings_fld[' . $field . ']',
2469
+                $template_form_fields[$field_id] = [
2470
+                    'name'       => 'test_settings_fld['.$field.']',
2471 2471
                     'label'      => $config['label'],
2472 2472
                     'input'      => $config['input'],
2473 2473
                     'type'       => $config['type'],
2474 2474
                     'required'   => $config['required'],
2475 2475
                     'validation' => $config['validation'],
2476
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2476
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2477 2477
                     'css_class'  => $config['css_class'],
2478 2478
                     'options'    => isset($config['options']) ? $config['options'] : [],
2479 2479
                     'default'    => $default,
@@ -2487,7 +2487,7 @@  discard block
 block discarded – undo
2487 2487
             : '';
2488 2488
 
2489 2489
         // print out $test_settings_fields
2490
-        if (! empty($test_settings_html)) {
2490
+        if ( ! empty($test_settings_html)) {
2491 2491
             $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2492 2492
             $test_settings_html .= 'name="test_button" value="';
2493 2493
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2533,7 +2533,7 @@  discard block
 block discarded – undo
2533 2533
         ];
2534 2534
 
2535 2535
         return EEH_Template::display_template(
2536
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2536
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2537 2537
             $template_args,
2538 2538
             true
2539 2539
         );
@@ -2559,7 +2559,7 @@  discard block
 block discarded – undo
2559 2559
         // $messenger = $this->_message_template_group->messenger_obj();
2560 2560
         // now let's set the content depending on the status of the shortcodes array
2561 2561
         if (empty($shortcodes)) {
2562
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2562
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2563 2563
             return;
2564 2564
         }
2565 2565
         ?>
@@ -2595,7 +2595,7 @@  discard block
 block discarded – undo
2595 2595
     {
2596 2596
 
2597 2597
         // no need to run this if the property is already set
2598
-        if (! empty($this->_shortcodes)) {
2598
+        if ( ! empty($this->_shortcodes)) {
2599 2599
             return;
2600 2600
         }
2601 2601
 
@@ -2650,7 +2650,7 @@  discard block
 block discarded – undo
2650 2650
     protected function _set_message_template_group()
2651 2651
     {
2652 2652
         // get out if this is already set.
2653
-        if (! empty($this->_message_template_group)) {
2653
+        if ( ! empty($this->_message_template_group)) {
2654 2654
             return;
2655 2655
         }
2656 2656
 
@@ -3036,7 +3036,7 @@  discard block
 block discarded – undo
3036 3036
     {
3037 3037
         if (is_array($content)) {
3038 3038
             foreach ($content as $key => $value) {
3039
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3039
+                $content[$key] = $this->sanitizeMessageTemplateContent($value);
3040 3040
             }
3041 3041
             return $content;
3042 3042
         }
@@ -3074,7 +3074,7 @@  discard block
 block discarded – undo
3074 3074
 
3075 3075
         $context   = ucwords(str_replace('_', ' ', $context));
3076 3076
         $item_desc = $messenger_label && $message_type_label
3077
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3077
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
3078 3078
             : '';
3079 3079
         $item_desc .= 'Message Template';
3080 3080
         return $item_desc;
@@ -3226,7 +3226,7 @@  discard block
 block discarded – undo
3226 3226
         if ($all) {
3227 3227
             // Checkboxes
3228 3228
             $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3229
-            if (! empty($checkboxes)) {
3229
+            if ( ! empty($checkboxes)) {
3230 3230
                 // if array has more than one element then success message should be plural.
3231 3231
                 // todo: what about nonce?
3232 3232
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -3236,18 +3236,18 @@  discard block
 block discarded – undo
3236 3236
                     $trashed_or_restored = $trash
3237 3237
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3238 3238
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3239
-                    if (! $trashed_or_restored) {
3239
+                    if ( ! $trashed_or_restored) {
3240 3240
                         $success = 0;
3241 3241
                     }
3242 3242
                 }
3243 3243
             } else {
3244 3244
                 // grab single GRP_ID and handle
3245 3245
                 $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3246
-                if (! empty($GRP_ID)) {
3246
+                if ( ! empty($GRP_ID)) {
3247 3247
                     $trashed_or_restored = $trash
3248 3248
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3249 3249
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3250
-                    if (! $trashed_or_restored) {
3250
+                    if ( ! $trashed_or_restored) {
3251 3251
                         $success = 0;
3252 3252
                     }
3253 3253
                 } else {
@@ -3295,7 +3295,7 @@  discard block
 block discarded – undo
3295 3295
 
3296 3296
         // checkboxes
3297 3297
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3298
-        if (! empty($checkboxes)) {
3298
+        if ( ! empty($checkboxes)) {
3299 3299
             // if array has more than one element then success message should be plural
3300 3300
             $success = count($checkboxes) > 1 ? 2 : 1;
3301 3301
 
@@ -3399,7 +3399,7 @@  discard block
 block discarded – undo
3399 3399
     protected function _set_m_mt_settings()
3400 3400
     {
3401 3401
         // first if this is already set then lets get out no need to regenerate data.
3402
-        if (! empty($this->_m_mt_settings)) {
3402
+        if ( ! empty($this->_m_mt_settings)) {
3403 3403
             return;
3404 3404
         }
3405 3405
 
@@ -3412,8 +3412,8 @@  discard block
 block discarded – undo
3412 3412
 
3413 3413
         foreach ($messengers as $messenger) {
3414 3414
             $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3415
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3416
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3415
+            $class = 'ee-messenger-'.sanitize_key($messenger->label['singular']);
3416
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3417 3417
                 'label' => ucwords($messenger->label['singular']),
3418 3418
                 'class' => $active ? "{$class} messenger-active" : $class,
3419 3419
                 'href'  => $messenger->name,
@@ -3431,7 +3431,7 @@  discard block
 block discarded – undo
3431 3431
             foreach ($message_types as $message_type) {
3432 3432
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3433 3433
                 // it shouldn't show in either the inactive OR active metabox.
3434
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3434
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3435 3435
                     continue;
3436 3436
                 }
3437 3437
 
@@ -3442,12 +3442,12 @@  discard block
 block discarded – undo
3442 3442
                     ? 'active'
3443 3443
                     : 'inactive';
3444 3444
 
3445
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3445
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3446 3446
                     'label'    => ucwords($message_type->label['singular']),
3447
-                    'class'    => 'message-type-' . $a_or_i,
3448
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3449
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3450
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3447
+                    'class'    => 'message-type-'.$a_or_i,
3448
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3449
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3450
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3451 3451
                     'title'    => $a_or_i === 'active'
3452 3452
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3453 3453
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3478,25 +3478,25 @@  discard block
 block discarded – undo
3478 3478
         $fields                                         = $message_type->get_admin_settings_fields();
3479 3479
         $settings_template_args['template_form_fields'] = '';
3480 3480
 
3481
-        if (! empty($fields) && $active) {
3481
+        if ( ! empty($fields) && $active) {
3482 3482
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3483 3483
             foreach ($fields as $fldname => $fldprops) {
3484
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3485
-                $template_form_field[ $field_id ] = [
3486
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3484
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3485
+                $template_form_field[$field_id] = [
3486
+                    'name'       => 'message_type_settings['.$fldname.']',
3487 3487
                     'label'      => $fldprops['label'],
3488 3488
                     'input'      => $fldprops['field_type'],
3489 3489
                     'type'       => $fldprops['value_type'],
3490 3490
                     'required'   => $fldprops['required'],
3491 3491
                     'validation' => $fldprops['validation'],
3492
-                    'value'      => isset($existing_settings[ $fldname ])
3493
-                        ? $existing_settings[ $fldname ]
3492
+                    'value'      => isset($existing_settings[$fldname])
3493
+                        ? $existing_settings[$fldname]
3494 3494
                         : $fldprops['default'],
3495 3495
                     'options'    => isset($fldprops['options'])
3496 3496
                         ? $fldprops['options']
3497 3497
                         : [],
3498
-                    'default'    => isset($existing_settings[ $fldname ])
3499
-                        ? $existing_settings[ $fldname ]
3498
+                    'default'    => isset($existing_settings[$fldname])
3499
+                        ? $existing_settings[$fldname]
3500 3500
                         : $fldprops['default'],
3501 3501
                     'css_class'  => 'no-drag',
3502 3502
                     'format'     => $fldprops['format'],
@@ -3516,15 +3516,15 @@  discard block
 block discarded – undo
3516 3516
         $settings_template_args['description'] = $message_type->description;
3517 3517
         // we also need some hidden fields
3518 3518
         $hidden_fields = [
3519
-            'message_type_settings[messenger]' . $message_type->name    => [
3519
+            'message_type_settings[messenger]'.$message_type->name    => [
3520 3520
                 'type'  => 'hidden',
3521 3521
                 'value' => $messenger->name,
3522 3522
             ],
3523
-            'message_type_settings[message_type]' . $message_type->name => [
3523
+            'message_type_settings[message_type]'.$message_type->name => [
3524 3524
                 'type'  => 'hidden',
3525 3525
                 'value' => $message_type->name,
3526 3526
             ],
3527
-            'type' . $message_type->name                                => [
3527
+            'type'.$message_type->name                                => [
3528 3528
                 'type'  => 'hidden',
3529 3529
                 'value' => 'message_type',
3530 3530
             ],
@@ -3534,12 +3534,12 @@  discard block
 block discarded – undo
3534 3534
             $hidden_fields,
3535 3535
             'array'
3536 3536
         );
3537
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3537
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3538 3538
             ? ' hidden'
3539 3539
             : '';
3540 3540
 
3541 3541
 
3542
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3542
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3543 3543
         return EEH_Template::display_template($template, $settings_template_args, true);
3544 3544
     }
3545 3545
 
@@ -3567,21 +3567,21 @@  discard block
 block discarded – undo
3567 3567
 
3568 3568
                 // messenger meta boxes
3569 3569
                 $active         = $selected_messenger === $messenger;
3570
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3571
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3570
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3571
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3572 3572
                     : '';
3573 3573
 
3574
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3574
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3575 3575
                     esc_html__('%s Settings', 'event_espresso'),
3576 3576
                     $tab_array['label']
3577 3577
                 );
3578 3578
 
3579
-                $m_template_args[ $messenger . '_a_box' ] = [
3579
+                $m_template_args[$messenger.'_a_box'] = [
3580 3580
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3581 3581
                     'inactive_message_types' => isset(
3582
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3582
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3583 3583
                     )
3584
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3584
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3585 3585
                         : '',
3586 3586
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3587 3587
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3593,13 +3593,13 @@  discard block
 block discarded – undo
3593 3593
                 // message type meta boxes
3594 3594
                 // (which is really just the inactive container for each messenger
3595 3595
                 // showing inactive message types for that messenger)
3596
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3597
-                $mt_template_args[ $messenger . '_i_box' ] = [
3596
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3597
+                $mt_template_args[$messenger.'_i_box'] = [
3598 3598
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3599 3599
                     'inactive_message_types' => isset(
3600
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3600
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3601 3601
                     )
3602
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3602
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3603 3603
                         : '',
3604 3604
                     'hidden'                 => $active ? '' : ' hidden',
3605 3605
                     'hide_on_message'        => $hide_on_message,
@@ -3612,14 +3612,14 @@  discard block
 block discarded – undo
3612 3612
 
3613 3613
 
3614 3614
         // register messenger metaboxes
3615
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3615
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3616 3616
         foreach ($m_boxes as $box => $label) {
3617
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3617
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3618 3618
             $msgr          = str_replace('_a_box', '', $box);
3619 3619
             $this->addMetaBox(
3620
-                'espresso_' . $msgr . '_settings',
3620
+                'espresso_'.$msgr.'_settings',
3621 3621
                 $label,
3622
-                function ($post, $metabox) {
3622
+                function($post, $metabox) {
3623 3623
                     EEH_Template::display_template(
3624 3624
                         $metabox['args']['template_path'],
3625 3625
                         $metabox['args']['template_args']
@@ -3633,17 +3633,17 @@  discard block
 block discarded – undo
3633 3633
         }
3634 3634
 
3635 3635
         // register message type metaboxes
3636
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3636
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3637 3637
         foreach ($mt_boxes as $box => $label) {
3638 3638
             $callback_args = [
3639 3639
                 'template_path' => $mt_template_path,
3640
-                'template_args' => $mt_template_args[ $box ],
3640
+                'template_args' => $mt_template_args[$box],
3641 3641
             ];
3642
-            $mt            = str_replace('_i_box', '', $box);
3642
+            $mt = str_replace('_i_box', '', $box);
3643 3643
             $this->addMetaBox(
3644
-                'espresso_' . $mt . '_inactive_mts',
3644
+                'espresso_'.$mt.'_inactive_mts',
3645 3645
                 $label,
3646
-                function ($post, $metabox) {
3646
+                function($post, $metabox) {
3647 3647
                     EEH_Template::display_template(
3648 3648
                         $metabox['args']['template_path'],
3649 3649
                         $metabox['args']['template_args']
@@ -3790,7 +3790,7 @@  discard block
 block discarded – undo
3790 3790
             if ($form->is_valid()) {
3791 3791
                 $valid_data = $form->valid_data();
3792 3792
                 foreach ($valid_data as $property => $value) {
3793
-                    $setter = 'set_' . $property;
3793
+                    $setter = 'set_'.$property;
3794 3794
                     if (method_exists($network_config, $setter)) {
3795 3795
                         $network_config->{$setter}($value);
3796 3796
                     } elseif (
@@ -3826,7 +3826,7 @@  discard block
 block discarded – undo
3826 3826
     protected function _get_mt_tabs($tab_array)
3827 3827
     {
3828 3828
         $tab_array = (array) $tab_array;
3829
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3829
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3830 3830
         $tabs      = '';
3831 3831
 
3832 3832
         foreach ($tab_array as $tab) {
@@ -3854,19 +3854,19 @@  discard block
 block discarded – undo
3854 3854
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3855 3855
 
3856 3856
 
3857
-        if (! empty($fields)) {
3857
+        if ( ! empty($fields)) {
3858 3858
             $existing_settings = $messenger->get_existing_admin_settings();
3859 3859
 
3860 3860
             foreach ($fields as $field_name => $field_props) {
3861
-                $field_id                         = $messenger->name . '-' . $field_name;
3862
-                $template_form_field[ $field_id ] = [
3863
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3861
+                $field_id                         = $messenger->name.'-'.$field_name;
3862
+                $template_form_field[$field_id] = [
3863
+                    'name'       => 'messenger_settings['.$field_id.']',
3864 3864
                     'label'      => $field_props['label'],
3865 3865
                     'input'      => $field_props['field_type'],
3866 3866
                     'type'       => $field_props['value_type'],
3867 3867
                     'required'   => $field_props['required'],
3868 3868
                     'validation' => $field_props['validation'],
3869
-                    'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3869
+                    'value'      => $existing_settings[$field_id] ?? $field_props['default'],
3870 3870
                     'css_class'  => '',
3871 3871
                     'format'     => $field_props['format'],
3872 3872
                 ];
@@ -3879,20 +3879,20 @@  discard block
 block discarded – undo
3879 3879
 
3880 3880
         // we also need some hidden fields
3881 3881
         $settings_template_args['hidden_fields'] = [
3882
-            'messenger_settings[messenger]' . $messenger->name => [
3882
+            'messenger_settings[messenger]'.$messenger->name => [
3883 3883
                 'type'  => 'hidden',
3884 3884
                 'value' => $messenger->name,
3885 3885
             ],
3886
-            'type' . $messenger->name                          => [
3886
+            'type'.$messenger->name                          => [
3887 3887
                 'type'  => 'hidden',
3888 3888
                 'value' => 'messenger',
3889 3889
             ],
3890 3890
         ];
3891 3891
 
3892 3892
         // make sure any active message types that are existing are included in the hidden fields
3893
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3894
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3895
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3893
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3894
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3895
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3896 3896
                     'type'  => 'hidden',
3897 3897
                     'value' => $mt,
3898 3898
                 ];
@@ -3902,7 +3902,7 @@  discard block
 block discarded – undo
3902 3902
             $settings_template_args['hidden_fields'],
3903 3903
             'array'
3904 3904
         );
3905
-        $active                                  =
3905
+        $active =
3906 3906
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3907 3907
 
3908 3908
         $settings_template_args['messenger']           = $messenger->name;
@@ -3922,9 +3922,9 @@  discard block
 block discarded – undo
3922 3922
 
3923 3923
 
3924 3924
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3925
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3925
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3926 3926
         $settings_template_args['on_off_status'] = $active;
3927
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3927
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3928 3928
         return EEH_Template::display_template(
3929 3929
             $template,
3930 3930
             $settings_template_args,
@@ -3949,7 +3949,7 @@  discard block
 block discarded – undo
3949 3949
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3950 3950
         // let's check that we have required data
3951 3951
 
3952
-        if (! $this->_active_messenger_name) {
3952
+        if ( ! $this->_active_messenger_name) {
3953 3953
             EE_Error::add_error(
3954 3954
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3955 3955
                 __FILE__,
@@ -3967,7 +3967,7 @@  discard block
 block discarded – undo
3967 3967
 
3968 3968
 
3969 3969
         $status = $this->request->getRequestParam('status');
3970
-        if (! $status) {
3970
+        if ( ! $status) {
3971 3971
             EE_Error::add_error(
3972 3972
                 esc_html__(
3973 3973
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4024,7 +4024,7 @@  discard block
 block discarded – undo
4024 4024
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
4025 4025
 
4026 4026
         // let's make sure we have the necessary data
4027
-        if (! $this->_active_message_type_name) {
4027
+        if ( ! $this->_active_message_type_name) {
4028 4028
             EE_Error::add_error(
4029 4029
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4030 4030
                 __FILE__,
@@ -4034,7 +4034,7 @@  discard block
 block discarded – undo
4034 4034
             $success = false;
4035 4035
         }
4036 4036
 
4037
-        if (! $this->_active_messenger_name) {
4037
+        if ( ! $this->_active_messenger_name) {
4038 4038
             EE_Error::add_error(
4039 4039
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4040 4040
                 __FILE__,
@@ -4045,7 +4045,7 @@  discard block
 block discarded – undo
4045 4045
         }
4046 4046
 
4047 4047
         $status = $this->request->getRequestParam('status');
4048
-        if (! $status) {
4048
+        if ( ! $status) {
4049 4049
             EE_Error::add_error(
4050 4050
                 esc_html__(
4051 4051
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4257,7 +4257,7 @@  discard block
 block discarded – undo
4257 4257
         EE_Message_Type $message_type = null
4258 4258
     ) {
4259 4259
         // if $messenger isn't a valid messenger object then get out.
4260
-        if (! $messenger instanceof EE_Messenger) {
4260
+        if ( ! $messenger instanceof EE_Messenger) {
4261 4261
             EE_Error::add_error(
4262 4262
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4263 4263
                 __FILE__,
@@ -4311,7 +4311,7 @@  discard block
 block discarded – undo
4311 4311
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4312 4312
             // in which case we just give a success message for the messenger being successfully activated.
4313 4313
         } else {
4314
-            if (! $messenger->get_default_message_types()) {
4314
+            if ( ! $messenger->get_default_message_types()) {
4315 4315
                 // messenger doesn't have any default message types so still a success.
4316 4316
                 EE_Error::add_success(
4317 4317
                     sprintf(
@@ -4367,7 +4367,7 @@  discard block
 block discarded – undo
4367 4367
         EE_Error::overwrite_success();
4368 4368
 
4369 4369
         // if $messenger isn't a valid messenger object then get out.
4370
-        if (! $messenger instanceof EE_Messenger) {
4370
+        if ( ! $messenger instanceof EE_Messenger) {
4371 4371
             EE_Error::add_error(
4372 4372
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4373 4373
                 __FILE__,
@@ -4437,7 +4437,7 @@  discard block
 block discarded – undo
4437 4437
      */
4438 4438
     public function update_mt_form()
4439 4439
     {
4440
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4440
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4441 4441
             EE_Error::add_error(
4442 4442
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4443 4443
                 __FILE__,
@@ -4448,7 +4448,7 @@  discard block
 block discarded – undo
4448 4448
         }
4449 4449
 
4450 4450
         $message_types = $this->get_installed_message_types();
4451
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4451
+        $message_type  = $message_types[$this->_active_message_type_name];
4452 4452
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4453 4453
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4454 4454
 
@@ -4467,7 +4467,7 @@  discard block
 block discarded – undo
4467 4467
     public function save_settings()
4468 4468
     {
4469 4469
         $type = $this->request->getRequestParam('type');
4470
-        if (! $type) {
4470
+        if ( ! $type) {
4471 4471
             EE_Error::add_error(
4472 4472
                 esc_html__(
4473 4473
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.