Completed
Branch dev (6b2695)
by
unknown
13:02 queued 05:30
created
templates/reg_admin_details_side_meta_box_registrant.template.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 
19 19
 $attendee_full_name = "$fname $lname";
20 20
 $email = sanitize_email($email);
21
-$avatar  = get_avatar_url($email);
21
+$avatar = get_avatar_url($email);
22 22
 ?>
23 23
 
24 24
 <div id='admin-side-mbox-primary-registrant-dv' class='admin-side-mbox-dv'>
25
-    <?php if (! empty($avatar)) : ?>
25
+    <?php if ( ! empty($avatar)) : ?>
26 26
     <div class="ee-admin-attendee-avatar">
27 27
         <img alt="profile pic for <?php echo esc_html($attendee_full_name); ?>" src="<?php echo $avatar; ?>" />
28 28
     </div>
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
                 <a href="mailto:<?php echo esc_attr($email); ?>"><?php echo esc_html($email); ?></a>
38 38
             </div>
39 39
         </div>
40
-        <?php if (! empty($phone)) : ?>
40
+        <?php if ( ! empty($phone)) : ?>
41 41
             <div class='ee-admin-attendee-phone'>
42 42
                 <div class='ee-admin-contact-details-with-dashicon'>
43 43
                     <span class='dashicons dashicons-phone'></span>
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
                 </div>
46 46
             </div>
47 47
         <?php endif; ?>
48
-        <?php if (! empty($formatted_address)) : ?>
48
+        <?php if ( ! empty($formatted_address)) : ?>
49 49
         <div class='ee-admin-attendee-address'>
50 50
             <div class='ee-admin-contact-details-with-dashicon'>
51 51
                 <span class='dashicons dashicons-location'></span>
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             <?php echo esc_html($att_edit_label); ?>
74 74
         </a>
75 75
 
76
-    <?php if (! empty($create_link)) : ?>
76
+    <?php if ( ! empty($create_link)) : ?>
77 77
         <a class="button button--small button--secondary" href="<?php echo esc_url_raw($create_link); ?>"
78 78
            title="<?php esc_attr_e(
79 79
                'This registration shares the contact details for the primary registration in this group.  If you\'d like this registration to have its own details, you can do so by clicking this button',
@@ -86,4 +86,4 @@  discard block
 block discarded – undo
86 86
     <?php endif; ?>
87 87
 
88 88
     </div>
89
-<?php endif;?>
89
+<?php endif; ?>
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3651 added lines, -3651 removed lines patch added patch discarded remove patch
@@ -19,2203 +19,2203 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
21 21
 {
22
-    /**
23
-     * @var EE_Registration
24
-     */
25
-    private $_registration;
26
-
27
-    /**
28
-     * @var EE_Event
29
-     */
30
-    private $_reg_event;
31
-
32
-    /**
33
-     * @var EE_Session
34
-     */
35
-    private $_session;
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    private static $_reg_status;
41
-
42
-    /**
43
-     * Form for displaying the custom questions for this registration.
44
-     * This gets used a few times throughout the request so its best to cache it
45
-     *
46
-     * @var EE_Registration_Custom_Questions_Form
47
-     */
48
-    protected $_reg_custom_questions_form;
49
-
50
-    /**
51
-     * @var EEM_Registration $registration_model
52
-     */
53
-    private $registration_model;
54
-
55
-    /**
56
-     * @var EEM_Attendee $attendee_model
57
-     */
58
-    private $attendee_model;
59
-
60
-    /**
61
-     * @var EEM_Event $event_model
62
-     */
63
-    private $event_model;
64
-
65
-    /**
66
-     * @var EEM_Status $status_model
67
-     */
68
-    private $status_model;
69
-
70
-
71
-    /**
72
-     * @param bool $routing
73
-     * @throws EE_Error
74
-     * @throws InvalidArgumentException
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws ReflectionException
78
-     */
79
-    public function __construct($routing = true)
80
-    {
81
-        parent::__construct($routing);
82
-        add_action('wp_loaded', [$this, 'wp_loaded']);
83
-    }
84
-
85
-
86
-    /**
87
-     * @return EEM_Registration
88
-     * @throws InvalidArgumentException
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     * @since 4.10.2.p
92
-     */
93
-    protected function getRegistrationModel()
94
-    {
95
-        if (! $this->registration_model instanceof EEM_Registration) {
96
-            $this->registration_model = $this->loader->getShared('EEM_Registration');
97
-        }
98
-        return $this->registration_model;
99
-    }
100
-
101
-
102
-    /**
103
-     * @return EEM_Attendee
104
-     * @throws InvalidArgumentException
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     * @since 4.10.2.p
108
-     */
109
-    protected function getAttendeeModel()
110
-    {
111
-        if (! $this->attendee_model instanceof EEM_Attendee) {
112
-            $this->attendee_model = $this->loader->getShared('EEM_Attendee');
113
-        }
114
-        return $this->attendee_model;
115
-    }
116
-
117
-
118
-    /**
119
-     * @return EEM_Event
120
-     * @throws InvalidArgumentException
121
-     * @throws InvalidDataTypeException
122
-     * @throws InvalidInterfaceException
123
-     * @since 4.10.2.p
124
-     */
125
-    protected function getEventModel()
126
-    {
127
-        if (! $this->event_model instanceof EEM_Event) {
128
-            $this->event_model = $this->loader->getShared('EEM_Event');
129
-        }
130
-        return $this->event_model;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return EEM_Status
136
-     * @throws InvalidArgumentException
137
-     * @throws InvalidDataTypeException
138
-     * @throws InvalidInterfaceException
139
-     * @since 4.10.2.p
140
-     */
141
-    protected function getStatusModel()
142
-    {
143
-        if (! $this->status_model instanceof EEM_Status) {
144
-            $this->status_model = $this->loader->getShared('EEM_Status');
145
-        }
146
-        return $this->status_model;
147
-    }
148
-
149
-
150
-    public function wp_loaded()
151
-    {
152
-        // when adding a new registration...
153
-        $action = $this->request->getRequestParam('action');
154
-        if ($action === 'new_registration') {
155
-            EE_System::do_not_cache();
156
-            if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
-                // and it's NOT the attendee information reg step
158
-                // force cookie expiration by setting time to last week
159
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
-                // and update the global
161
-                $_COOKIE['ee_registration_added'] = 0;
162
-            }
163
-        }
164
-    }
165
-
166
-
167
-    protected function _init_page_props()
168
-    {
169
-        $this->page_slug        = REG_PG_SLUG;
170
-        $this->_admin_base_url  = REG_ADMIN_URL;
171
-        $this->_admin_base_path = REG_ADMIN;
172
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
173
-        $this->_cpt_routes      = [
174
-            'add_new_attendee' => 'espresso_attendees',
175
-            'edit_attendee'    => 'espresso_attendees',
176
-            'insert_attendee'  => 'espresso_attendees',
177
-            'update_attendee'  => 'espresso_attendees',
178
-        ];
179
-        $this->_cpt_model_names = [
180
-            'add_new_attendee' => 'EEM_Attendee',
181
-            'edit_attendee'    => 'EEM_Attendee',
182
-        ];
183
-        $this->_cpt_edit_routes = [
184
-            'espresso_attendees' => 'edit_attendee',
185
-        ];
186
-        $this->_pagenow_map     = [
187
-            'add_new_attendee' => 'post-new.php',
188
-            'edit_attendee'    => 'post.php',
189
-            'trash'            => 'post.php',
190
-        ];
191
-        add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
-        // add filters so that the comment urls don't take users to a confusing 404 page
193
-        add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
-    }
195
-
196
-
197
-    /**
198
-     * @param string     $link    The comment permalink with '#comment-$id' appended.
199
-     * @param WP_Comment $comment The current comment object.
200
-     * @return string
201
-     */
202
-    public function clear_comment_link($link, WP_Comment $comment)
203
-    {
204
-        // gotta make sure this only happens on this route
205
-        $post_type = get_post_type($comment->comment_post_ID);
206
-        if ($post_type === 'espresso_attendees') {
207
-            return '#commentsdiv';
208
-        }
209
-        return $link;
210
-    }
211
-
212
-
213
-    protected function _ajax_hooks()
214
-    {
215
-        // todo: all hooks for registrations ajax goes in here
216
-        add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
-    }
218
-
219
-
220
-    protected function _define_page_props()
221
-    {
222
-        $this->_admin_page_title = $this->page_label;
223
-        $this->_labels           = [
224
-            'buttons'                      => [
225
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
-            ],
234
-            'publishbox'                   => [
235
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
-            ],
238
-            'hide_add_button_on_cpt_route' => [
239
-                'edit_attendee' => true,
240
-            ],
241
-        ];
242
-    }
243
-
244
-
245
-    /**
246
-     * grab url requests and route them
247
-     *
248
-     * @return void
249
-     * @throws EE_Error
250
-     */
251
-    public function _set_page_routes()
252
-    {
253
-        $this->_get_registration_status_array();
254
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
-        $REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
-        $ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
-        $this->_page_routes = [
259
-            'default'                             => [
260
-                'func'       => '_registrations_overview_list_table',
261
-                'capability' => 'ee_read_registrations',
262
-            ],
263
-            'view_registration'                   => [
264
-                'func'       => '_registration_details',
265
-                'capability' => 'ee_read_registration',
266
-                'obj_id'     => $REG_ID,
267
-            ],
268
-            'edit_registration'                   => [
269
-                'func'               => '_update_attendee_registration_form',
270
-                'noheader'           => true,
271
-                'headers_sent_route' => 'view_registration',
272
-                'capability'         => 'ee_edit_registration',
273
-                'obj_id'             => $REG_ID,
274
-                '_REG_ID'            => $REG_ID,
275
-            ],
276
-            'trash_registrations'                 => [
277
-                'func'       => '_trash_or_restore_registrations',
278
-                'args'       => ['trash' => true],
279
-                'noheader'   => true,
280
-                'capability' => 'ee_delete_registrations',
281
-            ],
282
-            'restore_registrations'               => [
283
-                'func'       => '_trash_or_restore_registrations',
284
-                'args'       => ['trash' => false],
285
-                'noheader'   => true,
286
-                'capability' => 'ee_delete_registrations',
287
-            ],
288
-            'delete_registrations'                => [
289
-                'func'       => '_delete_registrations',
290
-                'noheader'   => true,
291
-                'capability' => 'ee_delete_registrations',
292
-            ],
293
-            'new_registration'                    => [
294
-                'func'       => 'new_registration',
295
-                'capability' => 'ee_edit_registrations',
296
-            ],
297
-            'process_reg_step'                    => [
298
-                'func'       => 'process_reg_step',
299
-                'noheader'   => true,
300
-                'capability' => 'ee_edit_registrations',
301
-            ],
302
-            'redirect_to_txn'                     => [
303
-                'func'       => 'redirect_to_txn',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-            ],
307
-            'change_reg_status'                   => [
308
-                'func'       => '_change_reg_status',
309
-                'noheader'   => true,
310
-                'capability' => 'ee_edit_registration',
311
-                'obj_id'     => $REG_ID,
312
-            ],
313
-            'approve_registration'                => [
314
-                'func'       => 'approve_registration',
315
-                'noheader'   => true,
316
-                'capability' => 'ee_edit_registration',
317
-                'obj_id'     => $REG_ID,
318
-            ],
319
-            'approve_and_notify_registration'     => [
320
-                'func'       => 'approve_registration',
321
-                'noheader'   => true,
322
-                'args'       => [true],
323
-                'capability' => 'ee_edit_registration',
324
-                'obj_id'     => $REG_ID,
325
-            ],
326
-            'approve_registrations'               => [
327
-                'func'       => 'bulk_action_on_registrations',
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_registrations',
330
-                'args'       => ['approve'],
331
-            ],
332
-            'approve_and_notify_registrations'    => [
333
-                'func'       => 'bulk_action_on_registrations',
334
-                'noheader'   => true,
335
-                'capability' => 'ee_edit_registrations',
336
-                'args'       => ['approve', true],
337
-            ],
338
-            'decline_registration'                => [
339
-                'func'       => 'decline_registration',
340
-                'noheader'   => true,
341
-                'capability' => 'ee_edit_registration',
342
-                'obj_id'     => $REG_ID,
343
-            ],
344
-            'decline_and_notify_registration'     => [
345
-                'func'       => 'decline_registration',
346
-                'noheader'   => true,
347
-                'args'       => [true],
348
-                'capability' => 'ee_edit_registration',
349
-                'obj_id'     => $REG_ID,
350
-            ],
351
-            'decline_registrations'               => [
352
-                'func'       => 'bulk_action_on_registrations',
353
-                'noheader'   => true,
354
-                'capability' => 'ee_edit_registrations',
355
-                'args'       => ['decline'],
356
-            ],
357
-            'decline_and_notify_registrations'    => [
358
-                'func'       => 'bulk_action_on_registrations',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_edit_registrations',
361
-                'args'       => ['decline', true],
362
-            ],
363
-            'pending_registration'                => [
364
-                'func'       => 'pending_registration',
365
-                'noheader'   => true,
366
-                'capability' => 'ee_edit_registration',
367
-                'obj_id'     => $REG_ID,
368
-            ],
369
-            'pending_and_notify_registration'     => [
370
-                'func'       => 'pending_registration',
371
-                'noheader'   => true,
372
-                'args'       => [true],
373
-                'capability' => 'ee_edit_registration',
374
-                'obj_id'     => $REG_ID,
375
-            ],
376
-            'pending_registrations'               => [
377
-                'func'       => 'bulk_action_on_registrations',
378
-                'noheader'   => true,
379
-                'capability' => 'ee_edit_registrations',
380
-                'args'       => ['pending'],
381
-            ],
382
-            'pending_and_notify_registrations'    => [
383
-                'func'       => 'bulk_action_on_registrations',
384
-                'noheader'   => true,
385
-                'capability' => 'ee_edit_registrations',
386
-                'args'       => ['pending', true],
387
-            ],
388
-            'no_approve_registration'             => [
389
-                'func'       => 'not_approve_registration',
390
-                'noheader'   => true,
391
-                'capability' => 'ee_edit_registration',
392
-                'obj_id'     => $REG_ID,
393
-            ],
394
-            'no_approve_and_notify_registration'  => [
395
-                'func'       => 'not_approve_registration',
396
-                'noheader'   => true,
397
-                'args'       => [true],
398
-                'capability' => 'ee_edit_registration',
399
-                'obj_id'     => $REG_ID,
400
-            ],
401
-            'no_approve_registrations'            => [
402
-                'func'       => 'bulk_action_on_registrations',
403
-                'noheader'   => true,
404
-                'capability' => 'ee_edit_registrations',
405
-                'args'       => ['not_approve'],
406
-            ],
407
-            'no_approve_and_notify_registrations' => [
408
-                'func'       => 'bulk_action_on_registrations',
409
-                'noheader'   => true,
410
-                'capability' => 'ee_edit_registrations',
411
-                'args'       => ['not_approve', true],
412
-            ],
413
-            'cancel_registration'                 => [
414
-                'func'       => 'cancel_registration',
415
-                'noheader'   => true,
416
-                'capability' => 'ee_edit_registration',
417
-                'obj_id'     => $REG_ID,
418
-            ],
419
-            'cancel_and_notify_registration'      => [
420
-                'func'       => 'cancel_registration',
421
-                'noheader'   => true,
422
-                'args'       => [true],
423
-                'capability' => 'ee_edit_registration',
424
-                'obj_id'     => $REG_ID,
425
-            ],
426
-            'cancel_registrations'                => [
427
-                'func'       => 'bulk_action_on_registrations',
428
-                'noheader'   => true,
429
-                'capability' => 'ee_edit_registrations',
430
-                'args'       => ['cancel'],
431
-            ],
432
-            'cancel_and_notify_registrations'     => [
433
-                'func'       => 'bulk_action_on_registrations',
434
-                'noheader'   => true,
435
-                'capability' => 'ee_edit_registrations',
436
-                'args'       => ['cancel', true],
437
-            ],
438
-            'wait_list_registration'              => [
439
-                'func'       => 'wait_list_registration',
440
-                'noheader'   => true,
441
-                'capability' => 'ee_edit_registration',
442
-                'obj_id'     => $REG_ID,
443
-            ],
444
-            'wait_list_and_notify_registration'   => [
445
-                'func'       => 'wait_list_registration',
446
-                'noheader'   => true,
447
-                'args'       => [true],
448
-                'capability' => 'ee_edit_registration',
449
-                'obj_id'     => $REG_ID,
450
-            ],
451
-            'contact_list'                        => [
452
-                'func'       => '_attendee_contact_list_table',
453
-                'capability' => 'ee_read_contacts',
454
-            ],
455
-            'add_new_attendee'                    => [
456
-                'func' => '_create_new_cpt_item',
457
-                'args' => [
458
-                    'new_attendee' => true,
459
-                    'capability'   => 'ee_edit_contacts',
460
-                ],
461
-            ],
462
-            'edit_attendee'                       => [
463
-                'func'       => '_edit_cpt_item',
464
-                'capability' => 'ee_edit_contacts',
465
-                'obj_id'     => $ATT_ID,
466
-            ],
467
-            'duplicate_attendee'                  => [
468
-                'func'       => '_duplicate_attendee',
469
-                'noheader'   => true,
470
-                'capability' => 'ee_edit_contacts',
471
-                'obj_id'     => $ATT_ID,
472
-            ],
473
-            'insert_attendee'                     => [
474
-                'func'       => '_insert_or_update_attendee',
475
-                'args'       => [
476
-                    'new_attendee' => true,
477
-                ],
478
-                'noheader'   => true,
479
-                'capability' => 'ee_edit_contacts',
480
-            ],
481
-            'update_attendee'                     => [
482
-                'func'       => '_insert_or_update_attendee',
483
-                'args'       => [
484
-                    'new_attendee' => false,
485
-                ],
486
-                'noheader'   => true,
487
-                'capability' => 'ee_edit_contacts',
488
-                'obj_id'     => $ATT_ID,
489
-            ],
490
-            'trash_attendees'                     => [
491
-                'func'       => '_trash_or_restore_attendees',
492
-                'args'       => [
493
-                    'trash' => 'true',
494
-                ],
495
-                'noheader'   => true,
496
-                'capability' => 'ee_delete_contacts',
497
-            ],
498
-            'trash_attendee'                      => [
499
-                'func'       => '_trash_or_restore_attendees',
500
-                'args'       => [
501
-                    'trash' => true,
502
-                ],
503
-                'noheader'   => true,
504
-                'capability' => 'ee_delete_contacts',
505
-                'obj_id'     => $ATT_ID,
506
-            ],
507
-            'restore_attendees'                   => [
508
-                'func'       => '_trash_or_restore_attendees',
509
-                'args'       => [
510
-                    'trash' => false,
511
-                ],
512
-                'noheader'   => true,
513
-                'capability' => 'ee_delete_contacts',
514
-                'obj_id'     => $ATT_ID,
515
-            ],
516
-            'resend_registration'                 => [
517
-                'func'       => '_resend_registration',
518
-                'noheader'   => true,
519
-                'capability' => 'ee_send_message',
520
-            ],
521
-            'registrations_report'                => [
522
-                'func'       => '_registrations_report',
523
-                'noheader'   => true,
524
-                'capability' => 'ee_read_registrations',
525
-            ],
526
-            'contact_list_export'                 => [
527
-                'func'       => '_contact_list_export',
528
-                'noheader'   => true,
529
-                'capability' => 'export',
530
-            ],
531
-            'contact_list_report'                 => [
532
-                'func'       => '_contact_list_report',
533
-                'noheader'   => true,
534
-                'capability' => 'ee_read_contacts',
535
-            ],
536
-        ];
537
-    }
538
-
539
-
540
-    protected function _set_page_config()
541
-    {
542
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
-        $this->_page_config = [
545
-            'default'           => [
546
-                'nav'           => [
547
-                    'label' => esc_html__('Overview', 'event_espresso'),
548
-                    'order' => 5,
549
-                ],
550
-                'help_tabs'     => [
551
-                    'registrations_overview_help_tab'                       => [
552
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
-                        'filename' => 'registrations_overview',
554
-                    ],
555
-                    'registrations_overview_table_column_headings_help_tab' => [
556
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
-                        'filename' => 'registrations_overview_table_column_headings',
558
-                    ],
559
-                    'registrations_overview_filters_help_tab'               => [
560
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
-                        'filename' => 'registrations_overview_filters',
562
-                    ],
563
-                    'registrations_overview_views_help_tab'                 => [
564
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
565
-                        'filename' => 'registrations_overview_views',
566
-                    ],
567
-                    'registrations_regoverview_other_help_tab'              => [
568
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
-                        'filename' => 'registrations_overview_other',
570
-                    ],
571
-                ],
572
-                'list_table'    => 'EE_Registrations_List_Table',
573
-                'require_nonce' => false,
574
-            ],
575
-            'view_registration' => [
576
-                'nav'           => [
577
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
578
-                    'order'      => 15,
579
-                    'url'        => $REG_ID
580
-                        ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
581
-                        : $this->_admin_base_url,
582
-                    'persistent' => false,
583
-                ],
584
-                'help_tabs'     => [
585
-                    'registrations_details_help_tab'                    => [
586
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
587
-                        'filename' => 'registrations_details',
588
-                    ],
589
-                    'registrations_details_table_help_tab'              => [
590
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
591
-                        'filename' => 'registrations_details_table',
592
-                    ],
593
-                    'registrations_details_form_answers_help_tab'       => [
594
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
595
-                        'filename' => 'registrations_details_form_answers',
596
-                    ],
597
-                    'registrations_details_registrant_details_help_tab' => [
598
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
599
-                        'filename' => 'registrations_details_registrant_details',
600
-                    ],
601
-                ],
602
-                'metaboxes'     => array_merge(
603
-                    $this->_default_espresso_metaboxes,
604
-                    ['_registration_details_metaboxes']
605
-                ),
606
-                'require_nonce' => false,
607
-            ],
608
-            'new_registration'  => [
609
-                'nav'           => [
610
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
611
-                    'url'        => '#',
612
-                    'order'      => 15,
613
-                    'persistent' => false,
614
-                ],
615
-                'metaboxes'     => $this->_default_espresso_metaboxes,
616
-                'labels'        => [
617
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
618
-                ],
619
-                'require_nonce' => false,
620
-            ],
621
-            'add_new_attendee'  => [
622
-                'nav'           => [
623
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
624
-                    'order'      => 15,
625
-                    'persistent' => false,
626
-                ],
627
-                'metaboxes'     => array_merge(
628
-                    $this->_default_espresso_metaboxes,
629
-                    ['_publish_post_box', 'attendee_editor_metaboxes']
630
-                ),
631
-                'require_nonce' => false,
632
-            ],
633
-            'edit_attendee'     => [
634
-                'nav'           => [
635
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
636
-                    'order'      => 15,
637
-                    'persistent' => false,
638
-                    'url'        => $ATT_ID
639
-                        ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
640
-                        : $this->_admin_base_url,
641
-                ],
642
-                'metaboxes'     => array_merge(
643
-                    $this->_default_espresso_metaboxes,
644
-                    ['attendee_editor_metaboxes']
645
-                ),
646
-                'require_nonce' => false,
647
-            ],
648
-            'contact_list'      => [
649
-                'nav'           => [
650
-                    'label' => esc_html__('Contact List', 'event_espresso'),
651
-                    'order' => 20,
652
-                ],
653
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
654
-                'help_tabs'     => [
655
-                    'registrations_contact_list_help_tab'                       => [
656
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
657
-                        'filename' => 'registrations_contact_list',
658
-                    ],
659
-                    'registrations_contact-list_table_column_headings_help_tab' => [
660
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
661
-                        'filename' => 'registrations_contact_list_table_column_headings',
662
-                    ],
663
-                    'registrations_contact_list_views_help_tab'                 => [
664
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
665
-                        'filename' => 'registrations_contact_list_views',
666
-                    ],
667
-                    'registrations_contact_list_other_help_tab'                 => [
668
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
669
-                        'filename' => 'registrations_contact_list_other',
670
-                    ],
671
-                ],
672
-                'metaboxes'     => [],
673
-                'require_nonce' => false,
674
-            ],
675
-            // override default cpt routes
676
-            'create_new'        => '',
677
-            'edit'              => '',
678
-        ];
679
-    }
680
-
681
-
682
-    /**
683
-     * The below methods aren't used by this class currently
684
-     */
685
-    protected function _add_screen_options()
686
-    {
687
-    }
688
-
689
-
690
-    protected function _add_feature_pointers()
691
-    {
692
-    }
693
-
694
-
695
-    public function admin_init()
696
-    {
697
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
698
-            'click "Update Registration Questions" to save your changes',
699
-            'event_espresso'
700
-        );
701
-    }
702
-
703
-
704
-    public function admin_notices()
705
-    {
706
-    }
707
-
708
-
709
-    public function admin_footer_scripts()
710
-    {
711
-    }
712
-
713
-
714
-    /**
715
-     * get list of registration statuses
716
-     *
717
-     * @return void
718
-     * @throws EE_Error
719
-     */
720
-    private function _get_registration_status_array()
721
-    {
722
-        self::$_reg_status = EEM_Registration::reg_status_array([], true);
723
-    }
724
-
725
-
726
-    /**
727
-     * @throws InvalidArgumentException
728
-     * @throws InvalidDataTypeException
729
-     * @throws InvalidInterfaceException
730
-     * @since 4.10.2.p
731
-     */
732
-    protected function _add_screen_options_default()
733
-    {
734
-        $this->_per_page_screen_option();
735
-    }
736
-
737
-
738
-    /**
739
-     * @throws InvalidArgumentException
740
-     * @throws InvalidDataTypeException
741
-     * @throws InvalidInterfaceException
742
-     * @since 4.10.2.p
743
-     */
744
-    protected function _add_screen_options_contact_list()
745
-    {
746
-        $page_title              = $this->_admin_page_title;
747
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
748
-        $this->_per_page_screen_option();
749
-        $this->_admin_page_title = $page_title;
750
-    }
751
-
752
-
753
-    public function load_scripts_styles()
754
-    {
755
-        // style
756
-        wp_register_style(
757
-            'espresso_reg',
758
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
759
-            ['ee-admin-css'],
760
-            EVENT_ESPRESSO_VERSION
761
-        );
762
-        wp_enqueue_style('espresso_reg');
763
-        // script
764
-        wp_register_script(
765
-            'espresso_reg',
766
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
767
-            ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
768
-            EVENT_ESPRESSO_VERSION,
769
-            true
770
-        );
771
-        wp_enqueue_script('espresso_reg');
772
-    }
773
-
774
-
775
-    /**
776
-     * @throws EE_Error
777
-     * @throws InvalidArgumentException
778
-     * @throws InvalidDataTypeException
779
-     * @throws InvalidInterfaceException
780
-     * @throws ReflectionException
781
-     * @since 4.10.2.p
782
-     */
783
-    public function load_scripts_styles_edit_attendee()
784
-    {
785
-        // stuff to only show up on our attendee edit details page.
786
-        $attendee_details_translations = [
787
-            'att_publish_text' => sprintf(
788
-            /* translators: The date and time */
789
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
790
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
791
-            ),
792
-        ];
793
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
794
-        wp_enqueue_script('jquery-validate');
795
-    }
796
-
797
-
798
-    /**
799
-     * @throws EE_Error
800
-     * @throws InvalidArgumentException
801
-     * @throws InvalidDataTypeException
802
-     * @throws InvalidInterfaceException
803
-     * @throws ReflectionException
804
-     * @since 4.10.2.p
805
-     */
806
-    public function load_scripts_styles_view_registration()
807
-    {
808
-        // styles
809
-        wp_enqueue_style('espresso-ui-theme');
810
-        // scripts
811
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
812
-        $this->_reg_custom_questions_form->wp_enqueue_scripts();
813
-    }
814
-
815
-
816
-    public function load_scripts_styles_contact_list()
817
-    {
818
-        wp_dequeue_style('espresso_reg');
819
-        wp_register_style(
820
-            'espresso_att',
821
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
822
-            ['ee-admin-css'],
823
-            EVENT_ESPRESSO_VERSION
824
-        );
825
-        wp_enqueue_style('espresso_att');
826
-    }
827
-
828
-
829
-    public function load_scripts_styles_new_registration()
830
-    {
831
-        wp_register_script(
832
-            'ee-spco-for-admin',
833
-            REG_ASSETS_URL . 'spco_for_admin.js',
834
-            ['underscore', 'jquery'],
835
-            EVENT_ESPRESSO_VERSION,
836
-            true
837
-        );
838
-        wp_enqueue_script('ee-spco-for-admin');
839
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
840
-        EE_Form_Section_Proper::wp_enqueue_scripts();
841
-        EED_Ticket_Selector::load_tckt_slctr_assets();
842
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
843
-    }
844
-
845
-
846
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
847
-    {
848
-        add_filter('FHEE_load_EE_messages', '__return_true');
849
-    }
850
-
851
-
852
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
853
-    {
854
-        add_filter('FHEE_load_EE_messages', '__return_true');
855
-    }
856
-
857
-
858
-    /**
859
-     * @throws EE_Error
860
-     * @throws InvalidArgumentException
861
-     * @throws InvalidDataTypeException
862
-     * @throws InvalidInterfaceException
863
-     * @throws ReflectionException
864
-     * @since 4.10.2.p
865
-     */
866
-    protected function _set_list_table_views_default()
867
-    {
868
-        // for notification related bulk actions we need to make sure only active messengers have an option.
869
-        EED_Messages::set_autoloaders();
870
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
871
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
872
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
873
-        // key= bulk_action_slug, value= message type.
874
-        $match_array = [
875
-            'approve_registrations'    => 'registration',
876
-            'decline_registrations'    => 'declined_registration',
877
-            'pending_registrations'    => 'pending_approval',
878
-            'no_approve_registrations' => 'not_approved_registration',
879
-            'cancel_registrations'     => 'cancelled_registration',
880
-        ];
881
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
882
-            'ee_send_message',
883
-            'batch_send_messages'
884
-        );
885
-        /** setup reg status bulk actions **/
886
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
887
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
888
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
889
-                'Approve and Notify Registrations',
890
-                'event_espresso'
891
-            );
892
-        }
893
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
894
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
895
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
896
-                'Decline and Notify Registrations',
897
-                'event_espresso'
898
-            );
899
-        }
900
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
901
-            'Set Registrations to Pending Payment',
902
-            'event_espresso'
903
-        );
904
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
905
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
906
-                'Set Registrations to Pending Payment and Notify',
907
-                'event_espresso'
908
-            );
909
-        }
910
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
911
-            'Set Registrations to Not Approved',
912
-            'event_espresso'
913
-        );
914
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
915
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
916
-                'Set Registrations to Not Approved and Notify',
917
-                'event_espresso'
918
-            );
919
-        }
920
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
921
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
922
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
923
-                'Cancel Registrations and Notify',
924
-                'event_espresso'
925
-            );
926
-        }
927
-        $def_reg_status_actions = apply_filters(
928
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
929
-            $def_reg_status_actions,
930
-            $active_mts,
931
-            $can_send
932
-        );
933
-
934
-        $this->_views = [
935
-            'all'   => [
936
-                'slug'        => 'all',
937
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
938
-                'count'       => 0,
939
-                'bulk_action' => array_merge(
940
-                    $def_reg_status_actions,
941
-                    [
942
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
-                    ]
944
-                ),
945
-            ],
946
-            'month' => [
947
-                'slug'        => 'month',
948
-                'label'       => esc_html__('This Month', 'event_espresso'),
949
-                'count'       => 0,
950
-                'bulk_action' => array_merge(
951
-                    $def_reg_status_actions,
952
-                    [
953
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
-                    ]
955
-                ),
956
-            ],
957
-            'today' => [
958
-                'slug'        => 'today',
959
-                'label'       => sprintf(
960
-                    esc_html__('Today - %s', 'event_espresso'),
961
-                    date('M d, Y', current_time('timestamp'))
962
-                ),
963
-                'count'       => 0,
964
-                'bulk_action' => array_merge(
965
-                    $def_reg_status_actions,
966
-                    [
967
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
-                    ]
969
-                ),
970
-            ],
971
-        ];
972
-        if (
973
-            EE_Registry::instance()->CAP->current_user_can(
974
-                'ee_delete_registrations',
975
-                'espresso_registrations_delete_registration'
976
-            )
977
-        ) {
978
-            $this->_views['incomplete'] = [
979
-                'slug'        => 'incomplete',
980
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
981
-                'count'       => 0,
982
-                'bulk_action' => [
983
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
984
-                ],
985
-            ];
986
-            $this->_views['trash']      = [
987
-                'slug'        => 'trash',
988
-                'label'       => esc_html__('Trash', 'event_espresso'),
989
-                'count'       => 0,
990
-                'bulk_action' => [
991
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
992
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
993
-                ],
994
-            ];
995
-        }
996
-    }
997
-
998
-
999
-    protected function _set_list_table_views_contact_list()
1000
-    {
1001
-        $this->_views = [
1002
-            'in_use' => [
1003
-                'slug'        => 'in_use',
1004
-                'label'       => esc_html__('In Use', 'event_espresso'),
1005
-                'count'       => 0,
1006
-                'bulk_action' => [
1007
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1008
-                ],
1009
-            ],
1010
-        ];
1011
-        if (
1012
-            EE_Registry::instance()->CAP->current_user_can(
1013
-                'ee_delete_contacts',
1014
-                'espresso_registrations_trash_attendees'
1015
-            )
1016
-        ) {
1017
-            $this->_views['trash'] = [
1018
-                'slug'        => 'trash',
1019
-                'label'       => esc_html__('Trash', 'event_espresso'),
1020
-                'count'       => 0,
1021
-                'bulk_action' => [
1022
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1023
-                ],
1024
-            ];
1025
-        }
1026
-    }
1027
-
1028
-
1029
-    /**
1030
-     * @return array
1031
-     * @throws EE_Error
1032
-     */
1033
-    protected function _registration_legend_items()
1034
-    {
1035
-        $fc_items = [
1036
-            'star-icon'        => [
1037
-                'class' => 'dashicons dashicons-star-filled gold-icon',
1038
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1039
-            ],
1040
-            'view_details'     => [
1041
-                'class' => 'dashicons dashicons-clipboard',
1042
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1043
-            ],
1044
-            'edit_attendee'    => [
1045
-                'class' => 'dashicons dashicons-admin-users',
1046
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1047
-            ],
1048
-            'view_transaction' => [
1049
-                'class' => 'dashicons dashicons-cart',
1050
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1051
-            ],
1052
-            'view_invoice'     => [
1053
-                'class' => 'dashicons dashicons-media-spreadsheet',
1054
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1055
-            ],
1056
-        ];
1057
-        if (
1058
-            EE_Registry::instance()->CAP->current_user_can(
1059
-                'ee_send_message',
1060
-                'espresso_registrations_resend_registration'
1061
-            )
1062
-        ) {
1063
-            $fc_items['resend_registration'] = [
1064
-                'class' => 'dashicons dashicons-email-alt',
1065
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1066
-            ];
1067
-        } else {
1068
-            $fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1069
-        }
1070
-        if (
1071
-            EE_Registry::instance()->CAP->current_user_can(
1072
-                'ee_read_global_messages',
1073
-                'view_filtered_messages'
1074
-            )
1075
-        ) {
1076
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1077
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1078
-                $fc_items['view_related_messages'] = [
1079
-                    'class' => $related_for_icon['css_class'],
1080
-                    'desc'  => $related_for_icon['label'],
1081
-                ];
1082
-            }
1083
-        }
1084
-        $sc_items = [
1085
-            'approved_status'   => [
1086
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1087
-                'desc'  => EEH_Template::pretty_status(
1088
-                    EEM_Registration::status_id_approved,
1089
-                    false,
1090
-                    'sentence'
1091
-                ),
1092
-            ],
1093
-            'pending_status'    => [
1094
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1095
-                'desc'  => EEH_Template::pretty_status(
1096
-                    EEM_Registration::status_id_pending_payment,
1097
-                    false,
1098
-                    'sentence'
1099
-                ),
1100
-            ],
1101
-            'wait_list'         => [
1102
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1103
-                'desc'  => EEH_Template::pretty_status(
1104
-                    EEM_Registration::status_id_wait_list,
1105
-                    false,
1106
-                    'sentence'
1107
-                ),
1108
-            ],
1109
-            'incomplete_status' => [
1110
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1111
-                'desc'  => EEH_Template::pretty_status(
1112
-                    EEM_Registration::status_id_incomplete,
1113
-                    false,
1114
-                    'sentence'
1115
-                ),
1116
-            ],
1117
-            'not_approved'      => [
1118
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1119
-                'desc'  => EEH_Template::pretty_status(
1120
-                    EEM_Registration::status_id_not_approved,
1121
-                    false,
1122
-                    'sentence'
1123
-                ),
1124
-            ],
1125
-            'declined_status'   => [
1126
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1127
-                'desc'  => EEH_Template::pretty_status(
1128
-                    EEM_Registration::status_id_declined,
1129
-                    false,
1130
-                    'sentence'
1131
-                ),
1132
-            ],
1133
-            'cancelled_status'  => [
1134
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1135
-                'desc'  => EEH_Template::pretty_status(
1136
-                    EEM_Registration::status_id_cancelled,
1137
-                    false,
1138
-                    'sentence'
1139
-                ),
1140
-            ],
1141
-        ];
1142
-        return array_merge($fc_items, $sc_items);
1143
-    }
1144
-
1145
-
1146
-
1147
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1148
-
1149
-
1150
-    /**
1151
-     * @throws DomainException
1152
-     * @throws EE_Error
1153
-     * @throws InvalidArgumentException
1154
-     * @throws InvalidDataTypeException
1155
-     * @throws InvalidInterfaceException
1156
-     */
1157
-    protected function _registrations_overview_list_table()
1158
-    {
1159
-        $this->appendAddNewRegistrationButtonToPageTitle();
1160
-        $header_text                  = '';
1161
-        $admin_page_header_decorators = [
1162
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1163
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1164
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1165
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1166
-        ];
1167
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1168
-            $filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1169
-            $header_text = $filter_header_decorator->getHeaderText($header_text);
1170
-        }
1171
-        $this->_template_args['admin_page_header'] = $header_text;
1172
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1173
-        $this->display_admin_list_table_page_with_no_sidebar();
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * @throws EE_Error
1179
-     * @throws InvalidArgumentException
1180
-     * @throws InvalidDataTypeException
1181
-     * @throws InvalidInterfaceException
1182
-     */
1183
-    private function appendAddNewRegistrationButtonToPageTitle()
1184
-    {
1185
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1186
-        if (
1187
-            $EVT_ID
1188
-            && EE_Registry::instance()->CAP->current_user_can(
1189
-                'ee_edit_registrations',
1190
-                'espresso_registrations_new_registration',
1191
-                $EVT_ID
1192
-            )
1193
-        ) {
1194
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1195
-                'new_registration',
1196
-                'add-registrant',
1197
-                ['event_id' => $EVT_ID],
1198
-                'add-new-h2'
1199
-            );
1200
-        }
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * This sets the _registration property for the registration details screen
1206
-     *
1207
-     * @return void
1208
-     * @throws EE_Error
1209
-     * @throws InvalidArgumentException
1210
-     * @throws InvalidDataTypeException
1211
-     * @throws InvalidInterfaceException
1212
-     */
1213
-    private function _set_registration_object()
1214
-    {
1215
-        // get out if we've already set the object
1216
-        if ($this->_registration instanceof EE_Registration) {
1217
-            return;
1218
-        }
1219
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1220
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1221
-            return;
1222
-        }
1223
-        $error_msg = sprintf(
1224
-            esc_html__(
1225
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1226
-                'event_espresso'
1227
-            ),
1228
-            $REG_ID
1229
-        );
1230
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1231
-        $this->_registration = null;
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     * Used to retrieve registrations for the list table.
1237
-     *
1238
-     * @param int  $per_page
1239
-     * @param bool $count
1240
-     * @param bool $this_month
1241
-     * @param bool $today
1242
-     * @return EE_Registration[]|int
1243
-     * @throws EE_Error
1244
-     * @throws InvalidArgumentException
1245
-     * @throws InvalidDataTypeException
1246
-     * @throws InvalidInterfaceException
1247
-     */
1248
-    public function get_registrations(
1249
-        $per_page = 10,
1250
-        $count = false,
1251
-        $this_month = false,
1252
-        $today = false
1253
-    ) {
1254
-        if ($this_month) {
1255
-            $this->request->setRequestParam('status', 'month');
1256
-        }
1257
-        if ($today) {
1258
-            $this->request->setRequestParam('status', 'today');
1259
-        }
1260
-        $query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1261
-        /**
1262
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1263
-         *
1264
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1265
-         * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1266
-         *                      or if you have the development copy of EE you can view this at the path:
1267
-         *                      /docs/G--Model-System/model-query-params.md
1268
-         */
1269
-        $query_params['group_by'] = '';
1270
-
1271
-        return $count
1272
-            ? $this->getRegistrationModel()->count($query_params)
1273
-            /** @type EE_Registration[] */
1274
-            : $this->getRegistrationModel()->get_all($query_params);
1275
-    }
1276
-
1277
-
1278
-    /**
1279
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1280
-     * Note: this listens to values on the request for some of the query parameters.
1281
-     *
1282
-     * @param array $request
1283
-     * @param int   $per_page
1284
-     * @param bool  $count
1285
-     * @return array
1286
-     * @throws EE_Error
1287
-     * @throws InvalidArgumentException
1288
-     * @throws InvalidDataTypeException
1289
-     * @throws InvalidInterfaceException
1290
-     */
1291
-    protected function _get_registration_query_parameters(
1292
-        $request = [],
1293
-        $per_page = 10,
1294
-        $count = false
1295
-    ) {
1296
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1297
-        $list_table_query_builder = $this->loader->getNew(
1298
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1299
-            [null, null, $request]
1300
-        );
1301
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1302
-    }
1303
-
1304
-
1305
-    public function get_registration_status_array()
1306
-    {
1307
-        return self::$_reg_status;
1308
-    }
1309
-
1310
-
1311
-
1312
-
1313
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1314
-    /**
1315
-     * generates HTML for the View Registration Details Admin page
1316
-     *
1317
-     * @return void
1318
-     * @throws DomainException
1319
-     * @throws EE_Error
1320
-     * @throws InvalidArgumentException
1321
-     * @throws InvalidDataTypeException
1322
-     * @throws InvalidInterfaceException
1323
-     * @throws EntityNotFoundException
1324
-     * @throws ReflectionException
1325
-     */
1326
-    protected function _registration_details()
1327
-    {
1328
-        $this->_template_args = [];
1329
-        $this->_set_registration_object();
1330
-        if (is_object($this->_registration)) {
1331
-            $transaction                                   = $this->_registration->transaction()
1332
-                ? $this->_registration->transaction()
1333
-                : EE_Transaction::new_instance();
1334
-            $this->_session                                = $transaction->session_data();
1335
-            $event_id                                      = $this->_registration->event_ID();
1336
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1337
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1338
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1339
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1340
-            $this->_template_args['grand_total']           = $transaction->total();
1341
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1342
-            // link back to overview
1343
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1344
-            $this->_template_args['registration']                = $this->_registration;
1345
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1346
-                [
1347
-                    'action'   => 'default',
1348
-                    'event_id' => $event_id,
1349
-                ],
1350
-                REG_ADMIN_URL
1351
-            );
1352
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1353
-                [
1354
-                    'action' => 'default',
1355
-                    'EVT_ID' => $event_id,
1356
-                    'page'   => 'espresso_transactions',
1357
-                ],
1358
-                admin_url('admin.php')
1359
-            );
1360
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1361
-                [
1362
-                    'page'   => 'espresso_events',
1363
-                    'action' => 'edit',
1364
-                    'post'   => $event_id,
1365
-                ],
1366
-                admin_url('admin.php')
1367
-            );
1368
-            // next and previous links
1369
-            $next_reg                                      = $this->_registration->next(
1370
-                null,
1371
-                [],
1372
-                'REG_ID'
1373
-            );
1374
-            $this->_template_args['next_registration']     = $next_reg
1375
-                ? $this->_next_link(
1376
-                    EE_Admin_Page::add_query_args_and_nonce(
1377
-                        [
1378
-                            'action'  => 'view_registration',
1379
-                            '_REG_ID' => $next_reg['REG_ID'],
1380
-                        ],
1381
-                        REG_ADMIN_URL
1382
-                    ),
1383
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1384
-                )
1385
-                : '';
1386
-            $previous_reg                                  = $this->_registration->previous(
1387
-                null,
1388
-                [],
1389
-                'REG_ID'
1390
-            );
1391
-            $this->_template_args['previous_registration'] = $previous_reg
1392
-                ? $this->_previous_link(
1393
-                    EE_Admin_Page::add_query_args_and_nonce(
1394
-                        [
1395
-                            'action'  => 'view_registration',
1396
-                            '_REG_ID' => $previous_reg['REG_ID'],
1397
-                        ],
1398
-                        REG_ADMIN_URL
1399
-                    ),
1400
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1401
-                )
1402
-                : '';
1403
-            // grab header
1404
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1405
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1406
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1407
-                $template_path,
1408
-                $this->_template_args,
1409
-                true
1410
-            );
1411
-        } else {
1412
-            $this->_template_args['admin_page_header'] = '';
1413
-            $this->_display_espresso_notices();
1414
-        }
1415
-        // the details template wrapper
1416
-        $this->display_admin_page_with_sidebar();
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     * @throws EE_Error
1422
-     * @throws InvalidArgumentException
1423
-     * @throws InvalidDataTypeException
1424
-     * @throws InvalidInterfaceException
1425
-     * @throws ReflectionException
1426
-     * @since 4.10.2.p
1427
-     */
1428
-    protected function _registration_details_metaboxes()
1429
-    {
1430
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1431
-        $this->_set_registration_object();
1432
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1433
-        $this->addMetaBox(
1434
-            'edit-reg-status-mbox',
1435
-            esc_html__('Registration Status', 'event_espresso'),
1436
-            [$this, 'set_reg_status_buttons_metabox'],
1437
-            $this->_wp_page_slug
1438
-        );
1439
-        $this->addMetaBox(
1440
-            'edit-reg-details-mbox',
1441
-            '<span>' . esc_html__('Registration Details', 'event_espresso')
1442
-            . '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1443
-            [$this, '_reg_details_meta_box'],
1444
-            $this->_wp_page_slug
1445
-        );
1446
-        if (
1447
-            $attendee instanceof EE_Attendee
1448
-            && EE_Registry::instance()->CAP->current_user_can(
1449
-                'ee_read_registration',
1450
-                'edit-reg-questions-mbox',
1451
-                $this->_registration->ID()
1452
-            )
1453
-        ) {
1454
-            $this->addMetaBox(
1455
-                $this->_wp_page_slug,
1456
-                'edit-reg-questions-mbox',
1457
-                esc_html__('Registration Form Answers', 'event_espresso'),
1458
-                [$this, '_reg_questions_meta_box'],
1459
-                $this->_wp_page_slug
1460
-            );
1461
-        }
1462
-        $this->addMetaBox(
1463
-            'edit-reg-registrant-mbox',
1464
-            esc_html__('Contact Details', 'event_espresso'),
1465
-            [$this, '_reg_registrant_side_meta_box'],
1466
-            $this->_wp_page_slug,
1467
-            'side'
1468
-        );
1469
-        if ($this->_registration->group_size() > 1) {
1470
-            $this->addMetaBox(
1471
-                'edit-reg-attendees-mbox',
1472
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1473
-                [$this, '_reg_attendees_meta_box'],
1474
-                $this->_wp_page_slug
1475
-            );
1476
-        }
1477
-    }
1478
-
1479
-
1480
-    /**
1481
-     * set_reg_status_buttons_metabox
1482
-     *
1483
-     * @return void
1484
-     * @throws EE_Error
1485
-     * @throws EntityNotFoundException
1486
-     * @throws InvalidArgumentException
1487
-     * @throws InvalidDataTypeException
1488
-     * @throws InvalidInterfaceException
1489
-     * @throws ReflectionException
1490
-     */
1491
-    public function set_reg_status_buttons_metabox()
1492
-    {
1493
-        $this->_set_registration_object();
1494
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1495
-        $output                 = $change_reg_status_form->form_open(
1496
-            self::add_query_args_and_nonce(
1497
-                [
1498
-                    'action' => 'change_reg_status',
1499
-                ],
1500
-                REG_ADMIN_URL
1501
-            )
1502
-        );
1503
-        $output                 .= $change_reg_status_form->get_html();
1504
-        $output                 .= $change_reg_status_form->form_close();
1505
-        echo wp_kses($output, AllowedTags::getWithFormTags());
1506
-    }
1507
-
1508
-
1509
-    /**
1510
-     * @return EE_Form_Section_Proper
1511
-     * @throws EE_Error
1512
-     * @throws InvalidArgumentException
1513
-     * @throws InvalidDataTypeException
1514
-     * @throws InvalidInterfaceException
1515
-     * @throws EntityNotFoundException
1516
-     * @throws ReflectionException
1517
-     */
1518
-    protected function _generate_reg_status_change_form()
1519
-    {
1520
-        $reg_status_change_form_array = [
1521
-            'name'            => 'reg_status_change_form',
1522
-            'html_id'         => 'reg-status-change-form',
1523
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1524
-            'subsections'     => [
1525
-                'return'         => new EE_Hidden_Input(
1526
-                    [
1527
-                        'name'    => 'return',
1528
-                        'default' => 'view_registration',
1529
-                    ]
1530
-                ),
1531
-                'REG_ID'         => new EE_Hidden_Input(
1532
-                    [
1533
-                        'name'    => 'REG_ID',
1534
-                        'default' => $this->_registration->ID(),
1535
-                    ]
1536
-                ),
1537
-            ],
1538
-        ];
1539
-        if (
1540
-            EE_Registry::instance()->CAP->current_user_can(
1541
-                'ee_edit_registration',
1542
-                'toggle_registration_status',
1543
-                $this->_registration->ID()
1544
-            )
1545
-        ) {
1546
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1547
-                $this->_get_reg_statuses(),
1548
-                [
1549
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1550
-                    'default'         => $this->_registration->status_ID(),
1551
-                ]
1552
-            );
1553
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1554
-                [
1555
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1556
-                    'default'         => false,
1557
-                    'html_help_text'  => esc_html__(
1558
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1559
-                        'event_espresso'
1560
-                    ),
1561
-                ]
1562
-            );
1563
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1564
-                [
1565
-                    'html_class'      => 'button--primary',
1566
-                    'html_label_text' => '&nbsp;',
1567
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1568
-                ]
1569
-            );
1570
-        }
1571
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1572
-    }
1573
-
1574
-
1575
-    /**
1576
-     * Returns an array of all the buttons for the various statuses and switch status actions
1577
-     *
1578
-     * @return array
1579
-     * @throws EE_Error
1580
-     * @throws InvalidArgumentException
1581
-     * @throws InvalidDataTypeException
1582
-     * @throws InvalidInterfaceException
1583
-     * @throws EntityNotFoundException
1584
-     */
1585
-    protected function _get_reg_statuses()
1586
-    {
1587
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1588
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1589
-        // get current reg status
1590
-        $current_status = $this->_registration->status_ID();
1591
-        // is registration for free event? This will determine whether to display the pending payment option
1592
-        if (
1593
-            $current_status !== EEM_Registration::status_id_pending_payment
1594
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1595
-        ) {
1596
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1597
-        }
1598
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1599
-    }
1600
-
1601
-
1602
-    /**
1603
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1604
-     *
1605
-     * @param bool $status REG status given for changing registrations to.
1606
-     * @param bool $notify Whether to send messages notifications or not.
1607
-     * @return array (array with reg_id(s) updated and whether update was successful.
1608
-     * @throws DomainException
1609
-     * @throws EE_Error
1610
-     * @throws EntityNotFoundException
1611
-     * @throws InvalidArgumentException
1612
-     * @throws InvalidDataTypeException
1613
-     * @throws InvalidInterfaceException
1614
-     * @throws ReflectionException
1615
-     * @throws RuntimeException
1616
-     */
1617
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1618
-    {
1619
-        $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1620
-            ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1621
-            : $this->request->getRequestParam('_REG_ID', [], 'int', true);
1622
-
1623
-        // sanitize $REG_IDs
1624
-        $REG_IDs = array_map('absint', $REG_IDs);
1625
-        // and remove empty entries
1626
-        $REG_IDs = array_filter($REG_IDs);
1627
-
1628
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1629
-
1630
-        /**
1631
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1632
-         * Currently this value is used downstream by the _process_resend_registration method.
1633
-         *
1634
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1635
-         * @param bool                     $status           The status registrations were changed to.
1636
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1637
-         * @param Registrations_Admin_Page $admin_page_object
1638
-         */
1639
-        $REG_ID = apply_filters(
1640
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1641
-            $result['REG_ID'],
1642
-            $status,
1643
-            $result['success'],
1644
-            $this
1645
-        );
1646
-        $this->request->setRequestParam('_REG_ID', $REG_ID);
1647
-
1648
-        // notify?
1649
-        if (
1650
-            $notify
1651
-            && $result['success']
1652
-            && ! empty($REG_ID)
1653
-            && EE_Registry::instance()->CAP->current_user_can(
1654
-                'ee_send_message',
1655
-                'espresso_registrations_resend_registration'
1656
-            )
1657
-        ) {
1658
-            $this->_process_resend_registration();
1659
-        }
1660
-        return $result;
1661
-    }
1662
-
1663
-
1664
-    /**
1665
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1666
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1667
-     *
1668
-     * @param array  $REG_IDs
1669
-     * @param string $status
1670
-     * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1671
-     *                       slug sent with setting the registration status.
1672
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1673
-     * @throws EE_Error
1674
-     * @throws InvalidArgumentException
1675
-     * @throws InvalidDataTypeException
1676
-     * @throws InvalidInterfaceException
1677
-     * @throws ReflectionException
1678
-     * @throws RuntimeException
1679
-     * @throws EntityNotFoundException
1680
-     * @throws DomainException
1681
-     */
1682
-    protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1683
-    {
1684
-        $success = false;
1685
-        // typecast $REG_IDs
1686
-        $REG_IDs = (array) $REG_IDs;
1687
-        if (! empty($REG_IDs)) {
1688
-            $success = true;
1689
-            // set default status if none is passed
1690
-            $status         = $status ?: EEM_Registration::status_id_pending_payment;
1691
-            $status_context = $notify
1692
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1693
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1694
-            // loop through REG_ID's and change status
1695
-            foreach ($REG_IDs as $REG_ID) {
1696
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1697
-                if ($registration instanceof EE_Registration) {
1698
-                    $registration->set_status(
1699
-                        $status,
1700
-                        false,
1701
-                        new Context(
1702
-                            $status_context,
1703
-                            esc_html__(
1704
-                                'Manually triggered status change on a Registration Admin Page route.',
1705
-                                'event_espresso'
1706
-                            )
1707
-                        )
1708
-                    );
1709
-                    $result = $registration->save();
1710
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1711
-                    $success = $result !== false ? $success : false;
1712
-                }
1713
-            }
1714
-        }
1715
-
1716
-        // return $success and processed registrations
1717
-        return ['REG_ID' => $REG_IDs, 'success' => $success];
1718
-    }
1719
-
1720
-
1721
-    /**
1722
-     * Common logic for setting up success message and redirecting to appropriate route
1723
-     *
1724
-     * @param string $STS_ID status id for the registration changed to
1725
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1726
-     * @return void
1727
-     * @throws DomainException
1728
-     * @throws EE_Error
1729
-     * @throws EntityNotFoundException
1730
-     * @throws InvalidArgumentException
1731
-     * @throws InvalidDataTypeException
1732
-     * @throws InvalidInterfaceException
1733
-     * @throws ReflectionException
1734
-     * @throws RuntimeException
1735
-     */
1736
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1737
-    {
1738
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1739
-            : ['success' => false];
1740
-        $success = isset($result['success']) && $result['success'];
1741
-        // setup success message
1742
-        if ($success) {
1743
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1744
-                $msg = sprintf(
1745
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1746
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1747
-                );
1748
-            } else {
1749
-                $msg = sprintf(
1750
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1751
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1752
-                );
1753
-            }
1754
-            EE_Error::add_success($msg);
1755
-        } else {
1756
-            EE_Error::add_error(
1757
-                esc_html__(
1758
-                    'Something went wrong, and the status was not changed',
1759
-                    'event_espresso'
1760
-                ),
1761
-                __FILE__,
1762
-                __LINE__,
1763
-                __FUNCTION__
1764
-            );
1765
-        }
1766
-        $return = $this->request->getRequestParam('return');
1767
-        $route  = $return === 'view_registration'
1768
-            ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1769
-            : ['action' => 'default'];
1770
-        $route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1771
-        $this->_redirect_after_action($success, '', '', $route, true);
1772
-    }
1773
-
1774
-
1775
-    /**
1776
-     * incoming reg status change from reg details page.
1777
-     *
1778
-     * @return void
1779
-     * @throws EE_Error
1780
-     * @throws EntityNotFoundException
1781
-     * @throws InvalidArgumentException
1782
-     * @throws InvalidDataTypeException
1783
-     * @throws InvalidInterfaceException
1784
-     * @throws ReflectionException
1785
-     * @throws RuntimeException
1786
-     * @throws DomainException
1787
-     */
1788
-    protected function _change_reg_status()
1789
-    {
1790
-        $this->request->setRequestParam('return', 'view_registration');
1791
-        // set notify based on whether the send notifications toggle is set or not
1792
-        $notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1793
-        $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1794
-        $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1795
-        switch ($reg_status) {
1796
-            case EEM_Registration::status_id_approved:
1797
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1798
-                $this->approve_registration($notify);
1799
-                break;
1800
-            case EEM_Registration::status_id_pending_payment:
1801
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1802
-                $this->pending_registration($notify);
1803
-                break;
1804
-            case EEM_Registration::status_id_not_approved:
1805
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1806
-                $this->not_approve_registration($notify);
1807
-                break;
1808
-            case EEM_Registration::status_id_declined:
1809
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1810
-                $this->decline_registration($notify);
1811
-                break;
1812
-            case EEM_Registration::status_id_cancelled:
1813
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1814
-                $this->cancel_registration($notify);
1815
-                break;
1816
-            case EEM_Registration::status_id_wait_list:
1817
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1818
-                $this->wait_list_registration($notify);
1819
-                break;
1820
-            case EEM_Registration::status_id_incomplete:
1821
-            default:
1822
-                $this->request->unSetRequestParam('return');
1823
-                $this->_reg_status_change_return('');
1824
-                break;
1825
-        }
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * Callback for bulk action routes.
1831
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1832
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1833
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1834
-     * when an action is happening on just a single registration).
1835
-     *
1836
-     * @param      $action
1837
-     * @param bool $notify
1838
-     */
1839
-    protected function bulk_action_on_registrations($action, $notify = false)
1840
-    {
1841
-        do_action(
1842
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1843
-            $this,
1844
-            $action,
1845
-            $notify
1846
-        );
1847
-        $method = $action . '_registration';
1848
-        if (method_exists($this, $method)) {
1849
-            $this->$method($notify);
1850
-        }
1851
-    }
1852
-
1853
-
1854
-    /**
1855
-     * approve_registration
1856
-     *
1857
-     * @param bool $notify whether or not to notify the registrant about their approval.
1858
-     * @return void
1859
-     * @throws EE_Error
1860
-     * @throws EntityNotFoundException
1861
-     * @throws InvalidArgumentException
1862
-     * @throws InvalidDataTypeException
1863
-     * @throws InvalidInterfaceException
1864
-     * @throws ReflectionException
1865
-     * @throws RuntimeException
1866
-     * @throws DomainException
1867
-     */
1868
-    protected function approve_registration($notify = false)
1869
-    {
1870
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     * decline_registration
1876
-     *
1877
-     * @param bool $notify whether or not to notify the registrant about their status change.
1878
-     * @return void
1879
-     * @throws EE_Error
1880
-     * @throws EntityNotFoundException
1881
-     * @throws InvalidArgumentException
1882
-     * @throws InvalidDataTypeException
1883
-     * @throws InvalidInterfaceException
1884
-     * @throws ReflectionException
1885
-     * @throws RuntimeException
1886
-     * @throws DomainException
1887
-     */
1888
-    protected function decline_registration($notify = false)
1889
-    {
1890
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1891
-    }
1892
-
1893
-
1894
-    /**
1895
-     * cancel_registration
1896
-     *
1897
-     * @param bool $notify whether or not to notify the registrant about their status change.
1898
-     * @return void
1899
-     * @throws EE_Error
1900
-     * @throws EntityNotFoundException
1901
-     * @throws InvalidArgumentException
1902
-     * @throws InvalidDataTypeException
1903
-     * @throws InvalidInterfaceException
1904
-     * @throws ReflectionException
1905
-     * @throws RuntimeException
1906
-     * @throws DomainException
1907
-     */
1908
-    protected function cancel_registration($notify = false)
1909
-    {
1910
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1911
-    }
1912
-
1913
-
1914
-    /**
1915
-     * not_approve_registration
1916
-     *
1917
-     * @param bool $notify whether or not to notify the registrant about their status change.
1918
-     * @return void
1919
-     * @throws EE_Error
1920
-     * @throws EntityNotFoundException
1921
-     * @throws InvalidArgumentException
1922
-     * @throws InvalidDataTypeException
1923
-     * @throws InvalidInterfaceException
1924
-     * @throws ReflectionException
1925
-     * @throws RuntimeException
1926
-     * @throws DomainException
1927
-     */
1928
-    protected function not_approve_registration($notify = false)
1929
-    {
1930
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1931
-    }
1932
-
1933
-
1934
-    /**
1935
-     * decline_registration
1936
-     *
1937
-     * @param bool $notify whether or not to notify the registrant about their status change.
1938
-     * @return void
1939
-     * @throws EE_Error
1940
-     * @throws EntityNotFoundException
1941
-     * @throws InvalidArgumentException
1942
-     * @throws InvalidDataTypeException
1943
-     * @throws InvalidInterfaceException
1944
-     * @throws ReflectionException
1945
-     * @throws RuntimeException
1946
-     * @throws DomainException
1947
-     */
1948
-    protected function pending_registration($notify = false)
1949
-    {
1950
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1951
-    }
1952
-
1953
-
1954
-    /**
1955
-     * waitlist_registration
1956
-     *
1957
-     * @param bool $notify whether or not to notify the registrant about their status change.
1958
-     * @return void
1959
-     * @throws EE_Error
1960
-     * @throws EntityNotFoundException
1961
-     * @throws InvalidArgumentException
1962
-     * @throws InvalidDataTypeException
1963
-     * @throws InvalidInterfaceException
1964
-     * @throws ReflectionException
1965
-     * @throws RuntimeException
1966
-     * @throws DomainException
1967
-     */
1968
-    protected function wait_list_registration($notify = false)
1969
-    {
1970
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1971
-    }
1972
-
1973
-
1974
-    /**
1975
-     * generates HTML for the Registration main meta box
1976
-     *
1977
-     * @return void
1978
-     * @throws DomainException
1979
-     * @throws EE_Error
1980
-     * @throws InvalidArgumentException
1981
-     * @throws InvalidDataTypeException
1982
-     * @throws InvalidInterfaceException
1983
-     * @throws ReflectionException
1984
-     * @throws EntityNotFoundException
1985
-     */
1986
-    public function _reg_details_meta_box()
1987
-    {
1988
-        EEH_Autoloader::register_line_item_display_autoloaders();
1989
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1990
-        EE_Registry::instance()->load_helper('Line_Item');
1991
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1992
-            : EE_Transaction::new_instance();
1993
-        $this->_session = $transaction->session_data();
1994
-        $filters        = new EE_Line_Item_Filter_Collection();
1995
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1996
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
1997
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
1998
-            $filters,
1999
-            $transaction->total_line_item()
2000
-        );
2001
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2002
-        $line_item_display                       = new EE_Line_Item_Display(
2003
-            'reg_admin_table',
2004
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2005
-        );
2006
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2007
-            $filtered_line_item_tree,
2008
-            ['EE_Registration' => $this->_registration]
2009
-        );
2010
-        $attendee                                = $this->_registration->attendee();
2011
-        if (
2012
-            EE_Registry::instance()->CAP->current_user_can(
2013
-                'ee_read_transaction',
2014
-                'espresso_transactions_view_transaction'
2015
-            )
2016
-        ) {
2017
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2018
-                EE_Admin_Page::add_query_args_and_nonce(
2019
-                    [
2020
-                        'action' => 'view_transaction',
2021
-                        'TXN_ID' => $transaction->ID(),
2022
-                    ],
2023
-                    TXN_ADMIN_URL
2024
-                ),
2025
-                esc_html__(' View Transaction', 'event_espresso'),
2026
-                'button button--secondary right',
2027
-                'dashicons dashicons-cart'
2028
-            );
2029
-        } else {
2030
-            $this->_template_args['view_transaction_button'] = '';
2031
-        }
2032
-        if (
2033
-            $attendee instanceof EE_Attendee
2034
-            && EE_Registry::instance()->CAP->current_user_can(
2035
-                'ee_send_message',
2036
-                'espresso_registrations_resend_registration'
2037
-            )
2038
-        ) {
2039
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2040
-                EE_Admin_Page::add_query_args_and_nonce(
2041
-                    [
2042
-                        'action'      => 'resend_registration',
2043
-                        '_REG_ID'     => $this->_registration->ID(),
2044
-                        'redirect_to' => 'view_registration',
2045
-                    ],
2046
-                    REG_ADMIN_URL
2047
-                ),
2048
-                esc_html__(' Resend Registration', 'event_espresso'),
2049
-                'button button--secondary right',
2050
-                'dashicons dashicons-email-alt'
2051
-            );
2052
-        } else {
2053
-            $this->_template_args['resend_registration_button'] = '';
2054
-        }
2055
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2056
-        $payment                               = $transaction->get_first_related('Payment');
2057
-        $payment                               = ! $payment instanceof EE_Payment
2058
-            ? EE_Payment::new_instance()
2059
-            : $payment;
2060
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2061
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2062
-            ? EE_Payment_Method::new_instance()
2063
-            : $payment_method;
2064
-        $reg_details                           = [
2065
-            'payment_method'       => $payment_method->name(),
2066
-            'response_msg'         => $payment->gateway_response(),
2067
-            'registration_id'      => $this->_registration->get('REG_code'),
2068
-            'registration_session' => $this->_registration->session_ID(),
2069
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2070
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2071
-        ];
2072
-        if (isset($reg_details['registration_id'])) {
2073
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2074
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2075
-                'Registration ID',
2076
-                'event_espresso'
2077
-            );
2078
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2079
-        }
2080
-        if (isset($reg_details['payment_method'])) {
2081
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2082
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2083
-                'Most Recent Payment Method',
2084
-                'event_espresso'
2085
-            );
2086
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2087
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2088
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2089
-                'Payment method response',
2090
-                'event_espresso'
2091
-            );
2092
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2093
-        }
2094
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2095
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2096
-            'Registration Session',
2097
-            'event_espresso'
2098
-        );
2099
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2100
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2101
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2102
-            'Registration placed from IP',
2103
-            'event_espresso'
2104
-        );
2105
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2106
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2107
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2108
-            'Registrant User Agent',
2109
-            'event_espresso'
2110
-        );
2111
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2112
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2113
-            [
2114
-                'action'   => 'default',
2115
-                'event_id' => $this->_registration->event_ID(),
2116
-            ],
2117
-            REG_ADMIN_URL
2118
-        );
2119
-
2120
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2121
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2122
-
2123
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2124
-        EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2125
-    }
2126
-
2127
-
2128
-    /**
2129
-     * generates HTML for the Registration Questions meta box.
2130
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2131
-     * otherwise uses new forms system
2132
-     *
2133
-     * @return void
2134
-     * @throws DomainException
2135
-     * @throws EE_Error
2136
-     * @throws InvalidArgumentException
2137
-     * @throws InvalidDataTypeException
2138
-     * @throws InvalidInterfaceException
2139
-     * @throws ReflectionException
2140
-     */
2141
-    public function _reg_questions_meta_box()
2142
-    {
2143
-        // allow someone to override this method entirely
2144
-        if (
2145
-            apply_filters(
2146
-                'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2147
-                true,
2148
-                $this,
2149
-                $this->_registration
2150
-            )
2151
-        ) {
2152
-            $form = $this->_get_reg_custom_questions_form(
2153
-                $this->_registration->ID()
2154
-            );
2155
-
2156
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2157
-                ? $form->get_html_and_js()
2158
-                : '';
2159
-
2160
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2161
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2162
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2163
-            EEH_Template::display_template($template_path, $this->_template_args);
2164
-        }
2165
-    }
2166
-
2167
-
2168
-    /**
2169
-     * form_before_question_group
2170
-     *
2171
-     * @param string $output
2172
-     * @return        string
2173
-     * @deprecated    as of 4.8.32.rc.000
2174
-     */
2175
-    public function form_before_question_group($output)
2176
-    {
2177
-        EE_Error::doing_it_wrong(
2178
-            __CLASS__ . '::' . __FUNCTION__,
2179
-            esc_html__(
2180
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2181
-                'event_espresso'
2182
-            ),
2183
-            '4.8.32.rc.000'
2184
-        );
2185
-        return '
22
+	/**
23
+	 * @var EE_Registration
24
+	 */
25
+	private $_registration;
26
+
27
+	/**
28
+	 * @var EE_Event
29
+	 */
30
+	private $_reg_event;
31
+
32
+	/**
33
+	 * @var EE_Session
34
+	 */
35
+	private $_session;
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	private static $_reg_status;
41
+
42
+	/**
43
+	 * Form for displaying the custom questions for this registration.
44
+	 * This gets used a few times throughout the request so its best to cache it
45
+	 *
46
+	 * @var EE_Registration_Custom_Questions_Form
47
+	 */
48
+	protected $_reg_custom_questions_form;
49
+
50
+	/**
51
+	 * @var EEM_Registration $registration_model
52
+	 */
53
+	private $registration_model;
54
+
55
+	/**
56
+	 * @var EEM_Attendee $attendee_model
57
+	 */
58
+	private $attendee_model;
59
+
60
+	/**
61
+	 * @var EEM_Event $event_model
62
+	 */
63
+	private $event_model;
64
+
65
+	/**
66
+	 * @var EEM_Status $status_model
67
+	 */
68
+	private $status_model;
69
+
70
+
71
+	/**
72
+	 * @param bool $routing
73
+	 * @throws EE_Error
74
+	 * @throws InvalidArgumentException
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws ReflectionException
78
+	 */
79
+	public function __construct($routing = true)
80
+	{
81
+		parent::__construct($routing);
82
+		add_action('wp_loaded', [$this, 'wp_loaded']);
83
+	}
84
+
85
+
86
+	/**
87
+	 * @return EEM_Registration
88
+	 * @throws InvalidArgumentException
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 * @since 4.10.2.p
92
+	 */
93
+	protected function getRegistrationModel()
94
+	{
95
+		if (! $this->registration_model instanceof EEM_Registration) {
96
+			$this->registration_model = $this->loader->getShared('EEM_Registration');
97
+		}
98
+		return $this->registration_model;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return EEM_Attendee
104
+	 * @throws InvalidArgumentException
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 * @since 4.10.2.p
108
+	 */
109
+	protected function getAttendeeModel()
110
+	{
111
+		if (! $this->attendee_model instanceof EEM_Attendee) {
112
+			$this->attendee_model = $this->loader->getShared('EEM_Attendee');
113
+		}
114
+		return $this->attendee_model;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return EEM_Event
120
+	 * @throws InvalidArgumentException
121
+	 * @throws InvalidDataTypeException
122
+	 * @throws InvalidInterfaceException
123
+	 * @since 4.10.2.p
124
+	 */
125
+	protected function getEventModel()
126
+	{
127
+		if (! $this->event_model instanceof EEM_Event) {
128
+			$this->event_model = $this->loader->getShared('EEM_Event');
129
+		}
130
+		return $this->event_model;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return EEM_Status
136
+	 * @throws InvalidArgumentException
137
+	 * @throws InvalidDataTypeException
138
+	 * @throws InvalidInterfaceException
139
+	 * @since 4.10.2.p
140
+	 */
141
+	protected function getStatusModel()
142
+	{
143
+		if (! $this->status_model instanceof EEM_Status) {
144
+			$this->status_model = $this->loader->getShared('EEM_Status');
145
+		}
146
+		return $this->status_model;
147
+	}
148
+
149
+
150
+	public function wp_loaded()
151
+	{
152
+		// when adding a new registration...
153
+		$action = $this->request->getRequestParam('action');
154
+		if ($action === 'new_registration') {
155
+			EE_System::do_not_cache();
156
+			if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
+				// and it's NOT the attendee information reg step
158
+				// force cookie expiration by setting time to last week
159
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
+				// and update the global
161
+				$_COOKIE['ee_registration_added'] = 0;
162
+			}
163
+		}
164
+	}
165
+
166
+
167
+	protected function _init_page_props()
168
+	{
169
+		$this->page_slug        = REG_PG_SLUG;
170
+		$this->_admin_base_url  = REG_ADMIN_URL;
171
+		$this->_admin_base_path = REG_ADMIN;
172
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
173
+		$this->_cpt_routes      = [
174
+			'add_new_attendee' => 'espresso_attendees',
175
+			'edit_attendee'    => 'espresso_attendees',
176
+			'insert_attendee'  => 'espresso_attendees',
177
+			'update_attendee'  => 'espresso_attendees',
178
+		];
179
+		$this->_cpt_model_names = [
180
+			'add_new_attendee' => 'EEM_Attendee',
181
+			'edit_attendee'    => 'EEM_Attendee',
182
+		];
183
+		$this->_cpt_edit_routes = [
184
+			'espresso_attendees' => 'edit_attendee',
185
+		];
186
+		$this->_pagenow_map     = [
187
+			'add_new_attendee' => 'post-new.php',
188
+			'edit_attendee'    => 'post.php',
189
+			'trash'            => 'post.php',
190
+		];
191
+		add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
+		// add filters so that the comment urls don't take users to a confusing 404 page
193
+		add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param string     $link    The comment permalink with '#comment-$id' appended.
199
+	 * @param WP_Comment $comment The current comment object.
200
+	 * @return string
201
+	 */
202
+	public function clear_comment_link($link, WP_Comment $comment)
203
+	{
204
+		// gotta make sure this only happens on this route
205
+		$post_type = get_post_type($comment->comment_post_ID);
206
+		if ($post_type === 'espresso_attendees') {
207
+			return '#commentsdiv';
208
+		}
209
+		return $link;
210
+	}
211
+
212
+
213
+	protected function _ajax_hooks()
214
+	{
215
+		// todo: all hooks for registrations ajax goes in here
216
+		add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
+	}
218
+
219
+
220
+	protected function _define_page_props()
221
+	{
222
+		$this->_admin_page_title = $this->page_label;
223
+		$this->_labels           = [
224
+			'buttons'                      => [
225
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
+			],
234
+			'publishbox'                   => [
235
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
+			],
238
+			'hide_add_button_on_cpt_route' => [
239
+				'edit_attendee' => true,
240
+			],
241
+		];
242
+	}
243
+
244
+
245
+	/**
246
+	 * grab url requests and route them
247
+	 *
248
+	 * @return void
249
+	 * @throws EE_Error
250
+	 */
251
+	public function _set_page_routes()
252
+	{
253
+		$this->_get_registration_status_array();
254
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
+		$REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
+		$ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
+		$this->_page_routes = [
259
+			'default'                             => [
260
+				'func'       => '_registrations_overview_list_table',
261
+				'capability' => 'ee_read_registrations',
262
+			],
263
+			'view_registration'                   => [
264
+				'func'       => '_registration_details',
265
+				'capability' => 'ee_read_registration',
266
+				'obj_id'     => $REG_ID,
267
+			],
268
+			'edit_registration'                   => [
269
+				'func'               => '_update_attendee_registration_form',
270
+				'noheader'           => true,
271
+				'headers_sent_route' => 'view_registration',
272
+				'capability'         => 'ee_edit_registration',
273
+				'obj_id'             => $REG_ID,
274
+				'_REG_ID'            => $REG_ID,
275
+			],
276
+			'trash_registrations'                 => [
277
+				'func'       => '_trash_or_restore_registrations',
278
+				'args'       => ['trash' => true],
279
+				'noheader'   => true,
280
+				'capability' => 'ee_delete_registrations',
281
+			],
282
+			'restore_registrations'               => [
283
+				'func'       => '_trash_or_restore_registrations',
284
+				'args'       => ['trash' => false],
285
+				'noheader'   => true,
286
+				'capability' => 'ee_delete_registrations',
287
+			],
288
+			'delete_registrations'                => [
289
+				'func'       => '_delete_registrations',
290
+				'noheader'   => true,
291
+				'capability' => 'ee_delete_registrations',
292
+			],
293
+			'new_registration'                    => [
294
+				'func'       => 'new_registration',
295
+				'capability' => 'ee_edit_registrations',
296
+			],
297
+			'process_reg_step'                    => [
298
+				'func'       => 'process_reg_step',
299
+				'noheader'   => true,
300
+				'capability' => 'ee_edit_registrations',
301
+			],
302
+			'redirect_to_txn'                     => [
303
+				'func'       => 'redirect_to_txn',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+			],
307
+			'change_reg_status'                   => [
308
+				'func'       => '_change_reg_status',
309
+				'noheader'   => true,
310
+				'capability' => 'ee_edit_registration',
311
+				'obj_id'     => $REG_ID,
312
+			],
313
+			'approve_registration'                => [
314
+				'func'       => 'approve_registration',
315
+				'noheader'   => true,
316
+				'capability' => 'ee_edit_registration',
317
+				'obj_id'     => $REG_ID,
318
+			],
319
+			'approve_and_notify_registration'     => [
320
+				'func'       => 'approve_registration',
321
+				'noheader'   => true,
322
+				'args'       => [true],
323
+				'capability' => 'ee_edit_registration',
324
+				'obj_id'     => $REG_ID,
325
+			],
326
+			'approve_registrations'               => [
327
+				'func'       => 'bulk_action_on_registrations',
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_registrations',
330
+				'args'       => ['approve'],
331
+			],
332
+			'approve_and_notify_registrations'    => [
333
+				'func'       => 'bulk_action_on_registrations',
334
+				'noheader'   => true,
335
+				'capability' => 'ee_edit_registrations',
336
+				'args'       => ['approve', true],
337
+			],
338
+			'decline_registration'                => [
339
+				'func'       => 'decline_registration',
340
+				'noheader'   => true,
341
+				'capability' => 'ee_edit_registration',
342
+				'obj_id'     => $REG_ID,
343
+			],
344
+			'decline_and_notify_registration'     => [
345
+				'func'       => 'decline_registration',
346
+				'noheader'   => true,
347
+				'args'       => [true],
348
+				'capability' => 'ee_edit_registration',
349
+				'obj_id'     => $REG_ID,
350
+			],
351
+			'decline_registrations'               => [
352
+				'func'       => 'bulk_action_on_registrations',
353
+				'noheader'   => true,
354
+				'capability' => 'ee_edit_registrations',
355
+				'args'       => ['decline'],
356
+			],
357
+			'decline_and_notify_registrations'    => [
358
+				'func'       => 'bulk_action_on_registrations',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_edit_registrations',
361
+				'args'       => ['decline', true],
362
+			],
363
+			'pending_registration'                => [
364
+				'func'       => 'pending_registration',
365
+				'noheader'   => true,
366
+				'capability' => 'ee_edit_registration',
367
+				'obj_id'     => $REG_ID,
368
+			],
369
+			'pending_and_notify_registration'     => [
370
+				'func'       => 'pending_registration',
371
+				'noheader'   => true,
372
+				'args'       => [true],
373
+				'capability' => 'ee_edit_registration',
374
+				'obj_id'     => $REG_ID,
375
+			],
376
+			'pending_registrations'               => [
377
+				'func'       => 'bulk_action_on_registrations',
378
+				'noheader'   => true,
379
+				'capability' => 'ee_edit_registrations',
380
+				'args'       => ['pending'],
381
+			],
382
+			'pending_and_notify_registrations'    => [
383
+				'func'       => 'bulk_action_on_registrations',
384
+				'noheader'   => true,
385
+				'capability' => 'ee_edit_registrations',
386
+				'args'       => ['pending', true],
387
+			],
388
+			'no_approve_registration'             => [
389
+				'func'       => 'not_approve_registration',
390
+				'noheader'   => true,
391
+				'capability' => 'ee_edit_registration',
392
+				'obj_id'     => $REG_ID,
393
+			],
394
+			'no_approve_and_notify_registration'  => [
395
+				'func'       => 'not_approve_registration',
396
+				'noheader'   => true,
397
+				'args'       => [true],
398
+				'capability' => 'ee_edit_registration',
399
+				'obj_id'     => $REG_ID,
400
+			],
401
+			'no_approve_registrations'            => [
402
+				'func'       => 'bulk_action_on_registrations',
403
+				'noheader'   => true,
404
+				'capability' => 'ee_edit_registrations',
405
+				'args'       => ['not_approve'],
406
+			],
407
+			'no_approve_and_notify_registrations' => [
408
+				'func'       => 'bulk_action_on_registrations',
409
+				'noheader'   => true,
410
+				'capability' => 'ee_edit_registrations',
411
+				'args'       => ['not_approve', true],
412
+			],
413
+			'cancel_registration'                 => [
414
+				'func'       => 'cancel_registration',
415
+				'noheader'   => true,
416
+				'capability' => 'ee_edit_registration',
417
+				'obj_id'     => $REG_ID,
418
+			],
419
+			'cancel_and_notify_registration'      => [
420
+				'func'       => 'cancel_registration',
421
+				'noheader'   => true,
422
+				'args'       => [true],
423
+				'capability' => 'ee_edit_registration',
424
+				'obj_id'     => $REG_ID,
425
+			],
426
+			'cancel_registrations'                => [
427
+				'func'       => 'bulk_action_on_registrations',
428
+				'noheader'   => true,
429
+				'capability' => 'ee_edit_registrations',
430
+				'args'       => ['cancel'],
431
+			],
432
+			'cancel_and_notify_registrations'     => [
433
+				'func'       => 'bulk_action_on_registrations',
434
+				'noheader'   => true,
435
+				'capability' => 'ee_edit_registrations',
436
+				'args'       => ['cancel', true],
437
+			],
438
+			'wait_list_registration'              => [
439
+				'func'       => 'wait_list_registration',
440
+				'noheader'   => true,
441
+				'capability' => 'ee_edit_registration',
442
+				'obj_id'     => $REG_ID,
443
+			],
444
+			'wait_list_and_notify_registration'   => [
445
+				'func'       => 'wait_list_registration',
446
+				'noheader'   => true,
447
+				'args'       => [true],
448
+				'capability' => 'ee_edit_registration',
449
+				'obj_id'     => $REG_ID,
450
+			],
451
+			'contact_list'                        => [
452
+				'func'       => '_attendee_contact_list_table',
453
+				'capability' => 'ee_read_contacts',
454
+			],
455
+			'add_new_attendee'                    => [
456
+				'func' => '_create_new_cpt_item',
457
+				'args' => [
458
+					'new_attendee' => true,
459
+					'capability'   => 'ee_edit_contacts',
460
+				],
461
+			],
462
+			'edit_attendee'                       => [
463
+				'func'       => '_edit_cpt_item',
464
+				'capability' => 'ee_edit_contacts',
465
+				'obj_id'     => $ATT_ID,
466
+			],
467
+			'duplicate_attendee'                  => [
468
+				'func'       => '_duplicate_attendee',
469
+				'noheader'   => true,
470
+				'capability' => 'ee_edit_contacts',
471
+				'obj_id'     => $ATT_ID,
472
+			],
473
+			'insert_attendee'                     => [
474
+				'func'       => '_insert_or_update_attendee',
475
+				'args'       => [
476
+					'new_attendee' => true,
477
+				],
478
+				'noheader'   => true,
479
+				'capability' => 'ee_edit_contacts',
480
+			],
481
+			'update_attendee'                     => [
482
+				'func'       => '_insert_or_update_attendee',
483
+				'args'       => [
484
+					'new_attendee' => false,
485
+				],
486
+				'noheader'   => true,
487
+				'capability' => 'ee_edit_contacts',
488
+				'obj_id'     => $ATT_ID,
489
+			],
490
+			'trash_attendees'                     => [
491
+				'func'       => '_trash_or_restore_attendees',
492
+				'args'       => [
493
+					'trash' => 'true',
494
+				],
495
+				'noheader'   => true,
496
+				'capability' => 'ee_delete_contacts',
497
+			],
498
+			'trash_attendee'                      => [
499
+				'func'       => '_trash_or_restore_attendees',
500
+				'args'       => [
501
+					'trash' => true,
502
+				],
503
+				'noheader'   => true,
504
+				'capability' => 'ee_delete_contacts',
505
+				'obj_id'     => $ATT_ID,
506
+			],
507
+			'restore_attendees'                   => [
508
+				'func'       => '_trash_or_restore_attendees',
509
+				'args'       => [
510
+					'trash' => false,
511
+				],
512
+				'noheader'   => true,
513
+				'capability' => 'ee_delete_contacts',
514
+				'obj_id'     => $ATT_ID,
515
+			],
516
+			'resend_registration'                 => [
517
+				'func'       => '_resend_registration',
518
+				'noheader'   => true,
519
+				'capability' => 'ee_send_message',
520
+			],
521
+			'registrations_report'                => [
522
+				'func'       => '_registrations_report',
523
+				'noheader'   => true,
524
+				'capability' => 'ee_read_registrations',
525
+			],
526
+			'contact_list_export'                 => [
527
+				'func'       => '_contact_list_export',
528
+				'noheader'   => true,
529
+				'capability' => 'export',
530
+			],
531
+			'contact_list_report'                 => [
532
+				'func'       => '_contact_list_report',
533
+				'noheader'   => true,
534
+				'capability' => 'ee_read_contacts',
535
+			],
536
+		];
537
+	}
538
+
539
+
540
+	protected function _set_page_config()
541
+	{
542
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
+		$this->_page_config = [
545
+			'default'           => [
546
+				'nav'           => [
547
+					'label' => esc_html__('Overview', 'event_espresso'),
548
+					'order' => 5,
549
+				],
550
+				'help_tabs'     => [
551
+					'registrations_overview_help_tab'                       => [
552
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
+						'filename' => 'registrations_overview',
554
+					],
555
+					'registrations_overview_table_column_headings_help_tab' => [
556
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
+						'filename' => 'registrations_overview_table_column_headings',
558
+					],
559
+					'registrations_overview_filters_help_tab'               => [
560
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
+						'filename' => 'registrations_overview_filters',
562
+					],
563
+					'registrations_overview_views_help_tab'                 => [
564
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
565
+						'filename' => 'registrations_overview_views',
566
+					],
567
+					'registrations_regoverview_other_help_tab'              => [
568
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
+						'filename' => 'registrations_overview_other',
570
+					],
571
+				],
572
+				'list_table'    => 'EE_Registrations_List_Table',
573
+				'require_nonce' => false,
574
+			],
575
+			'view_registration' => [
576
+				'nav'           => [
577
+					'label'      => esc_html__('REG Details', 'event_espresso'),
578
+					'order'      => 15,
579
+					'url'        => $REG_ID
580
+						? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
581
+						: $this->_admin_base_url,
582
+					'persistent' => false,
583
+				],
584
+				'help_tabs'     => [
585
+					'registrations_details_help_tab'                    => [
586
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
587
+						'filename' => 'registrations_details',
588
+					],
589
+					'registrations_details_table_help_tab'              => [
590
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
591
+						'filename' => 'registrations_details_table',
592
+					],
593
+					'registrations_details_form_answers_help_tab'       => [
594
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
595
+						'filename' => 'registrations_details_form_answers',
596
+					],
597
+					'registrations_details_registrant_details_help_tab' => [
598
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
599
+						'filename' => 'registrations_details_registrant_details',
600
+					],
601
+				],
602
+				'metaboxes'     => array_merge(
603
+					$this->_default_espresso_metaboxes,
604
+					['_registration_details_metaboxes']
605
+				),
606
+				'require_nonce' => false,
607
+			],
608
+			'new_registration'  => [
609
+				'nav'           => [
610
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
611
+					'url'        => '#',
612
+					'order'      => 15,
613
+					'persistent' => false,
614
+				],
615
+				'metaboxes'     => $this->_default_espresso_metaboxes,
616
+				'labels'        => [
617
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
618
+				],
619
+				'require_nonce' => false,
620
+			],
621
+			'add_new_attendee'  => [
622
+				'nav'           => [
623
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
624
+					'order'      => 15,
625
+					'persistent' => false,
626
+				],
627
+				'metaboxes'     => array_merge(
628
+					$this->_default_espresso_metaboxes,
629
+					['_publish_post_box', 'attendee_editor_metaboxes']
630
+				),
631
+				'require_nonce' => false,
632
+			],
633
+			'edit_attendee'     => [
634
+				'nav'           => [
635
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
636
+					'order'      => 15,
637
+					'persistent' => false,
638
+					'url'        => $ATT_ID
639
+						? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
640
+						: $this->_admin_base_url,
641
+				],
642
+				'metaboxes'     => array_merge(
643
+					$this->_default_espresso_metaboxes,
644
+					['attendee_editor_metaboxes']
645
+				),
646
+				'require_nonce' => false,
647
+			],
648
+			'contact_list'      => [
649
+				'nav'           => [
650
+					'label' => esc_html__('Contact List', 'event_espresso'),
651
+					'order' => 20,
652
+				],
653
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
654
+				'help_tabs'     => [
655
+					'registrations_contact_list_help_tab'                       => [
656
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
657
+						'filename' => 'registrations_contact_list',
658
+					],
659
+					'registrations_contact-list_table_column_headings_help_tab' => [
660
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
661
+						'filename' => 'registrations_contact_list_table_column_headings',
662
+					],
663
+					'registrations_contact_list_views_help_tab'                 => [
664
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
665
+						'filename' => 'registrations_contact_list_views',
666
+					],
667
+					'registrations_contact_list_other_help_tab'                 => [
668
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
669
+						'filename' => 'registrations_contact_list_other',
670
+					],
671
+				],
672
+				'metaboxes'     => [],
673
+				'require_nonce' => false,
674
+			],
675
+			// override default cpt routes
676
+			'create_new'        => '',
677
+			'edit'              => '',
678
+		];
679
+	}
680
+
681
+
682
+	/**
683
+	 * The below methods aren't used by this class currently
684
+	 */
685
+	protected function _add_screen_options()
686
+	{
687
+	}
688
+
689
+
690
+	protected function _add_feature_pointers()
691
+	{
692
+	}
693
+
694
+
695
+	public function admin_init()
696
+	{
697
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
698
+			'click "Update Registration Questions" to save your changes',
699
+			'event_espresso'
700
+		);
701
+	}
702
+
703
+
704
+	public function admin_notices()
705
+	{
706
+	}
707
+
708
+
709
+	public function admin_footer_scripts()
710
+	{
711
+	}
712
+
713
+
714
+	/**
715
+	 * get list of registration statuses
716
+	 *
717
+	 * @return void
718
+	 * @throws EE_Error
719
+	 */
720
+	private function _get_registration_status_array()
721
+	{
722
+		self::$_reg_status = EEM_Registration::reg_status_array([], true);
723
+	}
724
+
725
+
726
+	/**
727
+	 * @throws InvalidArgumentException
728
+	 * @throws InvalidDataTypeException
729
+	 * @throws InvalidInterfaceException
730
+	 * @since 4.10.2.p
731
+	 */
732
+	protected function _add_screen_options_default()
733
+	{
734
+		$this->_per_page_screen_option();
735
+	}
736
+
737
+
738
+	/**
739
+	 * @throws InvalidArgumentException
740
+	 * @throws InvalidDataTypeException
741
+	 * @throws InvalidInterfaceException
742
+	 * @since 4.10.2.p
743
+	 */
744
+	protected function _add_screen_options_contact_list()
745
+	{
746
+		$page_title              = $this->_admin_page_title;
747
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
748
+		$this->_per_page_screen_option();
749
+		$this->_admin_page_title = $page_title;
750
+	}
751
+
752
+
753
+	public function load_scripts_styles()
754
+	{
755
+		// style
756
+		wp_register_style(
757
+			'espresso_reg',
758
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
759
+			['ee-admin-css'],
760
+			EVENT_ESPRESSO_VERSION
761
+		);
762
+		wp_enqueue_style('espresso_reg');
763
+		// script
764
+		wp_register_script(
765
+			'espresso_reg',
766
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
767
+			['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
768
+			EVENT_ESPRESSO_VERSION,
769
+			true
770
+		);
771
+		wp_enqueue_script('espresso_reg');
772
+	}
773
+
774
+
775
+	/**
776
+	 * @throws EE_Error
777
+	 * @throws InvalidArgumentException
778
+	 * @throws InvalidDataTypeException
779
+	 * @throws InvalidInterfaceException
780
+	 * @throws ReflectionException
781
+	 * @since 4.10.2.p
782
+	 */
783
+	public function load_scripts_styles_edit_attendee()
784
+	{
785
+		// stuff to only show up on our attendee edit details page.
786
+		$attendee_details_translations = [
787
+			'att_publish_text' => sprintf(
788
+			/* translators: The date and time */
789
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
790
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
791
+			),
792
+		];
793
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
794
+		wp_enqueue_script('jquery-validate');
795
+	}
796
+
797
+
798
+	/**
799
+	 * @throws EE_Error
800
+	 * @throws InvalidArgumentException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws InvalidInterfaceException
803
+	 * @throws ReflectionException
804
+	 * @since 4.10.2.p
805
+	 */
806
+	public function load_scripts_styles_view_registration()
807
+	{
808
+		// styles
809
+		wp_enqueue_style('espresso-ui-theme');
810
+		// scripts
811
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
812
+		$this->_reg_custom_questions_form->wp_enqueue_scripts();
813
+	}
814
+
815
+
816
+	public function load_scripts_styles_contact_list()
817
+	{
818
+		wp_dequeue_style('espresso_reg');
819
+		wp_register_style(
820
+			'espresso_att',
821
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
822
+			['ee-admin-css'],
823
+			EVENT_ESPRESSO_VERSION
824
+		);
825
+		wp_enqueue_style('espresso_att');
826
+	}
827
+
828
+
829
+	public function load_scripts_styles_new_registration()
830
+	{
831
+		wp_register_script(
832
+			'ee-spco-for-admin',
833
+			REG_ASSETS_URL . 'spco_for_admin.js',
834
+			['underscore', 'jquery'],
835
+			EVENT_ESPRESSO_VERSION,
836
+			true
837
+		);
838
+		wp_enqueue_script('ee-spco-for-admin');
839
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
840
+		EE_Form_Section_Proper::wp_enqueue_scripts();
841
+		EED_Ticket_Selector::load_tckt_slctr_assets();
842
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
843
+	}
844
+
845
+
846
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
847
+	{
848
+		add_filter('FHEE_load_EE_messages', '__return_true');
849
+	}
850
+
851
+
852
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
853
+	{
854
+		add_filter('FHEE_load_EE_messages', '__return_true');
855
+	}
856
+
857
+
858
+	/**
859
+	 * @throws EE_Error
860
+	 * @throws InvalidArgumentException
861
+	 * @throws InvalidDataTypeException
862
+	 * @throws InvalidInterfaceException
863
+	 * @throws ReflectionException
864
+	 * @since 4.10.2.p
865
+	 */
866
+	protected function _set_list_table_views_default()
867
+	{
868
+		// for notification related bulk actions we need to make sure only active messengers have an option.
869
+		EED_Messages::set_autoloaders();
870
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
871
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
872
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
873
+		// key= bulk_action_slug, value= message type.
874
+		$match_array = [
875
+			'approve_registrations'    => 'registration',
876
+			'decline_registrations'    => 'declined_registration',
877
+			'pending_registrations'    => 'pending_approval',
878
+			'no_approve_registrations' => 'not_approved_registration',
879
+			'cancel_registrations'     => 'cancelled_registration',
880
+		];
881
+		$can_send    = EE_Registry::instance()->CAP->current_user_can(
882
+			'ee_send_message',
883
+			'batch_send_messages'
884
+		);
885
+		/** setup reg status bulk actions **/
886
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
887
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
888
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
889
+				'Approve and Notify Registrations',
890
+				'event_espresso'
891
+			);
892
+		}
893
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
894
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
895
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
896
+				'Decline and Notify Registrations',
897
+				'event_espresso'
898
+			);
899
+		}
900
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
901
+			'Set Registrations to Pending Payment',
902
+			'event_espresso'
903
+		);
904
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
905
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
906
+				'Set Registrations to Pending Payment and Notify',
907
+				'event_espresso'
908
+			);
909
+		}
910
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
911
+			'Set Registrations to Not Approved',
912
+			'event_espresso'
913
+		);
914
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
915
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
916
+				'Set Registrations to Not Approved and Notify',
917
+				'event_espresso'
918
+			);
919
+		}
920
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
921
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
922
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
923
+				'Cancel Registrations and Notify',
924
+				'event_espresso'
925
+			);
926
+		}
927
+		$def_reg_status_actions = apply_filters(
928
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
929
+			$def_reg_status_actions,
930
+			$active_mts,
931
+			$can_send
932
+		);
933
+
934
+		$this->_views = [
935
+			'all'   => [
936
+				'slug'        => 'all',
937
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
938
+				'count'       => 0,
939
+				'bulk_action' => array_merge(
940
+					$def_reg_status_actions,
941
+					[
942
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
+					]
944
+				),
945
+			],
946
+			'month' => [
947
+				'slug'        => 'month',
948
+				'label'       => esc_html__('This Month', 'event_espresso'),
949
+				'count'       => 0,
950
+				'bulk_action' => array_merge(
951
+					$def_reg_status_actions,
952
+					[
953
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
+					]
955
+				),
956
+			],
957
+			'today' => [
958
+				'slug'        => 'today',
959
+				'label'       => sprintf(
960
+					esc_html__('Today - %s', 'event_espresso'),
961
+					date('M d, Y', current_time('timestamp'))
962
+				),
963
+				'count'       => 0,
964
+				'bulk_action' => array_merge(
965
+					$def_reg_status_actions,
966
+					[
967
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
+					]
969
+				),
970
+			],
971
+		];
972
+		if (
973
+			EE_Registry::instance()->CAP->current_user_can(
974
+				'ee_delete_registrations',
975
+				'espresso_registrations_delete_registration'
976
+			)
977
+		) {
978
+			$this->_views['incomplete'] = [
979
+				'slug'        => 'incomplete',
980
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
981
+				'count'       => 0,
982
+				'bulk_action' => [
983
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
984
+				],
985
+			];
986
+			$this->_views['trash']      = [
987
+				'slug'        => 'trash',
988
+				'label'       => esc_html__('Trash', 'event_espresso'),
989
+				'count'       => 0,
990
+				'bulk_action' => [
991
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
992
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
993
+				],
994
+			];
995
+		}
996
+	}
997
+
998
+
999
+	protected function _set_list_table_views_contact_list()
1000
+	{
1001
+		$this->_views = [
1002
+			'in_use' => [
1003
+				'slug'        => 'in_use',
1004
+				'label'       => esc_html__('In Use', 'event_espresso'),
1005
+				'count'       => 0,
1006
+				'bulk_action' => [
1007
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1008
+				],
1009
+			],
1010
+		];
1011
+		if (
1012
+			EE_Registry::instance()->CAP->current_user_can(
1013
+				'ee_delete_contacts',
1014
+				'espresso_registrations_trash_attendees'
1015
+			)
1016
+		) {
1017
+			$this->_views['trash'] = [
1018
+				'slug'        => 'trash',
1019
+				'label'       => esc_html__('Trash', 'event_espresso'),
1020
+				'count'       => 0,
1021
+				'bulk_action' => [
1022
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1023
+				],
1024
+			];
1025
+		}
1026
+	}
1027
+
1028
+
1029
+	/**
1030
+	 * @return array
1031
+	 * @throws EE_Error
1032
+	 */
1033
+	protected function _registration_legend_items()
1034
+	{
1035
+		$fc_items = [
1036
+			'star-icon'        => [
1037
+				'class' => 'dashicons dashicons-star-filled gold-icon',
1038
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1039
+			],
1040
+			'view_details'     => [
1041
+				'class' => 'dashicons dashicons-clipboard',
1042
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1043
+			],
1044
+			'edit_attendee'    => [
1045
+				'class' => 'dashicons dashicons-admin-users',
1046
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1047
+			],
1048
+			'view_transaction' => [
1049
+				'class' => 'dashicons dashicons-cart',
1050
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1051
+			],
1052
+			'view_invoice'     => [
1053
+				'class' => 'dashicons dashicons-media-spreadsheet',
1054
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1055
+			],
1056
+		];
1057
+		if (
1058
+			EE_Registry::instance()->CAP->current_user_can(
1059
+				'ee_send_message',
1060
+				'espresso_registrations_resend_registration'
1061
+			)
1062
+		) {
1063
+			$fc_items['resend_registration'] = [
1064
+				'class' => 'dashicons dashicons-email-alt',
1065
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1066
+			];
1067
+		} else {
1068
+			$fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1069
+		}
1070
+		if (
1071
+			EE_Registry::instance()->CAP->current_user_can(
1072
+				'ee_read_global_messages',
1073
+				'view_filtered_messages'
1074
+			)
1075
+		) {
1076
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1077
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1078
+				$fc_items['view_related_messages'] = [
1079
+					'class' => $related_for_icon['css_class'],
1080
+					'desc'  => $related_for_icon['label'],
1081
+				];
1082
+			}
1083
+		}
1084
+		$sc_items = [
1085
+			'approved_status'   => [
1086
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1087
+				'desc'  => EEH_Template::pretty_status(
1088
+					EEM_Registration::status_id_approved,
1089
+					false,
1090
+					'sentence'
1091
+				),
1092
+			],
1093
+			'pending_status'    => [
1094
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1095
+				'desc'  => EEH_Template::pretty_status(
1096
+					EEM_Registration::status_id_pending_payment,
1097
+					false,
1098
+					'sentence'
1099
+				),
1100
+			],
1101
+			'wait_list'         => [
1102
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1103
+				'desc'  => EEH_Template::pretty_status(
1104
+					EEM_Registration::status_id_wait_list,
1105
+					false,
1106
+					'sentence'
1107
+				),
1108
+			],
1109
+			'incomplete_status' => [
1110
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1111
+				'desc'  => EEH_Template::pretty_status(
1112
+					EEM_Registration::status_id_incomplete,
1113
+					false,
1114
+					'sentence'
1115
+				),
1116
+			],
1117
+			'not_approved'      => [
1118
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1119
+				'desc'  => EEH_Template::pretty_status(
1120
+					EEM_Registration::status_id_not_approved,
1121
+					false,
1122
+					'sentence'
1123
+				),
1124
+			],
1125
+			'declined_status'   => [
1126
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1127
+				'desc'  => EEH_Template::pretty_status(
1128
+					EEM_Registration::status_id_declined,
1129
+					false,
1130
+					'sentence'
1131
+				),
1132
+			],
1133
+			'cancelled_status'  => [
1134
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1135
+				'desc'  => EEH_Template::pretty_status(
1136
+					EEM_Registration::status_id_cancelled,
1137
+					false,
1138
+					'sentence'
1139
+				),
1140
+			],
1141
+		];
1142
+		return array_merge($fc_items, $sc_items);
1143
+	}
1144
+
1145
+
1146
+
1147
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1148
+
1149
+
1150
+	/**
1151
+	 * @throws DomainException
1152
+	 * @throws EE_Error
1153
+	 * @throws InvalidArgumentException
1154
+	 * @throws InvalidDataTypeException
1155
+	 * @throws InvalidInterfaceException
1156
+	 */
1157
+	protected function _registrations_overview_list_table()
1158
+	{
1159
+		$this->appendAddNewRegistrationButtonToPageTitle();
1160
+		$header_text                  = '';
1161
+		$admin_page_header_decorators = [
1162
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1163
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1164
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1165
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1166
+		];
1167
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1168
+			$filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1169
+			$header_text = $filter_header_decorator->getHeaderText($header_text);
1170
+		}
1171
+		$this->_template_args['admin_page_header'] = $header_text;
1172
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1173
+		$this->display_admin_list_table_page_with_no_sidebar();
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * @throws EE_Error
1179
+	 * @throws InvalidArgumentException
1180
+	 * @throws InvalidDataTypeException
1181
+	 * @throws InvalidInterfaceException
1182
+	 */
1183
+	private function appendAddNewRegistrationButtonToPageTitle()
1184
+	{
1185
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1186
+		if (
1187
+			$EVT_ID
1188
+			&& EE_Registry::instance()->CAP->current_user_can(
1189
+				'ee_edit_registrations',
1190
+				'espresso_registrations_new_registration',
1191
+				$EVT_ID
1192
+			)
1193
+		) {
1194
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1195
+				'new_registration',
1196
+				'add-registrant',
1197
+				['event_id' => $EVT_ID],
1198
+				'add-new-h2'
1199
+			);
1200
+		}
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * This sets the _registration property for the registration details screen
1206
+	 *
1207
+	 * @return void
1208
+	 * @throws EE_Error
1209
+	 * @throws InvalidArgumentException
1210
+	 * @throws InvalidDataTypeException
1211
+	 * @throws InvalidInterfaceException
1212
+	 */
1213
+	private function _set_registration_object()
1214
+	{
1215
+		// get out if we've already set the object
1216
+		if ($this->_registration instanceof EE_Registration) {
1217
+			return;
1218
+		}
1219
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1220
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1221
+			return;
1222
+		}
1223
+		$error_msg = sprintf(
1224
+			esc_html__(
1225
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1226
+				'event_espresso'
1227
+			),
1228
+			$REG_ID
1229
+		);
1230
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1231
+		$this->_registration = null;
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 * Used to retrieve registrations for the list table.
1237
+	 *
1238
+	 * @param int  $per_page
1239
+	 * @param bool $count
1240
+	 * @param bool $this_month
1241
+	 * @param bool $today
1242
+	 * @return EE_Registration[]|int
1243
+	 * @throws EE_Error
1244
+	 * @throws InvalidArgumentException
1245
+	 * @throws InvalidDataTypeException
1246
+	 * @throws InvalidInterfaceException
1247
+	 */
1248
+	public function get_registrations(
1249
+		$per_page = 10,
1250
+		$count = false,
1251
+		$this_month = false,
1252
+		$today = false
1253
+	) {
1254
+		if ($this_month) {
1255
+			$this->request->setRequestParam('status', 'month');
1256
+		}
1257
+		if ($today) {
1258
+			$this->request->setRequestParam('status', 'today');
1259
+		}
1260
+		$query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1261
+		/**
1262
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1263
+		 *
1264
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1265
+		 * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1266
+		 *                      or if you have the development copy of EE you can view this at the path:
1267
+		 *                      /docs/G--Model-System/model-query-params.md
1268
+		 */
1269
+		$query_params['group_by'] = '';
1270
+
1271
+		return $count
1272
+			? $this->getRegistrationModel()->count($query_params)
1273
+			/** @type EE_Registration[] */
1274
+			: $this->getRegistrationModel()->get_all($query_params);
1275
+	}
1276
+
1277
+
1278
+	/**
1279
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1280
+	 * Note: this listens to values on the request for some of the query parameters.
1281
+	 *
1282
+	 * @param array $request
1283
+	 * @param int   $per_page
1284
+	 * @param bool  $count
1285
+	 * @return array
1286
+	 * @throws EE_Error
1287
+	 * @throws InvalidArgumentException
1288
+	 * @throws InvalidDataTypeException
1289
+	 * @throws InvalidInterfaceException
1290
+	 */
1291
+	protected function _get_registration_query_parameters(
1292
+		$request = [],
1293
+		$per_page = 10,
1294
+		$count = false
1295
+	) {
1296
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1297
+		$list_table_query_builder = $this->loader->getNew(
1298
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1299
+			[null, null, $request]
1300
+		);
1301
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1302
+	}
1303
+
1304
+
1305
+	public function get_registration_status_array()
1306
+	{
1307
+		return self::$_reg_status;
1308
+	}
1309
+
1310
+
1311
+
1312
+
1313
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1314
+	/**
1315
+	 * generates HTML for the View Registration Details Admin page
1316
+	 *
1317
+	 * @return void
1318
+	 * @throws DomainException
1319
+	 * @throws EE_Error
1320
+	 * @throws InvalidArgumentException
1321
+	 * @throws InvalidDataTypeException
1322
+	 * @throws InvalidInterfaceException
1323
+	 * @throws EntityNotFoundException
1324
+	 * @throws ReflectionException
1325
+	 */
1326
+	protected function _registration_details()
1327
+	{
1328
+		$this->_template_args = [];
1329
+		$this->_set_registration_object();
1330
+		if (is_object($this->_registration)) {
1331
+			$transaction                                   = $this->_registration->transaction()
1332
+				? $this->_registration->transaction()
1333
+				: EE_Transaction::new_instance();
1334
+			$this->_session                                = $transaction->session_data();
1335
+			$event_id                                      = $this->_registration->event_ID();
1336
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1337
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1338
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1339
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1340
+			$this->_template_args['grand_total']           = $transaction->total();
1341
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1342
+			// link back to overview
1343
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1344
+			$this->_template_args['registration']                = $this->_registration;
1345
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1346
+				[
1347
+					'action'   => 'default',
1348
+					'event_id' => $event_id,
1349
+				],
1350
+				REG_ADMIN_URL
1351
+			);
1352
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1353
+				[
1354
+					'action' => 'default',
1355
+					'EVT_ID' => $event_id,
1356
+					'page'   => 'espresso_transactions',
1357
+				],
1358
+				admin_url('admin.php')
1359
+			);
1360
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1361
+				[
1362
+					'page'   => 'espresso_events',
1363
+					'action' => 'edit',
1364
+					'post'   => $event_id,
1365
+				],
1366
+				admin_url('admin.php')
1367
+			);
1368
+			// next and previous links
1369
+			$next_reg                                      = $this->_registration->next(
1370
+				null,
1371
+				[],
1372
+				'REG_ID'
1373
+			);
1374
+			$this->_template_args['next_registration']     = $next_reg
1375
+				? $this->_next_link(
1376
+					EE_Admin_Page::add_query_args_and_nonce(
1377
+						[
1378
+							'action'  => 'view_registration',
1379
+							'_REG_ID' => $next_reg['REG_ID'],
1380
+						],
1381
+						REG_ADMIN_URL
1382
+					),
1383
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1384
+				)
1385
+				: '';
1386
+			$previous_reg                                  = $this->_registration->previous(
1387
+				null,
1388
+				[],
1389
+				'REG_ID'
1390
+			);
1391
+			$this->_template_args['previous_registration'] = $previous_reg
1392
+				? $this->_previous_link(
1393
+					EE_Admin_Page::add_query_args_and_nonce(
1394
+						[
1395
+							'action'  => 'view_registration',
1396
+							'_REG_ID' => $previous_reg['REG_ID'],
1397
+						],
1398
+						REG_ADMIN_URL
1399
+					),
1400
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1401
+				)
1402
+				: '';
1403
+			// grab header
1404
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1405
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1406
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1407
+				$template_path,
1408
+				$this->_template_args,
1409
+				true
1410
+			);
1411
+		} else {
1412
+			$this->_template_args['admin_page_header'] = '';
1413
+			$this->_display_espresso_notices();
1414
+		}
1415
+		// the details template wrapper
1416
+		$this->display_admin_page_with_sidebar();
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 * @throws EE_Error
1422
+	 * @throws InvalidArgumentException
1423
+	 * @throws InvalidDataTypeException
1424
+	 * @throws InvalidInterfaceException
1425
+	 * @throws ReflectionException
1426
+	 * @since 4.10.2.p
1427
+	 */
1428
+	protected function _registration_details_metaboxes()
1429
+	{
1430
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1431
+		$this->_set_registration_object();
1432
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1433
+		$this->addMetaBox(
1434
+			'edit-reg-status-mbox',
1435
+			esc_html__('Registration Status', 'event_espresso'),
1436
+			[$this, 'set_reg_status_buttons_metabox'],
1437
+			$this->_wp_page_slug
1438
+		);
1439
+		$this->addMetaBox(
1440
+			'edit-reg-details-mbox',
1441
+			'<span>' . esc_html__('Registration Details', 'event_espresso')
1442
+			. '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1443
+			[$this, '_reg_details_meta_box'],
1444
+			$this->_wp_page_slug
1445
+		);
1446
+		if (
1447
+			$attendee instanceof EE_Attendee
1448
+			&& EE_Registry::instance()->CAP->current_user_can(
1449
+				'ee_read_registration',
1450
+				'edit-reg-questions-mbox',
1451
+				$this->_registration->ID()
1452
+			)
1453
+		) {
1454
+			$this->addMetaBox(
1455
+				$this->_wp_page_slug,
1456
+				'edit-reg-questions-mbox',
1457
+				esc_html__('Registration Form Answers', 'event_espresso'),
1458
+				[$this, '_reg_questions_meta_box'],
1459
+				$this->_wp_page_slug
1460
+			);
1461
+		}
1462
+		$this->addMetaBox(
1463
+			'edit-reg-registrant-mbox',
1464
+			esc_html__('Contact Details', 'event_espresso'),
1465
+			[$this, '_reg_registrant_side_meta_box'],
1466
+			$this->_wp_page_slug,
1467
+			'side'
1468
+		);
1469
+		if ($this->_registration->group_size() > 1) {
1470
+			$this->addMetaBox(
1471
+				'edit-reg-attendees-mbox',
1472
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1473
+				[$this, '_reg_attendees_meta_box'],
1474
+				$this->_wp_page_slug
1475
+			);
1476
+		}
1477
+	}
1478
+
1479
+
1480
+	/**
1481
+	 * set_reg_status_buttons_metabox
1482
+	 *
1483
+	 * @return void
1484
+	 * @throws EE_Error
1485
+	 * @throws EntityNotFoundException
1486
+	 * @throws InvalidArgumentException
1487
+	 * @throws InvalidDataTypeException
1488
+	 * @throws InvalidInterfaceException
1489
+	 * @throws ReflectionException
1490
+	 */
1491
+	public function set_reg_status_buttons_metabox()
1492
+	{
1493
+		$this->_set_registration_object();
1494
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1495
+		$output                 = $change_reg_status_form->form_open(
1496
+			self::add_query_args_and_nonce(
1497
+				[
1498
+					'action' => 'change_reg_status',
1499
+				],
1500
+				REG_ADMIN_URL
1501
+			)
1502
+		);
1503
+		$output                 .= $change_reg_status_form->get_html();
1504
+		$output                 .= $change_reg_status_form->form_close();
1505
+		echo wp_kses($output, AllowedTags::getWithFormTags());
1506
+	}
1507
+
1508
+
1509
+	/**
1510
+	 * @return EE_Form_Section_Proper
1511
+	 * @throws EE_Error
1512
+	 * @throws InvalidArgumentException
1513
+	 * @throws InvalidDataTypeException
1514
+	 * @throws InvalidInterfaceException
1515
+	 * @throws EntityNotFoundException
1516
+	 * @throws ReflectionException
1517
+	 */
1518
+	protected function _generate_reg_status_change_form()
1519
+	{
1520
+		$reg_status_change_form_array = [
1521
+			'name'            => 'reg_status_change_form',
1522
+			'html_id'         => 'reg-status-change-form',
1523
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1524
+			'subsections'     => [
1525
+				'return'         => new EE_Hidden_Input(
1526
+					[
1527
+						'name'    => 'return',
1528
+						'default' => 'view_registration',
1529
+					]
1530
+				),
1531
+				'REG_ID'         => new EE_Hidden_Input(
1532
+					[
1533
+						'name'    => 'REG_ID',
1534
+						'default' => $this->_registration->ID(),
1535
+					]
1536
+				),
1537
+			],
1538
+		];
1539
+		if (
1540
+			EE_Registry::instance()->CAP->current_user_can(
1541
+				'ee_edit_registration',
1542
+				'toggle_registration_status',
1543
+				$this->_registration->ID()
1544
+			)
1545
+		) {
1546
+			$reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1547
+				$this->_get_reg_statuses(),
1548
+				[
1549
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1550
+					'default'         => $this->_registration->status_ID(),
1551
+				]
1552
+			);
1553
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1554
+				[
1555
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1556
+					'default'         => false,
1557
+					'html_help_text'  => esc_html__(
1558
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1559
+						'event_espresso'
1560
+					),
1561
+				]
1562
+			);
1563
+			$reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1564
+				[
1565
+					'html_class'      => 'button--primary',
1566
+					'html_label_text' => '&nbsp;',
1567
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1568
+				]
1569
+			);
1570
+		}
1571
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1572
+	}
1573
+
1574
+
1575
+	/**
1576
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1577
+	 *
1578
+	 * @return array
1579
+	 * @throws EE_Error
1580
+	 * @throws InvalidArgumentException
1581
+	 * @throws InvalidDataTypeException
1582
+	 * @throws InvalidInterfaceException
1583
+	 * @throws EntityNotFoundException
1584
+	 */
1585
+	protected function _get_reg_statuses()
1586
+	{
1587
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1588
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1589
+		// get current reg status
1590
+		$current_status = $this->_registration->status_ID();
1591
+		// is registration for free event? This will determine whether to display the pending payment option
1592
+		if (
1593
+			$current_status !== EEM_Registration::status_id_pending_payment
1594
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1595
+		) {
1596
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1597
+		}
1598
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1599
+	}
1600
+
1601
+
1602
+	/**
1603
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1604
+	 *
1605
+	 * @param bool $status REG status given for changing registrations to.
1606
+	 * @param bool $notify Whether to send messages notifications or not.
1607
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1608
+	 * @throws DomainException
1609
+	 * @throws EE_Error
1610
+	 * @throws EntityNotFoundException
1611
+	 * @throws InvalidArgumentException
1612
+	 * @throws InvalidDataTypeException
1613
+	 * @throws InvalidInterfaceException
1614
+	 * @throws ReflectionException
1615
+	 * @throws RuntimeException
1616
+	 */
1617
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1618
+	{
1619
+		$REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1620
+			? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1621
+			: $this->request->getRequestParam('_REG_ID', [], 'int', true);
1622
+
1623
+		// sanitize $REG_IDs
1624
+		$REG_IDs = array_map('absint', $REG_IDs);
1625
+		// and remove empty entries
1626
+		$REG_IDs = array_filter($REG_IDs);
1627
+
1628
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1629
+
1630
+		/**
1631
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1632
+		 * Currently this value is used downstream by the _process_resend_registration method.
1633
+		 *
1634
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1635
+		 * @param bool                     $status           The status registrations were changed to.
1636
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1637
+		 * @param Registrations_Admin_Page $admin_page_object
1638
+		 */
1639
+		$REG_ID = apply_filters(
1640
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1641
+			$result['REG_ID'],
1642
+			$status,
1643
+			$result['success'],
1644
+			$this
1645
+		);
1646
+		$this->request->setRequestParam('_REG_ID', $REG_ID);
1647
+
1648
+		// notify?
1649
+		if (
1650
+			$notify
1651
+			&& $result['success']
1652
+			&& ! empty($REG_ID)
1653
+			&& EE_Registry::instance()->CAP->current_user_can(
1654
+				'ee_send_message',
1655
+				'espresso_registrations_resend_registration'
1656
+			)
1657
+		) {
1658
+			$this->_process_resend_registration();
1659
+		}
1660
+		return $result;
1661
+	}
1662
+
1663
+
1664
+	/**
1665
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1666
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1667
+	 *
1668
+	 * @param array  $REG_IDs
1669
+	 * @param string $status
1670
+	 * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1671
+	 *                       slug sent with setting the registration status.
1672
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1673
+	 * @throws EE_Error
1674
+	 * @throws InvalidArgumentException
1675
+	 * @throws InvalidDataTypeException
1676
+	 * @throws InvalidInterfaceException
1677
+	 * @throws ReflectionException
1678
+	 * @throws RuntimeException
1679
+	 * @throws EntityNotFoundException
1680
+	 * @throws DomainException
1681
+	 */
1682
+	protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1683
+	{
1684
+		$success = false;
1685
+		// typecast $REG_IDs
1686
+		$REG_IDs = (array) $REG_IDs;
1687
+		if (! empty($REG_IDs)) {
1688
+			$success = true;
1689
+			// set default status if none is passed
1690
+			$status         = $status ?: EEM_Registration::status_id_pending_payment;
1691
+			$status_context = $notify
1692
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1693
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1694
+			// loop through REG_ID's and change status
1695
+			foreach ($REG_IDs as $REG_ID) {
1696
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1697
+				if ($registration instanceof EE_Registration) {
1698
+					$registration->set_status(
1699
+						$status,
1700
+						false,
1701
+						new Context(
1702
+							$status_context,
1703
+							esc_html__(
1704
+								'Manually triggered status change on a Registration Admin Page route.',
1705
+								'event_espresso'
1706
+							)
1707
+						)
1708
+					);
1709
+					$result = $registration->save();
1710
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1711
+					$success = $result !== false ? $success : false;
1712
+				}
1713
+			}
1714
+		}
1715
+
1716
+		// return $success and processed registrations
1717
+		return ['REG_ID' => $REG_IDs, 'success' => $success];
1718
+	}
1719
+
1720
+
1721
+	/**
1722
+	 * Common logic for setting up success message and redirecting to appropriate route
1723
+	 *
1724
+	 * @param string $STS_ID status id for the registration changed to
1725
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1726
+	 * @return void
1727
+	 * @throws DomainException
1728
+	 * @throws EE_Error
1729
+	 * @throws EntityNotFoundException
1730
+	 * @throws InvalidArgumentException
1731
+	 * @throws InvalidDataTypeException
1732
+	 * @throws InvalidInterfaceException
1733
+	 * @throws ReflectionException
1734
+	 * @throws RuntimeException
1735
+	 */
1736
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1737
+	{
1738
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1739
+			: ['success' => false];
1740
+		$success = isset($result['success']) && $result['success'];
1741
+		// setup success message
1742
+		if ($success) {
1743
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1744
+				$msg = sprintf(
1745
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1746
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1747
+				);
1748
+			} else {
1749
+				$msg = sprintf(
1750
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1751
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1752
+				);
1753
+			}
1754
+			EE_Error::add_success($msg);
1755
+		} else {
1756
+			EE_Error::add_error(
1757
+				esc_html__(
1758
+					'Something went wrong, and the status was not changed',
1759
+					'event_espresso'
1760
+				),
1761
+				__FILE__,
1762
+				__LINE__,
1763
+				__FUNCTION__
1764
+			);
1765
+		}
1766
+		$return = $this->request->getRequestParam('return');
1767
+		$route  = $return === 'view_registration'
1768
+			? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1769
+			: ['action' => 'default'];
1770
+		$route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1771
+		$this->_redirect_after_action($success, '', '', $route, true);
1772
+	}
1773
+
1774
+
1775
+	/**
1776
+	 * incoming reg status change from reg details page.
1777
+	 *
1778
+	 * @return void
1779
+	 * @throws EE_Error
1780
+	 * @throws EntityNotFoundException
1781
+	 * @throws InvalidArgumentException
1782
+	 * @throws InvalidDataTypeException
1783
+	 * @throws InvalidInterfaceException
1784
+	 * @throws ReflectionException
1785
+	 * @throws RuntimeException
1786
+	 * @throws DomainException
1787
+	 */
1788
+	protected function _change_reg_status()
1789
+	{
1790
+		$this->request->setRequestParam('return', 'view_registration');
1791
+		// set notify based on whether the send notifications toggle is set or not
1792
+		$notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1793
+		$reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1794
+		$this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1795
+		switch ($reg_status) {
1796
+			case EEM_Registration::status_id_approved:
1797
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1798
+				$this->approve_registration($notify);
1799
+				break;
1800
+			case EEM_Registration::status_id_pending_payment:
1801
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1802
+				$this->pending_registration($notify);
1803
+				break;
1804
+			case EEM_Registration::status_id_not_approved:
1805
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1806
+				$this->not_approve_registration($notify);
1807
+				break;
1808
+			case EEM_Registration::status_id_declined:
1809
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1810
+				$this->decline_registration($notify);
1811
+				break;
1812
+			case EEM_Registration::status_id_cancelled:
1813
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1814
+				$this->cancel_registration($notify);
1815
+				break;
1816
+			case EEM_Registration::status_id_wait_list:
1817
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1818
+				$this->wait_list_registration($notify);
1819
+				break;
1820
+			case EEM_Registration::status_id_incomplete:
1821
+			default:
1822
+				$this->request->unSetRequestParam('return');
1823
+				$this->_reg_status_change_return('');
1824
+				break;
1825
+		}
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * Callback for bulk action routes.
1831
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1832
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1833
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1834
+	 * when an action is happening on just a single registration).
1835
+	 *
1836
+	 * @param      $action
1837
+	 * @param bool $notify
1838
+	 */
1839
+	protected function bulk_action_on_registrations($action, $notify = false)
1840
+	{
1841
+		do_action(
1842
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1843
+			$this,
1844
+			$action,
1845
+			$notify
1846
+		);
1847
+		$method = $action . '_registration';
1848
+		if (method_exists($this, $method)) {
1849
+			$this->$method($notify);
1850
+		}
1851
+	}
1852
+
1853
+
1854
+	/**
1855
+	 * approve_registration
1856
+	 *
1857
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1858
+	 * @return void
1859
+	 * @throws EE_Error
1860
+	 * @throws EntityNotFoundException
1861
+	 * @throws InvalidArgumentException
1862
+	 * @throws InvalidDataTypeException
1863
+	 * @throws InvalidInterfaceException
1864
+	 * @throws ReflectionException
1865
+	 * @throws RuntimeException
1866
+	 * @throws DomainException
1867
+	 */
1868
+	protected function approve_registration($notify = false)
1869
+	{
1870
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 * decline_registration
1876
+	 *
1877
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1878
+	 * @return void
1879
+	 * @throws EE_Error
1880
+	 * @throws EntityNotFoundException
1881
+	 * @throws InvalidArgumentException
1882
+	 * @throws InvalidDataTypeException
1883
+	 * @throws InvalidInterfaceException
1884
+	 * @throws ReflectionException
1885
+	 * @throws RuntimeException
1886
+	 * @throws DomainException
1887
+	 */
1888
+	protected function decline_registration($notify = false)
1889
+	{
1890
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1891
+	}
1892
+
1893
+
1894
+	/**
1895
+	 * cancel_registration
1896
+	 *
1897
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1898
+	 * @return void
1899
+	 * @throws EE_Error
1900
+	 * @throws EntityNotFoundException
1901
+	 * @throws InvalidArgumentException
1902
+	 * @throws InvalidDataTypeException
1903
+	 * @throws InvalidInterfaceException
1904
+	 * @throws ReflectionException
1905
+	 * @throws RuntimeException
1906
+	 * @throws DomainException
1907
+	 */
1908
+	protected function cancel_registration($notify = false)
1909
+	{
1910
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1911
+	}
1912
+
1913
+
1914
+	/**
1915
+	 * not_approve_registration
1916
+	 *
1917
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1918
+	 * @return void
1919
+	 * @throws EE_Error
1920
+	 * @throws EntityNotFoundException
1921
+	 * @throws InvalidArgumentException
1922
+	 * @throws InvalidDataTypeException
1923
+	 * @throws InvalidInterfaceException
1924
+	 * @throws ReflectionException
1925
+	 * @throws RuntimeException
1926
+	 * @throws DomainException
1927
+	 */
1928
+	protected function not_approve_registration($notify = false)
1929
+	{
1930
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1931
+	}
1932
+
1933
+
1934
+	/**
1935
+	 * decline_registration
1936
+	 *
1937
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1938
+	 * @return void
1939
+	 * @throws EE_Error
1940
+	 * @throws EntityNotFoundException
1941
+	 * @throws InvalidArgumentException
1942
+	 * @throws InvalidDataTypeException
1943
+	 * @throws InvalidInterfaceException
1944
+	 * @throws ReflectionException
1945
+	 * @throws RuntimeException
1946
+	 * @throws DomainException
1947
+	 */
1948
+	protected function pending_registration($notify = false)
1949
+	{
1950
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1951
+	}
1952
+
1953
+
1954
+	/**
1955
+	 * waitlist_registration
1956
+	 *
1957
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1958
+	 * @return void
1959
+	 * @throws EE_Error
1960
+	 * @throws EntityNotFoundException
1961
+	 * @throws InvalidArgumentException
1962
+	 * @throws InvalidDataTypeException
1963
+	 * @throws InvalidInterfaceException
1964
+	 * @throws ReflectionException
1965
+	 * @throws RuntimeException
1966
+	 * @throws DomainException
1967
+	 */
1968
+	protected function wait_list_registration($notify = false)
1969
+	{
1970
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1971
+	}
1972
+
1973
+
1974
+	/**
1975
+	 * generates HTML for the Registration main meta box
1976
+	 *
1977
+	 * @return void
1978
+	 * @throws DomainException
1979
+	 * @throws EE_Error
1980
+	 * @throws InvalidArgumentException
1981
+	 * @throws InvalidDataTypeException
1982
+	 * @throws InvalidInterfaceException
1983
+	 * @throws ReflectionException
1984
+	 * @throws EntityNotFoundException
1985
+	 */
1986
+	public function _reg_details_meta_box()
1987
+	{
1988
+		EEH_Autoloader::register_line_item_display_autoloaders();
1989
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1990
+		EE_Registry::instance()->load_helper('Line_Item');
1991
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1992
+			: EE_Transaction::new_instance();
1993
+		$this->_session = $transaction->session_data();
1994
+		$filters        = new EE_Line_Item_Filter_Collection();
1995
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1996
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
1997
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
1998
+			$filters,
1999
+			$transaction->total_line_item()
2000
+		);
2001
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2002
+		$line_item_display                       = new EE_Line_Item_Display(
2003
+			'reg_admin_table',
2004
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2005
+		);
2006
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2007
+			$filtered_line_item_tree,
2008
+			['EE_Registration' => $this->_registration]
2009
+		);
2010
+		$attendee                                = $this->_registration->attendee();
2011
+		if (
2012
+			EE_Registry::instance()->CAP->current_user_can(
2013
+				'ee_read_transaction',
2014
+				'espresso_transactions_view_transaction'
2015
+			)
2016
+		) {
2017
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2018
+				EE_Admin_Page::add_query_args_and_nonce(
2019
+					[
2020
+						'action' => 'view_transaction',
2021
+						'TXN_ID' => $transaction->ID(),
2022
+					],
2023
+					TXN_ADMIN_URL
2024
+				),
2025
+				esc_html__(' View Transaction', 'event_espresso'),
2026
+				'button button--secondary right',
2027
+				'dashicons dashicons-cart'
2028
+			);
2029
+		} else {
2030
+			$this->_template_args['view_transaction_button'] = '';
2031
+		}
2032
+		if (
2033
+			$attendee instanceof EE_Attendee
2034
+			&& EE_Registry::instance()->CAP->current_user_can(
2035
+				'ee_send_message',
2036
+				'espresso_registrations_resend_registration'
2037
+			)
2038
+		) {
2039
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2040
+				EE_Admin_Page::add_query_args_and_nonce(
2041
+					[
2042
+						'action'      => 'resend_registration',
2043
+						'_REG_ID'     => $this->_registration->ID(),
2044
+						'redirect_to' => 'view_registration',
2045
+					],
2046
+					REG_ADMIN_URL
2047
+				),
2048
+				esc_html__(' Resend Registration', 'event_espresso'),
2049
+				'button button--secondary right',
2050
+				'dashicons dashicons-email-alt'
2051
+			);
2052
+		} else {
2053
+			$this->_template_args['resend_registration_button'] = '';
2054
+		}
2055
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2056
+		$payment                               = $transaction->get_first_related('Payment');
2057
+		$payment                               = ! $payment instanceof EE_Payment
2058
+			? EE_Payment::new_instance()
2059
+			: $payment;
2060
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2061
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2062
+			? EE_Payment_Method::new_instance()
2063
+			: $payment_method;
2064
+		$reg_details                           = [
2065
+			'payment_method'       => $payment_method->name(),
2066
+			'response_msg'         => $payment->gateway_response(),
2067
+			'registration_id'      => $this->_registration->get('REG_code'),
2068
+			'registration_session' => $this->_registration->session_ID(),
2069
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2070
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2071
+		];
2072
+		if (isset($reg_details['registration_id'])) {
2073
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2074
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2075
+				'Registration ID',
2076
+				'event_espresso'
2077
+			);
2078
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2079
+		}
2080
+		if (isset($reg_details['payment_method'])) {
2081
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2082
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2083
+				'Most Recent Payment Method',
2084
+				'event_espresso'
2085
+			);
2086
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2087
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2088
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2089
+				'Payment method response',
2090
+				'event_espresso'
2091
+			);
2092
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2093
+		}
2094
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2095
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2096
+			'Registration Session',
2097
+			'event_espresso'
2098
+		);
2099
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2100
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2101
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2102
+			'Registration placed from IP',
2103
+			'event_espresso'
2104
+		);
2105
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2106
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2107
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2108
+			'Registrant User Agent',
2109
+			'event_espresso'
2110
+		);
2111
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2112
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2113
+			[
2114
+				'action'   => 'default',
2115
+				'event_id' => $this->_registration->event_ID(),
2116
+			],
2117
+			REG_ADMIN_URL
2118
+		);
2119
+
2120
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2121
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2122
+
2123
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2124
+		EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2125
+	}
2126
+
2127
+
2128
+	/**
2129
+	 * generates HTML for the Registration Questions meta box.
2130
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2131
+	 * otherwise uses new forms system
2132
+	 *
2133
+	 * @return void
2134
+	 * @throws DomainException
2135
+	 * @throws EE_Error
2136
+	 * @throws InvalidArgumentException
2137
+	 * @throws InvalidDataTypeException
2138
+	 * @throws InvalidInterfaceException
2139
+	 * @throws ReflectionException
2140
+	 */
2141
+	public function _reg_questions_meta_box()
2142
+	{
2143
+		// allow someone to override this method entirely
2144
+		if (
2145
+			apply_filters(
2146
+				'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2147
+				true,
2148
+				$this,
2149
+				$this->_registration
2150
+			)
2151
+		) {
2152
+			$form = $this->_get_reg_custom_questions_form(
2153
+				$this->_registration->ID()
2154
+			);
2155
+
2156
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2157
+				? $form->get_html_and_js()
2158
+				: '';
2159
+
2160
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2161
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2162
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2163
+			EEH_Template::display_template($template_path, $this->_template_args);
2164
+		}
2165
+	}
2166
+
2167
+
2168
+	/**
2169
+	 * form_before_question_group
2170
+	 *
2171
+	 * @param string $output
2172
+	 * @return        string
2173
+	 * @deprecated    as of 4.8.32.rc.000
2174
+	 */
2175
+	public function form_before_question_group($output)
2176
+	{
2177
+		EE_Error::doing_it_wrong(
2178
+			__CLASS__ . '::' . __FUNCTION__,
2179
+			esc_html__(
2180
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2181
+				'event_espresso'
2182
+			),
2183
+			'4.8.32.rc.000'
2184
+		);
2185
+		return '
2186 2186
 	<table class="form-table ee-width-100">
2187 2187
 		<tbody>
2188 2188
 			';
2189
-    }
2190
-
2191
-
2192
-    /**
2193
-     * form_after_question_group
2194
-     *
2195
-     * @param string $output
2196
-     * @return        string
2197
-     * @deprecated    as of 4.8.32.rc.000
2198
-     */
2199
-    public function form_after_question_group($output)
2200
-    {
2201
-        EE_Error::doing_it_wrong(
2202
-            __CLASS__ . '::' . __FUNCTION__,
2203
-            esc_html__(
2204
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2205
-                'event_espresso'
2206
-            ),
2207
-            '4.8.32.rc.000'
2208
-        );
2209
-        return '
2189
+	}
2190
+
2191
+
2192
+	/**
2193
+	 * form_after_question_group
2194
+	 *
2195
+	 * @param string $output
2196
+	 * @return        string
2197
+	 * @deprecated    as of 4.8.32.rc.000
2198
+	 */
2199
+	public function form_after_question_group($output)
2200
+	{
2201
+		EE_Error::doing_it_wrong(
2202
+			__CLASS__ . '::' . __FUNCTION__,
2203
+			esc_html__(
2204
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2205
+				'event_espresso'
2206
+			),
2207
+			'4.8.32.rc.000'
2208
+		);
2209
+		return '
2210 2210
 			<tr class="hide-if-no-js">
2211 2211
 				<th> </th>
2212 2212
 				<td class="reg-admin-edit-attendee-question-td">
2213 2213
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2214
-               . esc_attr__('click to edit question', 'event_espresso')
2215
-               . '">
2214
+			   . esc_attr__('click to edit question', 'event_espresso')
2215
+			   . '">
2216 2216
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2217
-               . esc_html__('edit the above question group', 'event_espresso')
2218
-               . '</span>
2217
+			   . esc_html__('edit the above question group', 'event_espresso')
2218
+			   . '</span>
2219 2219
 						<div class="dashicons dashicons-edit"></div>
2220 2220
 					</a>
2221 2221
 				</td>
@@ -2223,636 +2223,636 @@  discard block
 block discarded – undo
2223 2223
 		</tbody>
2224 2224
 	</table>
2225 2225
 ';
2226
-    }
2227
-
2228
-
2229
-    /**
2230
-     * form_form_field_label_wrap
2231
-     *
2232
-     * @param string $label
2233
-     * @return        string
2234
-     * @deprecated    as of 4.8.32.rc.000
2235
-     */
2236
-    public function form_form_field_label_wrap($label)
2237
-    {
2238
-        EE_Error::doing_it_wrong(
2239
-            __CLASS__ . '::' . __FUNCTION__,
2240
-            esc_html__(
2241
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2242
-                'event_espresso'
2243
-            ),
2244
-            '4.8.32.rc.000'
2245
-        );
2246
-        return '
2226
+	}
2227
+
2228
+
2229
+	/**
2230
+	 * form_form_field_label_wrap
2231
+	 *
2232
+	 * @param string $label
2233
+	 * @return        string
2234
+	 * @deprecated    as of 4.8.32.rc.000
2235
+	 */
2236
+	public function form_form_field_label_wrap($label)
2237
+	{
2238
+		EE_Error::doing_it_wrong(
2239
+			__CLASS__ . '::' . __FUNCTION__,
2240
+			esc_html__(
2241
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2242
+				'event_espresso'
2243
+			),
2244
+			'4.8.32.rc.000'
2245
+		);
2246
+		return '
2247 2247
 			<tr>
2248 2248
 				<th>
2249 2249
 					' . $label . '
2250 2250
 				</th>';
2251
-    }
2252
-
2253
-
2254
-    /**
2255
-     * form_form_field_input__wrap
2256
-     *
2257
-     * @param string $input
2258
-     * @return        string
2259
-     * @deprecated    as of 4.8.32.rc.000
2260
-     */
2261
-    public function form_form_field_input__wrap($input)
2262
-    {
2263
-        EE_Error::doing_it_wrong(
2264
-            __CLASS__ . '::' . __FUNCTION__,
2265
-            esc_html__(
2266
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2267
-                'event_espresso'
2268
-            ),
2269
-            '4.8.32.rc.000'
2270
-        );
2271
-        return '
2251
+	}
2252
+
2253
+
2254
+	/**
2255
+	 * form_form_field_input__wrap
2256
+	 *
2257
+	 * @param string $input
2258
+	 * @return        string
2259
+	 * @deprecated    as of 4.8.32.rc.000
2260
+	 */
2261
+	public function form_form_field_input__wrap($input)
2262
+	{
2263
+		EE_Error::doing_it_wrong(
2264
+			__CLASS__ . '::' . __FUNCTION__,
2265
+			esc_html__(
2266
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2267
+				'event_espresso'
2268
+			),
2269
+			'4.8.32.rc.000'
2270
+		);
2271
+		return '
2272 2272
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2273 2273
 					' . $input . '
2274 2274
 				</td>
2275 2275
 			</tr>';
2276
-    }
2277
-
2278
-
2279
-    /**
2280
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2281
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2282
-     * to display the page
2283
-     *
2284
-     * @return void
2285
-     * @throws EE_Error
2286
-     * @throws InvalidArgumentException
2287
-     * @throws InvalidDataTypeException
2288
-     * @throws InvalidInterfaceException
2289
-     * @throws ReflectionException
2290
-     */
2291
-    protected function _update_attendee_registration_form()
2292
-    {
2293
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2294
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2295
-            $REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2296
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2297
-            if ($success) {
2298
-                $what  = esc_html__('Registration Form', 'event_espresso');
2299
-                $route = $REG_ID
2300
-                    ? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2301
-                    : ['action' => 'default'];
2302
-                $this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2303
-            }
2304
-        }
2305
-    }
2306
-
2307
-
2308
-    /**
2309
-     * Gets the form for saving registrations custom questions (if done
2310
-     * previously retrieves the cached form object, which may have validation errors in it)
2311
-     *
2312
-     * @param int $REG_ID
2313
-     * @return EE_Registration_Custom_Questions_Form
2314
-     * @throws EE_Error
2315
-     * @throws InvalidArgumentException
2316
-     * @throws InvalidDataTypeException
2317
-     * @throws InvalidInterfaceException
2318
-     * @throws ReflectionException
2319
-     */
2320
-    protected function _get_reg_custom_questions_form($REG_ID)
2321
-    {
2322
-        if (! $this->_reg_custom_questions_form) {
2323
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2324
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2325
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2326
-            );
2327
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2328
-        }
2329
-        return $this->_reg_custom_questions_form;
2330
-    }
2331
-
2332
-
2333
-    /**
2334
-     * Saves
2335
-     *
2336
-     * @param bool $REG_ID
2337
-     * @return bool
2338
-     * @throws EE_Error
2339
-     * @throws InvalidArgumentException
2340
-     * @throws InvalidDataTypeException
2341
-     * @throws InvalidInterfaceException
2342
-     * @throws ReflectionException
2343
-     */
2344
-    private function _save_reg_custom_questions_form($REG_ID = 0)
2345
-    {
2346
-        if (! $REG_ID) {
2347
-            EE_Error::add_error(
2348
-                esc_html__(
2349
-                    'An error occurred. No registration ID was received.',
2350
-                    'event_espresso'
2351
-                ),
2352
-                __FILE__,
2353
-                __FUNCTION__,
2354
-                __LINE__
2355
-            );
2356
-        }
2357
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2358
-        $form->receive_form_submission($this->request->requestParams());
2359
-        $success = false;
2360
-        if ($form->is_valid()) {
2361
-            foreach ($form->subforms() as $question_group_form) {
2362
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2363
-                    $where_conditions    = [
2364
-                        'QST_ID' => $question_id,
2365
-                        'REG_ID' => $REG_ID,
2366
-                    ];
2367
-                    $possibly_new_values = [
2368
-                        'ANS_value' => $input->normalized_value(),
2369
-                    ];
2370
-                    $answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2371
-                    if ($answer instanceof EE_Answer) {
2372
-                        $success = $answer->save($possibly_new_values);
2373
-                    } else {
2374
-                        // insert it then
2375
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2376
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2377
-                        $success     = $answer->save();
2378
-                    }
2379
-                }
2380
-            }
2381
-        } else {
2382
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2383
-        }
2384
-        return $success;
2385
-    }
2386
-
2387
-
2388
-    /**
2389
-     * generates HTML for the Registration main meta box
2390
-     *
2391
-     * @return void
2392
-     * @throws DomainException
2393
-     * @throws EE_Error
2394
-     * @throws InvalidArgumentException
2395
-     * @throws InvalidDataTypeException
2396
-     * @throws InvalidInterfaceException
2397
-     * @throws ReflectionException
2398
-     */
2399
-    public function _reg_attendees_meta_box()
2400
-    {
2401
-        $REG = $this->getRegistrationModel();
2402
-        // get all other registrations on this transaction, and cache
2403
-        // the attendees for them so we don't have to run another query using force_join
2404
-        $registrations                           = $REG->get_all(
2405
-            [
2406
-                [
2407
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2408
-                    'REG_ID' => ['!=', $this->_registration->ID()],
2409
-                ],
2410
-                'force_join'               => ['Attendee'],
2411
-                'default_where_conditions' => 'other_models_only',
2412
-            ]
2413
-        );
2414
-        $this->_template_args['attendees']       = [];
2415
-        $this->_template_args['attendee_notice'] = '';
2416
-        if (
2417
-            empty($registrations)
2418
-            || (is_array($registrations)
2419
-                && ! EEH_Array::get_one_item_from_array($registrations))
2420
-        ) {
2421
-            EE_Error::add_error(
2422
-                esc_html__(
2423
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2424
-                    'event_espresso'
2425
-                ),
2426
-                __FILE__,
2427
-                __FUNCTION__,
2428
-                __LINE__
2429
-            );
2430
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2431
-        } else {
2432
-            $att_nmbr = 1;
2433
-            foreach ($registrations as $registration) {
2434
-                /* @var $registration EE_Registration */
2435
-                $attendee                                                      = $registration->attendee()
2436
-                    ? $registration->attendee()
2437
-                    : $this->getAttendeeModel()->create_default_object();
2438
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2439
-                $this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2440
-                $this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2441
-                $this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2442
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2443
-                $this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2444
-                    ', ',
2445
-                    $attendee->full_address_as_array()
2446
-                );
2447
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2448
-                    [
2449
-                        'action' => 'edit_attendee',
2450
-                        'post'   => $attendee->ID(),
2451
-                    ],
2452
-                    REG_ADMIN_URL
2453
-                );
2454
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2455
-                    $registration->event_obj() instanceof EE_Event
2456
-                        ? $registration->event_obj()->name()
2457
-                        : '';
2458
-                $att_nmbr++;
2459
-            }
2460
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2461
-        }
2462
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2463
-        EEH_Template::display_template($template_path, $this->_template_args);
2464
-    }
2465
-
2466
-
2467
-    /**
2468
-     * generates HTML for the Edit Registration side meta box
2469
-     *
2470
-     * @return void
2471
-     * @throws DomainException
2472
-     * @throws EE_Error
2473
-     * @throws InvalidArgumentException
2474
-     * @throws InvalidDataTypeException
2475
-     * @throws InvalidInterfaceException
2476
-     * @throws ReflectionException
2477
-     */
2478
-    public function _reg_registrant_side_meta_box()
2479
-    {
2480
-        /*@var $attendee EE_Attendee */
2481
-        $att_check = $this->_registration->attendee();
2482
-        $attendee  = $att_check instanceof EE_Attendee
2483
-            ? $att_check
2484
-            : $this->getAttendeeModel()->create_default_object();
2485
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2486
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2487
-        // primary registration object (that way we know if we need to show create button or not)
2488
-        if (! $this->_registration->is_primary_registrant()) {
2489
-            $primary_registration = $this->_registration->get_primary_registration();
2490
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2491
-                : null;
2492
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2493
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2494
-                // custom attendee object so let's not worry about the primary reg.
2495
-                $primary_registration = null;
2496
-            }
2497
-        } else {
2498
-            $primary_registration = null;
2499
-        }
2500
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2501
-        $this->_template_args['fname']             = $attendee->fname();
2502
-        $this->_template_args['lname']             = $attendee->lname();
2503
-        $this->_template_args['email']             = $attendee->email();
2504
-        $this->_template_args['phone']             = $attendee->phone();
2505
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2506
-        // edit link
2507
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2508
-            [
2509
-                'action' => 'edit_attendee',
2510
-                'post'   => $attendee->ID(),
2511
-            ],
2512
-            REG_ADMIN_URL
2513
-        );
2514
-        $this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2515
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2516
-        // create link
2517
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2518
-            ? EE_Admin_Page::add_query_args_and_nonce(
2519
-                [
2520
-                    'action'  => 'duplicate_attendee',
2521
-                    '_REG_ID' => $this->_registration->ID(),
2522
-                ],
2523
-                REG_ADMIN_URL
2524
-            ) : '';
2525
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2526
-        $this->_template_args['att_check'] = $att_check;
2527
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2528
-        EEH_Template::display_template($template_path, $this->_template_args);
2529
-    }
2530
-
2531
-
2532
-    /**
2533
-     * trash or restore registrations
2534
-     *
2535
-     * @param boolean $trash whether to archive or restore
2536
-     * @return void
2537
-     * @throws EE_Error
2538
-     * @throws InvalidArgumentException
2539
-     * @throws InvalidDataTypeException
2540
-     * @throws InvalidInterfaceException
2541
-     * @throws RuntimeException
2542
-     */
2543
-    protected function _trash_or_restore_registrations($trash = true)
2544
-    {
2545
-        // if empty _REG_ID then get out because there's nothing to do
2546
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2547
-        if (empty($REG_IDs)) {
2548
-            EE_Error::add_error(
2549
-                sprintf(
2550
-                    esc_html__(
2551
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2552
-                        'event_espresso'
2553
-                    ),
2554
-                    $trash ? 'trash' : 'restore'
2555
-                ),
2556
-                __FILE__,
2557
-                __LINE__,
2558
-                __FUNCTION__
2559
-            );
2560
-            $this->_redirect_after_action(false, '', '', [], true);
2561
-        }
2562
-        $success        = 0;
2563
-        $overwrite_msgs = false;
2564
-        // Checkboxes
2565
-        $reg_count = count($REG_IDs);
2566
-        // cycle thru checkboxes
2567
-        foreach ($REG_IDs as $REG_ID) {
2568
-            /** @var EE_Registration $REG */
2569
-            $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2570
-            $payments = $REG->registration_payments();
2571
-            if (! empty($payments)) {
2572
-                $name           = $REG->attendee() instanceof EE_Attendee
2573
-                    ? $REG->attendee()->full_name()
2574
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2575
-                $overwrite_msgs = true;
2576
-                EE_Error::add_error(
2577
-                    sprintf(
2578
-                        esc_html__(
2579
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2580
-                            'event_espresso'
2581
-                        ),
2582
-                        $name
2583
-                    ),
2584
-                    __FILE__,
2585
-                    __FUNCTION__,
2586
-                    __LINE__
2587
-                );
2588
-                // can't trash this registration because it has payments.
2589
-                continue;
2590
-            }
2591
-            $updated = $trash ? $REG->delete() : $REG->restore();
2592
-            if ($updated) {
2593
-                $success++;
2594
-            }
2595
-        }
2596
-        $this->_redirect_after_action(
2597
-            $success === $reg_count, // were ALL registrations affected?
2598
-            $success > 1
2599
-                ? esc_html__('Registrations', 'event_espresso')
2600
-                : esc_html__('Registration', 'event_espresso'),
2601
-            $trash
2602
-                ? esc_html__('moved to the trash', 'event_espresso')
2603
-                : esc_html__('restored', 'event_espresso'),
2604
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2605
-            $overwrite_msgs
2606
-        );
2607
-    }
2608
-
2609
-
2610
-    /**
2611
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2612
-     * registration but also.
2613
-     * 1. Removing relations to EE_Attendee
2614
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2615
-     * ALSO trashed.
2616
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2617
-     * 4. Removing relationships between all tickets and the related registrations
2618
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2619
-     * 6. Deleting permanently any related Checkins.
2620
-     *
2621
-     * @return void
2622
-     * @throws EE_Error
2623
-     * @throws InvalidArgumentException
2624
-     * @throws InvalidDataTypeException
2625
-     * @throws InvalidInterfaceException
2626
-     * @throws ReflectionException
2627
-     */
2628
-    protected function _delete_registrations()
2629
-    {
2630
-        $REG_MDL = $this->getRegistrationModel();
2631
-        $success = 0;
2632
-        // Checkboxes
2633
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2634
-
2635
-        if (! empty($REG_IDs)) {
2636
-            // if array has more than one element than success message should be plural
2637
-            $success = count($REG_IDs) > 1 ? 2 : 1;
2638
-            // cycle thru checkboxes
2639
-            foreach ($REG_IDs as $REG_ID) {
2640
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2641
-                if (! $REG instanceof EE_Registration) {
2642
-                    continue;
2643
-                }
2644
-                $deleted = $this->_delete_registration($REG);
2645
-                if (! $deleted) {
2646
-                    $success = 0;
2647
-                }
2648
-            }
2649
-        }
2650
-
2651
-        $what        = $success > 1
2652
-            ? esc_html__('Registrations', 'event_espresso')
2653
-            : esc_html__('Registration', 'event_espresso');
2654
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2655
-        $this->_redirect_after_action(
2656
-            $success,
2657
-            $what,
2658
-            $action_desc,
2659
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2660
-            true
2661
-        );
2662
-    }
2663
-
2664
-
2665
-    /**
2666
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2667
-     * models get affected.
2668
-     *
2669
-     * @param EE_Registration $REG registration to be deleted permanently
2670
-     * @return bool true = successful deletion, false = fail.
2671
-     * @throws EE_Error
2672
-     * @throws InvalidArgumentException
2673
-     * @throws InvalidDataTypeException
2674
-     * @throws InvalidInterfaceException
2675
-     * @throws ReflectionException
2676
-     */
2677
-    protected function _delete_registration(EE_Registration $REG)
2678
-    {
2679
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2680
-        // registrations on the transaction that are NOT trashed.
2681
-        $TXN = $REG->get_first_related('Transaction');
2682
-        if (! $TXN instanceof EE_Transaction) {
2683
-            EE_Error::add_error(
2684
-                sprintf(
2685
-                    esc_html__(
2686
-                        'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2687
-                        'event_espresso'
2688
-                    ),
2689
-                    $REG->id()
2690
-                ),
2691
-                __FILE__,
2692
-                __FUNCTION__,
2693
-                __LINE__
2694
-            );
2695
-            return false;
2696
-        }
2697
-        $REGS        = $TXN->get_many_related('Registration');
2698
-        $all_trashed = true;
2699
-        foreach ($REGS as $registration) {
2700
-            if (! $registration->get('REG_deleted')) {
2701
-                $all_trashed = false;
2702
-            }
2703
-        }
2704
-        if (! $all_trashed) {
2705
-            EE_Error::add_error(
2706
-                esc_html__(
2707
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2708
-                    'event_espresso'
2709
-                ),
2710
-                __FILE__,
2711
-                __FUNCTION__,
2712
-                __LINE__
2713
-            );
2714
-            return false;
2715
-        }
2716
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2717
-        // separately from THIS one).
2718
-        foreach ($REGS as $registration) {
2719
-            // delete related answers
2720
-            $registration->delete_related_permanently('Answer');
2721
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2722
-            $attendee = $registration->get_first_related('Attendee');
2723
-            if ($attendee instanceof EE_Attendee) {
2724
-                $registration->_remove_relation_to($attendee, 'Attendee');
2725
-            }
2726
-            // now remove relationships to tickets on this registration.
2727
-            $registration->_remove_relations('Ticket');
2728
-            // now delete permanently the checkins related to this registration.
2729
-            $registration->delete_related_permanently('Checkin');
2730
-            if ($registration->ID() === $REG->ID()) {
2731
-                continue;
2732
-            } //we don't want to delete permanently the existing registration just yet.
2733
-            // remove relation to transaction for these registrations if NOT the existing registrations
2734
-            $registration->_remove_relations('Transaction');
2735
-            // delete permanently any related messages.
2736
-            $registration->delete_related_permanently('Message');
2737
-            // now delete this registration permanently
2738
-            $registration->delete_permanently();
2739
-        }
2740
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2741
-        // (the transaction and line items should be all that's left).
2742
-        // delete the line items related to the transaction for this registration.
2743
-        $TXN->delete_related_permanently('Line_Item');
2744
-        // we need to remove all the relationships on the transaction
2745
-        $TXN->delete_related_permanently('Payment');
2746
-        $TXN->delete_related_permanently('Extra_Meta');
2747
-        $TXN->delete_related_permanently('Message');
2748
-        // now we can delete this REG permanently (and the transaction of course)
2749
-        $REG->delete_related_permanently('Transaction');
2750
-        return $REG->delete_permanently();
2751
-    }
2752
-
2753
-
2754
-    /**
2755
-     *    generates HTML for the Register New Attendee Admin page
2756
-     *
2757
-     * @throws DomainException
2758
-     * @throws EE_Error
2759
-     * @throws InvalidArgumentException
2760
-     * @throws InvalidDataTypeException
2761
-     * @throws InvalidInterfaceException
2762
-     * @throws ReflectionException
2763
-     */
2764
-    public function new_registration()
2765
-    {
2766
-        if (! $this->_set_reg_event()) {
2767
-            throw new EE_Error(
2768
-                esc_html__(
2769
-                    'Unable to continue with registering because there is no Event ID in the request',
2770
-                    'event_espresso'
2771
-                )
2772
-            );
2773
-        }
2774
-        /** @var CurrentPage $current_page */
2775
-        $current_page = $this->loader->getShared(CurrentPage::class);
2776
-        $current_page->setEspressoPage(true);
2777
-        // gotta start with a clean slate if we're not coming here via ajax
2778
-        if (
2779
-            ! $this->request->isAjax()
2780
-            && (
2781
-                ! $this->request->requestParamIsSet('processing_registration')
2782
-                || $this->request->requestParamIsSet('step_error')
2783
-            )
2784
-        ) {
2785
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2786
-        }
2787
-        $this->_template_args['event_name'] = '';
2788
-        // event name
2789
-        if ($this->_reg_event) {
2790
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2791
-            $edit_event_url                     = self::add_query_args_and_nonce(
2792
-                [
2793
-                    'action' => 'edit',
2794
-                    'post'   => $this->_reg_event->ID(),
2795
-                ],
2796
-                EVENTS_ADMIN_URL
2797
-            );
2798
-            $edit_event_lnk                     = '<a href="'
2799
-                                                  . $edit_event_url
2800
-                                                  . '" title="'
2801
-                                                  . esc_attr__('Edit ', 'event_espresso')
2802
-                                                  . $this->_reg_event->name()
2803
-                                                  . '">'
2804
-                                                  . esc_html__('Edit Event', 'event_espresso')
2805
-                                                  . '</a>';
2806
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2807
-                                                   . $edit_event_lnk
2808
-                                                   . '</span>';
2809
-        }
2810
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2811
-        if ($this->request->isAjax()) {
2812
-            $this->_return_json();
2813
-        }
2814
-        // grab header
2815
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2816
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2817
-            $template_path,
2818
-            $this->_template_args,
2819
-            true
2820
-        );
2821
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2822
-        // the details template wrapper
2823
-        $this->display_admin_page_with_sidebar();
2824
-    }
2825
-
2826
-
2827
-    /**
2828
-     * This returns the content for a registration step
2829
-     *
2830
-     * @return string html
2831
-     * @throws DomainException
2832
-     * @throws EE_Error
2833
-     * @throws InvalidArgumentException
2834
-     * @throws InvalidDataTypeException
2835
-     * @throws InvalidInterfaceException
2836
-     * @throws ReflectionException
2837
-     */
2838
-    protected function _get_registration_step_content()
2839
-    {
2840
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2841
-            $warning_msg = sprintf(
2842
-                esc_html__(
2843
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2844
-                    'event_espresso'
2845
-                ),
2846
-                '<br />',
2847
-                '<h3 class="important-notice">',
2848
-                '</h3>',
2849
-                '<div class="float-right">',
2850
-                '<span id="redirect_timer" class="important-notice">30</span>',
2851
-                '</div>',
2852
-                '<b>',
2853
-                '</b>'
2854
-            );
2855
-            return '
2276
+	}
2277
+
2278
+
2279
+	/**
2280
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2281
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2282
+	 * to display the page
2283
+	 *
2284
+	 * @return void
2285
+	 * @throws EE_Error
2286
+	 * @throws InvalidArgumentException
2287
+	 * @throws InvalidDataTypeException
2288
+	 * @throws InvalidInterfaceException
2289
+	 * @throws ReflectionException
2290
+	 */
2291
+	protected function _update_attendee_registration_form()
2292
+	{
2293
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2294
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2295
+			$REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2296
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2297
+			if ($success) {
2298
+				$what  = esc_html__('Registration Form', 'event_espresso');
2299
+				$route = $REG_ID
2300
+					? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2301
+					: ['action' => 'default'];
2302
+				$this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2303
+			}
2304
+		}
2305
+	}
2306
+
2307
+
2308
+	/**
2309
+	 * Gets the form for saving registrations custom questions (if done
2310
+	 * previously retrieves the cached form object, which may have validation errors in it)
2311
+	 *
2312
+	 * @param int $REG_ID
2313
+	 * @return EE_Registration_Custom_Questions_Form
2314
+	 * @throws EE_Error
2315
+	 * @throws InvalidArgumentException
2316
+	 * @throws InvalidDataTypeException
2317
+	 * @throws InvalidInterfaceException
2318
+	 * @throws ReflectionException
2319
+	 */
2320
+	protected function _get_reg_custom_questions_form($REG_ID)
2321
+	{
2322
+		if (! $this->_reg_custom_questions_form) {
2323
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2324
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2325
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2326
+			);
2327
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2328
+		}
2329
+		return $this->_reg_custom_questions_form;
2330
+	}
2331
+
2332
+
2333
+	/**
2334
+	 * Saves
2335
+	 *
2336
+	 * @param bool $REG_ID
2337
+	 * @return bool
2338
+	 * @throws EE_Error
2339
+	 * @throws InvalidArgumentException
2340
+	 * @throws InvalidDataTypeException
2341
+	 * @throws InvalidInterfaceException
2342
+	 * @throws ReflectionException
2343
+	 */
2344
+	private function _save_reg_custom_questions_form($REG_ID = 0)
2345
+	{
2346
+		if (! $REG_ID) {
2347
+			EE_Error::add_error(
2348
+				esc_html__(
2349
+					'An error occurred. No registration ID was received.',
2350
+					'event_espresso'
2351
+				),
2352
+				__FILE__,
2353
+				__FUNCTION__,
2354
+				__LINE__
2355
+			);
2356
+		}
2357
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2358
+		$form->receive_form_submission($this->request->requestParams());
2359
+		$success = false;
2360
+		if ($form->is_valid()) {
2361
+			foreach ($form->subforms() as $question_group_form) {
2362
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2363
+					$where_conditions    = [
2364
+						'QST_ID' => $question_id,
2365
+						'REG_ID' => $REG_ID,
2366
+					];
2367
+					$possibly_new_values = [
2368
+						'ANS_value' => $input->normalized_value(),
2369
+					];
2370
+					$answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2371
+					if ($answer instanceof EE_Answer) {
2372
+						$success = $answer->save($possibly_new_values);
2373
+					} else {
2374
+						// insert it then
2375
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2376
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2377
+						$success     = $answer->save();
2378
+					}
2379
+				}
2380
+			}
2381
+		} else {
2382
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2383
+		}
2384
+		return $success;
2385
+	}
2386
+
2387
+
2388
+	/**
2389
+	 * generates HTML for the Registration main meta box
2390
+	 *
2391
+	 * @return void
2392
+	 * @throws DomainException
2393
+	 * @throws EE_Error
2394
+	 * @throws InvalidArgumentException
2395
+	 * @throws InvalidDataTypeException
2396
+	 * @throws InvalidInterfaceException
2397
+	 * @throws ReflectionException
2398
+	 */
2399
+	public function _reg_attendees_meta_box()
2400
+	{
2401
+		$REG = $this->getRegistrationModel();
2402
+		// get all other registrations on this transaction, and cache
2403
+		// the attendees for them so we don't have to run another query using force_join
2404
+		$registrations                           = $REG->get_all(
2405
+			[
2406
+				[
2407
+					'TXN_ID' => $this->_registration->transaction_ID(),
2408
+					'REG_ID' => ['!=', $this->_registration->ID()],
2409
+				],
2410
+				'force_join'               => ['Attendee'],
2411
+				'default_where_conditions' => 'other_models_only',
2412
+			]
2413
+		);
2414
+		$this->_template_args['attendees']       = [];
2415
+		$this->_template_args['attendee_notice'] = '';
2416
+		if (
2417
+			empty($registrations)
2418
+			|| (is_array($registrations)
2419
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2420
+		) {
2421
+			EE_Error::add_error(
2422
+				esc_html__(
2423
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2424
+					'event_espresso'
2425
+				),
2426
+				__FILE__,
2427
+				__FUNCTION__,
2428
+				__LINE__
2429
+			);
2430
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2431
+		} else {
2432
+			$att_nmbr = 1;
2433
+			foreach ($registrations as $registration) {
2434
+				/* @var $registration EE_Registration */
2435
+				$attendee                                                      = $registration->attendee()
2436
+					? $registration->attendee()
2437
+					: $this->getAttendeeModel()->create_default_object();
2438
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2439
+				$this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2440
+				$this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2441
+				$this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2442
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2443
+				$this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2444
+					', ',
2445
+					$attendee->full_address_as_array()
2446
+				);
2447
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2448
+					[
2449
+						'action' => 'edit_attendee',
2450
+						'post'   => $attendee->ID(),
2451
+					],
2452
+					REG_ADMIN_URL
2453
+				);
2454
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2455
+					$registration->event_obj() instanceof EE_Event
2456
+						? $registration->event_obj()->name()
2457
+						: '';
2458
+				$att_nmbr++;
2459
+			}
2460
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2461
+		}
2462
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2463
+		EEH_Template::display_template($template_path, $this->_template_args);
2464
+	}
2465
+
2466
+
2467
+	/**
2468
+	 * generates HTML for the Edit Registration side meta box
2469
+	 *
2470
+	 * @return void
2471
+	 * @throws DomainException
2472
+	 * @throws EE_Error
2473
+	 * @throws InvalidArgumentException
2474
+	 * @throws InvalidDataTypeException
2475
+	 * @throws InvalidInterfaceException
2476
+	 * @throws ReflectionException
2477
+	 */
2478
+	public function _reg_registrant_side_meta_box()
2479
+	{
2480
+		/*@var $attendee EE_Attendee */
2481
+		$att_check = $this->_registration->attendee();
2482
+		$attendee  = $att_check instanceof EE_Attendee
2483
+			? $att_check
2484
+			: $this->getAttendeeModel()->create_default_object();
2485
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2486
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2487
+		// primary registration object (that way we know if we need to show create button or not)
2488
+		if (! $this->_registration->is_primary_registrant()) {
2489
+			$primary_registration = $this->_registration->get_primary_registration();
2490
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2491
+				: null;
2492
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2493
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2494
+				// custom attendee object so let's not worry about the primary reg.
2495
+				$primary_registration = null;
2496
+			}
2497
+		} else {
2498
+			$primary_registration = null;
2499
+		}
2500
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2501
+		$this->_template_args['fname']             = $attendee->fname();
2502
+		$this->_template_args['lname']             = $attendee->lname();
2503
+		$this->_template_args['email']             = $attendee->email();
2504
+		$this->_template_args['phone']             = $attendee->phone();
2505
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2506
+		// edit link
2507
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2508
+			[
2509
+				'action' => 'edit_attendee',
2510
+				'post'   => $attendee->ID(),
2511
+			],
2512
+			REG_ADMIN_URL
2513
+		);
2514
+		$this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2515
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2516
+		// create link
2517
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2518
+			? EE_Admin_Page::add_query_args_and_nonce(
2519
+				[
2520
+					'action'  => 'duplicate_attendee',
2521
+					'_REG_ID' => $this->_registration->ID(),
2522
+				],
2523
+				REG_ADMIN_URL
2524
+			) : '';
2525
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2526
+		$this->_template_args['att_check'] = $att_check;
2527
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2528
+		EEH_Template::display_template($template_path, $this->_template_args);
2529
+	}
2530
+
2531
+
2532
+	/**
2533
+	 * trash or restore registrations
2534
+	 *
2535
+	 * @param boolean $trash whether to archive or restore
2536
+	 * @return void
2537
+	 * @throws EE_Error
2538
+	 * @throws InvalidArgumentException
2539
+	 * @throws InvalidDataTypeException
2540
+	 * @throws InvalidInterfaceException
2541
+	 * @throws RuntimeException
2542
+	 */
2543
+	protected function _trash_or_restore_registrations($trash = true)
2544
+	{
2545
+		// if empty _REG_ID then get out because there's nothing to do
2546
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2547
+		if (empty($REG_IDs)) {
2548
+			EE_Error::add_error(
2549
+				sprintf(
2550
+					esc_html__(
2551
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2552
+						'event_espresso'
2553
+					),
2554
+					$trash ? 'trash' : 'restore'
2555
+				),
2556
+				__FILE__,
2557
+				__LINE__,
2558
+				__FUNCTION__
2559
+			);
2560
+			$this->_redirect_after_action(false, '', '', [], true);
2561
+		}
2562
+		$success        = 0;
2563
+		$overwrite_msgs = false;
2564
+		// Checkboxes
2565
+		$reg_count = count($REG_IDs);
2566
+		// cycle thru checkboxes
2567
+		foreach ($REG_IDs as $REG_ID) {
2568
+			/** @var EE_Registration $REG */
2569
+			$REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2570
+			$payments = $REG->registration_payments();
2571
+			if (! empty($payments)) {
2572
+				$name           = $REG->attendee() instanceof EE_Attendee
2573
+					? $REG->attendee()->full_name()
2574
+					: esc_html__('Unknown Attendee', 'event_espresso');
2575
+				$overwrite_msgs = true;
2576
+				EE_Error::add_error(
2577
+					sprintf(
2578
+						esc_html__(
2579
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2580
+							'event_espresso'
2581
+						),
2582
+						$name
2583
+					),
2584
+					__FILE__,
2585
+					__FUNCTION__,
2586
+					__LINE__
2587
+				);
2588
+				// can't trash this registration because it has payments.
2589
+				continue;
2590
+			}
2591
+			$updated = $trash ? $REG->delete() : $REG->restore();
2592
+			if ($updated) {
2593
+				$success++;
2594
+			}
2595
+		}
2596
+		$this->_redirect_after_action(
2597
+			$success === $reg_count, // were ALL registrations affected?
2598
+			$success > 1
2599
+				? esc_html__('Registrations', 'event_espresso')
2600
+				: esc_html__('Registration', 'event_espresso'),
2601
+			$trash
2602
+				? esc_html__('moved to the trash', 'event_espresso')
2603
+				: esc_html__('restored', 'event_espresso'),
2604
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2605
+			$overwrite_msgs
2606
+		);
2607
+	}
2608
+
2609
+
2610
+	/**
2611
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2612
+	 * registration but also.
2613
+	 * 1. Removing relations to EE_Attendee
2614
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2615
+	 * ALSO trashed.
2616
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2617
+	 * 4. Removing relationships between all tickets and the related registrations
2618
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2619
+	 * 6. Deleting permanently any related Checkins.
2620
+	 *
2621
+	 * @return void
2622
+	 * @throws EE_Error
2623
+	 * @throws InvalidArgumentException
2624
+	 * @throws InvalidDataTypeException
2625
+	 * @throws InvalidInterfaceException
2626
+	 * @throws ReflectionException
2627
+	 */
2628
+	protected function _delete_registrations()
2629
+	{
2630
+		$REG_MDL = $this->getRegistrationModel();
2631
+		$success = 0;
2632
+		// Checkboxes
2633
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2634
+
2635
+		if (! empty($REG_IDs)) {
2636
+			// if array has more than one element than success message should be plural
2637
+			$success = count($REG_IDs) > 1 ? 2 : 1;
2638
+			// cycle thru checkboxes
2639
+			foreach ($REG_IDs as $REG_ID) {
2640
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2641
+				if (! $REG instanceof EE_Registration) {
2642
+					continue;
2643
+				}
2644
+				$deleted = $this->_delete_registration($REG);
2645
+				if (! $deleted) {
2646
+					$success = 0;
2647
+				}
2648
+			}
2649
+		}
2650
+
2651
+		$what        = $success > 1
2652
+			? esc_html__('Registrations', 'event_espresso')
2653
+			: esc_html__('Registration', 'event_espresso');
2654
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2655
+		$this->_redirect_after_action(
2656
+			$success,
2657
+			$what,
2658
+			$action_desc,
2659
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2660
+			true
2661
+		);
2662
+	}
2663
+
2664
+
2665
+	/**
2666
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2667
+	 * models get affected.
2668
+	 *
2669
+	 * @param EE_Registration $REG registration to be deleted permanently
2670
+	 * @return bool true = successful deletion, false = fail.
2671
+	 * @throws EE_Error
2672
+	 * @throws InvalidArgumentException
2673
+	 * @throws InvalidDataTypeException
2674
+	 * @throws InvalidInterfaceException
2675
+	 * @throws ReflectionException
2676
+	 */
2677
+	protected function _delete_registration(EE_Registration $REG)
2678
+	{
2679
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2680
+		// registrations on the transaction that are NOT trashed.
2681
+		$TXN = $REG->get_first_related('Transaction');
2682
+		if (! $TXN instanceof EE_Transaction) {
2683
+			EE_Error::add_error(
2684
+				sprintf(
2685
+					esc_html__(
2686
+						'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2687
+						'event_espresso'
2688
+					),
2689
+					$REG->id()
2690
+				),
2691
+				__FILE__,
2692
+				__FUNCTION__,
2693
+				__LINE__
2694
+			);
2695
+			return false;
2696
+		}
2697
+		$REGS        = $TXN->get_many_related('Registration');
2698
+		$all_trashed = true;
2699
+		foreach ($REGS as $registration) {
2700
+			if (! $registration->get('REG_deleted')) {
2701
+				$all_trashed = false;
2702
+			}
2703
+		}
2704
+		if (! $all_trashed) {
2705
+			EE_Error::add_error(
2706
+				esc_html__(
2707
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2708
+					'event_espresso'
2709
+				),
2710
+				__FILE__,
2711
+				__FUNCTION__,
2712
+				__LINE__
2713
+			);
2714
+			return false;
2715
+		}
2716
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2717
+		// separately from THIS one).
2718
+		foreach ($REGS as $registration) {
2719
+			// delete related answers
2720
+			$registration->delete_related_permanently('Answer');
2721
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2722
+			$attendee = $registration->get_first_related('Attendee');
2723
+			if ($attendee instanceof EE_Attendee) {
2724
+				$registration->_remove_relation_to($attendee, 'Attendee');
2725
+			}
2726
+			// now remove relationships to tickets on this registration.
2727
+			$registration->_remove_relations('Ticket');
2728
+			// now delete permanently the checkins related to this registration.
2729
+			$registration->delete_related_permanently('Checkin');
2730
+			if ($registration->ID() === $REG->ID()) {
2731
+				continue;
2732
+			} //we don't want to delete permanently the existing registration just yet.
2733
+			// remove relation to transaction for these registrations if NOT the existing registrations
2734
+			$registration->_remove_relations('Transaction');
2735
+			// delete permanently any related messages.
2736
+			$registration->delete_related_permanently('Message');
2737
+			// now delete this registration permanently
2738
+			$registration->delete_permanently();
2739
+		}
2740
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2741
+		// (the transaction and line items should be all that's left).
2742
+		// delete the line items related to the transaction for this registration.
2743
+		$TXN->delete_related_permanently('Line_Item');
2744
+		// we need to remove all the relationships on the transaction
2745
+		$TXN->delete_related_permanently('Payment');
2746
+		$TXN->delete_related_permanently('Extra_Meta');
2747
+		$TXN->delete_related_permanently('Message');
2748
+		// now we can delete this REG permanently (and the transaction of course)
2749
+		$REG->delete_related_permanently('Transaction');
2750
+		return $REG->delete_permanently();
2751
+	}
2752
+
2753
+
2754
+	/**
2755
+	 *    generates HTML for the Register New Attendee Admin page
2756
+	 *
2757
+	 * @throws DomainException
2758
+	 * @throws EE_Error
2759
+	 * @throws InvalidArgumentException
2760
+	 * @throws InvalidDataTypeException
2761
+	 * @throws InvalidInterfaceException
2762
+	 * @throws ReflectionException
2763
+	 */
2764
+	public function new_registration()
2765
+	{
2766
+		if (! $this->_set_reg_event()) {
2767
+			throw new EE_Error(
2768
+				esc_html__(
2769
+					'Unable to continue with registering because there is no Event ID in the request',
2770
+					'event_espresso'
2771
+				)
2772
+			);
2773
+		}
2774
+		/** @var CurrentPage $current_page */
2775
+		$current_page = $this->loader->getShared(CurrentPage::class);
2776
+		$current_page->setEspressoPage(true);
2777
+		// gotta start with a clean slate if we're not coming here via ajax
2778
+		if (
2779
+			! $this->request->isAjax()
2780
+			&& (
2781
+				! $this->request->requestParamIsSet('processing_registration')
2782
+				|| $this->request->requestParamIsSet('step_error')
2783
+			)
2784
+		) {
2785
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2786
+		}
2787
+		$this->_template_args['event_name'] = '';
2788
+		// event name
2789
+		if ($this->_reg_event) {
2790
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2791
+			$edit_event_url                     = self::add_query_args_and_nonce(
2792
+				[
2793
+					'action' => 'edit',
2794
+					'post'   => $this->_reg_event->ID(),
2795
+				],
2796
+				EVENTS_ADMIN_URL
2797
+			);
2798
+			$edit_event_lnk                     = '<a href="'
2799
+												  . $edit_event_url
2800
+												  . '" title="'
2801
+												  . esc_attr__('Edit ', 'event_espresso')
2802
+												  . $this->_reg_event->name()
2803
+												  . '">'
2804
+												  . esc_html__('Edit Event', 'event_espresso')
2805
+												  . '</a>';
2806
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2807
+												   . $edit_event_lnk
2808
+												   . '</span>';
2809
+		}
2810
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2811
+		if ($this->request->isAjax()) {
2812
+			$this->_return_json();
2813
+		}
2814
+		// grab header
2815
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2816
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2817
+			$template_path,
2818
+			$this->_template_args,
2819
+			true
2820
+		);
2821
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2822
+		// the details template wrapper
2823
+		$this->display_admin_page_with_sidebar();
2824
+	}
2825
+
2826
+
2827
+	/**
2828
+	 * This returns the content for a registration step
2829
+	 *
2830
+	 * @return string html
2831
+	 * @throws DomainException
2832
+	 * @throws EE_Error
2833
+	 * @throws InvalidArgumentException
2834
+	 * @throws InvalidDataTypeException
2835
+	 * @throws InvalidInterfaceException
2836
+	 * @throws ReflectionException
2837
+	 */
2838
+	protected function _get_registration_step_content()
2839
+	{
2840
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2841
+			$warning_msg = sprintf(
2842
+				esc_html__(
2843
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2844
+					'event_espresso'
2845
+				),
2846
+				'<br />',
2847
+				'<h3 class="important-notice">',
2848
+				'</h3>',
2849
+				'<div class="float-right">',
2850
+				'<span id="redirect_timer" class="important-notice">30</span>',
2851
+				'</div>',
2852
+				'<b>',
2853
+				'</b>'
2854
+			);
2855
+			return '
2856 2856
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2857 2857
 	<script >
2858 2858
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2865,844 +2865,844 @@  discard block
 block discarded – undo
2865 2865
 	        }
2866 2866
 	    }, 800 );
2867 2867
 	</script >';
2868
-        }
2869
-        $template_args = [
2870
-            'title'                    => '',
2871
-            'content'                  => '',
2872
-            'step_button_text'         => '',
2873
-            'show_notification_toggle' => false,
2874
-        ];
2875
-        // to indicate we're processing a new registration
2876
-        $hidden_fields = [
2877
-            'processing_registration' => [
2878
-                'type'  => 'hidden',
2879
-                'value' => 0,
2880
-            ],
2881
-            'event_id'                => [
2882
-                'type'  => 'hidden',
2883
-                'value' => $this->_reg_event->ID(),
2884
-            ],
2885
-        ];
2886
-        // if the cart is empty then we know we're at step one, so we'll display the ticket selector
2887
-        $cart = EE_Registry::instance()->SSN->cart();
2888
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2889
-        switch ($step) {
2890
-            case 'ticket':
2891
-                $hidden_fields['processing_registration']['value'] = 1;
2892
-                $template_args['title']                            = esc_html__(
2893
-                    'Step One: Select the Ticket for this registration',
2894
-                    'event_espresso'
2895
-                );
2896
-                $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2897
-                $template_args['content'] .= '</div>';
2898
-                $template_args['step_button_text'] = esc_html__(
2899
-                    'Add Tickets and Continue to Registrant Details',
2900
-                    'event_espresso'
2901
-                );
2902
-                $template_args['show_notification_toggle']         = false;
2903
-                break;
2904
-            case 'questions':
2905
-                $hidden_fields['processing_registration']['value'] = 2;
2906
-                $template_args['title']                            = esc_html__(
2907
-                    'Step Two: Add Registrant Details for this Registration',
2908
-                    'event_espresso'
2909
-                );
2910
-                // in theory, we should be able to run EED_SPCO at this point
2911
-                // because the cart should have been set up properly by the first process_reg_step run.
2912
-                $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2913
-                $template_args['step_button_text'] = esc_html__(
2914
-                    'Save Registration and Continue to Details',
2915
-                    'event_espresso'
2916
-                );
2917
-                $template_args['show_notification_toggle'] = true;
2918
-                break;
2919
-        }
2920
-        // we come back to the process_registration_step route.
2921
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2922
-        return EEH_Template::display_template(
2923
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2924
-            $template_args,
2925
-            true
2926
-        );
2927
-    }
2928
-
2929
-
2930
-    /**
2931
-     * set_reg_event
2932
-     *
2933
-     * @return bool
2934
-     * @throws EE_Error
2935
-     * @throws InvalidArgumentException
2936
-     * @throws InvalidDataTypeException
2937
-     * @throws InvalidInterfaceException
2938
-     */
2939
-    private function _set_reg_event()
2940
-    {
2941
-        if (is_object($this->_reg_event)) {
2942
-            return true;
2943
-        }
2944
-
2945
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2946
-        if (! $EVT_ID) {
2947
-            return false;
2948
-        }
2949
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2950
-        return true;
2951
-    }
2952
-
2953
-
2954
-    /**
2955
-     * process_reg_step
2956
-     *
2957
-     * @return void
2958
-     * @throws DomainException
2959
-     * @throws EE_Error
2960
-     * @throws InvalidArgumentException
2961
-     * @throws InvalidDataTypeException
2962
-     * @throws InvalidInterfaceException
2963
-     * @throws ReflectionException
2964
-     * @throws RuntimeException
2965
-     */
2966
-    public function process_reg_step()
2967
-    {
2968
-        EE_System::do_not_cache();
2969
-        $this->_set_reg_event();
2970
-        /** @var CurrentPage $current_page */
2971
-        $current_page = $this->loader->getShared(CurrentPage::class);
2972
-        $current_page->setEspressoPage(true);
2973
-        $this->request->setRequestParam('uts', time());
2974
-        // what step are we on?
2975
-        $cart = EE_Registry::instance()->SSN->cart();
2976
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2977
-        // if doing ajax then we need to verify the nonce
2978
-        if ($this->request->isAjax()) {
2979
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
2980
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2981
-        }
2982
-        switch ($step) {
2983
-            case 'ticket':
2984
-                // process ticket selection
2985
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2986
-                if ($success) {
2987
-                    EE_Error::add_success(
2988
-                        esc_html__(
2989
-                            'Tickets Selected. Now complete the registration.',
2990
-                            'event_espresso'
2991
-                        )
2992
-                    );
2993
-                } else {
2994
-                    $this->request->setRequestParam('step_error', true);
2995
-                    $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
2996
-                }
2997
-                if ($this->request->isAjax()) {
2998
-                    $this->new_registration(); // display next step
2999
-                } else {
3000
-                    $query_args = [
3001
-                        'action'                  => 'new_registration',
3002
-                        'processing_registration' => 1,
3003
-                        'event_id'                => $this->_reg_event->ID(),
3004
-                        'uts'                     => time(),
3005
-                    ];
3006
-                    $this->_redirect_after_action(
3007
-                        false,
3008
-                        '',
3009
-                        '',
3010
-                        $query_args,
3011
-                        true
3012
-                    );
3013
-                }
3014
-                break;
3015
-            case 'questions':
3016
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3017
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3018
-                }
3019
-                // process registration
3020
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3021
-                if ($cart instanceof EE_Cart) {
3022
-                    $grand_total = $cart->get_grand_total();
3023
-                    if ($grand_total instanceof EE_Line_Item) {
3024
-                        $grand_total->save_this_and_descendants_to_txn();
3025
-                    }
3026
-                }
3027
-                if (! $transaction instanceof EE_Transaction) {
3028
-                    $query_args = [
3029
-                        'action'                  => 'new_registration',
3030
-                        'processing_registration' => 2,
3031
-                        'event_id'                => $this->_reg_event->ID(),
3032
-                        'uts'                     => time(),
3033
-                    ];
3034
-                    if ($this->request->isAjax()) {
3035
-                        // display registration form again because there are errors (maybe validation?)
3036
-                        $this->new_registration();
3037
-                        return;
3038
-                    }
3039
-                    $this->_redirect_after_action(
3040
-                        false,
3041
-                        '',
3042
-                        '',
3043
-                        $query_args,
3044
-                        true
3045
-                    );
3046
-                    return;
3047
-                }
3048
-                // maybe update status, and make sure to save transaction if not done already
3049
-                if (! $transaction->update_status_based_on_total_paid()) {
3050
-                    $transaction->save();
3051
-                }
3052
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3053
-                $query_args = [
3054
-                    'action'        => 'redirect_to_txn',
3055
-                    'TXN_ID'        => $transaction->ID(),
3056
-                    'EVT_ID'        => $this->_reg_event->ID(),
3057
-                    'event_name'    => urlencode($this->_reg_event->name()),
3058
-                    'redirect_from' => 'new_registration',
3059
-                ];
3060
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3061
-                break;
3062
-        }
3063
-        // what are you looking here for?  Should be nothing to do at this point.
3064
-    }
3065
-
3066
-
3067
-    /**
3068
-     * redirect_to_txn
3069
-     *
3070
-     * @return void
3071
-     * @throws EE_Error
3072
-     * @throws InvalidArgumentException
3073
-     * @throws InvalidDataTypeException
3074
-     * @throws InvalidInterfaceException
3075
-     * @throws ReflectionException
3076
-     */
3077
-    public function redirect_to_txn()
3078
-    {
3079
-        EE_System::do_not_cache();
3080
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3081
-        $query_args = [
3082
-            'action' => 'view_transaction',
3083
-            'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3084
-            'page'   => 'espresso_transactions',
3085
-        ];
3086
-        if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3087
-            $query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3088
-            $query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3089
-            $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3090
-        }
3091
-        EE_Error::add_success(
3092
-            esc_html__(
3093
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3094
-                'event_espresso'
3095
-            )
3096
-        );
3097
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3098
-    }
3099
-
3100
-
3101
-    /**
3102
-     * generates HTML for the Attendee Contact List
3103
-     *
3104
-     * @return void
3105
-     * @throws DomainException
3106
-     * @throws EE_Error
3107
-     */
3108
-    protected function _attendee_contact_list_table()
3109
-    {
3110
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3111
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3112
-        $this->display_admin_list_table_page_with_no_sidebar();
3113
-    }
3114
-
3115
-
3116
-    /**
3117
-     * get_attendees
3118
-     *
3119
-     * @param      $per_page
3120
-     * @param bool $count whether to return count or data.
3121
-     * @param bool $trash
3122
-     * @return array|int
3123
-     * @throws EE_Error
3124
-     * @throws InvalidArgumentException
3125
-     * @throws InvalidDataTypeException
3126
-     * @throws InvalidInterfaceException
3127
-     */
3128
-    public function get_attendees($per_page, $count = false, $trash = false)
3129
-    {
3130
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3131
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3132
-        $orderby = $this->request->getRequestParam('orderby');
3133
-        switch ($orderby) {
3134
-            case 'ATT_ID':
3135
-            case 'ATT_fname':
3136
-            case 'ATT_email':
3137
-            case 'ATT_city':
3138
-            case 'STA_ID':
3139
-            case 'CNT_ID':
3140
-                break;
3141
-            case 'Registration_Count':
3142
-                $orderby = 'Registration_Count';
3143
-                break;
3144
-            default:
3145
-                $orderby = 'ATT_lname';
3146
-        }
3147
-        $sort         = $this->request->getRequestParam('order', 'ASC');
3148
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
3149
-        $per_page     = absint($per_page) ? $per_page : 10;
3150
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3151
-        $_where       = [];
3152
-        $search_term  = $this->request->getRequestParam('s');
3153
-        if ($search_term) {
3154
-            $search_term  = '%' . $search_term . '%';
3155
-            $_where['OR'] = [
3156
-                'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3157
-                'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3158
-                'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3159
-                'ATT_fname'                         => ['LIKE', $search_term],
3160
-                'ATT_lname'                         => ['LIKE', $search_term],
3161
-                'ATT_short_bio'                     => ['LIKE', $search_term],
3162
-                'ATT_email'                         => ['LIKE', $search_term],
3163
-                'ATT_address'                       => ['LIKE', $search_term],
3164
-                'ATT_address2'                      => ['LIKE', $search_term],
3165
-                'ATT_city'                          => ['LIKE', $search_term],
3166
-                'Country.CNT_name'                  => ['LIKE', $search_term],
3167
-                'State.STA_name'                    => ['LIKE', $search_term],
3168
-                'ATT_phone'                         => ['LIKE', $search_term],
3169
-                'Registration.REG_final_price'      => ['LIKE', $search_term],
3170
-                'Registration.REG_code'             => ['LIKE', $search_term],
3171
-                'Registration.REG_group_size'       => ['LIKE', $search_term],
3172
-            ];
3173
-        }
3174
-        $offset     = ($current_page - 1) * $per_page;
3175
-        $limit      = $count ? null : [$offset, $per_page];
3176
-        $query_args = [
3177
-            $_where,
3178
-            'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3179
-            'limit'         => $limit,
3180
-        ];
3181
-        if (! $count) {
3182
-            $query_args['order_by'] = [$orderby => $sort];
3183
-        }
3184
-        $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3185
-        return $count
3186
-            ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3187
-            : $this->getAttendeeModel()->get_all($query_args);
3188
-    }
3189
-
3190
-
3191
-    /**
3192
-     * This is just taking care of resending the registration confirmation
3193
-     *
3194
-     * @return void
3195
-     * @throws EE_Error
3196
-     * @throws InvalidArgumentException
3197
-     * @throws InvalidDataTypeException
3198
-     * @throws InvalidInterfaceException
3199
-     * @throws ReflectionException
3200
-     */
3201
-    protected function _resend_registration()
3202
-    {
3203
-        $this->_process_resend_registration();
3204
-        $REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3205
-        $redirect_to = $this->request->getRequestParam('redirect_to');
3206
-        $query_args  = $redirect_to
3207
-            ? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3208
-            : ['action' => 'default'];
3209
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3210
-    }
3211
-
3212
-
3213
-    /**
3214
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3215
-     * to use when selecting registrations
3216
-     *
3217
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3218
-     *                                                     the query parameters from the request
3219
-     * @return void ends the request with a redirect or download
3220
-     */
3221
-    public function _registrations_report_base($method_name_for_getting_query_params)
3222
-    {
3223
-        $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3224
-            ? $this->request->getRequestParam('EVT_ID', 0, 'int')
3225
-            : null;
3226
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3227
-            $request_params = $this->request->requestParams();
3228
-            wp_redirect(
3229
-                EE_Admin_Page::add_query_args_and_nonce(
3230
-                    [
3231
-                        'page'        => 'espresso_batch',
3232
-                        'batch'       => 'file',
3233
-                        'EVT_ID'      => $EVT_ID,
3234
-                        'filters'     => urlencode(
3235
-                            serialize(
3236
-                                $this->$method_name_for_getting_query_params(
3237
-                                    EEH_Array::is_set($request_params, 'filters', [])
3238
-                                )
3239
-                            )
3240
-                        ),
3241
-                        'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3242
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3243
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3244
-                    ]
3245
-                )
3246
-            );
3247
-        } else {
3248
-            // Pull the current request params
3249
-            $request_args = $this->request->requestParams();
3250
-            // Set the required request_args to be passed to the export
3251
-            $required_request_args = [
3252
-                'export' => 'report',
3253
-                'action' => 'registrations_report_for_event',
3254
-                'EVT_ID' => $EVT_ID,
3255
-            ];
3256
-            // Merge required request args, overriding any currently set
3257
-            $request_args = array_merge($request_args, $required_request_args);
3258
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3259
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3260
-                $EE_Export = EE_Export::instance($request_args);
3261
-                $EE_Export->export();
3262
-            }
3263
-        }
3264
-    }
3265
-
3266
-
3267
-    /**
3268
-     * Creates a registration report using only query parameters in the request
3269
-     *
3270
-     * @return void
3271
-     */
3272
-    public function _registrations_report()
3273
-    {
3274
-        $this->_registrations_report_base('_get_registration_query_parameters');
3275
-    }
3276
-
3277
-
3278
-    public function _contact_list_export()
3279
-    {
3280
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3281
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3282
-            $EE_Export = EE_Export::instance($this->request->requestParams());
3283
-            $EE_Export->export_attendees();
3284
-        }
3285
-    }
3286
-
3287
-
3288
-    public function _contact_list_report()
3289
-    {
3290
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3291
-            wp_redirect(
3292
-                EE_Admin_Page::add_query_args_and_nonce(
3293
-                    [
3294
-                        'page'        => 'espresso_batch',
3295
-                        'batch'       => 'file',
3296
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3297
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3298
-                    ]
3299
-                )
3300
-            );
3301
-        } else {
3302
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3303
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3304
-                $EE_Export = EE_Export::instance($this->request->requestParams());
3305
-                $EE_Export->report_attendees();
3306
-            }
3307
-        }
3308
-    }
3309
-
3310
-
3311
-
3312
-
3313
-
3314
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3315
-    /**
3316
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3317
-     *
3318
-     * @return void
3319
-     * @throws EE_Error
3320
-     * @throws InvalidArgumentException
3321
-     * @throws InvalidDataTypeException
3322
-     * @throws InvalidInterfaceException
3323
-     * @throws ReflectionException
3324
-     */
3325
-    protected function _duplicate_attendee()
3326
-    {
3327
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3328
-        $action = $this->request->getRequestParam('return', 'default');
3329
-        // verify we have necessary info
3330
-        if (! $REG_ID) {
3331
-            EE_Error::add_error(
3332
-                esc_html__(
3333
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3334
-                    'event_espresso'
3335
-                ),
3336
-                __FILE__,
3337
-                __LINE__,
3338
-                __FUNCTION__
3339
-            );
3340
-            $query_args = ['action' => $action];
3341
-            $this->_redirect_after_action('', '', '', $query_args, true);
3342
-        }
3343
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3344
-        $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3345
-        if (! $registration instanceof EE_Registration) {
3346
-            throw new RuntimeException(
3347
-                sprintf(
3348
-                    esc_html__(
3349
-                        'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3350
-                        'event_espresso'
3351
-                    ),
3352
-                    $REG_ID
3353
-                )
3354
-            );
3355
-        }
3356
-        $attendee = $registration->attendee();
3357
-        // remove relation of existing attendee on registration
3358
-        $registration->_remove_relation_to($attendee, 'Attendee');
3359
-        // new attendee
3360
-        $new_attendee = clone $attendee;
3361
-        $new_attendee->set('ATT_ID', 0);
3362
-        $new_attendee->save();
3363
-        // add new attendee to reg
3364
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3365
-        EE_Error::add_success(
3366
-            esc_html__(
3367
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3368
-                'event_espresso'
3369
-            )
3370
-        );
3371
-        // redirect to edit page for attendee
3372
-        $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3373
-        $this->_redirect_after_action('', '', '', $query_args, true);
3374
-    }
3375
-
3376
-
3377
-    /**
3378
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3379
-     *
3380
-     * @param int     $post_id
3381
-     * @param WP_Post $post
3382
-     * @throws DomainException
3383
-     * @throws EE_Error
3384
-     * @throws InvalidArgumentException
3385
-     * @throws InvalidDataTypeException
3386
-     * @throws InvalidInterfaceException
3387
-     * @throws LogicException
3388
-     * @throws InvalidFormSubmissionException
3389
-     * @throws ReflectionException
3390
-     */
3391
-    protected function _insert_update_cpt_item($post_id, $post)
3392
-    {
3393
-        $success  = true;
3394
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3395
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3396
-            : null;
3397
-        // for attendee updates
3398
-        if ($attendee instanceof EE_Attendee) {
3399
-            // note we should only be UPDATING attendees at this point.
3400
-            $fname          = $this->request->getRequestParam('ATT_fname', '');
3401
-            $lname          = $this->request->getRequestParam('ATT_lname', '');
3402
-            $updated_fields = [
3403
-                'ATT_fname'     => $fname,
3404
-                'ATT_lname'     => $lname,
3405
-                'ATT_full_name' => "{$fname} {$lname}",
3406
-                'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3407
-                'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3408
-                'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3409
-                'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3410
-                'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3411
-                'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3412
-            ];
3413
-            foreach ($updated_fields as $field => $value) {
3414
-                $attendee->set($field, $value);
3415
-            }
3416
-
3417
-            // process contact details metabox form handler (which will also save the attendee)
3418
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3419
-            $success              = $contact_details_form->process($this->request->requestParams());
3420
-
3421
-            $attendee_update_callbacks = apply_filters(
3422
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3423
-                []
3424
-            );
3425
-            foreach ($attendee_update_callbacks as $a_callback) {
3426
-                if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3427
-                    throw new EE_Error(
3428
-                        sprintf(
3429
-                            esc_html__(
3430
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3431
-                                'event_espresso'
3432
-                            ),
3433
-                            $a_callback
3434
-                        )
3435
-                    );
3436
-                }
3437
-            }
3438
-        }
3439
-
3440
-        if ($success === false) {
3441
-            EE_Error::add_error(
3442
-                esc_html__(
3443
-                    'Something went wrong with updating the meta table data for the registration.',
3444
-                    'event_espresso'
3445
-                ),
3446
-                __FILE__,
3447
-                __FUNCTION__,
3448
-                __LINE__
3449
-            );
3450
-        }
3451
-    }
3452
-
3453
-
3454
-    public function trash_cpt_item($post_id)
3455
-    {
3456
-    }
3457
-
3458
-
3459
-    public function delete_cpt_item($post_id)
3460
-    {
3461
-    }
3462
-
3463
-
3464
-    public function restore_cpt_item($post_id)
3465
-    {
3466
-    }
3467
-
3468
-
3469
-    protected function _restore_cpt_item($post_id, $revision_id)
3470
-    {
3471
-    }
3472
-
3473
-
3474
-    /**
3475
-     * @throws EE_Error
3476
-     * @throws ReflectionException
3477
-     * @since 4.10.2.p
3478
-     */
3479
-    public function attendee_editor_metaboxes()
3480
-    {
3481
-        $this->verify_cpt_object();
3482
-        remove_meta_box(
3483
-            'postexcerpt',
3484
-            $this->_cpt_routes[ $this->_req_action ],
3485
-            'normal'
3486
-        );
3487
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3488
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3489
-            $this->addMetaBox(
3490
-                'postexcerpt',
3491
-                esc_html__('Short Biography', 'event_espresso'),
3492
-                'post_excerpt_meta_box',
3493
-                $this->_cpt_routes[ $this->_req_action ]
3494
-            );
3495
-        }
3496
-        if (post_type_supports('espresso_attendees', 'comments')) {
3497
-            $this->addMetaBox(
3498
-                'commentsdiv',
3499
-                esc_html__('Notes on the Contact', 'event_espresso'),
3500
-                'post_comment_meta_box',
3501
-                $this->_cpt_routes[ $this->_req_action ],
3502
-                'normal',
3503
-                'core'
3504
-            );
3505
-        }
3506
-        $this->addMetaBox(
3507
-            'attendee_contact_info',
3508
-            esc_html__('Contact Info', 'event_espresso'),
3509
-            [$this, 'attendee_contact_info'],
3510
-            $this->_cpt_routes[ $this->_req_action ],
3511
-            'side',
3512
-            'core'
3513
-        );
3514
-        $this->addMetaBox(
3515
-            'attendee_details_address',
3516
-            esc_html__('Address Details', 'event_espresso'),
3517
-            [$this, 'attendee_address_details'],
3518
-            $this->_cpt_routes[ $this->_req_action ],
3519
-            'normal',
3520
-            'core'
3521
-        );
3522
-        $this->addMetaBox(
3523
-            'attendee_registrations',
3524
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3525
-            [$this, 'attendee_registrations_meta_box'],
3526
-            $this->_cpt_routes[ $this->_req_action ]
3527
-        );
3528
-    }
3529
-
3530
-
3531
-    /**
3532
-     * Metabox for attendee contact info
3533
-     *
3534
-     * @param WP_Post $post wp post object
3535
-     * @return void attendee contact info ( and form )
3536
-     * @throws EE_Error
3537
-     * @throws InvalidArgumentException
3538
-     * @throws InvalidDataTypeException
3539
-     * @throws InvalidInterfaceException
3540
-     * @throws LogicException
3541
-     * @throws DomainException
3542
-     */
3543
-    public function attendee_contact_info($post)
3544
-    {
3545
-        // get attendee object ( should already have it )
3546
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3547
-        $form->enqueueStylesAndScripts();
3548
-        echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3549
-    }
3550
-
3551
-
3552
-    /**
3553
-     * Return form handler for the contact details metabox
3554
-     *
3555
-     * @param EE_Attendee $attendee
3556
-     * @return AttendeeContactDetailsMetaboxFormHandler
3557
-     * @throws DomainException
3558
-     * @throws InvalidArgumentException
3559
-     * @throws InvalidDataTypeException
3560
-     * @throws InvalidInterfaceException
3561
-     */
3562
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3563
-    {
3564
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3565
-    }
3566
-
3567
-
3568
-    /**
3569
-     * Metabox for attendee details
3570
-     *
3571
-     * @param WP_Post $post wp post object
3572
-     * @throws EE_Error
3573
-     * @throws ReflectionException
3574
-     */
3575
-    public function attendee_address_details($post)
3576
-    {
3577
-        // get attendee object (should already have it)
3578
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3579
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3580
-            new EE_Question_Form_Input(
3581
-                EE_Question::new_instance(
3582
-                    [
3583
-                        'QST_ID'           => 0,
3584
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3585
-                        'QST_system'       => 'admin-state',
3586
-                    ]
3587
-                ),
3588
-                EE_Answer::new_instance(
3589
-                    [
3590
-                        'ANS_ID'    => 0,
3591
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3592
-                    ]
3593
-                ),
3594
-                [
3595
-                    'input_id'       => 'STA_ID',
3596
-                    'input_name'     => 'STA_ID',
3597
-                    'input_prefix'   => '',
3598
-                    'append_qstn_id' => false,
3599
-                ]
3600
-            )
3601
-        );
3602
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3603
-            new EE_Question_Form_Input(
3604
-                EE_Question::new_instance(
3605
-                    [
3606
-                        'QST_ID'           => 0,
3607
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3608
-                        'QST_system'       => 'admin-country',
3609
-                    ]
3610
-                ),
3611
-                EE_Answer::new_instance(
3612
-                    [
3613
-                        'ANS_ID'    => 0,
3614
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3615
-                    ]
3616
-                ),
3617
-                [
3618
-                    'input_id'       => 'CNT_ISO',
3619
-                    'input_name'     => 'CNT_ISO',
3620
-                    'input_prefix'   => '',
3621
-                    'append_qstn_id' => false,
3622
-                ]
3623
-            )
3624
-        );
3625
-        $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3626
-        EEH_Template::display_template($template, $this->_template_args);
3627
-    }
3628
-
3629
-
3630
-    /**
3631
-     * _attendee_details
3632
-     *
3633
-     * @param $post
3634
-     * @return void
3635
-     * @throws DomainException
3636
-     * @throws EE_Error
3637
-     * @throws InvalidArgumentException
3638
-     * @throws InvalidDataTypeException
3639
-     * @throws InvalidInterfaceException
3640
-     * @throws ReflectionException
3641
-     */
3642
-    public function attendee_registrations_meta_box($post)
3643
-    {
3644
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3645
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3646
-        $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3647
-        EEH_Template::display_template($template, $this->_template_args);
3648
-    }
3649
-
3650
-
3651
-    /**
3652
-     * add in the form fields for the attendee edit
3653
-     *
3654
-     * @param WP_Post $post wp post object
3655
-     * @return void echos html for new form.
3656
-     * @throws DomainException
3657
-     */
3658
-    public function after_title_form_fields($post)
3659
-    {
3660
-        if ($post->post_type === 'espresso_attendees') {
3661
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3662
-            $template_args['attendee'] = $this->_cpt_model_obj;
3663
-            EEH_Template::display_template($template, $template_args);
3664
-        }
3665
-    }
3666
-
3667
-
3668
-    /**
3669
-     * _trash_or_restore_attendee
3670
-     *
3671
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3672
-     * @return void
3673
-     * @throws EE_Error
3674
-     * @throws InvalidArgumentException
3675
-     * @throws InvalidDataTypeException
3676
-     * @throws InvalidInterfaceException
3677
-     */
3678
-    protected function _trash_or_restore_attendees($trash = true)
3679
-    {
3680
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3681
-        $status = $trash ? 'trash' : 'publish';
3682
-        // Checkboxes
3683
-        if ($this->request->requestParamIsSet('checkbox')) {
3684
-            $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3685
-            // if array has more than one element than success message should be plural
3686
-            $success = count($ATT_IDs) > 1 ? 2 : 1;
3687
-            // cycle thru checkboxes
3688
-            foreach ($ATT_IDs as $ATT_ID) {
3689
-                $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3690
-                if (! $updated) {
3691
-                    $success = 0;
3692
-                }
3693
-            }
3694
-        } else {
3695
-            // grab single id and delete
3696
-            $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3697
-            // update attendee
3698
-            $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3699
-        }
3700
-        $what        = $success > 1
3701
-            ? esc_html__('Contacts', 'event_espresso')
3702
-            : esc_html__('Contact', 'event_espresso');
3703
-        $action_desc = $trash
3704
-            ? esc_html__('moved to the trash', 'event_espresso')
3705
-            : esc_html__('restored', 'event_espresso');
3706
-        $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3707
-    }
2868
+		}
2869
+		$template_args = [
2870
+			'title'                    => '',
2871
+			'content'                  => '',
2872
+			'step_button_text'         => '',
2873
+			'show_notification_toggle' => false,
2874
+		];
2875
+		// to indicate we're processing a new registration
2876
+		$hidden_fields = [
2877
+			'processing_registration' => [
2878
+				'type'  => 'hidden',
2879
+				'value' => 0,
2880
+			],
2881
+			'event_id'                => [
2882
+				'type'  => 'hidden',
2883
+				'value' => $this->_reg_event->ID(),
2884
+			],
2885
+		];
2886
+		// if the cart is empty then we know we're at step one, so we'll display the ticket selector
2887
+		$cart = EE_Registry::instance()->SSN->cart();
2888
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2889
+		switch ($step) {
2890
+			case 'ticket':
2891
+				$hidden_fields['processing_registration']['value'] = 1;
2892
+				$template_args['title']                            = esc_html__(
2893
+					'Step One: Select the Ticket for this registration',
2894
+					'event_espresso'
2895
+				);
2896
+				$template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2897
+				$template_args['content'] .= '</div>';
2898
+				$template_args['step_button_text'] = esc_html__(
2899
+					'Add Tickets and Continue to Registrant Details',
2900
+					'event_espresso'
2901
+				);
2902
+				$template_args['show_notification_toggle']         = false;
2903
+				break;
2904
+			case 'questions':
2905
+				$hidden_fields['processing_registration']['value'] = 2;
2906
+				$template_args['title']                            = esc_html__(
2907
+					'Step Two: Add Registrant Details for this Registration',
2908
+					'event_espresso'
2909
+				);
2910
+				// in theory, we should be able to run EED_SPCO at this point
2911
+				// because the cart should have been set up properly by the first process_reg_step run.
2912
+				$template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2913
+				$template_args['step_button_text'] = esc_html__(
2914
+					'Save Registration and Continue to Details',
2915
+					'event_espresso'
2916
+				);
2917
+				$template_args['show_notification_toggle'] = true;
2918
+				break;
2919
+		}
2920
+		// we come back to the process_registration_step route.
2921
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2922
+		return EEH_Template::display_template(
2923
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2924
+			$template_args,
2925
+			true
2926
+		);
2927
+	}
2928
+
2929
+
2930
+	/**
2931
+	 * set_reg_event
2932
+	 *
2933
+	 * @return bool
2934
+	 * @throws EE_Error
2935
+	 * @throws InvalidArgumentException
2936
+	 * @throws InvalidDataTypeException
2937
+	 * @throws InvalidInterfaceException
2938
+	 */
2939
+	private function _set_reg_event()
2940
+	{
2941
+		if (is_object($this->_reg_event)) {
2942
+			return true;
2943
+		}
2944
+
2945
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2946
+		if (! $EVT_ID) {
2947
+			return false;
2948
+		}
2949
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2950
+		return true;
2951
+	}
2952
+
2953
+
2954
+	/**
2955
+	 * process_reg_step
2956
+	 *
2957
+	 * @return void
2958
+	 * @throws DomainException
2959
+	 * @throws EE_Error
2960
+	 * @throws InvalidArgumentException
2961
+	 * @throws InvalidDataTypeException
2962
+	 * @throws InvalidInterfaceException
2963
+	 * @throws ReflectionException
2964
+	 * @throws RuntimeException
2965
+	 */
2966
+	public function process_reg_step()
2967
+	{
2968
+		EE_System::do_not_cache();
2969
+		$this->_set_reg_event();
2970
+		/** @var CurrentPage $current_page */
2971
+		$current_page = $this->loader->getShared(CurrentPage::class);
2972
+		$current_page->setEspressoPage(true);
2973
+		$this->request->setRequestParam('uts', time());
2974
+		// what step are we on?
2975
+		$cart = EE_Registry::instance()->SSN->cart();
2976
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2977
+		// if doing ajax then we need to verify the nonce
2978
+		if ($this->request->isAjax()) {
2979
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
2980
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2981
+		}
2982
+		switch ($step) {
2983
+			case 'ticket':
2984
+				// process ticket selection
2985
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2986
+				if ($success) {
2987
+					EE_Error::add_success(
2988
+						esc_html__(
2989
+							'Tickets Selected. Now complete the registration.',
2990
+							'event_espresso'
2991
+						)
2992
+					);
2993
+				} else {
2994
+					$this->request->setRequestParam('step_error', true);
2995
+					$query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
2996
+				}
2997
+				if ($this->request->isAjax()) {
2998
+					$this->new_registration(); // display next step
2999
+				} else {
3000
+					$query_args = [
3001
+						'action'                  => 'new_registration',
3002
+						'processing_registration' => 1,
3003
+						'event_id'                => $this->_reg_event->ID(),
3004
+						'uts'                     => time(),
3005
+					];
3006
+					$this->_redirect_after_action(
3007
+						false,
3008
+						'',
3009
+						'',
3010
+						$query_args,
3011
+						true
3012
+					);
3013
+				}
3014
+				break;
3015
+			case 'questions':
3016
+				if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3017
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3018
+				}
3019
+				// process registration
3020
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3021
+				if ($cart instanceof EE_Cart) {
3022
+					$grand_total = $cart->get_grand_total();
3023
+					if ($grand_total instanceof EE_Line_Item) {
3024
+						$grand_total->save_this_and_descendants_to_txn();
3025
+					}
3026
+				}
3027
+				if (! $transaction instanceof EE_Transaction) {
3028
+					$query_args = [
3029
+						'action'                  => 'new_registration',
3030
+						'processing_registration' => 2,
3031
+						'event_id'                => $this->_reg_event->ID(),
3032
+						'uts'                     => time(),
3033
+					];
3034
+					if ($this->request->isAjax()) {
3035
+						// display registration form again because there are errors (maybe validation?)
3036
+						$this->new_registration();
3037
+						return;
3038
+					}
3039
+					$this->_redirect_after_action(
3040
+						false,
3041
+						'',
3042
+						'',
3043
+						$query_args,
3044
+						true
3045
+					);
3046
+					return;
3047
+				}
3048
+				// maybe update status, and make sure to save transaction if not done already
3049
+				if (! $transaction->update_status_based_on_total_paid()) {
3050
+					$transaction->save();
3051
+				}
3052
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3053
+				$query_args = [
3054
+					'action'        => 'redirect_to_txn',
3055
+					'TXN_ID'        => $transaction->ID(),
3056
+					'EVT_ID'        => $this->_reg_event->ID(),
3057
+					'event_name'    => urlencode($this->_reg_event->name()),
3058
+					'redirect_from' => 'new_registration',
3059
+				];
3060
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3061
+				break;
3062
+		}
3063
+		// what are you looking here for?  Should be nothing to do at this point.
3064
+	}
3065
+
3066
+
3067
+	/**
3068
+	 * redirect_to_txn
3069
+	 *
3070
+	 * @return void
3071
+	 * @throws EE_Error
3072
+	 * @throws InvalidArgumentException
3073
+	 * @throws InvalidDataTypeException
3074
+	 * @throws InvalidInterfaceException
3075
+	 * @throws ReflectionException
3076
+	 */
3077
+	public function redirect_to_txn()
3078
+	{
3079
+		EE_System::do_not_cache();
3080
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3081
+		$query_args = [
3082
+			'action' => 'view_transaction',
3083
+			'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3084
+			'page'   => 'espresso_transactions',
3085
+		];
3086
+		if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3087
+			$query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3088
+			$query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3089
+			$query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3090
+		}
3091
+		EE_Error::add_success(
3092
+			esc_html__(
3093
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3094
+				'event_espresso'
3095
+			)
3096
+		);
3097
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3098
+	}
3099
+
3100
+
3101
+	/**
3102
+	 * generates HTML for the Attendee Contact List
3103
+	 *
3104
+	 * @return void
3105
+	 * @throws DomainException
3106
+	 * @throws EE_Error
3107
+	 */
3108
+	protected function _attendee_contact_list_table()
3109
+	{
3110
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3111
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3112
+		$this->display_admin_list_table_page_with_no_sidebar();
3113
+	}
3114
+
3115
+
3116
+	/**
3117
+	 * get_attendees
3118
+	 *
3119
+	 * @param      $per_page
3120
+	 * @param bool $count whether to return count or data.
3121
+	 * @param bool $trash
3122
+	 * @return array|int
3123
+	 * @throws EE_Error
3124
+	 * @throws InvalidArgumentException
3125
+	 * @throws InvalidDataTypeException
3126
+	 * @throws InvalidInterfaceException
3127
+	 */
3128
+	public function get_attendees($per_page, $count = false, $trash = false)
3129
+	{
3130
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3131
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3132
+		$orderby = $this->request->getRequestParam('orderby');
3133
+		switch ($orderby) {
3134
+			case 'ATT_ID':
3135
+			case 'ATT_fname':
3136
+			case 'ATT_email':
3137
+			case 'ATT_city':
3138
+			case 'STA_ID':
3139
+			case 'CNT_ID':
3140
+				break;
3141
+			case 'Registration_Count':
3142
+				$orderby = 'Registration_Count';
3143
+				break;
3144
+			default:
3145
+				$orderby = 'ATT_lname';
3146
+		}
3147
+		$sort         = $this->request->getRequestParam('order', 'ASC');
3148
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
3149
+		$per_page     = absint($per_page) ? $per_page : 10;
3150
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3151
+		$_where       = [];
3152
+		$search_term  = $this->request->getRequestParam('s');
3153
+		if ($search_term) {
3154
+			$search_term  = '%' . $search_term . '%';
3155
+			$_where['OR'] = [
3156
+				'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3157
+				'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3158
+				'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3159
+				'ATT_fname'                         => ['LIKE', $search_term],
3160
+				'ATT_lname'                         => ['LIKE', $search_term],
3161
+				'ATT_short_bio'                     => ['LIKE', $search_term],
3162
+				'ATT_email'                         => ['LIKE', $search_term],
3163
+				'ATT_address'                       => ['LIKE', $search_term],
3164
+				'ATT_address2'                      => ['LIKE', $search_term],
3165
+				'ATT_city'                          => ['LIKE', $search_term],
3166
+				'Country.CNT_name'                  => ['LIKE', $search_term],
3167
+				'State.STA_name'                    => ['LIKE', $search_term],
3168
+				'ATT_phone'                         => ['LIKE', $search_term],
3169
+				'Registration.REG_final_price'      => ['LIKE', $search_term],
3170
+				'Registration.REG_code'             => ['LIKE', $search_term],
3171
+				'Registration.REG_group_size'       => ['LIKE', $search_term],
3172
+			];
3173
+		}
3174
+		$offset     = ($current_page - 1) * $per_page;
3175
+		$limit      = $count ? null : [$offset, $per_page];
3176
+		$query_args = [
3177
+			$_where,
3178
+			'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3179
+			'limit'         => $limit,
3180
+		];
3181
+		if (! $count) {
3182
+			$query_args['order_by'] = [$orderby => $sort];
3183
+		}
3184
+		$query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3185
+		return $count
3186
+			? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3187
+			: $this->getAttendeeModel()->get_all($query_args);
3188
+	}
3189
+
3190
+
3191
+	/**
3192
+	 * This is just taking care of resending the registration confirmation
3193
+	 *
3194
+	 * @return void
3195
+	 * @throws EE_Error
3196
+	 * @throws InvalidArgumentException
3197
+	 * @throws InvalidDataTypeException
3198
+	 * @throws InvalidInterfaceException
3199
+	 * @throws ReflectionException
3200
+	 */
3201
+	protected function _resend_registration()
3202
+	{
3203
+		$this->_process_resend_registration();
3204
+		$REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3205
+		$redirect_to = $this->request->getRequestParam('redirect_to');
3206
+		$query_args  = $redirect_to
3207
+			? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3208
+			: ['action' => 'default'];
3209
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3210
+	}
3211
+
3212
+
3213
+	/**
3214
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3215
+	 * to use when selecting registrations
3216
+	 *
3217
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3218
+	 *                                                     the query parameters from the request
3219
+	 * @return void ends the request with a redirect or download
3220
+	 */
3221
+	public function _registrations_report_base($method_name_for_getting_query_params)
3222
+	{
3223
+		$EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3224
+			? $this->request->getRequestParam('EVT_ID', 0, 'int')
3225
+			: null;
3226
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3227
+			$request_params = $this->request->requestParams();
3228
+			wp_redirect(
3229
+				EE_Admin_Page::add_query_args_and_nonce(
3230
+					[
3231
+						'page'        => 'espresso_batch',
3232
+						'batch'       => 'file',
3233
+						'EVT_ID'      => $EVT_ID,
3234
+						'filters'     => urlencode(
3235
+							serialize(
3236
+								$this->$method_name_for_getting_query_params(
3237
+									EEH_Array::is_set($request_params, 'filters', [])
3238
+								)
3239
+							)
3240
+						),
3241
+						'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3242
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3243
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3244
+					]
3245
+				)
3246
+			);
3247
+		} else {
3248
+			// Pull the current request params
3249
+			$request_args = $this->request->requestParams();
3250
+			// Set the required request_args to be passed to the export
3251
+			$required_request_args = [
3252
+				'export' => 'report',
3253
+				'action' => 'registrations_report_for_event',
3254
+				'EVT_ID' => $EVT_ID,
3255
+			];
3256
+			// Merge required request args, overriding any currently set
3257
+			$request_args = array_merge($request_args, $required_request_args);
3258
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3259
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3260
+				$EE_Export = EE_Export::instance($request_args);
3261
+				$EE_Export->export();
3262
+			}
3263
+		}
3264
+	}
3265
+
3266
+
3267
+	/**
3268
+	 * Creates a registration report using only query parameters in the request
3269
+	 *
3270
+	 * @return void
3271
+	 */
3272
+	public function _registrations_report()
3273
+	{
3274
+		$this->_registrations_report_base('_get_registration_query_parameters');
3275
+	}
3276
+
3277
+
3278
+	public function _contact_list_export()
3279
+	{
3280
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3281
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3282
+			$EE_Export = EE_Export::instance($this->request->requestParams());
3283
+			$EE_Export->export_attendees();
3284
+		}
3285
+	}
3286
+
3287
+
3288
+	public function _contact_list_report()
3289
+	{
3290
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3291
+			wp_redirect(
3292
+				EE_Admin_Page::add_query_args_and_nonce(
3293
+					[
3294
+						'page'        => 'espresso_batch',
3295
+						'batch'       => 'file',
3296
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3297
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3298
+					]
3299
+				)
3300
+			);
3301
+		} else {
3302
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3303
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3304
+				$EE_Export = EE_Export::instance($this->request->requestParams());
3305
+				$EE_Export->report_attendees();
3306
+			}
3307
+		}
3308
+	}
3309
+
3310
+
3311
+
3312
+
3313
+
3314
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3315
+	/**
3316
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3317
+	 *
3318
+	 * @return void
3319
+	 * @throws EE_Error
3320
+	 * @throws InvalidArgumentException
3321
+	 * @throws InvalidDataTypeException
3322
+	 * @throws InvalidInterfaceException
3323
+	 * @throws ReflectionException
3324
+	 */
3325
+	protected function _duplicate_attendee()
3326
+	{
3327
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3328
+		$action = $this->request->getRequestParam('return', 'default');
3329
+		// verify we have necessary info
3330
+		if (! $REG_ID) {
3331
+			EE_Error::add_error(
3332
+				esc_html__(
3333
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3334
+					'event_espresso'
3335
+				),
3336
+				__FILE__,
3337
+				__LINE__,
3338
+				__FUNCTION__
3339
+			);
3340
+			$query_args = ['action' => $action];
3341
+			$this->_redirect_after_action('', '', '', $query_args, true);
3342
+		}
3343
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3344
+		$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3345
+		if (! $registration instanceof EE_Registration) {
3346
+			throw new RuntimeException(
3347
+				sprintf(
3348
+					esc_html__(
3349
+						'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3350
+						'event_espresso'
3351
+					),
3352
+					$REG_ID
3353
+				)
3354
+			);
3355
+		}
3356
+		$attendee = $registration->attendee();
3357
+		// remove relation of existing attendee on registration
3358
+		$registration->_remove_relation_to($attendee, 'Attendee');
3359
+		// new attendee
3360
+		$new_attendee = clone $attendee;
3361
+		$new_attendee->set('ATT_ID', 0);
3362
+		$new_attendee->save();
3363
+		// add new attendee to reg
3364
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3365
+		EE_Error::add_success(
3366
+			esc_html__(
3367
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3368
+				'event_espresso'
3369
+			)
3370
+		);
3371
+		// redirect to edit page for attendee
3372
+		$query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3373
+		$this->_redirect_after_action('', '', '', $query_args, true);
3374
+	}
3375
+
3376
+
3377
+	/**
3378
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3379
+	 *
3380
+	 * @param int     $post_id
3381
+	 * @param WP_Post $post
3382
+	 * @throws DomainException
3383
+	 * @throws EE_Error
3384
+	 * @throws InvalidArgumentException
3385
+	 * @throws InvalidDataTypeException
3386
+	 * @throws InvalidInterfaceException
3387
+	 * @throws LogicException
3388
+	 * @throws InvalidFormSubmissionException
3389
+	 * @throws ReflectionException
3390
+	 */
3391
+	protected function _insert_update_cpt_item($post_id, $post)
3392
+	{
3393
+		$success  = true;
3394
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3395
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3396
+			: null;
3397
+		// for attendee updates
3398
+		if ($attendee instanceof EE_Attendee) {
3399
+			// note we should only be UPDATING attendees at this point.
3400
+			$fname          = $this->request->getRequestParam('ATT_fname', '');
3401
+			$lname          = $this->request->getRequestParam('ATT_lname', '');
3402
+			$updated_fields = [
3403
+				'ATT_fname'     => $fname,
3404
+				'ATT_lname'     => $lname,
3405
+				'ATT_full_name' => "{$fname} {$lname}",
3406
+				'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3407
+				'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3408
+				'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3409
+				'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3410
+				'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3411
+				'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3412
+			];
3413
+			foreach ($updated_fields as $field => $value) {
3414
+				$attendee->set($field, $value);
3415
+			}
3416
+
3417
+			// process contact details metabox form handler (which will also save the attendee)
3418
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3419
+			$success              = $contact_details_form->process($this->request->requestParams());
3420
+
3421
+			$attendee_update_callbacks = apply_filters(
3422
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3423
+				[]
3424
+			);
3425
+			foreach ($attendee_update_callbacks as $a_callback) {
3426
+				if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3427
+					throw new EE_Error(
3428
+						sprintf(
3429
+							esc_html__(
3430
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3431
+								'event_espresso'
3432
+							),
3433
+							$a_callback
3434
+						)
3435
+					);
3436
+				}
3437
+			}
3438
+		}
3439
+
3440
+		if ($success === false) {
3441
+			EE_Error::add_error(
3442
+				esc_html__(
3443
+					'Something went wrong with updating the meta table data for the registration.',
3444
+					'event_espresso'
3445
+				),
3446
+				__FILE__,
3447
+				__FUNCTION__,
3448
+				__LINE__
3449
+			);
3450
+		}
3451
+	}
3452
+
3453
+
3454
+	public function trash_cpt_item($post_id)
3455
+	{
3456
+	}
3457
+
3458
+
3459
+	public function delete_cpt_item($post_id)
3460
+	{
3461
+	}
3462
+
3463
+
3464
+	public function restore_cpt_item($post_id)
3465
+	{
3466
+	}
3467
+
3468
+
3469
+	protected function _restore_cpt_item($post_id, $revision_id)
3470
+	{
3471
+	}
3472
+
3473
+
3474
+	/**
3475
+	 * @throws EE_Error
3476
+	 * @throws ReflectionException
3477
+	 * @since 4.10.2.p
3478
+	 */
3479
+	public function attendee_editor_metaboxes()
3480
+	{
3481
+		$this->verify_cpt_object();
3482
+		remove_meta_box(
3483
+			'postexcerpt',
3484
+			$this->_cpt_routes[ $this->_req_action ],
3485
+			'normal'
3486
+		);
3487
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3488
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3489
+			$this->addMetaBox(
3490
+				'postexcerpt',
3491
+				esc_html__('Short Biography', 'event_espresso'),
3492
+				'post_excerpt_meta_box',
3493
+				$this->_cpt_routes[ $this->_req_action ]
3494
+			);
3495
+		}
3496
+		if (post_type_supports('espresso_attendees', 'comments')) {
3497
+			$this->addMetaBox(
3498
+				'commentsdiv',
3499
+				esc_html__('Notes on the Contact', 'event_espresso'),
3500
+				'post_comment_meta_box',
3501
+				$this->_cpt_routes[ $this->_req_action ],
3502
+				'normal',
3503
+				'core'
3504
+			);
3505
+		}
3506
+		$this->addMetaBox(
3507
+			'attendee_contact_info',
3508
+			esc_html__('Contact Info', 'event_espresso'),
3509
+			[$this, 'attendee_contact_info'],
3510
+			$this->_cpt_routes[ $this->_req_action ],
3511
+			'side',
3512
+			'core'
3513
+		);
3514
+		$this->addMetaBox(
3515
+			'attendee_details_address',
3516
+			esc_html__('Address Details', 'event_espresso'),
3517
+			[$this, 'attendee_address_details'],
3518
+			$this->_cpt_routes[ $this->_req_action ],
3519
+			'normal',
3520
+			'core'
3521
+		);
3522
+		$this->addMetaBox(
3523
+			'attendee_registrations',
3524
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3525
+			[$this, 'attendee_registrations_meta_box'],
3526
+			$this->_cpt_routes[ $this->_req_action ]
3527
+		);
3528
+	}
3529
+
3530
+
3531
+	/**
3532
+	 * Metabox for attendee contact info
3533
+	 *
3534
+	 * @param WP_Post $post wp post object
3535
+	 * @return void attendee contact info ( and form )
3536
+	 * @throws EE_Error
3537
+	 * @throws InvalidArgumentException
3538
+	 * @throws InvalidDataTypeException
3539
+	 * @throws InvalidInterfaceException
3540
+	 * @throws LogicException
3541
+	 * @throws DomainException
3542
+	 */
3543
+	public function attendee_contact_info($post)
3544
+	{
3545
+		// get attendee object ( should already have it )
3546
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3547
+		$form->enqueueStylesAndScripts();
3548
+		echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3549
+	}
3550
+
3551
+
3552
+	/**
3553
+	 * Return form handler for the contact details metabox
3554
+	 *
3555
+	 * @param EE_Attendee $attendee
3556
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3557
+	 * @throws DomainException
3558
+	 * @throws InvalidArgumentException
3559
+	 * @throws InvalidDataTypeException
3560
+	 * @throws InvalidInterfaceException
3561
+	 */
3562
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3563
+	{
3564
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3565
+	}
3566
+
3567
+
3568
+	/**
3569
+	 * Metabox for attendee details
3570
+	 *
3571
+	 * @param WP_Post $post wp post object
3572
+	 * @throws EE_Error
3573
+	 * @throws ReflectionException
3574
+	 */
3575
+	public function attendee_address_details($post)
3576
+	{
3577
+		// get attendee object (should already have it)
3578
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3579
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3580
+			new EE_Question_Form_Input(
3581
+				EE_Question::new_instance(
3582
+					[
3583
+						'QST_ID'           => 0,
3584
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3585
+						'QST_system'       => 'admin-state',
3586
+					]
3587
+				),
3588
+				EE_Answer::new_instance(
3589
+					[
3590
+						'ANS_ID'    => 0,
3591
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3592
+					]
3593
+				),
3594
+				[
3595
+					'input_id'       => 'STA_ID',
3596
+					'input_name'     => 'STA_ID',
3597
+					'input_prefix'   => '',
3598
+					'append_qstn_id' => false,
3599
+				]
3600
+			)
3601
+		);
3602
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3603
+			new EE_Question_Form_Input(
3604
+				EE_Question::new_instance(
3605
+					[
3606
+						'QST_ID'           => 0,
3607
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3608
+						'QST_system'       => 'admin-country',
3609
+					]
3610
+				),
3611
+				EE_Answer::new_instance(
3612
+					[
3613
+						'ANS_ID'    => 0,
3614
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3615
+					]
3616
+				),
3617
+				[
3618
+					'input_id'       => 'CNT_ISO',
3619
+					'input_name'     => 'CNT_ISO',
3620
+					'input_prefix'   => '',
3621
+					'append_qstn_id' => false,
3622
+				]
3623
+			)
3624
+		);
3625
+		$template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3626
+		EEH_Template::display_template($template, $this->_template_args);
3627
+	}
3628
+
3629
+
3630
+	/**
3631
+	 * _attendee_details
3632
+	 *
3633
+	 * @param $post
3634
+	 * @return void
3635
+	 * @throws DomainException
3636
+	 * @throws EE_Error
3637
+	 * @throws InvalidArgumentException
3638
+	 * @throws InvalidDataTypeException
3639
+	 * @throws InvalidInterfaceException
3640
+	 * @throws ReflectionException
3641
+	 */
3642
+	public function attendee_registrations_meta_box($post)
3643
+	{
3644
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3645
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3646
+		$template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3647
+		EEH_Template::display_template($template, $this->_template_args);
3648
+	}
3649
+
3650
+
3651
+	/**
3652
+	 * add in the form fields for the attendee edit
3653
+	 *
3654
+	 * @param WP_Post $post wp post object
3655
+	 * @return void echos html for new form.
3656
+	 * @throws DomainException
3657
+	 */
3658
+	public function after_title_form_fields($post)
3659
+	{
3660
+		if ($post->post_type === 'espresso_attendees') {
3661
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3662
+			$template_args['attendee'] = $this->_cpt_model_obj;
3663
+			EEH_Template::display_template($template, $template_args);
3664
+		}
3665
+	}
3666
+
3667
+
3668
+	/**
3669
+	 * _trash_or_restore_attendee
3670
+	 *
3671
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3672
+	 * @return void
3673
+	 * @throws EE_Error
3674
+	 * @throws InvalidArgumentException
3675
+	 * @throws InvalidDataTypeException
3676
+	 * @throws InvalidInterfaceException
3677
+	 */
3678
+	protected function _trash_or_restore_attendees($trash = true)
3679
+	{
3680
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3681
+		$status = $trash ? 'trash' : 'publish';
3682
+		// Checkboxes
3683
+		if ($this->request->requestParamIsSet('checkbox')) {
3684
+			$ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3685
+			// if array has more than one element than success message should be plural
3686
+			$success = count($ATT_IDs) > 1 ? 2 : 1;
3687
+			// cycle thru checkboxes
3688
+			foreach ($ATT_IDs as $ATT_ID) {
3689
+				$updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3690
+				if (! $updated) {
3691
+					$success = 0;
3692
+				}
3693
+			}
3694
+		} else {
3695
+			// grab single id and delete
3696
+			$ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3697
+			// update attendee
3698
+			$success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3699
+		}
3700
+		$what        = $success > 1
3701
+			? esc_html__('Contacts', 'event_espresso')
3702
+			: esc_html__('Contact', 'event_espresso');
3703
+		$action_desc = $trash
3704
+			? esc_html__('moved to the trash', 'event_espresso')
3705
+			: esc_html__('restored', 'event_espresso');
3706
+		$this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3707
+	}
3708 3708
 }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4643 added lines, -4643 removed lines patch added patch discarded remove patch
@@ -17,2683 +17,2683 @@  discard block
 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 $_context_switcher;
62
-
63
-    protected $_shortcodes           = [];
64
-
65
-    protected $_active_messengers    = [];
66
-
67
-    protected $_active_message_types = [];
68
-
69
-    /**
70
-     * @var EE_Message_Template_Group $_message_template_group
71
-     */
72
-    protected $_message_template_group;
73
-
74
-    protected $_m_mt_settings = [];
75
-
76
-
77
-    /**
78
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
-     * IF there is no group then it gets automatically set to the Default template pack.
80
-     *
81
-     * @since 4.5.0
82
-     *
83
-     * @var EE_Messages_Template_Pack
84
-     */
85
-    protected $_template_pack;
86
-
87
-
88
-    /**
89
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
-     * group is.  If there is no group then it automatically gets set to default.
91
-     *
92
-     * @since 4.5.0
93
-     *
94
-     * @var string
95
-     */
96
-    protected $_variation;
97
-
98
-
99
-    /**
100
-     * @param bool $routing
101
-     * @throws EE_Error
102
-     * @throws ReflectionException
103
-     */
104
-    public function __construct($routing = true)
105
-    {
106
-        // make sure messages autoloader is running
107
-        EED_Messages::set_autoloaders();
108
-        parent::__construct($routing);
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EEM_Message
114
-     * @throws EE_Error
115
-     */
116
-    public function getMsgModel()
117
-    {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
119
-            $this->MSG_MODEL = EEM_Message::instance();
120
-        }
121
-        return $this->MSG_MODEL;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return EEM_Message_Template
127
-     * @throws EE_Error
128
-     */
129
-    public function getMtpModel()
130
-    {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
-            $this->MTP_MODEL = EEM_Message_Template::instance();
133
-        }
134
-        return $this->MTP_MODEL;
135
-    }
136
-
137
-
138
-    /**
139
-     * @return EEM_Message_Template_Group
140
-     * @throws EE_Error
141
-     */
142
-    public function getMtgModel()
143
-    {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
-        }
147
-        return $this->MTG_MODEL;
148
-    }
149
-
150
-
151
-    /**
152
-     * @throws EE_Error
153
-     * @throws ReflectionException
154
-     */
155
-    protected function _init_page_props()
156
-    {
157
-        $this->page_slug        = EE_MSG_PG_SLUG;
158
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
-        $this->_admin_base_path = EE_MSG_ADMIN;
161
-
162
-        $messenger    = $this->request->getRequestParam('messenger', '');
163
-        $message_type = $this->request->getRequestParam('message_type', '');
164
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
-
167
-        $this->_load_message_resource_manager();
168
-    }
169
-
170
-
171
-    /**
172
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
-     *
174
-     * @throws EE_Error
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidInterfaceException
177
-     * @throws InvalidArgumentException
178
-     * @throws ReflectionException
179
-     */
180
-    protected function _load_message_resource_manager()
181
-    {
182
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
-    }
184
-
185
-
186
-    /**
187
-     * @return array
188
-     * @throws EE_Error
189
-     * @throws InvalidArgumentException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     * @deprecated 4.9.9.rc.014
193
-     */
194
-    public function get_messengers_for_list_table()
195
-    {
196
-        EE_Error::doing_it_wrong(
197
-            __METHOD__,
198
-            sprintf(
199
-                esc_html__(
200
-                    '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',
201
-                    'event_espresso'
202
-                ),
203
-                'Messages_Admin_Page::get_messengers_select_input()'
204
-            ),
205
-            '4.9.9.rc.014'
206
-        );
207
-
208
-        $m_values          = [];
209
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
-        // setup messengers for selects
211
-        $i = 1;
212
-        foreach ($active_messengers as $active_messenger) {
213
-            if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
-                $i++;
217
-            }
218
-        }
219
-
220
-        return $m_values;
221
-    }
222
-
223
-
224
-    /**
225
-     * @return array
226
-     * @throws EE_Error
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidDataTypeException
229
-     * @throws InvalidInterfaceException
230
-     * @deprecated 4.9.9.rc.014
231
-     */
232
-    public function get_message_types_for_list_table()
233
-    {
234
-        EE_Error::doing_it_wrong(
235
-            __METHOD__,
236
-            sprintf(
237
-                esc_html__(
238
-                    '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',
239
-                    'event_espresso'
240
-                ),
241
-                'Messages_Admin_Page::get_message_types_select_input()'
242
-            ),
243
-            '4.9.9.rc.014'
244
-        );
245
-
246
-        $mt_values       = [];
247
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
-        $i               = 1;
249
-        foreach ($active_messages as $active_message) {
250
-            if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
-                $i++;
254
-            }
255
-        }
256
-
257
-        return $mt_values;
258
-    }
259
-
260
-
261
-    /**
262
-     * @return array
263
-     * @throws EE_Error
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     * @deprecated 4.9.9.rc.014
268
-     */
269
-    public function get_contexts_for_message_types_for_list_table()
270
-    {
271
-        EE_Error::doing_it_wrong(
272
-            __METHOD__,
273
-            sprintf(
274
-                esc_html__(
275
-                    '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',
276
-                    'event_espresso'
277
-                ),
278
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
-            ),
280
-            '4.9.9.rc.014'
281
-        );
282
-
283
-        $contexts                = [];
284
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
-        foreach ($active_message_contexts as $active_message) {
286
-            if ($active_message instanceof EE_Message) {
287
-                $message_type = $active_message->message_type_object();
288
-                if ($message_type instanceof EE_message_type) {
289
-                    $message_type_contexts = $message_type->get_contexts();
290
-                    foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
292
-                    }
293
-                }
294
-            }
295
-        }
296
-
297
-        return $contexts;
298
-    }
299
-
300
-
301
-    /**
302
-     * Generate select input with provided messenger options array.
303
-     *
304
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
-     *                                 labels.
306
-     * @return string
307
-     * @throws EE_Error
308
-     */
309
-    public function get_messengers_select_input($messenger_options)
310
-    {
311
-        // if empty or just one value then just return an empty string
312
-        if (
313
-            empty($messenger_options)
314
-            || ! is_array($messenger_options)
315
-            || count($messenger_options) === 1
316
-        ) {
317
-            return '';
318
-        }
319
-        // merge in default
320
-        $messenger_options = array_merge(
321
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
-            $messenger_options
323
-        );
324
-        $input             = new EE_Select_Input(
325
-            $messenger_options,
326
-            [
327
-                'html_name'  => 'ee_messenger_filter_by',
328
-                'html_id'    => 'ee_messenger_filter_by',
329
-                'html_class' => 'wide',
330
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
-            ]
332
-        );
333
-
334
-        return $input->get_html_for_input();
335
-    }
336
-
337
-
338
-    /**
339
-     * Generate select input with provided message type options array.
340
-     *
341
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
-     *                                    message type labels
343
-     * @return string
344
-     * @throws EE_Error
345
-     */
346
-    public function get_message_types_select_input($message_type_options)
347
-    {
348
-        // if empty or count of options is 1 then just return an empty string
349
-        if (
350
-            empty($message_type_options)
351
-            || ! is_array($message_type_options)
352
-            || count($message_type_options) === 1
353
-        ) {
354
-            return '';
355
-        }
356
-        // merge in default
357
-        $message_type_options = array_merge(
358
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
-            $message_type_options
360
-        );
361
-        $input                = new EE_Select_Input(
362
-            $message_type_options,
363
-            [
364
-                'html_name'  => 'ee_message_type_filter_by',
365
-                'html_id'    => 'ee_message_type_filter_by',
366
-                'html_class' => 'wide',
367
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
-            ]
369
-        );
370
-
371
-        return $input->get_html_for_input();
372
-    }
373
-
374
-
375
-    /**
376
-     * Generate select input with provide message type contexts array.
377
-     *
378
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
-     *                               context label.
380
-     * @return string
381
-     * @throws EE_Error
382
-     */
383
-    public function get_contexts_for_message_types_select_input($context_options)
384
-    {
385
-        // if empty or count of options is one then just return empty string
386
-        if (
387
-            empty($context_options)
388
-            || ! is_array($context_options)
389
-            || count($context_options) === 1
390
-        ) {
391
-            return '';
392
-        }
393
-        // merge in default
394
-        $context_options = array_merge(
395
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
-            $context_options
397
-        );
398
-        $input           = new EE_Select_Input(
399
-            $context_options,
400
-            [
401
-                'html_name'  => 'ee_context_filter_by',
402
-                'html_id'    => 'ee_context_filter_by',
403
-                'html_class' => 'wide',
404
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
-            ]
406
-        );
407
-
408
-        return $input->get_html_for_input();
409
-    }
410
-
411
-
412
-    protected function _ajax_hooks()
413
-    {
414
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
-    }
421
-
422
-
423
-    protected function _define_page_props()
424
-    {
425
-        $this->_admin_page_title = $this->page_label;
426
-        $this->_labels           = [
427
-            'buttons'    => [
428
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
-            ],
432
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
-        ];
434
-    }
435
-
436
-
437
-    /**
438
-     *        an array for storing key => value pairs of request actions and their corresponding methods
439
-     *
440
-     * @access protected
441
-     * @return void
442
-     */
443
-    protected function _set_page_routes()
444
-    {
445
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
-
449
-        $this->_page_routes = [
450
-            'default'                          => [
451
-                'func'       => '_message_queue_list_table',
452
-                'capability' => 'ee_read_global_messages',
453
-            ],
454
-            'global_mtps'                      => [
455
-                'func'       => '_ee_default_messages_overview_list_table',
456
-                'capability' => 'ee_read_global_messages',
457
-            ],
458
-            'custom_mtps'                      => [
459
-                'func'       => '_custom_mtps_preview',
460
-                'capability' => 'ee_read_messages',
461
-            ],
462
-            'add_new_message_template'         => [
463
-                'func'       => 'add_message_template',
464
-                'capability' => 'ee_edit_messages',
465
-                'noheader'   => true,
466
-            ],
467
-            'edit_message_template'            => [
468
-                'func'       => '_edit_message_template',
469
-                'capability' => 'ee_edit_message',
470
-                'obj_id'     => $GRP_ID,
471
-            ],
472
-            'preview_message'                  => [
473
-                'func'               => '_preview_message',
474
-                'capability'         => 'ee_read_message',
475
-                'obj_id'             => $GRP_ID,
476
-                'noheader'           => true,
477
-                'headers_sent_route' => 'display_preview_message',
478
-            ],
479
-            'display_preview_message'          => [
480
-                'func'       => '_display_preview_message',
481
-                'capability' => 'ee_read_message',
482
-                'obj_id'     => $GRP_ID,
483
-            ],
484
-            'insert_message_template'          => [
485
-                'func'       => '_insert_or_update_message_template',
486
-                'capability' => 'ee_edit_messages',
487
-                'args'       => ['new' => true],
488
-                'noheader'   => true,
489
-            ],
490
-            'update_message_template'          => [
491
-                'func'       => '_insert_or_update_message_template',
492
-                'capability' => 'ee_edit_message',
493
-                'obj_id'     => $GRP_ID,
494
-                'args'       => ['new' => false],
495
-                'noheader'   => true,
496
-            ],
497
-            'trash_message_template'           => [
498
-                'func'       => '_trash_or_restore_message_template',
499
-                'capability' => 'ee_delete_message',
500
-                'obj_id'     => $GRP_ID,
501
-                'args'       => ['trash' => true, 'all' => true],
502
-                'noheader'   => true,
503
-            ],
504
-            'trash_message_template_context'   => [
505
-                'func'       => '_trash_or_restore_message_template',
506
-                'capability' => 'ee_delete_message',
507
-                'obj_id'     => $GRP_ID,
508
-                'args'       => ['trash' => true],
509
-                'noheader'   => true,
510
-            ],
511
-            'restore_message_template'         => [
512
-                'func'       => '_trash_or_restore_message_template',
513
-                'capability' => 'ee_delete_message',
514
-                'obj_id'     => $GRP_ID,
515
-                'args'       => ['trash' => false, 'all' => true],
516
-                'noheader'   => true,
517
-            ],
518
-            'restore_message_template_context' => [
519
-                'func'       => '_trash_or_restore_message_template',
520
-                'capability' => 'ee_delete_message',
521
-                'obj_id'     => $GRP_ID,
522
-                'args'       => ['trash' => false],
523
-                'noheader'   => true,
524
-            ],
525
-            'delete_message_template'          => [
526
-                'func'       => '_delete_message_template',
527
-                'capability' => 'ee_delete_message',
528
-                'obj_id'     => $GRP_ID,
529
-                'noheader'   => true,
530
-            ],
531
-            'reset_to_default'                 => [
532
-                'func'       => '_reset_to_default_template',
533
-                'capability' => 'ee_edit_message',
534
-                'obj_id'     => $GRP_ID,
535
-                'noheader'   => true,
536
-            ],
537
-            'settings'                         => [
538
-                'func'       => '_settings',
539
-                'capability' => 'manage_options',
540
-            ],
541
-            'update_global_settings'           => [
542
-                'func'       => '_update_global_settings',
543
-                'capability' => 'manage_options',
544
-                'noheader'   => true,
545
-            ],
546
-            'generate_now'                     => [
547
-                'func'       => '_generate_now',
548
-                'capability' => 'ee_send_message',
549
-                'noheader'   => true,
550
-            ],
551
-            'generate_and_send_now'            => [
552
-                'func'       => '_generate_and_send_now',
553
-                'capability' => 'ee_send_message',
554
-                'noheader'   => true,
555
-            ],
556
-            'queue_for_resending'              => [
557
-                'func'       => '_queue_for_resending',
558
-                'capability' => 'ee_send_message',
559
-                'noheader'   => true,
560
-            ],
561
-            'send_now'                         => [
562
-                'func'       => '_send_now',
563
-                'capability' => 'ee_send_message',
564
-                'noheader'   => true,
565
-            ],
566
-            'delete_ee_message'                => [
567
-                'func'       => '_delete_ee_messages',
568
-                'capability' => 'ee_delete_messages',
569
-                'noheader'   => true,
570
-            ],
571
-            'delete_ee_messages'               => [
572
-                'func'       => '_delete_ee_messages',
573
-                'capability' => 'ee_delete_messages',
574
-                'noheader'   => true,
575
-                'obj_id'     => $MSG_ID,
576
-            ],
577
-        ];
578
-    }
579
-
580
-
581
-    protected function _set_page_config()
582
-    {
583
-        $this->_page_config = [
584
-            'default'                  => [
585
-                'nav'           => [
586
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
587
-                    'order' => 10,
588
-                ],
589
-                'list_table'    => 'EE_Message_List_Table',
590
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
-                'require_nonce' => false,
592
-            ],
593
-            'global_mtps'              => [
594
-                'nav'           => [
595
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
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
-                    'order' => 30,
631
-                ],
632
-                'help_tabs'     => [],
633
-                'require_nonce' => false,
634
-            ],
635
-            'add_new_message_template' => [
636
-                'nav'           => [
637
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
-                    'order'      => 5,
639
-                    'persistent' => false,
640
-                ],
641
-                'require_nonce' => false,
642
-            ],
643
-            'edit_message_template'    => [
644
-                'labels'        => [
645
-                    'buttons'    => [
646
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
-                    ],
648
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
-                ],
650
-                'nav'           => [
651
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
-                    'order'      => 5,
653
-                    'persistent' => false,
654
-                    'url'        => '',
655
-                ],
656
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
-                'has_metaboxes' => true,
658
-                'help_tabs'     => [
659
-                    'edit_message_template'            => [
660
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
-                        'callback' => 'edit_message_template_help_tab',
662
-                    ],
663
-                    'message_templates_help_tab'       => [
664
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
665
-                        'filename' => 'messages_templates',
666
-                    ],
667
-                    'message_template_shortcodes'      => [
668
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
-                        'callback' => 'message_template_shortcodes_help_tab',
670
-                    ],
671
-                    'message_preview_help_tab'         => [
672
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
673
-                        'filename' => 'messages_preview',
674
-                    ],
675
-                    'messages_overview_other_help_tab' => [
676
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
677
-                        'filename' => 'messages_overview_other',
678
-                    ],
679
-                ],
680
-                'require_nonce' => false,
681
-            ],
682
-            'display_preview_message'  => [
683
-                'nav'           => [
684
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
685
-                    'order'      => 5,
686
-                    'url'        => '',
687
-                    'persistent' => false,
688
-                ],
689
-                'help_tabs'     => [
690
-                    'preview_message' => [
691
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
692
-                        'callback' => 'preview_message_help_tab',
693
-                    ],
694
-                ],
695
-                'require_nonce' => false,
696
-            ],
697
-            'settings'                 => [
698
-                'nav'           => [
699
-                    'label' => esc_html__('Settings', 'event_espresso'),
700
-                    'order' => 40,
701
-                ],
702
-                'metaboxes'     => ['_messages_settings_metaboxes'],
703
-                'help_tabs'     => [
704
-                    'messages_settings_help_tab'               => [
705
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
-                        'filename' => 'messages_settings',
707
-                    ],
708
-                    'messages_settings_message_types_help_tab' => [
709
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
-                        'filename' => 'messages_settings_message_types',
711
-                    ],
712
-                    'messages_settings_messengers_help_tab'    => [
713
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
-                        'filename' => 'messages_settings_messengers',
715
-                    ],
716
-                ],
717
-                'require_nonce' => false,
718
-            ],
719
-        ];
720
-    }
721
-
722
-
723
-    protected function _add_screen_options()
724
-    {
725
-        // todo
726
-    }
727
-
728
-
729
-    protected function _add_screen_options_global_mtps()
730
-    {
731
-        /**
732
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
734
-         */
735
-        $page_title              = $this->_admin_page_title;
736
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
-        $this->_per_page_screen_option();
738
-        $this->_admin_page_title = $page_title;
739
-    }
740
-
741
-
742
-    protected function _add_screen_options_default()
743
-    {
744
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
-        $this->_per_page_screen_option();
746
-    }
747
-
748
-
749
-    // none of the below group are currently used for Messages
750
-    protected function _add_feature_pointers()
751
-    {
752
-    }
753
-
754
-
755
-    public function admin_init()
756
-    {
757
-    }
758
-
759
-
760
-    public function admin_notices()
761
-    {
762
-    }
763
-
764
-
765
-    public function admin_footer_scripts()
766
-    {
767
-    }
768
-
769
-
770
-    public function messages_help_tab()
771
-    {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
-    }
774
-
775
-
776
-    public function messengers_help_tab()
777
-    {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
-    }
780
-
781
-
782
-    public function message_types_help_tab()
783
-    {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
-    }
786
-
787
-
788
-    public function messages_overview_help_tab()
789
-    {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
-    }
792
-
793
-
794
-    public function message_templates_help_tab()
795
-    {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
-    }
798
-
799
-
800
-    public function edit_message_template_help_tab()
801
-    {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
-                        . esc_attr__('Editor Title', 'event_espresso')
804
-                        . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
807
-                        . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
810
-                        . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
813
-                        . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
-                        . esc_attr__('Publish Metabox', 'event_espresso')
816
-                        . '" />';
817
-        EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
-            $args
820
-        );
821
-    }
822
-
823
-
824
-    /**
825
-     * @throws ReflectionException
826
-     * @throws EE_Error
827
-     */
828
-    public function message_template_shortcodes_help_tab()
829
-    {
830
-        $this->_set_shortcodes();
831
-        $args['shortcodes'] = $this->_shortcodes;
832
-        EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
-            $args
835
-        );
836
-    }
837
-
838
-
839
-    public function preview_message_help_tab()
840
-    {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
-    }
843
-
844
-
845
-    public function settings_help_tab()
846
-    {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
-        $args['img3'] = '<div class="switch">'
852
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
-                        . ' type="checkbox" checked="checked">'
854
-                        . '<label for="ee-on-off-toggle-on"></label>'
855
-                        . '</div>';
856
-        $args['img4'] = '<div class="switch">'
857
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
-                        . ' type="checkbox">'
859
-                        . '<label for="ee-on-off-toggle-on"></label>'
860
-                        . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
-    }
863
-
864
-
865
-    public function load_scripts_styles()
866
-    {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
-        wp_enqueue_style('espresso_ee_msg');
869
-
870
-        wp_register_script(
871
-            'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
874
-            EVENT_ESPRESSO_VERSION,
875
-            true
876
-        );
877
-        wp_register_script(
878
-            'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
-            ['ee-dialog'],
881
-            EVENT_ESPRESSO_VERSION
882
-        );
883
-    }
884
-
885
-
886
-    public function load_scripts_styles_default()
887
-    {
888
-        wp_enqueue_script('ee-msg-list-table-js');
889
-    }
890
-
891
-
892
-    public function wp_editor_css($mce_css)
893
-    {
894
-        // if we're on the edit_message_template route
895
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
-            $message_type_name = $this->_active_message_type_name;
897
-
898
-            // we're going to REPLACE the existing mce css
899
-            // we need to get the css file location from the active messenger
900
-            $mce_css = $this->_active_messenger->get_variation(
901
-                $this->_template_pack,
902
-                $message_type_name,
903
-                true,
904
-                'wpeditor',
905
-                $this->_variation
906
-            );
907
-        }
908
-
909
-        return $mce_css;
910
-    }
911
-
912
-
913
-    /**
914
-     * @throws EE_Error
915
-     * @throws ReflectionException
916
-     */
917
-    public function load_scripts_styles_edit_message_template()
918
-    {
919
-
920
-        $this->_set_shortcodes();
921
-
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
-            esc_html__(
924
-                '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.',
925
-                'event_espresso'
926
-            ),
927
-            $this->_message_template_group->messenger_obj()->label['singular'],
928
-            $this->_message_template_group->message_type_obj()->label['singular']
929
-        );
930
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
-            '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?',
932
-            'event_espresso'
933
-        );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
-            'event_espresso'
937
-        );
938
-
939
-        wp_register_script(
940
-            'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
-            ['jquery'],
943
-            EVENT_ESPRESSO_VERSION
944
-        );
945
-
946
-        wp_enqueue_script('ee_admin_js');
947
-        wp_enqueue_script('ee_msgs_edit_js');
948
-
949
-        // add in special css for tiny_mce
950
-        add_filter('mce_css', [$this, 'wp_editor_css']);
951
-    }
952
-
953
-
954
-    /**
955
-     * @throws EE_Error
956
-     * @throws ReflectionException
957
-     */
958
-    public function load_scripts_styles_display_preview_message()
959
-    {
960
-        $this->_set_message_template_group();
961
-        if ($this->_active_messenger_name) {
962
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
-                $this->_active_messenger_name
964
-            );
965
-        }
966
-
967
-        wp_enqueue_style(
968
-            'espresso_preview_css',
969
-            $this->_active_messenger->get_variation(
970
-                $this->_template_pack,
971
-                $this->_active_message_type_name,
972
-                true,
973
-                'preview',
974
-                $this->_variation
975
-            )
976
-        );
977
-    }
978
-
979
-
980
-    public function load_scripts_styles_settings()
981
-    {
982
-        wp_register_style(
983
-            'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
-            [],
986
-            EVENT_ESPRESSO_VERSION
987
-        );
988
-        wp_enqueue_style('ee-text-links');
989
-        wp_enqueue_style('ee-message-settings');
990
-        wp_enqueue_script('ee-messages-settings');
991
-    }
992
-
993
-
994
-    /**
995
-     * set views array for List Table
996
-     */
997
-    public function _set_list_table_views_global_mtps()
998
-    {
999
-        $this->_views = [
1000
-            'in_use' => [
1001
-                'slug'  => 'in_use',
1002
-                'label' => esc_html__('In Use', 'event_espresso'),
1003
-                'count' => 0,
1004
-            ],
1005
-        ];
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * Set views array for the Custom Template List Table
1011
-     */
1012
-    public function _set_list_table_views_custom_mtps()
1013
-    {
1014
-        $this->_set_list_table_views_global_mtps();
1015
-        $this->_views['in_use']['bulk_action'] = [
1016
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
-        ];
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * set views array for message queue list table
1023
-     *
1024
-     * @throws InvalidDataTypeException
1025
-     * @throws InvalidInterfaceException
1026
-     * @throws InvalidArgumentException
1027
-     * @throws EE_Error
1028
-     * @throws ReflectionException
1029
-     */
1030
-    public function _set_list_table_views_default()
1031
-    {
1032
-        EE_Registry::instance()->load_helper('Template');
1033
-
1034
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
-            'ee_send_message',
1036
-            'message_list_table_bulk_actions'
1037
-        )
1038
-            ? [
1039
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
-            ]
1044
-            : [];
1045
-
1046
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
-            'ee_delete_messages',
1048
-            'message_list_table_bulk_actions'
1049
-        )
1050
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
-            : [];
1052
-
1053
-
1054
-        $this->_views = [
1055
-            'all' => [
1056
-                'slug'        => 'all',
1057
-                'label'       => esc_html__('All', 'event_espresso'),
1058
-                'count'       => 0,
1059
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
-            ],
1061
-        ];
1062
-
1063
-
1064
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
-                continue;
1067
-            }
1068
-            $status_bulk_actions = $common_bulk_actions;
1069
-            // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1071
-                switch ($status) {
1072
-                    case EEM_Message::status_idle:
1073
-                    case EEM_Message::status_resend:
1074
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
-                        break;
1076
-
1077
-                    case EEM_Message::status_failed:
1078
-                    case EEM_Message::status_debug_only:
1079
-                    case EEM_Message::status_messenger_executing:
1080
-                        $status_bulk_actions = [];
1081
-                        break;
1082
-
1083
-                    case EEM_Message::status_incomplete:
1084
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
-                        break;
1086
-
1087
-                    case EEM_Message::status_retry:
1088
-                    case EEM_Message::status_sent:
1089
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
-                        break;
1091
-                }
1092
-            }
1093
-
1094
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1095
-            if ($status === EEM_Message::status_messenger_executing) {
1096
-                continue;
1097
-            }
1098
-
1099
-            $this->_views[ strtolower($status) ] = [
1100
-                'slug'        => strtolower($status),
1101
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
-                'count'       => 0,
1103
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
-            ];
1105
-        }
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * @throws EE_Error
1111
-     */
1112
-    protected function _ee_default_messages_overview_list_table()
1113
-    {
1114
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
-        $this->display_admin_list_table_page_with_no_sidebar();
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * @throws EE_Error
1121
-     * @throws ReflectionException
1122
-     */
1123
-    protected function _message_queue_list_table()
1124
-    {
1125
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
-        $this->_template_args['per_column']        = 6;
1127
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
-        $message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1129
-        $this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1130
-        $this->display_admin_list_table_page_with_no_sidebar();
1131
-    }
1132
-
1133
-
1134
-    /**
1135
-     * @throws EE_Error
1136
-     */
1137
-    protected function _message_legend_items()
1138
-    {
1139
-
1140
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1141
-        $action_items       = [];
1142
-
1143
-        foreach ($action_css_classes as $action_item => $action_details) {
1144
-            if ($action_item === 'see_notifications_for') {
1145
-                continue;
1146
-            }
1147
-            $action_items[ $action_item ] = [
1148
-                'class' => $action_details['css_class'],
1149
-                'desc'  => $action_details['label'],
1150
-            ];
1151
-        }
1152
-
1153
-        /** @var array $status_items status legend setup */
1154
-        $status_items = [
1155
-            'sent_status'                => [
1156
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1157
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158
-            ],
1159
-            'idle_status'                => [
1160
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1161
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162
-            ],
1163
-            'failed_status'              => [
1164
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1165
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166
-            ],
1167
-            'messenger_executing_status' => [
1168
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1169
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170
-            ],
1171
-            'resend_status'              => [
1172
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1173
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174
-            ],
1175
-            'incomplete_status'          => [
1176
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1177
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178
-            ],
1179
-            'retry_status'               => [
1180
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1181
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182
-            ],
1183
-        ];
1184
-        if (EEM_Message::debug()) {
1185
-            $status_items['debug_only_status'] = [
1186
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1187
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188
-            ];
1189
-        }
1190
-
1191
-        return array_merge($action_items, $status_items);
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * @throws EE_Error
1197
-     */
1198
-    protected function _custom_mtps_preview()
1199
-    {
1200
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
-                                                . ' alt="' . esc_attr__(
1203
-                                                    'Preview Custom Message Templates screenshot',
1204
-                                                    'event_espresso'
1205
-                                                ) . '" />';
1206
-        $this->_template_args['preview_text'] = '<strong>'
1207
-                                                . esc_html__(
1208
-                                                    '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.',
1209
-                                                    'event_espresso'
1210
-                                                )
1211
-                                                . '</strong>';
1212
-
1213
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     * get_message_templates
1219
-     * This gets all the message templates for listing on the overview list.
1220
-     *
1221
-     * @access public
1222
-     * @param int    $per_page the amount of templates groups to show per page
1223
-     * @param string $type     the current _view we're getting templates for
1224
-     * @param bool   $count    return count?
1225
-     * @param bool   $all      disregard any paging info (get all data);
1226
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1227
-     * @return array
1228
-     * @throws EE_Error
1229
-     * @throws InvalidArgumentException
1230
-     * @throws InvalidDataTypeException
1231
-     * @throws InvalidInterfaceException
1232
-     */
1233
-    public function get_message_templates(
1234
-        $per_page = 10,
1235
-        $type = 'in_use',
1236
-        $count = false,
1237
-        $all = false,
1238
-        $global = true
1239
-    ) {
1240
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1241
-        $this->request->setRequestParam('orderby', $orderby);
1242
-
1243
-        $order        = $this->request->getRequestParam('order', 'ASC');
1244
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1245
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1246
-
1247
-        $offset = ($current_page - 1) * $per_page;
1248
-        $limit  = $all ? null : [$offset, $per_page];
1249
-
1250
-        // options will match what is in the _views array property
1251
-        return $type === 'in_use'
1252
-            ? $this->getMtgModel()->get_all_active_message_templates(
1253
-                $orderby,
1254
-                $order,
1255
-                $limit,
1256
-                $count,
1257
-                $global,
1258
-                true
1259
-            )
1260
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1261
-                $orderby,
1262
-                $order,
1263
-                $limit,
1264
-                $count,
1265
-                $global
1266
-            );
1267
-    }
1268
-
1269
-
1270
-    /**
1271
-     * filters etc might need a list of installed message_types
1272
-     *
1273
-     * @return array an array of message type objects
1274
-     */
1275
-    public function get_installed_message_types()
1276
-    {
1277
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1278
-        $installed               = [];
1279
-
1280
-        foreach ($installed_message_types as $message_type) {
1281
-            $installed[ $message_type->name ] = $message_type;
1282
-        }
1283
-
1284
-        return $installed;
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1290
-     *
1291
-     * @param string $message_type
1292
-     * @param string $messenger
1293
-     * @param string $GRP_ID
1294
-     *
1295
-     * @throws EE_error
1296
-     * @throws ReflectionException
1297
-     */
1298
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1299
-    {
1300
-        // set values override any request data
1301
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1302
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1303
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1304
-
1305
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1306
-        if (empty($message_type) || empty($messenger)) {
1307
-            throw new EE_Error(
1308
-                esc_html__(
1309
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1310
-                    'event_espresso'
1311
-                )
1312
-            );
1313
-        }
1314
-
1315
-        // we need the GRP_ID for the template being used as the base for the new template
1316
-        if (empty($GRP_ID)) {
1317
-            throw new EE_Error(
1318
-                esc_html__(
1319
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1320
-                    'event_espresso'
1321
-                )
1322
-            );
1323
-        }
1324
-
1325
-        // let's just make sure the template gets generated!
1326
-
1327
-        // we need to reassign some variables for what the insert is expecting
1328
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1329
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1330
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1331
-
1332
-        $this->_insert_or_update_message_template(true);
1333
-    }
1334
-
1335
-
1336
-    /**
1337
-     * @param string $message_type     message type slug
1338
-     * @param string $messenger        messenger slug
1339
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1340
-     *                                 off of.
1341
-     * @throws EE_error
1342
-     * @throws ReflectionException
1343
-     * @deprecated 4.10.29.p
1344
-     */
1345
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1346
-    {
1347
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * _edit_message_template
1353
-     *
1354
-     * @access protected
1355
-     * @return void
1356
-     * @throws InvalidIdentifierException
1357
-     * @throws DomainException
1358
-     * @throws EE_Error
1359
-     * @throws InvalidArgumentException
1360
-     * @throws ReflectionException
1361
-     * @throws InvalidDataTypeException
1362
-     * @throws InvalidInterfaceException
1363
-     */
1364
-    protected function _edit_message_template()
1365
-    {
1366
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1367
-        $template_fields = '';
1368
-        $sidebar_fields  = '';
1369
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1370
-        // valid html in the templates.
1371
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1372
-
1373
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1374
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1375
-
1376
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1377
-        $message_template_group = $this->_message_template_group;
1378
-        $c_label                = $message_template_group->context_label();
1379
-        $c_config               = $message_template_group->contexts_config();
1380
-
1381
-        reset($c_config);
1382
-        $context = $this->request->getRequestParam('context', key($c_config));
1383
-        $context = strtolower($context);
1384
-
1385
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1386
-
1387
-        $edit_message_template_form_url = add_query_arg(
1388
-            ['action' => $action, 'noheader' => true],
1389
-            EE_MSG_ADMIN_URL
1390
-        );
1391
-
1392
-        // set active messenger for this view
1393
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1394
-            $message_template_group->messenger()
1395
-        );
1396
-        $this->_active_message_type_name = $message_template_group->message_type();
1397
-
1398
-
1399
-        // Do we have any validation errors?
1400
-        $validators = $this->_get_transient();
1401
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1402
-
1403
-
1404
-        // we need to assemble the title from Various details
1405
-        $context_label = sprintf(
1406
-            esc_html__('(%s %s)', 'event_espresso'),
1407
-            $c_config[ $context ]['label'],
1408
-            ucwords($c_label['label'])
1409
-        );
1410
-
1411
-        $title = sprintf(
1412
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1413
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1414
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1415
-            $context_label
1416
-        );
1417
-
1418
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1419
-        $this->_template_args['message_template'] = $message_template_group;
1420
-        $this->_template_args['is_extra_fields']  = false;
1421
-
1422
-
1423
-        // let's get EEH_MSG_Template so we can get template form fields
1424
-        $template_field_structure = EEH_MSG_Template::get_fields(
1425
-            $message_template_group->messenger(),
1426
-            $message_template_group->message_type()
1427
-        );
1428
-
1429
-        if (! $template_field_structure) {
1430
-            $template_field_structure = false;
1431
-            $template_fields          = esc_html__(
1432
-                'There was an error in assembling the fields for this display (you should see an error message)',
1433
-                'event_espresso'
1434
-            );
1435
-        }
1436
-
1437
-
1438
-        $message_templates = $message_template_group->context_templates();
1439
-
1440
-
1441
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442
-        // will get handled in the "extra" array.
1443
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
-                unset($template_field_structure[ $context ][ $reference_field ]);
1446
-            }
1447
-        }
1448
-
1449
-        // let's loop through the template_field_structure and actually assemble the input fields!
1450
-        if (! empty($template_field_structure)) {
1451
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1452
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453
-                // the extra array and reset them.
1454
-                if ($template_field === 'extra') {
1455
-                    $this->_template_args['is_extra_fields'] = true;
1456
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1458
-                        $content          = $message_template instanceof EE_Message_Template
1459
-                            ? $message_template->get('MTP_content')
1460
-                            : '';
1461
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1462
-                            // let's verify if we need this extra field via the shortcodes parameter.
1463
-                            $continue = false;
1464
-                            if (isset($extra_array['shortcodes_required'])) {
1465
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
-                                        $continue = true;
1468
-                                    }
1469
-                                }
1470
-                                if ($continue) {
1471
-                                    continue;
1472
-                                }
1473
-                            }
1474
-
1475
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1476
-
1477
-                            $template_form_fields[ $field_id ]         = $extra_array;
1478
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1479
-                                                                         . $reference_field
1480
-                                                                         . '][content]['
1481
-                                                                         . $extra_field . ']';
1482
-                            $css_class                                 = isset($extra_array['css_class'])
1483
-                                ? $extra_array['css_class']
1484
-                                : '';
1485
-
1486
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
-                                                                              && in_array($extra_field, $v_fields, true)
1488
-                                                                              && (
1489
-                                                                                  is_array($validators[ $extra_field ])
1490
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1491
-                                                                              )
1492
-                                ? 'validate-error ' . $css_class
1493
-                                : $css_class;
1494
-
1495
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
-                                                                          && isset($content[ $extra_field ])
1497
-                                ? $content[ $extra_field ]
1498
-                                : '';
1499
-
1500
-                            // do we have a validation error?  if we do then let's use that value instead
1501
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
-                                ? $validators[ $extra_field ]['value']
1503
-                                : $template_form_fields[ $field_id ]['value'];
1504
-
1505
-
1506
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
-
1508
-                            // shortcode selector
1509
-                            $field_name_to_use                                   = $extra_field === 'main'
1510
-                                ? 'content'
1511
-                                : $extra_field;
1512
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
-                                $field_name_to_use,
1514
-                                $field_id
1515
-                            );
1516
-                        }
1517
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
-                        $template_field_template_name_id = $reference_field . '-name';
1519
-
1520
-                        $template_form_fields[ $template_field_MTP_id ] = [
1521
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1522
-                            'label'      => null,
1523
-                            'input'      => 'hidden',
1524
-                            'type'       => 'int',
1525
-                            'required'   => false,
1526
-                            'validation' => false,
1527
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1528
-                            'css_class'  => '',
1529
-                            'format'     => '%d',
1530
-                            'db-col'     => 'MTP_ID',
1531
-                        ];
1532
-
1533
-                        $template_form_fields[ $template_field_template_name_id ] = [
1534
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1535
-                            'label'      => null,
1536
-                            'input'      => 'hidden',
1537
-                            'type'       => 'string',
1538
-                            'required'   => false,
1539
-                            'validation' => true,
1540
-                            'value'      => $reference_field,
1541
-                            'css_class'  => '',
1542
-                            'format'     => '%s',
1543
-                            'db-col'     => 'MTP_template_field',
1544
-                        ];
1545
-                    }
1546
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547
-                } else {
1548
-                    $field_id                                   = $template_field . '-content';
1549
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1550
-                    $template_form_fields[ $field_id ]['name']  =
1551
-                        'MTP_template_fields[' . $template_field . '][content]';
1552
-                    $message_template                           =
1553
-                        isset($message_templates[ $context ][ $template_field ])
1554
-                            ? $message_templates[ $context ][ $template_field ]
1555
-                            : null;
1556
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
-                                                                  && is_array($message_templates[ $context ])
1558
-                                                                  && $message_template instanceof EE_Message_Template
1559
-                        ? $message_template->get('MTP_content')
1560
-                        : '';
1561
-
1562
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1563
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
-                        ? $validators[ $template_field ]['value']
1565
-                        : $template_form_fields[ $field_id ]['value'];
1566
-
1567
-
1568
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
-                    $css_class                                      = isset($field_setup_array['css_class'])
1570
-                        ? $field_setup_array['css_class']
1571
-                        : '';
1572
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
-                                                                      && in_array($template_field, $v_fields, true)
1574
-                                                                      && isset($validators[ $template_field ]['msg'])
1575
-                        ? 'validate-error ' . $css_class
1576
-                        : $css_class;
1577
-
1578
-                    // shortcode selector
1579
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
-                        $template_field,
1581
-                        $field_id
1582
-                    );
1583
-                }
1584
-
1585
-                // k took care of content field(s) now let's take care of others.
1586
-
1587
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
-                $template_field_field_template_name_id = $template_field . '-name';
1589
-
1590
-                // foreach template field there are actually two form fields created
1591
-                $template_form_fields[ $template_field_MTP_id ] = [
1592
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1593
-                    'label'      => null,
1594
-                    'input'      => 'hidden',
1595
-                    'type'       => 'int',
1596
-                    'required'   => false,
1597
-                    'validation' => true,
1598
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1599
-                    'css_class'  => '',
1600
-                    'format'     => '%d',
1601
-                    'db-col'     => 'MTP_ID',
1602
-                ];
1603
-
1604
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1605
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1606
-                    'label'      => null,
1607
-                    'input'      => 'hidden',
1608
-                    'type'       => 'string',
1609
-                    'required'   => false,
1610
-                    'validation' => true,
1611
-                    'value'      => $template_field,
1612
-                    'css_class'  => '',
1613
-                    'format'     => '%s',
1614
-                    'db-col'     => 'MTP_template_field',
1615
-                ];
1616
-            }
1617
-
1618
-            // add other fields
1619
-            $template_form_fields['ee-msg-current-context'] = [
1620
-                'name'       => 'MTP_context',
1621
-                'label'      => null,
1622
-                'input'      => 'hidden',
1623
-                'type'       => 'string',
1624
-                'required'   => false,
1625
-                'validation' => true,
1626
-                'value'      => $context,
1627
-                'css_class'  => '',
1628
-                'format'     => '%s',
1629
-                'db-col'     => 'MTP_context',
1630
-            ];
1631
-
1632
-            $template_form_fields['ee-msg-grp-id'] = [
1633
-                'name'       => 'GRP_ID',
1634
-                'label'      => null,
1635
-                'input'      => 'hidden',
1636
-                'type'       => 'int',
1637
-                'required'   => false,
1638
-                'validation' => true,
1639
-                'value'      => $GRP_ID,
1640
-                'css_class'  => '',
1641
-                'format'     => '%d',
1642
-                'db-col'     => 'GRP_ID',
1643
-            ];
1644
-
1645
-            $template_form_fields['ee-msg-messenger'] = [
1646
-                'name'       => 'MTP_messenger',
1647
-                'label'      => null,
1648
-                'input'      => 'hidden',
1649
-                'type'       => 'string',
1650
-                'required'   => false,
1651
-                'validation' => true,
1652
-                'value'      => $message_template_group->messenger(),
1653
-                'css_class'  => '',
1654
-                'format'     => '%s',
1655
-                'db-col'     => 'MTP_messenger',
1656
-            ];
1657
-
1658
-            $template_form_fields['ee-msg-message-type'] = [
1659
-                'name'       => 'MTP_message_type',
1660
-                'label'      => null,
1661
-                'input'      => 'hidden',
1662
-                'type'       => 'string',
1663
-                'required'   => false,
1664
-                'validation' => true,
1665
-                'value'      => $message_template_group->message_type(),
1666
-                'css_class'  => '',
1667
-                'format'     => '%s',
1668
-                'db-col'     => 'MTP_message_type',
1669
-            ];
1670
-
1671
-            $sidebar_form_fields['ee-msg-is-global'] = [
1672
-                'name'       => 'MTP_is_global',
1673
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1674
-                'input'      => 'hidden',
1675
-                'type'       => 'int',
1676
-                'required'   => false,
1677
-                'validation' => true,
1678
-                'value'      => $message_template_group->get('MTP_is_global'),
1679
-                'css_class'  => '',
1680
-                'format'     => '%d',
1681
-                'db-col'     => 'MTP_is_global',
1682
-            ];
1683
-
1684
-            $sidebar_form_fields['ee-msg-is-override'] = [
1685
-                'name'       => 'MTP_is_override',
1686
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1687
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1688
-                'type'       => 'int',
1689
-                'required'   => false,
1690
-                'validation' => true,
1691
-                'value'      => $message_template_group->get('MTP_is_override'),
1692
-                'css_class'  => '',
1693
-                'format'     => '%d',
1694
-                'db-col'     => 'MTP_is_override',
1695
-            ];
1696
-
1697
-            $sidebar_form_fields['ee-msg-is-active'] = [
1698
-                'name'       => 'MTP_is_active',
1699
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1700
-                'input'      => 'hidden',
1701
-                'type'       => 'int',
1702
-                'required'   => false,
1703
-                'validation' => true,
1704
-                'value'      => $message_template_group->is_active(),
1705
-                'css_class'  => '',
1706
-                'format'     => '%d',
1707
-                'db-col'     => 'MTP_is_active',
1708
-            ];
1709
-
1710
-            $sidebar_form_fields['ee-msg-deleted'] = [
1711
-                'name'       => 'MTP_deleted',
1712
-                'label'      => null,
1713
-                'input'      => 'hidden',
1714
-                'type'       => 'int',
1715
-                'required'   => false,
1716
-                'validation' => true,
1717
-                'value'      => $message_template_group->get('MTP_deleted'),
1718
-                'css_class'  => '',
1719
-                'format'     => '%d',
1720
-                'db-col'     => 'MTP_deleted',
1721
-            ];
1722
-            $sidebar_form_fields['ee-msg-author']  = [
1723
-                'name'       => 'MTP_user_id',
1724
-                'label'      => esc_html__('Author', 'event_espresso'),
1725
-                'input'      => 'hidden',
1726
-                'type'       => 'int',
1727
-                'required'   => false,
1728
-                'validation' => false,
1729
-                'value'      => $message_template_group->user(),
1730
-                'format'     => '%d',
1731
-                'db-col'     => 'MTP_user_id',
1732
-            ];
1733
-
1734
-            $sidebar_form_fields['ee-msg-route'] = [
1735
-                'name'  => 'action',
1736
-                'input' => 'hidden',
1737
-                'type'  => 'string',
1738
-                'value' => $action,
1739
-            ];
1740
-
1741
-            $sidebar_form_fields['ee-msg-id']        = [
1742
-                'name'  => 'id',
1743
-                'input' => 'hidden',
1744
-                'type'  => 'int',
1745
-                'value' => $GRP_ID,
1746
-            ];
1747
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
-                'name'  => $action . '_nonce',
1749
-                'input' => 'hidden',
1750
-                'type'  => 'string',
1751
-                'value' => wp_create_nonce($action . '_nonce'),
1752
-            ];
1753
-
1754
-            $template_switch = $this->request->getRequestParam('template_switch');
1755
-            if ($template_switch) {
1756
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1757
-                    'name'  => 'template_switch',
1758
-                    'input' => 'hidden',
1759
-                    'type'  => 'int',
1760
-                    'value' => 1,
1761
-                ];
1762
-            }
1763
-
1764
-
1765
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1766
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1767
-        } //end if ( !empty($template_field_structure) )
1768
-
1769
-        // set extra content for publish box
1770
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1771
-        $this->_set_publish_post_box_vars(
1772
-            'id',
1773
-            $GRP_ID,
1774
-            false,
1775
-            add_query_arg(
1776
-                ['action' => 'global_mtps'],
1777
-                $this->_admin_base_url
1778
-            )
1779
-        );
1780
-
1781
-        // add preview button
1782
-        $preview_url    = parent::add_query_args_and_nonce(
1783
-            [
1784
-                'message_type' => $message_template_group->message_type(),
1785
-                'messenger'    => $message_template_group->messenger(),
1786
-                'context'      => $context,
1787
-                'GRP_ID'       => $GRP_ID,
1788
-                'evt_id'       => $EVT_ID ?: false,
1789
-                'action'       => 'preview_message',
1790
-            ],
1791
-            $this->_admin_base_url
1792
-        );
1793
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1794
-                          . esc_html__('Preview', 'event_espresso')
1795
-                          . '</a>';
1796
-
1797
-
1798
-        // setup context switcher
1799
-        $this->_set_context_switcher(
1800
-            $message_template_group,
1801
-            [
1802
-                'page'    => 'espresso_messages',
1803
-                'action'  => 'edit_message_template',
1804
-                'id'      => $GRP_ID,
1805
-                'evt_id'  => $EVT_ID,
1806
-                'context' => $context,
1807
-                'extra'   => $preview_button,
1808
-            ]
1809
-        );
1810
-
1811
-
1812
-        // main box
1813
-        $this->_template_args['template_fields']                         = $template_fields;
1814
-        $this->_template_args['sidebar_box_id']                          = 'details';
1815
-        $this->_template_args['action']                                  = $action;
1816
-        $this->_template_args['context']                                 = $context;
1817
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1818
-        $this->_template_args['learn_more_about_message_templates_link'] =
1819
-            $this->_learn_more_about_message_templates_link();
1820
-
1821
-
1822
-        $this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1823
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1824
-            $message_template_group,
1825
-            $context,
1826
-            $context_label
1827
-        );
1828
-        $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1829
-        $this->_template_args['before_admin_page_content'] .= '</div>';
1830
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1831
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1832
-
1833
-        $this->_template_path = $this->_template_args['GRP_ID']
1834
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1835
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1836
-
1837
-        // send along EE_Message_Template_Group object for further template use.
1838
-        $this->_template_args['MTP'] = $message_template_group;
1839
-
1840
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1841
-            $this->_template_path,
1842
-            $this->_template_args,
1843
-            true
1844
-        );
1845
-
1846
-
1847
-        // finally, let's set the admin_page title
1848
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1849
-
1850
-
1851
-        // we need to take care of setting the shortcodes property for use elsewhere.
1852
-        $this->_set_shortcodes();
1853
-
1854
-
1855
-        // final template wrapper
1856
-        $this->display_admin_page_with_sidebar();
1857
-    }
1858
-
1859
-
1860
-    public function filter_tinymce_init($mceInit, $editor_id)
1861
-    {
1862
-        return $mceInit;
1863
-    }
1864
-
1865
-
1866
-    public function add_context_switcher()
1867
-    {
1868
-        return $this->_context_switcher;
1869
-    }
1870
-
1871
-
1872
-    /**
1873
-     * Adds the activation/deactivation toggle for the message template context.
1874
-     *
1875
-     * @param EE_Message_Template_Group $message_template_group
1876
-     * @param string                    $context
1877
-     * @param string                    $context_label
1878
-     * @return string
1879
-     * @throws DomainException
1880
-     * @throws EE_Error
1881
-     * @throws InvalidIdentifierException
1882
-     * @throws ReflectionException
1883
-     */
1884
-    protected function add_active_context_element(
1885
-        EE_Message_Template_Group $message_template_group,
1886
-        $context,
1887
-        $context_label
1888
-    ) {
1889
-        $template_args = [
1890
-            'context'                   => $context,
1891
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1892
-            'is_active'                 => $message_template_group->is_context_active($context),
1893
-            'on_off_action'             => $message_template_group->is_context_active($context)
1894
-                ? 'context-off'
1895
-                : 'context-on',
1896
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1897
-            'message_template_group_id' => $message_template_group->ID(),
1898
-        ];
1899
-        return EEH_Template::display_template(
1900
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1901
-            $template_args,
1902
-            true
1903
-        );
1904
-    }
1905
-
1906
-
1907
-    /**
1908
-     * Ajax callback for `toggle_context_template` ajax action.
1909
-     * Handles toggling the message context on or off.
1910
-     *
1911
-     * @throws EE_Error
1912
-     * @throws InvalidArgumentException
1913
-     * @throws InvalidDataTypeException
1914
-     * @throws InvalidIdentifierException
1915
-     * @throws InvalidInterfaceException
1916
-     */
1917
-    public function toggle_context_template()
1918
-    {
1919
-        $success = true;
1920
-        // check for required data
1921
-        if (
1922
-            ! (
1923
-                $this->request->requestParamIsSet('message_template_group_id')
1924
-                && $this->request->requestParamIsSet('context')
1925
-                && $this->request->requestParamIsSet('status')
1926
-            )
1927
-        ) {
1928
-            EE_Error::add_error(
1929
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1930
-                __FILE__,
1931
-                __FUNCTION__,
1932
-                __LINE__
1933
-            );
1934
-            $success = false;
1935
-        }
1936
-
1937
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1938
-        $context = $this->request->getRequestParam('context', '');
1939
-        $status  = $this->request->getRequestParam('status', '');
1940
-
1941
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1942
-
1943
-        if ($status !== 'off' && $status !== 'on') {
1944
-            EE_Error::add_error(
1945
-                sprintf(
1946
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1947
-                    $status
1948
-                ),
1949
-                __FILE__,
1950
-                __FUNCTION__,
1951
-                __LINE__
1952
-            );
1953
-            $success = false;
1954
-        }
1955
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1956
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1957
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1958
-            EE_Error::add_error(
1959
-                sprintf(
1960
-                    esc_html__(
1961
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1962
-                        'event_espresso'
1963
-                    ),
1964
-                    $message_template_group_id,
1965
-                    'EE_Message_Template_Group'
1966
-                ),
1967
-                __FILE__,
1968
-                __FUNCTION__,
1969
-                __LINE__
1970
-            );
1971
-            $success = false;
1972
-        }
1973
-        if ($success) {
1974
-            $success = $status === 'off'
1975
-                ? $message_template_group->deactivate_context($context)
1976
-                : $message_template_group->activate_context($context);
1977
-        }
1978
-        $this->_template_args['success'] = $success;
1979
-        $this->_return_json();
1980
-    }
1981
-
1982
-
1983
-    public function _add_form_element_before()
1984
-    {
1985
-        return '<form method="post" action="'
1986
-               . $this->_template_args['edit_message_template_form_url']
1987
-               . '" id="ee-msg-edit-frm">';
1988
-    }
1989
-
1990
-
1991
-    public function _add_form_element_after()
1992
-    {
1993
-        return '</form>';
1994
-    }
1995
-
1996
-
1997
-    /**
1998
-     * This executes switching the template pack for a message template.
1999
-     *
2000
-     * @throws EE_Error
2001
-     * @throws InvalidDataTypeException
2002
-     * @throws InvalidInterfaceException
2003
-     * @throws InvalidArgumentException
2004
-     * @throws ReflectionException
2005
-     * @since 4.5.0
2006
-     */
2007
-    public function switch_template_pack()
2008
-    {
2009
-
2010
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2011
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2012
-
2013
-        // verify we have needed values.
2014
-        if (empty($GRP_ID) || empty($template_pack)) {
2015
-            $this->_template_args['error'] = true;
2016
-            EE_Error::add_error(
2017
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2018
-                __FILE__,
2019
-                __FUNCTION__,
2020
-                __LINE__
2021
-            );
2022
-        } else {
2023
-            // get template, set the new template_pack and then reset to default
2024
-            /** @var EE_Message_Template_Group $message_template_group */
2025
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2026
-
2027
-            $message_template_group->set_template_pack_name($template_pack);
2028
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2029
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2030
-
2031
-            $query_args = $this->_reset_to_default_template();
2032
-
2033
-            if (empty($query_args['id'])) {
2034
-                EE_Error::add_error(
2035
-                    esc_html__(
2036
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2037
-                        'event_espresso'
2038
-                    ),
2039
-                    __FILE__,
2040
-                    __FUNCTION__,
2041
-                    __LINE__
2042
-                );
2043
-                $this->_template_args['error'] = true;
2044
-            } else {
2045
-                $template_label       = $message_template_group->get_template_pack()->label;
2046
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2047
-                EE_Error::add_success(
2048
-                    sprintf(
2049
-                        esc_html__(
2050
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2051
-                            'event_espresso'
2052
-                        ),
2053
-                        $template_label,
2054
-                        $template_pack_labels->template_pack
2055
-                    )
2056
-                );
2057
-                // generate the redirect url for js.
2058
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2059
-
2060
-                $this->_template_args['data']['redirect_url'] = $url;
2061
-                $this->_template_args['success']              = true;
2062
-            }
2063
-
2064
-            $this->_return_json();
2065
-        }
2066
-    }
2067
-
2068
-
2069
-    /**
2070
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2071
-     * they want.
2072
-     *
2073
-     * @access protected
2074
-     * @return array|void
2075
-     * @throws EE_Error
2076
-     * @throws InvalidArgumentException
2077
-     * @throws InvalidDataTypeException
2078
-     * @throws InvalidInterfaceException
2079
-     * @throws ReflectionException
2080
-     */
2081
-    protected function _reset_to_default_template()
2082
-    {
2083
-        $templates    = [];
2084
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2085
-        $messenger    = $this->request->getRequestParam('msgr');
2086
-        $message_type = $this->request->getRequestParam('mt');
2087
-        // we need to make sure we've got the info we need.
2088
-        if (! ($GRP_ID && $messenger && $message_type)) {
2089
-            EE_Error::add_error(
2090
-                esc_html__(
2091
-                    '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.',
2092
-                    'event_espresso'
2093
-                ),
2094
-                __FILE__,
2095
-                __FUNCTION__,
2096
-                __LINE__
2097
-            );
2098
-        }
2099
-
2100
-        // all templates will be reset to whatever the defaults are
2101
-        // for the global template matching the messenger and message type.
2102
-        $success = ! empty($GRP_ID);
2103
-
2104
-        if ($success) {
2105
-            // let's first determine if the incoming template is a global template,
2106
-            // if it isn't then we need to get the global template matching messenger and message type.
2107
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2108
-
2109
-
2110
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2111
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2112
-
2113
-            if ($success) {
2114
-                // if successfully deleted, lets generate the new ones.
2115
-                // Note. We set GLOBAL to true, because resets on ANY template
2116
-                // will use the related global template defaults for regeneration.
2117
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2118
-                // HOWEVER, we DO keep the template pack and template variation set
2119
-                // for the current custom template when resetting.
2120
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2121
-            }
2122
-        }
2123
-
2124
-        // any error messages?
2125
-        if (! $success) {
2126
-            EE_Error::add_error(
2127
-                esc_html__(
2128
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2129
-                    'event_espresso'
2130
-                ),
2131
-                __FILE__,
2132
-                __FUNCTION__,
2133
-                __LINE__
2134
-            );
2135
-        }
2136
-
2137
-        // all good, let's add a success message!
2138
-        if ($success && ! empty($templates)) {
2139
-            // the info for the template we generated is the first element in the returned array
2140
-            EE_Error::overwrite_success();
2141
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2142
-        }
2143
-
2144
-
2145
-        $query_args = [
2146
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2147
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2148
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2149
-        ];
2150
-
2151
-        // if called via ajax then we return query args otherwise redirect
2152
-        if ($this->request->isAjax()) {
2153
-            return $query_args;
2154
-        }
2155
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2156
-    }
2157
-
2158
-
2159
-    /**
2160
-     * Retrieve and set the message preview for display.
2161
-     *
2162
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2163
-     * @return string
2164
-     * @throws ReflectionException
2165
-     * @throws EE_Error
2166
-     * @throws InvalidArgumentException
2167
-     * @throws InvalidDataTypeException
2168
-     * @throws InvalidInterfaceException
2169
-     */
2170
-    public function _preview_message($send = false)
2171
-    {
2172
-        // first make sure we've got the necessary parameters
2173
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2174
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2175
-            EE_Error::add_error(
2176
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2177
-                __FILE__,
2178
-                __FUNCTION__,
2179
-                __LINE__
2180
-            );
2181
-        }
2182
-
2183
-        $context = $this->request->getRequestParam('context');
2184
-        // get the preview!
2185
-        $preview = EED_Messages::preview_message(
2186
-            $this->_active_message_type_name,
2187
-            $context,
2188
-            $this->_active_messenger_name,
2189
-            $send
2190
-        );
2191
-
2192
-        if ($send) {
2193
-            return $preview;
2194
-        }
2195
-
2196
-        // if we have an evt_id set on the request, use it.
2197
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2198
-
2199
-        // let's add a button to go back to the edit view
2200
-        $query_args             = [
2201
-            'id'      => $GRP_ID,
2202
-            'evt_id'  => $EVT_ID,
2203
-            'context' => $context,
2204
-            'action'  => 'edit_message_template',
2205
-        ];
2206
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2207
-        $preview_button         = '<a href="'
2208
-                                  . $go_back_url
2209
-                                  . '" class="button--secondary messages-preview-go-back-button">'
2210
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2211
-                                  . '</a>';
2212
-        $message_types          = $this->get_installed_message_types();
2213
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2214
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2215
-            ? ucwords($active_messenger->label['singular'])
2216
-            : esc_html__('Unknown Messenger', 'event_espresso');
2217
-        // let's provide a helpful title for context
2218
-        $preview_title = sprintf(
2219
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2220
-            $active_messenger_label,
2221
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2222
-        );
2223
-        if (empty($preview)) {
2224
-            $this->noEventsErrorMessage();
2225
-        }
2226
-        // setup display of preview.
2227
-        $this->_admin_page_title                    = $preview_title;
2228
-        $this->_template_args['admin_page_title']   = $preview_title;
2229
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2230
-        $this->_template_args['data']['force_json'] = true;
2231
-
2232
-        return '';
2233
-    }
2234
-
2235
-
2236
-    /**
2237
-     * Used to set an error if there are no events available for generating a preview/test send.
2238
-     *
2239
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2240
-     */
2241
-    protected function noEventsErrorMessage($test_send = false)
2242
-    {
2243
-        $events_url = parent::add_query_args_and_nonce(
2244
-            [
2245
-                'action' => 'default',
2246
-                'page'   => 'espresso_events',
2247
-            ],
2248
-            admin_url('admin.php')
2249
-        );
2250
-        $message    = $test_send
2251
-            ? esc_html__(
2252
-                '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!',
2253
-                'event_espresso'
2254
-            )
2255
-            : esc_html__(
2256
-                '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!',
2257
-                'event_espresso'
2258
-            );
2259
-
2260
-        EE_Error::add_attention(
2261
-            sprintf(
2262
-                $message,
2263
-                "<a href='{$events_url}'>",
2264
-                '</a>'
2265
-            )
2266
-        );
2267
-    }
2268
-
2269
-
2270
-    /**
2271
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2272
-     * gets called automatically.
2273
-     *
2274
-     * @return void
2275
-     * @throws EE_Error
2276
-     * @since 4.5.0
2277
-     *
2278
-     */
2279
-    protected function _display_preview_message()
2280
-    {
2281
-        $this->display_admin_page_with_no_sidebar();
2282
-    }
2283
-
2284
-
2285
-    /**
2286
-     * registers metaboxes that should show up on the "edit_message_template" page
2287
-     *
2288
-     * @access protected
2289
-     * @return void
2290
-     */
2291
-    protected function _register_edit_meta_boxes()
2292
-    {
2293
-        $this->addMetaBox(
2294
-            'mtp_valid_shortcodes',
2295
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2296
-            [$this, 'shortcode_meta_box'],
2297
-            $this->_current_screen->id,
2298
-            'side'
2299
-        );
2300
-        $this->addMetaBox(
2301
-            'mtp_extra_actions',
2302
-            esc_html__('Extra Actions', 'event_espresso'),
2303
-            [$this, 'extra_actions_meta_box'],
2304
-            $this->_current_screen->id,
2305
-            'side',
2306
-            'high'
2307
-        );
2308
-        $this->addMetaBox(
2309
-            'mtp_templates',
2310
-            esc_html__('Template Styles', 'event_espresso'),
2311
-            [$this, 'template_pack_meta_box'],
2312
-            $this->_current_screen->id,
2313
-            'side',
2314
-            'high'
2315
-        );
2316
-    }
2317
-
2318
-
2319
-    /**
2320
-     * metabox content for all template pack and variation selection.
2321
-     *
2322
-     * @return void
2323
-     * @throws DomainException
2324
-     * @throws EE_Error
2325
-     * @throws InvalidArgumentException
2326
-     * @throws ReflectionException
2327
-     * @throws InvalidDataTypeException
2328
-     * @throws InvalidInterfaceException
2329
-     * @since 4.5.0
2330
-     */
2331
-    public function template_pack_meta_box()
2332
-    {
2333
-        $this->_set_message_template_group();
2334
-
2335
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2336
-
2337
-        $tp_select_values = [];
2338
-
2339
-        foreach ($tp_collection as $tp) {
2340
-            // only include template packs that support this messenger and message type!
2341
-            $supports = $tp->get_supports();
2342
-            if (
2343
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2344
-                || ! in_array(
2345
-                    $this->_message_template_group->message_type(),
2346
-                    $supports[ $this->_message_template_group->messenger() ],
2347
-                    true
2348
-                )
2349
-            ) {
2350
-                // not supported
2351
-                continue;
2352
-            }
2353
-
2354
-            $tp_select_values[] = [
2355
-                'text' => $tp->label,
2356
-                'id'   => $tp->dbref,
2357
-            ];
2358
-        }
2359
-
2360
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2361
-        // the default template pack.  This still allows for the odd template pack to override.
2362
-        if (empty($tp_select_values)) {
2363
-            $tp_select_values[] = [
2364
-                'text' => esc_html__('Default', 'event_espresso'),
2365
-                'id'   => 'default',
2366
-            ];
2367
-        }
2368
-
2369
-        // setup variation select values for the currently selected template.
2370
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2371
-            $this->_message_template_group->messenger(),
2372
-            $this->_message_template_group->message_type()
2373
-        );
2374
-        $variations_select_values = [];
2375
-        foreach ($variations as $variation => $label) {
2376
-            $variations_select_values[] = [
2377
-                'text' => $label,
2378
-                'id'   => $variation,
2379
-            ];
2380
-        }
2381
-
2382
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2383
-
2384
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2385
-            'MTP_template_pack',
2386
-            $tp_select_values,
2387
-            $this->_message_template_group->get_template_pack_name()
2388
-        );
2389
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2390
-            'MTP_template_variation',
2391
-            $variations_select_values,
2392
-            $this->_message_template_group->get_template_pack_variation()
2393
-        );
2394
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2395
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2396
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2397
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2398
-
2399
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2400
-
2401
-        EEH_Template::display_template($template, $template_args);
2402
-    }
2403
-
2404
-
2405
-    /**
2406
-     * This meta box holds any extra actions related to Message Templates
2407
-     * For now, this includes Resetting templates to defaults and sending a test email.
2408
-     *
2409
-     * @access  public
2410
-     * @return void
2411
-     * @throws EE_Error
2412
-     */
2413
-    public function extra_actions_meta_box()
2414
-    {
2415
-        $template_form_fields = [];
2416
-
2417
-        $extra_args = [
2418
-            'msgr'   => $this->_message_template_group->messenger(),
2419
-            'mt'     => $this->_message_template_group->message_type(),
2420
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2421
-        ];
2422
-        // first we need to see if there are any fields
2423
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2424
-
2425
-        if (! empty($fields)) {
2426
-            // yup there be fields
2427
-            foreach ($fields as $field => $config) {
2428
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2429
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2430
-                $default  = isset($config['default']) ? $config['default'] : '';
2431
-                $default  = isset($config['value']) ? $config['value'] : $default;
2432
-
2433
-                // if type is hidden and the value is empty
2434
-                // something may have gone wrong so let's correct with the defaults
2435
-                $fix                = $config['input'] === 'hidden'
2436
-                                      && isset($existing[ $field ])
2437
-                                      && empty($existing[ $field ])
2438
-                    ? $default
2439
-                    : '';
2440
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2441
-                    ? $existing[ $field ]
2442
-                    : $fix;
2443
-
2444
-                $template_form_fields[ $field_id ] = [
2445
-                    'name'       => 'test_settings_fld[' . $field . ']',
2446
-                    'label'      => $config['label'],
2447
-                    'input'      => $config['input'],
2448
-                    'type'       => $config['type'],
2449
-                    'required'   => $config['required'],
2450
-                    'validation' => $config['validation'],
2451
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2452
-                    'css_class'  => $config['css_class'],
2453
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2454
-                    'default'    => $default,
2455
-                    'format'     => $config['format'],
2456
-                ];
2457
-            }
2458
-        }
2459
-
2460
-        $test_settings_html = ! empty($template_form_fields)
2461
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2462
-            : '';
2463
-
2464
-        // print out $test_settings_fields
2465
-        if (! empty($test_settings_html)) {
2466
-            $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2467
-            $test_settings_html .= 'name="test_button" value="';
2468
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2469
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2470
-        }
2471
-
2472
-        // and button
2473
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2474
-        $test_settings_html .= '<p>';
2475
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2476
-        $test_settings_html .= '</p>';
2477
-        $test_settings_html .= $this->get_action_link_or_button(
2478
-            'reset_to_default',
2479
-            'reset',
2480
-            $extra_args,
2481
-            'button--primary reset-default-button'
2482
-        );
2483
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2484
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2485
-    }
2486
-
2487
-
2488
-    /**
2489
-     * This returns the shortcode selector skeleton for a given context and field.
2490
-     *
2491
-     * @param string $field           The name of the field retrieving shortcodes for.
2492
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2493
-     * @return string
2494
-     * @throws DomainException
2495
-     * @throws EE_Error
2496
-     * @throws InvalidArgumentException
2497
-     * @throws ReflectionException
2498
-     * @throws InvalidDataTypeException
2499
-     * @throws InvalidInterfaceException
2500
-     * @since 4.9.rc.000
2501
-     */
2502
-    protected function _get_shortcode_selector($field, $linked_input_id)
2503
-    {
2504
-        $template_args = [
2505
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2506
-            'fieldname'       => $field,
2507
-            'linked_input_id' => $linked_input_id,
2508
-        ];
2509
-
2510
-        return EEH_Template::display_template(
2511
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2512
-            $template_args,
2513
-            true
2514
-        );
2515
-    }
2516
-
2517
-
2518
-    /**
2519
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2520
-     * page)
2521
-     *
2522
-     * @access public
2523
-     * @return void
2524
-     * @throws EE_Error
2525
-     * @throws InvalidArgumentException
2526
-     * @throws ReflectionException
2527
-     * @throws InvalidDataTypeException
2528
-     * @throws InvalidInterfaceException
2529
-     */
2530
-    public function shortcode_meta_box()
2531
-    {
2532
-        $shortcodes = $this->_get_shortcodes([], false);
2533
-        // just make sure the shortcodes property is set
2534
-        // $messenger = $this->_message_template_group->messenger_obj();
2535
-        // now let's set the content depending on the status of the shortcodes array
2536
-        if (empty($shortcodes)) {
2537
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2538
-            return;
2539
-        }
2540
-        ?>
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 $_context_switcher;
62
+
63
+	protected $_shortcodes           = [];
64
+
65
+	protected $_active_messengers    = [];
66
+
67
+	protected $_active_message_types = [];
68
+
69
+	/**
70
+	 * @var EE_Message_Template_Group $_message_template_group
71
+	 */
72
+	protected $_message_template_group;
73
+
74
+	protected $_m_mt_settings = [];
75
+
76
+
77
+	/**
78
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
+	 * IF there is no group then it gets automatically set to the Default template pack.
80
+	 *
81
+	 * @since 4.5.0
82
+	 *
83
+	 * @var EE_Messages_Template_Pack
84
+	 */
85
+	protected $_template_pack;
86
+
87
+
88
+	/**
89
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
+	 * group is.  If there is no group then it automatically gets set to default.
91
+	 *
92
+	 * @since 4.5.0
93
+	 *
94
+	 * @var string
95
+	 */
96
+	protected $_variation;
97
+
98
+
99
+	/**
100
+	 * @param bool $routing
101
+	 * @throws EE_Error
102
+	 * @throws ReflectionException
103
+	 */
104
+	public function __construct($routing = true)
105
+	{
106
+		// make sure messages autoloader is running
107
+		EED_Messages::set_autoloaders();
108
+		parent::__construct($routing);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EEM_Message
114
+	 * @throws EE_Error
115
+	 */
116
+	public function getMsgModel()
117
+	{
118
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
119
+			$this->MSG_MODEL = EEM_Message::instance();
120
+		}
121
+		return $this->MSG_MODEL;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return EEM_Message_Template
127
+	 * @throws EE_Error
128
+	 */
129
+	public function getMtpModel()
130
+	{
131
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
+			$this->MTP_MODEL = EEM_Message_Template::instance();
133
+		}
134
+		return $this->MTP_MODEL;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return EEM_Message_Template_Group
140
+	 * @throws EE_Error
141
+	 */
142
+	public function getMtgModel()
143
+	{
144
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
+		}
147
+		return $this->MTG_MODEL;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @throws EE_Error
153
+	 * @throws ReflectionException
154
+	 */
155
+	protected function _init_page_props()
156
+	{
157
+		$this->page_slug        = EE_MSG_PG_SLUG;
158
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
+		$this->_admin_base_path = EE_MSG_ADMIN;
161
+
162
+		$messenger    = $this->request->getRequestParam('messenger', '');
163
+		$message_type = $this->request->getRequestParam('message_type', '');
164
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
+
167
+		$this->_load_message_resource_manager();
168
+	}
169
+
170
+
171
+	/**
172
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
+	 *
174
+	 * @throws EE_Error
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidInterfaceException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws ReflectionException
179
+	 */
180
+	protected function _load_message_resource_manager()
181
+	{
182
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return array
188
+	 * @throws EE_Error
189
+	 * @throws InvalidArgumentException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 * @deprecated 4.9.9.rc.014
193
+	 */
194
+	public function get_messengers_for_list_table()
195
+	{
196
+		EE_Error::doing_it_wrong(
197
+			__METHOD__,
198
+			sprintf(
199
+				esc_html__(
200
+					'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',
201
+					'event_espresso'
202
+				),
203
+				'Messages_Admin_Page::get_messengers_select_input()'
204
+			),
205
+			'4.9.9.rc.014'
206
+		);
207
+
208
+		$m_values          = [];
209
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
+		// setup messengers for selects
211
+		$i = 1;
212
+		foreach ($active_messengers as $active_messenger) {
213
+			if ($active_messenger instanceof EE_Message) {
214
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
215
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
+				$i++;
217
+			}
218
+		}
219
+
220
+		return $m_values;
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return array
226
+	 * @throws EE_Error
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidDataTypeException
229
+	 * @throws InvalidInterfaceException
230
+	 * @deprecated 4.9.9.rc.014
231
+	 */
232
+	public function get_message_types_for_list_table()
233
+	{
234
+		EE_Error::doing_it_wrong(
235
+			__METHOD__,
236
+			sprintf(
237
+				esc_html__(
238
+					'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',
239
+					'event_espresso'
240
+				),
241
+				'Messages_Admin_Page::get_message_types_select_input()'
242
+			),
243
+			'4.9.9.rc.014'
244
+		);
245
+
246
+		$mt_values       = [];
247
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
+		$i               = 1;
249
+		foreach ($active_messages as $active_message) {
250
+			if ($active_message instanceof EE_Message) {
251
+				$mt_values[ $i ]['id']   = $active_message->message_type();
252
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
+				$i++;
254
+			}
255
+		}
256
+
257
+		return $mt_values;
258
+	}
259
+
260
+
261
+	/**
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 * @deprecated 4.9.9.rc.014
268
+	 */
269
+	public function get_contexts_for_message_types_for_list_table()
270
+	{
271
+		EE_Error::doing_it_wrong(
272
+			__METHOD__,
273
+			sprintf(
274
+				esc_html__(
275
+					'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',
276
+					'event_espresso'
277
+				),
278
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
+			),
280
+			'4.9.9.rc.014'
281
+		);
282
+
283
+		$contexts                = [];
284
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
+		foreach ($active_message_contexts as $active_message) {
286
+			if ($active_message instanceof EE_Message) {
287
+				$message_type = $active_message->message_type_object();
288
+				if ($message_type instanceof EE_message_type) {
289
+					$message_type_contexts = $message_type->get_contexts();
290
+					foreach ($message_type_contexts as $context => $context_details) {
291
+						$contexts[ $context ] = $context_details['label'];
292
+					}
293
+				}
294
+			}
295
+		}
296
+
297
+		return $contexts;
298
+	}
299
+
300
+
301
+	/**
302
+	 * Generate select input with provided messenger options array.
303
+	 *
304
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
+	 *                                 labels.
306
+	 * @return string
307
+	 * @throws EE_Error
308
+	 */
309
+	public function get_messengers_select_input($messenger_options)
310
+	{
311
+		// if empty or just one value then just return an empty string
312
+		if (
313
+			empty($messenger_options)
314
+			|| ! is_array($messenger_options)
315
+			|| count($messenger_options) === 1
316
+		) {
317
+			return '';
318
+		}
319
+		// merge in default
320
+		$messenger_options = array_merge(
321
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
+			$messenger_options
323
+		);
324
+		$input             = new EE_Select_Input(
325
+			$messenger_options,
326
+			[
327
+				'html_name'  => 'ee_messenger_filter_by',
328
+				'html_id'    => 'ee_messenger_filter_by',
329
+				'html_class' => 'wide',
330
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
+			]
332
+		);
333
+
334
+		return $input->get_html_for_input();
335
+	}
336
+
337
+
338
+	/**
339
+	 * Generate select input with provided message type options array.
340
+	 *
341
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
+	 *                                    message type labels
343
+	 * @return string
344
+	 * @throws EE_Error
345
+	 */
346
+	public function get_message_types_select_input($message_type_options)
347
+	{
348
+		// if empty or count of options is 1 then just return an empty string
349
+		if (
350
+			empty($message_type_options)
351
+			|| ! is_array($message_type_options)
352
+			|| count($message_type_options) === 1
353
+		) {
354
+			return '';
355
+		}
356
+		// merge in default
357
+		$message_type_options = array_merge(
358
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
+			$message_type_options
360
+		);
361
+		$input                = new EE_Select_Input(
362
+			$message_type_options,
363
+			[
364
+				'html_name'  => 'ee_message_type_filter_by',
365
+				'html_id'    => 'ee_message_type_filter_by',
366
+				'html_class' => 'wide',
367
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
+			]
369
+		);
370
+
371
+		return $input->get_html_for_input();
372
+	}
373
+
374
+
375
+	/**
376
+	 * Generate select input with provide message type contexts array.
377
+	 *
378
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
+	 *                               context label.
380
+	 * @return string
381
+	 * @throws EE_Error
382
+	 */
383
+	public function get_contexts_for_message_types_select_input($context_options)
384
+	{
385
+		// if empty or count of options is one then just return empty string
386
+		if (
387
+			empty($context_options)
388
+			|| ! is_array($context_options)
389
+			|| count($context_options) === 1
390
+		) {
391
+			return '';
392
+		}
393
+		// merge in default
394
+		$context_options = array_merge(
395
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
+			$context_options
397
+		);
398
+		$input           = new EE_Select_Input(
399
+			$context_options,
400
+			[
401
+				'html_name'  => 'ee_context_filter_by',
402
+				'html_id'    => 'ee_context_filter_by',
403
+				'html_class' => 'wide',
404
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
+			]
406
+		);
407
+
408
+		return $input->get_html_for_input();
409
+	}
410
+
411
+
412
+	protected function _ajax_hooks()
413
+	{
414
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
+	}
421
+
422
+
423
+	protected function _define_page_props()
424
+	{
425
+		$this->_admin_page_title = $this->page_label;
426
+		$this->_labels           = [
427
+			'buttons'    => [
428
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
+			],
432
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
+		];
434
+	}
435
+
436
+
437
+	/**
438
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
439
+	 *
440
+	 * @access protected
441
+	 * @return void
442
+	 */
443
+	protected function _set_page_routes()
444
+	{
445
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
+
449
+		$this->_page_routes = [
450
+			'default'                          => [
451
+				'func'       => '_message_queue_list_table',
452
+				'capability' => 'ee_read_global_messages',
453
+			],
454
+			'global_mtps'                      => [
455
+				'func'       => '_ee_default_messages_overview_list_table',
456
+				'capability' => 'ee_read_global_messages',
457
+			],
458
+			'custom_mtps'                      => [
459
+				'func'       => '_custom_mtps_preview',
460
+				'capability' => 'ee_read_messages',
461
+			],
462
+			'add_new_message_template'         => [
463
+				'func'       => 'add_message_template',
464
+				'capability' => 'ee_edit_messages',
465
+				'noheader'   => true,
466
+			],
467
+			'edit_message_template'            => [
468
+				'func'       => '_edit_message_template',
469
+				'capability' => 'ee_edit_message',
470
+				'obj_id'     => $GRP_ID,
471
+			],
472
+			'preview_message'                  => [
473
+				'func'               => '_preview_message',
474
+				'capability'         => 'ee_read_message',
475
+				'obj_id'             => $GRP_ID,
476
+				'noheader'           => true,
477
+				'headers_sent_route' => 'display_preview_message',
478
+			],
479
+			'display_preview_message'          => [
480
+				'func'       => '_display_preview_message',
481
+				'capability' => 'ee_read_message',
482
+				'obj_id'     => $GRP_ID,
483
+			],
484
+			'insert_message_template'          => [
485
+				'func'       => '_insert_or_update_message_template',
486
+				'capability' => 'ee_edit_messages',
487
+				'args'       => ['new' => true],
488
+				'noheader'   => true,
489
+			],
490
+			'update_message_template'          => [
491
+				'func'       => '_insert_or_update_message_template',
492
+				'capability' => 'ee_edit_message',
493
+				'obj_id'     => $GRP_ID,
494
+				'args'       => ['new' => false],
495
+				'noheader'   => true,
496
+			],
497
+			'trash_message_template'           => [
498
+				'func'       => '_trash_or_restore_message_template',
499
+				'capability' => 'ee_delete_message',
500
+				'obj_id'     => $GRP_ID,
501
+				'args'       => ['trash' => true, 'all' => true],
502
+				'noheader'   => true,
503
+			],
504
+			'trash_message_template_context'   => [
505
+				'func'       => '_trash_or_restore_message_template',
506
+				'capability' => 'ee_delete_message',
507
+				'obj_id'     => $GRP_ID,
508
+				'args'       => ['trash' => true],
509
+				'noheader'   => true,
510
+			],
511
+			'restore_message_template'         => [
512
+				'func'       => '_trash_or_restore_message_template',
513
+				'capability' => 'ee_delete_message',
514
+				'obj_id'     => $GRP_ID,
515
+				'args'       => ['trash' => false, 'all' => true],
516
+				'noheader'   => true,
517
+			],
518
+			'restore_message_template_context' => [
519
+				'func'       => '_trash_or_restore_message_template',
520
+				'capability' => 'ee_delete_message',
521
+				'obj_id'     => $GRP_ID,
522
+				'args'       => ['trash' => false],
523
+				'noheader'   => true,
524
+			],
525
+			'delete_message_template'          => [
526
+				'func'       => '_delete_message_template',
527
+				'capability' => 'ee_delete_message',
528
+				'obj_id'     => $GRP_ID,
529
+				'noheader'   => true,
530
+			],
531
+			'reset_to_default'                 => [
532
+				'func'       => '_reset_to_default_template',
533
+				'capability' => 'ee_edit_message',
534
+				'obj_id'     => $GRP_ID,
535
+				'noheader'   => true,
536
+			],
537
+			'settings'                         => [
538
+				'func'       => '_settings',
539
+				'capability' => 'manage_options',
540
+			],
541
+			'update_global_settings'           => [
542
+				'func'       => '_update_global_settings',
543
+				'capability' => 'manage_options',
544
+				'noheader'   => true,
545
+			],
546
+			'generate_now'                     => [
547
+				'func'       => '_generate_now',
548
+				'capability' => 'ee_send_message',
549
+				'noheader'   => true,
550
+			],
551
+			'generate_and_send_now'            => [
552
+				'func'       => '_generate_and_send_now',
553
+				'capability' => 'ee_send_message',
554
+				'noheader'   => true,
555
+			],
556
+			'queue_for_resending'              => [
557
+				'func'       => '_queue_for_resending',
558
+				'capability' => 'ee_send_message',
559
+				'noheader'   => true,
560
+			],
561
+			'send_now'                         => [
562
+				'func'       => '_send_now',
563
+				'capability' => 'ee_send_message',
564
+				'noheader'   => true,
565
+			],
566
+			'delete_ee_message'                => [
567
+				'func'       => '_delete_ee_messages',
568
+				'capability' => 'ee_delete_messages',
569
+				'noheader'   => true,
570
+			],
571
+			'delete_ee_messages'               => [
572
+				'func'       => '_delete_ee_messages',
573
+				'capability' => 'ee_delete_messages',
574
+				'noheader'   => true,
575
+				'obj_id'     => $MSG_ID,
576
+			],
577
+		];
578
+	}
579
+
580
+
581
+	protected function _set_page_config()
582
+	{
583
+		$this->_page_config = [
584
+			'default'                  => [
585
+				'nav'           => [
586
+					'label' => esc_html__('Message Activity', 'event_espresso'),
587
+					'order' => 10,
588
+				],
589
+				'list_table'    => 'EE_Message_List_Table',
590
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
+				'require_nonce' => false,
592
+			],
593
+			'global_mtps'              => [
594
+				'nav'           => [
595
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
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
+					'order' => 30,
631
+				],
632
+				'help_tabs'     => [],
633
+				'require_nonce' => false,
634
+			],
635
+			'add_new_message_template' => [
636
+				'nav'           => [
637
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
+					'order'      => 5,
639
+					'persistent' => false,
640
+				],
641
+				'require_nonce' => false,
642
+			],
643
+			'edit_message_template'    => [
644
+				'labels'        => [
645
+					'buttons'    => [
646
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
+					],
648
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
+				],
650
+				'nav'           => [
651
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
+					'order'      => 5,
653
+					'persistent' => false,
654
+					'url'        => '',
655
+				],
656
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
+				'has_metaboxes' => true,
658
+				'help_tabs'     => [
659
+					'edit_message_template'            => [
660
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
+						'callback' => 'edit_message_template_help_tab',
662
+					],
663
+					'message_templates_help_tab'       => [
664
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
665
+						'filename' => 'messages_templates',
666
+					],
667
+					'message_template_shortcodes'      => [
668
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
+						'callback' => 'message_template_shortcodes_help_tab',
670
+					],
671
+					'message_preview_help_tab'         => [
672
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
673
+						'filename' => 'messages_preview',
674
+					],
675
+					'messages_overview_other_help_tab' => [
676
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
677
+						'filename' => 'messages_overview_other',
678
+					],
679
+				],
680
+				'require_nonce' => false,
681
+			],
682
+			'display_preview_message'  => [
683
+				'nav'           => [
684
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
685
+					'order'      => 5,
686
+					'url'        => '',
687
+					'persistent' => false,
688
+				],
689
+				'help_tabs'     => [
690
+					'preview_message' => [
691
+						'title'    => esc_html__('About Previews', 'event_espresso'),
692
+						'callback' => 'preview_message_help_tab',
693
+					],
694
+				],
695
+				'require_nonce' => false,
696
+			],
697
+			'settings'                 => [
698
+				'nav'           => [
699
+					'label' => esc_html__('Settings', 'event_espresso'),
700
+					'order' => 40,
701
+				],
702
+				'metaboxes'     => ['_messages_settings_metaboxes'],
703
+				'help_tabs'     => [
704
+					'messages_settings_help_tab'               => [
705
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
+						'filename' => 'messages_settings',
707
+					],
708
+					'messages_settings_message_types_help_tab' => [
709
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
+						'filename' => 'messages_settings_message_types',
711
+					],
712
+					'messages_settings_messengers_help_tab'    => [
713
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
+						'filename' => 'messages_settings_messengers',
715
+					],
716
+				],
717
+				'require_nonce' => false,
718
+			],
719
+		];
720
+	}
721
+
722
+
723
+	protected function _add_screen_options()
724
+	{
725
+		// todo
726
+	}
727
+
728
+
729
+	protected function _add_screen_options_global_mtps()
730
+	{
731
+		/**
732
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
734
+		 */
735
+		$page_title              = $this->_admin_page_title;
736
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
+		$this->_per_page_screen_option();
738
+		$this->_admin_page_title = $page_title;
739
+	}
740
+
741
+
742
+	protected function _add_screen_options_default()
743
+	{
744
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
+		$this->_per_page_screen_option();
746
+	}
747
+
748
+
749
+	// none of the below group are currently used for Messages
750
+	protected function _add_feature_pointers()
751
+	{
752
+	}
753
+
754
+
755
+	public function admin_init()
756
+	{
757
+	}
758
+
759
+
760
+	public function admin_notices()
761
+	{
762
+	}
763
+
764
+
765
+	public function admin_footer_scripts()
766
+	{
767
+	}
768
+
769
+
770
+	public function messages_help_tab()
771
+	{
772
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
+	}
774
+
775
+
776
+	public function messengers_help_tab()
777
+	{
778
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
+	}
780
+
781
+
782
+	public function message_types_help_tab()
783
+	{
784
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
+	}
786
+
787
+
788
+	public function messages_overview_help_tab()
789
+	{
790
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
+	}
792
+
793
+
794
+	public function message_templates_help_tab()
795
+	{
796
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
+	}
798
+
799
+
800
+	public function edit_message_template_help_tab()
801
+	{
802
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
+						. esc_attr__('Editor Title', 'event_espresso')
804
+						. '" />';
805
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
807
+						. '" />';
808
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
810
+						. '" />';
811
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
813
+						. '" />';
814
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
+						. esc_attr__('Publish Metabox', 'event_espresso')
816
+						. '" />';
817
+		EEH_Template::display_template(
818
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
+			$args
820
+		);
821
+	}
822
+
823
+
824
+	/**
825
+	 * @throws ReflectionException
826
+	 * @throws EE_Error
827
+	 */
828
+	public function message_template_shortcodes_help_tab()
829
+	{
830
+		$this->_set_shortcodes();
831
+		$args['shortcodes'] = $this->_shortcodes;
832
+		EEH_Template::display_template(
833
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
+			$args
835
+		);
836
+	}
837
+
838
+
839
+	public function preview_message_help_tab()
840
+	{
841
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
+	}
843
+
844
+
845
+	public function settings_help_tab()
846
+	{
847
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
+		$args['img3'] = '<div class="switch">'
852
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
+						. ' type="checkbox" checked="checked">'
854
+						. '<label for="ee-on-off-toggle-on"></label>'
855
+						. '</div>';
856
+		$args['img4'] = '<div class="switch">'
857
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
+						. ' type="checkbox">'
859
+						. '<label for="ee-on-off-toggle-on"></label>'
860
+						. '</div>';
861
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
+	}
863
+
864
+
865
+	public function load_scripts_styles()
866
+	{
867
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
+		wp_enqueue_style('espresso_ee_msg');
869
+
870
+		wp_register_script(
871
+			'ee-messages-settings',
872
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
874
+			EVENT_ESPRESSO_VERSION,
875
+			true
876
+		);
877
+		wp_register_script(
878
+			'ee-msg-list-table-js',
879
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
+			['ee-dialog'],
881
+			EVENT_ESPRESSO_VERSION
882
+		);
883
+	}
884
+
885
+
886
+	public function load_scripts_styles_default()
887
+	{
888
+		wp_enqueue_script('ee-msg-list-table-js');
889
+	}
890
+
891
+
892
+	public function wp_editor_css($mce_css)
893
+	{
894
+		// if we're on the edit_message_template route
895
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
+			$message_type_name = $this->_active_message_type_name;
897
+
898
+			// we're going to REPLACE the existing mce css
899
+			// we need to get the css file location from the active messenger
900
+			$mce_css = $this->_active_messenger->get_variation(
901
+				$this->_template_pack,
902
+				$message_type_name,
903
+				true,
904
+				'wpeditor',
905
+				$this->_variation
906
+			);
907
+		}
908
+
909
+		return $mce_css;
910
+	}
911
+
912
+
913
+	/**
914
+	 * @throws EE_Error
915
+	 * @throws ReflectionException
916
+	 */
917
+	public function load_scripts_styles_edit_message_template()
918
+	{
919
+
920
+		$this->_set_shortcodes();
921
+
922
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
+			esc_html__(
924
+				'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.',
925
+				'event_espresso'
926
+			),
927
+			$this->_message_template_group->messenger_obj()->label['singular'],
928
+			$this->_message_template_group->message_type_obj()->label['singular']
929
+		);
930
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
+			'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?',
932
+			'event_espresso'
933
+		);
934
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
+			'event_espresso'
937
+		);
938
+
939
+		wp_register_script(
940
+			'ee_msgs_edit_js',
941
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
+			['jquery'],
943
+			EVENT_ESPRESSO_VERSION
944
+		);
945
+
946
+		wp_enqueue_script('ee_admin_js');
947
+		wp_enqueue_script('ee_msgs_edit_js');
948
+
949
+		// add in special css for tiny_mce
950
+		add_filter('mce_css', [$this, 'wp_editor_css']);
951
+	}
952
+
953
+
954
+	/**
955
+	 * @throws EE_Error
956
+	 * @throws ReflectionException
957
+	 */
958
+	public function load_scripts_styles_display_preview_message()
959
+	{
960
+		$this->_set_message_template_group();
961
+		if ($this->_active_messenger_name) {
962
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
+				$this->_active_messenger_name
964
+			);
965
+		}
966
+
967
+		wp_enqueue_style(
968
+			'espresso_preview_css',
969
+			$this->_active_messenger->get_variation(
970
+				$this->_template_pack,
971
+				$this->_active_message_type_name,
972
+				true,
973
+				'preview',
974
+				$this->_variation
975
+			)
976
+		);
977
+	}
978
+
979
+
980
+	public function load_scripts_styles_settings()
981
+	{
982
+		wp_register_style(
983
+			'ee-message-settings',
984
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
+			[],
986
+			EVENT_ESPRESSO_VERSION
987
+		);
988
+		wp_enqueue_style('ee-text-links');
989
+		wp_enqueue_style('ee-message-settings');
990
+		wp_enqueue_script('ee-messages-settings');
991
+	}
992
+
993
+
994
+	/**
995
+	 * set views array for List Table
996
+	 */
997
+	public function _set_list_table_views_global_mtps()
998
+	{
999
+		$this->_views = [
1000
+			'in_use' => [
1001
+				'slug'  => 'in_use',
1002
+				'label' => esc_html__('In Use', 'event_espresso'),
1003
+				'count' => 0,
1004
+			],
1005
+		];
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * Set views array for the Custom Template List Table
1011
+	 */
1012
+	public function _set_list_table_views_custom_mtps()
1013
+	{
1014
+		$this->_set_list_table_views_global_mtps();
1015
+		$this->_views['in_use']['bulk_action'] = [
1016
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
+		];
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * set views array for message queue list table
1023
+	 *
1024
+	 * @throws InvalidDataTypeException
1025
+	 * @throws InvalidInterfaceException
1026
+	 * @throws InvalidArgumentException
1027
+	 * @throws EE_Error
1028
+	 * @throws ReflectionException
1029
+	 */
1030
+	public function _set_list_table_views_default()
1031
+	{
1032
+		EE_Registry::instance()->load_helper('Template');
1033
+
1034
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
+			'ee_send_message',
1036
+			'message_list_table_bulk_actions'
1037
+		)
1038
+			? [
1039
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
+			]
1044
+			: [];
1045
+
1046
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
+			'ee_delete_messages',
1048
+			'message_list_table_bulk_actions'
1049
+		)
1050
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
+			: [];
1052
+
1053
+
1054
+		$this->_views = [
1055
+			'all' => [
1056
+				'slug'        => 'all',
1057
+				'label'       => esc_html__('All', 'event_espresso'),
1058
+				'count'       => 0,
1059
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
+			],
1061
+		];
1062
+
1063
+
1064
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
+				continue;
1067
+			}
1068
+			$status_bulk_actions = $common_bulk_actions;
1069
+			// unset bulk actions not applying to status
1070
+			if (! empty($status_bulk_actions)) {
1071
+				switch ($status) {
1072
+					case EEM_Message::status_idle:
1073
+					case EEM_Message::status_resend:
1074
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
+						break;
1076
+
1077
+					case EEM_Message::status_failed:
1078
+					case EEM_Message::status_debug_only:
1079
+					case EEM_Message::status_messenger_executing:
1080
+						$status_bulk_actions = [];
1081
+						break;
1082
+
1083
+					case EEM_Message::status_incomplete:
1084
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
+						break;
1086
+
1087
+					case EEM_Message::status_retry:
1088
+					case EEM_Message::status_sent:
1089
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
+						break;
1091
+				}
1092
+			}
1093
+
1094
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1095
+			if ($status === EEM_Message::status_messenger_executing) {
1096
+				continue;
1097
+			}
1098
+
1099
+			$this->_views[ strtolower($status) ] = [
1100
+				'slug'        => strtolower($status),
1101
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
+				'count'       => 0,
1103
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
+			];
1105
+		}
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * @throws EE_Error
1111
+	 */
1112
+	protected function _ee_default_messages_overview_list_table()
1113
+	{
1114
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
+		$this->display_admin_list_table_page_with_no_sidebar();
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * @throws EE_Error
1121
+	 * @throws ReflectionException
1122
+	 */
1123
+	protected function _message_queue_list_table()
1124
+	{
1125
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
+		$this->_template_args['per_column']        = 6;
1127
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
+		$message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1129
+		$this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1130
+		$this->display_admin_list_table_page_with_no_sidebar();
1131
+	}
1132
+
1133
+
1134
+	/**
1135
+	 * @throws EE_Error
1136
+	 */
1137
+	protected function _message_legend_items()
1138
+	{
1139
+
1140
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1141
+		$action_items       = [];
1142
+
1143
+		foreach ($action_css_classes as $action_item => $action_details) {
1144
+			if ($action_item === 'see_notifications_for') {
1145
+				continue;
1146
+			}
1147
+			$action_items[ $action_item ] = [
1148
+				'class' => $action_details['css_class'],
1149
+				'desc'  => $action_details['label'],
1150
+			];
1151
+		}
1152
+
1153
+		/** @var array $status_items status legend setup */
1154
+		$status_items = [
1155
+			'sent_status'                => [
1156
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1157
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158
+			],
1159
+			'idle_status'                => [
1160
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1161
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162
+			],
1163
+			'failed_status'              => [
1164
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1165
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166
+			],
1167
+			'messenger_executing_status' => [
1168
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1169
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170
+			],
1171
+			'resend_status'              => [
1172
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1173
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174
+			],
1175
+			'incomplete_status'          => [
1176
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1177
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178
+			],
1179
+			'retry_status'               => [
1180
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1181
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182
+			],
1183
+		];
1184
+		if (EEM_Message::debug()) {
1185
+			$status_items['debug_only_status'] = [
1186
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1187
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188
+			];
1189
+		}
1190
+
1191
+		return array_merge($action_items, $status_items);
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * @throws EE_Error
1197
+	 */
1198
+	protected function _custom_mtps_preview()
1199
+	{
1200
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
+												. ' alt="' . esc_attr__(
1203
+													'Preview Custom Message Templates screenshot',
1204
+													'event_espresso'
1205
+												) . '" />';
1206
+		$this->_template_args['preview_text'] = '<strong>'
1207
+												. esc_html__(
1208
+													'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.',
1209
+													'event_espresso'
1210
+												)
1211
+												. '</strong>';
1212
+
1213
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 * get_message_templates
1219
+	 * This gets all the message templates for listing on the overview list.
1220
+	 *
1221
+	 * @access public
1222
+	 * @param int    $per_page the amount of templates groups to show per page
1223
+	 * @param string $type     the current _view we're getting templates for
1224
+	 * @param bool   $count    return count?
1225
+	 * @param bool   $all      disregard any paging info (get all data);
1226
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1227
+	 * @return array
1228
+	 * @throws EE_Error
1229
+	 * @throws InvalidArgumentException
1230
+	 * @throws InvalidDataTypeException
1231
+	 * @throws InvalidInterfaceException
1232
+	 */
1233
+	public function get_message_templates(
1234
+		$per_page = 10,
1235
+		$type = 'in_use',
1236
+		$count = false,
1237
+		$all = false,
1238
+		$global = true
1239
+	) {
1240
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1241
+		$this->request->setRequestParam('orderby', $orderby);
1242
+
1243
+		$order        = $this->request->getRequestParam('order', 'ASC');
1244
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1245
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1246
+
1247
+		$offset = ($current_page - 1) * $per_page;
1248
+		$limit  = $all ? null : [$offset, $per_page];
1249
+
1250
+		// options will match what is in the _views array property
1251
+		return $type === 'in_use'
1252
+			? $this->getMtgModel()->get_all_active_message_templates(
1253
+				$orderby,
1254
+				$order,
1255
+				$limit,
1256
+				$count,
1257
+				$global,
1258
+				true
1259
+			)
1260
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1261
+				$orderby,
1262
+				$order,
1263
+				$limit,
1264
+				$count,
1265
+				$global
1266
+			);
1267
+	}
1268
+
1269
+
1270
+	/**
1271
+	 * filters etc might need a list of installed message_types
1272
+	 *
1273
+	 * @return array an array of message type objects
1274
+	 */
1275
+	public function get_installed_message_types()
1276
+	{
1277
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1278
+		$installed               = [];
1279
+
1280
+		foreach ($installed_message_types as $message_type) {
1281
+			$installed[ $message_type->name ] = $message_type;
1282
+		}
1283
+
1284
+		return $installed;
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1290
+	 *
1291
+	 * @param string $message_type
1292
+	 * @param string $messenger
1293
+	 * @param string $GRP_ID
1294
+	 *
1295
+	 * @throws EE_error
1296
+	 * @throws ReflectionException
1297
+	 */
1298
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1299
+	{
1300
+		// set values override any request data
1301
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1302
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1303
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1304
+
1305
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1306
+		if (empty($message_type) || empty($messenger)) {
1307
+			throw new EE_Error(
1308
+				esc_html__(
1309
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1310
+					'event_espresso'
1311
+				)
1312
+			);
1313
+		}
1314
+
1315
+		// we need the GRP_ID for the template being used as the base for the new template
1316
+		if (empty($GRP_ID)) {
1317
+			throw new EE_Error(
1318
+				esc_html__(
1319
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1320
+					'event_espresso'
1321
+				)
1322
+			);
1323
+		}
1324
+
1325
+		// let's just make sure the template gets generated!
1326
+
1327
+		// we need to reassign some variables for what the insert is expecting
1328
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1329
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1330
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1331
+
1332
+		$this->_insert_or_update_message_template(true);
1333
+	}
1334
+
1335
+
1336
+	/**
1337
+	 * @param string $message_type     message type slug
1338
+	 * @param string $messenger        messenger slug
1339
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1340
+	 *                                 off of.
1341
+	 * @throws EE_error
1342
+	 * @throws ReflectionException
1343
+	 * @deprecated 4.10.29.p
1344
+	 */
1345
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1346
+	{
1347
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * _edit_message_template
1353
+	 *
1354
+	 * @access protected
1355
+	 * @return void
1356
+	 * @throws InvalidIdentifierException
1357
+	 * @throws DomainException
1358
+	 * @throws EE_Error
1359
+	 * @throws InvalidArgumentException
1360
+	 * @throws ReflectionException
1361
+	 * @throws InvalidDataTypeException
1362
+	 * @throws InvalidInterfaceException
1363
+	 */
1364
+	protected function _edit_message_template()
1365
+	{
1366
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1367
+		$template_fields = '';
1368
+		$sidebar_fields  = '';
1369
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1370
+		// valid html in the templates.
1371
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1372
+
1373
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1374
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1375
+
1376
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1377
+		$message_template_group = $this->_message_template_group;
1378
+		$c_label                = $message_template_group->context_label();
1379
+		$c_config               = $message_template_group->contexts_config();
1380
+
1381
+		reset($c_config);
1382
+		$context = $this->request->getRequestParam('context', key($c_config));
1383
+		$context = strtolower($context);
1384
+
1385
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1386
+
1387
+		$edit_message_template_form_url = add_query_arg(
1388
+			['action' => $action, 'noheader' => true],
1389
+			EE_MSG_ADMIN_URL
1390
+		);
1391
+
1392
+		// set active messenger for this view
1393
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1394
+			$message_template_group->messenger()
1395
+		);
1396
+		$this->_active_message_type_name = $message_template_group->message_type();
1397
+
1398
+
1399
+		// Do we have any validation errors?
1400
+		$validators = $this->_get_transient();
1401
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1402
+
1403
+
1404
+		// we need to assemble the title from Various details
1405
+		$context_label = sprintf(
1406
+			esc_html__('(%s %s)', 'event_espresso'),
1407
+			$c_config[ $context ]['label'],
1408
+			ucwords($c_label['label'])
1409
+		);
1410
+
1411
+		$title = sprintf(
1412
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1413
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1414
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1415
+			$context_label
1416
+		);
1417
+
1418
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1419
+		$this->_template_args['message_template'] = $message_template_group;
1420
+		$this->_template_args['is_extra_fields']  = false;
1421
+
1422
+
1423
+		// let's get EEH_MSG_Template so we can get template form fields
1424
+		$template_field_structure = EEH_MSG_Template::get_fields(
1425
+			$message_template_group->messenger(),
1426
+			$message_template_group->message_type()
1427
+		);
1428
+
1429
+		if (! $template_field_structure) {
1430
+			$template_field_structure = false;
1431
+			$template_fields          = esc_html__(
1432
+				'There was an error in assembling the fields for this display (you should see an error message)',
1433
+				'event_espresso'
1434
+			);
1435
+		}
1436
+
1437
+
1438
+		$message_templates = $message_template_group->context_templates();
1439
+
1440
+
1441
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442
+		// will get handled in the "extra" array.
1443
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
+				unset($template_field_structure[ $context ][ $reference_field ]);
1446
+			}
1447
+		}
1448
+
1449
+		// let's loop through the template_field_structure and actually assemble the input fields!
1450
+		if (! empty($template_field_structure)) {
1451
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1452
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453
+				// the extra array and reset them.
1454
+				if ($template_field === 'extra') {
1455
+					$this->_template_args['is_extra_fields'] = true;
1456
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
+						$message_template = $message_templates[ $context ][ $reference_field ];
1458
+						$content          = $message_template instanceof EE_Message_Template
1459
+							? $message_template->get('MTP_content')
1460
+							: '';
1461
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1462
+							// let's verify if we need this extra field via the shortcodes parameter.
1463
+							$continue = false;
1464
+							if (isset($extra_array['shortcodes_required'])) {
1465
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
+										$continue = true;
1468
+									}
1469
+								}
1470
+								if ($continue) {
1471
+									continue;
1472
+								}
1473
+							}
1474
+
1475
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1476
+
1477
+							$template_form_fields[ $field_id ]         = $extra_array;
1478
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1479
+																		 . $reference_field
1480
+																		 . '][content]['
1481
+																		 . $extra_field . ']';
1482
+							$css_class                                 = isset($extra_array['css_class'])
1483
+								? $extra_array['css_class']
1484
+								: '';
1485
+
1486
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
+																			  && in_array($extra_field, $v_fields, true)
1488
+																			  && (
1489
+																				  is_array($validators[ $extra_field ])
1490
+																				  && isset($validators[ $extra_field ]['msg'])
1491
+																			  )
1492
+								? 'validate-error ' . $css_class
1493
+								: $css_class;
1494
+
1495
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
+																		  && isset($content[ $extra_field ])
1497
+								? $content[ $extra_field ]
1498
+								: '';
1499
+
1500
+							// do we have a validation error?  if we do then let's use that value instead
1501
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
+								? $validators[ $extra_field ]['value']
1503
+								: $template_form_fields[ $field_id ]['value'];
1504
+
1505
+
1506
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
+
1508
+							// shortcode selector
1509
+							$field_name_to_use                                   = $extra_field === 'main'
1510
+								? 'content'
1511
+								: $extra_field;
1512
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
+								$field_name_to_use,
1514
+								$field_id
1515
+							);
1516
+						}
1517
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
+						$template_field_template_name_id = $reference_field . '-name';
1519
+
1520
+						$template_form_fields[ $template_field_MTP_id ] = [
1521
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1522
+							'label'      => null,
1523
+							'input'      => 'hidden',
1524
+							'type'       => 'int',
1525
+							'required'   => false,
1526
+							'validation' => false,
1527
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1528
+							'css_class'  => '',
1529
+							'format'     => '%d',
1530
+							'db-col'     => 'MTP_ID',
1531
+						];
1532
+
1533
+						$template_form_fields[ $template_field_template_name_id ] = [
1534
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1535
+							'label'      => null,
1536
+							'input'      => 'hidden',
1537
+							'type'       => 'string',
1538
+							'required'   => false,
1539
+							'validation' => true,
1540
+							'value'      => $reference_field,
1541
+							'css_class'  => '',
1542
+							'format'     => '%s',
1543
+							'db-col'     => 'MTP_template_field',
1544
+						];
1545
+					}
1546
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547
+				} else {
1548
+					$field_id                                   = $template_field . '-content';
1549
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1550
+					$template_form_fields[ $field_id ]['name']  =
1551
+						'MTP_template_fields[' . $template_field . '][content]';
1552
+					$message_template                           =
1553
+						isset($message_templates[ $context ][ $template_field ])
1554
+							? $message_templates[ $context ][ $template_field ]
1555
+							: null;
1556
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
+																  && is_array($message_templates[ $context ])
1558
+																  && $message_template instanceof EE_Message_Template
1559
+						? $message_template->get('MTP_content')
1560
+						: '';
1561
+
1562
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1563
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
+						? $validators[ $template_field ]['value']
1565
+						: $template_form_fields[ $field_id ]['value'];
1566
+
1567
+
1568
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
+					$css_class                                      = isset($field_setup_array['css_class'])
1570
+						? $field_setup_array['css_class']
1571
+						: '';
1572
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
+																	  && in_array($template_field, $v_fields, true)
1574
+																	  && isset($validators[ $template_field ]['msg'])
1575
+						? 'validate-error ' . $css_class
1576
+						: $css_class;
1577
+
1578
+					// shortcode selector
1579
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
+						$template_field,
1581
+						$field_id
1582
+					);
1583
+				}
1584
+
1585
+				// k took care of content field(s) now let's take care of others.
1586
+
1587
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
+				$template_field_field_template_name_id = $template_field . '-name';
1589
+
1590
+				// foreach template field there are actually two form fields created
1591
+				$template_form_fields[ $template_field_MTP_id ] = [
1592
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1593
+					'label'      => null,
1594
+					'input'      => 'hidden',
1595
+					'type'       => 'int',
1596
+					'required'   => false,
1597
+					'validation' => true,
1598
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1599
+					'css_class'  => '',
1600
+					'format'     => '%d',
1601
+					'db-col'     => 'MTP_ID',
1602
+				];
1603
+
1604
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1605
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1606
+					'label'      => null,
1607
+					'input'      => 'hidden',
1608
+					'type'       => 'string',
1609
+					'required'   => false,
1610
+					'validation' => true,
1611
+					'value'      => $template_field,
1612
+					'css_class'  => '',
1613
+					'format'     => '%s',
1614
+					'db-col'     => 'MTP_template_field',
1615
+				];
1616
+			}
1617
+
1618
+			// add other fields
1619
+			$template_form_fields['ee-msg-current-context'] = [
1620
+				'name'       => 'MTP_context',
1621
+				'label'      => null,
1622
+				'input'      => 'hidden',
1623
+				'type'       => 'string',
1624
+				'required'   => false,
1625
+				'validation' => true,
1626
+				'value'      => $context,
1627
+				'css_class'  => '',
1628
+				'format'     => '%s',
1629
+				'db-col'     => 'MTP_context',
1630
+			];
1631
+
1632
+			$template_form_fields['ee-msg-grp-id'] = [
1633
+				'name'       => 'GRP_ID',
1634
+				'label'      => null,
1635
+				'input'      => 'hidden',
1636
+				'type'       => 'int',
1637
+				'required'   => false,
1638
+				'validation' => true,
1639
+				'value'      => $GRP_ID,
1640
+				'css_class'  => '',
1641
+				'format'     => '%d',
1642
+				'db-col'     => 'GRP_ID',
1643
+			];
1644
+
1645
+			$template_form_fields['ee-msg-messenger'] = [
1646
+				'name'       => 'MTP_messenger',
1647
+				'label'      => null,
1648
+				'input'      => 'hidden',
1649
+				'type'       => 'string',
1650
+				'required'   => false,
1651
+				'validation' => true,
1652
+				'value'      => $message_template_group->messenger(),
1653
+				'css_class'  => '',
1654
+				'format'     => '%s',
1655
+				'db-col'     => 'MTP_messenger',
1656
+			];
1657
+
1658
+			$template_form_fields['ee-msg-message-type'] = [
1659
+				'name'       => 'MTP_message_type',
1660
+				'label'      => null,
1661
+				'input'      => 'hidden',
1662
+				'type'       => 'string',
1663
+				'required'   => false,
1664
+				'validation' => true,
1665
+				'value'      => $message_template_group->message_type(),
1666
+				'css_class'  => '',
1667
+				'format'     => '%s',
1668
+				'db-col'     => 'MTP_message_type',
1669
+			];
1670
+
1671
+			$sidebar_form_fields['ee-msg-is-global'] = [
1672
+				'name'       => 'MTP_is_global',
1673
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1674
+				'input'      => 'hidden',
1675
+				'type'       => 'int',
1676
+				'required'   => false,
1677
+				'validation' => true,
1678
+				'value'      => $message_template_group->get('MTP_is_global'),
1679
+				'css_class'  => '',
1680
+				'format'     => '%d',
1681
+				'db-col'     => 'MTP_is_global',
1682
+			];
1683
+
1684
+			$sidebar_form_fields['ee-msg-is-override'] = [
1685
+				'name'       => 'MTP_is_override',
1686
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1687
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1688
+				'type'       => 'int',
1689
+				'required'   => false,
1690
+				'validation' => true,
1691
+				'value'      => $message_template_group->get('MTP_is_override'),
1692
+				'css_class'  => '',
1693
+				'format'     => '%d',
1694
+				'db-col'     => 'MTP_is_override',
1695
+			];
1696
+
1697
+			$sidebar_form_fields['ee-msg-is-active'] = [
1698
+				'name'       => 'MTP_is_active',
1699
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1700
+				'input'      => 'hidden',
1701
+				'type'       => 'int',
1702
+				'required'   => false,
1703
+				'validation' => true,
1704
+				'value'      => $message_template_group->is_active(),
1705
+				'css_class'  => '',
1706
+				'format'     => '%d',
1707
+				'db-col'     => 'MTP_is_active',
1708
+			];
1709
+
1710
+			$sidebar_form_fields['ee-msg-deleted'] = [
1711
+				'name'       => 'MTP_deleted',
1712
+				'label'      => null,
1713
+				'input'      => 'hidden',
1714
+				'type'       => 'int',
1715
+				'required'   => false,
1716
+				'validation' => true,
1717
+				'value'      => $message_template_group->get('MTP_deleted'),
1718
+				'css_class'  => '',
1719
+				'format'     => '%d',
1720
+				'db-col'     => 'MTP_deleted',
1721
+			];
1722
+			$sidebar_form_fields['ee-msg-author']  = [
1723
+				'name'       => 'MTP_user_id',
1724
+				'label'      => esc_html__('Author', 'event_espresso'),
1725
+				'input'      => 'hidden',
1726
+				'type'       => 'int',
1727
+				'required'   => false,
1728
+				'validation' => false,
1729
+				'value'      => $message_template_group->user(),
1730
+				'format'     => '%d',
1731
+				'db-col'     => 'MTP_user_id',
1732
+			];
1733
+
1734
+			$sidebar_form_fields['ee-msg-route'] = [
1735
+				'name'  => 'action',
1736
+				'input' => 'hidden',
1737
+				'type'  => 'string',
1738
+				'value' => $action,
1739
+			];
1740
+
1741
+			$sidebar_form_fields['ee-msg-id']        = [
1742
+				'name'  => 'id',
1743
+				'input' => 'hidden',
1744
+				'type'  => 'int',
1745
+				'value' => $GRP_ID,
1746
+			];
1747
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
+				'name'  => $action . '_nonce',
1749
+				'input' => 'hidden',
1750
+				'type'  => 'string',
1751
+				'value' => wp_create_nonce($action . '_nonce'),
1752
+			];
1753
+
1754
+			$template_switch = $this->request->getRequestParam('template_switch');
1755
+			if ($template_switch) {
1756
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1757
+					'name'  => 'template_switch',
1758
+					'input' => 'hidden',
1759
+					'type'  => 'int',
1760
+					'value' => 1,
1761
+				];
1762
+			}
1763
+
1764
+
1765
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1766
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1767
+		} //end if ( !empty($template_field_structure) )
1768
+
1769
+		// set extra content for publish box
1770
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1771
+		$this->_set_publish_post_box_vars(
1772
+			'id',
1773
+			$GRP_ID,
1774
+			false,
1775
+			add_query_arg(
1776
+				['action' => 'global_mtps'],
1777
+				$this->_admin_base_url
1778
+			)
1779
+		);
1780
+
1781
+		// add preview button
1782
+		$preview_url    = parent::add_query_args_and_nonce(
1783
+			[
1784
+				'message_type' => $message_template_group->message_type(),
1785
+				'messenger'    => $message_template_group->messenger(),
1786
+				'context'      => $context,
1787
+				'GRP_ID'       => $GRP_ID,
1788
+				'evt_id'       => $EVT_ID ?: false,
1789
+				'action'       => 'preview_message',
1790
+			],
1791
+			$this->_admin_base_url
1792
+		);
1793
+		$preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1794
+						  . esc_html__('Preview', 'event_espresso')
1795
+						  . '</a>';
1796
+
1797
+
1798
+		// setup context switcher
1799
+		$this->_set_context_switcher(
1800
+			$message_template_group,
1801
+			[
1802
+				'page'    => 'espresso_messages',
1803
+				'action'  => 'edit_message_template',
1804
+				'id'      => $GRP_ID,
1805
+				'evt_id'  => $EVT_ID,
1806
+				'context' => $context,
1807
+				'extra'   => $preview_button,
1808
+			]
1809
+		);
1810
+
1811
+
1812
+		// main box
1813
+		$this->_template_args['template_fields']                         = $template_fields;
1814
+		$this->_template_args['sidebar_box_id']                          = 'details';
1815
+		$this->_template_args['action']                                  = $action;
1816
+		$this->_template_args['context']                                 = $context;
1817
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1818
+		$this->_template_args['learn_more_about_message_templates_link'] =
1819
+			$this->_learn_more_about_message_templates_link();
1820
+
1821
+
1822
+		$this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1823
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1824
+			$message_template_group,
1825
+			$context,
1826
+			$context_label
1827
+		);
1828
+		$this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1829
+		$this->_template_args['before_admin_page_content'] .= '</div>';
1830
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1831
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1832
+
1833
+		$this->_template_path = $this->_template_args['GRP_ID']
1834
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1835
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1836
+
1837
+		// send along EE_Message_Template_Group object for further template use.
1838
+		$this->_template_args['MTP'] = $message_template_group;
1839
+
1840
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1841
+			$this->_template_path,
1842
+			$this->_template_args,
1843
+			true
1844
+		);
1845
+
1846
+
1847
+		// finally, let's set the admin_page title
1848
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1849
+
1850
+
1851
+		// we need to take care of setting the shortcodes property for use elsewhere.
1852
+		$this->_set_shortcodes();
1853
+
1854
+
1855
+		// final template wrapper
1856
+		$this->display_admin_page_with_sidebar();
1857
+	}
1858
+
1859
+
1860
+	public function filter_tinymce_init($mceInit, $editor_id)
1861
+	{
1862
+		return $mceInit;
1863
+	}
1864
+
1865
+
1866
+	public function add_context_switcher()
1867
+	{
1868
+		return $this->_context_switcher;
1869
+	}
1870
+
1871
+
1872
+	/**
1873
+	 * Adds the activation/deactivation toggle for the message template context.
1874
+	 *
1875
+	 * @param EE_Message_Template_Group $message_template_group
1876
+	 * @param string                    $context
1877
+	 * @param string                    $context_label
1878
+	 * @return string
1879
+	 * @throws DomainException
1880
+	 * @throws EE_Error
1881
+	 * @throws InvalidIdentifierException
1882
+	 * @throws ReflectionException
1883
+	 */
1884
+	protected function add_active_context_element(
1885
+		EE_Message_Template_Group $message_template_group,
1886
+		$context,
1887
+		$context_label
1888
+	) {
1889
+		$template_args = [
1890
+			'context'                   => $context,
1891
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1892
+			'is_active'                 => $message_template_group->is_context_active($context),
1893
+			'on_off_action'             => $message_template_group->is_context_active($context)
1894
+				? 'context-off'
1895
+				: 'context-on',
1896
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1897
+			'message_template_group_id' => $message_template_group->ID(),
1898
+		];
1899
+		return EEH_Template::display_template(
1900
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1901
+			$template_args,
1902
+			true
1903
+		);
1904
+	}
1905
+
1906
+
1907
+	/**
1908
+	 * Ajax callback for `toggle_context_template` ajax action.
1909
+	 * Handles toggling the message context on or off.
1910
+	 *
1911
+	 * @throws EE_Error
1912
+	 * @throws InvalidArgumentException
1913
+	 * @throws InvalidDataTypeException
1914
+	 * @throws InvalidIdentifierException
1915
+	 * @throws InvalidInterfaceException
1916
+	 */
1917
+	public function toggle_context_template()
1918
+	{
1919
+		$success = true;
1920
+		// check for required data
1921
+		if (
1922
+			! (
1923
+				$this->request->requestParamIsSet('message_template_group_id')
1924
+				&& $this->request->requestParamIsSet('context')
1925
+				&& $this->request->requestParamIsSet('status')
1926
+			)
1927
+		) {
1928
+			EE_Error::add_error(
1929
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1930
+				__FILE__,
1931
+				__FUNCTION__,
1932
+				__LINE__
1933
+			);
1934
+			$success = false;
1935
+		}
1936
+
1937
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1938
+		$context = $this->request->getRequestParam('context', '');
1939
+		$status  = $this->request->getRequestParam('status', '');
1940
+
1941
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1942
+
1943
+		if ($status !== 'off' && $status !== 'on') {
1944
+			EE_Error::add_error(
1945
+				sprintf(
1946
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1947
+					$status
1948
+				),
1949
+				__FILE__,
1950
+				__FUNCTION__,
1951
+				__LINE__
1952
+			);
1953
+			$success = false;
1954
+		}
1955
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1956
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1957
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1958
+			EE_Error::add_error(
1959
+				sprintf(
1960
+					esc_html__(
1961
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1962
+						'event_espresso'
1963
+					),
1964
+					$message_template_group_id,
1965
+					'EE_Message_Template_Group'
1966
+				),
1967
+				__FILE__,
1968
+				__FUNCTION__,
1969
+				__LINE__
1970
+			);
1971
+			$success = false;
1972
+		}
1973
+		if ($success) {
1974
+			$success = $status === 'off'
1975
+				? $message_template_group->deactivate_context($context)
1976
+				: $message_template_group->activate_context($context);
1977
+		}
1978
+		$this->_template_args['success'] = $success;
1979
+		$this->_return_json();
1980
+	}
1981
+
1982
+
1983
+	public function _add_form_element_before()
1984
+	{
1985
+		return '<form method="post" action="'
1986
+			   . $this->_template_args['edit_message_template_form_url']
1987
+			   . '" id="ee-msg-edit-frm">';
1988
+	}
1989
+
1990
+
1991
+	public function _add_form_element_after()
1992
+	{
1993
+		return '</form>';
1994
+	}
1995
+
1996
+
1997
+	/**
1998
+	 * This executes switching the template pack for a message template.
1999
+	 *
2000
+	 * @throws EE_Error
2001
+	 * @throws InvalidDataTypeException
2002
+	 * @throws InvalidInterfaceException
2003
+	 * @throws InvalidArgumentException
2004
+	 * @throws ReflectionException
2005
+	 * @since 4.5.0
2006
+	 */
2007
+	public function switch_template_pack()
2008
+	{
2009
+
2010
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2011
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2012
+
2013
+		// verify we have needed values.
2014
+		if (empty($GRP_ID) || empty($template_pack)) {
2015
+			$this->_template_args['error'] = true;
2016
+			EE_Error::add_error(
2017
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2018
+				__FILE__,
2019
+				__FUNCTION__,
2020
+				__LINE__
2021
+			);
2022
+		} else {
2023
+			// get template, set the new template_pack and then reset to default
2024
+			/** @var EE_Message_Template_Group $message_template_group */
2025
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2026
+
2027
+			$message_template_group->set_template_pack_name($template_pack);
2028
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2029
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2030
+
2031
+			$query_args = $this->_reset_to_default_template();
2032
+
2033
+			if (empty($query_args['id'])) {
2034
+				EE_Error::add_error(
2035
+					esc_html__(
2036
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2037
+						'event_espresso'
2038
+					),
2039
+					__FILE__,
2040
+					__FUNCTION__,
2041
+					__LINE__
2042
+				);
2043
+				$this->_template_args['error'] = true;
2044
+			} else {
2045
+				$template_label       = $message_template_group->get_template_pack()->label;
2046
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2047
+				EE_Error::add_success(
2048
+					sprintf(
2049
+						esc_html__(
2050
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2051
+							'event_espresso'
2052
+						),
2053
+						$template_label,
2054
+						$template_pack_labels->template_pack
2055
+					)
2056
+				);
2057
+				// generate the redirect url for js.
2058
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2059
+
2060
+				$this->_template_args['data']['redirect_url'] = $url;
2061
+				$this->_template_args['success']              = true;
2062
+			}
2063
+
2064
+			$this->_return_json();
2065
+		}
2066
+	}
2067
+
2068
+
2069
+	/**
2070
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2071
+	 * they want.
2072
+	 *
2073
+	 * @access protected
2074
+	 * @return array|void
2075
+	 * @throws EE_Error
2076
+	 * @throws InvalidArgumentException
2077
+	 * @throws InvalidDataTypeException
2078
+	 * @throws InvalidInterfaceException
2079
+	 * @throws ReflectionException
2080
+	 */
2081
+	protected function _reset_to_default_template()
2082
+	{
2083
+		$templates    = [];
2084
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2085
+		$messenger    = $this->request->getRequestParam('msgr');
2086
+		$message_type = $this->request->getRequestParam('mt');
2087
+		// we need to make sure we've got the info we need.
2088
+		if (! ($GRP_ID && $messenger && $message_type)) {
2089
+			EE_Error::add_error(
2090
+				esc_html__(
2091
+					'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.',
2092
+					'event_espresso'
2093
+				),
2094
+				__FILE__,
2095
+				__FUNCTION__,
2096
+				__LINE__
2097
+			);
2098
+		}
2099
+
2100
+		// all templates will be reset to whatever the defaults are
2101
+		// for the global template matching the messenger and message type.
2102
+		$success = ! empty($GRP_ID);
2103
+
2104
+		if ($success) {
2105
+			// let's first determine if the incoming template is a global template,
2106
+			// if it isn't then we need to get the global template matching messenger and message type.
2107
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2108
+
2109
+
2110
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2111
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2112
+
2113
+			if ($success) {
2114
+				// if successfully deleted, lets generate the new ones.
2115
+				// Note. We set GLOBAL to true, because resets on ANY template
2116
+				// will use the related global template defaults for regeneration.
2117
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2118
+				// HOWEVER, we DO keep the template pack and template variation set
2119
+				// for the current custom template when resetting.
2120
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2121
+			}
2122
+		}
2123
+
2124
+		// any error messages?
2125
+		if (! $success) {
2126
+			EE_Error::add_error(
2127
+				esc_html__(
2128
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2129
+					'event_espresso'
2130
+				),
2131
+				__FILE__,
2132
+				__FUNCTION__,
2133
+				__LINE__
2134
+			);
2135
+		}
2136
+
2137
+		// all good, let's add a success message!
2138
+		if ($success && ! empty($templates)) {
2139
+			// the info for the template we generated is the first element in the returned array
2140
+			EE_Error::overwrite_success();
2141
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2142
+		}
2143
+
2144
+
2145
+		$query_args = [
2146
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2147
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2148
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2149
+		];
2150
+
2151
+		// if called via ajax then we return query args otherwise redirect
2152
+		if ($this->request->isAjax()) {
2153
+			return $query_args;
2154
+		}
2155
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2156
+	}
2157
+
2158
+
2159
+	/**
2160
+	 * Retrieve and set the message preview for display.
2161
+	 *
2162
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2163
+	 * @return string
2164
+	 * @throws ReflectionException
2165
+	 * @throws EE_Error
2166
+	 * @throws InvalidArgumentException
2167
+	 * @throws InvalidDataTypeException
2168
+	 * @throws InvalidInterfaceException
2169
+	 */
2170
+	public function _preview_message($send = false)
2171
+	{
2172
+		// first make sure we've got the necessary parameters
2173
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2174
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2175
+			EE_Error::add_error(
2176
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2177
+				__FILE__,
2178
+				__FUNCTION__,
2179
+				__LINE__
2180
+			);
2181
+		}
2182
+
2183
+		$context = $this->request->getRequestParam('context');
2184
+		// get the preview!
2185
+		$preview = EED_Messages::preview_message(
2186
+			$this->_active_message_type_name,
2187
+			$context,
2188
+			$this->_active_messenger_name,
2189
+			$send
2190
+		);
2191
+
2192
+		if ($send) {
2193
+			return $preview;
2194
+		}
2195
+
2196
+		// if we have an evt_id set on the request, use it.
2197
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2198
+
2199
+		// let's add a button to go back to the edit view
2200
+		$query_args             = [
2201
+			'id'      => $GRP_ID,
2202
+			'evt_id'  => $EVT_ID,
2203
+			'context' => $context,
2204
+			'action'  => 'edit_message_template',
2205
+		];
2206
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2207
+		$preview_button         = '<a href="'
2208
+								  . $go_back_url
2209
+								  . '" class="button--secondary messages-preview-go-back-button">'
2210
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2211
+								  . '</a>';
2212
+		$message_types          = $this->get_installed_message_types();
2213
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2214
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2215
+			? ucwords($active_messenger->label['singular'])
2216
+			: esc_html__('Unknown Messenger', 'event_espresso');
2217
+		// let's provide a helpful title for context
2218
+		$preview_title = sprintf(
2219
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2220
+			$active_messenger_label,
2221
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2222
+		);
2223
+		if (empty($preview)) {
2224
+			$this->noEventsErrorMessage();
2225
+		}
2226
+		// setup display of preview.
2227
+		$this->_admin_page_title                    = $preview_title;
2228
+		$this->_template_args['admin_page_title']   = $preview_title;
2229
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2230
+		$this->_template_args['data']['force_json'] = true;
2231
+
2232
+		return '';
2233
+	}
2234
+
2235
+
2236
+	/**
2237
+	 * Used to set an error if there are no events available for generating a preview/test send.
2238
+	 *
2239
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2240
+	 */
2241
+	protected function noEventsErrorMessage($test_send = false)
2242
+	{
2243
+		$events_url = parent::add_query_args_and_nonce(
2244
+			[
2245
+				'action' => 'default',
2246
+				'page'   => 'espresso_events',
2247
+			],
2248
+			admin_url('admin.php')
2249
+		);
2250
+		$message    = $test_send
2251
+			? esc_html__(
2252
+				'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!',
2253
+				'event_espresso'
2254
+			)
2255
+			: esc_html__(
2256
+				'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!',
2257
+				'event_espresso'
2258
+			);
2259
+
2260
+		EE_Error::add_attention(
2261
+			sprintf(
2262
+				$message,
2263
+				"<a href='{$events_url}'>",
2264
+				'</a>'
2265
+			)
2266
+		);
2267
+	}
2268
+
2269
+
2270
+	/**
2271
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2272
+	 * gets called automatically.
2273
+	 *
2274
+	 * @return void
2275
+	 * @throws EE_Error
2276
+	 * @since 4.5.0
2277
+	 *
2278
+	 */
2279
+	protected function _display_preview_message()
2280
+	{
2281
+		$this->display_admin_page_with_no_sidebar();
2282
+	}
2283
+
2284
+
2285
+	/**
2286
+	 * registers metaboxes that should show up on the "edit_message_template" page
2287
+	 *
2288
+	 * @access protected
2289
+	 * @return void
2290
+	 */
2291
+	protected function _register_edit_meta_boxes()
2292
+	{
2293
+		$this->addMetaBox(
2294
+			'mtp_valid_shortcodes',
2295
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2296
+			[$this, 'shortcode_meta_box'],
2297
+			$this->_current_screen->id,
2298
+			'side'
2299
+		);
2300
+		$this->addMetaBox(
2301
+			'mtp_extra_actions',
2302
+			esc_html__('Extra Actions', 'event_espresso'),
2303
+			[$this, 'extra_actions_meta_box'],
2304
+			$this->_current_screen->id,
2305
+			'side',
2306
+			'high'
2307
+		);
2308
+		$this->addMetaBox(
2309
+			'mtp_templates',
2310
+			esc_html__('Template Styles', 'event_espresso'),
2311
+			[$this, 'template_pack_meta_box'],
2312
+			$this->_current_screen->id,
2313
+			'side',
2314
+			'high'
2315
+		);
2316
+	}
2317
+
2318
+
2319
+	/**
2320
+	 * metabox content for all template pack and variation selection.
2321
+	 *
2322
+	 * @return void
2323
+	 * @throws DomainException
2324
+	 * @throws EE_Error
2325
+	 * @throws InvalidArgumentException
2326
+	 * @throws ReflectionException
2327
+	 * @throws InvalidDataTypeException
2328
+	 * @throws InvalidInterfaceException
2329
+	 * @since 4.5.0
2330
+	 */
2331
+	public function template_pack_meta_box()
2332
+	{
2333
+		$this->_set_message_template_group();
2334
+
2335
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2336
+
2337
+		$tp_select_values = [];
2338
+
2339
+		foreach ($tp_collection as $tp) {
2340
+			// only include template packs that support this messenger and message type!
2341
+			$supports = $tp->get_supports();
2342
+			if (
2343
+				! isset($supports[ $this->_message_template_group->messenger() ])
2344
+				|| ! in_array(
2345
+					$this->_message_template_group->message_type(),
2346
+					$supports[ $this->_message_template_group->messenger() ],
2347
+					true
2348
+				)
2349
+			) {
2350
+				// not supported
2351
+				continue;
2352
+			}
2353
+
2354
+			$tp_select_values[] = [
2355
+				'text' => $tp->label,
2356
+				'id'   => $tp->dbref,
2357
+			];
2358
+		}
2359
+
2360
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2361
+		// the default template pack.  This still allows for the odd template pack to override.
2362
+		if (empty($tp_select_values)) {
2363
+			$tp_select_values[] = [
2364
+				'text' => esc_html__('Default', 'event_espresso'),
2365
+				'id'   => 'default',
2366
+			];
2367
+		}
2368
+
2369
+		// setup variation select values for the currently selected template.
2370
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2371
+			$this->_message_template_group->messenger(),
2372
+			$this->_message_template_group->message_type()
2373
+		);
2374
+		$variations_select_values = [];
2375
+		foreach ($variations as $variation => $label) {
2376
+			$variations_select_values[] = [
2377
+				'text' => $label,
2378
+				'id'   => $variation,
2379
+			];
2380
+		}
2381
+
2382
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2383
+
2384
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2385
+			'MTP_template_pack',
2386
+			$tp_select_values,
2387
+			$this->_message_template_group->get_template_pack_name()
2388
+		);
2389
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2390
+			'MTP_template_variation',
2391
+			$variations_select_values,
2392
+			$this->_message_template_group->get_template_pack_variation()
2393
+		);
2394
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2395
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2396
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2397
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2398
+
2399
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2400
+
2401
+		EEH_Template::display_template($template, $template_args);
2402
+	}
2403
+
2404
+
2405
+	/**
2406
+	 * This meta box holds any extra actions related to Message Templates
2407
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2408
+	 *
2409
+	 * @access  public
2410
+	 * @return void
2411
+	 * @throws EE_Error
2412
+	 */
2413
+	public function extra_actions_meta_box()
2414
+	{
2415
+		$template_form_fields = [];
2416
+
2417
+		$extra_args = [
2418
+			'msgr'   => $this->_message_template_group->messenger(),
2419
+			'mt'     => $this->_message_template_group->message_type(),
2420
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2421
+		];
2422
+		// first we need to see if there are any fields
2423
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2424
+
2425
+		if (! empty($fields)) {
2426
+			// yup there be fields
2427
+			foreach ($fields as $field => $config) {
2428
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2429
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2430
+				$default  = isset($config['default']) ? $config['default'] : '';
2431
+				$default  = isset($config['value']) ? $config['value'] : $default;
2432
+
2433
+				// if type is hidden and the value is empty
2434
+				// something may have gone wrong so let's correct with the defaults
2435
+				$fix                = $config['input'] === 'hidden'
2436
+									  && isset($existing[ $field ])
2437
+									  && empty($existing[ $field ])
2438
+					? $default
2439
+					: '';
2440
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2441
+					? $existing[ $field ]
2442
+					: $fix;
2443
+
2444
+				$template_form_fields[ $field_id ] = [
2445
+					'name'       => 'test_settings_fld[' . $field . ']',
2446
+					'label'      => $config['label'],
2447
+					'input'      => $config['input'],
2448
+					'type'       => $config['type'],
2449
+					'required'   => $config['required'],
2450
+					'validation' => $config['validation'],
2451
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2452
+					'css_class'  => $config['css_class'],
2453
+					'options'    => isset($config['options']) ? $config['options'] : [],
2454
+					'default'    => $default,
2455
+					'format'     => $config['format'],
2456
+				];
2457
+			}
2458
+		}
2459
+
2460
+		$test_settings_html = ! empty($template_form_fields)
2461
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2462
+			: '';
2463
+
2464
+		// print out $test_settings_fields
2465
+		if (! empty($test_settings_html)) {
2466
+			$test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2467
+			$test_settings_html .= 'name="test_button" value="';
2468
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2469
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2470
+		}
2471
+
2472
+		// and button
2473
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2474
+		$test_settings_html .= '<p>';
2475
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2476
+		$test_settings_html .= '</p>';
2477
+		$test_settings_html .= $this->get_action_link_or_button(
2478
+			'reset_to_default',
2479
+			'reset',
2480
+			$extra_args,
2481
+			'button--primary reset-default-button'
2482
+		);
2483
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2484
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2485
+	}
2486
+
2487
+
2488
+	/**
2489
+	 * This returns the shortcode selector skeleton for a given context and field.
2490
+	 *
2491
+	 * @param string $field           The name of the field retrieving shortcodes for.
2492
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2493
+	 * @return string
2494
+	 * @throws DomainException
2495
+	 * @throws EE_Error
2496
+	 * @throws InvalidArgumentException
2497
+	 * @throws ReflectionException
2498
+	 * @throws InvalidDataTypeException
2499
+	 * @throws InvalidInterfaceException
2500
+	 * @since 4.9.rc.000
2501
+	 */
2502
+	protected function _get_shortcode_selector($field, $linked_input_id)
2503
+	{
2504
+		$template_args = [
2505
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2506
+			'fieldname'       => $field,
2507
+			'linked_input_id' => $linked_input_id,
2508
+		];
2509
+
2510
+		return EEH_Template::display_template(
2511
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2512
+			$template_args,
2513
+			true
2514
+		);
2515
+	}
2516
+
2517
+
2518
+	/**
2519
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2520
+	 * page)
2521
+	 *
2522
+	 * @access public
2523
+	 * @return void
2524
+	 * @throws EE_Error
2525
+	 * @throws InvalidArgumentException
2526
+	 * @throws ReflectionException
2527
+	 * @throws InvalidDataTypeException
2528
+	 * @throws InvalidInterfaceException
2529
+	 */
2530
+	public function shortcode_meta_box()
2531
+	{
2532
+		$shortcodes = $this->_get_shortcodes([], false);
2533
+		// just make sure the shortcodes property is set
2534
+		// $messenger = $this->_message_template_group->messenger_obj();
2535
+		// now let's set the content depending on the status of the shortcodes array
2536
+		if (empty($shortcodes)) {
2537
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2538
+			return;
2539
+		}
2540
+		?>
2541 2541
         <div style="float:right; margin-top:10px">
2542 2542
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2543
-            ?>
2543
+			?>
2544 2544
         </div>
2545 2545
         <p class="small-text">
2546 2546
             <?php printf(
2547
-                esc_html__(
2548
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2549
-                    'event_espresso'
2550
-                ),
2551
-                '<span class="dashicons dashicons-shortcode"></span>'
2552
-            ); ?>
2547
+				esc_html__(
2548
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2549
+					'event_espresso'
2550
+				),
2551
+				'<span class="dashicons dashicons-shortcode"></span>'
2552
+			); ?>
2553 2553
         </p>
2554 2554
         <?php
2555
-    }
2556
-
2557
-
2558
-    /**
2559
-     * used to set the $_shortcodes property for when its needed elsewhere.
2560
-     *
2561
-     * @access protected
2562
-     * @return void
2563
-     * @throws EE_Error
2564
-     * @throws InvalidArgumentException
2565
-     * @throws ReflectionException
2566
-     * @throws InvalidDataTypeException
2567
-     * @throws InvalidInterfaceException
2568
-     */
2569
-    protected function _set_shortcodes()
2570
-    {
2571
-
2572
-        // no need to run this if the property is already set
2573
-        if (! empty($this->_shortcodes)) {
2574
-            return;
2575
-        }
2576
-
2577
-        $this->_shortcodes = $this->_get_shortcodes();
2578
-    }
2579
-
2580
-
2581
-    /**
2582
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2583
-     * property)
2584
-     *
2585
-     * @access  protected
2586
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2587
-     *                         for. Defaults to all (for the given context)
2588
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2589
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2590
-     *                         true just an array of shortcode/label pairs.
2591
-     * @throws EE_Error
2592
-     * @throws InvalidArgumentException
2593
-     * @throws ReflectionException
2594
-     * @throws InvalidDataTypeException
2595
-     * @throws InvalidInterfaceException
2596
-     */
2597
-    protected function _get_shortcodes($fields = [], $merged = true)
2598
-    {
2599
-        $this->_set_message_template_group();
2600
-
2601
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2602
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2603
-        if (empty($GRP_ID)) {
2604
-            return [];
2605
-        }
2606
-        $context = $this->request->getRequestParam(
2607
-            'messenger',
2608
-            key($this->_message_template_group->contexts_config())
2609
-        );
2610
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2611
-    }
2612
-
2613
-
2614
-    /**
2615
-     * This sets the _message_template property (containing the called message_template object)
2616
-     *
2617
-     * @access protected
2618
-     * @return void
2619
-     * @throws EE_Error
2620
-     * @throws InvalidArgumentException
2621
-     * @throws ReflectionException
2622
-     * @throws InvalidDataTypeException
2623
-     * @throws InvalidInterfaceException
2624
-     */
2625
-    protected function _set_message_template_group()
2626
-    {
2627
-        // get out if this is already set.
2628
-        if (! empty($this->_message_template_group)) {
2629
-            return;
2630
-        }
2631
-
2632
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2633
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2634
-
2635
-        // let's get the message templates
2636
-        $this->_message_template_group = ! empty($GRP_ID)
2637
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2638
-            : $this->getMtgModel()->create_default_object();
2639
-
2640
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2641
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2642
-    }
2643
-
2644
-
2645
-    /**
2646
-     * sets up a context switcher for edit forms
2647
-     *
2648
-     * @access  protected
2649
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2650
-     * @param array                     $args                  various things the context switcher needs.
2651
-     * @throws EE_Error
2652
-     */
2653
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2654
-    {
2655
-        $context_details = $template_group_object->contexts_config();
2656
-        $context_label   = $template_group_object->context_label();
2657
-        ob_start();
2658
-        ?>
2555
+	}
2556
+
2557
+
2558
+	/**
2559
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2560
+	 *
2561
+	 * @access protected
2562
+	 * @return void
2563
+	 * @throws EE_Error
2564
+	 * @throws InvalidArgumentException
2565
+	 * @throws ReflectionException
2566
+	 * @throws InvalidDataTypeException
2567
+	 * @throws InvalidInterfaceException
2568
+	 */
2569
+	protected function _set_shortcodes()
2570
+	{
2571
+
2572
+		// no need to run this if the property is already set
2573
+		if (! empty($this->_shortcodes)) {
2574
+			return;
2575
+		}
2576
+
2577
+		$this->_shortcodes = $this->_get_shortcodes();
2578
+	}
2579
+
2580
+
2581
+	/**
2582
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2583
+	 * property)
2584
+	 *
2585
+	 * @access  protected
2586
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2587
+	 *                         for. Defaults to all (for the given context)
2588
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2589
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2590
+	 *                         true just an array of shortcode/label pairs.
2591
+	 * @throws EE_Error
2592
+	 * @throws InvalidArgumentException
2593
+	 * @throws ReflectionException
2594
+	 * @throws InvalidDataTypeException
2595
+	 * @throws InvalidInterfaceException
2596
+	 */
2597
+	protected function _get_shortcodes($fields = [], $merged = true)
2598
+	{
2599
+		$this->_set_message_template_group();
2600
+
2601
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2602
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2603
+		if (empty($GRP_ID)) {
2604
+			return [];
2605
+		}
2606
+		$context = $this->request->getRequestParam(
2607
+			'messenger',
2608
+			key($this->_message_template_group->contexts_config())
2609
+		);
2610
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2611
+	}
2612
+
2613
+
2614
+	/**
2615
+	 * This sets the _message_template property (containing the called message_template object)
2616
+	 *
2617
+	 * @access protected
2618
+	 * @return void
2619
+	 * @throws EE_Error
2620
+	 * @throws InvalidArgumentException
2621
+	 * @throws ReflectionException
2622
+	 * @throws InvalidDataTypeException
2623
+	 * @throws InvalidInterfaceException
2624
+	 */
2625
+	protected function _set_message_template_group()
2626
+	{
2627
+		// get out if this is already set.
2628
+		if (! empty($this->_message_template_group)) {
2629
+			return;
2630
+		}
2631
+
2632
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2633
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2634
+
2635
+		// let's get the message templates
2636
+		$this->_message_template_group = ! empty($GRP_ID)
2637
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2638
+			: $this->getMtgModel()->create_default_object();
2639
+
2640
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2641
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2642
+	}
2643
+
2644
+
2645
+	/**
2646
+	 * sets up a context switcher for edit forms
2647
+	 *
2648
+	 * @access  protected
2649
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2650
+	 * @param array                     $args                  various things the context switcher needs.
2651
+	 * @throws EE_Error
2652
+	 */
2653
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2654
+	{
2655
+		$context_details = $template_group_object->contexts_config();
2656
+		$context_label   = $template_group_object->context_label();
2657
+		ob_start();
2658
+		?>
2659 2659
         <div class="ee-msg-switcher-container">
2660 2660
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2661 2661
                 <?php
2662
-                foreach ($args as $name => $value) {
2663
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2664
-                        continue;
2665
-                    }
2666
-                    ?>
2662
+				foreach ($args as $name => $value) {
2663
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2664
+						continue;
2665
+					}
2666
+					?>
2667 2667
                     <input type="hidden"
2668 2668
                            name="<?php echo esc_attr($name); ?>"
2669 2669
                            value="<?php echo esc_attr($value); ?>"
2670 2670
                     />
2671 2671
                     <?php
2672
-                }
2673
-                // setup nonce_url
2674
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2675
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2676
-                ?>
2672
+				}
2673
+				// setup nonce_url
2674
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2675
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2676
+				?>
2677 2677
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2678 2678
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2679 2679
                 </label>
2680 2680
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2681 2681
                     <?php
2682
-                    $context_templates = $template_group_object->context_templates();
2683
-                    if (is_array($context_templates)) :
2684
-                        foreach ($context_templates as $context => $template_fields) :
2685
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2686
-                            ?>
2682
+					$context_templates = $template_group_object->context_templates();
2683
+					if (is_array($context_templates)) :
2684
+						foreach ($context_templates as $context => $template_fields) :
2685
+							$checked = ($context === $args['context']) ? 'selected' : '';
2686
+							?>
2687 2687
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2688 2688
                                 <?php echo esc_html($context_details[ $context ]['label']); ?>
2689 2689
                             </option>
2690 2690
                         <?php endforeach;
2691
-                    endif; ?>
2691
+					endif; ?>
2692 2692
                 </select>
2693 2693
                 <?php $button_text = sprintf(
2694
-                    esc_html__('Switch %s', 'event_espresso'),
2695
-                    ucwords($context_label['label'])
2696
-                ); ?>
2694
+					esc_html__('Switch %s', 'event_espresso'),
2695
+					ucwords($context_label['label'])
2696
+				); ?>
2697 2697
                 <input class='button--secondary'
2698 2698
                        id="submit-msg-context-switcher-sbmt"
2699 2699
                        type="submit"
@@ -2703,1996 +2703,1996 @@  discard block
 block discarded – undo
2703 2703
             <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>
2704 2704
         </div> <!-- end .ee-msg-switcher-container -->
2705 2705
         <?php $this->_context_switcher = ob_get_clean();
2706
-    }
2707
-
2708
-
2709
-    /**
2710
-     * @param bool $new
2711
-     * @throws EE_Error
2712
-     * @throws ReflectionException
2713
-     */
2714
-    protected function _insert_or_update_message_template($new = false)
2715
-    {
2716
-        $form_data    = $this->getMessageTemplateFormData();
2717
-        $GRP_ID       = $form_data['GRP_ID'];
2718
-        $messenger    = $form_data['MTP_messenger'];
2719
-        $message_type = $form_data['MTP_message_type'];
2720
-        $context      = $form_data['MTP_context'];
2721
-
2722
-        // if this is "new" then we need to generate the default contexts
2723
-        // for the selected messenger/message_type for user to edit.
2724
-        [$success, $query_args] = $new
2725
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
-
2728
-        $success     = $success ? 1 : 0;
2729
-        $action_desc = $new ? 'created' : 'updated';
2730
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
-
2733
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
-    }
2735
-
2736
-
2737
-    /**
2738
-     * retrieve and sanitize form data
2739
-     *
2740
-     * @return array
2741
-     * @since 4.10.29.p
2742
-     */
2743
-    protected function getMessageTemplateFormData()
2744
-    {
2745
-        return [
2746
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
-        ];
2756
-    }
2757
-
2758
-
2759
-    /**
2760
-     * @param int    $GRP_ID
2761
-     * @param string $messenger
2762
-     * @param string $message_type
2763
-     * @return array no return on AJAX requests
2764
-     * @throws EE_Error
2765
-     * @throws ReflectionException
2766
-     * @since 4.10.29.p
2767
-     */
2768
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
-    {
2770
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
-        $success       = ! empty($new_templates);
2772
-
2773
-        // we return things differently if doing ajax
2774
-        if ($this->request->isAjax()) {
2775
-            $this->_template_args['success'] = $success;
2776
-            $this->_template_args['error']   = ! $success;
2777
-            $this->_template_args['content'] = '';
2778
-            $this->_template_args['data']    = [
2779
-                'grpID'        => $new_templates['GRP_ID'],
2780
-                'templateName' => $new_templates['template_name'],
2781
-            ];
2782
-            if ($success) {
2783
-                EE_Error::overwrite_success();
2784
-                EE_Error::add_success(
2785
-                    esc_html__(
2786
-                        '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.',
2787
-                        'event_espresso'
2788
-                    )
2789
-                );
2790
-            }
2791
-            $this->_return_json();
2792
-        }
2793
-        return [
2794
-            $success,
2795
-            // 'query_args'
2796
-            [
2797
-                'id'      => $new_templates['GRP_ID'],
2798
-                'context' => $new_templates['MTP_context'],
2799
-                'action'  => 'edit_message_template',
2800
-            ],
2801
-        ];
2802
-    }
2803
-
2804
-
2805
-    /**
2806
-     * @param int    $GRP_ID
2807
-     * @param string $messenger
2808
-     * @param string $message_type
2809
-     * @param string $context
2810
-     * @param array  $form_data
2811
-     * @return array
2812
-     * @throws EE_Error
2813
-     * @since 4.10.29.p
2814
-     */
2815
-    private function updateExistingTemplates(
2816
-        $GRP_ID,
2817
-        $messenger,
2818
-        $message_type,
2819
-        $context,
2820
-        array $form_data
2821
-    ) {
2822
-        $success         = false;
2823
-        $template_fields = $this->getTemplateFields();
2824
-        if ($template_fields) {
2825
-            // if field data is valid, then success will be true
2826
-            $success = $this->validateTemplateFields(
2827
-                $messenger,
2828
-                $message_type,
2829
-                $context,
2830
-                $template_fields
2831
-            );
2832
-            if ($success) {
2833
-                $field_data = [];
2834
-                foreach ($template_fields as $template_field => $content) {
2835
-                    // combine top-level form data with content for this field
2836
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
-                }
2839
-                // we can use the last set_column_values for the MTPG update
2840
-                // (because its the same for all of these specific MTPs)
2841
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
-            }
2843
-        }
2844
-
2845
-        return [
2846
-            $success,
2847
-            // 'query_args'
2848
-            [
2849
-                'id'      => $GRP_ID,
2850
-                'context' => $context,
2851
-                'action'  => 'edit_message_template',
2852
-            ],
2853
-        ];
2854
-    }
2855
-
2856
-
2857
-    /**
2858
-     * @return array
2859
-     * @since 4.10.29.p
2860
-     */
2861
-    private function getTemplateFields()
2862
-    {
2863
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
-        if (empty($template_fields)) {
2865
-            EE_Error::add_error(
2866
-                esc_html__(
2867
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
-                    'event_espresso'
2869
-                ),
2870
-                __FILE__,
2871
-                __FUNCTION__,
2872
-                __LINE__
2873
-            );
2874
-            return null;
2875
-        }
2876
-        // messages content is expected to be escaped
2877
-        return EEH_Array::addSlashesRecursively($template_fields);
2878
-    }
2879
-
2880
-
2881
-    /**
2882
-     * @param string $messenger
2883
-     * @param string $message_type
2884
-     * @param string $context
2885
-     * @param array  $template_fields
2886
-     * @return bool
2887
-     * @throws EE_Error
2888
-     * @since   4.10.29.p
2889
-     */
2890
-    private function validateTemplateFields(
2891
-        $messenger,
2892
-        $message_type,
2893
-        $context,
2894
-        array $template_fields
2895
-    ) {
2896
-        // first validate all fields!
2897
-        // this filter allows client code to add its own validation to the template fields as well.
2898
-        // returning an empty array means everything passed validation.
2899
-        // errors in validation should be represented in an array with the following shape:
2900
-        // array(
2901
-        //   'fieldname' => array(
2902
-        //          'msg' => 'error message'
2903
-        //          'value' => 'value for field producing error'
2904
-        // )
2905
-        $custom_validation = (array) apply_filters(
2906
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
-            [],
2908
-            $template_fields,
2909
-            $context,
2910
-            $messenger,
2911
-            $message_type
2912
-        );
2913
-
2914
-        $system_validation = $this->getMtgModel()->validate(
2915
-            $template_fields,
2916
-            $context,
2917
-            $messenger,
2918
-            $message_type
2919
-        );
2920
-
2921
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
-        $validates         = array_merge($custom_validation, $system_validation);
2923
-
2924
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
-        //  WE need to make sure there is no actual error messages in validates.
2927
-        if (empty($validates)) {
2928
-            return true;
2929
-        }
2930
-
2931
-        // add the transient so when the form loads we know which fields to highlight
2932
-        $this->_add_transient('edit_message_template', $validates);
2933
-        // setup notices
2934
-        foreach ($validates as $error) {
2935
-            if (isset($error['msg'])) {
2936
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
-            }
2938
-        }
2939
-        return false;
2940
-    }
2941
-
2942
-
2943
-    /**
2944
-     * @param array $field_data
2945
-     * @param array $form_data
2946
-     * @return array
2947
-     * @since   4.10.29.p
2948
-     */
2949
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
-    {
2951
-        return $form_data + [
2952
-                'MTP_ID'             => $field_data['MTP_ID'],
2953
-                'MTP_template_field' => $field_data['name'],
2954
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2956
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
-                    : $field_data['content'],
2958
-            ];
2959
-    }
2960
-
2961
-
2962
-    /**
2963
-     * @param string $template_field
2964
-     * @param array  $form_data
2965
-     * @return bool
2966
-     * @throws EE_Error
2967
-     * @since 4.10.29.p
2968
-     */
2969
-    private function updateMessageTemplates($template_field, array $form_data)
2970
-    {
2971
-        $MTP_ID                  = $form_data['MTP_ID'];
2972
-        $message_template_fields = [
2973
-            'GRP_ID'             => $form_data['GRP_ID'],
2974
-            'MTP_template_field' => $form_data['MTP_template_field'],
2975
-            'MTP_context'        => $form_data['MTP_context'],
2976
-            'MTP_content'        => $form_data['MTP_content'],
2977
-        ];
2978
-
2979
-        $hasMtpID = ! empty($MTP_ID);
2980
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2981
-        // this has already been through the template field validator and sanitized, so it will be
2982
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
-        // message template field in a messenger/message type and existing users don't have the
2984
-        // default setup for it.
2985
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
-        $updated = $hasMtpID
2987
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
-            : $this->getMtpModel()->insert($message_template_fields);
2989
-
2990
-        $insert_failed = ! $hasMtpID && ! $updated;
2991
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
-        $update_failed = $hasMtpID && $updated === false;
2994
-
2995
-        if ($insert_failed || $update_failed) {
2996
-            EE_Error::add_error(
2997
-                sprintf(
2998
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
-                    $template_field
3000
-                ),
3001
-                __FILE__,
3002
-                __FUNCTION__,
3003
-                __LINE__
3004
-            );
3005
-            return false;
3006
-        }
3007
-        return true;
3008
-    }
3009
-
3010
-
3011
-    /**
3012
-     * @param array $form_data
3013
-     * @return bool
3014
-     * @throws EE_Error
3015
-     * @since 4.10.29.p
3016
-     */
3017
-    private function updateMessageTemplateGroup(array $form_data)
3018
-    {
3019
-        $GRP_ID  = $form_data['GRP_ID'];
3020
-        $updated = $this->getMtgModel()->update(
3021
-        // fields and values
3022
-            [
3023
-                'MTP_user_id'      => $form_data['MTP_user_id'],
3024
-                'MTP_messenger'    => $form_data['MTP_messenger'],
3025
-                'MTP_message_type' => $form_data['MTP_message_type'],
3026
-                'MTP_is_global'    => $form_data['MTP_is_global'],
3027
-                'MTP_is_override'  => $form_data['MTP_is_override'],
3028
-                'MTP_deleted'      => $form_data['MTP_deleted'],
3029
-                'MTP_is_active'    => $form_data['MTP_is_active'],
3030
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
-                'MTP_description'  => $this->request->getRequestParam(
3032
-                    'ee_msg_non_global_fields[MTP_description]',
3033
-                    ''
3034
-                ),
3035
-            ],
3036
-            // where
3037
-            [['GRP_ID' => $GRP_ID]]
3038
-        );
3039
-
3040
-        if ($updated === false) {
3041
-            EE_Error::add_error(
3042
-                sprintf(
3043
-                    esc_html__(
3044
-                        'The Message Template Group (%d) was NOT updated for some reason',
3045
-                        'event_espresso'
3046
-                    ),
3047
-                    $form_data['GRP_ID']
3048
-                ),
3049
-                __FILE__,
3050
-                __FUNCTION__,
3051
-                __LINE__
3052
-            );
3053
-            return false;
3054
-        }
3055
-        // k now we need to ensure the template_pack and template_variation fields are set.
3056
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
-
3059
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3061
-            $message_template_group->set_template_pack_name($template_pack);
3062
-            $message_template_group->set_template_pack_variation($template_variation);
3063
-        }
3064
-        return true;
3065
-    }
3066
-
3067
-
3068
-    /**
3069
-     * recursively runs wp_kses() on message template content in a model safe manner
3070
-     *
3071
-     * @param array|string $content
3072
-     * @return array|string
3073
-     * @since   4.10.29.p
3074
-     */
3075
-    private function sanitizeMessageTemplateContent($content)
3076
-    {
3077
-        if (is_array($content)) {
3078
-            foreach ($content as $key => $value) {
3079
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
-            }
3081
-            return $content;
3082
-        }
3083
-        // remove slashes so wp_kses() works properly
3084
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3085
-        // so attributes using single quotes always appear invalid.
3086
-        $content = stripslashes($content);
3087
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3088
-        // But currently the models expect slashed data, so after wp_kses()
3089
-        // runs we need to re-slash the data. Sheesh.
3090
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
-        return addslashes($content);
3092
-    }
3093
-
3094
-
3095
-    /**
3096
-     * @param string $messenger
3097
-     * @param string $message_type
3098
-     * @param string $context
3099
-     * @return string
3100
-     * @since 4.10.29.p
3101
-     */
3102
-    private function generateUpdateDescription($messenger, $message_type, $context)
3103
-    {
3104
-        // need the message type and messenger objects to be able to use the labels for the notices
3105
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
-        $messenger_label  = $messenger_object instanceof EE_messenger
3107
-            ? ucwords($messenger_object->label['singular'])
3108
-            : '';
3109
-
3110
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
-        $message_type_label  = $message_type_object instanceof EE_message_type
3112
-            ? ucwords($message_type_object->label['singular'])
3113
-            : '';
3114
-
3115
-        $context   = ucwords(str_replace('_', ' ', $context));
3116
-        $item_desc = $messenger_label && $message_type_label
3117
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
-            : '';
3119
-        $item_desc .= 'Message Template';
3120
-        return $item_desc;
3121
-    }
3122
-
3123
-
3124
-    /**
3125
-     * @param string $messenger
3126
-     * @param string $message_type
3127
-     * @param string $context
3128
-     * @return bool
3129
-     * @throws EE_Error
3130
-     * @throws ReflectionException
3131
-     * @since 4.10.29.p
3132
-     */
3133
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
-    {
3135
-        // was a test send triggered?
3136
-        if ($this->request->requestParamIsSet('test_button')) {
3137
-            EE_Error::overwrite_success();
3138
-            $this->_do_test_send($context, $messenger, $message_type);
3139
-            return true;
3140
-        }
3141
-        return false;
3142
-    }
3143
-
3144
-
3145
-    /**
3146
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
-     *
3148
-     * @param string $context      what context being tested
3149
-     * @param string $messenger    messenger being tested
3150
-     * @param string $message_type message type being tested
3151
-     * @throws EE_Error
3152
-     * @throws InvalidArgumentException
3153
-     * @throws InvalidDataTypeException
3154
-     * @throws InvalidInterfaceException
3155
-     * @throws ReflectionException
3156
-     */
3157
-    protected function _do_test_send($context, $messenger, $message_type)
3158
-    {
3159
-        // set things up for preview
3160
-        $this->request->setRequestParam('messenger', $messenger);
3161
-        $this->request->setRequestParam('message_type', $message_type);
3162
-        $this->request->setRequestParam('context', $context);
3163
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
-
3166
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
-
3169
-        // let's save any existing fields that might be required by the messenger
3170
-        if (
3171
-            ! empty($test_settings_fld)
3172
-            && $active_messenger instanceof EE_messenger
3173
-            && apply_filters(
3174
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
-                true,
3176
-                $test_settings_fld,
3177
-                $active_messenger
3178
-            )
3179
-        ) {
3180
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3181
-        }
3182
-
3183
-        /**
3184
-         * Use filter to add additional controls on whether message can send or not
3185
-         */
3186
-        if (
3187
-            apply_filters(
3188
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
-                true,
3190
-                $context,
3191
-                $this->request->requestParams(),
3192
-                $messenger,
3193
-                $message_type
3194
-            )
3195
-        ) {
3196
-            if (EEM_Event::instance()->count() > 0) {
3197
-                $success = $this->_preview_message(true);
3198
-                if ($success) {
3199
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
-                } else {
3201
-                    EE_Error::add_error(
3202
-                        esc_html__('The test message was not sent', 'event_espresso'),
3203
-                        __FILE__,
3204
-                        __FUNCTION__,
3205
-                        __LINE__
3206
-                    );
3207
-                }
3208
-            } else {
3209
-                $this->noEventsErrorMessage(true);
3210
-            }
3211
-        }
3212
-    }
3213
-
3214
-
3215
-    /**
3216
-     * _generate_new_templates
3217
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
-     * for the event.
3220
-     *
3221
-     *
3222
-     * @param string $messenger      the messenger we are generating templates for
3223
-     * @param array  $message_types  array of message types that the templates are generated for.
3224
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
-     *                               indicate the message_template_group being used as the base.
3226
-     *
3227
-     * @param bool   $global
3228
-     *
3229
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
-     *                               encountering problems.
3231
-     * @throws EE_Error
3232
-     * @throws ReflectionException
3233
-     */
3234
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
-    {
3236
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
-        // just don't generate any templates.
3238
-        if (empty($message_types)) {
3239
-            return [];
3240
-        }
3241
-
3242
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
-        return $templates[0];
3244
-    }
3245
-
3246
-
3247
-    /**
3248
-     * [_trash_or_restore_message_template]
3249
-     *
3250
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
-     *                        an individual context (FALSE).
3253
-     * @return void
3254
-     * @throws EE_Error
3255
-     * @throws InvalidArgumentException
3256
-     * @throws InvalidDataTypeException
3257
-     * @throws InvalidInterfaceException
3258
-     */
3259
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
-    {
3261
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
-
3263
-        $success = 1;
3264
-
3265
-        // incoming GRP_IDs
3266
-        if ($all) {
3267
-            // Checkboxes
3268
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
-            if (! empty($checkboxes)) {
3270
-                // if array has more than one element then success message should be plural.
3271
-                // todo: what about nonce?
3272
-                $success = count($checkboxes) > 1 ? 2 : 1;
3273
-
3274
-                // cycle through checkboxes
3275
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3276
-                    $trashed_or_restored = $trash
3277
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
-                    if (! $trashed_or_restored) {
3280
-                        $success = 0;
3281
-                    }
3282
-                }
3283
-            } else {
3284
-                // grab single GRP_ID and handle
3285
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
-                if (! empty($GRP_ID)) {
3287
-                    $trashed_or_restored = $trash
3288
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
-                    if (! $trashed_or_restored) {
3291
-                        $success = 0;
3292
-                    }
3293
-                } else {
3294
-                    $success = 0;
3295
-                }
3296
-            }
3297
-        }
3298
-
3299
-        $action_desc = $trash
3300
-            ? esc_html__('moved to the trash', 'event_espresso')
3301
-            : esc_html__('restored', 'event_espresso');
3302
-
3303
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
-
3306
-        $item_desc = $all ? _n(
3307
-            'Message Template Group',
3308
-            'Message Template Groups',
3309
-            $success,
3310
-            'event_espresso'
3311
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
-
3313
-        $item_desc = $template_switch
3314
-            ? _n('template', 'templates', $success, 'event_espresso')
3315
-            : $item_desc;
3316
-
3317
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
-    }
3319
-
3320
-
3321
-    /**
3322
-     * [_delete_message_template]
3323
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
-     *
3325
-     * @return void
3326
-     * @throws EE_Error
3327
-     * @throws InvalidArgumentException
3328
-     * @throws InvalidDataTypeException
3329
-     * @throws InvalidInterfaceException
3330
-     * @throws ReflectionException
3331
-     */
3332
-    protected function _delete_message_template()
3333
-    {
3334
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
-
3336
-        // checkboxes
3337
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
-        if (! empty($checkboxes)) {
3339
-            // if array has more than one element then success message should be plural
3340
-            $success = count($checkboxes) > 1 ? 2 : 1;
3341
-
3342
-            // cycle through bulk action checkboxes
3343
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3344
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
-            }
3346
-        } else {
3347
-            // grab single grp_id and delete
3348
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3350
-        }
3351
-
3352
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
-    }
3354
-
3355
-
3356
-    /**
3357
-     * helper for permanently deleting a mtP group and all related message_templates
3358
-     *
3359
-     * @param int  $GRP_ID        The group being deleted
3360
-     * @param bool $include_group whether to delete the Message Template Group as well.
3361
-     * @return bool boolean to indicate the success of the deletes or not.
3362
-     * @throws EE_Error
3363
-     * @throws InvalidArgumentException
3364
-     * @throws InvalidDataTypeException
3365
-     * @throws InvalidInterfaceException
3366
-     * @throws ReflectionException
3367
-     * @throws ReflectionException
3368
-     */
3369
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
-    {
3371
-        $success = true;
3372
-        // first let's GET this group
3373
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
-        // then delete permanently all the related Message Templates
3375
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3376
-
3377
-        if ($deleted === 0) {
3378
-            $success = false;
3379
-        }
3380
-
3381
-        // now delete permanently this particular group
3382
-
3383
-        if ($include_group && ! $MTG->delete_permanently()) {
3384
-            $success = false;
3385
-        }
3386
-
3387
-        return $success;
3388
-    }
3389
-
3390
-
3391
-    /**
3392
-     *    _learn_more_about_message_templates_link
3393
-     *
3394
-     * @access protected
3395
-     * @return string
3396
-     */
3397
-    protected function _learn_more_about_message_templates_link()
3398
-    {
3399
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3401
-               . '</a>';
3402
-    }
3403
-
3404
-
3405
-    /**
3406
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
-     * ajax and other routes.
3408
-     *
3409
-     * @return void
3410
-     * @throws DomainException
3411
-     * @throws EE_Error
3412
-     */
3413
-    protected function _settings()
3414
-    {
3415
-        $this->_set_m_mt_settings();
3416
-
3417
-        // let's setup the messenger tabs
3418
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
-            $this->_m_mt_settings['messenger_tabs'],
3420
-            'messenger_links',
3421
-            '|',
3422
-            $this->request->getRequestParam('selected_messenger', 'email')
3423
-        );
3424
-
3425
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
-
3428
-        $this->display_admin_page_with_sidebar();
3429
-    }
3430
-
3431
-
3432
-    /**
3433
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
-     *
3435
-     * @access protected
3436
-     * @return void
3437
-     * @throws DomainException
3438
-     */
3439
-    protected function _set_m_mt_settings()
3440
-    {
3441
-        // first if this is already set then lets get out no need to regenerate data.
3442
-        if (! empty($this->_m_mt_settings)) {
3443
-            return;
3444
-        }
3445
-
3446
-        // get all installed messengers and message_types
3447
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3448
-        $message_types = $this->_message_resource_manager->installed_message_types();
3449
-
3450
-
3451
-        // assemble the array for the _tab_text_links helper
3452
-
3453
-        foreach ($messengers as $messenger) {
3454
-            $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3455
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3456
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3457
-                'label' => ucwords($messenger->label['singular']),
3458
-                'class' => $active ? "{$class} messenger-active" : $class,
3459
-                'href'  => $messenger->name,
3460
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
-                'slug'  => $messenger->name,
3462
-                'obj'   => $messenger,
3463
-                'icon' => $active
3464
-                    ? '<span class="dashicons dashicons-yes-alt"></span>'
3465
-                    : '<span class="dashicons dashicons-remove"></span>',
3466
-            ];
3467
-
3468
-
3469
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3470
-
3471
-            foreach ($message_types as $message_type) {
3472
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3473
-                // it shouldn't show in either the inactive OR active metabox.
3474
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3475
-                    continue;
3476
-                }
3477
-
3478
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3479
-                    $messenger->name,
3480
-                    $message_type->name
3481
-                )
3482
-                    ? 'active'
3483
-                    : 'inactive';
3484
-
3485
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3486
-                    'label'    => ucwords($message_type->label['singular']),
3487
-                    'class'    => 'message-type-' . $a_or_i,
3488
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3489
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3490
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3491
-                    'title'    => $a_or_i === 'active'
3492
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3493
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3494
-                    'content'  => $a_or_i === 'active'
3495
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3496
-                        : $this->_message_type_settings_content($message_type, $messenger),
3497
-                    'slug'     => $message_type->name,
3498
-                    'active'   => $a_or_i === 'active',
3499
-                    'obj'      => $message_type,
3500
-                ];
3501
-            }
3502
-        }
3503
-    }
3504
-
3505
-
3506
-    /**
3507
-     * This just prepares the content for the message type settings
3508
-     *
3509
-     * @param EE_message_type $message_type The message type object
3510
-     * @param EE_messenger    $messenger    The messenger object
3511
-     * @param boolean         $active       Whether the message type is active or not
3512
-     * @return string html output for the content
3513
-     * @throws DomainException
3514
-     */
3515
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3516
-    {
3517
-        // get message type fields
3518
-        $fields                                         = $message_type->get_admin_settings_fields();
3519
-        $settings_template_args['template_form_fields'] = '';
3520
-
3521
-        if (! empty($fields) && $active) {
3522
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3523
-            foreach ($fields as $fldname => $fldprops) {
3524
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3525
-                $template_form_field[ $field_id ] = [
3526
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3527
-                    'label'      => $fldprops['label'],
3528
-                    'input'      => $fldprops['field_type'],
3529
-                    'type'       => $fldprops['value_type'],
3530
-                    'required'   => $fldprops['required'],
3531
-                    'validation' => $fldprops['validation'],
3532
-                    'value'      => isset($existing_settings[ $fldname ])
3533
-                        ? $existing_settings[ $fldname ]
3534
-                        : $fldprops['default'],
3535
-                    'options'    => isset($fldprops['options'])
3536
-                        ? $fldprops['options']
3537
-                        : [],
3538
-                    'default'    => isset($existing_settings[ $fldname ])
3539
-                        ? $existing_settings[ $fldname ]
3540
-                        : $fldprops['default'],
3541
-                    'css_class'  => 'no-drag',
3542
-                    'format'     => $fldprops['format'],
3543
-                ];
3544
-            }
3545
-
3546
-
3547
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3548
-                ? $this->_generate_admin_form_fields(
3549
-                    $template_form_field,
3550
-                    'string',
3551
-                    'ee_mt_activate_form'
3552
-                )
3553
-                : '';
3554
-        }
3555
-
3556
-        $settings_template_args['description'] = $message_type->description;
3557
-        // we also need some hidden fields
3558
-        $hidden_fields = [
3559
-            'message_type_settings[messenger]' . $message_type->name    => [
3560
-                'type'  => 'hidden',
3561
-                'value' => $messenger->name,
3562
-            ],
3563
-            'message_type_settings[message_type]' . $message_type->name => [
3564
-                'type'  => 'hidden',
3565
-                'value' => $message_type->name,
3566
-            ],
3567
-            'type' . $message_type->name                                => [
3568
-                'type'  => 'hidden',
3569
-                'value' => 'message_type',
3570
-            ],
3571
-        ];
3572
-
3573
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3574
-            $hidden_fields,
3575
-            'array'
3576
-        );
3577
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3578
-            ? ' hidden'
3579
-            : '';
3580
-
3581
-
3582
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3583
-        return EEH_Template::display_template($template, $settings_template_args, true);
3584
-    }
3585
-
3586
-
3587
-    /**
3588
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3589
-     *
3590
-     * @access protected
3591
-     * @return void
3592
-     * @throws DomainException
3593
-     */
3594
-    protected function _messages_settings_metaboxes()
3595
-    {
3596
-        $this->_set_m_mt_settings();
3597
-        $m_boxes         = $mt_boxes = [];
3598
-        $m_template_args = $mt_template_args = [];
3599
-
3600
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3601
-
3602
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3603
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3604
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3605
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3606
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3607
-
3608
-                // messenger meta boxes
3609
-                $active         = $selected_messenger === $messenger;
3610
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3611
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3612
-                    : '';
3613
-
3614
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3615
-                    esc_html__('%s Settings', 'event_espresso'),
3616
-                    $tab_array['label']
3617
-                );
3618
-
3619
-                $m_template_args[ $messenger . '_a_box' ] = [
3620
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3621
-                    'inactive_message_types' => isset(
3622
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3623
-                    )
3624
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3625
-                        : '',
3626
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3627
-                    'hidden'                 => $active ? '' : ' hidden',
3628
-                    'hide_on_message'        => $hide_on_message,
3629
-                    'messenger'              => $messenger,
3630
-                    'active'                 => $active,
3631
-                ];
3632
-
3633
-                // message type meta boxes
3634
-                // (which is really just the inactive container for each messenger
3635
-                // showing inactive message types for that messenger)
3636
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3637
-                $mt_template_args[ $messenger . '_i_box' ] = [
3638
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3639
-                    'inactive_message_types' => isset(
3640
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3641
-                    )
3642
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3643
-                        : '',
3644
-                    'hidden'                 => $active ? '' : ' hidden',
3645
-                    'hide_on_message'        => $hide_on_message,
3646
-                    'hide_off_message'       => $hide_off_message,
3647
-                    'messenger'              => $messenger,
3648
-                    'active'                 => $active,
3649
-                ];
3650
-            }
3651
-        }
3652
-
3653
-
3654
-        // register messenger metaboxes
3655
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3656
-        foreach ($m_boxes as $box => $label) {
3657
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3658
-            $msgr          = str_replace('_a_box', '', $box);
3659
-            $this->addMetaBox(
3660
-                'espresso_' . $msgr . '_settings',
3661
-                $label,
3662
-                function ($post, $metabox) {
3663
-                    EEH_Template::display_template(
3664
-                        $metabox['args']['template_path'],
3665
-                        $metabox['args']['template_args']
3666
-                    );
3667
-                },
3668
-                $this->_current_screen->id,
3669
-                'normal',
3670
-                'high',
3671
-                $callback_args
3672
-            );
3673
-        }
3674
-
3675
-        // register message type metaboxes
3676
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3677
-        foreach ($mt_boxes as $box => $label) {
3678
-            $callback_args = [
3679
-                'template_path' => $mt_template_path,
3680
-                'template_args' => $mt_template_args[ $box ],
3681
-            ];
3682
-            $mt            = str_replace('_i_box', '', $box);
3683
-            $this->addMetaBox(
3684
-                'espresso_' . $mt . '_inactive_mts',
3685
-                $label,
3686
-                function ($post, $metabox) {
3687
-                    EEH_Template::display_template(
3688
-                        $metabox['args']['template_path'],
3689
-                        $metabox['args']['template_args']
3690
-                    );
3691
-                },
3692
-                $this->_current_screen->id,
3693
-                'side',
3694
-                'high',
3695
-                $callback_args
3696
-            );
3697
-        }
3698
-
3699
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3700
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3701
-        if (is_main_site()) {
3702
-            $this->addMetaBox(
3703
-                'espresso_global_message_settings',
3704
-                esc_html__('Global Message Settings', 'event_espresso'),
3705
-                [$this, 'global_messages_settings_metabox_content'],
3706
-                $this->_current_screen->id,
3707
-                'normal',
3708
-                'low',
3709
-                []
3710
-            );
3711
-        }
3712
-    }
3713
-
3714
-
3715
-    /**
3716
-     *  This generates the content for the global messages settings metabox.
3717
-     *
3718
-     * @return void
3719
-     * @throws EE_Error
3720
-     * @throws InvalidArgumentException
3721
-     * @throws ReflectionException
3722
-     * @throws InvalidDataTypeException
3723
-     * @throws InvalidInterfaceException
3724
-     */
3725
-    public function global_messages_settings_metabox_content()
3726
-    {
3727
-        $form = $this->_generate_global_settings_form();
3728
-        echo wp_kses(
3729
-            $form->form_open(
3730
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3731
-                'POST'
3732
-            ),
3733
-            AllowedTags::getWithFormTags()
3734
-        );
3735
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3736
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3737
-    }
3738
-
3739
-
3740
-    /**
3741
-     * This generates and returns the form object for the global messages settings.
3742
-     *
3743
-     * @return EE_Form_Section_Proper
3744
-     * @throws EE_Error
3745
-     * @throws InvalidArgumentException
3746
-     * @throws ReflectionException
3747
-     * @throws InvalidDataTypeException
3748
-     * @throws InvalidInterfaceException
3749
-     */
3750
-    protected function _generate_global_settings_form()
3751
-    {
3752
-        /** @var EE_Network_Core_Config $network_config */
3753
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3754
-
3755
-        return new EE_Form_Section_Proper(
3756
-            [
3757
-                'name'            => 'global_messages_settings',
3758
-                'html_id'         => 'global_messages_settings',
3759
-                'html_class'      => 'form-table',
3760
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3761
-                'subsections'     => apply_filters(
3762
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3763
-                    [
3764
-                        'do_messages_on_same_request' => new EE_Select_Input(
3765
-                            [
3766
-                                true  => esc_html__('On the same request', 'event_espresso'),
3767
-                                false => esc_html__('On a separate request', 'event_espresso'),
3768
-                            ],
3769
-                            [
3770
-                                'default'         => $network_config->do_messages_on_same_request,
3771
-                                'html_label_text' => esc_html__(
3772
-                                    'Generate and send all messages:',
3773
-                                    'event_espresso'
3774
-                                ),
3775
-                                'html_help_text'  => esc_html__(
3776
-                                    '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.',
3777
-                                    'event_espresso'
3778
-                                ),
3779
-                            ]
3780
-                        ),
3781
-                        'delete_threshold'            => new EE_Select_Input(
3782
-                            [
3783
-                                0  => esc_html__('Forever', 'event_espresso'),
3784
-                                3  => esc_html__('3 Months', 'event_espresso'),
3785
-                                6  => esc_html__('6 Months', 'event_espresso'),
3786
-                                9  => esc_html__('9 Months', 'event_espresso'),
3787
-                                12 => esc_html__('12 Months', 'event_espresso'),
3788
-                                24 => esc_html__('24 Months', 'event_espresso'),
3789
-                                36 => esc_html__('36 Months', 'event_espresso'),
3790
-                            ],
3791
-                            [
3792
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3793
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3794
-                                'html_help_text'  => esc_html__(
3795
-                                    'You can control how long a record of processed messages is kept via this option.',
3796
-                                    'event_espresso'
3797
-                                ),
3798
-                            ]
3799
-                        ),
3800
-                        'update_settings'             => new EE_Submit_Input(
3801
-                            [
3802
-                                'default'         => esc_html__('Update', 'event_espresso'),
3803
-                                'html_label_text' => '',
3804
-                            ]
3805
-                        ),
3806
-                    ]
3807
-                ),
3808
-            ]
3809
-        );
3810
-    }
3811
-
3812
-
3813
-    /**
3814
-     * This handles updating the global settings set on the admin page.
3815
-     *
3816
-     * @throws EE_Error
3817
-     * @throws InvalidDataTypeException
3818
-     * @throws InvalidInterfaceException
3819
-     * @throws InvalidArgumentException
3820
-     * @throws ReflectionException
3821
-     */
3822
-    protected function _update_global_settings()
3823
-    {
3824
-        /** @var EE_Network_Core_Config $network_config */
3825
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3826
-        $messages_config = EE_Registry::instance()->CFG->messages;
3827
-        $form            = $this->_generate_global_settings_form();
3828
-        if ($form->was_submitted()) {
3829
-            $form->receive_form_submission();
3830
-            if ($form->is_valid()) {
3831
-                $valid_data = $form->valid_data();
3832
-                foreach ($valid_data as $property => $value) {
3833
-                    $setter = 'set_' . $property;
3834
-                    if (method_exists($network_config, $setter)) {
3835
-                        $network_config->{$setter}($value);
3836
-                    } elseif (
3837
-                        property_exists($network_config, $property)
3838
-                        && $network_config->{$property} !== $value
3839
-                    ) {
3840
-                        $network_config->{$property} = $value;
3841
-                    } elseif (
3842
-                        property_exists($messages_config, $property)
3843
-                        && $messages_config->{$property} !== $value
3844
-                    ) {
3845
-                        $messages_config->{$property} = $value;
3846
-                    }
3847
-                }
3848
-                // only update if the form submission was valid!
3849
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3850
-                EE_Registry::instance()->CFG->update_espresso_config();
3851
-                EE_Error::overwrite_success();
3852
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3853
-            }
3854
-        }
3855
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3856
-    }
3857
-
3858
-
3859
-    /**
3860
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3861
-     *
3862
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3863
-     * @return string html formatted tabs
3864
-     * @throws DomainException
3865
-     */
3866
-    protected function _get_mt_tabs($tab_array)
3867
-    {
3868
-        $tab_array = (array) $tab_array;
3869
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3870
-        $tabs      = '';
3871
-
3872
-        foreach ($tab_array as $tab) {
3873
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3874
-        }
3875
-
3876
-        return $tabs;
3877
-    }
3878
-
3879
-
3880
-    /**
3881
-     * This prepares the content of the messenger meta box admin settings
3882
-     *
3883
-     * @param EE_messenger $messenger The messenger we're setting up content for
3884
-     * @return string html formatted content
3885
-     * @throws DomainException
3886
-     */
3887
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3888
-    {
3889
-
3890
-        $fields                                         = $messenger->get_admin_settings_fields();
3891
-        $settings_template_args['template_form_fields'] = '';
3892
-
3893
-        // is $messenger active?
3894
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3895
-
3896
-
3897
-        if (! empty($fields)) {
3898
-            $existing_settings = $messenger->get_existing_admin_settings();
3899
-
3900
-            foreach ($fields as $fldname => $fldprops) {
3901
-                $field_id                         = $messenger->name . '-' . $fldname;
3902
-                $template_form_field[ $field_id ] = [
3903
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3904
-                    'label'      => $fldprops['label'],
3905
-                    'input'      => $fldprops['field_type'],
3906
-                    'type'       => $fldprops['value_type'],
3907
-                    'required'   => $fldprops['required'],
3908
-                    'validation' => $fldprops['validation'],
3909
-                    'value'      => isset($existing_settings[ $field_id ])
3910
-                        ? $existing_settings[ $field_id ]
3911
-                        : $fldprops['default'],
3912
-                    'css_class'  => '',
3913
-                    'format'     => $fldprops['format'],
3914
-                ];
3915
-            }
3916
-
3917
-
3918
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3919
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3920
-                : '';
3921
-        }
3922
-
3923
-        // we also need some hidden fields
3924
-        $settings_template_args['hidden_fields'] = [
3925
-            'messenger_settings[messenger]' . $messenger->name => [
3926
-                'type'  => 'hidden',
3927
-                'value' => $messenger->name,
3928
-            ],
3929
-            'type' . $messenger->name                          => [
3930
-                'type'  => 'hidden',
3931
-                'value' => 'messenger',
3932
-            ],
3933
-        ];
3934
-
3935
-        // make sure any active message types that are existing are included in the hidden fields
3936
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3937
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3938
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3939
-                    'type'  => 'hidden',
3940
-                    'value' => $mt,
3941
-                ];
3942
-            }
3943
-        }
3944
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3945
-            $settings_template_args['hidden_fields'],
3946
-            'array'
3947
-        );
3948
-        $active                                  =
3949
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3950
-
3951
-        $settings_template_args['messenger']           = $messenger->name;
3952
-        $settings_template_args['description']         = $messenger->description;
3953
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3954
-
3955
-
3956
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3957
-            $messenger->name
3958
-        )
3959
-            ? $settings_template_args['show_hide_edit_form']
3960
-            : ' hidden';
3961
-
3962
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3963
-            ? ' hidden'
3964
-            : $settings_template_args['show_hide_edit_form'];
3965
-
3966
-
3967
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3968
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3969
-        $settings_template_args['on_off_status'] = $active;
3970
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3971
-        return EEH_Template::display_template(
3972
-            $template,
3973
-            $settings_template_args,
3974
-            true
3975
-        );
3976
-    }
3977
-
3978
-
3979
-    /**
3980
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3981
-     *
3982
-     * @throws DomainException
3983
-     * @throws EE_Error
3984
-     * @throws InvalidDataTypeException
3985
-     * @throws InvalidInterfaceException
3986
-     * @throws InvalidArgumentException
3987
-     * @throws ReflectionException
3988
-     */
3989
-    public function activate_messenger_toggle()
3990
-    {
3991
-        $success = true;
3992
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3993
-        // let's check that we have required data
3994
-
3995
-        if (! $this->_active_messenger_name) {
3996
-            EE_Error::add_error(
3997
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3998
-                __FILE__,
3999
-                __FUNCTION__,
4000
-                __LINE__
4001
-            );
4002
-            $success = false;
4003
-        }
4004
-
4005
-        // do a nonce check here since we're not arriving via a normal route
4006
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4007
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4008
-
4009
-        $this->_verify_nonce($nonce, $nonce_ref);
4010
-
4011
-
4012
-        $status = $this->request->getRequestParam('status');
4013
-        if (! $status) {
4014
-            EE_Error::add_error(
4015
-                esc_html__(
4016
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4017
-                    'event_espresso'
4018
-                ),
4019
-                __FILE__,
4020
-                __FUNCTION__,
4021
-                __LINE__
4022
-            );
4023
-            $success = false;
4024
-        }
4025
-
4026
-        // do check to verify we have a valid status.
4027
-        if ($status !== 'off' && $status !== 'on') {
4028
-            EE_Error::add_error(
4029
-                sprintf(
4030
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4031
-                    $status
4032
-                ),
4033
-                __FILE__,
4034
-                __FUNCTION__,
4035
-                __LINE__
4036
-            );
4037
-            $success = false;
4038
-        }
4039
-
4040
-        if ($success) {
4041
-            // made it here?  Stop dawdling then!!
4042
-            $success = $status === 'off'
4043
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4044
-                : $this->_activate_messenger($this->_active_messenger_name);
4045
-        }
4046
-
4047
-        $this->_template_args['success'] = $success;
4048
-
4049
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4050
-        $this->_return_json();
4051
-    }
4052
-
4053
-
4054
-    /**
4055
-     * used by ajax from the messages settings page to activate|deactivate a message type
4056
-     *
4057
-     * @throws DomainException
4058
-     * @throws EE_Error
4059
-     * @throws ReflectionException
4060
-     * @throws InvalidDataTypeException
4061
-     * @throws InvalidInterfaceException
4062
-     * @throws InvalidArgumentException
4063
-     */
4064
-    public function activate_mt_toggle()
4065
-    {
4066
-        $success = true;
4067
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4068
-
4069
-        // let's make sure we have the necessary data
4070
-        if (! $this->_active_message_type_name) {
4071
-            EE_Error::add_error(
4072
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4073
-                __FILE__,
4074
-                __FUNCTION__,
4075
-                __LINE__
4076
-            );
4077
-            $success = false;
4078
-        }
4079
-
4080
-        if (! $this->_active_messenger_name) {
4081
-            EE_Error::add_error(
4082
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4083
-                __FILE__,
4084
-                __FUNCTION__,
4085
-                __LINE__
4086
-            );
4087
-            $success = false;
4088
-        }
4089
-
4090
-        $status = $this->request->getRequestParam('status');
4091
-        if (! $status) {
4092
-            EE_Error::add_error(
4093
-                esc_html__(
4094
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4095
-                    'event_espresso'
4096
-                ),
4097
-                __FILE__,
4098
-                __FUNCTION__,
4099
-                __LINE__
4100
-            );
4101
-            $success = false;
4102
-        }
4103
-
4104
-
4105
-        // do check to verify we have a valid status.
4106
-        if ($status !== 'activate' && $status !== 'deactivate') {
4107
-            EE_Error::add_error(
4108
-                sprintf(
4109
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4110
-                    $status
4111
-                ),
4112
-                __FILE__,
4113
-                __FUNCTION__,
4114
-                __LINE__
4115
-            );
4116
-            $success = false;
4117
-        }
4118
-
4119
-
4120
-        // do a nonce check here since we're not arriving via a normal route
4121
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4122
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4123
-
4124
-        if ($success) {
4125
-            // made it here? um, what are you waiting for then?
4126
-            $success = $status === 'deactivate'
4127
-                ? $this->_deactivate_message_type_for_messenger(
4128
-                    $this->_active_messenger_name,
4129
-                    $this->_active_message_type_name
4130
-                )
4131
-                : $this->_activate_message_type_for_messenger(
4132
-                    $this->_active_messenger_name,
4133
-                    $this->_active_message_type_name
4134
-                );
4135
-        }
4136
-
4137
-        $this->_template_args['success'] = $success;
4138
-        $this->_return_json();
4139
-    }
4140
-
4141
-
4142
-    /**
4143
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4144
-     *
4145
-     * @param string $messenger_name The name of the messenger being activated
4146
-     * @return bool
4147
-     * @throws DomainException
4148
-     * @throws EE_Error
4149
-     * @throws InvalidArgumentException
4150
-     * @throws ReflectionException
4151
-     * @throws InvalidDataTypeException
4152
-     * @throws InvalidInterfaceException
4153
-     */
4154
-    protected function _activate_messenger($messenger_name)
4155
-    {
4156
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4157
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4158
-            ? $active_messenger->get_default_message_types()
4159
-            : [];
4160
-
4161
-        // ensure is active
4162
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4163
-
4164
-        // set response_data for reload
4165
-        foreach ($message_types_to_activate as $message_type_name) {
4166
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4167
-            if (
4168
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4169
-                    $messenger_name,
4170
-                    $message_type_name
4171
-                )
4172
-                && $message_type instanceof EE_message_type
4173
-            ) {
4174
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4175
-                if ($message_type->get_admin_settings_fields()) {
4176
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4177
-                }
4178
-            }
4179
-        }
4180
-
4181
-        // add success message for activating messenger
4182
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4183
-    }
4184
-
4185
-
4186
-    /**
4187
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4188
-     *
4189
-     * @param string $messenger_name The name of the messenger being activated
4190
-     * @return bool
4191
-     * @throws DomainException
4192
-     * @throws EE_Error
4193
-     * @throws InvalidArgumentException
4194
-     * @throws ReflectionException
4195
-     * @throws InvalidDataTypeException
4196
-     * @throws InvalidInterfaceException
4197
-     */
4198
-    protected function _deactivate_messenger($messenger_name)
4199
-    {
4200
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4201
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4202
-
4203
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4204
-    }
4205
-
4206
-
4207
-    /**
4208
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4209
-     *
4210
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4211
-     * @param string $message_type_name The name of the message type being activated for the messenger
4212
-     * @return bool
4213
-     * @throws DomainException
4214
-     * @throws EE_Error
4215
-     * @throws InvalidArgumentException
4216
-     * @throws ReflectionException
4217
-     * @throws InvalidDataTypeException
4218
-     * @throws InvalidInterfaceException
4219
-     */
4220
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4221
-    {
4222
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4223
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4224
-
4225
-        // ensure is active
4226
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4227
-
4228
-        // set response for load
4229
-        if (
4230
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4231
-                $messenger_name,
4232
-                $message_type_name
4233
-            )
4234
-        ) {
4235
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4236
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4237
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4238
-            }
4239
-        }
4240
-
4241
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4242
-            $active_messenger,
4243
-            $message_type_to_activate
4244
-        );
4245
-    }
4246
-
4247
-
4248
-    /**
4249
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4250
-     *
4251
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4252
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4253
-     * @return bool
4254
-     * @throws DomainException
4255
-     * @throws EE_Error
4256
-     * @throws InvalidArgumentException
4257
-     * @throws ReflectionException
4258
-     * @throws InvalidDataTypeException
4259
-     * @throws InvalidInterfaceException
4260
-     */
4261
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4262
-    {
4263
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4264
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4265
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4266
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4267
-
4268
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4269
-            $active_messenger,
4270
-            $message_type_to_deactivate
4271
-        );
4272
-    }
4273
-
4274
-
4275
-    /**
4276
-     * This just initializes the defaults for activating messenger and message type responses.
4277
-     */
4278
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4279
-    {
4280
-        $this->_template_args['data']['active_mts'] = [];
4281
-        $this->_template_args['data']['mt_reload']  = [];
4282
-    }
4283
-
4284
-
4285
-    /**
4286
-     * Setup appropriate response for activating a messenger and/or message types
4287
-     *
4288
-     * @param EE_messenger         $messenger
4289
-     * @param EE_message_type|null $message_type
4290
-     * @return bool
4291
-     * @throws DomainException
4292
-     * @throws EE_Error
4293
-     * @throws InvalidArgumentException
4294
-     * @throws ReflectionException
4295
-     * @throws InvalidDataTypeException
4296
-     * @throws InvalidInterfaceException
4297
-     */
4298
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4299
-        $messenger,
4300
-        EE_Message_Type $message_type = null
4301
-    ) {
4302
-        // if $messenger isn't a valid messenger object then get out.
4303
-        if (! $messenger instanceof EE_Messenger) {
4304
-            EE_Error::add_error(
4305
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4306
-                __FILE__,
4307
-                __FUNCTION__,
4308
-                __LINE__
4309
-            );
4310
-            return false;
4311
-        }
4312
-        // activated
4313
-        if ($this->_template_args['data']['active_mts']) {
4314
-            EE_Error::overwrite_success();
4315
-            // activated a message type with the messenger
4316
-            if ($message_type instanceof EE_message_type) {
4317
-                EE_Error::add_success(
4318
-                    sprintf(
4319
-                        esc_html__(
4320
-                            '%s message type has been successfully activated with the %s messenger',
4321
-                            'event_espresso'
4322
-                        ),
4323
-                        ucwords($message_type->label['singular']),
4324
-                        ucwords($messenger->label['singular'])
4325
-                    )
4326
-                );
4327
-
4328
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4329
-                if ($message_type->name === 'invoice') {
4330
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4331
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4332
-                    if ($pm instanceof EE_Payment_Method) {
4333
-                        EE_Error::add_attention(
4334
-                            esc_html__(
4335
-                                '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.',
4336
-                                'event_espresso'
4337
-                            )
4338
-                        );
4339
-                    }
4340
-                }
4341
-                // just toggles the entire messenger
4342
-            } else {
4343
-                EE_Error::add_success(
4344
-                    sprintf(
4345
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4346
-                        ucwords($messenger->label['singular'])
4347
-                    )
4348
-                );
4349
-            }
4350
-
4351
-            return true;
4352
-
4353
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4354
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4355
-            // in which case we just give a success message for the messenger being successfully activated.
4356
-        } else {
4357
-            if (! $messenger->get_default_message_types()) {
4358
-                // messenger doesn't have any default message types so still a success.
4359
-                EE_Error::add_success(
4360
-                    sprintf(
4361
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4362
-                        ucwords($messenger->label['singular'])
4363
-                    )
4364
-                );
4365
-
4366
-                return true;
4367
-            } else {
4368
-                EE_Error::add_error(
4369
-                    $message_type instanceof EE_message_type
4370
-                    ? sprintf(
4371
-                        esc_html__(
4372
-                            '%s message type was not successfully activated with the %s messenger',
4373
-                            'event_espresso'
4374
-                        ),
4375
-                        ucwords($message_type->label['singular']),
4376
-                        ucwords($messenger->label['singular'])
4377
-                    )
4378
-                    : sprintf(
4379
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4380
-                        ucwords($messenger->label['singular'])
4381
-                    ),
4382
-                    __FILE__,
4383
-                    __FUNCTION__,
4384
-                    __LINE__
4385
-                );
4386
-
4387
-                return false;
4388
-            }
4389
-        }
4390
-    }
4391
-
4392
-
4393
-    /**
4394
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4395
-     *
4396
-     * @param EE_messenger         $messenger
4397
-     * @param EE_message_type|null $message_type
4398
-     * @return bool
4399
-     * @throws DomainException
4400
-     * @throws EE_Error
4401
-     * @throws InvalidArgumentException
4402
-     * @throws ReflectionException
4403
-     * @throws InvalidDataTypeException
4404
-     * @throws InvalidInterfaceException
4405
-     */
4406
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4407
-        $messenger,
4408
-        EE_message_type $message_type = null
4409
-    ) {
4410
-        EE_Error::overwrite_success();
4411
-
4412
-        // if $messenger isn't a valid messenger object then get out.
4413
-        if (! $messenger instanceof EE_Messenger) {
4414
-            EE_Error::add_error(
4415
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4416
-                __FILE__,
4417
-                __FUNCTION__,
4418
-                __LINE__
4419
-            );
4420
-
4421
-            return false;
4422
-        }
4423
-
4424
-        if ($message_type instanceof EE_message_type) {
4425
-            $message_type_name = $message_type->name;
4426
-            EE_Error::add_success(
4427
-                sprintf(
4428
-                    esc_html__(
4429
-                        '%s message type has been successfully deactivated for the %s messenger.',
4430
-                        'event_espresso'
4431
-                    ),
4432
-                    ucwords($message_type->label['singular']),
4433
-                    ucwords($messenger->label['singular'])
4434
-                )
4435
-            );
4436
-        } else {
4437
-            $message_type_name = '';
4438
-            EE_Error::add_success(
4439
-                sprintf(
4440
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4441
-                    ucwords($messenger->label['singular'])
4442
-                )
4443
-            );
4444
-        }
4445
-
4446
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4447
-        if (
4448
-            $messenger->name === 'html'
4449
-            && (
4450
-                is_null($message_type)
4451
-                || $message_type_name === 'invoice'
4452
-            )
4453
-        ) {
4454
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4455
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4456
-            if ($count_updated > 0) {
4457
-                $msg = $message_type_name === 'invoice'
4458
-                    ? esc_html__(
4459
-                        '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.',
4460
-                        'event_espresso'
4461
-                    )
4462
-                    : esc_html__(
4463
-                        '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.',
4464
-                        'event_espresso'
4465
-                    );
4466
-                EE_Error::add_attention($msg);
4467
-            }
4468
-        }
4469
-
4470
-        return true;
4471
-    }
4472
-
4473
-
4474
-    /**
4475
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4476
-     *
4477
-     * @throws DomainException
4478
-     * @throws EE_Error
4479
-     * @throws EE_Error
4480
-     */
4481
-    public function update_mt_form()
4482
-    {
4483
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4484
-            EE_Error::add_error(
4485
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4486
-                __FILE__,
4487
-                __FUNCTION__,
4488
-                __LINE__
4489
-            );
4490
-            $this->_return_json();
4491
-        }
4492
-
4493
-        $message_types = $this->get_installed_message_types();
4494
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4495
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4496
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4497
-
4498
-        $this->_template_args['success'] = true;
4499
-        $this->_template_args['content'] = $content;
4500
-        $this->_return_json();
4501
-    }
4502
-
4503
-
4504
-    /**
4505
-     * this handles saving the settings for a messenger or message type
4506
-     *
4507
-     * @throws EE_Error
4508
-     * @throws EE_Error
4509
-     */
4510
-    public function save_settings()
4511
-    {
4512
-        $type = $this->request->getRequestParam('type');
4513
-        if (! $type) {
4514
-            EE_Error::add_error(
4515
-                esc_html__(
4516
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4517
-                    'event_espresso'
4518
-                ),
4519
-                __FILE__,
4520
-                __FUNCTION__,
4521
-                __LINE__
4522
-            );
4523
-            $this->_template_args['error'] = true;
4524
-            $this->_return_json();
4525
-        }
4526
-
4527
-
4528
-        if ($type === 'messenger') {
4529
-            // this should be an array.
4530
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4531
-            $messenger = $settings['messenger'];
4532
-            // remove messenger and message_types from settings array
4533
-            unset($settings['messenger'], $settings['message_types']);
4534
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4535
-        } elseif ($type === 'message_type') {
4536
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4537
-            $messenger    = $settings['messenger'];
4538
-            $message_type = $settings['message_type'];
4539
-            // remove messenger and message_types from settings array
4540
-            unset($settings['messenger'], $settings['message_types']);
4541
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4542
-        }
4543
-
4544
-        // okay we should have the data all setup.  Now we just update!
4545
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4546
-
4547
-        if ($success) {
4548
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4549
-        } else {
4550
-            EE_Error::add_error(
4551
-                esc_html__('Settings did not get updated', 'event_espresso'),
4552
-                __FILE__,
4553
-                __FUNCTION__,
4554
-                __LINE__
4555
-            );
4556
-        }
4557
-
4558
-        $this->_template_args['success'] = $success;
4559
-        $this->_return_json();
4560
-    }
4561
-
4562
-
4563
-
4564
-
4565
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4566
-
4567
-
4568
-    /**
4569
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4570
-     * However, this does not send immediately, it just queues for sending.
4571
-     *
4572
-     * @throws EE_Error
4573
-     * @throws InvalidDataTypeException
4574
-     * @throws InvalidInterfaceException
4575
-     * @throws InvalidArgumentException
4576
-     * @throws ReflectionException
4577
-     * @since 4.9.0
4578
-     */
4579
-    protected function _generate_now()
4580
-    {
4581
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4582
-        $this->_redirect_after_action(false, '', '', [], true);
4583
-    }
4584
-
4585
-
4586
-    /**
4587
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4588
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4589
-     *
4590
-     * @throws EE_Error
4591
-     * @throws InvalidDataTypeException
4592
-     * @throws InvalidInterfaceException
4593
-     * @throws InvalidArgumentException
4594
-     * @throws ReflectionException
4595
-     * @since 4.9.0
4596
-     */
4597
-    protected function _generate_and_send_now()
4598
-    {
4599
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4600
-        $this->_redirect_after_action(false, '', '', [], true);
4601
-    }
4602
-
4603
-
4604
-    /**
4605
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4606
-     *
4607
-     * @throws EE_Error
4608
-     * @throws InvalidDataTypeException
4609
-     * @throws InvalidInterfaceException
4610
-     * @throws InvalidArgumentException
4611
-     * @throws ReflectionException
4612
-     * @since 4.9.0
4613
-     */
4614
-    protected function _queue_for_resending()
4615
-    {
4616
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4617
-        $this->_redirect_after_action(false, '', '', [], true);
4618
-    }
4619
-
4620
-
4621
-    /**
4622
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4623
-     *
4624
-     * @throws EE_Error
4625
-     * @throws InvalidDataTypeException
4626
-     * @throws InvalidInterfaceException
4627
-     * @throws InvalidArgumentException
4628
-     * @throws ReflectionException
4629
-     * @since 4.9.0
4630
-     */
4631
-    protected function _send_now()
4632
-    {
4633
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4634
-        $this->_redirect_after_action(false, '', '', [], true);
4635
-    }
4636
-
4637
-
4638
-    /**
4639
-     * Deletes EE_messages for IDs in the request.
4640
-     *
4641
-     * @throws EE_Error
4642
-     * @throws InvalidDataTypeException
4643
-     * @throws InvalidInterfaceException
4644
-     * @throws InvalidArgumentException
4645
-     * @since 4.9.0
4646
-     */
4647
-    protected function _delete_ee_messages()
4648
-    {
4649
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4650
-        $deleted_count = 0;
4651
-        foreach ($MSG_IDs as $MSG_ID) {
4652
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4653
-                $deleted_count++;
4654
-            }
4655
-        }
4656
-        if ($deleted_count) {
4657
-            EE_Error::add_success(
4658
-                esc_html(
4659
-                    _n(
4660
-                        'Message successfully deleted',
4661
-                        'Messages successfully deleted',
4662
-                        $deleted_count,
4663
-                        'event_espresso'
4664
-                    )
4665
-                )
4666
-            );
4667
-        } else {
4668
-            EE_Error::add_error(
4669
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4670
-                __FILE__,
4671
-                __FUNCTION__,
4672
-                __LINE__
4673
-            );
4674
-        }
4675
-        $this->_redirect_after_action(false, '', '', [], true);
4676
-    }
4677
-
4678
-
4679
-    /**
4680
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4681
-     *
4682
-     * @return array
4683
-     * @since 4.9.0
4684
-     */
4685
-    protected function _get_msg_ids_from_request()
4686
-    {
4687
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4688
-        if (empty($MSG_IDs)) {
4689
-            return [];
4690
-        }
4691
-        // if 'MSG_ID' was just a single ID (not an array)
4692
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4693
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4694
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4695
-            ? $MSG_IDs
4696
-            : array_keys($MSG_IDs);
4697
-    }
2706
+	}
2707
+
2708
+
2709
+	/**
2710
+	 * @param bool $new
2711
+	 * @throws EE_Error
2712
+	 * @throws ReflectionException
2713
+	 */
2714
+	protected function _insert_or_update_message_template($new = false)
2715
+	{
2716
+		$form_data    = $this->getMessageTemplateFormData();
2717
+		$GRP_ID       = $form_data['GRP_ID'];
2718
+		$messenger    = $form_data['MTP_messenger'];
2719
+		$message_type = $form_data['MTP_message_type'];
2720
+		$context      = $form_data['MTP_context'];
2721
+
2722
+		// if this is "new" then we need to generate the default contexts
2723
+		// for the selected messenger/message_type for user to edit.
2724
+		[$success, $query_args] = $new
2725
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
+
2728
+		$success     = $success ? 1 : 0;
2729
+		$action_desc = $new ? 'created' : 'updated';
2730
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
+
2733
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
+	}
2735
+
2736
+
2737
+	/**
2738
+	 * retrieve and sanitize form data
2739
+	 *
2740
+	 * @return array
2741
+	 * @since 4.10.29.p
2742
+	 */
2743
+	protected function getMessageTemplateFormData()
2744
+	{
2745
+		return [
2746
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
+		];
2756
+	}
2757
+
2758
+
2759
+	/**
2760
+	 * @param int    $GRP_ID
2761
+	 * @param string $messenger
2762
+	 * @param string $message_type
2763
+	 * @return array no return on AJAX requests
2764
+	 * @throws EE_Error
2765
+	 * @throws ReflectionException
2766
+	 * @since 4.10.29.p
2767
+	 */
2768
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
+	{
2770
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
+		$success       = ! empty($new_templates);
2772
+
2773
+		// we return things differently if doing ajax
2774
+		if ($this->request->isAjax()) {
2775
+			$this->_template_args['success'] = $success;
2776
+			$this->_template_args['error']   = ! $success;
2777
+			$this->_template_args['content'] = '';
2778
+			$this->_template_args['data']    = [
2779
+				'grpID'        => $new_templates['GRP_ID'],
2780
+				'templateName' => $new_templates['template_name'],
2781
+			];
2782
+			if ($success) {
2783
+				EE_Error::overwrite_success();
2784
+				EE_Error::add_success(
2785
+					esc_html__(
2786
+						'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.',
2787
+						'event_espresso'
2788
+					)
2789
+				);
2790
+			}
2791
+			$this->_return_json();
2792
+		}
2793
+		return [
2794
+			$success,
2795
+			// 'query_args'
2796
+			[
2797
+				'id'      => $new_templates['GRP_ID'],
2798
+				'context' => $new_templates['MTP_context'],
2799
+				'action'  => 'edit_message_template',
2800
+			],
2801
+		];
2802
+	}
2803
+
2804
+
2805
+	/**
2806
+	 * @param int    $GRP_ID
2807
+	 * @param string $messenger
2808
+	 * @param string $message_type
2809
+	 * @param string $context
2810
+	 * @param array  $form_data
2811
+	 * @return array
2812
+	 * @throws EE_Error
2813
+	 * @since 4.10.29.p
2814
+	 */
2815
+	private function updateExistingTemplates(
2816
+		$GRP_ID,
2817
+		$messenger,
2818
+		$message_type,
2819
+		$context,
2820
+		array $form_data
2821
+	) {
2822
+		$success         = false;
2823
+		$template_fields = $this->getTemplateFields();
2824
+		if ($template_fields) {
2825
+			// if field data is valid, then success will be true
2826
+			$success = $this->validateTemplateFields(
2827
+				$messenger,
2828
+				$message_type,
2829
+				$context,
2830
+				$template_fields
2831
+			);
2832
+			if ($success) {
2833
+				$field_data = [];
2834
+				foreach ($template_fields as $template_field => $content) {
2835
+					// combine top-level form data with content for this field
2836
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
+				}
2839
+				// we can use the last set_column_values for the MTPG update
2840
+				// (because its the same for all of these specific MTPs)
2841
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
+			}
2843
+		}
2844
+
2845
+		return [
2846
+			$success,
2847
+			// 'query_args'
2848
+			[
2849
+				'id'      => $GRP_ID,
2850
+				'context' => $context,
2851
+				'action'  => 'edit_message_template',
2852
+			],
2853
+		];
2854
+	}
2855
+
2856
+
2857
+	/**
2858
+	 * @return array
2859
+	 * @since 4.10.29.p
2860
+	 */
2861
+	private function getTemplateFields()
2862
+	{
2863
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
+		if (empty($template_fields)) {
2865
+			EE_Error::add_error(
2866
+				esc_html__(
2867
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
+					'event_espresso'
2869
+				),
2870
+				__FILE__,
2871
+				__FUNCTION__,
2872
+				__LINE__
2873
+			);
2874
+			return null;
2875
+		}
2876
+		// messages content is expected to be escaped
2877
+		return EEH_Array::addSlashesRecursively($template_fields);
2878
+	}
2879
+
2880
+
2881
+	/**
2882
+	 * @param string $messenger
2883
+	 * @param string $message_type
2884
+	 * @param string $context
2885
+	 * @param array  $template_fields
2886
+	 * @return bool
2887
+	 * @throws EE_Error
2888
+	 * @since   4.10.29.p
2889
+	 */
2890
+	private function validateTemplateFields(
2891
+		$messenger,
2892
+		$message_type,
2893
+		$context,
2894
+		array $template_fields
2895
+	) {
2896
+		// first validate all fields!
2897
+		// this filter allows client code to add its own validation to the template fields as well.
2898
+		// returning an empty array means everything passed validation.
2899
+		// errors in validation should be represented in an array with the following shape:
2900
+		// array(
2901
+		//   'fieldname' => array(
2902
+		//          'msg' => 'error message'
2903
+		//          'value' => 'value for field producing error'
2904
+		// )
2905
+		$custom_validation = (array) apply_filters(
2906
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
+			[],
2908
+			$template_fields,
2909
+			$context,
2910
+			$messenger,
2911
+			$message_type
2912
+		);
2913
+
2914
+		$system_validation = $this->getMtgModel()->validate(
2915
+			$template_fields,
2916
+			$context,
2917
+			$messenger,
2918
+			$message_type
2919
+		);
2920
+
2921
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
+		$validates         = array_merge($custom_validation, $system_validation);
2923
+
2924
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
+		//  WE need to make sure there is no actual error messages in validates.
2927
+		if (empty($validates)) {
2928
+			return true;
2929
+		}
2930
+
2931
+		// add the transient so when the form loads we know which fields to highlight
2932
+		$this->_add_transient('edit_message_template', $validates);
2933
+		// setup notices
2934
+		foreach ($validates as $error) {
2935
+			if (isset($error['msg'])) {
2936
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
+			}
2938
+		}
2939
+		return false;
2940
+	}
2941
+
2942
+
2943
+	/**
2944
+	 * @param array $field_data
2945
+	 * @param array $form_data
2946
+	 * @return array
2947
+	 * @since   4.10.29.p
2948
+	 */
2949
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
+	{
2951
+		return $form_data + [
2952
+				'MTP_ID'             => $field_data['MTP_ID'],
2953
+				'MTP_template_field' => $field_data['name'],
2954
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2956
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
+					: $field_data['content'],
2958
+			];
2959
+	}
2960
+
2961
+
2962
+	/**
2963
+	 * @param string $template_field
2964
+	 * @param array  $form_data
2965
+	 * @return bool
2966
+	 * @throws EE_Error
2967
+	 * @since 4.10.29.p
2968
+	 */
2969
+	private function updateMessageTemplates($template_field, array $form_data)
2970
+	{
2971
+		$MTP_ID                  = $form_data['MTP_ID'];
2972
+		$message_template_fields = [
2973
+			'GRP_ID'             => $form_data['GRP_ID'],
2974
+			'MTP_template_field' => $form_data['MTP_template_field'],
2975
+			'MTP_context'        => $form_data['MTP_context'],
2976
+			'MTP_content'        => $form_data['MTP_content'],
2977
+		];
2978
+
2979
+		$hasMtpID = ! empty($MTP_ID);
2980
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2981
+		// this has already been through the template field validator and sanitized, so it will be
2982
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
+		// message template field in a messenger/message type and existing users don't have the
2984
+		// default setup for it.
2985
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
+		$updated = $hasMtpID
2987
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
+			: $this->getMtpModel()->insert($message_template_fields);
2989
+
2990
+		$insert_failed = ! $hasMtpID && ! $updated;
2991
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
+		$update_failed = $hasMtpID && $updated === false;
2994
+
2995
+		if ($insert_failed || $update_failed) {
2996
+			EE_Error::add_error(
2997
+				sprintf(
2998
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
+					$template_field
3000
+				),
3001
+				__FILE__,
3002
+				__FUNCTION__,
3003
+				__LINE__
3004
+			);
3005
+			return false;
3006
+		}
3007
+		return true;
3008
+	}
3009
+
3010
+
3011
+	/**
3012
+	 * @param array $form_data
3013
+	 * @return bool
3014
+	 * @throws EE_Error
3015
+	 * @since 4.10.29.p
3016
+	 */
3017
+	private function updateMessageTemplateGroup(array $form_data)
3018
+	{
3019
+		$GRP_ID  = $form_data['GRP_ID'];
3020
+		$updated = $this->getMtgModel()->update(
3021
+		// fields and values
3022
+			[
3023
+				'MTP_user_id'      => $form_data['MTP_user_id'],
3024
+				'MTP_messenger'    => $form_data['MTP_messenger'],
3025
+				'MTP_message_type' => $form_data['MTP_message_type'],
3026
+				'MTP_is_global'    => $form_data['MTP_is_global'],
3027
+				'MTP_is_override'  => $form_data['MTP_is_override'],
3028
+				'MTP_deleted'      => $form_data['MTP_deleted'],
3029
+				'MTP_is_active'    => $form_data['MTP_is_active'],
3030
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
+				'MTP_description'  => $this->request->getRequestParam(
3032
+					'ee_msg_non_global_fields[MTP_description]',
3033
+					''
3034
+				),
3035
+			],
3036
+			// where
3037
+			[['GRP_ID' => $GRP_ID]]
3038
+		);
3039
+
3040
+		if ($updated === false) {
3041
+			EE_Error::add_error(
3042
+				sprintf(
3043
+					esc_html__(
3044
+						'The Message Template Group (%d) was NOT updated for some reason',
3045
+						'event_espresso'
3046
+					),
3047
+					$form_data['GRP_ID']
3048
+				),
3049
+				__FILE__,
3050
+				__FUNCTION__,
3051
+				__LINE__
3052
+			);
3053
+			return false;
3054
+		}
3055
+		// k now we need to ensure the template_pack and template_variation fields are set.
3056
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
+
3059
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3061
+			$message_template_group->set_template_pack_name($template_pack);
3062
+			$message_template_group->set_template_pack_variation($template_variation);
3063
+		}
3064
+		return true;
3065
+	}
3066
+
3067
+
3068
+	/**
3069
+	 * recursively runs wp_kses() on message template content in a model safe manner
3070
+	 *
3071
+	 * @param array|string $content
3072
+	 * @return array|string
3073
+	 * @since   4.10.29.p
3074
+	 */
3075
+	private function sanitizeMessageTemplateContent($content)
3076
+	{
3077
+		if (is_array($content)) {
3078
+			foreach ($content as $key => $value) {
3079
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
+			}
3081
+			return $content;
3082
+		}
3083
+		// remove slashes so wp_kses() works properly
3084
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3085
+		// so attributes using single quotes always appear invalid.
3086
+		$content = stripslashes($content);
3087
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3088
+		// But currently the models expect slashed data, so after wp_kses()
3089
+		// runs we need to re-slash the data. Sheesh.
3090
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
+		return addslashes($content);
3092
+	}
3093
+
3094
+
3095
+	/**
3096
+	 * @param string $messenger
3097
+	 * @param string $message_type
3098
+	 * @param string $context
3099
+	 * @return string
3100
+	 * @since 4.10.29.p
3101
+	 */
3102
+	private function generateUpdateDescription($messenger, $message_type, $context)
3103
+	{
3104
+		// need the message type and messenger objects to be able to use the labels for the notices
3105
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
+		$messenger_label  = $messenger_object instanceof EE_messenger
3107
+			? ucwords($messenger_object->label['singular'])
3108
+			: '';
3109
+
3110
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
+		$message_type_label  = $message_type_object instanceof EE_message_type
3112
+			? ucwords($message_type_object->label['singular'])
3113
+			: '';
3114
+
3115
+		$context   = ucwords(str_replace('_', ' ', $context));
3116
+		$item_desc = $messenger_label && $message_type_label
3117
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
+			: '';
3119
+		$item_desc .= 'Message Template';
3120
+		return $item_desc;
3121
+	}
3122
+
3123
+
3124
+	/**
3125
+	 * @param string $messenger
3126
+	 * @param string $message_type
3127
+	 * @param string $context
3128
+	 * @return bool
3129
+	 * @throws EE_Error
3130
+	 * @throws ReflectionException
3131
+	 * @since 4.10.29.p
3132
+	 */
3133
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
+	{
3135
+		// was a test send triggered?
3136
+		if ($this->request->requestParamIsSet('test_button')) {
3137
+			EE_Error::overwrite_success();
3138
+			$this->_do_test_send($context, $messenger, $message_type);
3139
+			return true;
3140
+		}
3141
+		return false;
3142
+	}
3143
+
3144
+
3145
+	/**
3146
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
+	 *
3148
+	 * @param string $context      what context being tested
3149
+	 * @param string $messenger    messenger being tested
3150
+	 * @param string $message_type message type being tested
3151
+	 * @throws EE_Error
3152
+	 * @throws InvalidArgumentException
3153
+	 * @throws InvalidDataTypeException
3154
+	 * @throws InvalidInterfaceException
3155
+	 * @throws ReflectionException
3156
+	 */
3157
+	protected function _do_test_send($context, $messenger, $message_type)
3158
+	{
3159
+		// set things up for preview
3160
+		$this->request->setRequestParam('messenger', $messenger);
3161
+		$this->request->setRequestParam('message_type', $message_type);
3162
+		$this->request->setRequestParam('context', $context);
3163
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
+
3166
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
+
3169
+		// let's save any existing fields that might be required by the messenger
3170
+		if (
3171
+			! empty($test_settings_fld)
3172
+			&& $active_messenger instanceof EE_messenger
3173
+			&& apply_filters(
3174
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
+				true,
3176
+				$test_settings_fld,
3177
+				$active_messenger
3178
+			)
3179
+		) {
3180
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3181
+		}
3182
+
3183
+		/**
3184
+		 * Use filter to add additional controls on whether message can send or not
3185
+		 */
3186
+		if (
3187
+			apply_filters(
3188
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
+				true,
3190
+				$context,
3191
+				$this->request->requestParams(),
3192
+				$messenger,
3193
+				$message_type
3194
+			)
3195
+		) {
3196
+			if (EEM_Event::instance()->count() > 0) {
3197
+				$success = $this->_preview_message(true);
3198
+				if ($success) {
3199
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
+				} else {
3201
+					EE_Error::add_error(
3202
+						esc_html__('The test message was not sent', 'event_espresso'),
3203
+						__FILE__,
3204
+						__FUNCTION__,
3205
+						__LINE__
3206
+					);
3207
+				}
3208
+			} else {
3209
+				$this->noEventsErrorMessage(true);
3210
+			}
3211
+		}
3212
+	}
3213
+
3214
+
3215
+	/**
3216
+	 * _generate_new_templates
3217
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
+	 * for the event.
3220
+	 *
3221
+	 *
3222
+	 * @param string $messenger      the messenger we are generating templates for
3223
+	 * @param array  $message_types  array of message types that the templates are generated for.
3224
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
+	 *                               indicate the message_template_group being used as the base.
3226
+	 *
3227
+	 * @param bool   $global
3228
+	 *
3229
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
+	 *                               encountering problems.
3231
+	 * @throws EE_Error
3232
+	 * @throws ReflectionException
3233
+	 */
3234
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
+	{
3236
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
+		// just don't generate any templates.
3238
+		if (empty($message_types)) {
3239
+			return [];
3240
+		}
3241
+
3242
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
+		return $templates[0];
3244
+	}
3245
+
3246
+
3247
+	/**
3248
+	 * [_trash_or_restore_message_template]
3249
+	 *
3250
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
+	 *                        an individual context (FALSE).
3253
+	 * @return void
3254
+	 * @throws EE_Error
3255
+	 * @throws InvalidArgumentException
3256
+	 * @throws InvalidDataTypeException
3257
+	 * @throws InvalidInterfaceException
3258
+	 */
3259
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
+	{
3261
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
+
3263
+		$success = 1;
3264
+
3265
+		// incoming GRP_IDs
3266
+		if ($all) {
3267
+			// Checkboxes
3268
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
+			if (! empty($checkboxes)) {
3270
+				// if array has more than one element then success message should be plural.
3271
+				// todo: what about nonce?
3272
+				$success = count($checkboxes) > 1 ? 2 : 1;
3273
+
3274
+				// cycle through checkboxes
3275
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3276
+					$trashed_or_restored = $trash
3277
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
+					if (! $trashed_or_restored) {
3280
+						$success = 0;
3281
+					}
3282
+				}
3283
+			} else {
3284
+				// grab single GRP_ID and handle
3285
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
+				if (! empty($GRP_ID)) {
3287
+					$trashed_or_restored = $trash
3288
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
+					if (! $trashed_or_restored) {
3291
+						$success = 0;
3292
+					}
3293
+				} else {
3294
+					$success = 0;
3295
+				}
3296
+			}
3297
+		}
3298
+
3299
+		$action_desc = $trash
3300
+			? esc_html__('moved to the trash', 'event_espresso')
3301
+			: esc_html__('restored', 'event_espresso');
3302
+
3303
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
+
3306
+		$item_desc = $all ? _n(
3307
+			'Message Template Group',
3308
+			'Message Template Groups',
3309
+			$success,
3310
+			'event_espresso'
3311
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
+
3313
+		$item_desc = $template_switch
3314
+			? _n('template', 'templates', $success, 'event_espresso')
3315
+			: $item_desc;
3316
+
3317
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
+	}
3319
+
3320
+
3321
+	/**
3322
+	 * [_delete_message_template]
3323
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
+	 *
3325
+	 * @return void
3326
+	 * @throws EE_Error
3327
+	 * @throws InvalidArgumentException
3328
+	 * @throws InvalidDataTypeException
3329
+	 * @throws InvalidInterfaceException
3330
+	 * @throws ReflectionException
3331
+	 */
3332
+	protected function _delete_message_template()
3333
+	{
3334
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
+
3336
+		// checkboxes
3337
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
+		if (! empty($checkboxes)) {
3339
+			// if array has more than one element then success message should be plural
3340
+			$success = count($checkboxes) > 1 ? 2 : 1;
3341
+
3342
+			// cycle through bulk action checkboxes
3343
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3344
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
+			}
3346
+		} else {
3347
+			// grab single grp_id and delete
3348
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3350
+		}
3351
+
3352
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
+	}
3354
+
3355
+
3356
+	/**
3357
+	 * helper for permanently deleting a mtP group and all related message_templates
3358
+	 *
3359
+	 * @param int  $GRP_ID        The group being deleted
3360
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3361
+	 * @return bool boolean to indicate the success of the deletes or not.
3362
+	 * @throws EE_Error
3363
+	 * @throws InvalidArgumentException
3364
+	 * @throws InvalidDataTypeException
3365
+	 * @throws InvalidInterfaceException
3366
+	 * @throws ReflectionException
3367
+	 * @throws ReflectionException
3368
+	 */
3369
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
+	{
3371
+		$success = true;
3372
+		// first let's GET this group
3373
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
+		// then delete permanently all the related Message Templates
3375
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3376
+
3377
+		if ($deleted === 0) {
3378
+			$success = false;
3379
+		}
3380
+
3381
+		// now delete permanently this particular group
3382
+
3383
+		if ($include_group && ! $MTG->delete_permanently()) {
3384
+			$success = false;
3385
+		}
3386
+
3387
+		return $success;
3388
+	}
3389
+
3390
+
3391
+	/**
3392
+	 *    _learn_more_about_message_templates_link
3393
+	 *
3394
+	 * @access protected
3395
+	 * @return string
3396
+	 */
3397
+	protected function _learn_more_about_message_templates_link()
3398
+	{
3399
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3401
+			   . '</a>';
3402
+	}
3403
+
3404
+
3405
+	/**
3406
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
+	 * ajax and other routes.
3408
+	 *
3409
+	 * @return void
3410
+	 * @throws DomainException
3411
+	 * @throws EE_Error
3412
+	 */
3413
+	protected function _settings()
3414
+	{
3415
+		$this->_set_m_mt_settings();
3416
+
3417
+		// let's setup the messenger tabs
3418
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
+			$this->_m_mt_settings['messenger_tabs'],
3420
+			'messenger_links',
3421
+			'|',
3422
+			$this->request->getRequestParam('selected_messenger', 'email')
3423
+		);
3424
+
3425
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
+
3428
+		$this->display_admin_page_with_sidebar();
3429
+	}
3430
+
3431
+
3432
+	/**
3433
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
+	 *
3435
+	 * @access protected
3436
+	 * @return void
3437
+	 * @throws DomainException
3438
+	 */
3439
+	protected function _set_m_mt_settings()
3440
+	{
3441
+		// first if this is already set then lets get out no need to regenerate data.
3442
+		if (! empty($this->_m_mt_settings)) {
3443
+			return;
3444
+		}
3445
+
3446
+		// get all installed messengers and message_types
3447
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3448
+		$message_types = $this->_message_resource_manager->installed_message_types();
3449
+
3450
+
3451
+		// assemble the array for the _tab_text_links helper
3452
+
3453
+		foreach ($messengers as $messenger) {
3454
+			$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3455
+			$class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3456
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3457
+				'label' => ucwords($messenger->label['singular']),
3458
+				'class' => $active ? "{$class} messenger-active" : $class,
3459
+				'href'  => $messenger->name,
3460
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
+				'slug'  => $messenger->name,
3462
+				'obj'   => $messenger,
3463
+				'icon' => $active
3464
+					? '<span class="dashicons dashicons-yes-alt"></span>'
3465
+					: '<span class="dashicons dashicons-remove"></span>',
3466
+			];
3467
+
3468
+
3469
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3470
+
3471
+			foreach ($message_types as $message_type) {
3472
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3473
+				// it shouldn't show in either the inactive OR active metabox.
3474
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3475
+					continue;
3476
+				}
3477
+
3478
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3479
+					$messenger->name,
3480
+					$message_type->name
3481
+				)
3482
+					? 'active'
3483
+					: 'inactive';
3484
+
3485
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3486
+					'label'    => ucwords($message_type->label['singular']),
3487
+					'class'    => 'message-type-' . $a_or_i,
3488
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3489
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3490
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3491
+					'title'    => $a_or_i === 'active'
3492
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3493
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3494
+					'content'  => $a_or_i === 'active'
3495
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3496
+						: $this->_message_type_settings_content($message_type, $messenger),
3497
+					'slug'     => $message_type->name,
3498
+					'active'   => $a_or_i === 'active',
3499
+					'obj'      => $message_type,
3500
+				];
3501
+			}
3502
+		}
3503
+	}
3504
+
3505
+
3506
+	/**
3507
+	 * This just prepares the content for the message type settings
3508
+	 *
3509
+	 * @param EE_message_type $message_type The message type object
3510
+	 * @param EE_messenger    $messenger    The messenger object
3511
+	 * @param boolean         $active       Whether the message type is active or not
3512
+	 * @return string html output for the content
3513
+	 * @throws DomainException
3514
+	 */
3515
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3516
+	{
3517
+		// get message type fields
3518
+		$fields                                         = $message_type->get_admin_settings_fields();
3519
+		$settings_template_args['template_form_fields'] = '';
3520
+
3521
+		if (! empty($fields) && $active) {
3522
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3523
+			foreach ($fields as $fldname => $fldprops) {
3524
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3525
+				$template_form_field[ $field_id ] = [
3526
+					'name'       => 'message_type_settings[' . $fldname . ']',
3527
+					'label'      => $fldprops['label'],
3528
+					'input'      => $fldprops['field_type'],
3529
+					'type'       => $fldprops['value_type'],
3530
+					'required'   => $fldprops['required'],
3531
+					'validation' => $fldprops['validation'],
3532
+					'value'      => isset($existing_settings[ $fldname ])
3533
+						? $existing_settings[ $fldname ]
3534
+						: $fldprops['default'],
3535
+					'options'    => isset($fldprops['options'])
3536
+						? $fldprops['options']
3537
+						: [],
3538
+					'default'    => isset($existing_settings[ $fldname ])
3539
+						? $existing_settings[ $fldname ]
3540
+						: $fldprops['default'],
3541
+					'css_class'  => 'no-drag',
3542
+					'format'     => $fldprops['format'],
3543
+				];
3544
+			}
3545
+
3546
+
3547
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3548
+				? $this->_generate_admin_form_fields(
3549
+					$template_form_field,
3550
+					'string',
3551
+					'ee_mt_activate_form'
3552
+				)
3553
+				: '';
3554
+		}
3555
+
3556
+		$settings_template_args['description'] = $message_type->description;
3557
+		// we also need some hidden fields
3558
+		$hidden_fields = [
3559
+			'message_type_settings[messenger]' . $message_type->name    => [
3560
+				'type'  => 'hidden',
3561
+				'value' => $messenger->name,
3562
+			],
3563
+			'message_type_settings[message_type]' . $message_type->name => [
3564
+				'type'  => 'hidden',
3565
+				'value' => $message_type->name,
3566
+			],
3567
+			'type' . $message_type->name                                => [
3568
+				'type'  => 'hidden',
3569
+				'value' => 'message_type',
3570
+			],
3571
+		];
3572
+
3573
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3574
+			$hidden_fields,
3575
+			'array'
3576
+		);
3577
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3578
+			? ' hidden'
3579
+			: '';
3580
+
3581
+
3582
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3583
+		return EEH_Template::display_template($template, $settings_template_args, true);
3584
+	}
3585
+
3586
+
3587
+	/**
3588
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3589
+	 *
3590
+	 * @access protected
3591
+	 * @return void
3592
+	 * @throws DomainException
3593
+	 */
3594
+	protected function _messages_settings_metaboxes()
3595
+	{
3596
+		$this->_set_m_mt_settings();
3597
+		$m_boxes         = $mt_boxes = [];
3598
+		$m_template_args = $mt_template_args = [];
3599
+
3600
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3601
+
3602
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3603
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3604
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3605
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3606
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3607
+
3608
+				// messenger meta boxes
3609
+				$active         = $selected_messenger === $messenger;
3610
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3611
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3612
+					: '';
3613
+
3614
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3615
+					esc_html__('%s Settings', 'event_espresso'),
3616
+					$tab_array['label']
3617
+				);
3618
+
3619
+				$m_template_args[ $messenger . '_a_box' ] = [
3620
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3621
+					'inactive_message_types' => isset(
3622
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3623
+					)
3624
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3625
+						: '',
3626
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3627
+					'hidden'                 => $active ? '' : ' hidden',
3628
+					'hide_on_message'        => $hide_on_message,
3629
+					'messenger'              => $messenger,
3630
+					'active'                 => $active,
3631
+				];
3632
+
3633
+				// message type meta boxes
3634
+				// (which is really just the inactive container for each messenger
3635
+				// showing inactive message types for that messenger)
3636
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3637
+				$mt_template_args[ $messenger . '_i_box' ] = [
3638
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3639
+					'inactive_message_types' => isset(
3640
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3641
+					)
3642
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3643
+						: '',
3644
+					'hidden'                 => $active ? '' : ' hidden',
3645
+					'hide_on_message'        => $hide_on_message,
3646
+					'hide_off_message'       => $hide_off_message,
3647
+					'messenger'              => $messenger,
3648
+					'active'                 => $active,
3649
+				];
3650
+			}
3651
+		}
3652
+
3653
+
3654
+		// register messenger metaboxes
3655
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3656
+		foreach ($m_boxes as $box => $label) {
3657
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3658
+			$msgr          = str_replace('_a_box', '', $box);
3659
+			$this->addMetaBox(
3660
+				'espresso_' . $msgr . '_settings',
3661
+				$label,
3662
+				function ($post, $metabox) {
3663
+					EEH_Template::display_template(
3664
+						$metabox['args']['template_path'],
3665
+						$metabox['args']['template_args']
3666
+					);
3667
+				},
3668
+				$this->_current_screen->id,
3669
+				'normal',
3670
+				'high',
3671
+				$callback_args
3672
+			);
3673
+		}
3674
+
3675
+		// register message type metaboxes
3676
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3677
+		foreach ($mt_boxes as $box => $label) {
3678
+			$callback_args = [
3679
+				'template_path' => $mt_template_path,
3680
+				'template_args' => $mt_template_args[ $box ],
3681
+			];
3682
+			$mt            = str_replace('_i_box', '', $box);
3683
+			$this->addMetaBox(
3684
+				'espresso_' . $mt . '_inactive_mts',
3685
+				$label,
3686
+				function ($post, $metabox) {
3687
+					EEH_Template::display_template(
3688
+						$metabox['args']['template_path'],
3689
+						$metabox['args']['template_args']
3690
+					);
3691
+				},
3692
+				$this->_current_screen->id,
3693
+				'side',
3694
+				'high',
3695
+				$callback_args
3696
+			);
3697
+		}
3698
+
3699
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3700
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3701
+		if (is_main_site()) {
3702
+			$this->addMetaBox(
3703
+				'espresso_global_message_settings',
3704
+				esc_html__('Global Message Settings', 'event_espresso'),
3705
+				[$this, 'global_messages_settings_metabox_content'],
3706
+				$this->_current_screen->id,
3707
+				'normal',
3708
+				'low',
3709
+				[]
3710
+			);
3711
+		}
3712
+	}
3713
+
3714
+
3715
+	/**
3716
+	 *  This generates the content for the global messages settings metabox.
3717
+	 *
3718
+	 * @return void
3719
+	 * @throws EE_Error
3720
+	 * @throws InvalidArgumentException
3721
+	 * @throws ReflectionException
3722
+	 * @throws InvalidDataTypeException
3723
+	 * @throws InvalidInterfaceException
3724
+	 */
3725
+	public function global_messages_settings_metabox_content()
3726
+	{
3727
+		$form = $this->_generate_global_settings_form();
3728
+		echo wp_kses(
3729
+			$form->form_open(
3730
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3731
+				'POST'
3732
+			),
3733
+			AllowedTags::getWithFormTags()
3734
+		);
3735
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3736
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3737
+	}
3738
+
3739
+
3740
+	/**
3741
+	 * This generates and returns the form object for the global messages settings.
3742
+	 *
3743
+	 * @return EE_Form_Section_Proper
3744
+	 * @throws EE_Error
3745
+	 * @throws InvalidArgumentException
3746
+	 * @throws ReflectionException
3747
+	 * @throws InvalidDataTypeException
3748
+	 * @throws InvalidInterfaceException
3749
+	 */
3750
+	protected function _generate_global_settings_form()
3751
+	{
3752
+		/** @var EE_Network_Core_Config $network_config */
3753
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3754
+
3755
+		return new EE_Form_Section_Proper(
3756
+			[
3757
+				'name'            => 'global_messages_settings',
3758
+				'html_id'         => 'global_messages_settings',
3759
+				'html_class'      => 'form-table',
3760
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3761
+				'subsections'     => apply_filters(
3762
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3763
+					[
3764
+						'do_messages_on_same_request' => new EE_Select_Input(
3765
+							[
3766
+								true  => esc_html__('On the same request', 'event_espresso'),
3767
+								false => esc_html__('On a separate request', 'event_espresso'),
3768
+							],
3769
+							[
3770
+								'default'         => $network_config->do_messages_on_same_request,
3771
+								'html_label_text' => esc_html__(
3772
+									'Generate and send all messages:',
3773
+									'event_espresso'
3774
+								),
3775
+								'html_help_text'  => esc_html__(
3776
+									'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.',
3777
+									'event_espresso'
3778
+								),
3779
+							]
3780
+						),
3781
+						'delete_threshold'            => new EE_Select_Input(
3782
+							[
3783
+								0  => esc_html__('Forever', 'event_espresso'),
3784
+								3  => esc_html__('3 Months', 'event_espresso'),
3785
+								6  => esc_html__('6 Months', 'event_espresso'),
3786
+								9  => esc_html__('9 Months', 'event_espresso'),
3787
+								12 => esc_html__('12 Months', 'event_espresso'),
3788
+								24 => esc_html__('24 Months', 'event_espresso'),
3789
+								36 => esc_html__('36 Months', 'event_espresso'),
3790
+							],
3791
+							[
3792
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3793
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3794
+								'html_help_text'  => esc_html__(
3795
+									'You can control how long a record of processed messages is kept via this option.',
3796
+									'event_espresso'
3797
+								),
3798
+							]
3799
+						),
3800
+						'update_settings'             => new EE_Submit_Input(
3801
+							[
3802
+								'default'         => esc_html__('Update', 'event_espresso'),
3803
+								'html_label_text' => '',
3804
+							]
3805
+						),
3806
+					]
3807
+				),
3808
+			]
3809
+		);
3810
+	}
3811
+
3812
+
3813
+	/**
3814
+	 * This handles updating the global settings set on the admin page.
3815
+	 *
3816
+	 * @throws EE_Error
3817
+	 * @throws InvalidDataTypeException
3818
+	 * @throws InvalidInterfaceException
3819
+	 * @throws InvalidArgumentException
3820
+	 * @throws ReflectionException
3821
+	 */
3822
+	protected function _update_global_settings()
3823
+	{
3824
+		/** @var EE_Network_Core_Config $network_config */
3825
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3826
+		$messages_config = EE_Registry::instance()->CFG->messages;
3827
+		$form            = $this->_generate_global_settings_form();
3828
+		if ($form->was_submitted()) {
3829
+			$form->receive_form_submission();
3830
+			if ($form->is_valid()) {
3831
+				$valid_data = $form->valid_data();
3832
+				foreach ($valid_data as $property => $value) {
3833
+					$setter = 'set_' . $property;
3834
+					if (method_exists($network_config, $setter)) {
3835
+						$network_config->{$setter}($value);
3836
+					} elseif (
3837
+						property_exists($network_config, $property)
3838
+						&& $network_config->{$property} !== $value
3839
+					) {
3840
+						$network_config->{$property} = $value;
3841
+					} elseif (
3842
+						property_exists($messages_config, $property)
3843
+						&& $messages_config->{$property} !== $value
3844
+					) {
3845
+						$messages_config->{$property} = $value;
3846
+					}
3847
+				}
3848
+				// only update if the form submission was valid!
3849
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3850
+				EE_Registry::instance()->CFG->update_espresso_config();
3851
+				EE_Error::overwrite_success();
3852
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3853
+			}
3854
+		}
3855
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3856
+	}
3857
+
3858
+
3859
+	/**
3860
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3861
+	 *
3862
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3863
+	 * @return string html formatted tabs
3864
+	 * @throws DomainException
3865
+	 */
3866
+	protected function _get_mt_tabs($tab_array)
3867
+	{
3868
+		$tab_array = (array) $tab_array;
3869
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3870
+		$tabs      = '';
3871
+
3872
+		foreach ($tab_array as $tab) {
3873
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3874
+		}
3875
+
3876
+		return $tabs;
3877
+	}
3878
+
3879
+
3880
+	/**
3881
+	 * This prepares the content of the messenger meta box admin settings
3882
+	 *
3883
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3884
+	 * @return string html formatted content
3885
+	 * @throws DomainException
3886
+	 */
3887
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3888
+	{
3889
+
3890
+		$fields                                         = $messenger->get_admin_settings_fields();
3891
+		$settings_template_args['template_form_fields'] = '';
3892
+
3893
+		// is $messenger active?
3894
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3895
+
3896
+
3897
+		if (! empty($fields)) {
3898
+			$existing_settings = $messenger->get_existing_admin_settings();
3899
+
3900
+			foreach ($fields as $fldname => $fldprops) {
3901
+				$field_id                         = $messenger->name . '-' . $fldname;
3902
+				$template_form_field[ $field_id ] = [
3903
+					'name'       => 'messenger_settings[' . $field_id . ']',
3904
+					'label'      => $fldprops['label'],
3905
+					'input'      => $fldprops['field_type'],
3906
+					'type'       => $fldprops['value_type'],
3907
+					'required'   => $fldprops['required'],
3908
+					'validation' => $fldprops['validation'],
3909
+					'value'      => isset($existing_settings[ $field_id ])
3910
+						? $existing_settings[ $field_id ]
3911
+						: $fldprops['default'],
3912
+					'css_class'  => '',
3913
+					'format'     => $fldprops['format'],
3914
+				];
3915
+			}
3916
+
3917
+
3918
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3919
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3920
+				: '';
3921
+		}
3922
+
3923
+		// we also need some hidden fields
3924
+		$settings_template_args['hidden_fields'] = [
3925
+			'messenger_settings[messenger]' . $messenger->name => [
3926
+				'type'  => 'hidden',
3927
+				'value' => $messenger->name,
3928
+			],
3929
+			'type' . $messenger->name                          => [
3930
+				'type'  => 'hidden',
3931
+				'value' => 'messenger',
3932
+			],
3933
+		];
3934
+
3935
+		// make sure any active message types that are existing are included in the hidden fields
3936
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3937
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3938
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3939
+					'type'  => 'hidden',
3940
+					'value' => $mt,
3941
+				];
3942
+			}
3943
+		}
3944
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3945
+			$settings_template_args['hidden_fields'],
3946
+			'array'
3947
+		);
3948
+		$active                                  =
3949
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3950
+
3951
+		$settings_template_args['messenger']           = $messenger->name;
3952
+		$settings_template_args['description']         = $messenger->description;
3953
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3954
+
3955
+
3956
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3957
+			$messenger->name
3958
+		)
3959
+			? $settings_template_args['show_hide_edit_form']
3960
+			: ' hidden';
3961
+
3962
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3963
+			? ' hidden'
3964
+			: $settings_template_args['show_hide_edit_form'];
3965
+
3966
+
3967
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3968
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3969
+		$settings_template_args['on_off_status'] = $active;
3970
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3971
+		return EEH_Template::display_template(
3972
+			$template,
3973
+			$settings_template_args,
3974
+			true
3975
+		);
3976
+	}
3977
+
3978
+
3979
+	/**
3980
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3981
+	 *
3982
+	 * @throws DomainException
3983
+	 * @throws EE_Error
3984
+	 * @throws InvalidDataTypeException
3985
+	 * @throws InvalidInterfaceException
3986
+	 * @throws InvalidArgumentException
3987
+	 * @throws ReflectionException
3988
+	 */
3989
+	public function activate_messenger_toggle()
3990
+	{
3991
+		$success = true;
3992
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3993
+		// let's check that we have required data
3994
+
3995
+		if (! $this->_active_messenger_name) {
3996
+			EE_Error::add_error(
3997
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3998
+				__FILE__,
3999
+				__FUNCTION__,
4000
+				__LINE__
4001
+			);
4002
+			$success = false;
4003
+		}
4004
+
4005
+		// do a nonce check here since we're not arriving via a normal route
4006
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4007
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4008
+
4009
+		$this->_verify_nonce($nonce, $nonce_ref);
4010
+
4011
+
4012
+		$status = $this->request->getRequestParam('status');
4013
+		if (! $status) {
4014
+			EE_Error::add_error(
4015
+				esc_html__(
4016
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4017
+					'event_espresso'
4018
+				),
4019
+				__FILE__,
4020
+				__FUNCTION__,
4021
+				__LINE__
4022
+			);
4023
+			$success = false;
4024
+		}
4025
+
4026
+		// do check to verify we have a valid status.
4027
+		if ($status !== 'off' && $status !== 'on') {
4028
+			EE_Error::add_error(
4029
+				sprintf(
4030
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4031
+					$status
4032
+				),
4033
+				__FILE__,
4034
+				__FUNCTION__,
4035
+				__LINE__
4036
+			);
4037
+			$success = false;
4038
+		}
4039
+
4040
+		if ($success) {
4041
+			// made it here?  Stop dawdling then!!
4042
+			$success = $status === 'off'
4043
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4044
+				: $this->_activate_messenger($this->_active_messenger_name);
4045
+		}
4046
+
4047
+		$this->_template_args['success'] = $success;
4048
+
4049
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4050
+		$this->_return_json();
4051
+	}
4052
+
4053
+
4054
+	/**
4055
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4056
+	 *
4057
+	 * @throws DomainException
4058
+	 * @throws EE_Error
4059
+	 * @throws ReflectionException
4060
+	 * @throws InvalidDataTypeException
4061
+	 * @throws InvalidInterfaceException
4062
+	 * @throws InvalidArgumentException
4063
+	 */
4064
+	public function activate_mt_toggle()
4065
+	{
4066
+		$success = true;
4067
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4068
+
4069
+		// let's make sure we have the necessary data
4070
+		if (! $this->_active_message_type_name) {
4071
+			EE_Error::add_error(
4072
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4073
+				__FILE__,
4074
+				__FUNCTION__,
4075
+				__LINE__
4076
+			);
4077
+			$success = false;
4078
+		}
4079
+
4080
+		if (! $this->_active_messenger_name) {
4081
+			EE_Error::add_error(
4082
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4083
+				__FILE__,
4084
+				__FUNCTION__,
4085
+				__LINE__
4086
+			);
4087
+			$success = false;
4088
+		}
4089
+
4090
+		$status = $this->request->getRequestParam('status');
4091
+		if (! $status) {
4092
+			EE_Error::add_error(
4093
+				esc_html__(
4094
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4095
+					'event_espresso'
4096
+				),
4097
+				__FILE__,
4098
+				__FUNCTION__,
4099
+				__LINE__
4100
+			);
4101
+			$success = false;
4102
+		}
4103
+
4104
+
4105
+		// do check to verify we have a valid status.
4106
+		if ($status !== 'activate' && $status !== 'deactivate') {
4107
+			EE_Error::add_error(
4108
+				sprintf(
4109
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4110
+					$status
4111
+				),
4112
+				__FILE__,
4113
+				__FUNCTION__,
4114
+				__LINE__
4115
+			);
4116
+			$success = false;
4117
+		}
4118
+
4119
+
4120
+		// do a nonce check here since we're not arriving via a normal route
4121
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4122
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4123
+
4124
+		if ($success) {
4125
+			// made it here? um, what are you waiting for then?
4126
+			$success = $status === 'deactivate'
4127
+				? $this->_deactivate_message_type_for_messenger(
4128
+					$this->_active_messenger_name,
4129
+					$this->_active_message_type_name
4130
+				)
4131
+				: $this->_activate_message_type_for_messenger(
4132
+					$this->_active_messenger_name,
4133
+					$this->_active_message_type_name
4134
+				);
4135
+		}
4136
+
4137
+		$this->_template_args['success'] = $success;
4138
+		$this->_return_json();
4139
+	}
4140
+
4141
+
4142
+	/**
4143
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4144
+	 *
4145
+	 * @param string $messenger_name The name of the messenger being activated
4146
+	 * @return bool
4147
+	 * @throws DomainException
4148
+	 * @throws EE_Error
4149
+	 * @throws InvalidArgumentException
4150
+	 * @throws ReflectionException
4151
+	 * @throws InvalidDataTypeException
4152
+	 * @throws InvalidInterfaceException
4153
+	 */
4154
+	protected function _activate_messenger($messenger_name)
4155
+	{
4156
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4157
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4158
+			? $active_messenger->get_default_message_types()
4159
+			: [];
4160
+
4161
+		// ensure is active
4162
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4163
+
4164
+		// set response_data for reload
4165
+		foreach ($message_types_to_activate as $message_type_name) {
4166
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4167
+			if (
4168
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4169
+					$messenger_name,
4170
+					$message_type_name
4171
+				)
4172
+				&& $message_type instanceof EE_message_type
4173
+			) {
4174
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4175
+				if ($message_type->get_admin_settings_fields()) {
4176
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4177
+				}
4178
+			}
4179
+		}
4180
+
4181
+		// add success message for activating messenger
4182
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4183
+	}
4184
+
4185
+
4186
+	/**
4187
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4188
+	 *
4189
+	 * @param string $messenger_name The name of the messenger being activated
4190
+	 * @return bool
4191
+	 * @throws DomainException
4192
+	 * @throws EE_Error
4193
+	 * @throws InvalidArgumentException
4194
+	 * @throws ReflectionException
4195
+	 * @throws InvalidDataTypeException
4196
+	 * @throws InvalidInterfaceException
4197
+	 */
4198
+	protected function _deactivate_messenger($messenger_name)
4199
+	{
4200
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4201
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4202
+
4203
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4204
+	}
4205
+
4206
+
4207
+	/**
4208
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4209
+	 *
4210
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4211
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4212
+	 * @return bool
4213
+	 * @throws DomainException
4214
+	 * @throws EE_Error
4215
+	 * @throws InvalidArgumentException
4216
+	 * @throws ReflectionException
4217
+	 * @throws InvalidDataTypeException
4218
+	 * @throws InvalidInterfaceException
4219
+	 */
4220
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4221
+	{
4222
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4223
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4224
+
4225
+		// ensure is active
4226
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4227
+
4228
+		// set response for load
4229
+		if (
4230
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4231
+				$messenger_name,
4232
+				$message_type_name
4233
+			)
4234
+		) {
4235
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4236
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4237
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4238
+			}
4239
+		}
4240
+
4241
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4242
+			$active_messenger,
4243
+			$message_type_to_activate
4244
+		);
4245
+	}
4246
+
4247
+
4248
+	/**
4249
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4250
+	 *
4251
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4252
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4253
+	 * @return bool
4254
+	 * @throws DomainException
4255
+	 * @throws EE_Error
4256
+	 * @throws InvalidArgumentException
4257
+	 * @throws ReflectionException
4258
+	 * @throws InvalidDataTypeException
4259
+	 * @throws InvalidInterfaceException
4260
+	 */
4261
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4262
+	{
4263
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4264
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4265
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4266
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4267
+
4268
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4269
+			$active_messenger,
4270
+			$message_type_to_deactivate
4271
+		);
4272
+	}
4273
+
4274
+
4275
+	/**
4276
+	 * This just initializes the defaults for activating messenger and message type responses.
4277
+	 */
4278
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4279
+	{
4280
+		$this->_template_args['data']['active_mts'] = [];
4281
+		$this->_template_args['data']['mt_reload']  = [];
4282
+	}
4283
+
4284
+
4285
+	/**
4286
+	 * Setup appropriate response for activating a messenger and/or message types
4287
+	 *
4288
+	 * @param EE_messenger         $messenger
4289
+	 * @param EE_message_type|null $message_type
4290
+	 * @return bool
4291
+	 * @throws DomainException
4292
+	 * @throws EE_Error
4293
+	 * @throws InvalidArgumentException
4294
+	 * @throws ReflectionException
4295
+	 * @throws InvalidDataTypeException
4296
+	 * @throws InvalidInterfaceException
4297
+	 */
4298
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4299
+		$messenger,
4300
+		EE_Message_Type $message_type = null
4301
+	) {
4302
+		// if $messenger isn't a valid messenger object then get out.
4303
+		if (! $messenger instanceof EE_Messenger) {
4304
+			EE_Error::add_error(
4305
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4306
+				__FILE__,
4307
+				__FUNCTION__,
4308
+				__LINE__
4309
+			);
4310
+			return false;
4311
+		}
4312
+		// activated
4313
+		if ($this->_template_args['data']['active_mts']) {
4314
+			EE_Error::overwrite_success();
4315
+			// activated a message type with the messenger
4316
+			if ($message_type instanceof EE_message_type) {
4317
+				EE_Error::add_success(
4318
+					sprintf(
4319
+						esc_html__(
4320
+							'%s message type has been successfully activated with the %s messenger',
4321
+							'event_espresso'
4322
+						),
4323
+						ucwords($message_type->label['singular']),
4324
+						ucwords($messenger->label['singular'])
4325
+					)
4326
+				);
4327
+
4328
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4329
+				if ($message_type->name === 'invoice') {
4330
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4331
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4332
+					if ($pm instanceof EE_Payment_Method) {
4333
+						EE_Error::add_attention(
4334
+							esc_html__(
4335
+								'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.',
4336
+								'event_espresso'
4337
+							)
4338
+						);
4339
+					}
4340
+				}
4341
+				// just toggles the entire messenger
4342
+			} else {
4343
+				EE_Error::add_success(
4344
+					sprintf(
4345
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4346
+						ucwords($messenger->label['singular'])
4347
+					)
4348
+				);
4349
+			}
4350
+
4351
+			return true;
4352
+
4353
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4354
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4355
+			// in which case we just give a success message for the messenger being successfully activated.
4356
+		} else {
4357
+			if (! $messenger->get_default_message_types()) {
4358
+				// messenger doesn't have any default message types so still a success.
4359
+				EE_Error::add_success(
4360
+					sprintf(
4361
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4362
+						ucwords($messenger->label['singular'])
4363
+					)
4364
+				);
4365
+
4366
+				return true;
4367
+			} else {
4368
+				EE_Error::add_error(
4369
+					$message_type instanceof EE_message_type
4370
+					? sprintf(
4371
+						esc_html__(
4372
+							'%s message type was not successfully activated with the %s messenger',
4373
+							'event_espresso'
4374
+						),
4375
+						ucwords($message_type->label['singular']),
4376
+						ucwords($messenger->label['singular'])
4377
+					)
4378
+					: sprintf(
4379
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4380
+						ucwords($messenger->label['singular'])
4381
+					),
4382
+					__FILE__,
4383
+					__FUNCTION__,
4384
+					__LINE__
4385
+				);
4386
+
4387
+				return false;
4388
+			}
4389
+		}
4390
+	}
4391
+
4392
+
4393
+	/**
4394
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4395
+	 *
4396
+	 * @param EE_messenger         $messenger
4397
+	 * @param EE_message_type|null $message_type
4398
+	 * @return bool
4399
+	 * @throws DomainException
4400
+	 * @throws EE_Error
4401
+	 * @throws InvalidArgumentException
4402
+	 * @throws ReflectionException
4403
+	 * @throws InvalidDataTypeException
4404
+	 * @throws InvalidInterfaceException
4405
+	 */
4406
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4407
+		$messenger,
4408
+		EE_message_type $message_type = null
4409
+	) {
4410
+		EE_Error::overwrite_success();
4411
+
4412
+		// if $messenger isn't a valid messenger object then get out.
4413
+		if (! $messenger instanceof EE_Messenger) {
4414
+			EE_Error::add_error(
4415
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4416
+				__FILE__,
4417
+				__FUNCTION__,
4418
+				__LINE__
4419
+			);
4420
+
4421
+			return false;
4422
+		}
4423
+
4424
+		if ($message_type instanceof EE_message_type) {
4425
+			$message_type_name = $message_type->name;
4426
+			EE_Error::add_success(
4427
+				sprintf(
4428
+					esc_html__(
4429
+						'%s message type has been successfully deactivated for the %s messenger.',
4430
+						'event_espresso'
4431
+					),
4432
+					ucwords($message_type->label['singular']),
4433
+					ucwords($messenger->label['singular'])
4434
+				)
4435
+			);
4436
+		} else {
4437
+			$message_type_name = '';
4438
+			EE_Error::add_success(
4439
+				sprintf(
4440
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4441
+					ucwords($messenger->label['singular'])
4442
+				)
4443
+			);
4444
+		}
4445
+
4446
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4447
+		if (
4448
+			$messenger->name === 'html'
4449
+			&& (
4450
+				is_null($message_type)
4451
+				|| $message_type_name === 'invoice'
4452
+			)
4453
+		) {
4454
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4455
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4456
+			if ($count_updated > 0) {
4457
+				$msg = $message_type_name === 'invoice'
4458
+					? esc_html__(
4459
+						'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.',
4460
+						'event_espresso'
4461
+					)
4462
+					: esc_html__(
4463
+						'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.',
4464
+						'event_espresso'
4465
+					);
4466
+				EE_Error::add_attention($msg);
4467
+			}
4468
+		}
4469
+
4470
+		return true;
4471
+	}
4472
+
4473
+
4474
+	/**
4475
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4476
+	 *
4477
+	 * @throws DomainException
4478
+	 * @throws EE_Error
4479
+	 * @throws EE_Error
4480
+	 */
4481
+	public function update_mt_form()
4482
+	{
4483
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4484
+			EE_Error::add_error(
4485
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4486
+				__FILE__,
4487
+				__FUNCTION__,
4488
+				__LINE__
4489
+			);
4490
+			$this->_return_json();
4491
+		}
4492
+
4493
+		$message_types = $this->get_installed_message_types();
4494
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4495
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4496
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4497
+
4498
+		$this->_template_args['success'] = true;
4499
+		$this->_template_args['content'] = $content;
4500
+		$this->_return_json();
4501
+	}
4502
+
4503
+
4504
+	/**
4505
+	 * this handles saving the settings for a messenger or message type
4506
+	 *
4507
+	 * @throws EE_Error
4508
+	 * @throws EE_Error
4509
+	 */
4510
+	public function save_settings()
4511
+	{
4512
+		$type = $this->request->getRequestParam('type');
4513
+		if (! $type) {
4514
+			EE_Error::add_error(
4515
+				esc_html__(
4516
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4517
+					'event_espresso'
4518
+				),
4519
+				__FILE__,
4520
+				__FUNCTION__,
4521
+				__LINE__
4522
+			);
4523
+			$this->_template_args['error'] = true;
4524
+			$this->_return_json();
4525
+		}
4526
+
4527
+
4528
+		if ($type === 'messenger') {
4529
+			// this should be an array.
4530
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4531
+			$messenger = $settings['messenger'];
4532
+			// remove messenger and message_types from settings array
4533
+			unset($settings['messenger'], $settings['message_types']);
4534
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4535
+		} elseif ($type === 'message_type') {
4536
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4537
+			$messenger    = $settings['messenger'];
4538
+			$message_type = $settings['message_type'];
4539
+			// remove messenger and message_types from settings array
4540
+			unset($settings['messenger'], $settings['message_types']);
4541
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4542
+		}
4543
+
4544
+		// okay we should have the data all setup.  Now we just update!
4545
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4546
+
4547
+		if ($success) {
4548
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4549
+		} else {
4550
+			EE_Error::add_error(
4551
+				esc_html__('Settings did not get updated', 'event_espresso'),
4552
+				__FILE__,
4553
+				__FUNCTION__,
4554
+				__LINE__
4555
+			);
4556
+		}
4557
+
4558
+		$this->_template_args['success'] = $success;
4559
+		$this->_return_json();
4560
+	}
4561
+
4562
+
4563
+
4564
+
4565
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4566
+
4567
+
4568
+	/**
4569
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4570
+	 * However, this does not send immediately, it just queues for sending.
4571
+	 *
4572
+	 * @throws EE_Error
4573
+	 * @throws InvalidDataTypeException
4574
+	 * @throws InvalidInterfaceException
4575
+	 * @throws InvalidArgumentException
4576
+	 * @throws ReflectionException
4577
+	 * @since 4.9.0
4578
+	 */
4579
+	protected function _generate_now()
4580
+	{
4581
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4582
+		$this->_redirect_after_action(false, '', '', [], true);
4583
+	}
4584
+
4585
+
4586
+	/**
4587
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4588
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4589
+	 *
4590
+	 * @throws EE_Error
4591
+	 * @throws InvalidDataTypeException
4592
+	 * @throws InvalidInterfaceException
4593
+	 * @throws InvalidArgumentException
4594
+	 * @throws ReflectionException
4595
+	 * @since 4.9.0
4596
+	 */
4597
+	protected function _generate_and_send_now()
4598
+	{
4599
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4600
+		$this->_redirect_after_action(false, '', '', [], true);
4601
+	}
4602
+
4603
+
4604
+	/**
4605
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4606
+	 *
4607
+	 * @throws EE_Error
4608
+	 * @throws InvalidDataTypeException
4609
+	 * @throws InvalidInterfaceException
4610
+	 * @throws InvalidArgumentException
4611
+	 * @throws ReflectionException
4612
+	 * @since 4.9.0
4613
+	 */
4614
+	protected function _queue_for_resending()
4615
+	{
4616
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4617
+		$this->_redirect_after_action(false, '', '', [], true);
4618
+	}
4619
+
4620
+
4621
+	/**
4622
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4623
+	 *
4624
+	 * @throws EE_Error
4625
+	 * @throws InvalidDataTypeException
4626
+	 * @throws InvalidInterfaceException
4627
+	 * @throws InvalidArgumentException
4628
+	 * @throws ReflectionException
4629
+	 * @since 4.9.0
4630
+	 */
4631
+	protected function _send_now()
4632
+	{
4633
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4634
+		$this->_redirect_after_action(false, '', '', [], true);
4635
+	}
4636
+
4637
+
4638
+	/**
4639
+	 * Deletes EE_messages for IDs in the request.
4640
+	 *
4641
+	 * @throws EE_Error
4642
+	 * @throws InvalidDataTypeException
4643
+	 * @throws InvalidInterfaceException
4644
+	 * @throws InvalidArgumentException
4645
+	 * @since 4.9.0
4646
+	 */
4647
+	protected function _delete_ee_messages()
4648
+	{
4649
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4650
+		$deleted_count = 0;
4651
+		foreach ($MSG_IDs as $MSG_ID) {
4652
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4653
+				$deleted_count++;
4654
+			}
4655
+		}
4656
+		if ($deleted_count) {
4657
+			EE_Error::add_success(
4658
+				esc_html(
4659
+					_n(
4660
+						'Message successfully deleted',
4661
+						'Messages successfully deleted',
4662
+						$deleted_count,
4663
+						'event_espresso'
4664
+					)
4665
+				)
4666
+			);
4667
+		} else {
4668
+			EE_Error::add_error(
4669
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4670
+				__FILE__,
4671
+				__FUNCTION__,
4672
+				__LINE__
4673
+			);
4674
+		}
4675
+		$this->_redirect_after_action(false, '', '', [], true);
4676
+	}
4677
+
4678
+
4679
+	/**
4680
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4681
+	 *
4682
+	 * @return array
4683
+	 * @since 4.9.0
4684
+	 */
4685
+	protected function _get_msg_ids_from_request()
4686
+	{
4687
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4688
+		if (empty($MSG_IDs)) {
4689
+			return [];
4690
+		}
4691
+		// if 'MSG_ID' was just a single ID (not an array)
4692
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4693
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4694
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4695
+			? $MSG_IDs
4696
+			: array_keys($MSG_IDs);
4697
+	}
4698 4698
 }
Please login to merge, or discard this patch.
Spacing   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      */
116 116
     public function getMsgModel()
117 117
     {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
118
+        if ( ! $this->MSG_MODEL instanceof EEM_Message) {
119 119
             $this->MSG_MODEL = EEM_Message::instance();
120 120
         }
121 121
         return $this->MSG_MODEL;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function getMtpModel()
130 130
     {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
+        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) {
132 132
             $this->MTP_MODEL = EEM_Message_Template::instance();
133 133
         }
134 134
         return $this->MTP_MODEL;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function getMtgModel()
143 143
     {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
+        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145 145
             $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146 146
         }
147 147
         return $this->MTG_MODEL;
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
         $i = 1;
212 212
         foreach ($active_messengers as $active_messenger) {
213 213
             if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
214
+                $m_values[$i]['id']   = $active_messenger->messenger();
215
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
216 216
                 $i++;
217 217
             }
218 218
         }
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
         $i               = 1;
249 249
         foreach ($active_messages as $active_message) {
250 250
             if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
251
+                $mt_values[$i]['id']   = $active_message->message_type();
252
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
253 253
                 $i++;
254 254
             }
255 255
         }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 if ($message_type instanceof EE_message_type) {
289 289
                     $message_type_contexts = $message_type->get_contexts();
290 290
                     foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
291
+                        $contexts[$context] = $context_details['label'];
292 292
                     }
293 293
                 }
294 294
             }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322 322
             $messenger_options
323 323
         );
324
-        $input             = new EE_Select_Input(
324
+        $input = new EE_Select_Input(
325 325
             $messenger_options,
326 326
             [
327 327
                 'html_name'  => 'ee_messenger_filter_by',
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359 359
             $message_type_options
360 360
         );
361
-        $input                = new EE_Select_Input(
361
+        $input = new EE_Select_Input(
362 362
             $message_type_options,
363 363
             [
364 364
                 'html_name'  => 'ee_message_type_filter_by',
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396 396
             $context_options
397 397
         );
398
-        $input           = new EE_Select_Input(
398
+        $input = new EE_Select_Input(
399 399
             $context_options,
400 400
             [
401 401
                 'html_name'  => 'ee_context_filter_by',
@@ -769,53 +769,53 @@  discard block
 block discarded – undo
769 769
 
770 770
     public function messages_help_tab()
771 771
     {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
772
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
773 773
     }
774 774
 
775 775
 
776 776
     public function messengers_help_tab()
777 777
     {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
778
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
779 779
     }
780 780
 
781 781
 
782 782
     public function message_types_help_tab()
783 783
     {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
784
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
785 785
     }
786 786
 
787 787
 
788 788
     public function messages_overview_help_tab()
789 789
     {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
790
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
791 791
     }
792 792
 
793 793
 
794 794
     public function message_templates_help_tab()
795 795
     {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
796
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
797 797
     }
798 798
 
799 799
 
800 800
     public function edit_message_template_help_tab()
801 801
     {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
802
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
803 803
                         . esc_attr__('Editor Title', 'event_espresso')
804 804
                         . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
805
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
806 806
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
807 807
                         . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
808
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
809 809
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
810 810
                         . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
811
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
812 812
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
813 813
                         . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
814
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
815 815
                         . esc_attr__('Publish Metabox', 'event_espresso')
816 816
                         . '" />';
817 817
         EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
818
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
819 819
             $args
820 820
         );
821 821
     }
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
         $this->_set_shortcodes();
831 831
         $args['shortcodes'] = $this->_shortcodes;
832 832
         EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
833
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
834 834
             $args
835 835
         );
836 836
     }
@@ -838,16 +838,16 @@  discard block
 block discarded – undo
838 838
 
839 839
     public function preview_message_help_tab()
840 840
     {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
841
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
842 842
     }
843 843
 
844 844
 
845 845
     public function settings_help_tab()
846 846
     {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
847
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
848
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
849
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
850
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
851 851
         $args['img3'] = '<div class="switch">'
852 852
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853 853
                         . ' type="checkbox" checked="checked">'
@@ -858,25 +858,25 @@  discard block
 block discarded – undo
858 858
                         . ' type="checkbox">'
859 859
                         . '<label for="ee-on-off-toggle-on"></label>'
860 860
                         . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
861
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
862 862
     }
863 863
 
864 864
 
865 865
     public function load_scripts_styles()
866 866
     {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868 868
         wp_enqueue_style('espresso_ee_msg');
869 869
 
870 870
         wp_register_script(
871 871
             'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
872
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
873 873
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
874 874
             EVENT_ESPRESSO_VERSION,
875 875
             true
876 876
         );
877 877
         wp_register_script(
878 878
             'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
879
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
880 880
             ['ee-dialog'],
881 881
             EVENT_ESPRESSO_VERSION
882 882
         );
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 
920 920
         $this->_set_shortcodes();
921 921
 
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
922
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
923 923
             esc_html__(
924 924
                 '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.',
925 925
                 'event_espresso'
@@ -931,14 +931,14 @@  discard block
 block discarded – undo
931 931
             '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?',
932 932
             'event_espresso'
933 933
         );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
934
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
935 935
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936 936
             'event_espresso'
937 937
         );
938 938
 
939 939
         wp_register_script(
940 940
             'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
941
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
942 942
             ['jquery'],
943 943
             EVENT_ESPRESSO_VERSION
944 944
         );
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
     {
982 982
         wp_register_style(
983 983
             'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
984
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
985 985
             [],
986 986
             EVENT_ESPRESSO_VERSION
987 987
         );
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
             }
1068 1068
             $status_bulk_actions = $common_bulk_actions;
1069 1069
             // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1070
+            if ( ! empty($status_bulk_actions)) {
1071 1071
                 switch ($status) {
1072 1072
                     case EEM_Message::status_idle:
1073 1073
                     case EEM_Message::status_resend:
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
                 continue;
1097 1097
             }
1098 1098
 
1099
-            $this->_views[ strtolower($status) ] = [
1099
+            $this->_views[strtolower($status)] = [
1100 1100
                 'slug'        => strtolower($status),
1101 1101
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102 1102
                 'count'       => 0,
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
             if ($action_item === 'see_notifications_for') {
1145 1145
                 continue;
1146 1146
             }
1147
-            $action_items[ $action_item ] = [
1147
+            $action_items[$action_item] = [
1148 1148
                 'class' => $action_details['css_class'],
1149 1149
                 'desc'  => $action_details['label'],
1150 1150
             ];
@@ -1153,37 +1153,37 @@  discard block
 block discarded – undo
1153 1153
         /** @var array $status_items status legend setup */
1154 1154
         $status_items = [
1155 1155
             'sent_status'                => [
1156
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1156
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_sent,
1157 1157
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158 1158
             ],
1159 1159
             'idle_status'                => [
1160
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1160
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_idle,
1161 1161
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162 1162
             ],
1163 1163
             'failed_status'              => [
1164
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1164
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_failed,
1165 1165
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166 1166
             ],
1167 1167
             'messenger_executing_status' => [
1168
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1168
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_messenger_executing,
1169 1169
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170 1170
             ],
1171 1171
             'resend_status'              => [
1172
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1172
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_resend,
1173 1173
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174 1174
             ],
1175 1175
             'incomplete_status'          => [
1176
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1176
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_incomplete,
1177 1177
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178 1178
             ],
1179 1179
             'retry_status'               => [
1180
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1180
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_retry,
1181 1181
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182 1182
             ],
1183 1183
         ];
1184 1184
         if (EEM_Message::debug()) {
1185 1185
             $status_items['debug_only_status'] = [
1186
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1186
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_debug_only,
1187 1187
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188 1188
             ];
1189 1189
         }
@@ -1198,11 +1198,11 @@  discard block
 block discarded – undo
1198 1198
     protected function _custom_mtps_preview()
1199 1199
     {
1200 1200
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
-                                                . ' alt="' . esc_attr__(
1201
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1202
+                                                . ' alt="'.esc_attr__(
1203 1203
                                                     'Preview Custom Message Templates screenshot',
1204 1204
                                                     'event_espresso'
1205
-                                                ) . '" />';
1205
+                                                ).'" />';
1206 1206
         $this->_template_args['preview_text'] = '<strong>'
1207 1207
                                                 . esc_html__(
1208 1208
                                                     '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.',
@@ -1278,7 +1278,7 @@  discard block
 block discarded – undo
1278 1278
         $installed               = [];
1279 1279
 
1280 1280
         foreach ($installed_message_types as $message_type) {
1281
-            $installed[ $message_type->name ] = $message_type;
1281
+            $installed[$message_type->name] = $message_type;
1282 1282
         }
1283 1283
 
1284 1284
         return $installed;
@@ -1404,7 +1404,7 @@  discard block
 block discarded – undo
1404 1404
         // we need to assemble the title from Various details
1405 1405
         $context_label = sprintf(
1406 1406
             esc_html__('(%s %s)', 'event_espresso'),
1407
-            $c_config[ $context ]['label'],
1407
+            $c_config[$context]['label'],
1408 1408
             ucwords($c_label['label'])
1409 1409
         );
1410 1410
 
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
             $message_template_group->message_type()
1427 1427
         );
1428 1428
 
1429
-        if (! $template_field_structure) {
1429
+        if ( ! $template_field_structure) {
1430 1430
             $template_field_structure = false;
1431 1431
             $template_fields          = esc_html__(
1432 1432
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1440,21 +1440,21 @@  discard block
 block discarded – undo
1440 1440
 
1441 1441
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442 1442
         // will get handled in the "extra" array.
1443
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
-                unset($template_field_structure[ $context ][ $reference_field ]);
1443
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1444
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1445
+                unset($template_field_structure[$context][$reference_field]);
1446 1446
             }
1447 1447
         }
1448 1448
 
1449 1449
         // let's loop through the template_field_structure and actually assemble the input fields!
1450
-        if (! empty($template_field_structure)) {
1451
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1450
+        if ( ! empty($template_field_structure)) {
1451
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1452 1452
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453 1453
                 // the extra array and reset them.
1454 1454
                 if ($template_field === 'extra') {
1455 1455
                     $this->_template_args['is_extra_fields'] = true;
1456 1456
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1457
+                        $message_template = $message_templates[$context][$reference_field];
1458 1458
                         $content          = $message_template instanceof EE_Message_Template
1459 1459
                             ? $message_template->get('MTP_content')
1460 1460
                             : '';
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
                             $continue = false;
1464 1464
                             if (isset($extra_array['shortcodes_required'])) {
1465 1465
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1466
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1467 1467
                                         $continue = true;
1468 1468
                                     }
1469 1469
                                 }
@@ -1472,53 +1472,53 @@  discard block
 block discarded – undo
1472 1472
                                 }
1473 1473
                             }
1474 1474
 
1475
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1475
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1476 1476
 
1477
-                            $template_form_fields[ $field_id ]         = $extra_array;
1478
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1477
+                            $template_form_fields[$field_id]         = $extra_array;
1478
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1479 1479
                                                                          . $reference_field
1480 1480
                                                                          . '][content]['
1481
-                                                                         . $extra_field . ']';
1482
-                            $css_class                                 = isset($extra_array['css_class'])
1481
+                                                                         . $extra_field.']';
1482
+                            $css_class = isset($extra_array['css_class'])
1483 1483
                                 ? $extra_array['css_class']
1484 1484
                                 : '';
1485 1485
 
1486
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1486
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1487 1487
                                                                               && in_array($extra_field, $v_fields, true)
1488 1488
                                                                               && (
1489
-                                                                                  is_array($validators[ $extra_field ])
1490
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1489
+                                                                                  is_array($validators[$extra_field])
1490
+                                                                                  && isset($validators[$extra_field]['msg'])
1491 1491
                                                                               )
1492
-                                ? 'validate-error ' . $css_class
1492
+                                ? 'validate-error '.$css_class
1493 1493
                                 : $css_class;
1494 1494
 
1495
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
-                                                                          && isset($content[ $extra_field ])
1497
-                                ? $content[ $extra_field ]
1495
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1496
+                                                                          && isset($content[$extra_field])
1497
+                                ? $content[$extra_field]
1498 1498
                                 : '';
1499 1499
 
1500 1500
                             // do we have a validation error?  if we do then let's use that value instead
1501
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
-                                ? $validators[ $extra_field ]['value']
1503
-                                : $template_form_fields[ $field_id ]['value'];
1501
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1502
+                                ? $validators[$extra_field]['value']
1503
+                                : $template_form_fields[$field_id]['value'];
1504 1504
 
1505 1505
 
1506
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1506
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1507 1507
 
1508 1508
                             // shortcode selector
1509 1509
                             $field_name_to_use                                   = $extra_field === 'main'
1510 1510
                                 ? 'content'
1511 1511
                                 : $extra_field;
1512
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1512
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1513 1513
                                 $field_name_to_use,
1514 1514
                                 $field_id
1515 1515
                             );
1516 1516
                         }
1517
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
-                        $template_field_template_name_id = $reference_field . '-name';
1517
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1518
+                        $template_field_template_name_id = $reference_field.'-name';
1519 1519
 
1520
-                        $template_form_fields[ $template_field_MTP_id ] = [
1521
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1520
+                        $template_form_fields[$template_field_MTP_id] = [
1521
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1522 1522
                             'label'      => null,
1523 1523
                             'input'      => 'hidden',
1524 1524
                             'type'       => 'int',
@@ -1530,8 +1530,8 @@  discard block
 block discarded – undo
1530 1530
                             'db-col'     => 'MTP_ID',
1531 1531
                         ];
1532 1532
 
1533
-                        $template_form_fields[ $template_field_template_name_id ] = [
1534
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1533
+                        $template_form_fields[$template_field_template_name_id] = [
1534
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1535 1535
                             'label'      => null,
1536 1536
                             'input'      => 'hidden',
1537 1537
                             'type'       => 'string',
@@ -1545,38 +1545,38 @@  discard block
 block discarded – undo
1545 1545
                     }
1546 1546
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547 1547
                 } else {
1548
-                    $field_id                                   = $template_field . '-content';
1549
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1550
-                    $template_form_fields[ $field_id ]['name']  =
1551
-                        'MTP_template_fields[' . $template_field . '][content]';
1548
+                    $field_id                                   = $template_field.'-content';
1549
+                    $template_form_fields[$field_id]          = $field_setup_array;
1550
+                    $template_form_fields[$field_id]['name']  =
1551
+                        'MTP_template_fields['.$template_field.'][content]';
1552 1552
                     $message_template                           =
1553
-                        isset($message_templates[ $context ][ $template_field ])
1554
-                            ? $message_templates[ $context ][ $template_field ]
1553
+                        isset($message_templates[$context][$template_field])
1554
+                            ? $message_templates[$context][$template_field]
1555 1555
                             : null;
1556
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
-                                                                  && is_array($message_templates[ $context ])
1556
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1557
+                                                                  && is_array($message_templates[$context])
1558 1558
                                                                   && $message_template instanceof EE_Message_Template
1559 1559
                         ? $message_template->get('MTP_content')
1560 1560
                         : '';
1561 1561
 
1562 1562
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1563
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
-                        ? $validators[ $template_field ]['value']
1565
-                        : $template_form_fields[ $field_id ]['value'];
1563
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1564
+                        ? $validators[$template_field]['value']
1565
+                        : $template_form_fields[$field_id]['value'];
1566 1566
 
1567 1567
 
1568
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1568
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1569 1569
                     $css_class                                      = isset($field_setup_array['css_class'])
1570 1570
                         ? $field_setup_array['css_class']
1571 1571
                         : '';
1572
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1572
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1573 1573
                                                                       && in_array($template_field, $v_fields, true)
1574
-                                                                      && isset($validators[ $template_field ]['msg'])
1575
-                        ? 'validate-error ' . $css_class
1574
+                                                                      && isset($validators[$template_field]['msg'])
1575
+                        ? 'validate-error '.$css_class
1576 1576
                         : $css_class;
1577 1577
 
1578 1578
                     // shortcode selector
1579
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1579
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1580 1580
                         $template_field,
1581 1581
                         $field_id
1582 1582
                     );
@@ -1584,12 +1584,12 @@  discard block
 block discarded – undo
1584 1584
 
1585 1585
                 // k took care of content field(s) now let's take care of others.
1586 1586
 
1587
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
-                $template_field_field_template_name_id = $template_field . '-name';
1587
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1588
+                $template_field_field_template_name_id = $template_field.'-name';
1589 1589
 
1590 1590
                 // foreach template field there are actually two form fields created
1591
-                $template_form_fields[ $template_field_MTP_id ] = [
1592
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1591
+                $template_form_fields[$template_field_MTP_id] = [
1592
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1593 1593
                     'label'      => null,
1594 1594
                     'input'      => 'hidden',
1595 1595
                     'type'       => 'int',
@@ -1601,8 +1601,8 @@  discard block
 block discarded – undo
1601 1601
                     'db-col'     => 'MTP_ID',
1602 1602
                 ];
1603 1603
 
1604
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1605
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1604
+                $template_form_fields[$template_field_field_template_name_id] = [
1605
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1606 1606
                     'label'      => null,
1607 1607
                     'input'      => 'hidden',
1608 1608
                     'type'       => 'string',
@@ -1719,7 +1719,7 @@  discard block
 block discarded – undo
1719 1719
                 'format'     => '%d',
1720 1720
                 'db-col'     => 'MTP_deleted',
1721 1721
             ];
1722
-            $sidebar_form_fields['ee-msg-author']  = [
1722
+            $sidebar_form_fields['ee-msg-author'] = [
1723 1723
                 'name'       => 'MTP_user_id',
1724 1724
                 'label'      => esc_html__('Author', 'event_espresso'),
1725 1725
                 'input'      => 'hidden',
@@ -1738,17 +1738,17 @@  discard block
 block discarded – undo
1738 1738
                 'value' => $action,
1739 1739
             ];
1740 1740
 
1741
-            $sidebar_form_fields['ee-msg-id']        = [
1741
+            $sidebar_form_fields['ee-msg-id'] = [
1742 1742
                 'name'  => 'id',
1743 1743
                 'input' => 'hidden',
1744 1744
                 'type'  => 'int',
1745 1745
                 'value' => $GRP_ID,
1746 1746
             ];
1747 1747
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
-                'name'  => $action . '_nonce',
1748
+                'name'  => $action.'_nonce',
1749 1749
                 'input' => 'hidden',
1750 1750
                 'type'  => 'string',
1751
-                'value' => wp_create_nonce($action . '_nonce'),
1751
+                'value' => wp_create_nonce($action.'_nonce'),
1752 1752
             ];
1753 1753
 
1754 1754
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1779,7 +1779,7 @@  discard block
 block discarded – undo
1779 1779
         );
1780 1780
 
1781 1781
         // add preview button
1782
-        $preview_url    = parent::add_query_args_and_nonce(
1782
+        $preview_url = parent::add_query_args_and_nonce(
1783 1783
             [
1784 1784
                 'message_type' => $message_template_group->message_type(),
1785 1785
                 'messenger'    => $message_template_group->messenger(),
@@ -1790,7 +1790,7 @@  discard block
 block discarded – undo
1790 1790
             ],
1791 1791
             $this->_admin_base_url
1792 1792
         );
1793
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1793
+        $preview_button = '<a href="'.$preview_url.'" class="button--secondary messages-preview-button">'
1794 1794
                           . esc_html__('Preview', 'event_espresso')
1795 1795
                           . '</a>';
1796 1796
 
@@ -1828,11 +1828,11 @@  discard block
 block discarded – undo
1828 1828
         $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1829 1829
         $this->_template_args['before_admin_page_content'] .= '</div>';
1830 1830
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1831
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1832 1832
 
1833 1833
         $this->_template_path = $this->_template_args['GRP_ID']
1834 1834
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1835
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1836 1836
 
1837 1837
         // send along EE_Message_Template_Group object for further template use.
1838 1838
         $this->_template_args['MTP'] = $message_template_group;
@@ -1888,7 +1888,7 @@  discard block
 block discarded – undo
1888 1888
     ) {
1889 1889
         $template_args = [
1890 1890
             'context'                   => $context,
1891
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1892 1892
             'is_active'                 => $message_template_group->is_context_active($context),
1893 1893
             'on_off_action'             => $message_template_group->is_context_active($context)
1894 1894
                 ? 'context-off'
@@ -1897,7 +1897,7 @@  discard block
 block discarded – undo
1897 1897
             'message_template_group_id' => $message_template_group->ID(),
1898 1898
         ];
1899 1899
         return EEH_Template::display_template(
1900
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1901 1901
             $template_args,
1902 1902
             true
1903 1903
         );
@@ -1954,7 +1954,7 @@  discard block
 block discarded – undo
1954 1954
         }
1955 1955
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1956 1956
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1957
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1958 1958
             EE_Error::add_error(
1959 1959
                 sprintf(
1960 1960
                     esc_html__(
@@ -2085,7 +2085,7 @@  discard block
 block discarded – undo
2085 2085
         $messenger    = $this->request->getRequestParam('msgr');
2086 2086
         $message_type = $this->request->getRequestParam('mt');
2087 2087
         // we need to make sure we've got the info we need.
2088
-        if (! ($GRP_ID && $messenger && $message_type)) {
2088
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2089 2089
             EE_Error::add_error(
2090 2090
                 esc_html__(
2091 2091
                     '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.',
@@ -2122,7 +2122,7 @@  discard block
 block discarded – undo
2122 2122
         }
2123 2123
 
2124 2124
         // any error messages?
2125
-        if (! $success) {
2125
+        if ( ! $success) {
2126 2126
             EE_Error::add_error(
2127 2127
                 esc_html__(
2128 2128
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2171,7 +2171,7 @@  discard block
 block discarded – undo
2171 2171
     {
2172 2172
         // first make sure we've got the necessary parameters
2173 2173
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2174
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2175 2175
             EE_Error::add_error(
2176 2176
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2177 2177
                 __FILE__,
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2198 2198
 
2199 2199
         // let's add a button to go back to the edit view
2200
-        $query_args             = [
2200
+        $query_args = [
2201 2201
             'id'      => $GRP_ID,
2202 2202
             'evt_id'  => $EVT_ID,
2203 2203
             'context' => $context,
@@ -2218,7 +2218,7 @@  discard block
 block discarded – undo
2218 2218
         $preview_title = sprintf(
2219 2219
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2220 2220
             $active_messenger_label,
2221
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2222 2222
         );
2223 2223
         if (empty($preview)) {
2224 2224
             $this->noEventsErrorMessage();
@@ -2226,7 +2226,7 @@  discard block
 block discarded – undo
2226 2226
         // setup display of preview.
2227 2227
         $this->_admin_page_title                    = $preview_title;
2228 2228
         $this->_template_args['admin_page_title']   = $preview_title;
2229
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2230 2230
         $this->_template_args['data']['force_json'] = true;
2231 2231
 
2232 2232
         return '';
@@ -2247,7 +2247,7 @@  discard block
 block discarded – undo
2247 2247
             ],
2248 2248
             admin_url('admin.php')
2249 2249
         );
2250
-        $message    = $test_send
2250
+        $message = $test_send
2251 2251
             ? esc_html__(
2252 2252
                 '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!',
2253 2253
                 'event_espresso'
@@ -2340,10 +2340,10 @@  discard block
 block discarded – undo
2340 2340
             // only include template packs that support this messenger and message type!
2341 2341
             $supports = $tp->get_supports();
2342 2342
             if (
2343
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2343
+                ! isset($supports[$this->_message_template_group->messenger()])
2344 2344
                 || ! in_array(
2345 2345
                     $this->_message_template_group->message_type(),
2346
-                    $supports[ $this->_message_template_group->messenger() ],
2346
+                    $supports[$this->_message_template_group->messenger()],
2347 2347
                     true
2348 2348
                 )
2349 2349
             ) {
@@ -2367,7 +2367,7 @@  discard block
 block discarded – undo
2367 2367
         }
2368 2368
 
2369 2369
         // setup variation select values for the currently selected template.
2370
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2371 2371
             $this->_message_template_group->messenger(),
2372 2372
             $this->_message_template_group->message_type()
2373 2373
         );
@@ -2381,12 +2381,12 @@  discard block
 block discarded – undo
2381 2381
 
2382 2382
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2383 2383
 
2384
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2385 2385
             'MTP_template_pack',
2386 2386
             $tp_select_values,
2387 2387
             $this->_message_template_group->get_template_pack_name()
2388 2388
         );
2389
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2390 2390
             'MTP_template_variation',
2391 2391
             $variations_select_values,
2392 2392
             $this->_message_template_group->get_template_pack_variation()
@@ -2396,7 +2396,7 @@  discard block
 block discarded – undo
2396 2396
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2397 2397
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2398 2398
 
2399
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2400 2400
 
2401 2401
         EEH_Template::display_template($template, $template_args);
2402 2402
     }
@@ -2422,33 +2422,33 @@  discard block
 block discarded – undo
2422 2422
         // first we need to see if there are any fields
2423 2423
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2424 2424
 
2425
-        if (! empty($fields)) {
2425
+        if ( ! empty($fields)) {
2426 2426
             // yup there be fields
2427 2427
             foreach ($fields as $field => $config) {
2428
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2429 2429
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2430 2430
                 $default  = isset($config['default']) ? $config['default'] : '';
2431 2431
                 $default  = isset($config['value']) ? $config['value'] : $default;
2432 2432
 
2433 2433
                 // if type is hidden and the value is empty
2434 2434
                 // something may have gone wrong so let's correct with the defaults
2435
-                $fix                = $config['input'] === 'hidden'
2436
-                                      && isset($existing[ $field ])
2437
-                                      && empty($existing[ $field ])
2435
+                $fix = $config['input'] === 'hidden'
2436
+                                      && isset($existing[$field])
2437
+                                      && empty($existing[$field])
2438 2438
                     ? $default
2439 2439
                     : '';
2440
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2441
-                    ? $existing[ $field ]
2440
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2441
+                    ? $existing[$field]
2442 2442
                     : $fix;
2443 2443
 
2444
-                $template_form_fields[ $field_id ] = [
2445
-                    'name'       => 'test_settings_fld[' . $field . ']',
2444
+                $template_form_fields[$field_id] = [
2445
+                    'name'       => 'test_settings_fld['.$field.']',
2446 2446
                     'label'      => $config['label'],
2447 2447
                     'input'      => $config['input'],
2448 2448
                     'type'       => $config['type'],
2449 2449
                     'required'   => $config['required'],
2450 2450
                     'validation' => $config['validation'],
2451
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2452 2452
                     'css_class'  => $config['css_class'],
2453 2453
                     'options'    => isset($config['options']) ? $config['options'] : [],
2454 2454
                     'default'    => $default,
@@ -2462,7 +2462,7 @@  discard block
 block discarded – undo
2462 2462
             : '';
2463 2463
 
2464 2464
         // print out $test_settings_fields
2465
-        if (! empty($test_settings_html)) {
2465
+        if ( ! empty($test_settings_html)) {
2466 2466
             $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2467 2467
             $test_settings_html .= 'name="test_button" value="';
2468 2468
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2508,7 +2508,7 @@  discard block
 block discarded – undo
2508 2508
         ];
2509 2509
 
2510 2510
         return EEH_Template::display_template(
2511
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2512 2512
             $template_args,
2513 2513
             true
2514 2514
         );
@@ -2534,7 +2534,7 @@  discard block
 block discarded – undo
2534 2534
         // $messenger = $this->_message_template_group->messenger_obj();
2535 2535
         // now let's set the content depending on the status of the shortcodes array
2536 2536
         if (empty($shortcodes)) {
2537
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2538 2538
             return;
2539 2539
         }
2540 2540
         ?>
@@ -2570,7 +2570,7 @@  discard block
 block discarded – undo
2570 2570
     {
2571 2571
 
2572 2572
         // no need to run this if the property is already set
2573
-        if (! empty($this->_shortcodes)) {
2573
+        if ( ! empty($this->_shortcodes)) {
2574 2574
             return;
2575 2575
         }
2576 2576
 
@@ -2625,7 +2625,7 @@  discard block
 block discarded – undo
2625 2625
     protected function _set_message_template_group()
2626 2626
     {
2627 2627
         // get out if this is already set.
2628
-        if (! empty($this->_message_template_group)) {
2628
+        if ( ! empty($this->_message_template_group)) {
2629 2629
             return;
2630 2630
         }
2631 2631
 
@@ -2671,8 +2671,8 @@  discard block
 block discarded – undo
2671 2671
                     <?php
2672 2672
                 }
2673 2673
                 // setup nonce_url
2674
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2675
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2674
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2675
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2676 2676
                 ?>
2677 2677
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2678 2678
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2685,7 +2685,7 @@  discard block
 block discarded – undo
2685 2685
                             $checked = ($context === $args['context']) ? 'selected' : '';
2686 2686
                             ?>
2687 2687
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2688
-                                <?php echo esc_html($context_details[ $context ]['label']); ?>
2688
+                                <?php echo esc_html($context_details[$context]['label']); ?>
2689 2689
                             </option>
2690 2690
                         <?php endforeach;
2691 2691
                     endif; ?>
@@ -3076,7 +3076,7 @@  discard block
 block discarded – undo
3076 3076
     {
3077 3077
         if (is_array($content)) {
3078 3078
             foreach ($content as $key => $value) {
3079
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3079
+                $content[$key] = $this->sanitizeMessageTemplateContent($value);
3080 3080
             }
3081 3081
             return $content;
3082 3082
         }
@@ -3114,7 +3114,7 @@  discard block
 block discarded – undo
3114 3114
 
3115 3115
         $context   = ucwords(str_replace('_', ' ', $context));
3116 3116
         $item_desc = $messenger_label && $message_type_label
3117
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3117
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
3118 3118
             : '';
3119 3119
         $item_desc .= 'Message Template';
3120 3120
         return $item_desc;
@@ -3266,7 +3266,7 @@  discard block
 block discarded – undo
3266 3266
         if ($all) {
3267 3267
             // Checkboxes
3268 3268
             $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
-            if (! empty($checkboxes)) {
3269
+            if ( ! empty($checkboxes)) {
3270 3270
                 // if array has more than one element then success message should be plural.
3271 3271
                 // todo: what about nonce?
3272 3272
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -3276,18 +3276,18 @@  discard block
 block discarded – undo
3276 3276
                     $trashed_or_restored = $trash
3277 3277
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278 3278
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
-                    if (! $trashed_or_restored) {
3279
+                    if ( ! $trashed_or_restored) {
3280 3280
                         $success = 0;
3281 3281
                     }
3282 3282
                 }
3283 3283
             } else {
3284 3284
                 // grab single GRP_ID and handle
3285 3285
                 $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
-                if (! empty($GRP_ID)) {
3286
+                if ( ! empty($GRP_ID)) {
3287 3287
                     $trashed_or_restored = $trash
3288 3288
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289 3289
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
-                    if (! $trashed_or_restored) {
3290
+                    if ( ! $trashed_or_restored) {
3291 3291
                         $success = 0;
3292 3292
                     }
3293 3293
                 } else {
@@ -3335,7 +3335,7 @@  discard block
 block discarded – undo
3335 3335
 
3336 3336
         // checkboxes
3337 3337
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
-        if (! empty($checkboxes)) {
3338
+        if ( ! empty($checkboxes)) {
3339 3339
             // if array has more than one element then success message should be plural
3340 3340
             $success = count($checkboxes) > 1 ? 2 : 1;
3341 3341
 
@@ -3439,7 +3439,7 @@  discard block
 block discarded – undo
3439 3439
     protected function _set_m_mt_settings()
3440 3440
     {
3441 3441
         // first if this is already set then lets get out no need to regenerate data.
3442
-        if (! empty($this->_m_mt_settings)) {
3442
+        if ( ! empty($this->_m_mt_settings)) {
3443 3443
             return;
3444 3444
         }
3445 3445
 
@@ -3452,8 +3452,8 @@  discard block
 block discarded – undo
3452 3452
 
3453 3453
         foreach ($messengers as $messenger) {
3454 3454
             $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3455
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3456
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
+            $class = 'ee-messenger-'.sanitize_key($messenger->label['singular']);
3456
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3457 3457
                 'label' => ucwords($messenger->label['singular']),
3458 3458
                 'class' => $active ? "{$class} messenger-active" : $class,
3459 3459
                 'href'  => $messenger->name,
@@ -3471,7 +3471,7 @@  discard block
 block discarded – undo
3471 3471
             foreach ($message_types as $message_type) {
3472 3472
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3473 3473
                 // it shouldn't show in either the inactive OR active metabox.
3474
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3474
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3475 3475
                     continue;
3476 3476
                 }
3477 3477
 
@@ -3482,12 +3482,12 @@  discard block
 block discarded – undo
3482 3482
                     ? 'active'
3483 3483
                     : 'inactive';
3484 3484
 
3485
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3485
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3486 3486
                     'label'    => ucwords($message_type->label['singular']),
3487
-                    'class'    => 'message-type-' . $a_or_i,
3488
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3489
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3490
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3487
+                    'class'    => 'message-type-'.$a_or_i,
3488
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3489
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3490
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3491 3491
                     'title'    => $a_or_i === 'active'
3492 3492
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3493 3493
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3518,25 +3518,25 @@  discard block
 block discarded – undo
3518 3518
         $fields                                         = $message_type->get_admin_settings_fields();
3519 3519
         $settings_template_args['template_form_fields'] = '';
3520 3520
 
3521
-        if (! empty($fields) && $active) {
3521
+        if ( ! empty($fields) && $active) {
3522 3522
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3523 3523
             foreach ($fields as $fldname => $fldprops) {
3524
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3525
-                $template_form_field[ $field_id ] = [
3526
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3524
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3525
+                $template_form_field[$field_id] = [
3526
+                    'name'       => 'message_type_settings['.$fldname.']',
3527 3527
                     'label'      => $fldprops['label'],
3528 3528
                     'input'      => $fldprops['field_type'],
3529 3529
                     'type'       => $fldprops['value_type'],
3530 3530
                     'required'   => $fldprops['required'],
3531 3531
                     'validation' => $fldprops['validation'],
3532
-                    'value'      => isset($existing_settings[ $fldname ])
3533
-                        ? $existing_settings[ $fldname ]
3532
+                    'value'      => isset($existing_settings[$fldname])
3533
+                        ? $existing_settings[$fldname]
3534 3534
                         : $fldprops['default'],
3535 3535
                     'options'    => isset($fldprops['options'])
3536 3536
                         ? $fldprops['options']
3537 3537
                         : [],
3538
-                    'default'    => isset($existing_settings[ $fldname ])
3539
-                        ? $existing_settings[ $fldname ]
3538
+                    'default'    => isset($existing_settings[$fldname])
3539
+                        ? $existing_settings[$fldname]
3540 3540
                         : $fldprops['default'],
3541 3541
                     'css_class'  => 'no-drag',
3542 3542
                     'format'     => $fldprops['format'],
@@ -3556,15 +3556,15 @@  discard block
 block discarded – undo
3556 3556
         $settings_template_args['description'] = $message_type->description;
3557 3557
         // we also need some hidden fields
3558 3558
         $hidden_fields = [
3559
-            'message_type_settings[messenger]' . $message_type->name    => [
3559
+            'message_type_settings[messenger]'.$message_type->name    => [
3560 3560
                 'type'  => 'hidden',
3561 3561
                 'value' => $messenger->name,
3562 3562
             ],
3563
-            'message_type_settings[message_type]' . $message_type->name => [
3563
+            'message_type_settings[message_type]'.$message_type->name => [
3564 3564
                 'type'  => 'hidden',
3565 3565
                 'value' => $message_type->name,
3566 3566
             ],
3567
-            'type' . $message_type->name                                => [
3567
+            'type'.$message_type->name                                => [
3568 3568
                 'type'  => 'hidden',
3569 3569
                 'value' => 'message_type',
3570 3570
             ],
@@ -3574,12 +3574,12 @@  discard block
 block discarded – undo
3574 3574
             $hidden_fields,
3575 3575
             'array'
3576 3576
         );
3577
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3577
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3578 3578
             ? ' hidden'
3579 3579
             : '';
3580 3580
 
3581 3581
 
3582
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3582
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3583 3583
         return EEH_Template::display_template($template, $settings_template_args, true);
3584 3584
     }
3585 3585
 
@@ -3607,21 +3607,21 @@  discard block
 block discarded – undo
3607 3607
 
3608 3608
                 // messenger meta boxes
3609 3609
                 $active         = $selected_messenger === $messenger;
3610
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3611
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3610
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3611
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3612 3612
                     : '';
3613 3613
 
3614
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3614
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3615 3615
                     esc_html__('%s Settings', 'event_espresso'),
3616 3616
                     $tab_array['label']
3617 3617
                 );
3618 3618
 
3619
-                $m_template_args[ $messenger . '_a_box' ] = [
3619
+                $m_template_args[$messenger.'_a_box'] = [
3620 3620
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3621 3621
                     'inactive_message_types' => isset(
3622
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3622
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3623 3623
                     )
3624
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3624
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3625 3625
                         : '',
3626 3626
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3627 3627
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3633,13 +3633,13 @@  discard block
 block discarded – undo
3633 3633
                 // message type meta boxes
3634 3634
                 // (which is really just the inactive container for each messenger
3635 3635
                 // showing inactive message types for that messenger)
3636
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3637
-                $mt_template_args[ $messenger . '_i_box' ] = [
3636
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3637
+                $mt_template_args[$messenger.'_i_box'] = [
3638 3638
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3639 3639
                     'inactive_message_types' => isset(
3640
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3640
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3641 3641
                     )
3642
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3642
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3643 3643
                         : '',
3644 3644
                     'hidden'                 => $active ? '' : ' hidden',
3645 3645
                     'hide_on_message'        => $hide_on_message,
@@ -3652,14 +3652,14 @@  discard block
 block discarded – undo
3652 3652
 
3653 3653
 
3654 3654
         // register messenger metaboxes
3655
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3655
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3656 3656
         foreach ($m_boxes as $box => $label) {
3657
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3657
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3658 3658
             $msgr          = str_replace('_a_box', '', $box);
3659 3659
             $this->addMetaBox(
3660
-                'espresso_' . $msgr . '_settings',
3660
+                'espresso_'.$msgr.'_settings',
3661 3661
                 $label,
3662
-                function ($post, $metabox) {
3662
+                function($post, $metabox) {
3663 3663
                     EEH_Template::display_template(
3664 3664
                         $metabox['args']['template_path'],
3665 3665
                         $metabox['args']['template_args']
@@ -3673,17 +3673,17 @@  discard block
 block discarded – undo
3673 3673
         }
3674 3674
 
3675 3675
         // register message type metaboxes
3676
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3676
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3677 3677
         foreach ($mt_boxes as $box => $label) {
3678 3678
             $callback_args = [
3679 3679
                 'template_path' => $mt_template_path,
3680
-                'template_args' => $mt_template_args[ $box ],
3680
+                'template_args' => $mt_template_args[$box],
3681 3681
             ];
3682
-            $mt            = str_replace('_i_box', '', $box);
3682
+            $mt = str_replace('_i_box', '', $box);
3683 3683
             $this->addMetaBox(
3684
-                'espresso_' . $mt . '_inactive_mts',
3684
+                'espresso_'.$mt.'_inactive_mts',
3685 3685
                 $label,
3686
-                function ($post, $metabox) {
3686
+                function($post, $metabox) {
3687 3687
                     EEH_Template::display_template(
3688 3688
                         $metabox['args']['template_path'],
3689 3689
                         $metabox['args']['template_args']
@@ -3830,7 +3830,7 @@  discard block
 block discarded – undo
3830 3830
             if ($form->is_valid()) {
3831 3831
                 $valid_data = $form->valid_data();
3832 3832
                 foreach ($valid_data as $property => $value) {
3833
-                    $setter = 'set_' . $property;
3833
+                    $setter = 'set_'.$property;
3834 3834
                     if (method_exists($network_config, $setter)) {
3835 3835
                         $network_config->{$setter}($value);
3836 3836
                     } elseif (
@@ -3866,7 +3866,7 @@  discard block
 block discarded – undo
3866 3866
     protected function _get_mt_tabs($tab_array)
3867 3867
     {
3868 3868
         $tab_array = (array) $tab_array;
3869
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3869
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3870 3870
         $tabs      = '';
3871 3871
 
3872 3872
         foreach ($tab_array as $tab) {
@@ -3894,20 +3894,20 @@  discard block
 block discarded – undo
3894 3894
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3895 3895
 
3896 3896
 
3897
-        if (! empty($fields)) {
3897
+        if ( ! empty($fields)) {
3898 3898
             $existing_settings = $messenger->get_existing_admin_settings();
3899 3899
 
3900 3900
             foreach ($fields as $fldname => $fldprops) {
3901
-                $field_id                         = $messenger->name . '-' . $fldname;
3902
-                $template_form_field[ $field_id ] = [
3903
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3901
+                $field_id                         = $messenger->name.'-'.$fldname;
3902
+                $template_form_field[$field_id] = [
3903
+                    'name'       => 'messenger_settings['.$field_id.']',
3904 3904
                     'label'      => $fldprops['label'],
3905 3905
                     'input'      => $fldprops['field_type'],
3906 3906
                     'type'       => $fldprops['value_type'],
3907 3907
                     'required'   => $fldprops['required'],
3908 3908
                     'validation' => $fldprops['validation'],
3909
-                    'value'      => isset($existing_settings[ $field_id ])
3910
-                        ? $existing_settings[ $field_id ]
3909
+                    'value'      => isset($existing_settings[$field_id])
3910
+                        ? $existing_settings[$field_id]
3911 3911
                         : $fldprops['default'],
3912 3912
                     'css_class'  => '',
3913 3913
                     'format'     => $fldprops['format'],
@@ -3922,20 +3922,20 @@  discard block
 block discarded – undo
3922 3922
 
3923 3923
         // we also need some hidden fields
3924 3924
         $settings_template_args['hidden_fields'] = [
3925
-            'messenger_settings[messenger]' . $messenger->name => [
3925
+            'messenger_settings[messenger]'.$messenger->name => [
3926 3926
                 'type'  => 'hidden',
3927 3927
                 'value' => $messenger->name,
3928 3928
             ],
3929
-            'type' . $messenger->name                          => [
3929
+            'type'.$messenger->name                          => [
3930 3930
                 'type'  => 'hidden',
3931 3931
                 'value' => 'messenger',
3932 3932
             ],
3933 3933
         ];
3934 3934
 
3935 3935
         // make sure any active message types that are existing are included in the hidden fields
3936
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3937
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3938
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3937
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3938
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3939 3939
                     'type'  => 'hidden',
3940 3940
                     'value' => $mt,
3941 3941
                 ];
@@ -3945,7 +3945,7 @@  discard block
 block discarded – undo
3945 3945
             $settings_template_args['hidden_fields'],
3946 3946
             'array'
3947 3947
         );
3948
-        $active                                  =
3948
+        $active =
3949 3949
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3950 3950
 
3951 3951
         $settings_template_args['messenger']           = $messenger->name;
@@ -3965,9 +3965,9 @@  discard block
 block discarded – undo
3965 3965
 
3966 3966
 
3967 3967
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3968
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3968
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3969 3969
         $settings_template_args['on_off_status'] = $active;
3970
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3970
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3971 3971
         return EEH_Template::display_template(
3972 3972
             $template,
3973 3973
             $settings_template_args,
@@ -3992,7 +3992,7 @@  discard block
 block discarded – undo
3992 3992
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3993 3993
         // let's check that we have required data
3994 3994
 
3995
-        if (! $this->_active_messenger_name) {
3995
+        if ( ! $this->_active_messenger_name) {
3996 3996
             EE_Error::add_error(
3997 3997
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3998 3998
                 __FILE__,
@@ -4010,7 +4010,7 @@  discard block
 block discarded – undo
4010 4010
 
4011 4011
 
4012 4012
         $status = $this->request->getRequestParam('status');
4013
-        if (! $status) {
4013
+        if ( ! $status) {
4014 4014
             EE_Error::add_error(
4015 4015
                 esc_html__(
4016 4016
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4067,7 +4067,7 @@  discard block
 block discarded – undo
4067 4067
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
4068 4068
 
4069 4069
         // let's make sure we have the necessary data
4070
-        if (! $this->_active_message_type_name) {
4070
+        if ( ! $this->_active_message_type_name) {
4071 4071
             EE_Error::add_error(
4072 4072
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4073 4073
                 __FILE__,
@@ -4077,7 +4077,7 @@  discard block
 block discarded – undo
4077 4077
             $success = false;
4078 4078
         }
4079 4079
 
4080
-        if (! $this->_active_messenger_name) {
4080
+        if ( ! $this->_active_messenger_name) {
4081 4081
             EE_Error::add_error(
4082 4082
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4083 4083
                 __FILE__,
@@ -4088,7 +4088,7 @@  discard block
 block discarded – undo
4088 4088
         }
4089 4089
 
4090 4090
         $status = $this->request->getRequestParam('status');
4091
-        if (! $status) {
4091
+        if ( ! $status) {
4092 4092
             EE_Error::add_error(
4093 4093
                 esc_html__(
4094 4094
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4300,7 +4300,7 @@  discard block
 block discarded – undo
4300 4300
         EE_Message_Type $message_type = null
4301 4301
     ) {
4302 4302
         // if $messenger isn't a valid messenger object then get out.
4303
-        if (! $messenger instanceof EE_Messenger) {
4303
+        if ( ! $messenger instanceof EE_Messenger) {
4304 4304
             EE_Error::add_error(
4305 4305
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4306 4306
                 __FILE__,
@@ -4354,7 +4354,7 @@  discard block
 block discarded – undo
4354 4354
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4355 4355
             // in which case we just give a success message for the messenger being successfully activated.
4356 4356
         } else {
4357
-            if (! $messenger->get_default_message_types()) {
4357
+            if ( ! $messenger->get_default_message_types()) {
4358 4358
                 // messenger doesn't have any default message types so still a success.
4359 4359
                 EE_Error::add_success(
4360 4360
                     sprintf(
@@ -4410,7 +4410,7 @@  discard block
 block discarded – undo
4410 4410
         EE_Error::overwrite_success();
4411 4411
 
4412 4412
         // if $messenger isn't a valid messenger object then get out.
4413
-        if (! $messenger instanceof EE_Messenger) {
4413
+        if ( ! $messenger instanceof EE_Messenger) {
4414 4414
             EE_Error::add_error(
4415 4415
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4416 4416
                 __FILE__,
@@ -4480,7 +4480,7 @@  discard block
 block discarded – undo
4480 4480
      */
4481 4481
     public function update_mt_form()
4482 4482
     {
4483
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4483
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4484 4484
             EE_Error::add_error(
4485 4485
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4486 4486
                 __FILE__,
@@ -4491,7 +4491,7 @@  discard block
 block discarded – undo
4491 4491
         }
4492 4492
 
4493 4493
         $message_types = $this->get_installed_message_types();
4494
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4494
+        $message_type  = $message_types[$this->_active_message_type_name];
4495 4495
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4496 4496
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4497 4497
 
@@ -4510,7 +4510,7 @@  discard block
 block discarded – undo
4510 4510
     public function save_settings()
4511 4511
     {
4512 4512
         $type = $this->request->getRequestParam('type');
4513
-        if (! $type) {
4513
+        if ( ! $type) {
4514 4514
             EE_Error::add_error(
4515 4515
                 esc_html__(
4516 4516
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.
messages/templates/ee_msg_details_main_edit_meta_box.template.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
     <input type="hidden" id="ee-msg-current-context" name="MTP_context" value="<?php echo esc_attr($context); ?>" />
24 24
     <!-- if this is not a global template then let's show the name and description fields -->
25 25
     <?php
26
-    if (! $MTP->is_global()) : ?>
26
+	if (! $MTP->is_global()) : ?>
27 27
         <div class="non-global-mtp-fields">
28 28
             <div class="ee-info-box">
29 29
                 <p>
30 30
                     <?php esc_html_e(
31
-                        'This is a custom template.  Custom Templates have an editable name and description to help you differentiate between templates.',
32
-                        'event_espresso'
33
-                    ); ?>
31
+						'This is a custom template.  Custom Templates have an editable name and description to help you differentiate between templates.',
32
+						'event_espresso'
33
+					); ?>
34 34
                 </p>
35 35
             </div>
36 36
             <div id="titlediv">
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
             </p>
60 60
         </div>
61 61
         <?php
62
-    else :
63
-        ?>
62
+	else :
63
+		?>
64 64
         <input type="hidden" name="ee_msg_non_global_fields[MTP_name]" value="<?php echo esc_attr($MTP->name()); ?>">
65 65
         <input type="hidden"
66 66
                name="ee_msg_non_global_fields[MTP_description]"
@@ -69,18 +69,18 @@  discard block
 block discarded – undo
69 69
     <?php endif; ?>
70 70
     <!-- we need to loop through the template_fields so we know our structure -->
71 71
     <?php
72
-    if (isset($template_fields) && ! empty($template_fields) && ! is_wp_error($template_fields)) {
73
-        echo wp_kses($template_fields, AllowedTags::getWithFormTags());
74
-    } else {
75
-        ?>
72
+	if (isset($template_fields) && ! empty($template_fields) && ! is_wp_error($template_fields)) {
73
+		echo wp_kses($template_fields, AllowedTags::getWithFormTags());
74
+	} else {
75
+		?>
76 76
         <p>
77 77
             <?php esc_html_e(
78
-                'Something has gone wrong, there are no template fields to output.',
79
-                'event_espresso'
80
-            ); ?>
78
+				'Something has gone wrong, there are no template fields to output.',
79
+				'event_espresso'
80
+			); ?>
81 81
         </p>
82 82
         <?php
83
-    }
83
+	}
84 84
 
85
-    ?>
85
+	?>
86 86
 </div> <!-- end #admin-primary-mbox-dv -->
Please login to merge, or discard this patch.
admin_pages/messages/templates/ee_msg_m_settings_content.template.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -45,9 +45,9 @@
 block discarded – undo
45 45
         <form method="POST" action="" class="mt-settings-form">
46 46
             <?php echo wp_kses($template_form_fields, AllowedTags::getWithFormTags()); ?>
47 47
             <?php
48
-            foreach ($hidden_fields as $name => $field) {
49
-                echo wp_kses($field['field'], AllowedTags::getWithFormTags());
50
-            } ?>
48
+			foreach ($hidden_fields as $name => $field) {
49
+				echo wp_kses($field['field'], AllowedTags::getWithFormTags());
50
+			} ?>
51 51
             <input type="submit"
52 52
                    value="<?php esc_attr_e('Submit', 'event_espresso'); ?>"
53 53
                    class="button--secondary no-drag"
Please login to merge, or discard this patch.
admin_pages/messages/templates/ee_msg_mt_settings_content.template.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@
 block discarded – undo
18 18
     <div class="mt-settings">
19 19
         <form method="POST" action="" class="mt-settings-form<?php echo esc_attr($show_form); ?>">
20 20
             <?php
21
-            echo wp_kses($template_form_fields, AllowedTags::getWithFormTags());
22
-            foreach ($hidden_fields as $field) {
23
-                echo wp_kses($field['field'], AllowedTags::getWithFormTags());
24
-            }
25
-            ?>
21
+			echo wp_kses($template_form_fields, AllowedTags::getWithFormTags());
22
+			foreach ($hidden_fields as $field) {
23
+				echo wp_kses($field['field'], AllowedTags::getWithFormTags());
24
+			}
25
+			?>
26 26
             <input class='button--secondary mt-settings-submit no-drag'
27 27
                    type="submit"
28 28
                    value="<?php esc_attr_e('Submit', 'event_espresso'); ?>"
Please login to merge, or discard this patch.
admin_pages/general_settings/General_Settings_Admin_Page.core.php 1 patch
Indentation   +1405 added lines, -1405 removed lines patch added patch discarded remove patch
@@ -20,1422 +20,1422 @@
 block discarded – undo
20 20
 class General_Settings_Admin_Page extends EE_Admin_Page
21 21
 {
22 22
 
23
-    /**
24
-     * @var EE_Core_Config
25
-     */
26
-    public $core_config;
27
-
28
-
29
-    /**
30
-     * Initialize basic properties.
31
-     */
32
-    protected function _init_page_props()
33
-    {
34
-        $this->page_slug        = GEN_SET_PG_SLUG;
35
-        $this->page_label       = GEN_SET_LABEL;
36
-        $this->_admin_base_url  = GEN_SET_ADMIN_URL;
37
-        $this->_admin_base_path = GEN_SET_ADMIN;
38
-    }
39
-
40
-
41
-    /**
42
-     * Set ajax hooks
43
-     */
44
-    protected function _ajax_hooks()
45
-    {
46
-        add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']);
47
-        add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']);
48
-        add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3);
49
-        add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']);
50
-    }
51
-
52
-
53
-    /**
54
-     * More page properties initialization.
55
-     */
56
-    protected function _define_page_props()
57
-    {
58
-        $this->_admin_page_title = GEN_SET_LABEL;
59
-        $this->_labels           = ['publishbox' => esc_html__('Update Settings', 'event_espresso')];
60
-    }
61
-
62
-
63
-    /**
64
-     * Set page routes property.
65
-     */
66
-    protected function _set_page_routes()
67
-    {
68
-        $this->_page_routes = [
69
-            'critical_pages'                => [
70
-                'func'       => '_espresso_page_settings',
71
-                'capability' => 'manage_options',
72
-            ],
73
-            'update_espresso_page_settings' => [
74
-                'func'       => '_update_espresso_page_settings',
75
-                'capability' => 'manage_options',
76
-                'noheader'   => true,
77
-            ],
78
-            'default'                       => [
79
-                'func'       => '_your_organization_settings',
80
-                'capability' => 'manage_options',
81
-            ],
82
-
83
-            'update_your_organization_settings' => [
84
-                'func'       => '_update_your_organization_settings',
85
-                'capability' => 'manage_options',
86
-                'noheader'   => true,
87
-            ],
88
-
89
-            'admin_option_settings' => [
90
-                'func'       => '_admin_option_settings',
91
-                'capability' => 'manage_options',
92
-            ],
93
-
94
-            'update_admin_option_settings' => [
95
-                'func'       => '_update_admin_option_settings',
96
-                'capability' => 'manage_options',
97
-                'noheader'   => true,
98
-            ],
99
-
100
-            'country_settings' => [
101
-                'func'       => '_country_settings',
102
-                'capability' => 'manage_options',
103
-            ],
104
-
105
-            'update_country_settings' => [
106
-                'func'       => '_update_country_settings',
107
-                'capability' => 'manage_options',
108
-                'noheader'   => true,
109
-            ],
110
-
111
-            'display_country_settings' => [
112
-                'func'       => 'display_country_settings',
113
-                'capability' => 'manage_options',
114
-                'noheader'   => true,
115
-            ],
116
-
117
-            'add_new_state' => [
118
-                'func'       => 'add_new_state',
119
-                'capability' => 'manage_options',
120
-                'noheader'   => true,
121
-            ],
122
-
123
-            'delete_state'            => [
124
-                'func'       => 'delete_state',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ],
128
-            'privacy_settings'        => [
129
-                'func'       => 'privacySettings',
130
-                'capability' => 'manage_options',
131
-            ],
132
-            'update_privacy_settings' => [
133
-                'func'               => 'updatePrivacySettings',
134
-                'capability'         => 'manage_options',
135
-                'noheader'           => true,
136
-                'headers_sent_route' => 'privacy_settings',
137
-            ],
138
-        ];
139
-    }
140
-
141
-
142
-    /**
143
-     * Set page configuration property
144
-     */
145
-    protected function _set_page_config()
146
-    {
147
-        $this->_page_config = [
148
-            'critical_pages'        => [
149
-                'nav'           => [
150
-                    'label' => esc_html__('Critical Pages', 'event_espresso'),
151
-                    'order' => 50,
152
-                ],
153
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
154
-                'help_tabs'     => [
155
-                    'general_settings_critical_pages_help_tab' => [
156
-                        'title'    => esc_html__('Critical Pages', 'event_espresso'),
157
-                        'filename' => 'general_settings_critical_pages',
158
-                    ],
159
-                ],
160
-                'require_nonce' => false,
161
-            ],
162
-            'default'               => [
163
-                'nav'           => [
164
-                    'label' => esc_html__('Your Organization', 'event_espresso'),
165
-                    'order' => 20,
166
-                ],
167
-                'help_tabs'     => [
168
-                    'general_settings_your_organization_help_tab' => [
169
-                        'title'    => esc_html__('Your Organization', 'event_espresso'),
170
-                        'filename' => 'general_settings_your_organization',
171
-                    ],
172
-                ],
173
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
174
-                'require_nonce' => false,
175
-            ],
176
-            'admin_option_settings' => [
177
-                'nav'           => [
178
-                    'label' => esc_html__('Admin Options', 'event_espresso'),
179
-                    'order' => 60,
180
-                ],
181
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
182
-                'help_tabs'     => [
183
-                    'general_settings_admin_options_help_tab' => [
184
-                        'title'    => esc_html__('Admin Options', 'event_espresso'),
185
-                        'filename' => 'general_settings_admin_options',
186
-                    ],
187
-                ],
188
-                'require_nonce' => false,
189
-            ],
190
-            'country_settings'      => [
191
-                'nav'           => [
192
-                    'label' => esc_html__('Countries', 'event_espresso'),
193
-                    'order' => 70,
194
-                ],
195
-                'help_tabs'     => [
196
-                    'general_settings_countries_help_tab' => [
197
-                        'title'    => esc_html__('Countries', 'event_espresso'),
198
-                        'filename' => 'general_settings_countries',
199
-                    ],
200
-                ],
201
-                'require_nonce' => false,
202
-            ],
203
-            'privacy_settings'      => [
204
-                'nav'           => [
205
-                    'label' => esc_html__('Privacy', 'event_espresso'),
206
-                    'order' => 80,
207
-                ],
208
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
209
-                'require_nonce' => false,
210
-            ],
211
-        ];
212
-    }
213
-
214
-
215
-    protected function _add_screen_options()
216
-    {
217
-    }
218
-
219
-
220
-    protected function _add_feature_pointers()
221
-    {
222
-    }
223
-
224
-
225
-    /**
226
-     * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
227
-     */
228
-    public function load_scripts_styles()
229
-    {
230
-        // styles
231
-        wp_enqueue_style('espresso-ui-theme');
232
-        // scripts
233
-        wp_enqueue_script('ee_admin_js');
234
-    }
235
-
236
-
237
-    /**
238
-     * Execute logic running on `admin_init`
239
-     */
240
-    public function admin_init()
241
-    {
242
-        $this->core_config = EE_Registry::instance()->CFG->core;
243
-
244
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(
245
-            esc_html__(
246
-                'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
247
-                'event_espresso'
248
-            )
249
-        );
250
-        EE_Registry::$i18n_js_strings['error_occurred']          = wp_strip_all_tags(
251
-            esc_html__(
252
-                'An error occurred! Please refresh the page and try again.',
253
-                'event_espresso'
254
-            )
255
-        );
256
-        EE_Registry::$i18n_js_strings['confirm_delete_state']    = wp_strip_all_tags(
257
-            esc_html__(
258
-                'Are you sure you want to delete this State / Province?',
259
-                'event_espresso'
260
-            )
261
-        );
262
-        EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
263
-            'admin-ajax.php?page=espresso_general_settings',
264
-            is_ssl() ? 'https://' : 'http://'
265
-        );
266
-    }
267
-
268
-
269
-    public function admin_notices()
270
-    {
271
-    }
272
-
273
-
274
-    public function admin_footer_scripts()
275
-    {
276
-    }
277
-
278
-
279
-    /**
280
-     * Enqueue scripts and styles for the default route.
281
-     */
282
-    public function load_scripts_styles_default()
283
-    {
284
-        // styles
285
-        wp_enqueue_style('thickbox');
286
-        // scripts
287
-        wp_enqueue_script('media-upload');
288
-        wp_enqueue_script('thickbox');
289
-        wp_register_script(
290
-            'organization_settings',
291
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
292
-            ['jquery', 'media-upload', 'thickbox'],
293
-            EVENT_ESPRESSO_VERSION,
294
-            true
295
-        );
296
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
297
-        wp_enqueue_script('organization_settings');
298
-        wp_enqueue_style('organization-css');
299
-        $confirm_image_delete = [
300
-            'text' => wp_strip_all_tags(
301
-                esc_html__(
302
-                    'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
303
-                    'event_espresso'
304
-                )
305
-            ),
306
-        ];
307
-        wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
308
-    }
309
-
310
-
311
-    /**
312
-     * Enqueue scripts and styles for the country settings route.
313
-     */
314
-    public function load_scripts_styles_country_settings()
315
-    {
316
-        // scripts
317
-        wp_register_script(
318
-            'gen_settings_countries',
319
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
320
-            ['ee_admin_js'],
321
-            EVENT_ESPRESSO_VERSION,
322
-            true
323
-        );
324
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
325
-        wp_enqueue_script('gen_settings_countries');
326
-        wp_enqueue_style('organization-css');
327
-    }
328
-
329
-
330
-    /*************        Espresso Pages        *************/
331
-    /**
332
-     * _espresso_page_settings
333
-     *
334
-     * @throws EE_Error
335
-     * @throws DomainException
336
-     * @throws DomainException
337
-     * @throws InvalidDataTypeException
338
-     * @throws InvalidArgumentException
339
-     */
340
-    protected function _espresso_page_settings()
341
-    {
342
-        // Check to make sure all of the main pages are set up properly,
343
-        // if not create the default pages and display an admin notice
344
-        EEH_Activation::verify_default_pages_exist();
345
-        $this->_transient_garbage_collection();
346
-
347
-        $this->_template_args['values']             = $this->_yes_no_values;
348
-
349
-        $this->_template_args['reg_page_id']        = $this->core_config->reg_page_id ?? null;
350
-        $this->_template_args['reg_page_obj']       = isset($this->core_config->reg_page_id)
351
-            ? get_post($this->core_config->reg_page_id)
352
-            : false;
353
-
354
-        $this->_template_args['txn_page_id']        = $this->core_config->txn_page_id ?? null;
355
-        $this->_template_args['txn_page_obj']       = isset($this->core_config->txn_page_id)
356
-            ? get_post($this->core_config->txn_page_id)
357
-            : false;
358
-
359
-        $this->_template_args['thank_you_page_id']  = $this->core_config->thank_you_page_id ?? null;
360
-        $this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id)
361
-            ? get_post($this->core_config->thank_you_page_id)
362
-            : false;
363
-
364
-        $this->_template_args['cancel_page_id']     = $this->core_config->cancel_page_id ?? null;
365
-        $this->_template_args['cancel_page_obj']    = isset($this->core_config->cancel_page_id)
366
-            ? get_post($this->core_config->cancel_page_id)
367
-            : false;
368
-
369
-        $this->_set_add_edit_form_tags('update_espresso_page_settings');
370
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
371
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
372
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
373
-            $this->_template_args,
374
-            true
375
-        );
376
-        $this->display_admin_page_with_sidebar();
377
-    }
378
-
379
-
380
-    /**
381
-     * Handler for updating espresso page settings.
382
-     *
383
-     * @throws EE_Error
384
-     */
385
-    protected function _update_espresso_page_settings()
386
-    {
387
-        // capture incoming request data && set page IDs
388
-        $this->core_config->reg_page_id       = $this->request->getRequestParam(
389
-            'reg_page_id',
390
-            $this->core_config->reg_page_id,
391
-            DataType::INT
392
-        );
393
-        $this->core_config->txn_page_id       = $this->request->getRequestParam(
394
-            'txn_page_id',
395
-            $this->core_config->txn_page_id,
396
-            DataType::INT
397
-        );
398
-        $this->core_config->thank_you_page_id = $this->request->getRequestParam(
399
-            'thank_you_page_id',
400
-            $this->core_config->thank_you_page_id,
401
-            DataType::INT
402
-        );
403
-        $this->core_config->cancel_page_id    = $this->request->getRequestParam(
404
-            'cancel_page_id',
405
-            $this->core_config->cancel_page_id,
406
-            DataType::INT
407
-        );
408
-
409
-        $this->core_config = apply_filters(
410
-            'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
411
-            $this->core_config,
412
-            $this->request->requestParams()
413
-        );
414
-
415
-        $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
416
-        $this->_redirect_after_action(
417
-            $this->_update_espresso_configuration(
418
-                $what,
419
-                $this->core_config,
420
-                __FILE__,
421
-                __FUNCTION__,
422
-                __LINE__
423
-            ),
424
-            $what,
425
-            '',
426
-            [
427
-                'action' => 'critical_pages',
428
-            ],
429
-            true
430
-        );
431
-    }
432
-
433
-
434
-    /*************        Your Organization        *************/
435
-
436
-
437
-    /**
438
-     * @throws DomainException
439
-     * @throws EE_Error
440
-     * @throws InvalidArgumentException
441
-     * @throws InvalidDataTypeException
442
-     * @throws InvalidInterfaceException
443
-     */
444
-    protected function _your_organization_settings()
445
-    {
446
-        $this->_template_args['admin_page_content'] = '';
447
-        try {
448
-            /** @var OrganizationSettings $organization_settings_form */
449
-            $organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
450
-
451
-            $this->_template_args['admin_page_content'] = EEH_HTML::div(
452
-                $organization_settings_form->display(),
453
-                '',
454
-                'padding'
455
-            );
456
-        } catch (Exception $e) {
457
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
458
-        }
459
-        $this->_set_add_edit_form_tags('update_your_organization_settings');
460
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
461
-        $this->display_admin_page_with_sidebar();
462
-    }
463
-
464
-
465
-    /**
466
-     * Handler for updating organization settings.
467
-     *
468
-     * @throws EE_Error
469
-     */
470
-    protected function _update_your_organization_settings()
471
-    {
472
-        try {
473
-            /** @var OrganizationSettings $organization_settings_form */
474
-            $organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
475
-
476
-            $success = $organization_settings_form->process($this->request->requestParams());
477
-
478
-            EE_Registry::instance()->CFG = apply_filters(
479
-                'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
480
-                EE_Registry::instance()->CFG
481
-            );
482
-        } catch (Exception $e) {
483
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
484
-            $success = false;
485
-        }
486
-
487
-        if ($success) {
488
-            $success = $this->_update_espresso_configuration(
489
-                esc_html__('Your Organization Settings', 'event_espresso'),
490
-                EE_Registry::instance()->CFG,
491
-                __FILE__,
492
-                __FUNCTION__,
493
-                __LINE__
494
-            );
495
-        }
496
-
497
-        $this->_redirect_after_action($success, '', '', ['action' => 'default'], true);
498
-    }
499
-
500
-
501
-
502
-    /*************        Admin Options        *************/
503
-
504
-
505
-    /**
506
-     * _admin_option_settings
507
-     *
508
-     * @throws EE_Error
509
-     * @throws LogicException
510
-     */
511
-    protected function _admin_option_settings()
512
-    {
513
-        $this->_template_args['admin_page_content'] = '';
514
-        try {
515
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
516
-            // still need this for the old school form in Extend_General_Settings_Admin_Page
517
-            $this->_template_args['values'] = $this->_yes_no_values;
518
-            // also need to account for the do_action that was in the old template
519
-            $admin_options_settings_form->setTemplateArgs($this->_template_args);
520
-            $this->_template_args['admin_page_content'] = EEH_HTML::div(
521
-                $admin_options_settings_form->display(),
522
-                '',
523
-                'padding'
524
-            );
525
-        } catch (Exception $e) {
526
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
527
-        }
528
-        $this->_set_add_edit_form_tags('update_admin_option_settings');
529
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
530
-        $this->display_admin_page_with_sidebar();
531
-    }
532
-
533
-
534
-    /**
535
-     * _update_admin_option_settings
536
-     *
537
-     * @throws EE_Error
538
-     * @throws InvalidDataTypeException
539
-     * @throws InvalidFormSubmissionException
540
-     * @throws InvalidArgumentException
541
-     * @throws LogicException
542
-     */
543
-    protected function _update_admin_option_settings()
544
-    {
545
-        try {
546
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
547
-            $admin_options_settings_form->process(
548
-                $this->request->getRequestParam(
549
-                    $admin_options_settings_form->slug(),
550
-                    [],
551
-                    DataType::STRING,
552
-                    true
553
-                )
554
-            );
555
-            EE_Registry::instance()->CFG->admin = apply_filters(
556
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
557
-                EE_Registry::instance()->CFG->admin
558
-            );
559
-        } catch (Exception $e) {
560
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
561
-        }
562
-        $this->_redirect_after_action(
563
-            apply_filters(
564
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
565
-                $this->_update_espresso_configuration(
566
-                    esc_html__('Admin Options', 'event_espresso'),
567
-                    EE_Registry::instance()->CFG->admin,
568
-                    __FILE__,
569
-                    __FUNCTION__,
570
-                    __LINE__
571
-                )
572
-            ),
573
-            esc_html__('Admin Options', 'event_espresso'),
574
-            'updated',
575
-            ['action' => 'admin_option_settings']
576
-        );
577
-    }
578
-
579
-
580
-    /*************        Countries        *************/
581
-
582
-
583
-    /**
584
-     * @param string|null $default
585
-     * @return string
586
-     */
587
-    protected function getCountryISO(?string $default = null): string
588
-    {
589
-        $default = $default ?? $this->getCountryIsoForSite();
590
-        $CNT_ISO = $this->request->getRequestParam('country', $default);
591
-        return strtoupper($CNT_ISO);
592
-    }
593
-
594
-
595
-    /**
596
-     * @return string
597
-     */
598
-    protected function getCountryIsoForSite(): string
599
-    {
600
-        return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
601
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
602
-            : 'US';
603
-    }
604
-
605
-
606
-    /**
607
-     * @param string          $CNT_ISO
608
-     * @param EE_Country|null $country
609
-     * @return EE_Base_Class|EE_Country
610
-     * @throws EE_Error
611
-     * @throws InvalidArgumentException
612
-     * @throws InvalidDataTypeException
613
-     * @throws InvalidInterfaceException
614
-     * @throws ReflectionException
615
-     */
616
-    protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null)
617
-    {
618
-        /** @var EE_Country $country */
619
-        return $country instanceof EE_Country && $country->ID() === $CNT_ISO
620
-            ? $country
621
-            : EEM_Country::instance()->get_one_by_ID($CNT_ISO);
622
-    }
623
-
624
-
625
-    /**
626
-     * Output Country Settings view.
627
-     *
628
-     * @throws DomainException
629
-     * @throws EE_Error
630
-     * @throws InvalidArgumentException
631
-     * @throws InvalidDataTypeException
632
-     * @throws InvalidInterfaceException
633
-     * @throws ReflectionException
634
-     */
635
-    protected function _country_settings()
636
-    {
637
-        $CNT_ISO = $this->getCountryISO();
638
-
639
-        $this->_template_args['values']    = $this->_yes_no_values;
640
-        $this->_template_args['countries'] = new EE_Question_Form_Input(
641
-            EE_Question::new_instance(
642
-                [
643
-                  'QST_ID'           => 0,
644
-                  'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
645
-                  'QST_system'       => 'admin-country',
646
-                ]
647
-            ),
648
-            EE_Answer::new_instance(
649
-                [
650
-                    'ANS_ID'    => 0,
651
-                    'ANS_value' => $CNT_ISO,
652
-                ]
653
-            ),
654
-            [
655
-                'input_id'       => 'country',
656
-                'input_name'     => 'country',
657
-                'input_prefix'   => '',
658
-                'append_qstn_id' => false,
659
-            ]
660
-        );
661
-
662
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO);
663
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10);
664
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10);
665
-        $this->_template_args['country_details_settings'] = $this->display_country_settings(
666
-            $country->ID(),
667
-            $country
668
-        );
669
-        $this->_template_args['country_states_settings']  = $this->display_country_states(
670
-            $country->ID(),
671
-            $country
672
-        );
673
-        $this->_template_args['CNT_name_for_site']        = $country->name();
674
-
675
-        $this->_set_add_edit_form_tags('update_country_settings');
676
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
677
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
678
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
679
-            $this->_template_args,
680
-            true
681
-        );
682
-        $this->display_admin_page_with_no_sidebar();
683
-    }
684
-
685
-
686
-    /**
687
-     * @param string          $CNT_ISO
688
-     * @param EE_Country|null $country
689
-     * @return string
690
-     * @throws DomainException
691
-     * @throws EE_Error
692
-     * @throws InvalidArgumentException
693
-     * @throws InvalidDataTypeException
694
-     * @throws InvalidInterfaceException
695
-     * @throws ReflectionException
696
-     */
697
-    public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string
698
-    {
699
-        $CNT_ISO          = $this->getCountryISO($CNT_ISO);
700
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
701
-
702
-        if (! $CNT_ISO) {
703
-            return '';
704
-        }
705
-
706
-        // for ajax
707
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
708
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
709
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
710
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
711
-        $country                                  = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
712
-        $CNT_cur_disabled                         = $CNT_ISO !== $CNT_ISO_for_site;
713
-        $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
714
-
715
-        $country_input_types            = [
716
-            'CNT_active'      => [
717
-                'type'             => 'RADIO_BTN',
718
-                'input_name'       => "cntry[$CNT_ISO]",
719
-                'class'            => '',
720
-                'options'          => $this->_yes_no_values,
721
-                'use_desc_4_label' => true,
722
-            ],
723
-            'CNT_ISO'         => [
724
-                'type'       => 'TEXT',
725
-                'input_name' => "cntry[$CNT_ISO]",
726
-                'class'      => 'ee-input-size--small',
727
-            ],
728
-            'CNT_ISO3'        => [
729
-                'type'       => 'TEXT',
730
-                'input_name' => "cntry[$CNT_ISO]",
731
-                'class'      => 'ee-input-size--small',
732
-            ],
733
-            // 'RGN_ID'          => [
734
-            //     'type'       => 'TEXT',
735
-            //     'input_name' => "cntry[$CNT_ISO]",
736
-            //     'class'      => 'ee-input-size--small',
737
-            // ],
738
-            'CNT_name'        => [
739
-                'type'       => 'TEXT',
740
-                'input_name' => "cntry[$CNT_ISO]",
741
-                'class'      => 'ee-input-size--big',
742
-            ],
743
-            'CNT_cur_code'    => [
744
-                'type'       => 'TEXT',
745
-                'input_name' => "cntry[$CNT_ISO]",
746
-                'class'      => 'ee-input-size--small',
747
-                'disabled'   => $CNT_cur_disabled,
748
-            ],
749
-            'CNT_cur_single'  => [
750
-                'type'       => 'TEXT',
751
-                'input_name' => "cntry[$CNT_ISO]",
752
-                'class'      => 'ee-input-size--reg',
753
-                'disabled'   => $CNT_cur_disabled,
754
-            ],
755
-            'CNT_cur_plural'  => [
756
-                'type'       => 'TEXT',
757
-                'input_name' => "cntry[$CNT_ISO]",
758
-                'class'      => 'ee-input-size--reg',
759
-                'disabled'   => $CNT_cur_disabled,
760
-            ],
761
-            'CNT_cur_sign'    => [
762
-                'type'         => 'TEXT',
763
-                'input_name'   => "cntry[$CNT_ISO]",
764
-                'class'        => 'ee-input-size--small',
765
-                'htmlentities' => false,
766
-                'disabled'     => $CNT_cur_disabled,
767
-            ],
768
-            'CNT_cur_sign_b4' => [
769
-                'type'             => 'RADIO_BTN',
770
-                'input_name'       => "cntry[$CNT_ISO]",
771
-                'class'            => '',
772
-                'options'          => $this->_yes_no_values,
773
-                'use_desc_4_label' => true,
774
-                'disabled'         => $CNT_cur_disabled,
775
-            ],
776
-            'CNT_cur_dec_plc' => [
777
-                'type'       => 'RADIO_BTN',
778
-                'input_name' => "cntry[$CNT_ISO]",
779
-                'class'      => '',
780
-                'options'    => [
781
-                    ['id' => 0, 'text' => ''],
782
-                    ['id' => 1, 'text' => ''],
783
-                    ['id' => 2, 'text' => ''],
784
-                    ['id' => 3, 'text' => ''],
785
-                ],
786
-                'disabled'   => $CNT_cur_disabled,
787
-            ],
788
-            'CNT_cur_dec_mrk' => [
789
-                'type'             => 'RADIO_BTN',
790
-                'input_name'       => "cntry[$CNT_ISO]",
791
-                'class'            => '',
792
-                'options'          => [
793
-                    [
794
-                        'id'   => ',',
795
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
796
-                    ],
797
-                    ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')],
798
-                ],
799
-                'use_desc_4_label' => true,
800
-                'disabled'         => $CNT_cur_disabled,
801
-            ],
802
-            'CNT_cur_thsnds'  => [
803
-                'type'             => 'RADIO_BTN',
804
-                'input_name'       => "cntry[$CNT_ISO]",
805
-                'class'            => '',
806
-                'options'          => [
807
-                    [
808
-                        'id'   => ',',
809
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
810
-                    ],
811
-                    [
812
-                        'id'   => '.',
813
-                        'text' => esc_html__('. (decimal)', 'event_espresso'),
814
-                    ],
815
-                    [
816
-                        'id'   => '&nbsp;',
817
-                        'text' => esc_html__('(space)', 'event_espresso'),
818
-                    ],
819
-                ],
820
-                'use_desc_4_label' => true,
821
-                'disabled'         => $CNT_cur_disabled,
822
-            ],
823
-            'CNT_tel_code'    => [
824
-                'type'       => 'TEXT',
825
-                'input_name' => "cntry[$CNT_ISO]",
826
-                'class'      => 'ee-input-size--small',
827
-            ],
828
-            'CNT_is_EU'       => [
829
-                'type'             => 'RADIO_BTN',
830
-                'input_name'       => "cntry[$CNT_ISO]",
831
-                'class'            => '',
832
-                'options'          => $this->_yes_no_values,
833
-                'use_desc_4_label' => true,
834
-            ],
835
-        ];
836
-        $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
837
-            $country,
838
-            $country_input_types
839
-        );
840
-        $country_details_settings       = EEH_Template::display_template(
841
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
842
-            $this->_template_args,
843
-            true
844
-        );
845
-
846
-        if (defined('DOING_AJAX')) {
847
-            $notices = EE_Error::get_notices(false, false, false);
848
-            echo wp_json_encode(
849
-                [
850
-                    'return_data' => $country_details_settings,
851
-                    'success'     => $notices['success'],
852
-                    'errors'      => $notices['errors'],
853
-                ]
854
-            );
855
-            die();
856
-        }
857
-        return $country_details_settings;
858
-    }
859
-
860
-
861
-    /**
862
-     * @param string          $CNT_ISO
863
-     * @param EE_Country|null $country
864
-     * @return string
865
-     * @throws DomainException
866
-     * @throws EE_Error
867
-     * @throws InvalidArgumentException
868
-     * @throws InvalidDataTypeException
869
-     * @throws InvalidInterfaceException
870
-     * @throws ReflectionException
871
-     */
872
-    public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string
873
-    {
874
-        $CNT_ISO = $this->getCountryISO($CNT_ISO);
875
-        if (! $CNT_ISO) {
876
-            return '';
877
-        }
878
-        // for ajax
879
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
880
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
881
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2);
882
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10);
883
-        $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
884
-        if (empty($states)) {
885
-            /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
886
-            $countrySubRegionDao = $this->loader->getShared(
887
-                'EventEspresso\core\services\address\CountrySubRegionDao'
888
-            );
889
-            if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
890
-                $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
891
-                if ($countrySubRegionDao->saveCountrySubRegions($country)) {
892
-                    $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
893
-                }
894
-            }
895
-        }
896
-        if (is_array($states)) {
897
-            foreach ($states as $STA_ID => $state) {
898
-                if ($state instanceof EE_State) {
899
-                    $inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object(
900
-                        $state,
901
-                        [
902
-                            'STA_abbrev' => [
903
-                                'type'             => 'TEXT',
904
-                                'label'            => esc_html__('Code', 'event_espresso'),
905
-                                'input_name'       => "states[$STA_ID]",
906
-                                'class'            => 'ee-input-size--tiny',
907
-                                'add_mobile_label' => true,
908
-                            ],
909
-                            'STA_name'   => [
910
-                                'type'             => 'TEXT',
911
-                                'label'            => esc_html__('Name', 'event_espresso'),
912
-                                'input_name'       => "states[$STA_ID]",
913
-                                'class'            => 'ee-input-size--big',
914
-                                'add_mobile_label' => true,
915
-                            ],
916
-                            'STA_active' => [
917
-                                'type'             => 'RADIO_BTN',
918
-                                'label'            => esc_html__('State Appears in Dropdown Select Lists', 'event_espresso'),
919
-                                'input_name'       => "states[$STA_ID]",
920
-                                'options'          => $this->_yes_no_values,
921
-                                'use_desc_4_label' => true,
922
-                                'add_mobile_label' => true,
923
-                            ],
924
-                        ]
925
-                    );
926
-
927
-                    $delete_state_url = EE_Admin_Page::add_query_args_and_nonce(
928
-                        [
929
-                            'action'     => 'delete_state',
930
-                            'STA_ID'     => $STA_ID,
931
-                            'CNT_ISO'    => $CNT_ISO,
932
-                            'STA_abbrev' => $state->abbrev(),
933
-                        ],
934
-                        GEN_SET_ADMIN_URL
935
-                    );
936
-
937
-                    $this->_template_args['states'][$STA_ID]['inputs']           = $inputs;
938
-                    $this->_template_args['states'][$STA_ID]['delete_state_url'] = $delete_state_url;
939
-                }
940
-            }
941
-        } else {
942
-            $this->_template_args['states'] = false;
943
-        }
944
-
945
-        $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
946
-            ['action' => 'add_new_state'],
947
-            GEN_SET_ADMIN_URL
948
-        );
949
-
950
-        $state_details_settings = EEH_Template::display_template(
951
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
952
-            $this->_template_args,
953
-            true
954
-        );
955
-
956
-        if (defined('DOING_AJAX')) {
957
-            $notices = EE_Error::get_notices(false, false, false);
958
-            echo wp_json_encode(
959
-                [
960
-                    'return_data' => $state_details_settings,
961
-                    'success'     => $notices['success'],
962
-                    'errors'      => $notices['errors'],
963
-                ]
964
-            );
965
-            die();
966
-        }
967
-        return $state_details_settings;
968
-    }
969
-
970
-
971
-    /**
972
-     * @return void
973
-     * @throws EE_Error
974
-     * @throws InvalidArgumentException
975
-     * @throws InvalidDataTypeException
976
-     * @throws InvalidInterfaceException
977
-     * @throws ReflectionException
978
-     */
979
-    public function add_new_state()
980
-    {
981
-        $success = true;
982
-        $CNT_ISO = $this->getCountryISO('');
983
-        if (! $CNT_ISO) {
984
-            EE_Error::add_error(
985
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
986
-                __FILE__,
987
-                __FUNCTION__,
988
-                __LINE__
989
-            );
990
-            $success = false;
991
-        }
992
-        $STA_abbrev = $this->request->getRequestParam('STA_abbrev');
993
-        if (! $STA_abbrev) {
994
-            EE_Error::add_error(
995
-                esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
996
-                __FILE__,
997
-                __FUNCTION__,
998
-                __LINE__
999
-            );
1000
-            $success = false;
1001
-        }
1002
-        $STA_name = $this->request->getRequestParam('STA_name');
1003
-        if (! $STA_name) {
1004
-            EE_Error::add_error(
1005
-                esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
1006
-                __FILE__,
1007
-                __FUNCTION__,
1008
-                __LINE__
1009
-            );
1010
-            $success = false;
1011
-        }
1012
-
1013
-        if ($success) {
1014
-            $cols_n_values = [
1015
-                'CNT_ISO'    => $CNT_ISO,
1016
-                'STA_abbrev' => $STA_abbrev,
1017
-                'STA_name'   => $STA_name,
1018
-                'STA_active' => true,
1019
-            ];
1020
-            $success       = EEM_State::instance()->insert($cols_n_values);
1021
-            EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1022
-        }
1023
-
1024
-        if (defined('DOING_AJAX')) {
1025
-            $notices = EE_Error::get_notices(false, false, false);
1026
-            echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO]));
1027
-            die();
1028
-        }
1029
-        $this->_redirect_after_action(
1030
-            $success,
1031
-            esc_html__('State', 'event_espresso'),
1032
-            'added',
1033
-            ['action' => 'country_settings']
1034
-        );
1035
-    }
1036
-
1037
-
1038
-    /**
1039
-     * @return void
1040
-     * @throws EE_Error
1041
-     * @throws InvalidArgumentException
1042
-     * @throws InvalidDataTypeException
1043
-     * @throws InvalidInterfaceException
1044
-     * @throws ReflectionException
1045
-     */
1046
-    public function delete_state()
1047
-    {
1048
-        $CNT_ISO    = $this->getCountryISO();
1049
-        $STA_ID     = $this->request->getRequestParam('STA_ID');
1050
-        $STA_abbrev = $this->request->getRequestParam('STA_abbrev');
1051
-
1052
-        if (! $STA_ID) {
1053
-            EE_Error::add_error(
1054
-                esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1055
-                __FILE__,
1056
-                __FUNCTION__,
1057
-                __LINE__
1058
-            );
1059
-            return;
1060
-        }
1061
-
1062
-        $success = EEM_State::instance()->delete_by_ID($STA_ID);
1063
-        if ($success !== false) {
1064
-            do_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1065
-                      $CNT_ISO,
1066
-                      $STA_ID,
1067
-                      ['STA_abbrev' => $STA_abbrev]);
1068
-            EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1069
-        }
1070
-        if (defined('DOING_AJAX')) {
1071
-            $notices                = EE_Error::get_notices(false);
1072
-            $notices['return_data'] = true;
1073
-            echo wp_json_encode($notices);
1074
-            die();
1075
-        }
1076
-        $this->_redirect_after_action(
1077
-            $success,
1078
-            esc_html__('State', 'event_espresso'),
1079
-            'deleted',
1080
-            ['action' => 'country_settings']
1081
-        );
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     * @return void
1087
-     * @throws EE_Error
1088
-     * @throws InvalidArgumentException
1089
-     * @throws InvalidDataTypeException
1090
-     * @throws InvalidInterfaceException
1091
-     * @throws ReflectionException
1092
-     */
1093
-    protected function _update_country_settings()
1094
-    {
1095
-        $CNT_ISO = $this->getCountryISO();
1096
-        if (! $CNT_ISO) {
1097
-            EE_Error::add_error(
1098
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1099
-                __FILE__,
1100
-                __FUNCTION__,
1101
-                __LINE__
1102
-            );
1103
-            return;
1104
-        }
1105
-
1106
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO);
1107
-
1108
-        $cols_n_values                    = [];
1109
-        $cols_n_values['CNT_ISO3']        = strtoupper(
1110
-            $this->request->getRequestParam('cntry', '', $country->ISO3())
1111
-        );
1112
-        $cols_n_values['CNT_name']        =
1113
-            $this->request->getRequestParam("cntry[$CNT_ISO][CNT_name]", $country->name());
1114
-        $cols_n_values['CNT_cur_code']    = strtoupper(
1115
-            $this->request->getRequestParam(
1116
-                "cntry[$CNT_ISO][CNT_cur_code]",
1117
-                $country->currency_code()
1118
-            )
1119
-        );
1120
-        $cols_n_values['CNT_cur_single']  = $this->request->getRequestParam(
1121
-            "cntry[$CNT_ISO][CNT_cur_single]",
1122
-            $country->currency_name_single()
1123
-        );
1124
-        $cols_n_values['CNT_cur_plural']  = $this->request->getRequestParam(
1125
-            "cntry[$CNT_ISO][CNT_cur_plural]",
1126
-            $country->currency_name_plural()
1127
-        );
1128
-        $cols_n_values['CNT_cur_sign']    = $this->request->getRequestParam(
1129
-            "cntry[$CNT_ISO][CNT_cur_sign]",
1130
-            $country->currency_sign()
1131
-        );
1132
-        $cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam(
1133
-            "cntry[$CNT_ISO][CNT_cur_sign_b4]",
1134
-            $country->currency_sign_before(),
1135
-            DataType::BOOL
1136
-        );
1137
-        $cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam(
1138
-            "cntry[$CNT_ISO][CNT_cur_dec_plc]",
1139
-            $country->currency_decimal_places()
1140
-        );
1141
-        $cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam(
1142
-            "cntry[$CNT_ISO][CNT_cur_dec_mrk]",
1143
-            $country->currency_decimal_mark()
1144
-        );
1145
-        $cols_n_values['CNT_cur_thsnds']  = $this->request->getRequestParam(
1146
-            "cntry[$CNT_ISO][CNT_cur_thsnds]",
1147
-            $country->currency_thousands_separator()
1148
-        );
1149
-        $cols_n_values['CNT_tel_code']    = $this->request->getRequestParam(
1150
-            "cntry[$CNT_ISO][CNT_tel_code]",
1151
-            $country->telephoneCode()
1152
-        );
1153
-        $cols_n_values['CNT_active']      = $this->request->getRequestParam(
1154
-            "cntry[$CNT_ISO][CNT_active]",
1155
-            $country->isActive(),
1156
-            DataType::BOOL
1157
-        );
1158
-
1159
-        // allow filtering of country data
1160
-        $cols_n_values = apply_filters(
1161
-            'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1162
-            $cols_n_values
1163
-        );
1164
-
1165
-        // where values
1166
-        $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]];
1167
-        // run the update
1168
-        $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1169
-
1170
-        // allow filtering of states data
1171
-        $states = apply_filters(
1172
-            'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1173
-            $this->request->getRequestParam('states', [], DataType::STRING, true)
1174
-        );
1175
-
1176
-        if (! empty($states) && $success !== false) {
1177
-            // loop thru state data ( looks like : states[75][STA_name] )
1178
-            foreach ($states as $STA_ID => $state) {
1179
-                $cols_n_values = [
1180
-                    'CNT_ISO'    => $CNT_ISO,
1181
-                    'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1182
-                    'STA_name'   => sanitize_text_field($state['STA_name']),
1183
-                    'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN),
1184
-                ];
1185
-                // where values
1186
-                $where_cols_n_values = [['STA_ID' => $STA_ID]];
1187
-                // run the update
1188
-                $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1189
-                if ($success !== false) {
1190
-                    do_action(
1191
-                        'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1192
-                        $CNT_ISO,
1193
-                        $STA_ID,
1194
-                        $cols_n_values
1195
-                    );
1196
-                }
1197
-            }
1198
-        }
1199
-        // check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1200
-        if (
1201
-            isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1202
-            && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1203
-        ) {
1204
-            EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1205
-            EE_Registry::instance()->CFG->update_espresso_config();
1206
-        }
1207
-
1208
-        if ($success !== false) {
1209
-            EE_Error::add_success(
1210
-                esc_html__('Country Settings updated successfully.', 'event_espresso')
1211
-            );
1212
-        }
1213
-        $this->_redirect_after_action(
1214
-            $success,
1215
-            '',
1216
-            '',
1217
-            ['action' => 'country_settings', 'country' => $CNT_ISO],
1218
-            true
1219
-        );
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * form_form_field_label_wrap
1225
-     *
1226
-     * @param string $label
1227
-     * @return string
1228
-     */
1229
-    public function country_form_field_label_wrap(string $label): string
1230
-    {
1231
-        return '
23
+	/**
24
+	 * @var EE_Core_Config
25
+	 */
26
+	public $core_config;
27
+
28
+
29
+	/**
30
+	 * Initialize basic properties.
31
+	 */
32
+	protected function _init_page_props()
33
+	{
34
+		$this->page_slug        = GEN_SET_PG_SLUG;
35
+		$this->page_label       = GEN_SET_LABEL;
36
+		$this->_admin_base_url  = GEN_SET_ADMIN_URL;
37
+		$this->_admin_base_path = GEN_SET_ADMIN;
38
+	}
39
+
40
+
41
+	/**
42
+	 * Set ajax hooks
43
+	 */
44
+	protected function _ajax_hooks()
45
+	{
46
+		add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']);
47
+		add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']);
48
+		add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3);
49
+		add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']);
50
+	}
51
+
52
+
53
+	/**
54
+	 * More page properties initialization.
55
+	 */
56
+	protected function _define_page_props()
57
+	{
58
+		$this->_admin_page_title = GEN_SET_LABEL;
59
+		$this->_labels           = ['publishbox' => esc_html__('Update Settings', 'event_espresso')];
60
+	}
61
+
62
+
63
+	/**
64
+	 * Set page routes property.
65
+	 */
66
+	protected function _set_page_routes()
67
+	{
68
+		$this->_page_routes = [
69
+			'critical_pages'                => [
70
+				'func'       => '_espresso_page_settings',
71
+				'capability' => 'manage_options',
72
+			],
73
+			'update_espresso_page_settings' => [
74
+				'func'       => '_update_espresso_page_settings',
75
+				'capability' => 'manage_options',
76
+				'noheader'   => true,
77
+			],
78
+			'default'                       => [
79
+				'func'       => '_your_organization_settings',
80
+				'capability' => 'manage_options',
81
+			],
82
+
83
+			'update_your_organization_settings' => [
84
+				'func'       => '_update_your_organization_settings',
85
+				'capability' => 'manage_options',
86
+				'noheader'   => true,
87
+			],
88
+
89
+			'admin_option_settings' => [
90
+				'func'       => '_admin_option_settings',
91
+				'capability' => 'manage_options',
92
+			],
93
+
94
+			'update_admin_option_settings' => [
95
+				'func'       => '_update_admin_option_settings',
96
+				'capability' => 'manage_options',
97
+				'noheader'   => true,
98
+			],
99
+
100
+			'country_settings' => [
101
+				'func'       => '_country_settings',
102
+				'capability' => 'manage_options',
103
+			],
104
+
105
+			'update_country_settings' => [
106
+				'func'       => '_update_country_settings',
107
+				'capability' => 'manage_options',
108
+				'noheader'   => true,
109
+			],
110
+
111
+			'display_country_settings' => [
112
+				'func'       => 'display_country_settings',
113
+				'capability' => 'manage_options',
114
+				'noheader'   => true,
115
+			],
116
+
117
+			'add_new_state' => [
118
+				'func'       => 'add_new_state',
119
+				'capability' => 'manage_options',
120
+				'noheader'   => true,
121
+			],
122
+
123
+			'delete_state'            => [
124
+				'func'       => 'delete_state',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			],
128
+			'privacy_settings'        => [
129
+				'func'       => 'privacySettings',
130
+				'capability' => 'manage_options',
131
+			],
132
+			'update_privacy_settings' => [
133
+				'func'               => 'updatePrivacySettings',
134
+				'capability'         => 'manage_options',
135
+				'noheader'           => true,
136
+				'headers_sent_route' => 'privacy_settings',
137
+			],
138
+		];
139
+	}
140
+
141
+
142
+	/**
143
+	 * Set page configuration property
144
+	 */
145
+	protected function _set_page_config()
146
+	{
147
+		$this->_page_config = [
148
+			'critical_pages'        => [
149
+				'nav'           => [
150
+					'label' => esc_html__('Critical Pages', 'event_espresso'),
151
+					'order' => 50,
152
+				],
153
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
154
+				'help_tabs'     => [
155
+					'general_settings_critical_pages_help_tab' => [
156
+						'title'    => esc_html__('Critical Pages', 'event_espresso'),
157
+						'filename' => 'general_settings_critical_pages',
158
+					],
159
+				],
160
+				'require_nonce' => false,
161
+			],
162
+			'default'               => [
163
+				'nav'           => [
164
+					'label' => esc_html__('Your Organization', 'event_espresso'),
165
+					'order' => 20,
166
+				],
167
+				'help_tabs'     => [
168
+					'general_settings_your_organization_help_tab' => [
169
+						'title'    => esc_html__('Your Organization', 'event_espresso'),
170
+						'filename' => 'general_settings_your_organization',
171
+					],
172
+				],
173
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
174
+				'require_nonce' => false,
175
+			],
176
+			'admin_option_settings' => [
177
+				'nav'           => [
178
+					'label' => esc_html__('Admin Options', 'event_espresso'),
179
+					'order' => 60,
180
+				],
181
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
182
+				'help_tabs'     => [
183
+					'general_settings_admin_options_help_tab' => [
184
+						'title'    => esc_html__('Admin Options', 'event_espresso'),
185
+						'filename' => 'general_settings_admin_options',
186
+					],
187
+				],
188
+				'require_nonce' => false,
189
+			],
190
+			'country_settings'      => [
191
+				'nav'           => [
192
+					'label' => esc_html__('Countries', 'event_espresso'),
193
+					'order' => 70,
194
+				],
195
+				'help_tabs'     => [
196
+					'general_settings_countries_help_tab' => [
197
+						'title'    => esc_html__('Countries', 'event_espresso'),
198
+						'filename' => 'general_settings_countries',
199
+					],
200
+				],
201
+				'require_nonce' => false,
202
+			],
203
+			'privacy_settings'      => [
204
+				'nav'           => [
205
+					'label' => esc_html__('Privacy', 'event_espresso'),
206
+					'order' => 80,
207
+				],
208
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
209
+				'require_nonce' => false,
210
+			],
211
+		];
212
+	}
213
+
214
+
215
+	protected function _add_screen_options()
216
+	{
217
+	}
218
+
219
+
220
+	protected function _add_feature_pointers()
221
+	{
222
+	}
223
+
224
+
225
+	/**
226
+	 * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
227
+	 */
228
+	public function load_scripts_styles()
229
+	{
230
+		// styles
231
+		wp_enqueue_style('espresso-ui-theme');
232
+		// scripts
233
+		wp_enqueue_script('ee_admin_js');
234
+	}
235
+
236
+
237
+	/**
238
+	 * Execute logic running on `admin_init`
239
+	 */
240
+	public function admin_init()
241
+	{
242
+		$this->core_config = EE_Registry::instance()->CFG->core;
243
+
244
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(
245
+			esc_html__(
246
+				'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
247
+				'event_espresso'
248
+			)
249
+		);
250
+		EE_Registry::$i18n_js_strings['error_occurred']          = wp_strip_all_tags(
251
+			esc_html__(
252
+				'An error occurred! Please refresh the page and try again.',
253
+				'event_espresso'
254
+			)
255
+		);
256
+		EE_Registry::$i18n_js_strings['confirm_delete_state']    = wp_strip_all_tags(
257
+			esc_html__(
258
+				'Are you sure you want to delete this State / Province?',
259
+				'event_espresso'
260
+			)
261
+		);
262
+		EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
263
+			'admin-ajax.php?page=espresso_general_settings',
264
+			is_ssl() ? 'https://' : 'http://'
265
+		);
266
+	}
267
+
268
+
269
+	public function admin_notices()
270
+	{
271
+	}
272
+
273
+
274
+	public function admin_footer_scripts()
275
+	{
276
+	}
277
+
278
+
279
+	/**
280
+	 * Enqueue scripts and styles for the default route.
281
+	 */
282
+	public function load_scripts_styles_default()
283
+	{
284
+		// styles
285
+		wp_enqueue_style('thickbox');
286
+		// scripts
287
+		wp_enqueue_script('media-upload');
288
+		wp_enqueue_script('thickbox');
289
+		wp_register_script(
290
+			'organization_settings',
291
+			GEN_SET_ASSETS_URL . 'your_organization_settings.js',
292
+			['jquery', 'media-upload', 'thickbox'],
293
+			EVENT_ESPRESSO_VERSION,
294
+			true
295
+		);
296
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
297
+		wp_enqueue_script('organization_settings');
298
+		wp_enqueue_style('organization-css');
299
+		$confirm_image_delete = [
300
+			'text' => wp_strip_all_tags(
301
+				esc_html__(
302
+					'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
303
+					'event_espresso'
304
+				)
305
+			),
306
+		];
307
+		wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Enqueue scripts and styles for the country settings route.
313
+	 */
314
+	public function load_scripts_styles_country_settings()
315
+	{
316
+		// scripts
317
+		wp_register_script(
318
+			'gen_settings_countries',
319
+			GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
320
+			['ee_admin_js'],
321
+			EVENT_ESPRESSO_VERSION,
322
+			true
323
+		);
324
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
325
+		wp_enqueue_script('gen_settings_countries');
326
+		wp_enqueue_style('organization-css');
327
+	}
328
+
329
+
330
+	/*************        Espresso Pages        *************/
331
+	/**
332
+	 * _espresso_page_settings
333
+	 *
334
+	 * @throws EE_Error
335
+	 * @throws DomainException
336
+	 * @throws DomainException
337
+	 * @throws InvalidDataTypeException
338
+	 * @throws InvalidArgumentException
339
+	 */
340
+	protected function _espresso_page_settings()
341
+	{
342
+		// Check to make sure all of the main pages are set up properly,
343
+		// if not create the default pages and display an admin notice
344
+		EEH_Activation::verify_default_pages_exist();
345
+		$this->_transient_garbage_collection();
346
+
347
+		$this->_template_args['values']             = $this->_yes_no_values;
348
+
349
+		$this->_template_args['reg_page_id']        = $this->core_config->reg_page_id ?? null;
350
+		$this->_template_args['reg_page_obj']       = isset($this->core_config->reg_page_id)
351
+			? get_post($this->core_config->reg_page_id)
352
+			: false;
353
+
354
+		$this->_template_args['txn_page_id']        = $this->core_config->txn_page_id ?? null;
355
+		$this->_template_args['txn_page_obj']       = isset($this->core_config->txn_page_id)
356
+			? get_post($this->core_config->txn_page_id)
357
+			: false;
358
+
359
+		$this->_template_args['thank_you_page_id']  = $this->core_config->thank_you_page_id ?? null;
360
+		$this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id)
361
+			? get_post($this->core_config->thank_you_page_id)
362
+			: false;
363
+
364
+		$this->_template_args['cancel_page_id']     = $this->core_config->cancel_page_id ?? null;
365
+		$this->_template_args['cancel_page_obj']    = isset($this->core_config->cancel_page_id)
366
+			? get_post($this->core_config->cancel_page_id)
367
+			: false;
368
+
369
+		$this->_set_add_edit_form_tags('update_espresso_page_settings');
370
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
371
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
372
+			GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
373
+			$this->_template_args,
374
+			true
375
+		);
376
+		$this->display_admin_page_with_sidebar();
377
+	}
378
+
379
+
380
+	/**
381
+	 * Handler for updating espresso page settings.
382
+	 *
383
+	 * @throws EE_Error
384
+	 */
385
+	protected function _update_espresso_page_settings()
386
+	{
387
+		// capture incoming request data && set page IDs
388
+		$this->core_config->reg_page_id       = $this->request->getRequestParam(
389
+			'reg_page_id',
390
+			$this->core_config->reg_page_id,
391
+			DataType::INT
392
+		);
393
+		$this->core_config->txn_page_id       = $this->request->getRequestParam(
394
+			'txn_page_id',
395
+			$this->core_config->txn_page_id,
396
+			DataType::INT
397
+		);
398
+		$this->core_config->thank_you_page_id = $this->request->getRequestParam(
399
+			'thank_you_page_id',
400
+			$this->core_config->thank_you_page_id,
401
+			DataType::INT
402
+		);
403
+		$this->core_config->cancel_page_id    = $this->request->getRequestParam(
404
+			'cancel_page_id',
405
+			$this->core_config->cancel_page_id,
406
+			DataType::INT
407
+		);
408
+
409
+		$this->core_config = apply_filters(
410
+			'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
411
+			$this->core_config,
412
+			$this->request->requestParams()
413
+		);
414
+
415
+		$what = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
416
+		$this->_redirect_after_action(
417
+			$this->_update_espresso_configuration(
418
+				$what,
419
+				$this->core_config,
420
+				__FILE__,
421
+				__FUNCTION__,
422
+				__LINE__
423
+			),
424
+			$what,
425
+			'',
426
+			[
427
+				'action' => 'critical_pages',
428
+			],
429
+			true
430
+		);
431
+	}
432
+
433
+
434
+	/*************        Your Organization        *************/
435
+
436
+
437
+	/**
438
+	 * @throws DomainException
439
+	 * @throws EE_Error
440
+	 * @throws InvalidArgumentException
441
+	 * @throws InvalidDataTypeException
442
+	 * @throws InvalidInterfaceException
443
+	 */
444
+	protected function _your_organization_settings()
445
+	{
446
+		$this->_template_args['admin_page_content'] = '';
447
+		try {
448
+			/** @var OrganizationSettings $organization_settings_form */
449
+			$organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
450
+
451
+			$this->_template_args['admin_page_content'] = EEH_HTML::div(
452
+				$organization_settings_form->display(),
453
+				'',
454
+				'padding'
455
+			);
456
+		} catch (Exception $e) {
457
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
458
+		}
459
+		$this->_set_add_edit_form_tags('update_your_organization_settings');
460
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
461
+		$this->display_admin_page_with_sidebar();
462
+	}
463
+
464
+
465
+	/**
466
+	 * Handler for updating organization settings.
467
+	 *
468
+	 * @throws EE_Error
469
+	 */
470
+	protected function _update_your_organization_settings()
471
+	{
472
+		try {
473
+			/** @var OrganizationSettings $organization_settings_form */
474
+			$organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
475
+
476
+			$success = $organization_settings_form->process($this->request->requestParams());
477
+
478
+			EE_Registry::instance()->CFG = apply_filters(
479
+				'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
480
+				EE_Registry::instance()->CFG
481
+			);
482
+		} catch (Exception $e) {
483
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
484
+			$success = false;
485
+		}
486
+
487
+		if ($success) {
488
+			$success = $this->_update_espresso_configuration(
489
+				esc_html__('Your Organization Settings', 'event_espresso'),
490
+				EE_Registry::instance()->CFG,
491
+				__FILE__,
492
+				__FUNCTION__,
493
+				__LINE__
494
+			);
495
+		}
496
+
497
+		$this->_redirect_after_action($success, '', '', ['action' => 'default'], true);
498
+	}
499
+
500
+
501
+
502
+	/*************        Admin Options        *************/
503
+
504
+
505
+	/**
506
+	 * _admin_option_settings
507
+	 *
508
+	 * @throws EE_Error
509
+	 * @throws LogicException
510
+	 */
511
+	protected function _admin_option_settings()
512
+	{
513
+		$this->_template_args['admin_page_content'] = '';
514
+		try {
515
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
516
+			// still need this for the old school form in Extend_General_Settings_Admin_Page
517
+			$this->_template_args['values'] = $this->_yes_no_values;
518
+			// also need to account for the do_action that was in the old template
519
+			$admin_options_settings_form->setTemplateArgs($this->_template_args);
520
+			$this->_template_args['admin_page_content'] = EEH_HTML::div(
521
+				$admin_options_settings_form->display(),
522
+				'',
523
+				'padding'
524
+			);
525
+		} catch (Exception $e) {
526
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
527
+		}
528
+		$this->_set_add_edit_form_tags('update_admin_option_settings');
529
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
530
+		$this->display_admin_page_with_sidebar();
531
+	}
532
+
533
+
534
+	/**
535
+	 * _update_admin_option_settings
536
+	 *
537
+	 * @throws EE_Error
538
+	 * @throws InvalidDataTypeException
539
+	 * @throws InvalidFormSubmissionException
540
+	 * @throws InvalidArgumentException
541
+	 * @throws LogicException
542
+	 */
543
+	protected function _update_admin_option_settings()
544
+	{
545
+		try {
546
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
547
+			$admin_options_settings_form->process(
548
+				$this->request->getRequestParam(
549
+					$admin_options_settings_form->slug(),
550
+					[],
551
+					DataType::STRING,
552
+					true
553
+				)
554
+			);
555
+			EE_Registry::instance()->CFG->admin = apply_filters(
556
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
557
+				EE_Registry::instance()->CFG->admin
558
+			);
559
+		} catch (Exception $e) {
560
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
561
+		}
562
+		$this->_redirect_after_action(
563
+			apply_filters(
564
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
565
+				$this->_update_espresso_configuration(
566
+					esc_html__('Admin Options', 'event_espresso'),
567
+					EE_Registry::instance()->CFG->admin,
568
+					__FILE__,
569
+					__FUNCTION__,
570
+					__LINE__
571
+				)
572
+			),
573
+			esc_html__('Admin Options', 'event_espresso'),
574
+			'updated',
575
+			['action' => 'admin_option_settings']
576
+		);
577
+	}
578
+
579
+
580
+	/*************        Countries        *************/
581
+
582
+
583
+	/**
584
+	 * @param string|null $default
585
+	 * @return string
586
+	 */
587
+	protected function getCountryISO(?string $default = null): string
588
+	{
589
+		$default = $default ?? $this->getCountryIsoForSite();
590
+		$CNT_ISO = $this->request->getRequestParam('country', $default);
591
+		return strtoupper($CNT_ISO);
592
+	}
593
+
594
+
595
+	/**
596
+	 * @return string
597
+	 */
598
+	protected function getCountryIsoForSite(): string
599
+	{
600
+		return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
601
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
602
+			: 'US';
603
+	}
604
+
605
+
606
+	/**
607
+	 * @param string          $CNT_ISO
608
+	 * @param EE_Country|null $country
609
+	 * @return EE_Base_Class|EE_Country
610
+	 * @throws EE_Error
611
+	 * @throws InvalidArgumentException
612
+	 * @throws InvalidDataTypeException
613
+	 * @throws InvalidInterfaceException
614
+	 * @throws ReflectionException
615
+	 */
616
+	protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null)
617
+	{
618
+		/** @var EE_Country $country */
619
+		return $country instanceof EE_Country && $country->ID() === $CNT_ISO
620
+			? $country
621
+			: EEM_Country::instance()->get_one_by_ID($CNT_ISO);
622
+	}
623
+
624
+
625
+	/**
626
+	 * Output Country Settings view.
627
+	 *
628
+	 * @throws DomainException
629
+	 * @throws EE_Error
630
+	 * @throws InvalidArgumentException
631
+	 * @throws InvalidDataTypeException
632
+	 * @throws InvalidInterfaceException
633
+	 * @throws ReflectionException
634
+	 */
635
+	protected function _country_settings()
636
+	{
637
+		$CNT_ISO = $this->getCountryISO();
638
+
639
+		$this->_template_args['values']    = $this->_yes_no_values;
640
+		$this->_template_args['countries'] = new EE_Question_Form_Input(
641
+			EE_Question::new_instance(
642
+				[
643
+				  'QST_ID'           => 0,
644
+				  'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
645
+				  'QST_system'       => 'admin-country',
646
+				]
647
+			),
648
+			EE_Answer::new_instance(
649
+				[
650
+					'ANS_ID'    => 0,
651
+					'ANS_value' => $CNT_ISO,
652
+				]
653
+			),
654
+			[
655
+				'input_id'       => 'country',
656
+				'input_name'     => 'country',
657
+				'input_prefix'   => '',
658
+				'append_qstn_id' => false,
659
+			]
660
+		);
661
+
662
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO);
663
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10);
664
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10);
665
+		$this->_template_args['country_details_settings'] = $this->display_country_settings(
666
+			$country->ID(),
667
+			$country
668
+		);
669
+		$this->_template_args['country_states_settings']  = $this->display_country_states(
670
+			$country->ID(),
671
+			$country
672
+		);
673
+		$this->_template_args['CNT_name_for_site']        = $country->name();
674
+
675
+		$this->_set_add_edit_form_tags('update_country_settings');
676
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
677
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
678
+			GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
679
+			$this->_template_args,
680
+			true
681
+		);
682
+		$this->display_admin_page_with_no_sidebar();
683
+	}
684
+
685
+
686
+	/**
687
+	 * @param string          $CNT_ISO
688
+	 * @param EE_Country|null $country
689
+	 * @return string
690
+	 * @throws DomainException
691
+	 * @throws EE_Error
692
+	 * @throws InvalidArgumentException
693
+	 * @throws InvalidDataTypeException
694
+	 * @throws InvalidInterfaceException
695
+	 * @throws ReflectionException
696
+	 */
697
+	public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string
698
+	{
699
+		$CNT_ISO          = $this->getCountryISO($CNT_ISO);
700
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
701
+
702
+		if (! $CNT_ISO) {
703
+			return '';
704
+		}
705
+
706
+		// for ajax
707
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
708
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
709
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
710
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
711
+		$country                                  = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
712
+		$CNT_cur_disabled                         = $CNT_ISO !== $CNT_ISO_for_site;
713
+		$this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
714
+
715
+		$country_input_types            = [
716
+			'CNT_active'      => [
717
+				'type'             => 'RADIO_BTN',
718
+				'input_name'       => "cntry[$CNT_ISO]",
719
+				'class'            => '',
720
+				'options'          => $this->_yes_no_values,
721
+				'use_desc_4_label' => true,
722
+			],
723
+			'CNT_ISO'         => [
724
+				'type'       => 'TEXT',
725
+				'input_name' => "cntry[$CNT_ISO]",
726
+				'class'      => 'ee-input-size--small',
727
+			],
728
+			'CNT_ISO3'        => [
729
+				'type'       => 'TEXT',
730
+				'input_name' => "cntry[$CNT_ISO]",
731
+				'class'      => 'ee-input-size--small',
732
+			],
733
+			// 'RGN_ID'          => [
734
+			//     'type'       => 'TEXT',
735
+			//     'input_name' => "cntry[$CNT_ISO]",
736
+			//     'class'      => 'ee-input-size--small',
737
+			// ],
738
+			'CNT_name'        => [
739
+				'type'       => 'TEXT',
740
+				'input_name' => "cntry[$CNT_ISO]",
741
+				'class'      => 'ee-input-size--big',
742
+			],
743
+			'CNT_cur_code'    => [
744
+				'type'       => 'TEXT',
745
+				'input_name' => "cntry[$CNT_ISO]",
746
+				'class'      => 'ee-input-size--small',
747
+				'disabled'   => $CNT_cur_disabled,
748
+			],
749
+			'CNT_cur_single'  => [
750
+				'type'       => 'TEXT',
751
+				'input_name' => "cntry[$CNT_ISO]",
752
+				'class'      => 'ee-input-size--reg',
753
+				'disabled'   => $CNT_cur_disabled,
754
+			],
755
+			'CNT_cur_plural'  => [
756
+				'type'       => 'TEXT',
757
+				'input_name' => "cntry[$CNT_ISO]",
758
+				'class'      => 'ee-input-size--reg',
759
+				'disabled'   => $CNT_cur_disabled,
760
+			],
761
+			'CNT_cur_sign'    => [
762
+				'type'         => 'TEXT',
763
+				'input_name'   => "cntry[$CNT_ISO]",
764
+				'class'        => 'ee-input-size--small',
765
+				'htmlentities' => false,
766
+				'disabled'     => $CNT_cur_disabled,
767
+			],
768
+			'CNT_cur_sign_b4' => [
769
+				'type'             => 'RADIO_BTN',
770
+				'input_name'       => "cntry[$CNT_ISO]",
771
+				'class'            => '',
772
+				'options'          => $this->_yes_no_values,
773
+				'use_desc_4_label' => true,
774
+				'disabled'         => $CNT_cur_disabled,
775
+			],
776
+			'CNT_cur_dec_plc' => [
777
+				'type'       => 'RADIO_BTN',
778
+				'input_name' => "cntry[$CNT_ISO]",
779
+				'class'      => '',
780
+				'options'    => [
781
+					['id' => 0, 'text' => ''],
782
+					['id' => 1, 'text' => ''],
783
+					['id' => 2, 'text' => ''],
784
+					['id' => 3, 'text' => ''],
785
+				],
786
+				'disabled'   => $CNT_cur_disabled,
787
+			],
788
+			'CNT_cur_dec_mrk' => [
789
+				'type'             => 'RADIO_BTN',
790
+				'input_name'       => "cntry[$CNT_ISO]",
791
+				'class'            => '',
792
+				'options'          => [
793
+					[
794
+						'id'   => ',',
795
+						'text' => esc_html__(', (comma)', 'event_espresso'),
796
+					],
797
+					['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')],
798
+				],
799
+				'use_desc_4_label' => true,
800
+				'disabled'         => $CNT_cur_disabled,
801
+			],
802
+			'CNT_cur_thsnds'  => [
803
+				'type'             => 'RADIO_BTN',
804
+				'input_name'       => "cntry[$CNT_ISO]",
805
+				'class'            => '',
806
+				'options'          => [
807
+					[
808
+						'id'   => ',',
809
+						'text' => esc_html__(', (comma)', 'event_espresso'),
810
+					],
811
+					[
812
+						'id'   => '.',
813
+						'text' => esc_html__('. (decimal)', 'event_espresso'),
814
+					],
815
+					[
816
+						'id'   => '&nbsp;',
817
+						'text' => esc_html__('(space)', 'event_espresso'),
818
+					],
819
+				],
820
+				'use_desc_4_label' => true,
821
+				'disabled'         => $CNT_cur_disabled,
822
+			],
823
+			'CNT_tel_code'    => [
824
+				'type'       => 'TEXT',
825
+				'input_name' => "cntry[$CNT_ISO]",
826
+				'class'      => 'ee-input-size--small',
827
+			],
828
+			'CNT_is_EU'       => [
829
+				'type'             => 'RADIO_BTN',
830
+				'input_name'       => "cntry[$CNT_ISO]",
831
+				'class'            => '',
832
+				'options'          => $this->_yes_no_values,
833
+				'use_desc_4_label' => true,
834
+			],
835
+		];
836
+		$this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
837
+			$country,
838
+			$country_input_types
839
+		);
840
+		$country_details_settings       = EEH_Template::display_template(
841
+			GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
842
+			$this->_template_args,
843
+			true
844
+		);
845
+
846
+		if (defined('DOING_AJAX')) {
847
+			$notices = EE_Error::get_notices(false, false, false);
848
+			echo wp_json_encode(
849
+				[
850
+					'return_data' => $country_details_settings,
851
+					'success'     => $notices['success'],
852
+					'errors'      => $notices['errors'],
853
+				]
854
+			);
855
+			die();
856
+		}
857
+		return $country_details_settings;
858
+	}
859
+
860
+
861
+	/**
862
+	 * @param string          $CNT_ISO
863
+	 * @param EE_Country|null $country
864
+	 * @return string
865
+	 * @throws DomainException
866
+	 * @throws EE_Error
867
+	 * @throws InvalidArgumentException
868
+	 * @throws InvalidDataTypeException
869
+	 * @throws InvalidInterfaceException
870
+	 * @throws ReflectionException
871
+	 */
872
+	public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string
873
+	{
874
+		$CNT_ISO = $this->getCountryISO($CNT_ISO);
875
+		if (! $CNT_ISO) {
876
+			return '';
877
+		}
878
+		// for ajax
879
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
880
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
881
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2);
882
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10);
883
+		$states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
884
+		if (empty($states)) {
885
+			/** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
886
+			$countrySubRegionDao = $this->loader->getShared(
887
+				'EventEspresso\core\services\address\CountrySubRegionDao'
888
+			);
889
+			if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
890
+				$country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
891
+				if ($countrySubRegionDao->saveCountrySubRegions($country)) {
892
+					$states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
893
+				}
894
+			}
895
+		}
896
+		if (is_array($states)) {
897
+			foreach ($states as $STA_ID => $state) {
898
+				if ($state instanceof EE_State) {
899
+					$inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object(
900
+						$state,
901
+						[
902
+							'STA_abbrev' => [
903
+								'type'             => 'TEXT',
904
+								'label'            => esc_html__('Code', 'event_espresso'),
905
+								'input_name'       => "states[$STA_ID]",
906
+								'class'            => 'ee-input-size--tiny',
907
+								'add_mobile_label' => true,
908
+							],
909
+							'STA_name'   => [
910
+								'type'             => 'TEXT',
911
+								'label'            => esc_html__('Name', 'event_espresso'),
912
+								'input_name'       => "states[$STA_ID]",
913
+								'class'            => 'ee-input-size--big',
914
+								'add_mobile_label' => true,
915
+							],
916
+							'STA_active' => [
917
+								'type'             => 'RADIO_BTN',
918
+								'label'            => esc_html__('State Appears in Dropdown Select Lists', 'event_espresso'),
919
+								'input_name'       => "states[$STA_ID]",
920
+								'options'          => $this->_yes_no_values,
921
+								'use_desc_4_label' => true,
922
+								'add_mobile_label' => true,
923
+							],
924
+						]
925
+					);
926
+
927
+					$delete_state_url = EE_Admin_Page::add_query_args_and_nonce(
928
+						[
929
+							'action'     => 'delete_state',
930
+							'STA_ID'     => $STA_ID,
931
+							'CNT_ISO'    => $CNT_ISO,
932
+							'STA_abbrev' => $state->abbrev(),
933
+						],
934
+						GEN_SET_ADMIN_URL
935
+					);
936
+
937
+					$this->_template_args['states'][$STA_ID]['inputs']           = $inputs;
938
+					$this->_template_args['states'][$STA_ID]['delete_state_url'] = $delete_state_url;
939
+				}
940
+			}
941
+		} else {
942
+			$this->_template_args['states'] = false;
943
+		}
944
+
945
+		$this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
946
+			['action' => 'add_new_state'],
947
+			GEN_SET_ADMIN_URL
948
+		);
949
+
950
+		$state_details_settings = EEH_Template::display_template(
951
+			GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
952
+			$this->_template_args,
953
+			true
954
+		);
955
+
956
+		if (defined('DOING_AJAX')) {
957
+			$notices = EE_Error::get_notices(false, false, false);
958
+			echo wp_json_encode(
959
+				[
960
+					'return_data' => $state_details_settings,
961
+					'success'     => $notices['success'],
962
+					'errors'      => $notices['errors'],
963
+				]
964
+			);
965
+			die();
966
+		}
967
+		return $state_details_settings;
968
+	}
969
+
970
+
971
+	/**
972
+	 * @return void
973
+	 * @throws EE_Error
974
+	 * @throws InvalidArgumentException
975
+	 * @throws InvalidDataTypeException
976
+	 * @throws InvalidInterfaceException
977
+	 * @throws ReflectionException
978
+	 */
979
+	public function add_new_state()
980
+	{
981
+		$success = true;
982
+		$CNT_ISO = $this->getCountryISO('');
983
+		if (! $CNT_ISO) {
984
+			EE_Error::add_error(
985
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
986
+				__FILE__,
987
+				__FUNCTION__,
988
+				__LINE__
989
+			);
990
+			$success = false;
991
+		}
992
+		$STA_abbrev = $this->request->getRequestParam('STA_abbrev');
993
+		if (! $STA_abbrev) {
994
+			EE_Error::add_error(
995
+				esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
996
+				__FILE__,
997
+				__FUNCTION__,
998
+				__LINE__
999
+			);
1000
+			$success = false;
1001
+		}
1002
+		$STA_name = $this->request->getRequestParam('STA_name');
1003
+		if (! $STA_name) {
1004
+			EE_Error::add_error(
1005
+				esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
1006
+				__FILE__,
1007
+				__FUNCTION__,
1008
+				__LINE__
1009
+			);
1010
+			$success = false;
1011
+		}
1012
+
1013
+		if ($success) {
1014
+			$cols_n_values = [
1015
+				'CNT_ISO'    => $CNT_ISO,
1016
+				'STA_abbrev' => $STA_abbrev,
1017
+				'STA_name'   => $STA_name,
1018
+				'STA_active' => true,
1019
+			];
1020
+			$success       = EEM_State::instance()->insert($cols_n_values);
1021
+			EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1022
+		}
1023
+
1024
+		if (defined('DOING_AJAX')) {
1025
+			$notices = EE_Error::get_notices(false, false, false);
1026
+			echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO]));
1027
+			die();
1028
+		}
1029
+		$this->_redirect_after_action(
1030
+			$success,
1031
+			esc_html__('State', 'event_espresso'),
1032
+			'added',
1033
+			['action' => 'country_settings']
1034
+		);
1035
+	}
1036
+
1037
+
1038
+	/**
1039
+	 * @return void
1040
+	 * @throws EE_Error
1041
+	 * @throws InvalidArgumentException
1042
+	 * @throws InvalidDataTypeException
1043
+	 * @throws InvalidInterfaceException
1044
+	 * @throws ReflectionException
1045
+	 */
1046
+	public function delete_state()
1047
+	{
1048
+		$CNT_ISO    = $this->getCountryISO();
1049
+		$STA_ID     = $this->request->getRequestParam('STA_ID');
1050
+		$STA_abbrev = $this->request->getRequestParam('STA_abbrev');
1051
+
1052
+		if (! $STA_ID) {
1053
+			EE_Error::add_error(
1054
+				esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1055
+				__FILE__,
1056
+				__FUNCTION__,
1057
+				__LINE__
1058
+			);
1059
+			return;
1060
+		}
1061
+
1062
+		$success = EEM_State::instance()->delete_by_ID($STA_ID);
1063
+		if ($success !== false) {
1064
+			do_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1065
+					  $CNT_ISO,
1066
+					  $STA_ID,
1067
+					  ['STA_abbrev' => $STA_abbrev]);
1068
+			EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1069
+		}
1070
+		if (defined('DOING_AJAX')) {
1071
+			$notices                = EE_Error::get_notices(false);
1072
+			$notices['return_data'] = true;
1073
+			echo wp_json_encode($notices);
1074
+			die();
1075
+		}
1076
+		$this->_redirect_after_action(
1077
+			$success,
1078
+			esc_html__('State', 'event_espresso'),
1079
+			'deleted',
1080
+			['action' => 'country_settings']
1081
+		);
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 * @return void
1087
+	 * @throws EE_Error
1088
+	 * @throws InvalidArgumentException
1089
+	 * @throws InvalidDataTypeException
1090
+	 * @throws InvalidInterfaceException
1091
+	 * @throws ReflectionException
1092
+	 */
1093
+	protected function _update_country_settings()
1094
+	{
1095
+		$CNT_ISO = $this->getCountryISO();
1096
+		if (! $CNT_ISO) {
1097
+			EE_Error::add_error(
1098
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1099
+				__FILE__,
1100
+				__FUNCTION__,
1101
+				__LINE__
1102
+			);
1103
+			return;
1104
+		}
1105
+
1106
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO);
1107
+
1108
+		$cols_n_values                    = [];
1109
+		$cols_n_values['CNT_ISO3']        = strtoupper(
1110
+			$this->request->getRequestParam('cntry', '', $country->ISO3())
1111
+		);
1112
+		$cols_n_values['CNT_name']        =
1113
+			$this->request->getRequestParam("cntry[$CNT_ISO][CNT_name]", $country->name());
1114
+		$cols_n_values['CNT_cur_code']    = strtoupper(
1115
+			$this->request->getRequestParam(
1116
+				"cntry[$CNT_ISO][CNT_cur_code]",
1117
+				$country->currency_code()
1118
+			)
1119
+		);
1120
+		$cols_n_values['CNT_cur_single']  = $this->request->getRequestParam(
1121
+			"cntry[$CNT_ISO][CNT_cur_single]",
1122
+			$country->currency_name_single()
1123
+		);
1124
+		$cols_n_values['CNT_cur_plural']  = $this->request->getRequestParam(
1125
+			"cntry[$CNT_ISO][CNT_cur_plural]",
1126
+			$country->currency_name_plural()
1127
+		);
1128
+		$cols_n_values['CNT_cur_sign']    = $this->request->getRequestParam(
1129
+			"cntry[$CNT_ISO][CNT_cur_sign]",
1130
+			$country->currency_sign()
1131
+		);
1132
+		$cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam(
1133
+			"cntry[$CNT_ISO][CNT_cur_sign_b4]",
1134
+			$country->currency_sign_before(),
1135
+			DataType::BOOL
1136
+		);
1137
+		$cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam(
1138
+			"cntry[$CNT_ISO][CNT_cur_dec_plc]",
1139
+			$country->currency_decimal_places()
1140
+		);
1141
+		$cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam(
1142
+			"cntry[$CNT_ISO][CNT_cur_dec_mrk]",
1143
+			$country->currency_decimal_mark()
1144
+		);
1145
+		$cols_n_values['CNT_cur_thsnds']  = $this->request->getRequestParam(
1146
+			"cntry[$CNT_ISO][CNT_cur_thsnds]",
1147
+			$country->currency_thousands_separator()
1148
+		);
1149
+		$cols_n_values['CNT_tel_code']    = $this->request->getRequestParam(
1150
+			"cntry[$CNT_ISO][CNT_tel_code]",
1151
+			$country->telephoneCode()
1152
+		);
1153
+		$cols_n_values['CNT_active']      = $this->request->getRequestParam(
1154
+			"cntry[$CNT_ISO][CNT_active]",
1155
+			$country->isActive(),
1156
+			DataType::BOOL
1157
+		);
1158
+
1159
+		// allow filtering of country data
1160
+		$cols_n_values = apply_filters(
1161
+			'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1162
+			$cols_n_values
1163
+		);
1164
+
1165
+		// where values
1166
+		$where_cols_n_values = [['CNT_ISO' => $CNT_ISO]];
1167
+		// run the update
1168
+		$success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1169
+
1170
+		// allow filtering of states data
1171
+		$states = apply_filters(
1172
+			'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1173
+			$this->request->getRequestParam('states', [], DataType::STRING, true)
1174
+		);
1175
+
1176
+		if (! empty($states) && $success !== false) {
1177
+			// loop thru state data ( looks like : states[75][STA_name] )
1178
+			foreach ($states as $STA_ID => $state) {
1179
+				$cols_n_values = [
1180
+					'CNT_ISO'    => $CNT_ISO,
1181
+					'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1182
+					'STA_name'   => sanitize_text_field($state['STA_name']),
1183
+					'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN),
1184
+				];
1185
+				// where values
1186
+				$where_cols_n_values = [['STA_ID' => $STA_ID]];
1187
+				// run the update
1188
+				$success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1189
+				if ($success !== false) {
1190
+					do_action(
1191
+						'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1192
+						$CNT_ISO,
1193
+						$STA_ID,
1194
+						$cols_n_values
1195
+					);
1196
+				}
1197
+			}
1198
+		}
1199
+		// check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1200
+		if (
1201
+			isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1202
+			&& $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1203
+		) {
1204
+			EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1205
+			EE_Registry::instance()->CFG->update_espresso_config();
1206
+		}
1207
+
1208
+		if ($success !== false) {
1209
+			EE_Error::add_success(
1210
+				esc_html__('Country Settings updated successfully.', 'event_espresso')
1211
+			);
1212
+		}
1213
+		$this->_redirect_after_action(
1214
+			$success,
1215
+			'',
1216
+			'',
1217
+			['action' => 'country_settings', 'country' => $CNT_ISO],
1218
+			true
1219
+		);
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * form_form_field_label_wrap
1225
+	 *
1226
+	 * @param string $label
1227
+	 * @return string
1228
+	 */
1229
+	public function country_form_field_label_wrap(string $label): string
1230
+	{
1231
+		return '
1232 1232
 			<tr>
1233 1233
 				<th>
1234 1234
 					' . $label . '
1235 1235
 				</th>';
1236
-    }
1237
-
1238
-
1239
-    /**
1240
-     * form_form_field_input__wrap
1241
-     *
1242
-     * @param string $input
1243
-     * @return string
1244
-     */
1245
-    public function country_form_field_input__wrap(string $input): string
1246
-    {
1247
-        return '
1236
+	}
1237
+
1238
+
1239
+	/**
1240
+	 * form_form_field_input__wrap
1241
+	 *
1242
+	 * @param string $input
1243
+	 * @return string
1244
+	 */
1245
+	public function country_form_field_input__wrap(string $input): string
1246
+	{
1247
+		return '
1248 1248
 				<td class="general-settings-country-input-td">
1249 1249
 					' . $input . '
1250 1250
 				</td>
1251 1251
 			</tr>';
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     * form_form_field_label_wrap
1257
-     *
1258
-     * @param string $label
1259
-     * @param string $required_text
1260
-     * @return string
1261
-     */
1262
-    public function state_form_field_label_wrap(string $label, string $required_text): string
1263
-    {
1264
-        return $required_text;
1265
-    }
1266
-
1267
-
1268
-    /**
1269
-     * form_form_field_input__wrap
1270
-     *
1271
-     * @param string $input
1272
-     * @return string
1273
-     */
1274
-    public function state_form_field_input__wrap(string $input): string
1275
-    {
1276
-        return '
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 * form_form_field_label_wrap
1257
+	 *
1258
+	 * @param string $label
1259
+	 * @param string $required_text
1260
+	 * @return string
1261
+	 */
1262
+	public function state_form_field_label_wrap(string $label, string $required_text): string
1263
+	{
1264
+		return $required_text;
1265
+	}
1266
+
1267
+
1268
+	/**
1269
+	 * form_form_field_input__wrap
1270
+	 *
1271
+	 * @param string $input
1272
+	 * @return string
1273
+	 */
1274
+	public function state_form_field_input__wrap(string $input): string
1275
+	{
1276
+		return '
1277 1277
 				<td class="general-settings-country-state-input-td">
1278 1278
 					' . $input . '
1279 1279
 				</td>';
1280
-    }
1281
-
1282
-
1283
-    /***********/
1284
-
1285
-
1286
-    /**
1287
-     * displays edit and view links for critical EE pages
1288
-     *
1289
-     * @param int $ee_page_id
1290
-     * @return string
1291
-     */
1292
-    public static function edit_view_links(int $ee_page_id): string
1293
-    {
1294
-        $edit_url = add_query_arg(
1295
-            ['post' => $ee_page_id, 'action' => 'edit'],
1296
-            admin_url('post.php')
1297
-        );
1298
-        $links    = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>';
1299
-        $links    .= ' &nbsp;|&nbsp; ';
1300
-        $links    .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1301
-
1302
-        return $links;
1303
-    }
1304
-
1305
-
1306
-    /**
1307
-     * displays page and shortcode status for critical EE pages
1308
-     *
1309
-     * @param WP_Post $ee_page
1310
-     * @param string  $shortcode
1311
-     * @return string
1312
-     */
1313
-    public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string
1314
-    {
1315
-        // page status
1316
-        if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1317
-            $pg_class  = 'ee-status-bg--success';
1318
-            $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1319
-        } else {
1320
-            $pg_class  = 'ee-status-bg--error';
1321
-            $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1322
-        }
1323
-
1324
-        // shortcode status
1325
-        if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1326
-            $sc_class  = 'ee-status-bg--success';
1327
-            $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1328
-        } else {
1329
-            $sc_class  = 'ee-status-bg--error';
1330
-            $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1331
-        }
1332
-
1333
-        return '
1280
+	}
1281
+
1282
+
1283
+	/***********/
1284
+
1285
+
1286
+	/**
1287
+	 * displays edit and view links for critical EE pages
1288
+	 *
1289
+	 * @param int $ee_page_id
1290
+	 * @return string
1291
+	 */
1292
+	public static function edit_view_links(int $ee_page_id): string
1293
+	{
1294
+		$edit_url = add_query_arg(
1295
+			['post' => $ee_page_id, 'action' => 'edit'],
1296
+			admin_url('post.php')
1297
+		);
1298
+		$links    = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>';
1299
+		$links    .= ' &nbsp;|&nbsp; ';
1300
+		$links    .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1301
+
1302
+		return $links;
1303
+	}
1304
+
1305
+
1306
+	/**
1307
+	 * displays page and shortcode status for critical EE pages
1308
+	 *
1309
+	 * @param WP_Post $ee_page
1310
+	 * @param string  $shortcode
1311
+	 * @return string
1312
+	 */
1313
+	public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string
1314
+	{
1315
+		// page status
1316
+		if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1317
+			$pg_class  = 'ee-status-bg--success';
1318
+			$pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1319
+		} else {
1320
+			$pg_class  = 'ee-status-bg--error';
1321
+			$pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1322
+		}
1323
+
1324
+		// shortcode status
1325
+		if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1326
+			$sc_class  = 'ee-status-bg--success';
1327
+			$sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1328
+		} else {
1329
+			$sc_class  = 'ee-status-bg--error';
1330
+			$sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1331
+		}
1332
+
1333
+		return '
1334 1334
         <span class="ee-page-status ' . $pg_class . '"><strong>' . $pg_status . '</strong></span>
1335 1335
         <span class="ee-page-status ' . $sc_class . '"><strong>' . $sc_status . '</strong></span>';
1336
-    }
1337
-
1338
-
1339
-    /**
1340
-     * generates a dropdown of all parent pages - copied from WP core
1341
-     *
1342
-     * @param int  $default
1343
-     * @param int  $parent
1344
-     * @param int  $level
1345
-     * @param bool $echo
1346
-     * @return string;
1347
-     */
1348
-    public static function page_settings_dropdown(
1349
-        int $default = 0,
1350
-        int $parent = 0,
1351
-        int $level = 0,
1352
-        bool $echo = true
1353
-    ): string {
1354
-        global $wpdb;
1355
-        $items  = $wpdb->get_results(
1356
-            $wpdb->prepare(
1357
-                "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1358
-                $parent
1359
-            )
1360
-        );
1361
-        $output = '';
1362
-
1363
-        if ($items) {
1364
-            $level = absint($level);
1365
-            foreach ($items as $item) {
1366
-                $ID         = absint($item->ID);
1367
-                $post_title = wp_strip_all_tags($item->post_title);
1368
-                $pad        = str_repeat('&nbsp;', $level * 3);
1369
-                $option     = "\n\t";
1370
-                $option     .= '<option class="level-' . $level . '" ';
1371
-                $option     .= 'value="' . $ID . '" ';
1372
-                $option     .= $ID === absint($default) ? ' selected="selected"' : '';
1373
-                $option     .= '>';
1374
-                $option     .= "$pad $post_title";
1375
-                $option     .= '</option>';
1376
-                $output     .= $option;
1377
-                ob_start();
1378
-                parent_dropdown($default, $item->ID, $level + 1);
1379
-                $output .= ob_get_clean();
1380
-            }
1381
-        }
1382
-        if ($echo) {
1383
-            echo wp_kses($output, AllowedTags::getAllowedTags());
1384
-            return '';
1385
-        }
1386
-        return $output;
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     * Loads the scripts for the privacy settings form
1392
-     */
1393
-    public function load_scripts_styles_privacy_settings()
1394
-    {
1395
-        $form_handler = $this->loader->getShared(
1396
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1397
-        );
1398
-        $form_handler->enqueueStylesAndScripts();
1399
-    }
1400
-
1401
-
1402
-    /**
1403
-     * display the privacy settings form
1404
-     *
1405
-     * @throws EE_Error
1406
-     */
1407
-    public function privacySettings()
1408
-    {
1409
-        $this->_set_add_edit_form_tags('update_privacy_settings');
1410
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1411
-        $form_handler                               = $this->loader->getShared(
1412
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1413
-        );
1414
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
1415
-            $form_handler->display(),
1416
-            '',
1417
-            'padding'
1418
-        );
1419
-        $this->display_admin_page_with_sidebar();
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * Update the privacy settings from form data
1425
-     *
1426
-     * @throws EE_Error
1427
-     */
1428
-    public function updatePrivacySettings()
1429
-    {
1430
-        $form_handler = $this->loader->getShared(
1431
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1432
-        );
1433
-        $success      = $form_handler->process($this->get_request_data());
1434
-        $this->_redirect_after_action(
1435
-            $success,
1436
-            esc_html__('Registration Form Options', 'event_espresso'),
1437
-            'updated',
1438
-            ['action' => 'privacy_settings']
1439
-        );
1440
-    }
1336
+	}
1337
+
1338
+
1339
+	/**
1340
+	 * generates a dropdown of all parent pages - copied from WP core
1341
+	 *
1342
+	 * @param int  $default
1343
+	 * @param int  $parent
1344
+	 * @param int  $level
1345
+	 * @param bool $echo
1346
+	 * @return string;
1347
+	 */
1348
+	public static function page_settings_dropdown(
1349
+		int $default = 0,
1350
+		int $parent = 0,
1351
+		int $level = 0,
1352
+		bool $echo = true
1353
+	): string {
1354
+		global $wpdb;
1355
+		$items  = $wpdb->get_results(
1356
+			$wpdb->prepare(
1357
+				"SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1358
+				$parent
1359
+			)
1360
+		);
1361
+		$output = '';
1362
+
1363
+		if ($items) {
1364
+			$level = absint($level);
1365
+			foreach ($items as $item) {
1366
+				$ID         = absint($item->ID);
1367
+				$post_title = wp_strip_all_tags($item->post_title);
1368
+				$pad        = str_repeat('&nbsp;', $level * 3);
1369
+				$option     = "\n\t";
1370
+				$option     .= '<option class="level-' . $level . '" ';
1371
+				$option     .= 'value="' . $ID . '" ';
1372
+				$option     .= $ID === absint($default) ? ' selected="selected"' : '';
1373
+				$option     .= '>';
1374
+				$option     .= "$pad $post_title";
1375
+				$option     .= '</option>';
1376
+				$output     .= $option;
1377
+				ob_start();
1378
+				parent_dropdown($default, $item->ID, $level + 1);
1379
+				$output .= ob_get_clean();
1380
+			}
1381
+		}
1382
+		if ($echo) {
1383
+			echo wp_kses($output, AllowedTags::getAllowedTags());
1384
+			return '';
1385
+		}
1386
+		return $output;
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 * Loads the scripts for the privacy settings form
1392
+	 */
1393
+	public function load_scripts_styles_privacy_settings()
1394
+	{
1395
+		$form_handler = $this->loader->getShared(
1396
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1397
+		);
1398
+		$form_handler->enqueueStylesAndScripts();
1399
+	}
1400
+
1401
+
1402
+	/**
1403
+	 * display the privacy settings form
1404
+	 *
1405
+	 * @throws EE_Error
1406
+	 */
1407
+	public function privacySettings()
1408
+	{
1409
+		$this->_set_add_edit_form_tags('update_privacy_settings');
1410
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1411
+		$form_handler                               = $this->loader->getShared(
1412
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1413
+		);
1414
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
1415
+			$form_handler->display(),
1416
+			'',
1417
+			'padding'
1418
+		);
1419
+		$this->display_admin_page_with_sidebar();
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * Update the privacy settings from form data
1425
+	 *
1426
+	 * @throws EE_Error
1427
+	 */
1428
+	public function updatePrivacySettings()
1429
+	{
1430
+		$form_handler = $this->loader->getShared(
1431
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1432
+		);
1433
+		$success      = $form_handler->process($this->get_request_data());
1434
+		$this->_redirect_after_action(
1435
+			$success,
1436
+			esc_html__('Registration Form Options', 'event_espresso'),
1437
+			'updated',
1438
+			['action' => 'privacy_settings']
1439
+		);
1440
+	}
1441 1441
 }
Please login to merge, or discard this patch.
admin_pages/general_settings/templates/countries_settings.template.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
 
15 15
     <h2 class="ee-admin-settings-hdr">
16 16
         <?php
17
-        echo esc_html__('Countries and States/Provinces', 'event_espresso');
18
-        echo EEH_Template::get_help_tab_link('country_select_info'); // already escaped
19
-        ?>
17
+		echo esc_html__('Countries and States/Provinces', 'event_espresso');
18
+		echo EEH_Template::get_help_tab_link('country_select_info'); // already escaped
19
+		?>
20 20
     </h2>
21 21
     <table class="form-table">
22 22
         <tbody>
@@ -26,28 +26,28 @@  discard block
 block discarded – undo
26 26
     <br/>
27 27
     <p>
28 28
         <?php esc_html_e(
29
-            'The country that is selected above will populate the Country Details settings and the options for States/Provinces. This information will be used throughout Event Espresso including for registration purposes and how currency is displayed. If you make a change to the country on this page, it is important that you also update your Contact Information on the Your Organization tab.',
30
-            'event_espresso'
31
-        ); ?>
29
+			'The country that is selected above will populate the Country Details settings and the options for States/Provinces. This information will be used throughout Event Espresso including for registration purposes and how currency is displayed. If you make a change to the country on this page, it is important that you also update your Contact Information on the Your Organization tab.',
30
+			'event_espresso'
31
+		); ?>
32 32
     </p>
33 33
     <p id="country-currency-setting-disabled-pg" style="display: none;">
34 34
         <span class="reminder-spn">
35 35
             <?php printf(
36
-                esc_html__(
37
-                    'Currency setting inputs are currently only enabled for the country "%1$s" which is the selected country for the site. This can be changed in the "Contact Information" section under the "Your Organization" tab of the Event Espresso - General Settings.',
38
-                    'event_espresso'
39
-                ),
40
-                $CNT_name_for_site
41
-            ); ?>
36
+				esc_html__(
37
+					'Currency setting inputs are currently only enabled for the country "%1$s" which is the selected country for the site. This can be changed in the "Contact Information" section under the "Your Organization" tab of the Event Espresso - General Settings.',
38
+					'event_espresso'
39
+				),
40
+				$CNT_name_for_site
41
+			); ?>
42 42
         </span>
43 43
     </p>
44 44
     <div id="country-settings-dv" class="ee-layout-row">
45 45
         <div id="country-details-settings-dv">
46 46
             <h2 class="ee-admin-settings-hdr">
47 47
                 <?php
48
-                echo esc_html__('Country Details', 'event_espresso');
49
-                echo wp_kses(EEH_Template::get_help_tab_link('country_details_info'), AllowedTags::getAllowedTags());
50
-                ?>
48
+				echo esc_html__('Country Details', 'event_espresso');
49
+				echo wp_kses(EEH_Template::get_help_tab_link('country_details_info'), AllowedTags::getAllowedTags());
50
+				?>
51 51
             </h2>
52 52
             <div id="country-details-dv">
53 53
                 <?php echo wp_kses($country_details_settings, AllowedTags::getAllowedTags()); ?>
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
         <div id="country-states-settings-dv">
58 58
             <h2 class="ee-admin-settings-hdr">
59 59
                 <?php
60
-                echo esc_html__('States/Provinces', 'event_espresso');
61
-                echo wp_kses(EEH_Template::get_help_tab_link('country_states_info'), AllowedTags::getAllowedTags());
62
-                ?>
60
+				echo esc_html__('States/Provinces', 'event_espresso');
61
+				echo wp_kses(EEH_Template::get_help_tab_link('country_states_info'), AllowedTags::getAllowedTags());
62
+				?>
63 63
             </h2>
64 64
             <div id="country-states-dv">
65 65
                 <?php echo wp_kses($country_states_settings, AllowedTags::getAllowedTags()); ?>
Please login to merge, or discard this patch.