Completed
Branch decaf-fixes/replace-request-ha... (dd0ac0)
by
unknown
04:45 queued 03:02
created
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4524 added lines, -4524 removed lines patch added patch discarded remove patch
@@ -19,2624 +19,2624 @@  discard block
 block discarded – undo
19 19
 class Messages_Admin_Page extends EE_Admin_Page
20 20
 {
21 21
 
22
-    /**
23
-     * @type EE_Message_Resource_Manager $_message_resource_manager
24
-     */
25
-    protected $_message_resource_manager;
26
-
27
-    /**
28
-     * @type string $_active_message_type_name
29
-     */
30
-    protected $_active_message_type_name = '';
31
-
32
-    /**
33
-     * @type EE_messenger $_active_messenger
34
-     */
35
-    protected $_active_messenger;
36
-    protected $_activate_state;
37
-    protected $_activate_meta_box_type;
38
-    protected $_current_message_meta_box;
39
-    protected $_current_message_meta_box_object;
40
-    protected $_context_switcher;
41
-    protected $_shortcodes = array();
42
-    protected $_active_messengers = array();
43
-    protected $_active_message_types = array();
44
-
45
-    /**
46
-     * @var EE_Message_Template_Group $_message_template_group
47
-     */
48
-    protected $_message_template_group;
49
-    protected $_m_mt_settings = array();
50
-
51
-
52
-    /**
53
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
54
-     * IF there is no group then it gets automatically set to the Default template pack.
55
-     *
56
-     * @since 4.5.0
57
-     *
58
-     * @var EE_Messages_Template_Pack
59
-     */
60
-    protected $_template_pack;
61
-
62
-
63
-    /**
64
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
65
-     * group is.  If there is no group then it automatically gets set to default.
66
-     *
67
-     * @since 4.5.0
68
-     *
69
-     * @var string
70
-     */
71
-    protected $_variation;
72
-
73
-
74
-    /**
75
-     * @param bool $routing
76
-     * @throws EE_Error
77
-     */
78
-    public function __construct($routing = true)
79
-    {
80
-        // make sure messages autoloader is running
81
-        EED_Messages::set_autoloaders();
82
-        parent::__construct($routing);
83
-    }
84
-
85
-
86
-    protected function _init_page_props()
87
-    {
88
-        $this->page_slug = EE_MSG_PG_SLUG;
89
-        $this->page_label = esc_html__('Messages Settings', 'event_espresso');
90
-        $this->_admin_base_url = EE_MSG_ADMIN_URL;
91
-        $this->_admin_base_path = EE_MSG_ADMIN;
92
-
93
-        $this->_activate_state = isset($this->_req_data['activate_state'])
94
-            ? (array) $this->_req_data['activate_state']
95
-            : array();
96
-
97
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
98
-        $this->_load_message_resource_manager();
99
-    }
100
-
101
-
102
-    /**
103
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
104
-     *
105
-     * @throws EE_Error
106
-     * @throws InvalidDataTypeException
107
-     * @throws InvalidInterfaceException
108
-     * @throws InvalidArgumentException
109
-     * @throws ReflectionException
110
-     */
111
-    protected function _load_message_resource_manager()
112
-    {
113
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
114
-    }
115
-
116
-
117
-    /**
118
-     * @deprecated 4.9.9.rc.014
119
-     * @return array
120
-     * @throws EE_Error
121
-     * @throws InvalidArgumentException
122
-     * @throws InvalidDataTypeException
123
-     * @throws InvalidInterfaceException
124
-     */
125
-    public function get_messengers_for_list_table()
126
-    {
127
-        EE_Error::doing_it_wrong(
128
-            __METHOD__,
129
-            sprintf(
130
-                esc_html__(
131
-                    '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',
132
-                    'event_espresso'
133
-                ),
134
-                'Messages_Admin_Page::get_messengers_select_input()'
135
-            ),
136
-            '4.9.9.rc.014'
137
-        );
138
-
139
-        $m_values = array();
140
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
141
-        // setup messengers for selects
142
-        $i = 1;
143
-        foreach ($active_messengers as $active_messenger) {
144
-            if ($active_messenger instanceof EE_Message) {
145
-                $m_values[ $i ]['id'] = $active_messenger->messenger();
146
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
147
-                $i++;
148
-            }
149
-        }
150
-
151
-        return $m_values;
152
-    }
153
-
154
-
155
-    /**
156
-     * @deprecated 4.9.9.rc.014
157
-     * @return array
158
-     * @throws EE_Error
159
-     * @throws InvalidArgumentException
160
-     * @throws InvalidDataTypeException
161
-     * @throws InvalidInterfaceException
162
-     */
163
-    public function get_message_types_for_list_table()
164
-    {
165
-        EE_Error::doing_it_wrong(
166
-            __METHOD__,
167
-            sprintf(
168
-                esc_html__(
169
-                    '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',
170
-                    'event_espresso'
171
-                ),
172
-                'Messages_Admin_Page::get_message_types_select_input()'
173
-            ),
174
-            '4.9.9.rc.014'
175
-        );
176
-
177
-        $mt_values = array();
178
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
179
-        $i = 1;
180
-        foreach ($active_messages as $active_message) {
181
-            if ($active_message instanceof EE_Message) {
182
-                $mt_values[ $i ]['id'] = $active_message->message_type();
183
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
184
-                $i++;
185
-            }
186
-        }
187
-
188
-        return $mt_values;
189
-    }
190
-
191
-
192
-    /**
193
-     * @deprecated 4.9.9.rc.014
194
-     * @return array
195
-     * @throws EE_Error
196
-     * @throws InvalidArgumentException
197
-     * @throws InvalidDataTypeException
198
-     * @throws InvalidInterfaceException
199
-     */
200
-    public function get_contexts_for_message_types_for_list_table()
201
-    {
202
-        EE_Error::doing_it_wrong(
203
-            __METHOD__,
204
-            sprintf(
205
-                esc_html__(
206
-                    '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',
207
-                    'event_espresso'
208
-                ),
209
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
210
-            ),
211
-            '4.9.9.rc.014'
212
-        );
213
-
214
-        $contexts = array();
215
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
216
-        foreach ($active_message_contexts as $active_message) {
217
-            if ($active_message instanceof EE_Message) {
218
-                $message_type = $active_message->message_type_object();
219
-                if ($message_type instanceof EE_message_type) {
220
-                    $message_type_contexts = $message_type->get_contexts();
221
-                    foreach ($message_type_contexts as $context => $context_details) {
222
-                        $contexts[ $context ] = $context_details['label'];
223
-                    }
224
-                }
225
-            }
226
-        }
227
-
228
-        return $contexts;
229
-    }
230
-
231
-
232
-    /**
233
-     * Generate select input with provided messenger options array.
234
-     *
235
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
236
-     *                                 labels.
237
-     * @return string
238
-     * @throws EE_Error
239
-     */
240
-    public function get_messengers_select_input($messenger_options)
241
-    {
242
-        // if empty or just one value then just return an empty string
243
-        if (empty($messenger_options)
244
-            || ! is_array($messenger_options)
245
-            || count($messenger_options) === 1
246
-        ) {
247
-            return '';
248
-        }
249
-        // merge in default
250
-        $messenger_options = array_merge(
251
-            array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
252
-            $messenger_options
253
-        );
254
-        $input = new EE_Select_Input(
255
-            $messenger_options,
256
-            array(
257
-                'html_name'  => 'ee_messenger_filter_by',
258
-                'html_id'    => 'ee_messenger_filter_by',
259
-                'html_class' => 'wide',
260
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
261
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
262
-                    : 'none_selected',
263
-            )
264
-        );
265
-
266
-        return $input->get_html_for_input();
267
-    }
268
-
269
-
270
-    /**
271
-     * Generate select input with provided message type options array.
272
-     *
273
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
274
-     *                                    message type labels
275
-     * @return string
276
-     * @throws EE_Error
277
-     */
278
-    public function get_message_types_select_input($message_type_options)
279
-    {
280
-        // if empty or count of options is 1 then just return an empty string
281
-        if (empty($message_type_options)
282
-            || ! is_array($message_type_options)
283
-            || count($message_type_options) === 1
284
-        ) {
285
-            return '';
286
-        }
287
-        // merge in default
288
-        $message_type_options = array_merge(
289
-            array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
290
-            $message_type_options
291
-        );
292
-        $input = new EE_Select_Input(
293
-            $message_type_options,
294
-            array(
295
-                'html_name'  => 'ee_message_type_filter_by',
296
-                'html_id'    => 'ee_message_type_filter_by',
297
-                'html_class' => 'wide',
298
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
299
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
300
-                    : 'none_selected',
301
-            )
302
-        );
303
-
304
-        return $input->get_html_for_input();
305
-    }
306
-
307
-
308
-    /**
309
-     * Generate select input with provide message type contexts array.
310
-     *
311
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
312
-     *                               context label.
313
-     * @return string
314
-     * @throws EE_Error
315
-     */
316
-    public function get_contexts_for_message_types_select_input($context_options)
317
-    {
318
-        // if empty or count of options is one then just return empty string
319
-        if (empty($context_options)
320
-            || ! is_array($context_options)
321
-            || count($context_options) === 1
322
-        ) {
323
-            return '';
324
-        }
325
-        // merge in default
326
-        $context_options = array_merge(
327
-            array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
328
-            $context_options
329
-        );
330
-        $input = new EE_Select_Input(
331
-            $context_options,
332
-            array(
333
-                'html_name'  => 'ee_context_filter_by',
334
-                'html_id'    => 'ee_context_filter_by',
335
-                'html_class' => 'wide',
336
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
337
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
338
-                    : 'none_selected',
339
-            )
340
-        );
341
-
342
-        return $input->get_html_for_input();
343
-    }
344
-
345
-
346
-    protected function _ajax_hooks()
347
-    {
348
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
349
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
350
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
351
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
352
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
353
-        add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
354
-    }
355
-
356
-
357
-    protected function _define_page_props()
358
-    {
359
-        $this->_admin_page_title = $this->page_label;
360
-        $this->_labels = array(
361
-            'buttons'    => array(
362
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
363
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
364
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
365
-            ),
366
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
367
-        );
368
-    }
369
-
370
-
371
-    /**
372
-     *        an array for storing key => value pairs of request actions and their corresponding methods
373
-     *
374
-     * @access protected
375
-     * @return void
376
-     */
377
-    protected function _set_page_routes()
378
-    {
379
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
380
-            ? $this->_req_data['GRP_ID']
381
-            : 0;
382
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
383
-            ? $this->_req_data['id']
384
-            : $grp_id;
385
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
386
-            ? $this->_req_data['MSG_ID']
387
-            : 0;
388
-
389
-        $this->_page_routes = array(
390
-            'default'                          => array(
391
-                'func'       => '_message_queue_list_table',
392
-                'capability' => 'ee_read_global_messages',
393
-            ),
394
-            'global_mtps'                      => array(
395
-                'func'       => '_ee_default_messages_overview_list_table',
396
-                'capability' => 'ee_read_global_messages',
397
-            ),
398
-            'custom_mtps'                      => array(
399
-                'func'       => '_custom_mtps_preview',
400
-                'capability' => 'ee_read_messages',
401
-            ),
402
-            'add_new_message_template'         => array(
403
-                'func'       => '_add_message_template',
404
-                'capability' => 'ee_edit_messages',
405
-                'noheader'   => true,
406
-            ),
407
-            'edit_message_template'            => array(
408
-                'func'       => '_edit_message_template',
409
-                'capability' => 'ee_edit_message',
410
-                'obj_id'     => $grp_id,
411
-            ),
412
-            'preview_message'                  => array(
413
-                'func'               => '_preview_message',
414
-                'capability'         => 'ee_read_message',
415
-                'obj_id'             => $grp_id,
416
-                'noheader'           => true,
417
-                'headers_sent_route' => 'display_preview_message',
418
-            ),
419
-            'display_preview_message'          => array(
420
-                'func'       => '_display_preview_message',
421
-                'capability' => 'ee_read_message',
422
-                'obj_id'     => $grp_id,
423
-            ),
424
-            'insert_message_template'          => array(
425
-                'func'       => '_insert_or_update_message_template',
426
-                'capability' => 'ee_edit_messages',
427
-                'args'       => array('new_template' => true),
428
-                'noheader'   => true,
429
-            ),
430
-            'update_message_template'          => array(
431
-                'func'       => '_insert_or_update_message_template',
432
-                'capability' => 'ee_edit_message',
433
-                'obj_id'     => $grp_id,
434
-                'args'       => array('new_template' => false),
435
-                'noheader'   => true,
436
-            ),
437
-            'trash_message_template'           => array(
438
-                'func'       => '_trash_or_restore_message_template',
439
-                'capability' => 'ee_delete_message',
440
-                'obj_id'     => $grp_id,
441
-                'args'       => array('trash' => true, 'all' => true),
442
-                'noheader'   => true,
443
-            ),
444
-            'trash_message_template_context'   => array(
445
-                'func'       => '_trash_or_restore_message_template',
446
-                'capability' => 'ee_delete_message',
447
-                'obj_id'     => $grp_id,
448
-                'args'       => array('trash' => true),
449
-                'noheader'   => true,
450
-            ),
451
-            'restore_message_template'         => array(
452
-                'func'       => '_trash_or_restore_message_template',
453
-                'capability' => 'ee_delete_message',
454
-                'obj_id'     => $grp_id,
455
-                'args'       => array('trash' => false, 'all' => true),
456
-                'noheader'   => true,
457
-            ),
458
-            'restore_message_template_context' => array(
459
-                'func'       => '_trash_or_restore_message_template',
460
-                'capability' => 'ee_delete_message',
461
-                'obj_id'     => $grp_id,
462
-                'args'       => array('trash' => false),
463
-                'noheader'   => true,
464
-            ),
465
-            'delete_message_template'          => array(
466
-                'func'       => '_delete_message_template',
467
-                'capability' => 'ee_delete_message',
468
-                'obj_id'     => $grp_id,
469
-                'noheader'   => true,
470
-            ),
471
-            'reset_to_default'                 => array(
472
-                'func'       => '_reset_to_default_template',
473
-                'capability' => 'ee_edit_message',
474
-                'obj_id'     => $grp_id,
475
-                'noheader'   => true,
476
-            ),
477
-            'settings'                         => array(
478
-                'func'       => '_settings',
479
-                'capability' => 'manage_options',
480
-            ),
481
-            'update_global_settings'           => array(
482
-                'func'       => '_update_global_settings',
483
-                'capability' => 'manage_options',
484
-                'noheader'   => true,
485
-            ),
486
-            'generate_now'                     => array(
487
-                'func'       => '_generate_now',
488
-                'capability' => 'ee_send_message',
489
-                'noheader'   => true,
490
-            ),
491
-            'generate_and_send_now'            => array(
492
-                'func'       => '_generate_and_send_now',
493
-                'capability' => 'ee_send_message',
494
-                'noheader'   => true,
495
-            ),
496
-            'queue_for_resending'              => array(
497
-                'func'       => '_queue_for_resending',
498
-                'capability' => 'ee_send_message',
499
-                'noheader'   => true,
500
-            ),
501
-            'send_now'                         => array(
502
-                'func'       => '_send_now',
503
-                'capability' => 'ee_send_message',
504
-                'noheader'   => true,
505
-            ),
506
-            'delete_ee_message'                => array(
507
-                'func'       => '_delete_ee_messages',
508
-                'capability' => 'ee_delete_messages',
509
-                'noheader'   => true,
510
-            ),
511
-            'delete_ee_messages'               => array(
512
-                'func'       => '_delete_ee_messages',
513
-                'capability' => 'ee_delete_messages',
514
-                'noheader'   => true,
515
-                'obj_id'     => $msg_id,
516
-            ),
517
-        );
518
-    }
519
-
520
-
521
-    protected function _set_page_config()
522
-    {
523
-        $this->_page_config = array(
524
-            'default'                  => array(
525
-                'nav'           => array(
526
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
527
-                    'order' => 10,
528
-                ),
529
-                'list_table'    => 'EE_Message_List_Table',
530
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
531
-                'require_nonce' => false,
532
-            ),
533
-            'global_mtps'              => array(
534
-                'nav'           => array(
535
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
536
-                    'order' => 20,
537
-                ),
538
-                'list_table'    => 'Messages_Template_List_Table',
539
-                'help_tabs'     => array(
540
-                    'messages_overview_help_tab'                                => array(
541
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
542
-                        'filename' => 'messages_overview',
543
-                    ),
544
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
545
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
546
-                        'filename' => 'messages_overview_table_column_headings',
547
-                    ),
548
-                    'messages_overview_messages_filters_help_tab'               => array(
549
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
550
-                        'filename' => 'messages_overview_filters',
551
-                    ),
552
-                    'messages_overview_messages_views_help_tab'                 => array(
553
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
554
-                        'filename' => 'messages_overview_views',
555
-                    ),
556
-                    'message_overview_message_types_help_tab'                   => array(
557
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
558
-                        'filename' => 'messages_overview_types',
559
-                    ),
560
-                    'messages_overview_messengers_help_tab'                     => array(
561
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
562
-                        'filename' => 'messages_overview_messengers',
563
-                    ),
564
-                ),
565
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
566
-                // 'help_tour'     => array('Messages_Overview_Help_Tour'),
567
-                'require_nonce' => false,
568
-            ),
569
-            'custom_mtps'              => array(
570
-                'nav'           => array(
571
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
-                    'order' => 30,
573
-                ),
574
-                'help_tabs'     => array(),
575
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
576
-                // 'help_tour'     => array(),
577
-                'require_nonce' => false,
578
-            ),
579
-            'add_new_message_template' => array(
580
-                'nav'           => array(
581
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
582
-                    'order'      => 5,
583
-                    'persistent' => false,
584
-                ),
585
-                'require_nonce' => false,
586
-            ),
587
-            'edit_message_template'    => array(
588
-                'labels'        => array(
589
-                    'buttons'    => array(
590
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
591
-                    ),
592
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
593
-                ),
594
-                'nav'           => array(
595
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
596
-                    'order'      => 5,
597
-                    'persistent' => false,
598
-                    'url'        => '',
599
-                ),
600
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
601
-                'has_metaboxes' => true,
602
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
603
-                // 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
604
-                'help_tabs'     => array(
605
-                    'edit_message_template'            => array(
606
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
607
-                        'callback' => 'edit_message_template_help_tab',
608
-                    ),
609
-                    'message_templates_help_tab'       => array(
610
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
611
-                        'filename' => 'messages_templates',
612
-                    ),
613
-                    'message_template_shortcodes'      => array(
614
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
615
-                        'callback' => 'message_template_shortcodes_help_tab',
616
-                    ),
617
-                    'message_preview_help_tab'         => array(
618
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
619
-                        'filename' => 'messages_preview',
620
-                    ),
621
-                    'messages_overview_other_help_tab' => array(
622
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
623
-                        'filename' => 'messages_overview_other',
624
-                    ),
625
-                ),
626
-                'require_nonce' => false,
627
-            ),
628
-            'display_preview_message'  => array(
629
-                'nav'           => array(
630
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
631
-                    'order'      => 5,
632
-                    'url'        => '',
633
-                    'persistent' => false,
634
-                ),
635
-                'help_tabs'     => array(
636
-                    'preview_message' => array(
637
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
638
-                        'callback' => 'preview_message_help_tab',
639
-                    ),
640
-                ),
641
-                'require_nonce' => false,
642
-            ),
643
-            'settings'                 => array(
644
-                'nav'           => array(
645
-                    'label' => esc_html__('Settings', 'event_espresso'),
646
-                    'order' => 40,
647
-                ),
648
-                'metaboxes'     => array('_messages_settings_metaboxes'),
649
-                'help_tabs'     => array(
650
-                    'messages_settings_help_tab'               => array(
651
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
652
-                        'filename' => 'messages_settings',
653
-                    ),
654
-                    'messages_settings_message_types_help_tab' => array(
655
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
656
-                        'filename' => 'messages_settings_message_types',
657
-                    ),
658
-                    'messages_settings_messengers_help_tab'    => array(
659
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
660
-                        'filename' => 'messages_settings_messengers',
661
-                    ),
662
-                ),
663
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
664
-                // 'help_tour'     => array('Messages_Settings_Help_Tour'),
665
-                'require_nonce' => false,
666
-            ),
667
-        );
668
-    }
669
-
670
-
671
-    protected function _add_screen_options()
672
-    {
673
-        // todo
674
-    }
675
-
676
-
677
-    protected function _add_screen_options_global_mtps()
678
-    {
679
-        /**
680
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
681
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
682
-         */
683
-        $page_title = $this->_admin_page_title;
684
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
685
-        $this->_per_page_screen_option();
686
-        $this->_admin_page_title = $page_title;
687
-    }
688
-
689
-
690
-    protected function _add_screen_options_default()
691
-    {
692
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
693
-        $this->_per_page_screen_option();
694
-    }
695
-
696
-
697
-    // none of the below group are currently used for Messages
698
-    protected function _add_feature_pointers()
699
-    {
700
-    }
701
-
702
-    public function admin_init()
703
-    {
704
-    }
705
-
706
-    public function admin_notices()
707
-    {
708
-    }
709
-
710
-    public function admin_footer_scripts()
711
-    {
712
-    }
713
-
714
-
715
-    public function messages_help_tab()
716
-    {
717
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
718
-    }
719
-
720
-
721
-    public function messengers_help_tab()
722
-    {
723
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
724
-    }
725
-
726
-
727
-    public function message_types_help_tab()
728
-    {
729
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
730
-    }
731
-
732
-
733
-    public function messages_overview_help_tab()
734
-    {
735
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
736
-    }
737
-
738
-
739
-    public function message_templates_help_tab()
740
-    {
741
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
742
-    }
743
-
744
-
745
-    public function edit_message_template_help_tab()
746
-    {
747
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
748
-                        . esc_attr__('Editor Title', 'event_espresso')
749
-                        . '" />';
750
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
751
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
752
-                        . '" />';
753
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
754
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
755
-                        . '" />';
756
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
757
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
758
-                        . '" />';
759
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
760
-                        . esc_attr__('Publish Metabox', 'event_espresso')
761
-                        . '" />';
762
-        EEH_Template::display_template(
763
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
764
-            $args
765
-        );
766
-    }
767
-
768
-
769
-    public function message_template_shortcodes_help_tab()
770
-    {
771
-        $this->_set_shortcodes();
772
-        $args['shortcodes'] = $this->_shortcodes;
773
-        EEH_Template::display_template(
774
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
775
-            $args
776
-        );
777
-    }
778
-
779
-
780
-    public function preview_message_help_tab()
781
-    {
782
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
783
-    }
784
-
785
-
786
-    public function settings_help_tab()
787
-    {
788
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
789
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
790
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
791
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
792
-        $args['img3'] = '<div class="switch">'
793
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
794
-                        . ' type="checkbox" checked="checked">'
795
-                        . '<label for="ee-on-off-toggle-on"></label>'
796
-                        . '</div>';
797
-        $args['img4'] = '<div class="switch">'
798
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
799
-                        . ' type="checkbox">'
800
-                        . '<label for="ee-on-off-toggle-on"></label>'
801
-                        . '</div>';
802
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
803
-    }
804
-
805
-
806
-    public function load_scripts_styles()
807
-    {
808
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
809
-        wp_enqueue_style('espresso_ee_msg');
810
-
811
-        wp_register_script(
812
-            'ee-messages-settings',
813
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
814
-            array('jquery-ui-droppable', 'ee-serialize-full-array'),
815
-            EVENT_ESPRESSO_VERSION,
816
-            true
817
-        );
818
-        wp_register_script(
819
-            'ee-msg-list-table-js',
820
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
821
-            array('ee-dialog'),
822
-            EVENT_ESPRESSO_VERSION
823
-        );
824
-    }
825
-
826
-
827
-    public function load_scripts_styles_default()
828
-    {
829
-        wp_enqueue_script('ee-msg-list-table-js');
830
-    }
831
-
832
-
833
-    public function wp_editor_css($mce_css)
834
-    {
835
-        // if we're on the edit_message_template route
836
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
837
-            $message_type_name = $this->_active_message_type_name;
838
-
839
-            // we're going to REPLACE the existing mce css
840
-            // we need to get the css file location from the active messenger
841
-            $mce_css = $this->_active_messenger->get_variation(
842
-                $this->_template_pack,
843
-                $message_type_name,
844
-                true,
845
-                'wpeditor',
846
-                $this->_variation
847
-            );
848
-        }
849
-
850
-        return $mce_css;
851
-    }
852
-
853
-
854
-    public function load_scripts_styles_edit_message_template()
855
-    {
856
-
857
-        $this->_set_shortcodes();
858
-
859
-        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
860
-            esc_html__(
861
-                '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.',
862
-                'event_espresso'
863
-            ),
864
-            $this->_message_template_group->messenger_obj()->label['singular'],
865
-            $this->_message_template_group->message_type_obj()->label['singular']
866
-        );
867
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
868
-            '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?',
869
-            'event_espresso'
870
-        );
871
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
872
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
873
-            'event_espresso'
874
-        );
875
-
876
-        wp_register_script(
877
-            'ee_msgs_edit_js',
878
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
879
-            array('jquery'),
880
-            EVENT_ESPRESSO_VERSION
881
-        );
882
-
883
-        wp_enqueue_script('ee_admin_js');
884
-        wp_enqueue_script('ee_msgs_edit_js');
885
-
886
-        // add in special css for tiny_mce
887
-        add_filter('mce_css', array($this, 'wp_editor_css'));
888
-    }
889
-
890
-
891
-    public function load_scripts_styles_display_preview_message()
892
-    {
893
-
894
-        $this->_set_message_template_group();
895
-
896
-        if (isset($this->_req_data['messenger'])) {
897
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
898
-                $this->_req_data['messenger']
899
-            );
900
-        }
901
-
902
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
903
-
904
-
905
-        wp_enqueue_style(
906
-            'espresso_preview_css',
907
-            $this->_active_messenger->get_variation(
908
-                $this->_template_pack,
909
-                $message_type_name,
910
-                true,
911
-                'preview',
912
-                $this->_variation
913
-            )
914
-        );
915
-    }
916
-
917
-
918
-    public function load_scripts_styles_settings()
919
-    {
920
-        wp_register_style(
921
-            'ee-message-settings',
922
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
923
-            array(),
924
-            EVENT_ESPRESSO_VERSION
925
-        );
926
-        wp_enqueue_style('ee-text-links');
927
-        wp_enqueue_style('ee-message-settings');
928
-        wp_enqueue_script('ee-messages-settings');
929
-    }
930
-
931
-
932
-    /**
933
-     * set views array for List Table
934
-     */
935
-    public function _set_list_table_views_global_mtps()
936
-    {
937
-        $this->_views = array(
938
-            'in_use' => array(
939
-                'slug'  => 'in_use',
940
-                'label' => esc_html__('In Use', 'event_espresso'),
941
-                'count' => 0,
942
-            ),
943
-        );
944
-    }
945
-
946
-
947
-    /**
948
-     * Set views array for the Custom Template List Table
949
-     */
950
-    public function _set_list_table_views_custom_mtps()
951
-    {
952
-        $this->_set_list_table_views_global_mtps();
953
-        $this->_views['in_use']['bulk_action'] = array(
954
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
955
-        );
956
-    }
957
-
958
-
959
-    /**
960
-     * set views array for message queue list table
961
-     *
962
-     * @throws InvalidDataTypeException
963
-     * @throws InvalidInterfaceException
964
-     * @throws InvalidArgumentException
965
-     * @throws EE_Error
966
-     * @throws ReflectionException
967
-     */
968
-    public function _set_list_table_views_default()
969
-    {
970
-        EE_Registry::instance()->load_helper('Template');
971
-
972
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
973
-            'ee_send_message',
974
-            'message_list_table_bulk_actions'
975
-        )
976
-            ? array(
977
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
978
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
979
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
980
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
981
-            )
982
-            : array();
983
-
984
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
985
-            'ee_delete_messages',
986
-            'message_list_table_bulk_actions'
987
-        )
988
-            ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
989
-            : array();
990
-
991
-
992
-        $this->_views = array(
993
-            'all' => array(
994
-                'slug'        => 'all',
995
-                'label'       => esc_html__('All', 'event_espresso'),
996
-                'count'       => 0,
997
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
998
-            ),
999
-        );
1000
-
1001
-
1002
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
1003
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1004
-                continue;
1005
-            }
1006
-            $status_bulk_actions = $common_bulk_actions;
1007
-            // unset bulk actions not applying to status
1008
-            if (! empty($status_bulk_actions)) {
1009
-                switch ($status) {
1010
-                    case EEM_Message::status_idle:
1011
-                    case EEM_Message::status_resend:
1012
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1013
-                        break;
1014
-
1015
-                    case EEM_Message::status_failed:
1016
-                    case EEM_Message::status_debug_only:
1017
-                    case EEM_Message::status_messenger_executing:
1018
-                        $status_bulk_actions = array();
1019
-                        break;
1020
-
1021
-                    case EEM_Message::status_incomplete:
1022
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1023
-                        break;
1024
-
1025
-                    case EEM_Message::status_retry:
1026
-                    case EEM_Message::status_sent:
1027
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1028
-                        break;
1029
-                }
1030
-            }
1031
-
1032
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1033
-            if ($status === EEM_Message::status_messenger_executing) {
1034
-                continue;
1035
-            }
1036
-
1037
-            $this->_views[ strtolower($status) ] = array(
1038
-                'slug'        => strtolower($status),
1039
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1040
-                'count'       => 0,
1041
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1042
-            );
1043
-        }
1044
-    }
1045
-
1046
-
1047
-    protected function _ee_default_messages_overview_list_table()
1048
-    {
1049
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1050
-        $this->display_admin_list_table_page_with_no_sidebar();
1051
-    }
1052
-
1053
-
1054
-    protected function _message_queue_list_table()
1055
-    {
1056
-        $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso');
1057
-        $this->_template_args['per_column'] = 6;
1058
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());
1059
-        $this->_template_args['before_list_table'] = '<h3>'
1060
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1061
-                                                     . '</h3>';
1062
-        $this->display_admin_list_table_page_with_no_sidebar();
1063
-    }
1064
-
1065
-
1066
-    protected function _message_legend_items()
1067
-    {
1068
-
1069
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1070
-        $action_items = array();
1071
-
1072
-        foreach ($action_css_classes as $action_item => $action_details) {
1073
-            if ($action_item === 'see_notifications_for') {
1074
-                continue;
1075
-            }
1076
-            $action_items[ $action_item ] = array(
1077
-                'class' => $action_details['css_class'],
1078
-                'desc'  => $action_details['label'],
1079
-            );
1080
-        }
1081
-
1082
-        /** @type array $status_items status legend setup */
1083
-        $status_items = array(
1084
-            'sent_status'                => array(
1085
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1086
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1087
-            ),
1088
-            'idle_status'                => array(
1089
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1090
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1091
-            ),
1092
-            'failed_status'              => array(
1093
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1094
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1095
-            ),
1096
-            'messenger_executing_status' => array(
1097
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1098
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1099
-            ),
1100
-            'resend_status'              => array(
1101
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1102
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1103
-            ),
1104
-            'incomplete_status'          => array(
1105
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1106
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1107
-            ),
1108
-            'retry_status'               => array(
1109
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1110
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1111
-            ),
1112
-        );
1113
-        if (EEM_Message::debug()) {
1114
-            $status_items['debug_only_status'] = array(
1115
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1116
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1117
-            );
1118
-        }
1119
-
1120
-        return array_merge($action_items, $status_items);
1121
-    }
1122
-
1123
-
1124
-    protected function _custom_mtps_preview()
1125
-    {
1126
-        $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1127
-        $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1128
-                                               . ' alt="' . esc_attr__(
1129
-                                                   'Preview Custom Message Templates screenshot',
1130
-                                                   'event_espresso'
1131
-                                               ) . '" />';
1132
-        $this->_template_args['preview_text'] = '<strong>'
1133
-                                                . esc_html__(
1134
-                                                    '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.',
1135
-                                                    'event_espresso'
1136
-                                                )
1137
-                                                . '</strong>';
1138
-
1139
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1140
-    }
1141
-
1142
-
1143
-    /**
1144
-     * get_message_templates
1145
-     * This gets all the message templates for listing on the overview list.
1146
-     *
1147
-     * @access public
1148
-     * @param int    $perpage the amount of templates groups to show per page
1149
-     * @param string $type    the current _view we're getting templates for
1150
-     * @param bool   $count   return count?
1151
-     * @param bool   $all     disregard any paging info (get all data);
1152
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1153
-     * @return array
1154
-     * @throws EE_Error
1155
-     * @throws InvalidArgumentException
1156
-     * @throws InvalidDataTypeException
1157
-     * @throws InvalidInterfaceException
1158
-     */
1159
-    public function get_message_templates(
1160
-        $perpage = 10,
1161
-        $type = 'in_use',
1162
-        $count = false,
1163
-        $all = false,
1164
-        $global = true
1165
-    ) {
1166
-
1167
-        $MTP = EEM_Message_Template_Group::instance();
1168
-
1169
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1170
-        $orderby = $this->_req_data['orderby'];
1171
-
1172
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1173
-            ? $this->_req_data['order']
1174
-            : 'ASC';
1175
-
1176
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1177
-            ? $this->_req_data['paged']
1178
-            : 1;
1179
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1180
-            ? $this->_req_data['perpage']
1181
-            : $perpage;
1182
-
1183
-        $offset = ($current_page - 1) * $per_page;
1184
-        $limit = $all ? null : array($offset, $per_page);
1185
-
1186
-
1187
-        // options will match what is in the _views array property
1188
-        switch ($type) {
1189
-            case 'in_use':
1190
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1191
-                break;
1192
-            default:
1193
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1194
-        }
1195
-
1196
-        return $templates;
1197
-    }
1198
-
1199
-
1200
-    /**
1201
-     * filters etc might need a list of installed message_types
1202
-     *
1203
-     * @return array an array of message type objects
1204
-     */
1205
-    public function get_installed_message_types()
1206
-    {
1207
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1208
-        $installed = array();
1209
-
1210
-        foreach ($installed_message_types as $message_type) {
1211
-            $installed[ $message_type->name ] = $message_type;
1212
-        }
1213
-
1214
-        return $installed;
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * _add_message_template
1220
-     *
1221
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1222
-     *
1223
-     * @param string $message_type
1224
-     * @param string $messenger
1225
-     * @param string $GRP_ID
1226
-     *
1227
-     * @throws EE_error
1228
-     */
1229
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1230
-    {
1231
-        // set values override any request data
1232
-        $message_type = ! empty($message_type) ? $message_type : $this->request->getRequestParam('message_type');
1233
-        $messenger = ! empty($messenger) ? $messenger : $this->request->getRequestParam('messenger');
1234
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1235
-
1236
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1237
-        if (empty($message_type) || empty($messenger)) {
1238
-            throw new EE_Error(
1239
-                esc_html__(
1240
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1241
-                    'event_espresso'
1242
-                )
1243
-            );
1244
-        }
1245
-
1246
-        // we need the GRP_ID for the template being used as the base for the new template
1247
-        if (empty($GRP_ID)) {
1248
-            throw new EE_Error(
1249
-                esc_html__(
1250
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1251
-                    'event_espresso'
1252
-                )
1253
-            );
1254
-        }
1255
-
1256
-        // let's just make sure the template gets generated!
1257
-
1258
-        // we need to reassign some variables for what the insert is expecting
1259
-        $this->_req_data['MTP_messenger'] = $messenger;
1260
-        $this->_req_data['MTP_message_type'] = $message_type;
1261
-        $this->_req_data['GRP_ID'] = $GRP_ID;
1262
-        $this->_insert_or_update_message_template(true);
1263
-    }
1264
-
1265
-
1266
-    /**
1267
-     * public wrapper for the _add_message_template method
1268
-     *
1269
-     * @param string $message_type     message type slug
1270
-     * @param string $messenger        messenger slug
1271
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1272
-     *                                 off of.
1273
-     * @throws EE_error
1274
-     */
1275
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1276
-    {
1277
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1278
-    }
1279
-
1280
-
1281
-    /**
1282
-     * _edit_message_template
1283
-     *
1284
-     * @access protected
1285
-     * @return void
1286
-     * @throws InvalidIdentifierException
1287
-     * @throws DomainException
1288
-     * @throws EE_Error
1289
-     * @throws InvalidArgumentException
1290
-     * @throws ReflectionException
1291
-     * @throws InvalidDataTypeException
1292
-     * @throws InvalidInterfaceException
1293
-     */
1294
-    protected function _edit_message_template()
1295
-    {
1296
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1297
-        $template_fields = '';
1298
-        $sidebar_fields = '';
1299
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1300
-        // valid html in the templates.
1301
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1302
-
1303
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1304
-            ? absint($this->_req_data['id'])
1305
-            : false;
1306
-
1307
-        $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
1308
-        ? absint($this->_req_data['evt_id'])
1309
-        : false;
1310
-
1311
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1312
-        $message_template_group = $this->_message_template_group;
1313
-        $c_label = $message_template_group->context_label();
1314
-        $c_config = $message_template_group->contexts_config();
1315
-
1316
-        reset($c_config);
1317
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1318
-            ? strtolower($this->_req_data['context'])
1319
-            : key($c_config);
1320
-
1321
-
1322
-        if (empty($GRP_ID)) {
1323
-            $action = 'insert_message_template';
1324
-            $edit_message_template_form_url = add_query_arg(
1325
-                array('action' => $action, 'noheader' => true),
1326
-                EE_MSG_ADMIN_URL
1327
-            );
1328
-        } else {
1329
-            $action = 'update_message_template';
1330
-            $edit_message_template_form_url = add_query_arg(
1331
-                array('action' => $action, 'noheader' => true),
1332
-                EE_MSG_ADMIN_URL
1333
-            );
1334
-        }
1335
-
1336
-        // set active messenger for this view
1337
-        $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
1338
-            $message_template_group->messenger()
1339
-        );
1340
-        $this->_active_message_type_name = $message_template_group->message_type();
1341
-
1342
-
1343
-        // Do we have any validation errors?
1344
-        $validators = $this->_get_transient();
1345
-        $v_fields = ! empty($validators) ? array_keys($validators) : array();
1346
-
1347
-
1348
-        // we need to assemble the title from Various details
1349
-        $context_label = sprintf(
1350
-            esc_html__('(%s %s)', 'event_espresso'),
1351
-            $c_config[ $context ]['label'],
1352
-            ucwords($c_label['label'])
1353
-        );
1354
-
1355
-        $title = sprintf(
1356
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1357
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1358
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1359
-            $context_label
1360
-        );
1361
-
1362
-        $this->_template_args['GRP_ID'] = $GRP_ID;
1363
-        $this->_template_args['message_template'] = $message_template_group;
1364
-        $this->_template_args['is_extra_fields'] = false;
1365
-
1366
-
1367
-        // let's get EEH_MSG_Template so we can get template form fields
1368
-        $template_field_structure = EEH_MSG_Template::get_fields(
1369
-            $message_template_group->messenger(),
1370
-            $message_template_group->message_type()
1371
-        );
1372
-
1373
-        if (! $template_field_structure) {
1374
-            $template_field_structure = false;
1375
-            $template_fields = esc_html__(
1376
-                'There was an error in assembling the fields for this display (you should see an error message)',
1377
-                'event_espresso'
1378
-            );
1379
-        }
1380
-
1381
-
1382
-        $message_templates = $message_template_group->context_templates();
1383
-
1384
-
1385
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1386
-        // will get handled in the "extra" array.
1387
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1388
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1389
-                unset($template_field_structure[ $context ][ $reference_field ]);
1390
-            }
1391
-        }
1392
-
1393
-        // let's loop through the template_field_structure and actually assemble the input fields!
1394
-        if (! empty($template_field_structure)) {
1395
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1396
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1397
-                // the extra array and reset them.
1398
-                if ($template_field === 'extra') {
1399
-                    $this->_template_args['is_extra_fields'] = true;
1400
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1401
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1402
-                        $content = $message_template instanceof EE_Message_Template
1403
-                            ? $message_template->get('MTP_content')
1404
-                            : '';
1405
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1406
-                            // let's verify if we need this extra field via the shortcodes parameter.
1407
-                            $continue = false;
1408
-                            if (isset($extra_array['shortcodes_required'])) {
1409
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1410
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1411
-                                        $continue = true;
1412
-                                    }
1413
-                                }
1414
-                                if ($continue) {
1415
-                                    continue;
1416
-                                }
1417
-                            }
1418
-
1419
-                            $field_id = $reference_field
1420
-                                        . '-'
1421
-                                        . $extra_field
1422
-                                        . '-content';
1423
-                            $template_form_fields[ $field_id ] = $extra_array;
1424
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1425
-                                                                         . $reference_field
1426
-                                                                         . '][content]['
1427
-                                                                         . $extra_field . ']';
1428
-                            $css_class = isset($extra_array['css_class'])
1429
-                                ? $extra_array['css_class']
1430
-                                : '';
1431
-
1432
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1433
-                                                                              && in_array($extra_field, $v_fields, true)
1434
-                                                                              &&
1435
-                                                                              (
1436
-                                                                                  is_array($validators[ $extra_field ])
1437
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1438
-                                                                              )
1439
-                                ? 'validate-error ' . $css_class
1440
-                                : $css_class;
1441
-
1442
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1443
-                                                                          && isset($content[ $extra_field ])
1444
-                                ? $content[ $extra_field ]
1445
-                                : '';
1446
-
1447
-                            // do we have a validation error?  if we do then let's use that value instead
1448
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1449
-                                ? $validators[ $extra_field ]['value']
1450
-                                : $template_form_fields[ $field_id ]['value'];
1451
-
1452
-
1453
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1454
-
1455
-                            // shortcode selector
1456
-                            $field_name_to_use = $extra_field === 'main'
1457
-                                ? 'content'
1458
-                                : $extra_field;
1459
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1460
-                                $field_name_to_use,
1461
-                                $field_id
1462
-                            );
1463
-
1464
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1465
-                                // we want to decode the entities
1466
-                                $template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value'];
1467
-                            }/**/
1468
-                        }
1469
-                        $templatefield_MTP_id = $reference_field . '-MTP_ID';
1470
-                        $templatefield_templatename_id = $reference_field . '-name';
1471
-
1472
-                        $template_form_fields[ $templatefield_MTP_id ] = array(
1473
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1474
-                            'label'      => null,
1475
-                            'input'      => 'hidden',
1476
-                            'type'       => 'int',
1477
-                            'required'   => false,
1478
-                            'validation' => false,
1479
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1480
-                            'css_class'  => '',
1481
-                            'format'     => '%d',
1482
-                            'db-col'     => 'MTP_ID',
1483
-                        );
1484
-
1485
-                        $template_form_fields[ $templatefield_templatename_id ] = array(
1486
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1487
-                            'label'      => null,
1488
-                            'input'      => 'hidden',
1489
-                            'type'       => 'string',
1490
-                            'required'   => false,
1491
-                            'validation' => true,
1492
-                            'value'      => $reference_field,
1493
-                            'css_class'  => '',
1494
-                            'format'     => '%s',
1495
-                            'db-col'     => 'MTP_template_field',
1496
-                        );
1497
-                    }
1498
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1499
-                } else {
1500
-                    $field_id = $template_field . '-content';
1501
-                    $template_form_fields[ $field_id ] = $field_setup_array;
1502
-                    $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]';
1503
-                    $message_template = isset($message_templates[ $context ][ $template_field ])
1504
-                        ? $message_templates[ $context ][ $template_field ]
1505
-                        : null;
1506
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1507
-                                                                  && is_array($message_templates[ $context ])
1508
-                                                                  && $message_template instanceof EE_Message_Template
1509
-                        ? $message_template->get('MTP_content')
1510
-                        : '';
1511
-
1512
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1513
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1514
-                        ? $validators[ $template_field ]['value']
1515
-                        : $template_form_fields[ $field_id ]['value'];
1516
-
1517
-
1518
-                    $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1519
-                    $css_class = isset($field_setup_array['css_class'])
1520
-                        ? $field_setup_array['css_class']
1521
-                        : '';
1522
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1523
-                                                                      && in_array($template_field, $v_fields, true)
1524
-                                                                      && isset($validators[ $template_field ]['msg'])
1525
-                        ? 'validate-error ' . $css_class
1526
-                        : $css_class;
1527
-
1528
-                    // shortcode selector
1529
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1530
-                        $template_field,
1531
-                        $field_id
1532
-                    );
1533
-                }
1534
-
1535
-                // k took care of content field(s) now let's take care of others.
1536
-
1537
-                $templatefield_MTP_id = $template_field . '-MTP_ID';
1538
-                $templatefield_field_templatename_id = $template_field . '-name';
1539
-
1540
-                // foreach template field there are actually two form fields created
1541
-                $template_form_fields[ $templatefield_MTP_id ] = array(
1542
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1543
-                    'label'      => null,
1544
-                    'input'      => 'hidden',
1545
-                    'type'       => 'int',
1546
-                    'required'   => false,
1547
-                    'validation' => true,
1548
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1549
-                    'css_class'  => '',
1550
-                    'format'     => '%d',
1551
-                    'db-col'     => 'MTP_ID',
1552
-                );
1553
-
1554
-                $template_form_fields[ $templatefield_field_templatename_id ] = array(
1555
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1556
-                    'label'      => null,
1557
-                    'input'      => 'hidden',
1558
-                    'type'       => 'string',
1559
-                    'required'   => false,
1560
-                    'validation' => true,
1561
-                    'value'      => $template_field,
1562
-                    'css_class'  => '',
1563
-                    'format'     => '%s',
1564
-                    'db-col'     => 'MTP_template_field',
1565
-                );
1566
-            }
1567
-
1568
-            // add other fields
1569
-            $template_form_fields['ee-msg-current-context'] = array(
1570
-                'name'       => 'MTP_context',
1571
-                'label'      => null,
1572
-                'input'      => 'hidden',
1573
-                'type'       => 'string',
1574
-                'required'   => false,
1575
-                'validation' => true,
1576
-                'value'      => $context,
1577
-                'css_class'  => '',
1578
-                'format'     => '%s',
1579
-                'db-col'     => 'MTP_context',
1580
-            );
1581
-
1582
-            $template_form_fields['ee-msg-grp-id'] = array(
1583
-                'name'       => 'GRP_ID',
1584
-                'label'      => null,
1585
-                'input'      => 'hidden',
1586
-                'type'       => 'int',
1587
-                'required'   => false,
1588
-                'validation' => true,
1589
-                'value'      => $GRP_ID,
1590
-                'css_class'  => '',
1591
-                'format'     => '%d',
1592
-                'db-col'     => 'GRP_ID',
1593
-            );
1594
-
1595
-            $template_form_fields['ee-msg-messenger'] = array(
1596
-                'name'       => 'MTP_messenger',
1597
-                'label'      => null,
1598
-                'input'      => 'hidden',
1599
-                'type'       => 'string',
1600
-                'required'   => false,
1601
-                'validation' => true,
1602
-                'value'      => $message_template_group->messenger(),
1603
-                'css_class'  => '',
1604
-                'format'     => '%s',
1605
-                'db-col'     => 'MTP_messenger',
1606
-            );
1607
-
1608
-            $template_form_fields['ee-msg-message-type'] = array(
1609
-                'name'       => 'MTP_message_type',
1610
-                'label'      => null,
1611
-                'input'      => 'hidden',
1612
-                'type'       => 'string',
1613
-                'required'   => false,
1614
-                'validation' => true,
1615
-                'value'      => $message_template_group->message_type(),
1616
-                'css_class'  => '',
1617
-                'format'     => '%s',
1618
-                'db-col'     => 'MTP_message_type',
1619
-            );
1620
-
1621
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1622
-                'name'       => 'MTP_is_global',
1623
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1624
-                'input'      => 'hidden',
1625
-                'type'       => 'int',
1626
-                'required'   => false,
1627
-                'validation' => true,
1628
-                'value'      => $message_template_group->get('MTP_is_global'),
1629
-                'css_class'  => '',
1630
-                'format'     => '%d',
1631
-                'db-col'     => 'MTP_is_global',
1632
-            );
1633
-
1634
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1635
-                'name'       => 'MTP_is_override',
1636
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1637
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1638
-                'type'       => 'int',
1639
-                'required'   => false,
1640
-                'validation' => true,
1641
-                'value'      => $message_template_group->get('MTP_is_override'),
1642
-                'css_class'  => '',
1643
-                'format'     => '%d',
1644
-                'db-col'     => 'MTP_is_override',
1645
-            );
1646
-
1647
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1648
-                'name'       => 'MTP_is_active',
1649
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1650
-                'input'      => 'hidden',
1651
-                'type'       => 'int',
1652
-                'required'   => false,
1653
-                'validation' => true,
1654
-                'value'      => $message_template_group->is_active(),
1655
-                'css_class'  => '',
1656
-                'format'     => '%d',
1657
-                'db-col'     => 'MTP_is_active',
1658
-            );
1659
-
1660
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1661
-                'name'       => 'MTP_deleted',
1662
-                'label'      => null,
1663
-                'input'      => 'hidden',
1664
-                'type'       => 'int',
1665
-                'required'   => false,
1666
-                'validation' => true,
1667
-                'value'      => $message_template_group->get('MTP_deleted'),
1668
-                'css_class'  => '',
1669
-                'format'     => '%d',
1670
-                'db-col'     => 'MTP_deleted',
1671
-            );
1672
-            $sidebar_form_fields['ee-msg-author'] = array(
1673
-                'name'       => 'MTP_user_id',
1674
-                'label'      => esc_html__('Author', 'event_espresso'),
1675
-                'input'      => 'hidden',
1676
-                'type'       => 'int',
1677
-                'required'   => false,
1678
-                'validation' => false,
1679
-                'value'      => $message_template_group->user(),
1680
-                'format'     => '%d',
1681
-                'db-col'     => 'MTP_user_id',
1682
-            );
1683
-
1684
-            $sidebar_form_fields['ee-msg-route'] = array(
1685
-                'name'  => 'action',
1686
-                'input' => 'hidden',
1687
-                'type'  => 'string',
1688
-                'value' => $action,
1689
-            );
1690
-
1691
-            $sidebar_form_fields['ee-msg-id'] = array(
1692
-                'name'  => 'id',
1693
-                'input' => 'hidden',
1694
-                'type'  => 'int',
1695
-                'value' => $GRP_ID,
1696
-            );
1697
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1698
-                'name'  => $action . '_nonce',
1699
-                'input' => 'hidden',
1700
-                'type'  => 'string',
1701
-                'value' => wp_create_nonce($action . '_nonce'),
1702
-            );
1703
-
1704
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1705
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1706
-                    'name'  => 'template_switch',
1707
-                    'input' => 'hidden',
1708
-                    'type'  => 'int',
1709
-                    'value' => 1,
1710
-                );
1711
-            }
1712
-
1713
-
1714
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1715
-            $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);
1716
-        } //end if ( !empty($template_field_structure) )
1717
-
1718
-        // set extra content for publish box
1719
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1720
-        $this->_set_publish_post_box_vars(
1721
-            'id',
1722
-            $GRP_ID,
1723
-            false,
1724
-            add_query_arg(
1725
-                array('action' => 'global_mtps'),
1726
-                $this->_admin_base_url
1727
-            )
1728
-        );
1729
-
1730
-        // add preview button
1731
-        $preview_url = parent::add_query_args_and_nonce(
1732
-            array(
1733
-                'message_type' => $message_template_group->message_type(),
1734
-                'messenger'    => $message_template_group->messenger(),
1735
-                'context'      => $context,
1736
-                'GRP_ID'       => $GRP_ID,
1737
-                'evt_id'       => $EVT_ID,
1738
-                'action'       => 'preview_message',
1739
-            ),
1740
-            $this->_admin_base_url
1741
-        );
1742
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1743
-                          . esc_html__('Preview', 'event_espresso')
1744
-                          . '</a>';
1745
-
1746
-
1747
-        // setup context switcher
1748
-        $context_switcher_args = array(
1749
-            'page'    => 'espresso_messages',
1750
-            'action'  => 'edit_message_template',
1751
-            'id'      => $GRP_ID,
1752
-            'evt_id'  => $EVT_ID,
1753
-            'context' => $context,
1754
-            'extra'   => $preview_button,
1755
-        );
1756
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1757
-
1758
-
1759
-        // main box
1760
-        $this->_template_args['template_fields'] = $template_fields;
1761
-        $this->_template_args['sidebar_box_id'] = 'details';
1762
-        $this->_template_args['action'] = $action;
1763
-        $this->_template_args['context'] = $context;
1764
-        $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;
1765
-        $this->_template_args['learn_more_about_message_templates_link'] =
1766
-            $this->_learn_more_about_message_templates_link();
1767
-
1768
-
1769
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1770
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1771
-            $message_template_group,
1772
-            $context,
1773
-            $context_label
1774
-        );
1775
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1776
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1777
-
1778
-        $this->_template_path = $this->_template_args['GRP_ID']
1779
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1780
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1781
-
1782
-        // send along EE_Message_Template_Group object for further template use.
1783
-        $this->_template_args['MTP'] = $message_template_group;
1784
-
1785
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1786
-            $this->_template_path,
1787
-            $this->_template_args,
1788
-            true
1789
-        );
1790
-
1791
-
1792
-        // finally, let's set the admin_page title
1793
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1794
-
1795
-
1796
-        // we need to take care of setting the shortcodes property for use elsewhere.
1797
-        $this->_set_shortcodes();
1798
-
1799
-
1800
-        // final template wrapper
1801
-        $this->display_admin_page_with_sidebar();
1802
-    }
1803
-
1804
-
1805
-    public function filter_tinymce_init($mceInit, $editor_id)
1806
-    {
1807
-        return $mceInit;
1808
-    }
1809
-
1810
-
1811
-    public function add_context_switcher()
1812
-    {
1813
-        return $this->_context_switcher;
1814
-    }
1815
-
1816
-
1817
-    /**
1818
-     * Adds the activation/deactivation toggle for the message template context.
1819
-     *
1820
-     * @param EE_Message_Template_Group $message_template_group
1821
-     * @param string                    $context
1822
-     * @param string                    $context_label
1823
-     * @return string
1824
-     * @throws DomainException
1825
-     * @throws EE_Error
1826
-     * @throws InvalidIdentifierException
1827
-     */
1828
-    protected function add_active_context_element(
1829
-        EE_Message_Template_Group $message_template_group,
1830
-        $context,
1831
-        $context_label
1832
-    ) {
1833
-        $template_args = array(
1834
-            'context'                   => $context,
1835
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1836
-            'is_active'                 => $message_template_group->is_context_active($context),
1837
-            'on_off_action'             => $message_template_group->is_context_active($context)
1838
-                ? 'context-off'
1839
-                : 'context-on',
1840
-            'context_label'             => str_replace(array('(', ')'), '', $context_label),
1841
-            'message_template_group_id' => $message_template_group->ID(),
1842
-        );
1843
-        return EEH_Template::display_template(
1844
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1845
-            $template_args,
1846
-            true
1847
-        );
1848
-    }
1849
-
1850
-
1851
-    /**
1852
-     * Ajax callback for `toggle_context_template` ajax action.
1853
-     * Handles toggling the message context on or off.
1854
-     *
1855
-     * @throws EE_Error
1856
-     * @throws InvalidArgumentException
1857
-     * @throws InvalidDataTypeException
1858
-     * @throws InvalidIdentifierException
1859
-     * @throws InvalidInterfaceException
1860
-     */
1861
-    public function toggle_context_template()
1862
-    {
1863
-        $success = true;
1864
-        // check for required data
1865
-        if (! isset(
1866
-            $this->_req_data['message_template_group_id'],
1867
-            $this->_req_data['context'],
1868
-            $this->_req_data['status']
1869
-        )) {
1870
-            EE_Error::add_error(
1871
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1872
-                __FILE__,
1873
-                __FUNCTION__,
1874
-                __LINE__
1875
-            );
1876
-            $success = false;
1877
-        }
1878
-
1879
-        $nonce = isset($this->_req_data['toggle_context_nonce'])
1880
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1881
-            : '';
1882
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1883
-        $this->_verify_nonce($nonce, $nonce_ref);
1884
-        $status = $this->_req_data['status'];
1885
-        if ($status !== 'off' && $status !== 'on') {
1886
-            EE_Error::add_error(
1887
-                sprintf(
1888
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1889
-                    $this->_req_data['status']
1890
-                ),
1891
-                __FILE__,
1892
-                __FUNCTION__,
1893
-                __LINE__
1894
-            );
1895
-            $success = false;
1896
-        }
1897
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1898
-            $this->_req_data['message_template_group_id']
1899
-        );
1900
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1901
-            EE_Error::add_error(
1902
-                sprintf(
1903
-                    esc_html__(
1904
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1905
-                        'event_espresso'
1906
-                    ),
1907
-                    $this->_req_data['message_template_group_id'],
1908
-                    'EE_Message_Template_Group'
1909
-                ),
1910
-                __FILE__,
1911
-                __FUNCTION__,
1912
-                __LINE__
1913
-            );
1914
-            $success = false;
1915
-        }
1916
-        if ($success) {
1917
-            $success = $status === 'off'
1918
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1919
-                : $message_template_group->activate_context($this->_req_data['context']);
1920
-        }
1921
-        $this->_template_args['success'] = $success;
1922
-        $this->_return_json();
1923
-    }
1924
-
1925
-
1926
-    public function _add_form_element_before()
1927
-    {
1928
-        return '<form method="post" action="'
1929
-               . $this->_template_args["edit_message_template_form_url"]
1930
-               . '" id="ee-msg-edit-frm">';
1931
-    }
1932
-
1933
-    public function _add_form_element_after()
1934
-    {
1935
-        return '</form>';
1936
-    }
1937
-
1938
-
1939
-    /**
1940
-     * This executes switching the template pack for a message template.
1941
-     *
1942
-     * @since 4.5.0
1943
-     * @throws EE_Error
1944
-     * @throws InvalidDataTypeException
1945
-     * @throws InvalidInterfaceException
1946
-     * @throws InvalidArgumentException
1947
-     * @throws ReflectionException
1948
-     */
1949
-    public function switch_template_pack()
1950
-    {
1951
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1952
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1953
-
1954
-        // verify we have needed values.
1955
-        if (empty($GRP_ID) || empty($template_pack)) {
1956
-            $this->_template_args['error'] = true;
1957
-            EE_Error::add_error(
1958
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1959
-                __FILE__,
1960
-                __FUNCTION__,
1961
-                __LINE__
1962
-            );
1963
-        } else {
1964
-            // get template, set the new template_pack and then reset to default
1965
-            /** @type EE_Message_Template_Group $message_template_group */
1966
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1967
-
1968
-            $message_template_group->set_template_pack_name($template_pack);
1969
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1970
-            $this->_req_data['mt'] = $message_template_group->message_type();
1971
-
1972
-            $query_args = $this->_reset_to_default_template();
1973
-
1974
-            if (empty($query_args['id'])) {
1975
-                EE_Error::add_error(
1976
-                    esc_html__(
1977
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1978
-                        'event_espresso'
1979
-                    ),
1980
-                    __FILE__,
1981
-                    __FUNCTION__,
1982
-                    __LINE__
1983
-                );
1984
-                $this->_template_args['error'] = true;
1985
-            } else {
1986
-                $template_label = $message_template_group->get_template_pack()->label;
1987
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1988
-                EE_Error::add_success(
1989
-                    sprintf(
1990
-                        esc_html__(
1991
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1992
-                            'event_espresso'
1993
-                        ),
1994
-                        $template_label,
1995
-                        $template_pack_labels->template_pack
1996
-                    )
1997
-                );
1998
-                // generate the redirect url for js.
1999
-                $url = self::add_query_args_and_nonce(
2000
-                    $query_args,
2001
-                    $this->_admin_base_url
2002
-                );
2003
-                $this->_template_args['data']['redirect_url'] = $url;
2004
-                $this->_template_args['success'] = true;
2005
-            }
2006
-
2007
-            $this->_return_json();
2008
-        }
2009
-    }
2010
-
2011
-
2012
-    /**
2013
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2014
-     * they want.
2015
-     *
2016
-     * @access protected
2017
-     * @return array|null
2018
-     * @throws EE_Error
2019
-     * @throws InvalidArgumentException
2020
-     * @throws InvalidDataTypeException
2021
-     * @throws InvalidInterfaceException
2022
-     */
2023
-    protected function _reset_to_default_template()
2024
-    {
2025
-
2026
-        $templates = array();
2027
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2028
-        // we need to make sure we've got the info we need.
2029
-        if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2030
-            EE_Error::add_error(
2031
-                esc_html__(
2032
-                    '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.',
2033
-                    'event_espresso'
2034
-                ),
2035
-                __FILE__,
2036
-                __FUNCTION__,
2037
-                __LINE__
2038
-            );
2039
-        }
2040
-
2041
-        // all templates will be reset to whatever the defaults are
2042
-        // for the global template matching the messenger and message type.
2043
-        $success = ! empty($GRP_ID) ? true : false;
2044
-
2045
-        if ($success) {
2046
-            // let's first determine if the incoming template is a global template,
2047
-            // if it isn't then we need to get the global template matching messenger and message type.
2048
-            // $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2049
-
2050
-
2051
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2052
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2053
-
2054
-            if ($success) {
2055
-                // if successfully deleted, lets generate the new ones.
2056
-                // Note. We set GLOBAL to true, because resets on ANY template
2057
-                // will use the related global template defaults for regeneration.
2058
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2059
-                // HOWEVER, we DO keep the template pack and template variation set
2060
-                // for the current custom template when resetting.
2061
-                $templates = $this->_generate_new_templates(
2062
-                    $this->_req_data['msgr'],
2063
-                    $this->_req_data['mt'],
2064
-                    $GRP_ID,
2065
-                    true
2066
-                );
2067
-            }
2068
-        }
2069
-
2070
-        // any error messages?
2071
-        if (! $success) {
2072
-            EE_Error::add_error(
2073
-                esc_html__(
2074
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2075
-                    'event_espresso'
2076
-                ),
2077
-                __FILE__,
2078
-                __FUNCTION__,
2079
-                __LINE__
2080
-            );
2081
-        }
2082
-
2083
-        // all good, let's add a success message!
2084
-        if ($success && ! empty($templates)) {
2085
-            // the info for the template we generated is the first element in the returned array
2086
-            // $templates = $templates[0];
2087
-            EE_Error::overwrite_success();
2088
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2089
-        }
2090
-
2091
-
2092
-        $query_args = array(
2093
-            'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2094
-            'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2095
-            'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2096
-        );
2097
-
2098
-        // if called via ajax then we return query args otherwise redirect
2099
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2100
-            return $query_args;
2101
-        } else {
2102
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2103
-
2104
-            return null;
2105
-        }
2106
-    }
2107
-
2108
-
2109
-    /**
2110
-     * Retrieve and set the message preview for display.
2111
-     *
2112
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2113
-     * @return string
2114
-     * @throws ReflectionException
2115
-     * @throws EE_Error
2116
-     * @throws InvalidArgumentException
2117
-     * @throws InvalidDataTypeException
2118
-     * @throws InvalidInterfaceException
2119
-     */
2120
-    public function _preview_message($send = false)
2121
-    {
2122
-        // first make sure we've got the necessary parameters
2123
-        if (
2124
-            ! (
2125
-                $this->request->requestParamIsSet('message_type')
2126
-                && $this->request->requestParamIsSet('messenger')
2127
-                && $this->request->requestParamIsSet('GRP_ID')
2128
-            )
2129
-        ) {
2130
-            EE_Error::add_error(
2131
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2132
-                __FILE__,
2133
-                __FUNCTION__,
2134
-                __LINE__
2135
-            );
2136
-        }
2137
-
2138
-        $context = $this->request->getRequestParam('context');
2139
-        $messenger = $this->request->getRequestParam('messenger');
2140
-        $message_type = $this->request->getRequestParam('message_type');
2141
-
2142
-        // get the preview!
2143
-        $preview = EED_Messages::preview_message($message_type, $context, $messenger, $send);
2144
-
2145
-        if ($send) {
2146
-            return $preview;
2147
-        }
2148
-
2149
-        // let's add a button to go back to the edit view
2150
-        $query_args = array(
2151
-            'id'      => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2152
-            'evt_id'  => $this->request->getRequestParam('evt_id', 0, 'int'),
2153
-            'context' => $context,
2154
-            'action'  => 'edit_message_template',
2155
-        );
2156
-        $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2157
-        $preview_button = '<a href="'
2158
-                          . $go_back_url
2159
-                          . '" class="button-secondary messages-preview-go-back-button">'
2160
-                          . esc_html__('Go Back to Edit', 'event_espresso')
2161
-                          . '</a>';
2162
-        $message_types = $this->get_installed_message_types();
2163
-        $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);
2164
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2165
-            ? ucwords($active_messenger->label['singular'])
2166
-            : esc_html__('Unknown Messenger', 'event_espresso');
2167
-        // let's provide a helpful title for context
2168
-        $preview_title = sprintf(
2169
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2170
-            $active_messenger_label,
2171
-            ucwords($message_types[ $message_type ]->label['singular'])
2172
-        );
2173
-        if (empty($preview)) {
2174
-            $this->noEventsErrorMessage();
2175
-        }
2176
-        // setup display of preview.
2177
-        $this->_admin_page_title = $preview_title;
2178
-        $this->_template_args['admin_page_title'] = $preview_title;
2179
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2180
-        $this->_template_args['data']['force_json'] = true;
2181
-
2182
-        return '';
2183
-    }
2184
-
2185
-
2186
-    /**
2187
-     * Used to set an error if there are no events available for generating a preview/test send.
2188
-     *
2189
-     * @param bool $test_send  Whether the error should be generated for the context of a test send.
2190
-     */
2191
-    protected function noEventsErrorMessage($test_send = false)
2192
-    {
2193
-        $events_url = parent::add_query_args_and_nonce(
2194
-            array(
2195
-                'action' => 'default',
2196
-                'page'   => 'espresso_events',
2197
-            ),
2198
-            admin_url('admin.php')
2199
-        );
2200
-        $message = $test_send
2201
-            ? __(
2202
-                '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!',
2203
-                'event_espresso'
2204
-            )
2205
-            : __(
2206
-                '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!',
2207
-                'event_espresso'
2208
-            );
2209
-
2210
-        EE_Error::add_attention(
2211
-            sprintf(
2212
-                $message,
2213
-                "<a href='{$events_url}'>",
2214
-                '</a>'
2215
-            )
2216
-        );
2217
-    }
2218
-
2219
-
2220
-    /**
2221
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2222
-     * gets called automatically.
2223
-     *
2224
-     * @since 4.5.0
2225
-     *
2226
-     * @return string
2227
-     */
2228
-    protected function _display_preview_message()
2229
-    {
2230
-        $this->display_admin_page_with_no_sidebar();
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     * registers metaboxes that should show up on the "edit_message_template" page
2236
-     *
2237
-     * @access protected
2238
-     * @return void
2239
-     */
2240
-    protected function _register_edit_meta_boxes()
2241
-    {
2242
-        add_meta_box(
2243
-            'mtp_valid_shortcodes',
2244
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2245
-            array($this, 'shortcode_meta_box'),
2246
-            $this->_current_screen->id,
2247
-            'side',
2248
-            'default'
2249
-        );
2250
-        add_meta_box(
2251
-            'mtp_extra_actions',
2252
-            esc_html__('Extra Actions', 'event_espresso'),
2253
-            array($this, 'extra_actions_meta_box'),
2254
-            $this->_current_screen->id,
2255
-            'side',
2256
-            'high'
2257
-        );
2258
-        add_meta_box(
2259
-            'mtp_templates',
2260
-            esc_html__('Template Styles', 'event_espresso'),
2261
-            array($this, 'template_pack_meta_box'),
2262
-            $this->_current_screen->id,
2263
-            'side',
2264
-            'high'
2265
-        );
2266
-    }
2267
-
2268
-
2269
-    /**
2270
-     * metabox content for all template pack and variation selection.
2271
-     *
2272
-     * @since 4.5.0
2273
-     * @return string
2274
-     * @throws DomainException
2275
-     * @throws EE_Error
2276
-     * @throws InvalidArgumentException
2277
-     * @throws ReflectionException
2278
-     * @throws InvalidDataTypeException
2279
-     * @throws InvalidInterfaceException
2280
-     */
2281
-    public function template_pack_meta_box()
2282
-    {
2283
-        $this->_set_message_template_group();
2284
-
2285
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2286
-
2287
-        $tp_select_values = array();
2288
-
2289
-        foreach ($tp_collection as $tp) {
2290
-            // only include template packs that support this messenger and message type!
2291
-            $supports = $tp->get_supports();
2292
-            if (! isset($supports[ $this->_message_template_group->messenger() ])
2293
-                || ! in_array(
2294
-                    $this->_message_template_group->message_type(),
2295
-                    $supports[ $this->_message_template_group->messenger() ],
2296
-                    true
2297
-                )
2298
-            ) {
2299
-                // not supported
2300
-                continue;
2301
-            }
2302
-
2303
-            $tp_select_values[] = array(
2304
-                'text' => $tp->label,
2305
-                'id'   => $tp->dbref,
2306
-            );
2307
-        }
2308
-
2309
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2310
-        // the default template pack.  This still allows for the odd template pack to override.
2311
-        if (empty($tp_select_values)) {
2312
-            $tp_select_values[] = array(
2313
-                'text' => esc_html__('Default', 'event_espresso'),
2314
-                'id'   => 'default',
2315
-            );
2316
-        }
2317
-
2318
-        // setup variation select values for the currently selected template.
2319
-        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2320
-            $this->_message_template_group->messenger(),
2321
-            $this->_message_template_group->message_type()
2322
-        );
2323
-        $variations_select_values = array();
2324
-        foreach ($variations as $variation => $label) {
2325
-            $variations_select_values[] = array(
2326
-                'text' => $label,
2327
-                'id'   => $variation,
2328
-            );
2329
-        }
2330
-
2331
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2332
-
2333
-        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2334
-            'MTP_template_pack',
2335
-            $tp_select_values,
2336
-            $this->_message_template_group->get_template_pack_name()
2337
-        );
2338
-        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2339
-            'MTP_template_variation',
2340
-            $variations_select_values,
2341
-            $this->_message_template_group->get_template_pack_variation()
2342
-        );
2343
-        $template_args['template_pack_label'] = $template_pack_labels->template_pack;
2344
-        $template_args['template_variation_label'] = $template_pack_labels->template_variation;
2345
-        $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;
2346
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2347
-
2348
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2349
-
2350
-        EEH_Template::display_template($template, $template_args);
2351
-    }
2352
-
2353
-
2354
-    /**
2355
-     * This meta box holds any extra actions related to Message Templates
2356
-     * For now, this includes Resetting templates to defaults and sending a test email.
2357
-     *
2358
-     * @access  public
2359
-     * @return void
2360
-     * @throws EE_Error
2361
-     */
2362
-    public function extra_actions_meta_box()
2363
-    {
2364
-        $template_form_fields = array();
2365
-
2366
-        $extra_args = array(
2367
-            'msgr'   => $this->_message_template_group->messenger(),
2368
-            'mt'     => $this->_message_template_group->message_type(),
2369
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2370
-        );
2371
-        // first we need to see if there are any fields
2372
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2373
-
2374
-        if (! empty($fields)) {
2375
-            // yup there be fields
2376
-            foreach ($fields as $field => $config) {
2377
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2378
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2379
-                $default = isset($config['default']) ? $config['default'] : '';
2380
-                $default = isset($config['value']) ? $config['value'] : $default;
2381
-
2382
-                // if type is hidden and the value is empty
2383
-                // something may have gone wrong so let's correct with the defaults
2384
-                $fix = $config['input'] === 'hidden'
2385
-                       && isset($existing[ $field ])
2386
-                       && empty($existing[ $field ])
2387
-                    ? $default
2388
-                    : '';
2389
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2390
-                    ? $existing[ $field ]
2391
-                    : $fix;
2392
-
2393
-                $template_form_fields[ $field_id ] = array(
2394
-                    'name'       => 'test_settings_fld[' . $field . ']',
2395
-                    'label'      => $config['label'],
2396
-                    'input'      => $config['input'],
2397
-                    'type'       => $config['type'],
2398
-                    'required'   => $config['required'],
2399
-                    'validation' => $config['validation'],
2400
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2401
-                    'css_class'  => $config['css_class'],
2402
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2403
-                    'default'    => $default,
2404
-                    'format'     => $config['format'],
2405
-                );
2406
-            }
2407
-        }
2408
-
2409
-        $test_settings_fields = ! empty($template_form_fields)
2410
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2411
-            : '';
2412
-
2413
-        $test_settings_html = '';
2414
-        // print out $test_settings_fields
2415
-        if (! empty($test_settings_fields)) {
2416
-            echo $test_settings_fields;
2417
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2418
-            $test_settings_html .= 'name="test_button" value="';
2419
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2420
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2421
-        }
2422
-
2423
-        // and button
2424
-        $test_settings_html .= '<p>'
2425
-                               . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2426
-                               . '</p>';
2427
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2428
-        $test_settings_html .= $this->get_action_link_or_button(
2429
-            'reset_to_default',
2430
-            'reset',
2431
-            $extra_args,
2432
-            'button-primary reset-default-button'
2433
-        );
2434
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2435
-        echo $test_settings_html;
2436
-    }
2437
-
2438
-
2439
-    /**
2440
-     * This returns the shortcode selector skeleton for a given context and field.
2441
-     *
2442
-     * @since 4.9.rc.000
2443
-     * @param string $field           The name of the field retrieving shortcodes for.
2444
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2445
-     * @return string
2446
-     * @throws DomainException
2447
-     * @throws EE_Error
2448
-     * @throws InvalidArgumentException
2449
-     * @throws ReflectionException
2450
-     * @throws InvalidDataTypeException
2451
-     * @throws InvalidInterfaceException
2452
-     */
2453
-    protected function _get_shortcode_selector($field, $linked_input_id)
2454
-    {
2455
-        $template_args = array(
2456
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2457
-            'fieldname'       => $field,
2458
-            'linked_input_id' => $linked_input_id,
2459
-        );
2460
-
2461
-        return EEH_Template::display_template(
2462
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2463
-            $template_args,
2464
-            true
2465
-        );
2466
-    }
2467
-
2468
-
2469
-    /**
2470
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2471
-     * page)
2472
-     *
2473
-     * @access public
2474
-     * @return void
2475
-     * @throws EE_Error
2476
-     * @throws InvalidArgumentException
2477
-     * @throws ReflectionException
2478
-     * @throws InvalidDataTypeException
2479
-     * @throws InvalidInterfaceException
2480
-     */
2481
-    public function shortcode_meta_box()
2482
-    {
2483
-        $shortcodes = $this->_get_shortcodes(array(), false); // just make sure shortcodes property is set
2484
-        // $messenger = $this->_message_template_group->messenger_obj();
2485
-        // now let's set the content depending on the status of the shortcodes array
2486
-        if (empty($shortcodes)) {
2487
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2488
-            echo $content;
2489
-        } else {
2490
-            // $alt = 0;
2491
-            ?>
22
+	/**
23
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
24
+	 */
25
+	protected $_message_resource_manager;
26
+
27
+	/**
28
+	 * @type string $_active_message_type_name
29
+	 */
30
+	protected $_active_message_type_name = '';
31
+
32
+	/**
33
+	 * @type EE_messenger $_active_messenger
34
+	 */
35
+	protected $_active_messenger;
36
+	protected $_activate_state;
37
+	protected $_activate_meta_box_type;
38
+	protected $_current_message_meta_box;
39
+	protected $_current_message_meta_box_object;
40
+	protected $_context_switcher;
41
+	protected $_shortcodes = array();
42
+	protected $_active_messengers = array();
43
+	protected $_active_message_types = array();
44
+
45
+	/**
46
+	 * @var EE_Message_Template_Group $_message_template_group
47
+	 */
48
+	protected $_message_template_group;
49
+	protected $_m_mt_settings = array();
50
+
51
+
52
+	/**
53
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
54
+	 * IF there is no group then it gets automatically set to the Default template pack.
55
+	 *
56
+	 * @since 4.5.0
57
+	 *
58
+	 * @var EE_Messages_Template_Pack
59
+	 */
60
+	protected $_template_pack;
61
+
62
+
63
+	/**
64
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
65
+	 * group is.  If there is no group then it automatically gets set to default.
66
+	 *
67
+	 * @since 4.5.0
68
+	 *
69
+	 * @var string
70
+	 */
71
+	protected $_variation;
72
+
73
+
74
+	/**
75
+	 * @param bool $routing
76
+	 * @throws EE_Error
77
+	 */
78
+	public function __construct($routing = true)
79
+	{
80
+		// make sure messages autoloader is running
81
+		EED_Messages::set_autoloaders();
82
+		parent::__construct($routing);
83
+	}
84
+
85
+
86
+	protected function _init_page_props()
87
+	{
88
+		$this->page_slug = EE_MSG_PG_SLUG;
89
+		$this->page_label = esc_html__('Messages Settings', 'event_espresso');
90
+		$this->_admin_base_url = EE_MSG_ADMIN_URL;
91
+		$this->_admin_base_path = EE_MSG_ADMIN;
92
+
93
+		$this->_activate_state = isset($this->_req_data['activate_state'])
94
+			? (array) $this->_req_data['activate_state']
95
+			: array();
96
+
97
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
98
+		$this->_load_message_resource_manager();
99
+	}
100
+
101
+
102
+	/**
103
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
104
+	 *
105
+	 * @throws EE_Error
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws InvalidInterfaceException
108
+	 * @throws InvalidArgumentException
109
+	 * @throws ReflectionException
110
+	 */
111
+	protected function _load_message_resource_manager()
112
+	{
113
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
114
+	}
115
+
116
+
117
+	/**
118
+	 * @deprecated 4.9.9.rc.014
119
+	 * @return array
120
+	 * @throws EE_Error
121
+	 * @throws InvalidArgumentException
122
+	 * @throws InvalidDataTypeException
123
+	 * @throws InvalidInterfaceException
124
+	 */
125
+	public function get_messengers_for_list_table()
126
+	{
127
+		EE_Error::doing_it_wrong(
128
+			__METHOD__,
129
+			sprintf(
130
+				esc_html__(
131
+					'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',
132
+					'event_espresso'
133
+				),
134
+				'Messages_Admin_Page::get_messengers_select_input()'
135
+			),
136
+			'4.9.9.rc.014'
137
+		);
138
+
139
+		$m_values = array();
140
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
141
+		// setup messengers for selects
142
+		$i = 1;
143
+		foreach ($active_messengers as $active_messenger) {
144
+			if ($active_messenger instanceof EE_Message) {
145
+				$m_values[ $i ]['id'] = $active_messenger->messenger();
146
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
147
+				$i++;
148
+			}
149
+		}
150
+
151
+		return $m_values;
152
+	}
153
+
154
+
155
+	/**
156
+	 * @deprecated 4.9.9.rc.014
157
+	 * @return array
158
+	 * @throws EE_Error
159
+	 * @throws InvalidArgumentException
160
+	 * @throws InvalidDataTypeException
161
+	 * @throws InvalidInterfaceException
162
+	 */
163
+	public function get_message_types_for_list_table()
164
+	{
165
+		EE_Error::doing_it_wrong(
166
+			__METHOD__,
167
+			sprintf(
168
+				esc_html__(
169
+					'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',
170
+					'event_espresso'
171
+				),
172
+				'Messages_Admin_Page::get_message_types_select_input()'
173
+			),
174
+			'4.9.9.rc.014'
175
+		);
176
+
177
+		$mt_values = array();
178
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
179
+		$i = 1;
180
+		foreach ($active_messages as $active_message) {
181
+			if ($active_message instanceof EE_Message) {
182
+				$mt_values[ $i ]['id'] = $active_message->message_type();
183
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
184
+				$i++;
185
+			}
186
+		}
187
+
188
+		return $mt_values;
189
+	}
190
+
191
+
192
+	/**
193
+	 * @deprecated 4.9.9.rc.014
194
+	 * @return array
195
+	 * @throws EE_Error
196
+	 * @throws InvalidArgumentException
197
+	 * @throws InvalidDataTypeException
198
+	 * @throws InvalidInterfaceException
199
+	 */
200
+	public function get_contexts_for_message_types_for_list_table()
201
+	{
202
+		EE_Error::doing_it_wrong(
203
+			__METHOD__,
204
+			sprintf(
205
+				esc_html__(
206
+					'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',
207
+					'event_espresso'
208
+				),
209
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
210
+			),
211
+			'4.9.9.rc.014'
212
+		);
213
+
214
+		$contexts = array();
215
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
216
+		foreach ($active_message_contexts as $active_message) {
217
+			if ($active_message instanceof EE_Message) {
218
+				$message_type = $active_message->message_type_object();
219
+				if ($message_type instanceof EE_message_type) {
220
+					$message_type_contexts = $message_type->get_contexts();
221
+					foreach ($message_type_contexts as $context => $context_details) {
222
+						$contexts[ $context ] = $context_details['label'];
223
+					}
224
+				}
225
+			}
226
+		}
227
+
228
+		return $contexts;
229
+	}
230
+
231
+
232
+	/**
233
+	 * Generate select input with provided messenger options array.
234
+	 *
235
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
236
+	 *                                 labels.
237
+	 * @return string
238
+	 * @throws EE_Error
239
+	 */
240
+	public function get_messengers_select_input($messenger_options)
241
+	{
242
+		// if empty or just one value then just return an empty string
243
+		if (empty($messenger_options)
244
+			|| ! is_array($messenger_options)
245
+			|| count($messenger_options) === 1
246
+		) {
247
+			return '';
248
+		}
249
+		// merge in default
250
+		$messenger_options = array_merge(
251
+			array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
252
+			$messenger_options
253
+		);
254
+		$input = new EE_Select_Input(
255
+			$messenger_options,
256
+			array(
257
+				'html_name'  => 'ee_messenger_filter_by',
258
+				'html_id'    => 'ee_messenger_filter_by',
259
+				'html_class' => 'wide',
260
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
261
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
262
+					: 'none_selected',
263
+			)
264
+		);
265
+
266
+		return $input->get_html_for_input();
267
+	}
268
+
269
+
270
+	/**
271
+	 * Generate select input with provided message type options array.
272
+	 *
273
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
274
+	 *                                    message type labels
275
+	 * @return string
276
+	 * @throws EE_Error
277
+	 */
278
+	public function get_message_types_select_input($message_type_options)
279
+	{
280
+		// if empty or count of options is 1 then just return an empty string
281
+		if (empty($message_type_options)
282
+			|| ! is_array($message_type_options)
283
+			|| count($message_type_options) === 1
284
+		) {
285
+			return '';
286
+		}
287
+		// merge in default
288
+		$message_type_options = array_merge(
289
+			array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
290
+			$message_type_options
291
+		);
292
+		$input = new EE_Select_Input(
293
+			$message_type_options,
294
+			array(
295
+				'html_name'  => 'ee_message_type_filter_by',
296
+				'html_id'    => 'ee_message_type_filter_by',
297
+				'html_class' => 'wide',
298
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
299
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
300
+					: 'none_selected',
301
+			)
302
+		);
303
+
304
+		return $input->get_html_for_input();
305
+	}
306
+
307
+
308
+	/**
309
+	 * Generate select input with provide message type contexts array.
310
+	 *
311
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
312
+	 *                               context label.
313
+	 * @return string
314
+	 * @throws EE_Error
315
+	 */
316
+	public function get_contexts_for_message_types_select_input($context_options)
317
+	{
318
+		// if empty or count of options is one then just return empty string
319
+		if (empty($context_options)
320
+			|| ! is_array($context_options)
321
+			|| count($context_options) === 1
322
+		) {
323
+			return '';
324
+		}
325
+		// merge in default
326
+		$context_options = array_merge(
327
+			array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
328
+			$context_options
329
+		);
330
+		$input = new EE_Select_Input(
331
+			$context_options,
332
+			array(
333
+				'html_name'  => 'ee_context_filter_by',
334
+				'html_id'    => 'ee_context_filter_by',
335
+				'html_class' => 'wide',
336
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
337
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
338
+					: 'none_selected',
339
+			)
340
+		);
341
+
342
+		return $input->get_html_for_input();
343
+	}
344
+
345
+
346
+	protected function _ajax_hooks()
347
+	{
348
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
349
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
350
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
351
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
352
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
353
+		add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
354
+	}
355
+
356
+
357
+	protected function _define_page_props()
358
+	{
359
+		$this->_admin_page_title = $this->page_label;
360
+		$this->_labels = array(
361
+			'buttons'    => array(
362
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
363
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
364
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
365
+			),
366
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
367
+		);
368
+	}
369
+
370
+
371
+	/**
372
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
373
+	 *
374
+	 * @access protected
375
+	 * @return void
376
+	 */
377
+	protected function _set_page_routes()
378
+	{
379
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
380
+			? $this->_req_data['GRP_ID']
381
+			: 0;
382
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
383
+			? $this->_req_data['id']
384
+			: $grp_id;
385
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
386
+			? $this->_req_data['MSG_ID']
387
+			: 0;
388
+
389
+		$this->_page_routes = array(
390
+			'default'                          => array(
391
+				'func'       => '_message_queue_list_table',
392
+				'capability' => 'ee_read_global_messages',
393
+			),
394
+			'global_mtps'                      => array(
395
+				'func'       => '_ee_default_messages_overview_list_table',
396
+				'capability' => 'ee_read_global_messages',
397
+			),
398
+			'custom_mtps'                      => array(
399
+				'func'       => '_custom_mtps_preview',
400
+				'capability' => 'ee_read_messages',
401
+			),
402
+			'add_new_message_template'         => array(
403
+				'func'       => '_add_message_template',
404
+				'capability' => 'ee_edit_messages',
405
+				'noheader'   => true,
406
+			),
407
+			'edit_message_template'            => array(
408
+				'func'       => '_edit_message_template',
409
+				'capability' => 'ee_edit_message',
410
+				'obj_id'     => $grp_id,
411
+			),
412
+			'preview_message'                  => array(
413
+				'func'               => '_preview_message',
414
+				'capability'         => 'ee_read_message',
415
+				'obj_id'             => $grp_id,
416
+				'noheader'           => true,
417
+				'headers_sent_route' => 'display_preview_message',
418
+			),
419
+			'display_preview_message'          => array(
420
+				'func'       => '_display_preview_message',
421
+				'capability' => 'ee_read_message',
422
+				'obj_id'     => $grp_id,
423
+			),
424
+			'insert_message_template'          => array(
425
+				'func'       => '_insert_or_update_message_template',
426
+				'capability' => 'ee_edit_messages',
427
+				'args'       => array('new_template' => true),
428
+				'noheader'   => true,
429
+			),
430
+			'update_message_template'          => array(
431
+				'func'       => '_insert_or_update_message_template',
432
+				'capability' => 'ee_edit_message',
433
+				'obj_id'     => $grp_id,
434
+				'args'       => array('new_template' => false),
435
+				'noheader'   => true,
436
+			),
437
+			'trash_message_template'           => array(
438
+				'func'       => '_trash_or_restore_message_template',
439
+				'capability' => 'ee_delete_message',
440
+				'obj_id'     => $grp_id,
441
+				'args'       => array('trash' => true, 'all' => true),
442
+				'noheader'   => true,
443
+			),
444
+			'trash_message_template_context'   => array(
445
+				'func'       => '_trash_or_restore_message_template',
446
+				'capability' => 'ee_delete_message',
447
+				'obj_id'     => $grp_id,
448
+				'args'       => array('trash' => true),
449
+				'noheader'   => true,
450
+			),
451
+			'restore_message_template'         => array(
452
+				'func'       => '_trash_or_restore_message_template',
453
+				'capability' => 'ee_delete_message',
454
+				'obj_id'     => $grp_id,
455
+				'args'       => array('trash' => false, 'all' => true),
456
+				'noheader'   => true,
457
+			),
458
+			'restore_message_template_context' => array(
459
+				'func'       => '_trash_or_restore_message_template',
460
+				'capability' => 'ee_delete_message',
461
+				'obj_id'     => $grp_id,
462
+				'args'       => array('trash' => false),
463
+				'noheader'   => true,
464
+			),
465
+			'delete_message_template'          => array(
466
+				'func'       => '_delete_message_template',
467
+				'capability' => 'ee_delete_message',
468
+				'obj_id'     => $grp_id,
469
+				'noheader'   => true,
470
+			),
471
+			'reset_to_default'                 => array(
472
+				'func'       => '_reset_to_default_template',
473
+				'capability' => 'ee_edit_message',
474
+				'obj_id'     => $grp_id,
475
+				'noheader'   => true,
476
+			),
477
+			'settings'                         => array(
478
+				'func'       => '_settings',
479
+				'capability' => 'manage_options',
480
+			),
481
+			'update_global_settings'           => array(
482
+				'func'       => '_update_global_settings',
483
+				'capability' => 'manage_options',
484
+				'noheader'   => true,
485
+			),
486
+			'generate_now'                     => array(
487
+				'func'       => '_generate_now',
488
+				'capability' => 'ee_send_message',
489
+				'noheader'   => true,
490
+			),
491
+			'generate_and_send_now'            => array(
492
+				'func'       => '_generate_and_send_now',
493
+				'capability' => 'ee_send_message',
494
+				'noheader'   => true,
495
+			),
496
+			'queue_for_resending'              => array(
497
+				'func'       => '_queue_for_resending',
498
+				'capability' => 'ee_send_message',
499
+				'noheader'   => true,
500
+			),
501
+			'send_now'                         => array(
502
+				'func'       => '_send_now',
503
+				'capability' => 'ee_send_message',
504
+				'noheader'   => true,
505
+			),
506
+			'delete_ee_message'                => array(
507
+				'func'       => '_delete_ee_messages',
508
+				'capability' => 'ee_delete_messages',
509
+				'noheader'   => true,
510
+			),
511
+			'delete_ee_messages'               => array(
512
+				'func'       => '_delete_ee_messages',
513
+				'capability' => 'ee_delete_messages',
514
+				'noheader'   => true,
515
+				'obj_id'     => $msg_id,
516
+			),
517
+		);
518
+	}
519
+
520
+
521
+	protected function _set_page_config()
522
+	{
523
+		$this->_page_config = array(
524
+			'default'                  => array(
525
+				'nav'           => array(
526
+					'label' => esc_html__('Message Activity', 'event_espresso'),
527
+					'order' => 10,
528
+				),
529
+				'list_table'    => 'EE_Message_List_Table',
530
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
531
+				'require_nonce' => false,
532
+			),
533
+			'global_mtps'              => array(
534
+				'nav'           => array(
535
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
536
+					'order' => 20,
537
+				),
538
+				'list_table'    => 'Messages_Template_List_Table',
539
+				'help_tabs'     => array(
540
+					'messages_overview_help_tab'                                => array(
541
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
542
+						'filename' => 'messages_overview',
543
+					),
544
+					'messages_overview_messages_table_column_headings_help_tab' => array(
545
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
546
+						'filename' => 'messages_overview_table_column_headings',
547
+					),
548
+					'messages_overview_messages_filters_help_tab'               => array(
549
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
550
+						'filename' => 'messages_overview_filters',
551
+					),
552
+					'messages_overview_messages_views_help_tab'                 => array(
553
+						'title'    => esc_html__('Message Views', 'event_espresso'),
554
+						'filename' => 'messages_overview_views',
555
+					),
556
+					'message_overview_message_types_help_tab'                   => array(
557
+						'title'    => esc_html__('Message Types', 'event_espresso'),
558
+						'filename' => 'messages_overview_types',
559
+					),
560
+					'messages_overview_messengers_help_tab'                     => array(
561
+						'title'    => esc_html__('Messengers', 'event_espresso'),
562
+						'filename' => 'messages_overview_messengers',
563
+					),
564
+				),
565
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
566
+				// 'help_tour'     => array('Messages_Overview_Help_Tour'),
567
+				'require_nonce' => false,
568
+			),
569
+			'custom_mtps'              => array(
570
+				'nav'           => array(
571
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
572
+					'order' => 30,
573
+				),
574
+				'help_tabs'     => array(),
575
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
576
+				// 'help_tour'     => array(),
577
+				'require_nonce' => false,
578
+			),
579
+			'add_new_message_template' => array(
580
+				'nav'           => array(
581
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
582
+					'order'      => 5,
583
+					'persistent' => false,
584
+				),
585
+				'require_nonce' => false,
586
+			),
587
+			'edit_message_template'    => array(
588
+				'labels'        => array(
589
+					'buttons'    => array(
590
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
591
+					),
592
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
593
+				),
594
+				'nav'           => array(
595
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
596
+					'order'      => 5,
597
+					'persistent' => false,
598
+					'url'        => '',
599
+				),
600
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
601
+				'has_metaboxes' => true,
602
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
603
+				// 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
604
+				'help_tabs'     => array(
605
+					'edit_message_template'            => array(
606
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
607
+						'callback' => 'edit_message_template_help_tab',
608
+					),
609
+					'message_templates_help_tab'       => array(
610
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
611
+						'filename' => 'messages_templates',
612
+					),
613
+					'message_template_shortcodes'      => array(
614
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
615
+						'callback' => 'message_template_shortcodes_help_tab',
616
+					),
617
+					'message_preview_help_tab'         => array(
618
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
619
+						'filename' => 'messages_preview',
620
+					),
621
+					'messages_overview_other_help_tab' => array(
622
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
623
+						'filename' => 'messages_overview_other',
624
+					),
625
+				),
626
+				'require_nonce' => false,
627
+			),
628
+			'display_preview_message'  => array(
629
+				'nav'           => array(
630
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
631
+					'order'      => 5,
632
+					'url'        => '',
633
+					'persistent' => false,
634
+				),
635
+				'help_tabs'     => array(
636
+					'preview_message' => array(
637
+						'title'    => esc_html__('About Previews', 'event_espresso'),
638
+						'callback' => 'preview_message_help_tab',
639
+					),
640
+				),
641
+				'require_nonce' => false,
642
+			),
643
+			'settings'                 => array(
644
+				'nav'           => array(
645
+					'label' => esc_html__('Settings', 'event_espresso'),
646
+					'order' => 40,
647
+				),
648
+				'metaboxes'     => array('_messages_settings_metaboxes'),
649
+				'help_tabs'     => array(
650
+					'messages_settings_help_tab'               => array(
651
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
652
+						'filename' => 'messages_settings',
653
+					),
654
+					'messages_settings_message_types_help_tab' => array(
655
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
656
+						'filename' => 'messages_settings_message_types',
657
+					),
658
+					'messages_settings_messengers_help_tab'    => array(
659
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
660
+						'filename' => 'messages_settings_messengers',
661
+					),
662
+				),
663
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
664
+				// 'help_tour'     => array('Messages_Settings_Help_Tour'),
665
+				'require_nonce' => false,
666
+			),
667
+		);
668
+	}
669
+
670
+
671
+	protected function _add_screen_options()
672
+	{
673
+		// todo
674
+	}
675
+
676
+
677
+	protected function _add_screen_options_global_mtps()
678
+	{
679
+		/**
680
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
681
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
682
+		 */
683
+		$page_title = $this->_admin_page_title;
684
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
685
+		$this->_per_page_screen_option();
686
+		$this->_admin_page_title = $page_title;
687
+	}
688
+
689
+
690
+	protected function _add_screen_options_default()
691
+	{
692
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
693
+		$this->_per_page_screen_option();
694
+	}
695
+
696
+
697
+	// none of the below group are currently used for Messages
698
+	protected function _add_feature_pointers()
699
+	{
700
+	}
701
+
702
+	public function admin_init()
703
+	{
704
+	}
705
+
706
+	public function admin_notices()
707
+	{
708
+	}
709
+
710
+	public function admin_footer_scripts()
711
+	{
712
+	}
713
+
714
+
715
+	public function messages_help_tab()
716
+	{
717
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
718
+	}
719
+
720
+
721
+	public function messengers_help_tab()
722
+	{
723
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
724
+	}
725
+
726
+
727
+	public function message_types_help_tab()
728
+	{
729
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
730
+	}
731
+
732
+
733
+	public function messages_overview_help_tab()
734
+	{
735
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
736
+	}
737
+
738
+
739
+	public function message_templates_help_tab()
740
+	{
741
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
742
+	}
743
+
744
+
745
+	public function edit_message_template_help_tab()
746
+	{
747
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
748
+						. esc_attr__('Editor Title', 'event_espresso')
749
+						. '" />';
750
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
751
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
752
+						. '" />';
753
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
754
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
755
+						. '" />';
756
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
757
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
758
+						. '" />';
759
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
760
+						. esc_attr__('Publish Metabox', 'event_espresso')
761
+						. '" />';
762
+		EEH_Template::display_template(
763
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
764
+			$args
765
+		);
766
+	}
767
+
768
+
769
+	public function message_template_shortcodes_help_tab()
770
+	{
771
+		$this->_set_shortcodes();
772
+		$args['shortcodes'] = $this->_shortcodes;
773
+		EEH_Template::display_template(
774
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
775
+			$args
776
+		);
777
+	}
778
+
779
+
780
+	public function preview_message_help_tab()
781
+	{
782
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
783
+	}
784
+
785
+
786
+	public function settings_help_tab()
787
+	{
788
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
789
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
790
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
791
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
792
+		$args['img3'] = '<div class="switch">'
793
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
794
+						. ' type="checkbox" checked="checked">'
795
+						. '<label for="ee-on-off-toggle-on"></label>'
796
+						. '</div>';
797
+		$args['img4'] = '<div class="switch">'
798
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
799
+						. ' type="checkbox">'
800
+						. '<label for="ee-on-off-toggle-on"></label>'
801
+						. '</div>';
802
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
803
+	}
804
+
805
+
806
+	public function load_scripts_styles()
807
+	{
808
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
809
+		wp_enqueue_style('espresso_ee_msg');
810
+
811
+		wp_register_script(
812
+			'ee-messages-settings',
813
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
814
+			array('jquery-ui-droppable', 'ee-serialize-full-array'),
815
+			EVENT_ESPRESSO_VERSION,
816
+			true
817
+		);
818
+		wp_register_script(
819
+			'ee-msg-list-table-js',
820
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
821
+			array('ee-dialog'),
822
+			EVENT_ESPRESSO_VERSION
823
+		);
824
+	}
825
+
826
+
827
+	public function load_scripts_styles_default()
828
+	{
829
+		wp_enqueue_script('ee-msg-list-table-js');
830
+	}
831
+
832
+
833
+	public function wp_editor_css($mce_css)
834
+	{
835
+		// if we're on the edit_message_template route
836
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
837
+			$message_type_name = $this->_active_message_type_name;
838
+
839
+			// we're going to REPLACE the existing mce css
840
+			// we need to get the css file location from the active messenger
841
+			$mce_css = $this->_active_messenger->get_variation(
842
+				$this->_template_pack,
843
+				$message_type_name,
844
+				true,
845
+				'wpeditor',
846
+				$this->_variation
847
+			);
848
+		}
849
+
850
+		return $mce_css;
851
+	}
852
+
853
+
854
+	public function load_scripts_styles_edit_message_template()
855
+	{
856
+
857
+		$this->_set_shortcodes();
858
+
859
+		EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
860
+			esc_html__(
861
+				'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.',
862
+				'event_espresso'
863
+			),
864
+			$this->_message_template_group->messenger_obj()->label['singular'],
865
+			$this->_message_template_group->message_type_obj()->label['singular']
866
+		);
867
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
868
+			'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?',
869
+			'event_espresso'
870
+		);
871
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
872
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
873
+			'event_espresso'
874
+		);
875
+
876
+		wp_register_script(
877
+			'ee_msgs_edit_js',
878
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
879
+			array('jquery'),
880
+			EVENT_ESPRESSO_VERSION
881
+		);
882
+
883
+		wp_enqueue_script('ee_admin_js');
884
+		wp_enqueue_script('ee_msgs_edit_js');
885
+
886
+		// add in special css for tiny_mce
887
+		add_filter('mce_css', array($this, 'wp_editor_css'));
888
+	}
889
+
890
+
891
+	public function load_scripts_styles_display_preview_message()
892
+	{
893
+
894
+		$this->_set_message_template_group();
895
+
896
+		if (isset($this->_req_data['messenger'])) {
897
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
898
+				$this->_req_data['messenger']
899
+			);
900
+		}
901
+
902
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
903
+
904
+
905
+		wp_enqueue_style(
906
+			'espresso_preview_css',
907
+			$this->_active_messenger->get_variation(
908
+				$this->_template_pack,
909
+				$message_type_name,
910
+				true,
911
+				'preview',
912
+				$this->_variation
913
+			)
914
+		);
915
+	}
916
+
917
+
918
+	public function load_scripts_styles_settings()
919
+	{
920
+		wp_register_style(
921
+			'ee-message-settings',
922
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
923
+			array(),
924
+			EVENT_ESPRESSO_VERSION
925
+		);
926
+		wp_enqueue_style('ee-text-links');
927
+		wp_enqueue_style('ee-message-settings');
928
+		wp_enqueue_script('ee-messages-settings');
929
+	}
930
+
931
+
932
+	/**
933
+	 * set views array for List Table
934
+	 */
935
+	public function _set_list_table_views_global_mtps()
936
+	{
937
+		$this->_views = array(
938
+			'in_use' => array(
939
+				'slug'  => 'in_use',
940
+				'label' => esc_html__('In Use', 'event_espresso'),
941
+				'count' => 0,
942
+			),
943
+		);
944
+	}
945
+
946
+
947
+	/**
948
+	 * Set views array for the Custom Template List Table
949
+	 */
950
+	public function _set_list_table_views_custom_mtps()
951
+	{
952
+		$this->_set_list_table_views_global_mtps();
953
+		$this->_views['in_use']['bulk_action'] = array(
954
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
955
+		);
956
+	}
957
+
958
+
959
+	/**
960
+	 * set views array for message queue list table
961
+	 *
962
+	 * @throws InvalidDataTypeException
963
+	 * @throws InvalidInterfaceException
964
+	 * @throws InvalidArgumentException
965
+	 * @throws EE_Error
966
+	 * @throws ReflectionException
967
+	 */
968
+	public function _set_list_table_views_default()
969
+	{
970
+		EE_Registry::instance()->load_helper('Template');
971
+
972
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
973
+			'ee_send_message',
974
+			'message_list_table_bulk_actions'
975
+		)
976
+			? array(
977
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
978
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
979
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
980
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
981
+			)
982
+			: array();
983
+
984
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
985
+			'ee_delete_messages',
986
+			'message_list_table_bulk_actions'
987
+		)
988
+			? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
989
+			: array();
990
+
991
+
992
+		$this->_views = array(
993
+			'all' => array(
994
+				'slug'        => 'all',
995
+				'label'       => esc_html__('All', 'event_espresso'),
996
+				'count'       => 0,
997
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
998
+			),
999
+		);
1000
+
1001
+
1002
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
1003
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1004
+				continue;
1005
+			}
1006
+			$status_bulk_actions = $common_bulk_actions;
1007
+			// unset bulk actions not applying to status
1008
+			if (! empty($status_bulk_actions)) {
1009
+				switch ($status) {
1010
+					case EEM_Message::status_idle:
1011
+					case EEM_Message::status_resend:
1012
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1013
+						break;
1014
+
1015
+					case EEM_Message::status_failed:
1016
+					case EEM_Message::status_debug_only:
1017
+					case EEM_Message::status_messenger_executing:
1018
+						$status_bulk_actions = array();
1019
+						break;
1020
+
1021
+					case EEM_Message::status_incomplete:
1022
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1023
+						break;
1024
+
1025
+					case EEM_Message::status_retry:
1026
+					case EEM_Message::status_sent:
1027
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1028
+						break;
1029
+				}
1030
+			}
1031
+
1032
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1033
+			if ($status === EEM_Message::status_messenger_executing) {
1034
+				continue;
1035
+			}
1036
+
1037
+			$this->_views[ strtolower($status) ] = array(
1038
+				'slug'        => strtolower($status),
1039
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1040
+				'count'       => 0,
1041
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1042
+			);
1043
+		}
1044
+	}
1045
+
1046
+
1047
+	protected function _ee_default_messages_overview_list_table()
1048
+	{
1049
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1050
+		$this->display_admin_list_table_page_with_no_sidebar();
1051
+	}
1052
+
1053
+
1054
+	protected function _message_queue_list_table()
1055
+	{
1056
+		$this->_search_btn_label = esc_html__('Message Activity', 'event_espresso');
1057
+		$this->_template_args['per_column'] = 6;
1058
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());
1059
+		$this->_template_args['before_list_table'] = '<h3>'
1060
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1061
+													 . '</h3>';
1062
+		$this->display_admin_list_table_page_with_no_sidebar();
1063
+	}
1064
+
1065
+
1066
+	protected function _message_legend_items()
1067
+	{
1068
+
1069
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1070
+		$action_items = array();
1071
+
1072
+		foreach ($action_css_classes as $action_item => $action_details) {
1073
+			if ($action_item === 'see_notifications_for') {
1074
+				continue;
1075
+			}
1076
+			$action_items[ $action_item ] = array(
1077
+				'class' => $action_details['css_class'],
1078
+				'desc'  => $action_details['label'],
1079
+			);
1080
+		}
1081
+
1082
+		/** @type array $status_items status legend setup */
1083
+		$status_items = array(
1084
+			'sent_status'                => array(
1085
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1086
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1087
+			),
1088
+			'idle_status'                => array(
1089
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1090
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1091
+			),
1092
+			'failed_status'              => array(
1093
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1094
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1095
+			),
1096
+			'messenger_executing_status' => array(
1097
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1098
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1099
+			),
1100
+			'resend_status'              => array(
1101
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1102
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1103
+			),
1104
+			'incomplete_status'          => array(
1105
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1106
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1107
+			),
1108
+			'retry_status'               => array(
1109
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1110
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1111
+			),
1112
+		);
1113
+		if (EEM_Message::debug()) {
1114
+			$status_items['debug_only_status'] = array(
1115
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1116
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1117
+			);
1118
+		}
1119
+
1120
+		return array_merge($action_items, $status_items);
1121
+	}
1122
+
1123
+
1124
+	protected function _custom_mtps_preview()
1125
+	{
1126
+		$this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1127
+		$this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1128
+											   . ' alt="' . esc_attr__(
1129
+												   'Preview Custom Message Templates screenshot',
1130
+												   'event_espresso'
1131
+											   ) . '" />';
1132
+		$this->_template_args['preview_text'] = '<strong>'
1133
+												. esc_html__(
1134
+													'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.',
1135
+													'event_espresso'
1136
+												)
1137
+												. '</strong>';
1138
+
1139
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1140
+	}
1141
+
1142
+
1143
+	/**
1144
+	 * get_message_templates
1145
+	 * This gets all the message templates for listing on the overview list.
1146
+	 *
1147
+	 * @access public
1148
+	 * @param int    $perpage the amount of templates groups to show per page
1149
+	 * @param string $type    the current _view we're getting templates for
1150
+	 * @param bool   $count   return count?
1151
+	 * @param bool   $all     disregard any paging info (get all data);
1152
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1153
+	 * @return array
1154
+	 * @throws EE_Error
1155
+	 * @throws InvalidArgumentException
1156
+	 * @throws InvalidDataTypeException
1157
+	 * @throws InvalidInterfaceException
1158
+	 */
1159
+	public function get_message_templates(
1160
+		$perpage = 10,
1161
+		$type = 'in_use',
1162
+		$count = false,
1163
+		$all = false,
1164
+		$global = true
1165
+	) {
1166
+
1167
+		$MTP = EEM_Message_Template_Group::instance();
1168
+
1169
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1170
+		$orderby = $this->_req_data['orderby'];
1171
+
1172
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1173
+			? $this->_req_data['order']
1174
+			: 'ASC';
1175
+
1176
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1177
+			? $this->_req_data['paged']
1178
+			: 1;
1179
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1180
+			? $this->_req_data['perpage']
1181
+			: $perpage;
1182
+
1183
+		$offset = ($current_page - 1) * $per_page;
1184
+		$limit = $all ? null : array($offset, $per_page);
1185
+
1186
+
1187
+		// options will match what is in the _views array property
1188
+		switch ($type) {
1189
+			case 'in_use':
1190
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1191
+				break;
1192
+			default:
1193
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1194
+		}
1195
+
1196
+		return $templates;
1197
+	}
1198
+
1199
+
1200
+	/**
1201
+	 * filters etc might need a list of installed message_types
1202
+	 *
1203
+	 * @return array an array of message type objects
1204
+	 */
1205
+	public function get_installed_message_types()
1206
+	{
1207
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1208
+		$installed = array();
1209
+
1210
+		foreach ($installed_message_types as $message_type) {
1211
+			$installed[ $message_type->name ] = $message_type;
1212
+		}
1213
+
1214
+		return $installed;
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * _add_message_template
1220
+	 *
1221
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1222
+	 *
1223
+	 * @param string $message_type
1224
+	 * @param string $messenger
1225
+	 * @param string $GRP_ID
1226
+	 *
1227
+	 * @throws EE_error
1228
+	 */
1229
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1230
+	{
1231
+		// set values override any request data
1232
+		$message_type = ! empty($message_type) ? $message_type : $this->request->getRequestParam('message_type');
1233
+		$messenger = ! empty($messenger) ? $messenger : $this->request->getRequestParam('messenger');
1234
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1235
+
1236
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1237
+		if (empty($message_type) || empty($messenger)) {
1238
+			throw new EE_Error(
1239
+				esc_html__(
1240
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1241
+					'event_espresso'
1242
+				)
1243
+			);
1244
+		}
1245
+
1246
+		// we need the GRP_ID for the template being used as the base for the new template
1247
+		if (empty($GRP_ID)) {
1248
+			throw new EE_Error(
1249
+				esc_html__(
1250
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1251
+					'event_espresso'
1252
+				)
1253
+			);
1254
+		}
1255
+
1256
+		// let's just make sure the template gets generated!
1257
+
1258
+		// we need to reassign some variables for what the insert is expecting
1259
+		$this->_req_data['MTP_messenger'] = $messenger;
1260
+		$this->_req_data['MTP_message_type'] = $message_type;
1261
+		$this->_req_data['GRP_ID'] = $GRP_ID;
1262
+		$this->_insert_or_update_message_template(true);
1263
+	}
1264
+
1265
+
1266
+	/**
1267
+	 * public wrapper for the _add_message_template method
1268
+	 *
1269
+	 * @param string $message_type     message type slug
1270
+	 * @param string $messenger        messenger slug
1271
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1272
+	 *                                 off of.
1273
+	 * @throws EE_error
1274
+	 */
1275
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1276
+	{
1277
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1278
+	}
1279
+
1280
+
1281
+	/**
1282
+	 * _edit_message_template
1283
+	 *
1284
+	 * @access protected
1285
+	 * @return void
1286
+	 * @throws InvalidIdentifierException
1287
+	 * @throws DomainException
1288
+	 * @throws EE_Error
1289
+	 * @throws InvalidArgumentException
1290
+	 * @throws ReflectionException
1291
+	 * @throws InvalidDataTypeException
1292
+	 * @throws InvalidInterfaceException
1293
+	 */
1294
+	protected function _edit_message_template()
1295
+	{
1296
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1297
+		$template_fields = '';
1298
+		$sidebar_fields = '';
1299
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1300
+		// valid html in the templates.
1301
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1302
+
1303
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1304
+			? absint($this->_req_data['id'])
1305
+			: false;
1306
+
1307
+		$EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
1308
+		? absint($this->_req_data['evt_id'])
1309
+		: false;
1310
+
1311
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1312
+		$message_template_group = $this->_message_template_group;
1313
+		$c_label = $message_template_group->context_label();
1314
+		$c_config = $message_template_group->contexts_config();
1315
+
1316
+		reset($c_config);
1317
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1318
+			? strtolower($this->_req_data['context'])
1319
+			: key($c_config);
1320
+
1321
+
1322
+		if (empty($GRP_ID)) {
1323
+			$action = 'insert_message_template';
1324
+			$edit_message_template_form_url = add_query_arg(
1325
+				array('action' => $action, 'noheader' => true),
1326
+				EE_MSG_ADMIN_URL
1327
+			);
1328
+		} else {
1329
+			$action = 'update_message_template';
1330
+			$edit_message_template_form_url = add_query_arg(
1331
+				array('action' => $action, 'noheader' => true),
1332
+				EE_MSG_ADMIN_URL
1333
+			);
1334
+		}
1335
+
1336
+		// set active messenger for this view
1337
+		$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
1338
+			$message_template_group->messenger()
1339
+		);
1340
+		$this->_active_message_type_name = $message_template_group->message_type();
1341
+
1342
+
1343
+		// Do we have any validation errors?
1344
+		$validators = $this->_get_transient();
1345
+		$v_fields = ! empty($validators) ? array_keys($validators) : array();
1346
+
1347
+
1348
+		// we need to assemble the title from Various details
1349
+		$context_label = sprintf(
1350
+			esc_html__('(%s %s)', 'event_espresso'),
1351
+			$c_config[ $context ]['label'],
1352
+			ucwords($c_label['label'])
1353
+		);
1354
+
1355
+		$title = sprintf(
1356
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1357
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1358
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1359
+			$context_label
1360
+		);
1361
+
1362
+		$this->_template_args['GRP_ID'] = $GRP_ID;
1363
+		$this->_template_args['message_template'] = $message_template_group;
1364
+		$this->_template_args['is_extra_fields'] = false;
1365
+
1366
+
1367
+		// let's get EEH_MSG_Template so we can get template form fields
1368
+		$template_field_structure = EEH_MSG_Template::get_fields(
1369
+			$message_template_group->messenger(),
1370
+			$message_template_group->message_type()
1371
+		);
1372
+
1373
+		if (! $template_field_structure) {
1374
+			$template_field_structure = false;
1375
+			$template_fields = esc_html__(
1376
+				'There was an error in assembling the fields for this display (you should see an error message)',
1377
+				'event_espresso'
1378
+			);
1379
+		}
1380
+
1381
+
1382
+		$message_templates = $message_template_group->context_templates();
1383
+
1384
+
1385
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1386
+		// will get handled in the "extra" array.
1387
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1388
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1389
+				unset($template_field_structure[ $context ][ $reference_field ]);
1390
+			}
1391
+		}
1392
+
1393
+		// let's loop through the template_field_structure and actually assemble the input fields!
1394
+		if (! empty($template_field_structure)) {
1395
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1396
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1397
+				// the extra array and reset them.
1398
+				if ($template_field === 'extra') {
1399
+					$this->_template_args['is_extra_fields'] = true;
1400
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1401
+						$message_template = $message_templates[ $context ][ $reference_field ];
1402
+						$content = $message_template instanceof EE_Message_Template
1403
+							? $message_template->get('MTP_content')
1404
+							: '';
1405
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1406
+							// let's verify if we need this extra field via the shortcodes parameter.
1407
+							$continue = false;
1408
+							if (isset($extra_array['shortcodes_required'])) {
1409
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1410
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1411
+										$continue = true;
1412
+									}
1413
+								}
1414
+								if ($continue) {
1415
+									continue;
1416
+								}
1417
+							}
1418
+
1419
+							$field_id = $reference_field
1420
+										. '-'
1421
+										. $extra_field
1422
+										. '-content';
1423
+							$template_form_fields[ $field_id ] = $extra_array;
1424
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1425
+																		 . $reference_field
1426
+																		 . '][content]['
1427
+																		 . $extra_field . ']';
1428
+							$css_class = isset($extra_array['css_class'])
1429
+								? $extra_array['css_class']
1430
+								: '';
1431
+
1432
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1433
+																			  && in_array($extra_field, $v_fields, true)
1434
+																			  &&
1435
+																			  (
1436
+																				  is_array($validators[ $extra_field ])
1437
+																				  && isset($validators[ $extra_field ]['msg'])
1438
+																			  )
1439
+								? 'validate-error ' . $css_class
1440
+								: $css_class;
1441
+
1442
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1443
+																		  && isset($content[ $extra_field ])
1444
+								? $content[ $extra_field ]
1445
+								: '';
1446
+
1447
+							// do we have a validation error?  if we do then let's use that value instead
1448
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1449
+								? $validators[ $extra_field ]['value']
1450
+								: $template_form_fields[ $field_id ]['value'];
1451
+
1452
+
1453
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1454
+
1455
+							// shortcode selector
1456
+							$field_name_to_use = $extra_field === 'main'
1457
+								? 'content'
1458
+								: $extra_field;
1459
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1460
+								$field_name_to_use,
1461
+								$field_id
1462
+							);
1463
+
1464
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1465
+								// we want to decode the entities
1466
+								$template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value'];
1467
+							}/**/
1468
+						}
1469
+						$templatefield_MTP_id = $reference_field . '-MTP_ID';
1470
+						$templatefield_templatename_id = $reference_field . '-name';
1471
+
1472
+						$template_form_fields[ $templatefield_MTP_id ] = array(
1473
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1474
+							'label'      => null,
1475
+							'input'      => 'hidden',
1476
+							'type'       => 'int',
1477
+							'required'   => false,
1478
+							'validation' => false,
1479
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1480
+							'css_class'  => '',
1481
+							'format'     => '%d',
1482
+							'db-col'     => 'MTP_ID',
1483
+						);
1484
+
1485
+						$template_form_fields[ $templatefield_templatename_id ] = array(
1486
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1487
+							'label'      => null,
1488
+							'input'      => 'hidden',
1489
+							'type'       => 'string',
1490
+							'required'   => false,
1491
+							'validation' => true,
1492
+							'value'      => $reference_field,
1493
+							'css_class'  => '',
1494
+							'format'     => '%s',
1495
+							'db-col'     => 'MTP_template_field',
1496
+						);
1497
+					}
1498
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1499
+				} else {
1500
+					$field_id = $template_field . '-content';
1501
+					$template_form_fields[ $field_id ] = $field_setup_array;
1502
+					$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]';
1503
+					$message_template = isset($message_templates[ $context ][ $template_field ])
1504
+						? $message_templates[ $context ][ $template_field ]
1505
+						: null;
1506
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1507
+																  && is_array($message_templates[ $context ])
1508
+																  && $message_template instanceof EE_Message_Template
1509
+						? $message_template->get('MTP_content')
1510
+						: '';
1511
+
1512
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1513
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1514
+						? $validators[ $template_field ]['value']
1515
+						: $template_form_fields[ $field_id ]['value'];
1516
+
1517
+
1518
+					$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1519
+					$css_class = isset($field_setup_array['css_class'])
1520
+						? $field_setup_array['css_class']
1521
+						: '';
1522
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1523
+																	  && in_array($template_field, $v_fields, true)
1524
+																	  && isset($validators[ $template_field ]['msg'])
1525
+						? 'validate-error ' . $css_class
1526
+						: $css_class;
1527
+
1528
+					// shortcode selector
1529
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1530
+						$template_field,
1531
+						$field_id
1532
+					);
1533
+				}
1534
+
1535
+				// k took care of content field(s) now let's take care of others.
1536
+
1537
+				$templatefield_MTP_id = $template_field . '-MTP_ID';
1538
+				$templatefield_field_templatename_id = $template_field . '-name';
1539
+
1540
+				// foreach template field there are actually two form fields created
1541
+				$template_form_fields[ $templatefield_MTP_id ] = array(
1542
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1543
+					'label'      => null,
1544
+					'input'      => 'hidden',
1545
+					'type'       => 'int',
1546
+					'required'   => false,
1547
+					'validation' => true,
1548
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1549
+					'css_class'  => '',
1550
+					'format'     => '%d',
1551
+					'db-col'     => 'MTP_ID',
1552
+				);
1553
+
1554
+				$template_form_fields[ $templatefield_field_templatename_id ] = array(
1555
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1556
+					'label'      => null,
1557
+					'input'      => 'hidden',
1558
+					'type'       => 'string',
1559
+					'required'   => false,
1560
+					'validation' => true,
1561
+					'value'      => $template_field,
1562
+					'css_class'  => '',
1563
+					'format'     => '%s',
1564
+					'db-col'     => 'MTP_template_field',
1565
+				);
1566
+			}
1567
+
1568
+			// add other fields
1569
+			$template_form_fields['ee-msg-current-context'] = array(
1570
+				'name'       => 'MTP_context',
1571
+				'label'      => null,
1572
+				'input'      => 'hidden',
1573
+				'type'       => 'string',
1574
+				'required'   => false,
1575
+				'validation' => true,
1576
+				'value'      => $context,
1577
+				'css_class'  => '',
1578
+				'format'     => '%s',
1579
+				'db-col'     => 'MTP_context',
1580
+			);
1581
+
1582
+			$template_form_fields['ee-msg-grp-id'] = array(
1583
+				'name'       => 'GRP_ID',
1584
+				'label'      => null,
1585
+				'input'      => 'hidden',
1586
+				'type'       => 'int',
1587
+				'required'   => false,
1588
+				'validation' => true,
1589
+				'value'      => $GRP_ID,
1590
+				'css_class'  => '',
1591
+				'format'     => '%d',
1592
+				'db-col'     => 'GRP_ID',
1593
+			);
1594
+
1595
+			$template_form_fields['ee-msg-messenger'] = array(
1596
+				'name'       => 'MTP_messenger',
1597
+				'label'      => null,
1598
+				'input'      => 'hidden',
1599
+				'type'       => 'string',
1600
+				'required'   => false,
1601
+				'validation' => true,
1602
+				'value'      => $message_template_group->messenger(),
1603
+				'css_class'  => '',
1604
+				'format'     => '%s',
1605
+				'db-col'     => 'MTP_messenger',
1606
+			);
1607
+
1608
+			$template_form_fields['ee-msg-message-type'] = array(
1609
+				'name'       => 'MTP_message_type',
1610
+				'label'      => null,
1611
+				'input'      => 'hidden',
1612
+				'type'       => 'string',
1613
+				'required'   => false,
1614
+				'validation' => true,
1615
+				'value'      => $message_template_group->message_type(),
1616
+				'css_class'  => '',
1617
+				'format'     => '%s',
1618
+				'db-col'     => 'MTP_message_type',
1619
+			);
1620
+
1621
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1622
+				'name'       => 'MTP_is_global',
1623
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1624
+				'input'      => 'hidden',
1625
+				'type'       => 'int',
1626
+				'required'   => false,
1627
+				'validation' => true,
1628
+				'value'      => $message_template_group->get('MTP_is_global'),
1629
+				'css_class'  => '',
1630
+				'format'     => '%d',
1631
+				'db-col'     => 'MTP_is_global',
1632
+			);
1633
+
1634
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1635
+				'name'       => 'MTP_is_override',
1636
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1637
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1638
+				'type'       => 'int',
1639
+				'required'   => false,
1640
+				'validation' => true,
1641
+				'value'      => $message_template_group->get('MTP_is_override'),
1642
+				'css_class'  => '',
1643
+				'format'     => '%d',
1644
+				'db-col'     => 'MTP_is_override',
1645
+			);
1646
+
1647
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1648
+				'name'       => 'MTP_is_active',
1649
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1650
+				'input'      => 'hidden',
1651
+				'type'       => 'int',
1652
+				'required'   => false,
1653
+				'validation' => true,
1654
+				'value'      => $message_template_group->is_active(),
1655
+				'css_class'  => '',
1656
+				'format'     => '%d',
1657
+				'db-col'     => 'MTP_is_active',
1658
+			);
1659
+
1660
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1661
+				'name'       => 'MTP_deleted',
1662
+				'label'      => null,
1663
+				'input'      => 'hidden',
1664
+				'type'       => 'int',
1665
+				'required'   => false,
1666
+				'validation' => true,
1667
+				'value'      => $message_template_group->get('MTP_deleted'),
1668
+				'css_class'  => '',
1669
+				'format'     => '%d',
1670
+				'db-col'     => 'MTP_deleted',
1671
+			);
1672
+			$sidebar_form_fields['ee-msg-author'] = array(
1673
+				'name'       => 'MTP_user_id',
1674
+				'label'      => esc_html__('Author', 'event_espresso'),
1675
+				'input'      => 'hidden',
1676
+				'type'       => 'int',
1677
+				'required'   => false,
1678
+				'validation' => false,
1679
+				'value'      => $message_template_group->user(),
1680
+				'format'     => '%d',
1681
+				'db-col'     => 'MTP_user_id',
1682
+			);
1683
+
1684
+			$sidebar_form_fields['ee-msg-route'] = array(
1685
+				'name'  => 'action',
1686
+				'input' => 'hidden',
1687
+				'type'  => 'string',
1688
+				'value' => $action,
1689
+			);
1690
+
1691
+			$sidebar_form_fields['ee-msg-id'] = array(
1692
+				'name'  => 'id',
1693
+				'input' => 'hidden',
1694
+				'type'  => 'int',
1695
+				'value' => $GRP_ID,
1696
+			);
1697
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1698
+				'name'  => $action . '_nonce',
1699
+				'input' => 'hidden',
1700
+				'type'  => 'string',
1701
+				'value' => wp_create_nonce($action . '_nonce'),
1702
+			);
1703
+
1704
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1705
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1706
+					'name'  => 'template_switch',
1707
+					'input' => 'hidden',
1708
+					'type'  => 'int',
1709
+					'value' => 1,
1710
+				);
1711
+			}
1712
+
1713
+
1714
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1715
+			$sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);
1716
+		} //end if ( !empty($template_field_structure) )
1717
+
1718
+		// set extra content for publish box
1719
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1720
+		$this->_set_publish_post_box_vars(
1721
+			'id',
1722
+			$GRP_ID,
1723
+			false,
1724
+			add_query_arg(
1725
+				array('action' => 'global_mtps'),
1726
+				$this->_admin_base_url
1727
+			)
1728
+		);
1729
+
1730
+		// add preview button
1731
+		$preview_url = parent::add_query_args_and_nonce(
1732
+			array(
1733
+				'message_type' => $message_template_group->message_type(),
1734
+				'messenger'    => $message_template_group->messenger(),
1735
+				'context'      => $context,
1736
+				'GRP_ID'       => $GRP_ID,
1737
+				'evt_id'       => $EVT_ID,
1738
+				'action'       => 'preview_message',
1739
+			),
1740
+			$this->_admin_base_url
1741
+		);
1742
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1743
+						  . esc_html__('Preview', 'event_espresso')
1744
+						  . '</a>';
1745
+
1746
+
1747
+		// setup context switcher
1748
+		$context_switcher_args = array(
1749
+			'page'    => 'espresso_messages',
1750
+			'action'  => 'edit_message_template',
1751
+			'id'      => $GRP_ID,
1752
+			'evt_id'  => $EVT_ID,
1753
+			'context' => $context,
1754
+			'extra'   => $preview_button,
1755
+		);
1756
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1757
+
1758
+
1759
+		// main box
1760
+		$this->_template_args['template_fields'] = $template_fields;
1761
+		$this->_template_args['sidebar_box_id'] = 'details';
1762
+		$this->_template_args['action'] = $action;
1763
+		$this->_template_args['context'] = $context;
1764
+		$this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;
1765
+		$this->_template_args['learn_more_about_message_templates_link'] =
1766
+			$this->_learn_more_about_message_templates_link();
1767
+
1768
+
1769
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1770
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1771
+			$message_template_group,
1772
+			$context,
1773
+			$context_label
1774
+		);
1775
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1776
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1777
+
1778
+		$this->_template_path = $this->_template_args['GRP_ID']
1779
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1780
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1781
+
1782
+		// send along EE_Message_Template_Group object for further template use.
1783
+		$this->_template_args['MTP'] = $message_template_group;
1784
+
1785
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1786
+			$this->_template_path,
1787
+			$this->_template_args,
1788
+			true
1789
+		);
1790
+
1791
+
1792
+		// finally, let's set the admin_page title
1793
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1794
+
1795
+
1796
+		// we need to take care of setting the shortcodes property for use elsewhere.
1797
+		$this->_set_shortcodes();
1798
+
1799
+
1800
+		// final template wrapper
1801
+		$this->display_admin_page_with_sidebar();
1802
+	}
1803
+
1804
+
1805
+	public function filter_tinymce_init($mceInit, $editor_id)
1806
+	{
1807
+		return $mceInit;
1808
+	}
1809
+
1810
+
1811
+	public function add_context_switcher()
1812
+	{
1813
+		return $this->_context_switcher;
1814
+	}
1815
+
1816
+
1817
+	/**
1818
+	 * Adds the activation/deactivation toggle for the message template context.
1819
+	 *
1820
+	 * @param EE_Message_Template_Group $message_template_group
1821
+	 * @param string                    $context
1822
+	 * @param string                    $context_label
1823
+	 * @return string
1824
+	 * @throws DomainException
1825
+	 * @throws EE_Error
1826
+	 * @throws InvalidIdentifierException
1827
+	 */
1828
+	protected function add_active_context_element(
1829
+		EE_Message_Template_Group $message_template_group,
1830
+		$context,
1831
+		$context_label
1832
+	) {
1833
+		$template_args = array(
1834
+			'context'                   => $context,
1835
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1836
+			'is_active'                 => $message_template_group->is_context_active($context),
1837
+			'on_off_action'             => $message_template_group->is_context_active($context)
1838
+				? 'context-off'
1839
+				: 'context-on',
1840
+			'context_label'             => str_replace(array('(', ')'), '', $context_label),
1841
+			'message_template_group_id' => $message_template_group->ID(),
1842
+		);
1843
+		return EEH_Template::display_template(
1844
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1845
+			$template_args,
1846
+			true
1847
+		);
1848
+	}
1849
+
1850
+
1851
+	/**
1852
+	 * Ajax callback for `toggle_context_template` ajax action.
1853
+	 * Handles toggling the message context on or off.
1854
+	 *
1855
+	 * @throws EE_Error
1856
+	 * @throws InvalidArgumentException
1857
+	 * @throws InvalidDataTypeException
1858
+	 * @throws InvalidIdentifierException
1859
+	 * @throws InvalidInterfaceException
1860
+	 */
1861
+	public function toggle_context_template()
1862
+	{
1863
+		$success = true;
1864
+		// check for required data
1865
+		if (! isset(
1866
+			$this->_req_data['message_template_group_id'],
1867
+			$this->_req_data['context'],
1868
+			$this->_req_data['status']
1869
+		)) {
1870
+			EE_Error::add_error(
1871
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1872
+				__FILE__,
1873
+				__FUNCTION__,
1874
+				__LINE__
1875
+			);
1876
+			$success = false;
1877
+		}
1878
+
1879
+		$nonce = isset($this->_req_data['toggle_context_nonce'])
1880
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1881
+			: '';
1882
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1883
+		$this->_verify_nonce($nonce, $nonce_ref);
1884
+		$status = $this->_req_data['status'];
1885
+		if ($status !== 'off' && $status !== 'on') {
1886
+			EE_Error::add_error(
1887
+				sprintf(
1888
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1889
+					$this->_req_data['status']
1890
+				),
1891
+				__FILE__,
1892
+				__FUNCTION__,
1893
+				__LINE__
1894
+			);
1895
+			$success = false;
1896
+		}
1897
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1898
+			$this->_req_data['message_template_group_id']
1899
+		);
1900
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1901
+			EE_Error::add_error(
1902
+				sprintf(
1903
+					esc_html__(
1904
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1905
+						'event_espresso'
1906
+					),
1907
+					$this->_req_data['message_template_group_id'],
1908
+					'EE_Message_Template_Group'
1909
+				),
1910
+				__FILE__,
1911
+				__FUNCTION__,
1912
+				__LINE__
1913
+			);
1914
+			$success = false;
1915
+		}
1916
+		if ($success) {
1917
+			$success = $status === 'off'
1918
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1919
+				: $message_template_group->activate_context($this->_req_data['context']);
1920
+		}
1921
+		$this->_template_args['success'] = $success;
1922
+		$this->_return_json();
1923
+	}
1924
+
1925
+
1926
+	public function _add_form_element_before()
1927
+	{
1928
+		return '<form method="post" action="'
1929
+			   . $this->_template_args["edit_message_template_form_url"]
1930
+			   . '" id="ee-msg-edit-frm">';
1931
+	}
1932
+
1933
+	public function _add_form_element_after()
1934
+	{
1935
+		return '</form>';
1936
+	}
1937
+
1938
+
1939
+	/**
1940
+	 * This executes switching the template pack for a message template.
1941
+	 *
1942
+	 * @since 4.5.0
1943
+	 * @throws EE_Error
1944
+	 * @throws InvalidDataTypeException
1945
+	 * @throws InvalidInterfaceException
1946
+	 * @throws InvalidArgumentException
1947
+	 * @throws ReflectionException
1948
+	 */
1949
+	public function switch_template_pack()
1950
+	{
1951
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1952
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1953
+
1954
+		// verify we have needed values.
1955
+		if (empty($GRP_ID) || empty($template_pack)) {
1956
+			$this->_template_args['error'] = true;
1957
+			EE_Error::add_error(
1958
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1959
+				__FILE__,
1960
+				__FUNCTION__,
1961
+				__LINE__
1962
+			);
1963
+		} else {
1964
+			// get template, set the new template_pack and then reset to default
1965
+			/** @type EE_Message_Template_Group $message_template_group */
1966
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1967
+
1968
+			$message_template_group->set_template_pack_name($template_pack);
1969
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1970
+			$this->_req_data['mt'] = $message_template_group->message_type();
1971
+
1972
+			$query_args = $this->_reset_to_default_template();
1973
+
1974
+			if (empty($query_args['id'])) {
1975
+				EE_Error::add_error(
1976
+					esc_html__(
1977
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1978
+						'event_espresso'
1979
+					),
1980
+					__FILE__,
1981
+					__FUNCTION__,
1982
+					__LINE__
1983
+				);
1984
+				$this->_template_args['error'] = true;
1985
+			} else {
1986
+				$template_label = $message_template_group->get_template_pack()->label;
1987
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1988
+				EE_Error::add_success(
1989
+					sprintf(
1990
+						esc_html__(
1991
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1992
+							'event_espresso'
1993
+						),
1994
+						$template_label,
1995
+						$template_pack_labels->template_pack
1996
+					)
1997
+				);
1998
+				// generate the redirect url for js.
1999
+				$url = self::add_query_args_and_nonce(
2000
+					$query_args,
2001
+					$this->_admin_base_url
2002
+				);
2003
+				$this->_template_args['data']['redirect_url'] = $url;
2004
+				$this->_template_args['success'] = true;
2005
+			}
2006
+
2007
+			$this->_return_json();
2008
+		}
2009
+	}
2010
+
2011
+
2012
+	/**
2013
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2014
+	 * they want.
2015
+	 *
2016
+	 * @access protected
2017
+	 * @return array|null
2018
+	 * @throws EE_Error
2019
+	 * @throws InvalidArgumentException
2020
+	 * @throws InvalidDataTypeException
2021
+	 * @throws InvalidInterfaceException
2022
+	 */
2023
+	protected function _reset_to_default_template()
2024
+	{
2025
+
2026
+		$templates = array();
2027
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2028
+		// we need to make sure we've got the info we need.
2029
+		if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2030
+			EE_Error::add_error(
2031
+				esc_html__(
2032
+					'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.',
2033
+					'event_espresso'
2034
+				),
2035
+				__FILE__,
2036
+				__FUNCTION__,
2037
+				__LINE__
2038
+			);
2039
+		}
2040
+
2041
+		// all templates will be reset to whatever the defaults are
2042
+		// for the global template matching the messenger and message type.
2043
+		$success = ! empty($GRP_ID) ? true : false;
2044
+
2045
+		if ($success) {
2046
+			// let's first determine if the incoming template is a global template,
2047
+			// if it isn't then we need to get the global template matching messenger and message type.
2048
+			// $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2049
+
2050
+
2051
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2052
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2053
+
2054
+			if ($success) {
2055
+				// if successfully deleted, lets generate the new ones.
2056
+				// Note. We set GLOBAL to true, because resets on ANY template
2057
+				// will use the related global template defaults for regeneration.
2058
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2059
+				// HOWEVER, we DO keep the template pack and template variation set
2060
+				// for the current custom template when resetting.
2061
+				$templates = $this->_generate_new_templates(
2062
+					$this->_req_data['msgr'],
2063
+					$this->_req_data['mt'],
2064
+					$GRP_ID,
2065
+					true
2066
+				);
2067
+			}
2068
+		}
2069
+
2070
+		// any error messages?
2071
+		if (! $success) {
2072
+			EE_Error::add_error(
2073
+				esc_html__(
2074
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2075
+					'event_espresso'
2076
+				),
2077
+				__FILE__,
2078
+				__FUNCTION__,
2079
+				__LINE__
2080
+			);
2081
+		}
2082
+
2083
+		// all good, let's add a success message!
2084
+		if ($success && ! empty($templates)) {
2085
+			// the info for the template we generated is the first element in the returned array
2086
+			// $templates = $templates[0];
2087
+			EE_Error::overwrite_success();
2088
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2089
+		}
2090
+
2091
+
2092
+		$query_args = array(
2093
+			'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2094
+			'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2095
+			'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2096
+		);
2097
+
2098
+		// if called via ajax then we return query args otherwise redirect
2099
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2100
+			return $query_args;
2101
+		} else {
2102
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2103
+
2104
+			return null;
2105
+		}
2106
+	}
2107
+
2108
+
2109
+	/**
2110
+	 * Retrieve and set the message preview for display.
2111
+	 *
2112
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2113
+	 * @return string
2114
+	 * @throws ReflectionException
2115
+	 * @throws EE_Error
2116
+	 * @throws InvalidArgumentException
2117
+	 * @throws InvalidDataTypeException
2118
+	 * @throws InvalidInterfaceException
2119
+	 */
2120
+	public function _preview_message($send = false)
2121
+	{
2122
+		// first make sure we've got the necessary parameters
2123
+		if (
2124
+			! (
2125
+				$this->request->requestParamIsSet('message_type')
2126
+				&& $this->request->requestParamIsSet('messenger')
2127
+				&& $this->request->requestParamIsSet('GRP_ID')
2128
+			)
2129
+		) {
2130
+			EE_Error::add_error(
2131
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2132
+				__FILE__,
2133
+				__FUNCTION__,
2134
+				__LINE__
2135
+			);
2136
+		}
2137
+
2138
+		$context = $this->request->getRequestParam('context');
2139
+		$messenger = $this->request->getRequestParam('messenger');
2140
+		$message_type = $this->request->getRequestParam('message_type');
2141
+
2142
+		// get the preview!
2143
+		$preview = EED_Messages::preview_message($message_type, $context, $messenger, $send);
2144
+
2145
+		if ($send) {
2146
+			return $preview;
2147
+		}
2148
+
2149
+		// let's add a button to go back to the edit view
2150
+		$query_args = array(
2151
+			'id'      => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2152
+			'evt_id'  => $this->request->getRequestParam('evt_id', 0, 'int'),
2153
+			'context' => $context,
2154
+			'action'  => 'edit_message_template',
2155
+		);
2156
+		$go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2157
+		$preview_button = '<a href="'
2158
+						  . $go_back_url
2159
+						  . '" class="button-secondary messages-preview-go-back-button">'
2160
+						  . esc_html__('Go Back to Edit', 'event_espresso')
2161
+						  . '</a>';
2162
+		$message_types = $this->get_installed_message_types();
2163
+		$active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);
2164
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2165
+			? ucwords($active_messenger->label['singular'])
2166
+			: esc_html__('Unknown Messenger', 'event_espresso');
2167
+		// let's provide a helpful title for context
2168
+		$preview_title = sprintf(
2169
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2170
+			$active_messenger_label,
2171
+			ucwords($message_types[ $message_type ]->label['singular'])
2172
+		);
2173
+		if (empty($preview)) {
2174
+			$this->noEventsErrorMessage();
2175
+		}
2176
+		// setup display of preview.
2177
+		$this->_admin_page_title = $preview_title;
2178
+		$this->_template_args['admin_page_title'] = $preview_title;
2179
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2180
+		$this->_template_args['data']['force_json'] = true;
2181
+
2182
+		return '';
2183
+	}
2184
+
2185
+
2186
+	/**
2187
+	 * Used to set an error if there are no events available for generating a preview/test send.
2188
+	 *
2189
+	 * @param bool $test_send  Whether the error should be generated for the context of a test send.
2190
+	 */
2191
+	protected function noEventsErrorMessage($test_send = false)
2192
+	{
2193
+		$events_url = parent::add_query_args_and_nonce(
2194
+			array(
2195
+				'action' => 'default',
2196
+				'page'   => 'espresso_events',
2197
+			),
2198
+			admin_url('admin.php')
2199
+		);
2200
+		$message = $test_send
2201
+			? __(
2202
+				'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!',
2203
+				'event_espresso'
2204
+			)
2205
+			: __(
2206
+				'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!',
2207
+				'event_espresso'
2208
+			);
2209
+
2210
+		EE_Error::add_attention(
2211
+			sprintf(
2212
+				$message,
2213
+				"<a href='{$events_url}'>",
2214
+				'</a>'
2215
+			)
2216
+		);
2217
+	}
2218
+
2219
+
2220
+	/**
2221
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2222
+	 * gets called automatically.
2223
+	 *
2224
+	 * @since 4.5.0
2225
+	 *
2226
+	 * @return string
2227
+	 */
2228
+	protected function _display_preview_message()
2229
+	{
2230
+		$this->display_admin_page_with_no_sidebar();
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 * registers metaboxes that should show up on the "edit_message_template" page
2236
+	 *
2237
+	 * @access protected
2238
+	 * @return void
2239
+	 */
2240
+	protected function _register_edit_meta_boxes()
2241
+	{
2242
+		add_meta_box(
2243
+			'mtp_valid_shortcodes',
2244
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2245
+			array($this, 'shortcode_meta_box'),
2246
+			$this->_current_screen->id,
2247
+			'side',
2248
+			'default'
2249
+		);
2250
+		add_meta_box(
2251
+			'mtp_extra_actions',
2252
+			esc_html__('Extra Actions', 'event_espresso'),
2253
+			array($this, 'extra_actions_meta_box'),
2254
+			$this->_current_screen->id,
2255
+			'side',
2256
+			'high'
2257
+		);
2258
+		add_meta_box(
2259
+			'mtp_templates',
2260
+			esc_html__('Template Styles', 'event_espresso'),
2261
+			array($this, 'template_pack_meta_box'),
2262
+			$this->_current_screen->id,
2263
+			'side',
2264
+			'high'
2265
+		);
2266
+	}
2267
+
2268
+
2269
+	/**
2270
+	 * metabox content for all template pack and variation selection.
2271
+	 *
2272
+	 * @since 4.5.0
2273
+	 * @return string
2274
+	 * @throws DomainException
2275
+	 * @throws EE_Error
2276
+	 * @throws InvalidArgumentException
2277
+	 * @throws ReflectionException
2278
+	 * @throws InvalidDataTypeException
2279
+	 * @throws InvalidInterfaceException
2280
+	 */
2281
+	public function template_pack_meta_box()
2282
+	{
2283
+		$this->_set_message_template_group();
2284
+
2285
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2286
+
2287
+		$tp_select_values = array();
2288
+
2289
+		foreach ($tp_collection as $tp) {
2290
+			// only include template packs that support this messenger and message type!
2291
+			$supports = $tp->get_supports();
2292
+			if (! isset($supports[ $this->_message_template_group->messenger() ])
2293
+				|| ! in_array(
2294
+					$this->_message_template_group->message_type(),
2295
+					$supports[ $this->_message_template_group->messenger() ],
2296
+					true
2297
+				)
2298
+			) {
2299
+				// not supported
2300
+				continue;
2301
+			}
2302
+
2303
+			$tp_select_values[] = array(
2304
+				'text' => $tp->label,
2305
+				'id'   => $tp->dbref,
2306
+			);
2307
+		}
2308
+
2309
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2310
+		// the default template pack.  This still allows for the odd template pack to override.
2311
+		if (empty($tp_select_values)) {
2312
+			$tp_select_values[] = array(
2313
+				'text' => esc_html__('Default', 'event_espresso'),
2314
+				'id'   => 'default',
2315
+			);
2316
+		}
2317
+
2318
+		// setup variation select values for the currently selected template.
2319
+		$variations = $this->_message_template_group->get_template_pack()->get_variations(
2320
+			$this->_message_template_group->messenger(),
2321
+			$this->_message_template_group->message_type()
2322
+		);
2323
+		$variations_select_values = array();
2324
+		foreach ($variations as $variation => $label) {
2325
+			$variations_select_values[] = array(
2326
+				'text' => $label,
2327
+				'id'   => $variation,
2328
+			);
2329
+		}
2330
+
2331
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2332
+
2333
+		$template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2334
+			'MTP_template_pack',
2335
+			$tp_select_values,
2336
+			$this->_message_template_group->get_template_pack_name()
2337
+		);
2338
+		$template_args['variations_selector'] = EEH_Form_Fields::select_input(
2339
+			'MTP_template_variation',
2340
+			$variations_select_values,
2341
+			$this->_message_template_group->get_template_pack_variation()
2342
+		);
2343
+		$template_args['template_pack_label'] = $template_pack_labels->template_pack;
2344
+		$template_args['template_variation_label'] = $template_pack_labels->template_variation;
2345
+		$template_args['template_pack_description'] = $template_pack_labels->template_pack_description;
2346
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2347
+
2348
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2349
+
2350
+		EEH_Template::display_template($template, $template_args);
2351
+	}
2352
+
2353
+
2354
+	/**
2355
+	 * This meta box holds any extra actions related to Message Templates
2356
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2357
+	 *
2358
+	 * @access  public
2359
+	 * @return void
2360
+	 * @throws EE_Error
2361
+	 */
2362
+	public function extra_actions_meta_box()
2363
+	{
2364
+		$template_form_fields = array();
2365
+
2366
+		$extra_args = array(
2367
+			'msgr'   => $this->_message_template_group->messenger(),
2368
+			'mt'     => $this->_message_template_group->message_type(),
2369
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2370
+		);
2371
+		// first we need to see if there are any fields
2372
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2373
+
2374
+		if (! empty($fields)) {
2375
+			// yup there be fields
2376
+			foreach ($fields as $field => $config) {
2377
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2378
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2379
+				$default = isset($config['default']) ? $config['default'] : '';
2380
+				$default = isset($config['value']) ? $config['value'] : $default;
2381
+
2382
+				// if type is hidden and the value is empty
2383
+				// something may have gone wrong so let's correct with the defaults
2384
+				$fix = $config['input'] === 'hidden'
2385
+					   && isset($existing[ $field ])
2386
+					   && empty($existing[ $field ])
2387
+					? $default
2388
+					: '';
2389
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2390
+					? $existing[ $field ]
2391
+					: $fix;
2392
+
2393
+				$template_form_fields[ $field_id ] = array(
2394
+					'name'       => 'test_settings_fld[' . $field . ']',
2395
+					'label'      => $config['label'],
2396
+					'input'      => $config['input'],
2397
+					'type'       => $config['type'],
2398
+					'required'   => $config['required'],
2399
+					'validation' => $config['validation'],
2400
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2401
+					'css_class'  => $config['css_class'],
2402
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2403
+					'default'    => $default,
2404
+					'format'     => $config['format'],
2405
+				);
2406
+			}
2407
+		}
2408
+
2409
+		$test_settings_fields = ! empty($template_form_fields)
2410
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2411
+			: '';
2412
+
2413
+		$test_settings_html = '';
2414
+		// print out $test_settings_fields
2415
+		if (! empty($test_settings_fields)) {
2416
+			echo $test_settings_fields;
2417
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2418
+			$test_settings_html .= 'name="test_button" value="';
2419
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2420
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2421
+		}
2422
+
2423
+		// and button
2424
+		$test_settings_html .= '<p>'
2425
+							   . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2426
+							   . '</p>';
2427
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2428
+		$test_settings_html .= $this->get_action_link_or_button(
2429
+			'reset_to_default',
2430
+			'reset',
2431
+			$extra_args,
2432
+			'button-primary reset-default-button'
2433
+		);
2434
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2435
+		echo $test_settings_html;
2436
+	}
2437
+
2438
+
2439
+	/**
2440
+	 * This returns the shortcode selector skeleton for a given context and field.
2441
+	 *
2442
+	 * @since 4.9.rc.000
2443
+	 * @param string $field           The name of the field retrieving shortcodes for.
2444
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2445
+	 * @return string
2446
+	 * @throws DomainException
2447
+	 * @throws EE_Error
2448
+	 * @throws InvalidArgumentException
2449
+	 * @throws ReflectionException
2450
+	 * @throws InvalidDataTypeException
2451
+	 * @throws InvalidInterfaceException
2452
+	 */
2453
+	protected function _get_shortcode_selector($field, $linked_input_id)
2454
+	{
2455
+		$template_args = array(
2456
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2457
+			'fieldname'       => $field,
2458
+			'linked_input_id' => $linked_input_id,
2459
+		);
2460
+
2461
+		return EEH_Template::display_template(
2462
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2463
+			$template_args,
2464
+			true
2465
+		);
2466
+	}
2467
+
2468
+
2469
+	/**
2470
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2471
+	 * page)
2472
+	 *
2473
+	 * @access public
2474
+	 * @return void
2475
+	 * @throws EE_Error
2476
+	 * @throws InvalidArgumentException
2477
+	 * @throws ReflectionException
2478
+	 * @throws InvalidDataTypeException
2479
+	 * @throws InvalidInterfaceException
2480
+	 */
2481
+	public function shortcode_meta_box()
2482
+	{
2483
+		$shortcodes = $this->_get_shortcodes(array(), false); // just make sure shortcodes property is set
2484
+		// $messenger = $this->_message_template_group->messenger_obj();
2485
+		// now let's set the content depending on the status of the shortcodes array
2486
+		if (empty($shortcodes)) {
2487
+			$content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2488
+			echo $content;
2489
+		} else {
2490
+			// $alt = 0;
2491
+			?>
2492 2492
             <div style="float:right; margin-top:10px"><?php
2493
-                            echo $this->_get_help_tab_link('message_template_shortcodes');
2494
-                            ?></div>
2493
+							echo $this->_get_help_tab_link('message_template_shortcodes');
2494
+							?></div>
2495 2495
             <p class="small-text"><?php
2496
-                                  printf(
2497
-                                      esc_html__(
2498
-                                          'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2499
-                                          'event_espresso'
2500
-                                      ),
2501
-                                      '<span class="dashicons dashicons-menu"></span>'
2502
-                                  );
2503
-                                ?>
2496
+								  printf(
2497
+									  esc_html__(
2498
+										  'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2499
+										  'event_espresso'
2500
+									  ),
2501
+									  '<span class="dashicons dashicons-menu"></span>'
2502
+								  );
2503
+								?>
2504 2504
             </p>
2505 2505
             <?php
2506
-        }
2507
-    }
2508
-
2509
-
2510
-    /**
2511
-     * used to set the $_shortcodes property for when its needed elsewhere.
2512
-     *
2513
-     * @access protected
2514
-     * @return void
2515
-     * @throws EE_Error
2516
-     * @throws InvalidArgumentException
2517
-     * @throws ReflectionException
2518
-     * @throws InvalidDataTypeException
2519
-     * @throws InvalidInterfaceException
2520
-     */
2521
-    protected function _set_shortcodes()
2522
-    {
2523
-
2524
-        // no need to run this if the property is already set
2525
-        if (! empty($this->_shortcodes)) {
2526
-            return;
2527
-        }
2528
-
2529
-        $this->_shortcodes = $this->_get_shortcodes();
2530
-    }
2531
-
2532
-
2533
-    /**
2534
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2535
-     * property)
2536
-     *
2537
-     * @access  protected
2538
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2539
-     *                         for. Defaults to all (for the given context)
2540
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2541
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2542
-     *                         true just an array of shortcode/label pairs.
2543
-     * @throws EE_Error
2544
-     * @throws InvalidArgumentException
2545
-     * @throws ReflectionException
2546
-     * @throws InvalidDataTypeException
2547
-     * @throws InvalidInterfaceException
2548
-     */
2549
-    protected function _get_shortcodes($fields = array(), $merged = true)
2550
-    {
2551
-        $this->_set_message_template_group();
2552
-
2553
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2554
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2555
-            ? absint($this->_req_data['id'])
2556
-            : false;
2557
-        $context = isset($this->_req_data['context'])
2558
-            ? $this->_req_data['context']
2559
-            : key($this->_message_template_group->contexts_config());
2560
-
2561
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2562
-    }
2563
-
2564
-
2565
-    /**
2566
-     * This sets the _message_template property (containing the called message_template object)
2567
-     *
2568
-     * @access protected
2569
-     * @return void
2570
-     * @throws EE_Error
2571
-     * @throws InvalidArgumentException
2572
-     * @throws ReflectionException
2573
-     * @throws InvalidDataTypeException
2574
-     * @throws InvalidInterfaceException
2575
-     */
2576
-    protected function _set_message_template_group()
2577
-    {
2578
-
2579
-        if (! empty($this->_message_template_group)) {
2580
-            return;
2581
-        } //get out if this is already set.
2582
-
2583
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2584
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2585
-
2586
-        // let's get the message templates
2587
-        $MTP = EEM_Message_Template_Group::instance();
2588
-
2589
-        if (empty($GRP_ID)) {
2590
-            $this->_message_template_group = $MTP->create_default_object();
2591
-        } else {
2592
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2593
-        }
2594
-
2595
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2596
-        $this->_variation = $this->_message_template_group->get_template_pack_variation();
2597
-    }
2598
-
2599
-
2600
-    /**
2601
-     * sets up a context switcher for edit forms
2602
-     *
2603
-     * @access  protected
2604
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2605
-     * @param array                      $args                  various things the context switcher needs.
2606
-     * @throws EE_Error
2607
-     */
2608
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2609
-    {
2610
-        $context_details = $template_group_object->contexts_config();
2611
-        $context_label = $template_group_object->context_label();
2612
-        ob_start();
2613
-        ?>
2506
+		}
2507
+	}
2508
+
2509
+
2510
+	/**
2511
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2512
+	 *
2513
+	 * @access protected
2514
+	 * @return void
2515
+	 * @throws EE_Error
2516
+	 * @throws InvalidArgumentException
2517
+	 * @throws ReflectionException
2518
+	 * @throws InvalidDataTypeException
2519
+	 * @throws InvalidInterfaceException
2520
+	 */
2521
+	protected function _set_shortcodes()
2522
+	{
2523
+
2524
+		// no need to run this if the property is already set
2525
+		if (! empty($this->_shortcodes)) {
2526
+			return;
2527
+		}
2528
+
2529
+		$this->_shortcodes = $this->_get_shortcodes();
2530
+	}
2531
+
2532
+
2533
+	/**
2534
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2535
+	 * property)
2536
+	 *
2537
+	 * @access  protected
2538
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2539
+	 *                         for. Defaults to all (for the given context)
2540
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2541
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2542
+	 *                         true just an array of shortcode/label pairs.
2543
+	 * @throws EE_Error
2544
+	 * @throws InvalidArgumentException
2545
+	 * @throws ReflectionException
2546
+	 * @throws InvalidDataTypeException
2547
+	 * @throws InvalidInterfaceException
2548
+	 */
2549
+	protected function _get_shortcodes($fields = array(), $merged = true)
2550
+	{
2551
+		$this->_set_message_template_group();
2552
+
2553
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2554
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2555
+			? absint($this->_req_data['id'])
2556
+			: false;
2557
+		$context = isset($this->_req_data['context'])
2558
+			? $this->_req_data['context']
2559
+			: key($this->_message_template_group->contexts_config());
2560
+
2561
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2562
+	}
2563
+
2564
+
2565
+	/**
2566
+	 * This sets the _message_template property (containing the called message_template object)
2567
+	 *
2568
+	 * @access protected
2569
+	 * @return void
2570
+	 * @throws EE_Error
2571
+	 * @throws InvalidArgumentException
2572
+	 * @throws ReflectionException
2573
+	 * @throws InvalidDataTypeException
2574
+	 * @throws InvalidInterfaceException
2575
+	 */
2576
+	protected function _set_message_template_group()
2577
+	{
2578
+
2579
+		if (! empty($this->_message_template_group)) {
2580
+			return;
2581
+		} //get out if this is already set.
2582
+
2583
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2584
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2585
+
2586
+		// let's get the message templates
2587
+		$MTP = EEM_Message_Template_Group::instance();
2588
+
2589
+		if (empty($GRP_ID)) {
2590
+			$this->_message_template_group = $MTP->create_default_object();
2591
+		} else {
2592
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2593
+		}
2594
+
2595
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2596
+		$this->_variation = $this->_message_template_group->get_template_pack_variation();
2597
+	}
2598
+
2599
+
2600
+	/**
2601
+	 * sets up a context switcher for edit forms
2602
+	 *
2603
+	 * @access  protected
2604
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2605
+	 * @param array                      $args                  various things the context switcher needs.
2606
+	 * @throws EE_Error
2607
+	 */
2608
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2609
+	{
2610
+		$context_details = $template_group_object->contexts_config();
2611
+		$context_label = $template_group_object->context_label();
2612
+		ob_start();
2613
+		?>
2614 2614
         <div class="ee-msg-switcher-container">
2615 2615
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2616 2616
                 <?php
2617
-                foreach ($args as $name => $value) {
2618
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2619
-                        continue;
2620
-                    }
2621
-                    ?>
2617
+				foreach ($args as $name => $value) {
2618
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2619
+						continue;
2620
+					}
2621
+					?>
2622 2622
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2623 2623
                     <?php
2624
-                }
2625
-                // setup nonce_url
2626
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2627
-                ?>
2624
+				}
2625
+				// setup nonce_url
2626
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2627
+				?>
2628 2628
                 <select name="context">
2629 2629
                     <?php
2630
-                    $context_templates = $template_group_object->context_templates();
2631
-                    if (is_array($context_templates)) :
2632
-                        foreach ($context_templates as $context => $template_fields) :
2633
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2634
-                            ?>
2630
+					$context_templates = $template_group_object->context_templates();
2631
+					if (is_array($context_templates)) :
2632
+						foreach ($context_templates as $context => $template_fields) :
2633
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2634
+							?>
2635 2635
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2636 2636
                                 <?php echo $context_details[ $context ]['label']; ?>
2637 2637
                             </option>
2638 2638
                         <?php endforeach;
2639
-                    endif; ?>
2639
+					endif; ?>
2640 2640
                 </select>
2641 2641
                 <?php $button_text = sprintf(__('Switch %s', 'event_espresso'), ucwords($context_label['label'])); ?>
2642 2642
                 <input id="submit-msg-context-switcher-sbmt" class="button-secondary" type="submit"
@@ -2645,1925 +2645,1925 @@  discard block
 block discarded – undo
2645 2645
             <?php echo $args['extra']; ?>
2646 2646
         </div> <!-- end .ee-msg-switcher-container -->
2647 2647
         <?php
2648
-        $output = ob_get_contents();
2649
-        ob_clean();
2650
-        $this->_context_switcher = $output;
2651
-    }
2652
-
2653
-
2654
-    /**
2655
-     * utility for sanitizing new values coming in.
2656
-     * Note: this is only used when updating a context.
2657
-     *
2658
-     * @access protected
2659
-     *
2660
-     * @param int $index This helps us know which template field to select from the request array.
2661
-     *
2662
-     * @return array
2663
-     */
2664
-    protected function _set_message_template_column_values($index)
2665
-    {
2666
-        if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2667
-            foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2668
-                $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2669
-            }
2670
-        }
2671
-
2672
-
2673
-        $set_column_values = array(
2674
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2675
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2676
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2677
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2678
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2679
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2680
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2681
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2682
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2683
-                ? absint($this->_req_data['MTP_is_global'])
2684
-                : 0,
2685
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2686
-                ? absint($this->_req_data['MTP_is_override'])
2687
-                : 0,
2688
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2689
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active']),
2690
-        );
2691
-
2692
-
2693
-        return $set_column_values;
2694
-    }
2695
-
2696
-
2697
-    protected function _insert_or_update_message_template($new = false)
2698
-    {
2699
-
2700
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2701
-        $success = 0;
2702
-        $override = false;
2703
-
2704
-        // setup notices description
2705
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2706
-
2707
-        // need the message type and messenger objects to be able to use the labels for the notices
2708
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2709
-        $messenger_label = $messenger_object instanceof EE_messenger
2710
-            ? ucwords($messenger_object->label['singular'])
2711
-            : '';
2712
-
2713
-        $message_type_slug = ! empty($this->_req_data['MTP_message_type'])
2714
-            ? $this->_req_data['MTP_message_type']
2715
-            : '';
2716
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2717
-
2718
-        $message_type_label = $message_type_object instanceof EE_message_type
2719
-            ? ucwords($message_type_object->label['singular'])
2720
-            : '';
2721
-
2722
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2723
-            ? $this->_req_data['MTP_context']
2724
-            : '';
2725
-        $context = ucwords(str_replace('_', ' ', $context_slug));
2726
-
2727
-        $item_desc = $messenger_label && $message_type_label
2728
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2729
-            : '';
2730
-        $item_desc .= 'Message Template';
2731
-        $query_args = array();
2732
-        $edit_array = array();
2733
-        $action_desc = '';
2734
-
2735
-        // if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2736
-        // user to edit.
2737
-        if ($new) {
2738
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2739
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2740
-                if (empty($edit_array)) {
2741
-                    $success = 0;
2742
-                } else {
2743
-                    $success = 1;
2744
-                    $edit_array = $edit_array[0];
2745
-                    $query_args = array(
2746
-                        'id'      => $edit_array['GRP_ID'],
2747
-                        'context' => $edit_array['MTP_context'],
2748
-                        'action'  => 'edit_message_template',
2749
-                    );
2750
-                }
2751
-            }
2752
-            $action_desc = 'created';
2753
-        } else {
2754
-            $MTPG = EEM_Message_Template_Group::instance();
2755
-            $MTP = EEM_Message_Template::instance();
2756
-
2757
-
2758
-            // run update for each template field in displayed context
2759
-            if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2760
-                EE_Error::add_error(
2761
-                    esc_html__(
2762
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2763
-                        'event_espresso'
2764
-                    ),
2765
-                    __FILE__,
2766
-                    __FUNCTION__,
2767
-                    __LINE__
2768
-                );
2769
-                $success = 0;
2770
-            } else {
2771
-                // first validate all fields!
2772
-                // this filter allows client code to add its own validation to the template fields as well.
2773
-                // returning an empty array means everything passed validation.
2774
-                // errors in validation should be represented in an array with the following shape:
2775
-                // array(
2776
-                //   'fieldname' => array(
2777
-                //          'msg' => 'error message'
2778
-                //          'value' => 'value for field producing error'
2779
-                // )
2780
-                $custom_validation = (array) apply_filters(
2781
-                    'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2782
-                    array(),
2783
-                    $this->_req_data['MTP_template_fields'],
2784
-                    $context_slug,
2785
-                    $messenger_slug,
2786
-                    $message_type_slug
2787
-                );
2788
-
2789
-                $system_validation = $MTPG->validate(
2790
-                    $this->_req_data['MTP_template_fields'],
2791
-                    $context_slug,
2792
-                    $messenger_slug,
2793
-                    $message_type_slug
2794
-                );
2795
-
2796
-                $system_validation = ! is_array($system_validation) && $system_validation ? array()
2797
-                    : $system_validation;
2798
-                $validates = array_merge($custom_validation, $system_validation);
2799
-
2800
-                // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2801
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2802
-                //  WE need to make sure there is no actual error messages in validates.
2803
-                if (is_array($validates) && ! empty($validates)) {
2804
-                    // add the transient so when the form loads we know which fields to highlight
2805
-                    $this->_add_transient('edit_message_template', $validates);
2806
-
2807
-                    $success = 0;
2808
-
2809
-                    // setup notices
2810
-                    foreach ($validates as $field => $error) {
2811
-                        if (isset($error['msg'])) {
2812
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2813
-                        }
2814
-                    }
2815
-                } else {
2816
-                    $set_column_values = array();
2817
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2818
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2819
-
2820
-                        $where_cols_n_values = array(
2821
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2822
-                        );
2823
-                        // if they aren't allowed to use all JS, restrict them to just posty-y tags
2824
-                        if (! current_user_can('unfiltered_html')) {
2825
-                            if (is_array($set_column_values['MTP_content'])) {
2826
-                                foreach ($set_column_values['MTP_content'] as $key => $value) {
2827
-                                    // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2828
-                                    // only removes slashes from double-quotes, so attributes using single quotes always
2829
-                                    // appear invalid.) But currently the models expect slashed data, so after wp_kses
2830
-                                    // runs we need to re-slash the data. Sheesh. See
2831
-                                    // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2832
-                                    $set_column_values['MTP_content'][ $key ] = addslashes(
2833
-                                        wp_kses(
2834
-                                            stripslashes($value),
2835
-                                            wp_kses_allowed_html('post')
2836
-                                        )
2837
-                                    );
2838
-                                }
2839
-                            } else {
2840
-                                $set_column_values['MTP_content'] = wp_kses(
2841
-                                    $set_column_values['MTP_content'],
2842
-                                    wp_kses_allowed_html('post')
2843
-                                );
2844
-                            }
2845
-                        }
2846
-                        $message_template_fields = array(
2847
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2848
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2849
-                            'MTP_context'        => $set_column_values['MTP_context'],
2850
-                            'MTP_content'        => $set_column_values['MTP_content'],
2851
-                        );
2852
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2853
-                            if ($updated === false) {
2854
-                                EE_Error::add_error(
2855
-                                    sprintf(
2856
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2857
-                                        $template_field
2858
-                                    ),
2859
-                                    __FILE__,
2860
-                                    __FUNCTION__,
2861
-                                    __LINE__
2862
-                                );
2863
-                            } else {
2864
-                                $success = 1;
2865
-                            }
2866
-                        } else {
2867
-                            // only do this logic if we don't have a MTP_ID for this field
2868
-                            if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2869
-                                // this has already been through the template field validator and sanitized, so it will be
2870
-                                // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2871
-                                // message template field in a messenger/message type and existing users don't have the
2872
-                                // default setup for it.
2873
-                                // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2874
-                                $updated = $MTP->insert($message_template_fields);
2875
-                                if (! $updated || is_wp_error($updated)) {
2876
-                                    EE_Error::add_error(
2877
-                                        sprintf(
2878
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2879
-                                            $template_field
2880
-                                        ),
2881
-                                        __FILE__,
2882
-                                        __FUNCTION__,
2883
-                                        __LINE__
2884
-                                    );
2885
-                                    $success = 0;
2886
-                                } else {
2887
-                                    $success = 1;
2888
-                                }
2889
-                            }
2890
-                        }
2891
-                        $action_desc = 'updated';
2892
-                    }
2893
-
2894
-                    // we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2895
-                    $mtpg_fields = array(
2896
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2897
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2898
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2899
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2900
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2901
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2902
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2903
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2904
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2905
-                            : '',
2906
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2907
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2908
-                            : '',
2909
-                    );
2910
-
2911
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2912
-                    $updated = $MTPG->update($mtpg_fields, array($mtpg_where));
2913
-
2914
-                    if ($updated === false) {
2915
-                        EE_Error::add_error(
2916
-                            sprintf(
2917
-                                esc_html__(
2918
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2919
-                                    'event_espresso'
2920
-                                ),
2921
-                                $set_column_values['GRP_ID']
2922
-                            ),
2923
-                            __FILE__,
2924
-                            __FUNCTION__,
2925
-                            __LINE__
2926
-                        );
2927
-                    } else {
2928
-                        // k now we need to ensure the template_pack and template_variation fields are set.
2929
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2930
-                            ? $this->_req_data['MTP_template_pack']
2931
-                            : 'default';
2932
-
2933
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2934
-                            ? $this->_req_data['MTP_template_variation']
2935
-                            : 'default';
2936
-
2937
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2938
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2939
-                            $mtpg_obj->set_template_pack_name($template_pack);
2940
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2941
-                        }
2942
-                        $success = 1;
2943
-                    }
2944
-                }
2945
-            }
2946
-        }
2947
-
2948
-        // we return things differently if doing ajax
2949
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2950
-            $this->_template_args['success'] = $success;
2951
-            $this->_template_args['error'] = ! $success ? true : false;
2952
-            $this->_template_args['content'] = '';
2953
-            $this->_template_args['data'] = array(
2954
-                'grpID'        => $edit_array['GRP_ID'],
2955
-                'templateName' => $edit_array['template_name'],
2956
-            );
2957
-            if ($success) {
2958
-                EE_Error::overwrite_success();
2959
-                EE_Error::add_success(
2960
-                    esc_html__(
2961
-                        '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.',
2962
-                        'event_espresso'
2963
-                    )
2964
-                );
2965
-            }
2966
-
2967
-            $this->_return_json();
2968
-        }
2969
-
2970
-
2971
-        // was a test send triggered?
2972
-        if (isset($this->_req_data['test_button'])) {
2973
-            EE_Error::overwrite_success();
2974
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2975
-            $override = true;
2976
-        }
2977
-
2978
-        if (empty($query_args)) {
2979
-            $query_args = array(
2980
-                'id'      => $this->_req_data['GRP_ID'],
2981
-                'context' => $context_slug,
2982
-                'action'  => 'edit_message_template',
2983
-            );
2984
-        }
2985
-
2986
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2987
-    }
2988
-
2989
-
2990
-    /**
2991
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2992
-     *
2993
-     * @param  string $context      what context being tested
2994
-     * @param  string $messenger    messenger being tested
2995
-     * @param  string $message_type message type being tested
2996
-     * @throws EE_Error
2997
-     * @throws InvalidArgumentException
2998
-     * @throws InvalidDataTypeException
2999
-     * @throws InvalidInterfaceException
3000
-     */
3001
-    protected function _do_test_send($context, $messenger, $message_type)
3002
-    {
3003
-        // set things up for preview
3004
-        $this->_req_data['messenger'] = $messenger;
3005
-        $this->_req_data['message_type'] = $message_type;
3006
-        $this->_req_data['context'] = $context;
3007
-        $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
3008
-        $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);
3009
-
3010
-        // let's save any existing fields that might be required by the messenger
3011
-        if (isset($this->_req_data['test_settings_fld'])
3012
-            && $active_messenger instanceof EE_messenger
3013
-            && apply_filters(
3014
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3015
-                true,
3016
-                $this->_req_data['test_settings_fld'],
3017
-                $active_messenger
3018
-            )
3019
-        ) {
3020
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
3021
-        }
3022
-
3023
-        /**
3024
-         * Use filter to add additional controls on whether message can send or not
3025
-         */
3026
-        if (apply_filters(
3027
-            'FHEE__Messages_Admin_Page__do_test_send__can_send',
3028
-            true,
3029
-            $context,
3030
-            $this->_req_data,
3031
-            $messenger,
3032
-            $message_type
3033
-        )) {
3034
-            if (EEM_Event::instance()->count() > 0) {
3035
-                $success = $this->_preview_message(true);
3036
-                if ($success) {
3037
-                    EE_Error::add_success(__('Test message sent', 'event_espresso'));
3038
-                } else {
3039
-                    EE_Error::add_error(
3040
-                        esc_html__('The test message was not sent', 'event_espresso'),
3041
-                        __FILE__,
3042
-                        __FUNCTION__,
3043
-                        __LINE__
3044
-                    );
3045
-                }
3046
-            } else {
3047
-                $this->noEventsErrorMessage(true);
3048
-            }
3049
-        }
3050
-    }
3051
-
3052
-
3053
-    /**
3054
-     * _generate_new_templates
3055
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3056
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3057
-     * for the event.
3058
-     *
3059
-     *
3060
-     * @param  string $messenger     the messenger we are generating templates for
3061
-     * @param array   $message_types array of message types that the templates are generated for.
3062
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
3063
-     *                               indicate the message_template_group being used as the base.
3064
-     *
3065
-     * @param bool    $global
3066
-     *
3067
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3068
-     *                               encountering problems.
3069
-     * @throws EE_Error
3070
-     */
3071
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3072
-    {
3073
-
3074
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3075
-        // just don't generate any templates.
3076
-        if (empty($message_types)) {
3077
-            return true;
3078
-        }
3079
-
3080
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3081
-    }
3082
-
3083
-
3084
-    /**
3085
-     * [_trash_or_restore_message_template]
3086
-     *
3087
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3088
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3089
-     *                        an individual context (FALSE).
3090
-     * @return void
3091
-     * @throws EE_Error
3092
-     * @throws InvalidArgumentException
3093
-     * @throws InvalidDataTypeException
3094
-     * @throws InvalidInterfaceException
3095
-     */
3096
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3097
-    {
3098
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3099
-        $MTP = EEM_Message_Template_Group::instance();
3100
-
3101
-        $success = 1;
3102
-
3103
-        // incoming GRP_IDs
3104
-        if ($all) {
3105
-            // Checkboxes
3106
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3107
-                // if array has more than one element then success message should be plural.
3108
-                // todo: what about nonce?
3109
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3110
-
3111
-                // cycle through checkboxes
3112
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3113
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3114
-                    if (! $trashed_or_restored) {
3115
-                        $success = 0;
3116
-                    }
3117
-                }
3118
-            } else {
3119
-                // grab single GRP_ID and handle
3120
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3121
-                if (! empty($GRP_ID)) {
3122
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3123
-                    if (! $trashed_or_restored) {
3124
-                        $success = 0;
3125
-                    }
3126
-                } else {
3127
-                    $success = 0;
3128
-                }
3129
-            }
3130
-        }
3131
-
3132
-        $action_desc = $trash
3133
-            ? esc_html__('moved to the trash', 'event_espresso')
3134
-            : esc_html__('restored', 'event_espresso');
3135
-
3136
-        $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc;
3137
-
3138
-        $item_desc = $all ? _n(
3139
-            'Message Template Group',
3140
-            'Message Template Groups',
3141
-            $success,
3142
-            'event_espresso'
3143
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3144
-
3145
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n(
3146
-            'template',
3147
-            'templates',
3148
-            $success,
3149
-            'event_espresso'
3150
-        ) : $item_desc;
3151
-
3152
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
3153
-    }
3154
-
3155
-
3156
-    /**
3157
-     * [_delete_message_template]
3158
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3159
-     *
3160
-     * @return void
3161
-     * @throws EE_Error
3162
-     * @throws InvalidArgumentException
3163
-     * @throws InvalidDataTypeException
3164
-     * @throws InvalidInterfaceException
3165
-     */
3166
-    protected function _delete_message_template()
3167
-    {
3168
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3169
-
3170
-        // checkboxes
3171
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3172
-            // if array has more than one element then success message should be plural
3173
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3174
-
3175
-            // cycle through bulk action checkboxes
3176
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3177
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3178
-            }
3179
-        } else {
3180
-            // grab single grp_id and delete
3181
-            $GRP_ID = absint($this->_req_data['id']);
3182
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3183
-        }
3184
-
3185
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3186
-    }
3187
-
3188
-
3189
-    /**
3190
-     * helper for permanently deleting a mtP group and all related message_templates
3191
-     *
3192
-     * @param  int  $GRP_ID        The group being deleted
3193
-     * @param  bool $include_group whether to delete the Message Template Group as well.
3194
-     * @return bool boolean to indicate the success of the deletes or not.
3195
-     * @throws EE_Error
3196
-     * @throws InvalidArgumentException
3197
-     * @throws InvalidDataTypeException
3198
-     * @throws InvalidInterfaceException
3199
-     */
3200
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3201
-    {
3202
-        $success = 1;
3203
-        $MTPG = EEM_Message_Template_Group::instance();
3204
-        // first let's GET this group
3205
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3206
-        // then delete permanently all the related Message Templates
3207
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3208
-
3209
-        if ($deleted === 0) {
3210
-            $success = 0;
3211
-        }
3212
-
3213
-        // now delete permanently this particular group
3214
-
3215
-        if ($include_group && ! $MTG->delete_permanently()) {
3216
-            $success = 0;
3217
-        }
3218
-
3219
-        return $success;
3220
-    }
3221
-
3222
-
3223
-    /**
3224
-     *    _learn_more_about_message_templates_link
3225
-     *
3226
-     * @access protected
3227
-     * @return string
3228
-     */
3229
-    protected function _learn_more_about_message_templates_link()
3230
-    {
3231
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3232
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3233
-               . '</a>';
3234
-    }
3235
-
3236
-
3237
-    /**
3238
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3239
-     * ajax and other routes.
3240
-     *
3241
-     * @return void
3242
-     * @throws DomainException
3243
-     */
3244
-    protected function _settings()
3245
-    {
3246
-
3247
-
3248
-        $this->_set_m_mt_settings();
3249
-
3250
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3251
-            ? $this->_req_data['selected_messenger']
3252
-            : 'email';
3253
-
3254
-        // let's setup the messenger tabs
3255
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3256
-            $this->_m_mt_settings['messenger_tabs'],
3257
-            'messenger_links',
3258
-            '|',
3259
-            $selected_messenger
3260
-        );
3261
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3262
-        $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';
3263
-
3264
-        $this->display_admin_page_with_sidebar();
3265
-    }
3266
-
3267
-
3268
-    /**
3269
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3270
-     *
3271
-     * @access protected
3272
-     * @return void
3273
-     * @throws DomainException
3274
-     */
3275
-    protected function _set_m_mt_settings()
3276
-    {
3277
-        // first if this is already set then lets get out no need to regenerate data.
3278
-        if (! empty($this->_m_mt_settings)) {
3279
-            return;
3280
-        }
3281
-
3282
-        // get all installed messengers and message_types
3283
-        /** @type EE_messenger[] $messengers */
3284
-        $messengers = $this->_message_resource_manager->installed_messengers();
3285
-        /** @type EE_message_type[] $message_types */
3286
-        $message_types = $this->_message_resource_manager->installed_message_types();
3287
-
3288
-
3289
-        // assemble the array for the _tab_text_links helper
3290
-
3291
-        foreach ($messengers as $messenger) {
3292
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array(
3293
-                'label' => ucwords($messenger->label['singular']),
3294
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3295
-                    ? 'messenger-active'
3296
-                    : '',
3297
-                'href'  => $messenger->name,
3298
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3299
-                'slug'  => $messenger->name,
3300
-                'obj'   => $messenger,
3301
-            );
3302
-
3303
-
3304
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3305
-
3306
-            foreach ($message_types as $message_type) {
3307
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3308
-                // it shouldn't show in either the inactive OR active metabox.
3309
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3310
-                    continue;
3311
-                }
3312
-
3313
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3314
-                    $messenger->name,
3315
-                    $message_type->name
3316
-                )
3317
-                    ? 'active'
3318
-                    : 'inactive';
3319
-
3320
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array(
3321
-                    'label'    => ucwords($message_type->label['singular']),
3322
-                    'class'    => 'message-type-' . $a_or_i,
3323
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3324
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3325
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3326
-                    'title'    => $a_or_i === 'active'
3327
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3328
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3329
-                    'content'  => $a_or_i === 'active'
3330
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3331
-                        : $this->_message_type_settings_content($message_type, $messenger),
3332
-                    'slug'     => $message_type->name,
3333
-                    'active'   => $a_or_i === 'active',
3334
-                    'obj'      => $message_type,
3335
-                );
3336
-            }
3337
-        }
3338
-    }
3339
-
3340
-
3341
-    /**
3342
-     * This just prepares the content for the message type settings
3343
-     *
3344
-     * @param  EE_message_type $message_type The message type object
3345
-     * @param  EE_messenger    $messenger    The messenger object
3346
-     * @param  boolean         $active       Whether the message type is active or not
3347
-     * @return string html output for the content
3348
-     * @throws DomainException
3349
-     */
3350
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3351
-    {
3352
-        // get message type fields
3353
-        $fields = $message_type->get_admin_settings_fields();
3354
-        $settings_template_args['template_form_fields'] = '';
3355
-
3356
-        if (! empty($fields) && $active) {
3357
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3358
-            foreach ($fields as $fldname => $fldprops) {
3359
-                $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3360
-                $template_form_field[ $field_id ] = array(
3361
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3362
-                    'label'      => $fldprops['label'],
3363
-                    'input'      => $fldprops['field_type'],
3364
-                    'type'       => $fldprops['value_type'],
3365
-                    'required'   => $fldprops['required'],
3366
-                    'validation' => $fldprops['validation'],
3367
-                    'value'      => isset($existing_settings[ $fldname ])
3368
-                        ? $existing_settings[ $fldname ]
3369
-                        : $fldprops['default'],
3370
-                    'options'    => isset($fldprops['options'])
3371
-                        ? $fldprops['options']
3372
-                        : array(),
3373
-                    'default'    => isset($existing_settings[ $fldname ])
3374
-                        ? $existing_settings[ $fldname ]
3375
-                        : $fldprops['default'],
3376
-                    'css_class'  => 'no-drag',
3377
-                    'format'     => $fldprops['format'],
3378
-                );
3379
-            }
3380
-
3381
-
3382
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3383
-                ? $this->_generate_admin_form_fields(
3384
-                    $template_form_field,
3385
-                    'string',
3386
-                    'ee_mt_activate_form'
3387
-                )
3388
-                : '';
3389
-        }
3390
-
3391
-        $settings_template_args['description'] = $message_type->description;
3392
-        // we also need some hidden fields
3393
-        $settings_template_args['hidden_fields'] = array(
3394
-            'message_type_settings[messenger]'    => array(
3395
-                'type'  => 'hidden',
3396
-                'value' => $messenger->name,
3397
-            ),
3398
-            'message_type_settings[message_type]' => array(
3399
-                'type'  => 'hidden',
3400
-                'value' => $message_type->name,
3401
-            ),
3402
-            'type'                                => array(
3403
-                'type'  => 'hidden',
3404
-                'value' => 'message_type',
3405
-            ),
3406
-        );
3407
-
3408
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3409
-            $settings_template_args['hidden_fields'],
3410
-            'array'
3411
-        );
3412
-        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3413
-            ? ' hidden'
3414
-            : '';
3415
-
3416
-
3417
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3418
-        $content = EEH_Template::display_template($template, $settings_template_args, true);
3419
-
3420
-        return $content;
3421
-    }
3422
-
3423
-
3424
-    /**
3425
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3426
-     *
3427
-     * @access protected
3428
-     * @return void
3429
-     * @throws DomainException
3430
-     */
3431
-    protected function _messages_settings_metaboxes()
3432
-    {
3433
-        $this->_set_m_mt_settings();
3434
-        $m_boxes = $mt_boxes = array();
3435
-        $m_template_args = $mt_template_args = array();
3436
-
3437
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3438
-            ? $this->_req_data['selected_messenger']
3439
-            : 'email';
3440
-
3441
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3442
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3443
-                $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3444
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3445
-                // messenger meta boxes
3446
-                $active = $selected_messenger === $messenger;
3447
-                $active_mt_tabs = isset(
3448
-                    $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3449
-                )
3450
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3451
-                    : '';
3452
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3453
-                    esc_html__('%s Settings', 'event_espresso'),
3454
-                    $tab_array['label']
3455
-                );
3456
-                $m_template_args[ $messenger . '_a_box' ] = array(
3457
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3458
-                    'inactive_message_types' => isset(
3459
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3460
-                    )
3461
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3462
-                        : '',
3463
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3464
-                    'hidden'                 => $active ? '' : ' hidden',
3465
-                    'hide_on_message'        => $hide_on_message,
3466
-                    'messenger'              => $messenger,
3467
-                    'active'                 => $active,
3468
-                );
3469
-                // message type meta boxes
3470
-                // (which is really just the inactive container for each messenger
3471
-                // showing inactive message types for that messenger)
3472
-                $mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso');
3473
-                $mt_template_args[ $messenger . '_i_box' ] = array(
3474
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3475
-                    'inactive_message_types' => isset(
3476
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3477
-                    )
3478
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3479
-                        : '',
3480
-                    'hidden'                 => $active ? '' : ' hidden',
3481
-                    'hide_on_message'        => $hide_on_message,
3482
-                    'hide_off_message'       => $hide_off_message,
3483
-                    'messenger'              => $messenger,
3484
-                    'active'                 => $active,
3485
-                );
3486
-            }
3487
-        }
3488
-
3489
-
3490
-        // register messenger metaboxes
3491
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3492
-        foreach ($m_boxes as $box => $label) {
3493
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]);
3494
-            $msgr = str_replace('_a_box', '', $box);
3495
-            add_meta_box(
3496
-                'espresso_' . $msgr . '_settings',
3497
-                $label,
3498
-                function ($post, $metabox) {
3499
-                    echo EEH_Template::display_template(
3500
-                        $metabox["args"]["template_path"],
3501
-                        $metabox["args"]["template_args"],
3502
-                        true
3503
-                    );
3504
-                },
3505
-                $this->_current_screen->id,
3506
-                'normal',
3507
-                'high',
3508
-                $callback_args
3509
-            );
3510
-        }
3511
-
3512
-        // register message type metaboxes
3513
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3514
-        foreach ($mt_boxes as $box => $label) {
3515
-            $callback_args = array(
3516
-                'template_path' => $mt_template_path,
3517
-                'template_args' => $mt_template_args[ $box ],
3518
-            );
3519
-            $mt = str_replace('_i_box', '', $box);
3520
-            add_meta_box(
3521
-                'espresso_' . $mt . '_inactive_mts',
3522
-                $label,
3523
-                function ($post, $metabox) {
3524
-                    echo EEH_Template::display_template(
3525
-                        $metabox["args"]["template_path"],
3526
-                        $metabox["args"]["template_args"],
3527
-                        true
3528
-                    );
3529
-                },
3530
-                $this->_current_screen->id,
3531
-                'side',
3532
-                'high',
3533
-                $callback_args
3534
-            );
3535
-        }
3536
-
3537
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3538
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3539
-        if (is_main_site()) {
3540
-            add_meta_box(
3541
-                'espresso_global_message_settings',
3542
-                esc_html__('Global Message Settings', 'event_espresso'),
3543
-                array($this, 'global_messages_settings_metabox_content'),
3544
-                $this->_current_screen->id,
3545
-                'normal',
3546
-                'low',
3547
-                array()
3548
-            );
3549
-        }
3550
-    }
3551
-
3552
-
3553
-    /**
3554
-     *  This generates the content for the global messages settings metabox.
3555
-     *
3556
-     * @return string
3557
-     * @throws EE_Error
3558
-     * @throws InvalidArgumentException
3559
-     * @throws ReflectionException
3560
-     * @throws InvalidDataTypeException
3561
-     * @throws InvalidInterfaceException
3562
-     */
3563
-    public function global_messages_settings_metabox_content()
3564
-    {
3565
-        $form = $this->_generate_global_settings_form();
3566
-        echo $form->form_open(
3567
-            $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3568
-            'POST'
3569
-        )
3570
-             . $form->get_html()
3571
-             . $form->form_close();
3572
-    }
3573
-
3574
-
3575
-    /**
3576
-     * This generates and returns the form object for the global messages settings.
3577
-     *
3578
-     * @return EE_Form_Section_Proper
3579
-     * @throws EE_Error
3580
-     * @throws InvalidArgumentException
3581
-     * @throws ReflectionException
3582
-     * @throws InvalidDataTypeException
3583
-     * @throws InvalidInterfaceException
3584
-     */
3585
-    protected function _generate_global_settings_form()
3586
-    {
3587
-        EE_Registry::instance()->load_helper('HTML');
3588
-        /** @var EE_Network_Core_Config $network_config */
3589
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3590
-
3591
-        return new EE_Form_Section_Proper(
3592
-            array(
3593
-                'name'            => 'global_messages_settings',
3594
-                'html_id'         => 'global_messages_settings',
3595
-                'html_class'      => 'form-table',
3596
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3597
-                'subsections'     => apply_filters(
3598
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3599
-                    array(
3600
-                        'do_messages_on_same_request' => new EE_Select_Input(
3601
-                            array(
3602
-                                true  => esc_html__("On the same request", "event_espresso"),
3603
-                                false => esc_html__("On a separate request", "event_espresso"),
3604
-                            ),
3605
-                            array(
3606
-                                'default'         => $network_config->do_messages_on_same_request,
3607
-                                'html_label_text' => esc_html__(
3608
-                                    'Generate and send all messages:',
3609
-                                    'event_espresso'
3610
-                                ),
3611
-                                'html_help_text'  => esc_html__(
3612
-                                    '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.',
3613
-                                    'event_espresso'
3614
-                                ),
3615
-                            )
3616
-                        ),
3617
-                        'delete_threshold'            => new EE_Select_Input(
3618
-                            array(
3619
-                                0  => esc_html__('Forever', 'event_espresso'),
3620
-                                3  => esc_html__('3 Months', 'event_espresso'),
3621
-                                6  => esc_html__('6 Months', 'event_espresso'),
3622
-                                9  => esc_html__('9 Months', 'event_espresso'),
3623
-                                12 => esc_html__('12 Months', 'event_espresso'),
3624
-                                24 => esc_html__('24 Months', 'event_espresso'),
3625
-                                36 => esc_html__('36 Months', 'event_espresso'),
3626
-                            ),
3627
-                            array(
3628
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3629
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3630
-                                'html_help_text'  => esc_html__(
3631
-                                    'You can control how long a record of processed messages is kept via this option.',
3632
-                                    'event_espresso'
3633
-                                ),
3634
-                            )
3635
-                        ),
3636
-                        'update_settings'             => new EE_Submit_Input(
3637
-                            array(
3638
-                                'default'         => esc_html__('Update', 'event_espresso'),
3639
-                                'html_label_text' => '&nbsp',
3640
-                            )
3641
-                        ),
3642
-                    )
3643
-                ),
3644
-            )
3645
-        );
3646
-    }
3647
-
3648
-
3649
-    /**
3650
-     * This handles updating the global settings set on the admin page.
3651
-     *
3652
-     * @throws EE_Error
3653
-     * @throws InvalidDataTypeException
3654
-     * @throws InvalidInterfaceException
3655
-     * @throws InvalidArgumentException
3656
-     * @throws ReflectionException
3657
-     */
3658
-    protected function _update_global_settings()
3659
-    {
3660
-        /** @var EE_Network_Core_Config $network_config */
3661
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3662
-        $messages_config = EE_Registry::instance()->CFG->messages;
3663
-        $form = $this->_generate_global_settings_form();
3664
-        if ($form->was_submitted()) {
3665
-            $form->receive_form_submission();
3666
-            if ($form->is_valid()) {
3667
-                $valid_data = $form->valid_data();
3668
-                foreach ($valid_data as $property => $value) {
3669
-                    $setter = 'set_' . $property;
3670
-                    if (method_exists($network_config, $setter)) {
3671
-                        $network_config->{$setter}($value);
3672
-                    } elseif (property_exists($network_config, $property)
3673
-                        && $network_config->{$property} !== $value
3674
-                    ) {
3675
-                        $network_config->{$property} = $value;
3676
-                    } elseif (property_exists($messages_config, $property)
3677
-                        && $messages_config->{$property} !== $value
3678
-                    ) {
3679
-                        $messages_config->{$property} = $value;
3680
-                    }
3681
-                }
3682
-                // only update if the form submission was valid!
3683
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3684
-                EE_Registry::instance()->CFG->update_espresso_config();
3685
-                EE_Error::overwrite_success();
3686
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3687
-            }
3688
-        }
3689
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3690
-    }
3691
-
3692
-
3693
-    /**
3694
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3695
-     *
3696
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3697
-     * @return string html formatted tabs
3698
-     * @throws DomainException
3699
-     */
3700
-    protected function _get_mt_tabs($tab_array)
3701
-    {
3702
-        $tab_array = (array) $tab_array;
3703
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3704
-        $tabs = '';
3705
-
3706
-        foreach ($tab_array as $tab) {
3707
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3708
-        }
3709
-
3710
-        return $tabs;
3711
-    }
3712
-
3713
-
3714
-    /**
3715
-     * This prepares the content of the messenger meta box admin settings
3716
-     *
3717
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3718
-     * @return string html formatted content
3719
-     * @throws DomainException
3720
-     */
3721
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3722
-    {
3723
-
3724
-        $fields = $messenger->get_admin_settings_fields();
3725
-        $settings_template_args['template_form_fields'] = '';
3726
-
3727
-        // is $messenger active?
3728
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3729
-
3730
-
3731
-        if (! empty($fields)) {
3732
-            $existing_settings = $messenger->get_existing_admin_settings();
3733
-
3734
-            foreach ($fields as $fldname => $fldprops) {
3735
-                $field_id = $messenger->name . '-' . $fldname;
3736
-                $template_form_field[ $field_id ] = array(
3737
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3738
-                    'label'      => $fldprops['label'],
3739
-                    'input'      => $fldprops['field_type'],
3740
-                    'type'       => $fldprops['value_type'],
3741
-                    'required'   => $fldprops['required'],
3742
-                    'validation' => $fldprops['validation'],
3743
-                    'value'      => isset($existing_settings[ $field_id ])
3744
-                        ? $existing_settings[ $field_id ]
3745
-                        : $fldprops['default'],
3746
-                    'css_class'  => '',
3747
-                    'format'     => $fldprops['format'],
3748
-                );
3749
-            }
3750
-
3751
-
3752
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3753
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3754
-                : '';
3755
-        }
3756
-
3757
-        // we also need some hidden fields
3758
-        $settings_template_args['hidden_fields'] = array(
3759
-            'messenger_settings[messenger]' => array(
3760
-                'type'  => 'hidden',
3761
-                'value' => $messenger->name,
3762
-            ),
3763
-            'type'                          => array(
3764
-                'type'  => 'hidden',
3765
-                'value' => 'messenger',
3766
-            ),
3767
-        );
3768
-
3769
-        // make sure any active message types that are existing are included in the hidden fields
3770
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3771
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3772
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array(
3773
-                    'type'  => 'hidden',
3774
-                    'value' => $mt,
3775
-                );
3776
-            }
3777
-        }
3778
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3779
-            $settings_template_args['hidden_fields'],
3780
-            'array'
3781
-        );
3782
-        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3783
-
3784
-        $settings_template_args['messenger'] = $messenger->name;
3785
-        $settings_template_args['description'] = $messenger->description;
3786
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3787
-
3788
-
3789
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3790
-            $messenger->name
3791
-        )
3792
-            ? $settings_template_args['show_hide_edit_form']
3793
-            : ' hidden';
3794
-
3795
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3796
-            ? ' hidden'
3797
-            : $settings_template_args['show_hide_edit_form'];
3798
-
3799
-
3800
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3801
-        $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3802
-        $settings_template_args['on_off_status'] = $active ? true : false;
3803
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3804
-        $content = EEH_Template::display_template(
3805
-            $template,
3806
-            $settings_template_args,
3807
-            true
3808
-        );
3809
-
3810
-        return $content;
3811
-    }
3812
-
3813
-
3814
-    /**
3815
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3816
-     *
3817
-     * @throws DomainException
3818
-     * @throws EE_Error
3819
-     * @throws InvalidDataTypeException
3820
-     * @throws InvalidInterfaceException
3821
-     * @throws InvalidArgumentException
3822
-     * @throws ReflectionException
3823
-     */
3824
-    public function activate_messenger_toggle()
3825
-    {
3826
-        $success = true;
3827
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3828
-        // let's check that we have required data
3829
-        if (! isset($this->_req_data['messenger'])) {
3830
-            EE_Error::add_error(
3831
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3832
-                __FILE__,
3833
-                __FUNCTION__,
3834
-                __LINE__
3835
-            );
3836
-            $success = false;
3837
-        }
3838
-
3839
-        // do a nonce check here since we're not arriving via a normal route
3840
-        $nonce = isset($this->_req_data['activate_nonce'])
3841
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3842
-            : '';
3843
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3844
-
3845
-        $this->_verify_nonce($nonce, $nonce_ref);
3846
-
3847
-
3848
-        if (! isset($this->_req_data['status'])) {
3849
-            EE_Error::add_error(
3850
-                esc_html__(
3851
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3852
-                    'event_espresso'
3853
-                ),
3854
-                __FILE__,
3855
-                __FUNCTION__,
3856
-                __LINE__
3857
-            );
3858
-            $success = false;
3859
-        }
3860
-
3861
-        // do check to verify we have a valid status.
3862
-        $status = $this->_req_data['status'];
3863
-
3864
-        if ($status !== 'off' && $status !== 'on') {
3865
-            EE_Error::add_error(
3866
-                sprintf(
3867
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3868
-                    $this->_req_data['status']
3869
-                ),
3870
-                __FILE__,
3871
-                __FUNCTION__,
3872
-                __LINE__
3873
-            );
3874
-            $success = false;
3875
-        }
3876
-
3877
-        if ($success) {
3878
-            // made it here?  Stop dawdling then!!
3879
-            $success = $status === 'off'
3880
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3881
-                : $this->_activate_messenger($this->_req_data['messenger']);
3882
-        }
3883
-
3884
-        $this->_template_args['success'] = $success;
3885
-
3886
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
3887
-        $this->_return_json();
3888
-    }
3889
-
3890
-
3891
-    /**
3892
-     * used by ajax from the messages settings page to activate|deactivate a message type
3893
-     *
3894
-     * @throws DomainException
3895
-     * @throws EE_Error
3896
-     * @throws ReflectionException
3897
-     * @throws InvalidDataTypeException
3898
-     * @throws InvalidInterfaceException
3899
-     * @throws InvalidArgumentException
3900
-     */
3901
-    public function activate_mt_toggle()
3902
-    {
3903
-        $success = true;
3904
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3905
-
3906
-        // let's make sure we have the necessary data
3907
-        if (! isset($this->_req_data['message_type'])) {
3908
-            EE_Error::add_error(
3909
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3910
-                __FILE__,
3911
-                __FUNCTION__,
3912
-                __LINE__
3913
-            );
3914
-            $success = false;
3915
-        }
3916
-
3917
-        if (! isset($this->_req_data['messenger'])) {
3918
-            EE_Error::add_error(
3919
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3920
-                __FILE__,
3921
-                __FUNCTION__,
3922
-                __LINE__
3923
-            );
3924
-            $success = false;
3925
-        }
3926
-
3927
-        if (! isset($this->_req_data['status'])) {
3928
-            EE_Error::add_error(
3929
-                esc_html__(
3930
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3931
-                    'event_espresso'
3932
-                ),
3933
-                __FILE__,
3934
-                __FUNCTION__,
3935
-                __LINE__
3936
-            );
3937
-            $success = false;
3938
-        }
3939
-
3940
-
3941
-        // do check to verify we have a valid status.
3942
-        $status = $this->_req_data['status'];
3943
-
3944
-        if ($status !== 'activate' && $status !== 'deactivate') {
3945
-            EE_Error::add_error(
3946
-                sprintf(
3947
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3948
-                    $this->_req_data['status']
3949
-                ),
3950
-                __FILE__,
3951
-                __FUNCTION__,
3952
-                __LINE__
3953
-            );
3954
-            $success = false;
3955
-        }
3956
-
3957
-
3958
-        // do a nonce check here since we're not arriving via a normal route
3959
-        $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3960
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3961
-
3962
-        $this->_verify_nonce($nonce, $nonce_ref);
3963
-
3964
-        if ($success) {
3965
-            // made it here? um, what are you waiting for then?
3966
-            $success = $status === 'deactivate'
3967
-                ? $this->_deactivate_message_type_for_messenger(
3968
-                    $this->_req_data['messenger'],
3969
-                    $this->_req_data['message_type']
3970
-                )
3971
-                : $this->_activate_message_type_for_messenger(
3972
-                    $this->_req_data['messenger'],
3973
-                    $this->_req_data['message_type']
3974
-                );
3975
-        }
3976
-
3977
-        $this->_template_args['success'] = $success;
3978
-        $this->_return_json();
3979
-    }
3980
-
3981
-
3982
-    /**
3983
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3984
-     *
3985
-     * @param string $messenger_name The name of the messenger being activated
3986
-     * @return bool
3987
-     * @throws DomainException
3988
-     * @throws EE_Error
3989
-     * @throws InvalidArgumentException
3990
-     * @throws ReflectionException
3991
-     * @throws InvalidDataTypeException
3992
-     * @throws InvalidInterfaceException
3993
-     */
3994
-    protected function _activate_messenger($messenger_name)
3995
-    {
3996
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3997
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3998
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3999
-            ? $active_messenger->get_default_message_types()
4000
-            : array();
4001
-
4002
-        // ensure is active
4003
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4004
-
4005
-        // set response_data for reload
4006
-        foreach ($message_types_to_activate as $message_type_name) {
4007
-            /** @var EE_message_type $message_type */
4008
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4009
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger(
4010
-                $messenger_name,
4011
-                $message_type_name
4012
-            )
4013
-                && $message_type instanceof EE_message_type
4014
-            ) {
4015
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4016
-                if ($message_type->get_admin_settings_fields()) {
4017
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4018
-                }
4019
-            }
4020
-        }
4021
-
4022
-        // add success message for activating messenger
4023
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4024
-    }
4025
-
4026
-
4027
-    /**
4028
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4029
-     *
4030
-     * @param string $messenger_name The name of the messenger being activated
4031
-     * @return bool
4032
-     * @throws DomainException
4033
-     * @throws EE_Error
4034
-     * @throws InvalidArgumentException
4035
-     * @throws ReflectionException
4036
-     * @throws InvalidDataTypeException
4037
-     * @throws InvalidInterfaceException
4038
-     */
4039
-    protected function _deactivate_messenger($messenger_name)
4040
-    {
4041
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4042
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4043
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4044
-
4045
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4046
-    }
4047
-
4048
-
4049
-    /**
4050
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4051
-     *
4052
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4053
-     * @param string $message_type_name The name of the message type being activated for the messenger
4054
-     * @return bool
4055
-     * @throws DomainException
4056
-     * @throws EE_Error
4057
-     * @throws InvalidArgumentException
4058
-     * @throws ReflectionException
4059
-     * @throws InvalidDataTypeException
4060
-     * @throws InvalidInterfaceException
4061
-     */
4062
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4063
-    {
4064
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4065
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4066
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4067
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4068
-
4069
-        // ensure is active
4070
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4071
-
4072
-        // set response for load
4073
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger(
4074
-            $messenger_name,
4075
-            $message_type_name
4076
-        )
4077
-        ) {
4078
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4079
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4080
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4081
-            }
4082
-        }
4083
-
4084
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4085
-            $active_messenger,
4086
-            $message_type_to_activate
4087
-        );
4088
-    }
4089
-
4090
-
4091
-    /**
4092
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4093
-     *
4094
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4095
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4096
-     * @return bool
4097
-     * @throws DomainException
4098
-     * @throws EE_Error
4099
-     * @throws InvalidArgumentException
4100
-     * @throws ReflectionException
4101
-     * @throws InvalidDataTypeException
4102
-     * @throws InvalidInterfaceException
4103
-     */
4104
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4105
-    {
4106
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4107
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4108
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4109
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4110
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4111
-
4112
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4113
-            $active_messenger,
4114
-            $message_type_to_deactivate
4115
-        );
4116
-    }
4117
-
4118
-
4119
-    /**
4120
-     * This just initializes the defaults for activating messenger and message type responses.
4121
-     */
4122
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4123
-    {
4124
-        $this->_template_args['data']['active_mts'] = array();
4125
-        $this->_template_args['data']['mt_reload'] = array();
4126
-    }
4127
-
4128
-
4129
-    /**
4130
-     * Setup appropriate response for activating a messenger and/or message types
4131
-     *
4132
-     * @param EE_messenger         $messenger
4133
-     * @param EE_message_type|null $message_type
4134
-     * @return bool
4135
-     * @throws DomainException
4136
-     * @throws EE_Error
4137
-     * @throws InvalidArgumentException
4138
-     * @throws ReflectionException
4139
-     * @throws InvalidDataTypeException
4140
-     * @throws InvalidInterfaceException
4141
-     */
4142
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4143
-        $messenger,
4144
-        EE_Message_Type $message_type = null
4145
-    ) {
4146
-        // if $messenger isn't a valid messenger object then get out.
4147
-        if (! $messenger instanceof EE_Messenger) {
4148
-            EE_Error::add_error(
4149
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4150
-                __FILE__,
4151
-                __FUNCTION__,
4152
-                __LINE__
4153
-            );
4154
-
4155
-            return false;
4156
-        }
4157
-        // activated
4158
-        if ($this->_template_args['data']['active_mts']) {
4159
-            EE_Error::overwrite_success();
4160
-            // activated a message type with the messenger
4161
-            if ($message_type instanceof EE_message_type) {
4162
-                EE_Error::add_success(
4163
-                    sprintf(
4164
-                        esc_html__(
4165
-                            '%s message type has been successfully activated with the %s messenger',
4166
-                            'event_espresso'
4167
-                        ),
4168
-                        ucwords($message_type->label['singular']),
4169
-                        ucwords($messenger->label['singular'])
4170
-                    )
4171
-                );
4172
-
4173
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4174
-                if ($message_type->name === 'invoice') {
4175
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4176
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4177
-                    if ($pm instanceof EE_Payment_Method) {
4178
-                        EE_Error::add_attention(
4179
-                            esc_html__(
4180
-                                '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.',
4181
-                                'event_espresso'
4182
-                            )
4183
-                        );
4184
-                    }
4185
-                }
4186
-                // just toggles the entire messenger
4187
-            } else {
4188
-                EE_Error::add_success(
4189
-                    sprintf(
4190
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4191
-                        ucwords($messenger->label['singular'])
4192
-                    )
4193
-                );
4194
-            }
4195
-
4196
-            return true;
4197
-
4198
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4199
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4200
-            // in which case we just give a success message for the messenger being successfully activated.
4201
-        } else {
4202
-            if (! $messenger->get_default_message_types()) {
4203
-                // messenger doesn't have any default message types so still a success.
4204
-                EE_Error::add_success(
4205
-                    sprintf(
4206
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4207
-                        ucwords($messenger->label['singular'])
4208
-                    )
4209
-                );
4210
-
4211
-                return true;
4212
-            } else {
4213
-                EE_Error::add_error(
4214
-                    $message_type instanceof EE_message_type
4215
-                        ? sprintf(
4216
-                            esc_html__(
4217
-                                '%s message type was not successfully activated with the %s messenger',
4218
-                                'event_espresso'
4219
-                            ),
4220
-                            ucwords($message_type->label['singular']),
4221
-                            ucwords($messenger->label['singular'])
4222
-                        )
4223
-                        : sprintf(
4224
-                            esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4225
-                            ucwords($messenger->label['singular'])
4226
-                        ),
4227
-                    __FILE__,
4228
-                    __FUNCTION__,
4229
-                    __LINE__
4230
-                );
4231
-
4232
-                return false;
4233
-            }
4234
-        }
4235
-    }
4236
-
4237
-
4238
-    /**
4239
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4240
-     *
4241
-     * @param EE_messenger         $messenger
4242
-     * @param EE_message_type|null $message_type
4243
-     * @return bool
4244
-     * @throws DomainException
4245
-     * @throws EE_Error
4246
-     * @throws InvalidArgumentException
4247
-     * @throws ReflectionException
4248
-     * @throws InvalidDataTypeException
4249
-     * @throws InvalidInterfaceException
4250
-     */
4251
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4252
-        $messenger,
4253
-        EE_message_type $message_type = null
4254
-    ) {
4255
-        EE_Error::overwrite_success();
4256
-
4257
-        // if $messenger isn't a valid messenger object then get out.
4258
-        if (! $messenger instanceof EE_Messenger) {
4259
-            EE_Error::add_error(
4260
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4261
-                __FILE__,
4262
-                __FUNCTION__,
4263
-                __LINE__
4264
-            );
4265
-
4266
-            return false;
4267
-        }
4268
-
4269
-        if ($message_type instanceof EE_message_type) {
4270
-            $message_type_name = $message_type->name;
4271
-            EE_Error::add_success(
4272
-                sprintf(
4273
-                    esc_html__(
4274
-                        '%s message type has been successfully deactivated for the %s messenger.',
4275
-                        'event_espresso'
4276
-                    ),
4277
-                    ucwords($message_type->label['singular']),
4278
-                    ucwords($messenger->label['singular'])
4279
-                )
4280
-            );
4281
-        } else {
4282
-            $message_type_name = '';
4283
-            EE_Error::add_success(
4284
-                sprintf(
4285
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4286
-                    ucwords($messenger->label['singular'])
4287
-                )
4288
-            );
4289
-        }
4290
-
4291
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4292
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4293
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4294
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4295
-            if ($count_updated > 0) {
4296
-                $msg = $message_type_name === 'invoice'
4297
-                    ? esc_html__(
4298
-                        '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.',
4299
-                        'event_espresso'
4300
-                    )
4301
-                    : esc_html__(
4302
-                        '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.',
4303
-                        'event_espresso'
4304
-                    );
4305
-                EE_Error::add_attention($msg);
4306
-            }
4307
-        }
4308
-
4309
-        return true;
4310
-    }
4311
-
4312
-
4313
-    /**
4314
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4315
-     *
4316
-     * @throws DomainException
4317
-     */
4318
-    public function update_mt_form()
4319
-    {
4320
-        if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4321
-            EE_Error::add_error(
4322
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4323
-                __FILE__,
4324
-                __FUNCTION__,
4325
-                __LINE__
4326
-            );
4327
-            $this->_return_json();
4328
-        }
4329
-
4330
-        $message_types = $this->get_installed_message_types();
4331
-
4332
-        $message_type = $message_types[ $this->_req_data['message_type'] ];
4333
-        $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4334
-
4335
-        $content = $this->_message_type_settings_content(
4336
-            $message_type,
4337
-            $messenger,
4338
-            true
4339
-        );
4340
-        $this->_template_args['success'] = true;
4341
-        $this->_template_args['content'] = $content;
4342
-        $this->_return_json();
4343
-    }
4344
-
4345
-
4346
-    /**
4347
-     * this handles saving the settings for a messenger or message type
4348
-     *
4349
-     */
4350
-    public function save_settings()
4351
-    {
4352
-        if (! isset($this->_req_data['type'])) {
4353
-            EE_Error::add_error(
4354
-                esc_html__(
4355
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4356
-                    'event_espresso'
4357
-                ),
4358
-                __FILE__,
4359
-                __FUNCTION__,
4360
-                __LINE__
4361
-            );
4362
-            $this->_template_args['error'] = true;
4363
-            $this->_return_json();
4364
-        }
4365
-
4366
-
4367
-        if ($this->_req_data['type'] === 'messenger') {
4368
-            // this should be an array.
4369
-            $settings = $this->_req_data['messenger_settings'];
4370
-            $messenger = $settings['messenger'];
4371
-            // let's setup the settings data
4372
-            foreach ($settings as $key => $value) {
4373
-                switch ($key) {
4374
-                    case 'messenger':
4375
-                        unset($settings['messenger']);
4376
-                        break;
4377
-                    case 'message_types':
4378
-                        unset($settings['message_types']);
4379
-                        break;
4380
-                    default:
4381
-                        $settings[ $key ] = $value;
4382
-                        break;
4383
-                }
4384
-            }
4385
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4386
-        } elseif ($this->_req_data['type'] === 'message_type') {
4387
-            $settings = $this->_req_data['message_type_settings'];
4388
-            $messenger = $settings['messenger'];
4389
-            $message_type = $settings['message_type'];
4390
-
4391
-            foreach ($settings as $key => $value) {
4392
-                switch ($key) {
4393
-                    case 'messenger':
4394
-                        unset($settings['messenger']);
4395
-                        break;
4396
-                    case 'message_type':
4397
-                        unset($settings['message_type']);
4398
-                        break;
4399
-                    default:
4400
-                        $settings[ $key ] = $value;
4401
-                        break;
4402
-                }
4403
-            }
4404
-
4405
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4406
-        }
4407
-
4408
-        // okay we should have the data all setup.  Now we just update!
4409
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4410
-
4411
-        if ($success) {
4412
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
4413
-        } else {
4414
-            EE_Error::add_error(
4415
-                esc_html__(
4416
-                    'Settings did not get updated',
4417
-                    'event_espresso'
4418
-                ),
4419
-                __FILE__,
4420
-                __FUNCTION__,
4421
-                __LINE__
4422
-            );
4423
-        }
4424
-
4425
-        $this->_template_args['success'] = $success;
4426
-        $this->_return_json();
4427
-    }
4428
-
4429
-
4430
-
4431
-
4432
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4433
-
4434
-
4435
-    /**
4436
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4437
-     * However, this does not send immediately, it just queues for sending.
4438
-     *
4439
-     * @since 4.9.0
4440
-     * @throws EE_Error
4441
-     * @throws InvalidDataTypeException
4442
-     * @throws InvalidInterfaceException
4443
-     * @throws InvalidArgumentException
4444
-     * @throws ReflectionException
4445
-     */
4446
-    protected function _generate_now()
4447
-    {
4448
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4449
-        $this->_redirect_after_action(false, '', '', array(), true);
4450
-    }
4451
-
4452
-
4453
-    /**
4454
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4455
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4456
-     *
4457
-     * @since 4.9.0
4458
-     * @throws EE_Error
4459
-     * @throws InvalidDataTypeException
4460
-     * @throws InvalidInterfaceException
4461
-     * @throws InvalidArgumentException
4462
-     * @throws ReflectionException
4463
-     */
4464
-    protected function _generate_and_send_now()
4465
-    {
4466
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4467
-        $this->_redirect_after_action(false, '', '', array(), true);
4468
-    }
4469
-
4470
-
4471
-    /**
4472
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4473
-     *
4474
-     * @since 4.9.0
4475
-     * @throws EE_Error
4476
-     * @throws InvalidDataTypeException
4477
-     * @throws InvalidInterfaceException
4478
-     * @throws InvalidArgumentException
4479
-     * @throws ReflectionException
4480
-     */
4481
-    protected function _queue_for_resending()
4482
-    {
4483
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4484
-        $this->_redirect_after_action(false, '', '', array(), true);
4485
-    }
4486
-
4487
-
4488
-    /**
4489
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4490
-     *
4491
-     * @since 4.9.0
4492
-     * @throws EE_Error
4493
-     * @throws InvalidDataTypeException
4494
-     * @throws InvalidInterfaceException
4495
-     * @throws InvalidArgumentException
4496
-     * @throws ReflectionException
4497
-     */
4498
-    protected function _send_now()
4499
-    {
4500
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4501
-        $this->_redirect_after_action(false, '', '', array(), true);
4502
-    }
4503
-
4504
-
4505
-    /**
4506
-     * Deletes EE_messages for IDs in the request.
4507
-     *
4508
-     * @since 4.9.0
4509
-     * @throws EE_Error
4510
-     * @throws InvalidDataTypeException
4511
-     * @throws InvalidInterfaceException
4512
-     * @throws InvalidArgumentException
4513
-     */
4514
-    protected function _delete_ee_messages()
4515
-    {
4516
-        $msg_ids = $this->_get_msg_ids_from_request();
4517
-        $deleted_count = 0;
4518
-        foreach ($msg_ids as $msg_id) {
4519
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4520
-                $deleted_count++;
4521
-            }
4522
-        }
4523
-        if ($deleted_count) {
4524
-            EE_Error::add_success(
4525
-                esc_html(
4526
-                    _n(
4527
-                        'Message successfully deleted',
4528
-                        'Messages successfully deleted',
4529
-                        $deleted_count,
4530
-                        'event_espresso'
4531
-                    )
4532
-                )
4533
-            );
4534
-            $this->_redirect_after_action(
4535
-                false,
4536
-                '',
4537
-                '',
4538
-                array(),
4539
-                true
4540
-            );
4541
-        } else {
4542
-            EE_Error::add_error(
4543
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4544
-                __FILE__,
4545
-                __FUNCTION__,
4546
-                __LINE__
4547
-            );
4548
-            $this->_redirect_after_action(false, '', '', array(), true);
4549
-        }
4550
-    }
4551
-
4552
-
4553
-    /**
4554
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4555
-     *
4556
-     * @since 4.9.0
4557
-     * @return array
4558
-     */
4559
-    protected function _get_msg_ids_from_request()
4560
-    {
4561
-        if (! isset($this->_req_data['MSG_ID'])) {
4562
-            return array();
4563
-        }
4564
-
4565
-        return is_array($this->_req_data['MSG_ID'])
4566
-            ? array_keys($this->_req_data['MSG_ID'])
4567
-            : array($this->_req_data['MSG_ID']);
4568
-    }
2648
+		$output = ob_get_contents();
2649
+		ob_clean();
2650
+		$this->_context_switcher = $output;
2651
+	}
2652
+
2653
+
2654
+	/**
2655
+	 * utility for sanitizing new values coming in.
2656
+	 * Note: this is only used when updating a context.
2657
+	 *
2658
+	 * @access protected
2659
+	 *
2660
+	 * @param int $index This helps us know which template field to select from the request array.
2661
+	 *
2662
+	 * @return array
2663
+	 */
2664
+	protected function _set_message_template_column_values($index)
2665
+	{
2666
+		if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2667
+			foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2668
+				$this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2669
+			}
2670
+		}
2671
+
2672
+
2673
+		$set_column_values = array(
2674
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2675
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2676
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2677
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2678
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2679
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2680
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2681
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2682
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2683
+				? absint($this->_req_data['MTP_is_global'])
2684
+				: 0,
2685
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2686
+				? absint($this->_req_data['MTP_is_override'])
2687
+				: 0,
2688
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2689
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active']),
2690
+		);
2691
+
2692
+
2693
+		return $set_column_values;
2694
+	}
2695
+
2696
+
2697
+	protected function _insert_or_update_message_template($new = false)
2698
+	{
2699
+
2700
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2701
+		$success = 0;
2702
+		$override = false;
2703
+
2704
+		// setup notices description
2705
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2706
+
2707
+		// need the message type and messenger objects to be able to use the labels for the notices
2708
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2709
+		$messenger_label = $messenger_object instanceof EE_messenger
2710
+			? ucwords($messenger_object->label['singular'])
2711
+			: '';
2712
+
2713
+		$message_type_slug = ! empty($this->_req_data['MTP_message_type'])
2714
+			? $this->_req_data['MTP_message_type']
2715
+			: '';
2716
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2717
+
2718
+		$message_type_label = $message_type_object instanceof EE_message_type
2719
+			? ucwords($message_type_object->label['singular'])
2720
+			: '';
2721
+
2722
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2723
+			? $this->_req_data['MTP_context']
2724
+			: '';
2725
+		$context = ucwords(str_replace('_', ' ', $context_slug));
2726
+
2727
+		$item_desc = $messenger_label && $message_type_label
2728
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2729
+			: '';
2730
+		$item_desc .= 'Message Template';
2731
+		$query_args = array();
2732
+		$edit_array = array();
2733
+		$action_desc = '';
2734
+
2735
+		// if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2736
+		// user to edit.
2737
+		if ($new) {
2738
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2739
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2740
+				if (empty($edit_array)) {
2741
+					$success = 0;
2742
+				} else {
2743
+					$success = 1;
2744
+					$edit_array = $edit_array[0];
2745
+					$query_args = array(
2746
+						'id'      => $edit_array['GRP_ID'],
2747
+						'context' => $edit_array['MTP_context'],
2748
+						'action'  => 'edit_message_template',
2749
+					);
2750
+				}
2751
+			}
2752
+			$action_desc = 'created';
2753
+		} else {
2754
+			$MTPG = EEM_Message_Template_Group::instance();
2755
+			$MTP = EEM_Message_Template::instance();
2756
+
2757
+
2758
+			// run update for each template field in displayed context
2759
+			if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2760
+				EE_Error::add_error(
2761
+					esc_html__(
2762
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2763
+						'event_espresso'
2764
+					),
2765
+					__FILE__,
2766
+					__FUNCTION__,
2767
+					__LINE__
2768
+				);
2769
+				$success = 0;
2770
+			} else {
2771
+				// first validate all fields!
2772
+				// this filter allows client code to add its own validation to the template fields as well.
2773
+				// returning an empty array means everything passed validation.
2774
+				// errors in validation should be represented in an array with the following shape:
2775
+				// array(
2776
+				//   'fieldname' => array(
2777
+				//          'msg' => 'error message'
2778
+				//          'value' => 'value for field producing error'
2779
+				// )
2780
+				$custom_validation = (array) apply_filters(
2781
+					'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2782
+					array(),
2783
+					$this->_req_data['MTP_template_fields'],
2784
+					$context_slug,
2785
+					$messenger_slug,
2786
+					$message_type_slug
2787
+				);
2788
+
2789
+				$system_validation = $MTPG->validate(
2790
+					$this->_req_data['MTP_template_fields'],
2791
+					$context_slug,
2792
+					$messenger_slug,
2793
+					$message_type_slug
2794
+				);
2795
+
2796
+				$system_validation = ! is_array($system_validation) && $system_validation ? array()
2797
+					: $system_validation;
2798
+				$validates = array_merge($custom_validation, $system_validation);
2799
+
2800
+				// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2801
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2802
+				//  WE need to make sure there is no actual error messages in validates.
2803
+				if (is_array($validates) && ! empty($validates)) {
2804
+					// add the transient so when the form loads we know which fields to highlight
2805
+					$this->_add_transient('edit_message_template', $validates);
2806
+
2807
+					$success = 0;
2808
+
2809
+					// setup notices
2810
+					foreach ($validates as $field => $error) {
2811
+						if (isset($error['msg'])) {
2812
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2813
+						}
2814
+					}
2815
+				} else {
2816
+					$set_column_values = array();
2817
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2818
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2819
+
2820
+						$where_cols_n_values = array(
2821
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2822
+						);
2823
+						// if they aren't allowed to use all JS, restrict them to just posty-y tags
2824
+						if (! current_user_can('unfiltered_html')) {
2825
+							if (is_array($set_column_values['MTP_content'])) {
2826
+								foreach ($set_column_values['MTP_content'] as $key => $value) {
2827
+									// remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2828
+									// only removes slashes from double-quotes, so attributes using single quotes always
2829
+									// appear invalid.) But currently the models expect slashed data, so after wp_kses
2830
+									// runs we need to re-slash the data. Sheesh. See
2831
+									// https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2832
+									$set_column_values['MTP_content'][ $key ] = addslashes(
2833
+										wp_kses(
2834
+											stripslashes($value),
2835
+											wp_kses_allowed_html('post')
2836
+										)
2837
+									);
2838
+								}
2839
+							} else {
2840
+								$set_column_values['MTP_content'] = wp_kses(
2841
+									$set_column_values['MTP_content'],
2842
+									wp_kses_allowed_html('post')
2843
+								);
2844
+							}
2845
+						}
2846
+						$message_template_fields = array(
2847
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2848
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2849
+							'MTP_context'        => $set_column_values['MTP_context'],
2850
+							'MTP_content'        => $set_column_values['MTP_content'],
2851
+						);
2852
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2853
+							if ($updated === false) {
2854
+								EE_Error::add_error(
2855
+									sprintf(
2856
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2857
+										$template_field
2858
+									),
2859
+									__FILE__,
2860
+									__FUNCTION__,
2861
+									__LINE__
2862
+								);
2863
+							} else {
2864
+								$success = 1;
2865
+							}
2866
+						} else {
2867
+							// only do this logic if we don't have a MTP_ID for this field
2868
+							if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2869
+								// this has already been through the template field validator and sanitized, so it will be
2870
+								// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2871
+								// message template field in a messenger/message type and existing users don't have the
2872
+								// default setup for it.
2873
+								// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2874
+								$updated = $MTP->insert($message_template_fields);
2875
+								if (! $updated || is_wp_error($updated)) {
2876
+									EE_Error::add_error(
2877
+										sprintf(
2878
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2879
+											$template_field
2880
+										),
2881
+										__FILE__,
2882
+										__FUNCTION__,
2883
+										__LINE__
2884
+									);
2885
+									$success = 0;
2886
+								} else {
2887
+									$success = 1;
2888
+								}
2889
+							}
2890
+						}
2891
+						$action_desc = 'updated';
2892
+					}
2893
+
2894
+					// we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2895
+					$mtpg_fields = array(
2896
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2897
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2898
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2899
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2900
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2901
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2902
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2903
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2904
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2905
+							: '',
2906
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2907
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2908
+							: '',
2909
+					);
2910
+
2911
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2912
+					$updated = $MTPG->update($mtpg_fields, array($mtpg_where));
2913
+
2914
+					if ($updated === false) {
2915
+						EE_Error::add_error(
2916
+							sprintf(
2917
+								esc_html__(
2918
+									'The Message Template Group (%d) was NOT updated for some reason',
2919
+									'event_espresso'
2920
+								),
2921
+								$set_column_values['GRP_ID']
2922
+							),
2923
+							__FILE__,
2924
+							__FUNCTION__,
2925
+							__LINE__
2926
+						);
2927
+					} else {
2928
+						// k now we need to ensure the template_pack and template_variation fields are set.
2929
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2930
+							? $this->_req_data['MTP_template_pack']
2931
+							: 'default';
2932
+
2933
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2934
+							? $this->_req_data['MTP_template_variation']
2935
+							: 'default';
2936
+
2937
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2938
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2939
+							$mtpg_obj->set_template_pack_name($template_pack);
2940
+							$mtpg_obj->set_template_pack_variation($template_variation);
2941
+						}
2942
+						$success = 1;
2943
+					}
2944
+				}
2945
+			}
2946
+		}
2947
+
2948
+		// we return things differently if doing ajax
2949
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2950
+			$this->_template_args['success'] = $success;
2951
+			$this->_template_args['error'] = ! $success ? true : false;
2952
+			$this->_template_args['content'] = '';
2953
+			$this->_template_args['data'] = array(
2954
+				'grpID'        => $edit_array['GRP_ID'],
2955
+				'templateName' => $edit_array['template_name'],
2956
+			);
2957
+			if ($success) {
2958
+				EE_Error::overwrite_success();
2959
+				EE_Error::add_success(
2960
+					esc_html__(
2961
+						'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.',
2962
+						'event_espresso'
2963
+					)
2964
+				);
2965
+			}
2966
+
2967
+			$this->_return_json();
2968
+		}
2969
+
2970
+
2971
+		// was a test send triggered?
2972
+		if (isset($this->_req_data['test_button'])) {
2973
+			EE_Error::overwrite_success();
2974
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2975
+			$override = true;
2976
+		}
2977
+
2978
+		if (empty($query_args)) {
2979
+			$query_args = array(
2980
+				'id'      => $this->_req_data['GRP_ID'],
2981
+				'context' => $context_slug,
2982
+				'action'  => 'edit_message_template',
2983
+			);
2984
+		}
2985
+
2986
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2987
+	}
2988
+
2989
+
2990
+	/**
2991
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2992
+	 *
2993
+	 * @param  string $context      what context being tested
2994
+	 * @param  string $messenger    messenger being tested
2995
+	 * @param  string $message_type message type being tested
2996
+	 * @throws EE_Error
2997
+	 * @throws InvalidArgumentException
2998
+	 * @throws InvalidDataTypeException
2999
+	 * @throws InvalidInterfaceException
3000
+	 */
3001
+	protected function _do_test_send($context, $messenger, $message_type)
3002
+	{
3003
+		// set things up for preview
3004
+		$this->_req_data['messenger'] = $messenger;
3005
+		$this->_req_data['message_type'] = $message_type;
3006
+		$this->_req_data['context'] = $context;
3007
+		$this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
3008
+		$active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);
3009
+
3010
+		// let's save any existing fields that might be required by the messenger
3011
+		if (isset($this->_req_data['test_settings_fld'])
3012
+			&& $active_messenger instanceof EE_messenger
3013
+			&& apply_filters(
3014
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3015
+				true,
3016
+				$this->_req_data['test_settings_fld'],
3017
+				$active_messenger
3018
+			)
3019
+		) {
3020
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
3021
+		}
3022
+
3023
+		/**
3024
+		 * Use filter to add additional controls on whether message can send or not
3025
+		 */
3026
+		if (apply_filters(
3027
+			'FHEE__Messages_Admin_Page__do_test_send__can_send',
3028
+			true,
3029
+			$context,
3030
+			$this->_req_data,
3031
+			$messenger,
3032
+			$message_type
3033
+		)) {
3034
+			if (EEM_Event::instance()->count() > 0) {
3035
+				$success = $this->_preview_message(true);
3036
+				if ($success) {
3037
+					EE_Error::add_success(__('Test message sent', 'event_espresso'));
3038
+				} else {
3039
+					EE_Error::add_error(
3040
+						esc_html__('The test message was not sent', 'event_espresso'),
3041
+						__FILE__,
3042
+						__FUNCTION__,
3043
+						__LINE__
3044
+					);
3045
+				}
3046
+			} else {
3047
+				$this->noEventsErrorMessage(true);
3048
+			}
3049
+		}
3050
+	}
3051
+
3052
+
3053
+	/**
3054
+	 * _generate_new_templates
3055
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3056
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3057
+	 * for the event.
3058
+	 *
3059
+	 *
3060
+	 * @param  string $messenger     the messenger we are generating templates for
3061
+	 * @param array   $message_types array of message types that the templates are generated for.
3062
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
3063
+	 *                               indicate the message_template_group being used as the base.
3064
+	 *
3065
+	 * @param bool    $global
3066
+	 *
3067
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3068
+	 *                               encountering problems.
3069
+	 * @throws EE_Error
3070
+	 */
3071
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3072
+	{
3073
+
3074
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3075
+		// just don't generate any templates.
3076
+		if (empty($message_types)) {
3077
+			return true;
3078
+		}
3079
+
3080
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3081
+	}
3082
+
3083
+
3084
+	/**
3085
+	 * [_trash_or_restore_message_template]
3086
+	 *
3087
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3088
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3089
+	 *                        an individual context (FALSE).
3090
+	 * @return void
3091
+	 * @throws EE_Error
3092
+	 * @throws InvalidArgumentException
3093
+	 * @throws InvalidDataTypeException
3094
+	 * @throws InvalidInterfaceException
3095
+	 */
3096
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3097
+	{
3098
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3099
+		$MTP = EEM_Message_Template_Group::instance();
3100
+
3101
+		$success = 1;
3102
+
3103
+		// incoming GRP_IDs
3104
+		if ($all) {
3105
+			// Checkboxes
3106
+			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3107
+				// if array has more than one element then success message should be plural.
3108
+				// todo: what about nonce?
3109
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3110
+
3111
+				// cycle through checkboxes
3112
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3113
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3114
+					if (! $trashed_or_restored) {
3115
+						$success = 0;
3116
+					}
3117
+				}
3118
+			} else {
3119
+				// grab single GRP_ID and handle
3120
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3121
+				if (! empty($GRP_ID)) {
3122
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3123
+					if (! $trashed_or_restored) {
3124
+						$success = 0;
3125
+					}
3126
+				} else {
3127
+					$success = 0;
3128
+				}
3129
+			}
3130
+		}
3131
+
3132
+		$action_desc = $trash
3133
+			? esc_html__('moved to the trash', 'event_espresso')
3134
+			: esc_html__('restored', 'event_espresso');
3135
+
3136
+		$action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc;
3137
+
3138
+		$item_desc = $all ? _n(
3139
+			'Message Template Group',
3140
+			'Message Template Groups',
3141
+			$success,
3142
+			'event_espresso'
3143
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3144
+
3145
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n(
3146
+			'template',
3147
+			'templates',
3148
+			$success,
3149
+			'event_espresso'
3150
+		) : $item_desc;
3151
+
3152
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
3153
+	}
3154
+
3155
+
3156
+	/**
3157
+	 * [_delete_message_template]
3158
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3159
+	 *
3160
+	 * @return void
3161
+	 * @throws EE_Error
3162
+	 * @throws InvalidArgumentException
3163
+	 * @throws InvalidDataTypeException
3164
+	 * @throws InvalidInterfaceException
3165
+	 */
3166
+	protected function _delete_message_template()
3167
+	{
3168
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3169
+
3170
+		// checkboxes
3171
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3172
+			// if array has more than one element then success message should be plural
3173
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3174
+
3175
+			// cycle through bulk action checkboxes
3176
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3177
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3178
+			}
3179
+		} else {
3180
+			// grab single grp_id and delete
3181
+			$GRP_ID = absint($this->_req_data['id']);
3182
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3183
+		}
3184
+
3185
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3186
+	}
3187
+
3188
+
3189
+	/**
3190
+	 * helper for permanently deleting a mtP group and all related message_templates
3191
+	 *
3192
+	 * @param  int  $GRP_ID        The group being deleted
3193
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
3194
+	 * @return bool boolean to indicate the success of the deletes or not.
3195
+	 * @throws EE_Error
3196
+	 * @throws InvalidArgumentException
3197
+	 * @throws InvalidDataTypeException
3198
+	 * @throws InvalidInterfaceException
3199
+	 */
3200
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3201
+	{
3202
+		$success = 1;
3203
+		$MTPG = EEM_Message_Template_Group::instance();
3204
+		// first let's GET this group
3205
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3206
+		// then delete permanently all the related Message Templates
3207
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3208
+
3209
+		if ($deleted === 0) {
3210
+			$success = 0;
3211
+		}
3212
+
3213
+		// now delete permanently this particular group
3214
+
3215
+		if ($include_group && ! $MTG->delete_permanently()) {
3216
+			$success = 0;
3217
+		}
3218
+
3219
+		return $success;
3220
+	}
3221
+
3222
+
3223
+	/**
3224
+	 *    _learn_more_about_message_templates_link
3225
+	 *
3226
+	 * @access protected
3227
+	 * @return string
3228
+	 */
3229
+	protected function _learn_more_about_message_templates_link()
3230
+	{
3231
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3232
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3233
+			   . '</a>';
3234
+	}
3235
+
3236
+
3237
+	/**
3238
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3239
+	 * ajax and other routes.
3240
+	 *
3241
+	 * @return void
3242
+	 * @throws DomainException
3243
+	 */
3244
+	protected function _settings()
3245
+	{
3246
+
3247
+
3248
+		$this->_set_m_mt_settings();
3249
+
3250
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3251
+			? $this->_req_data['selected_messenger']
3252
+			: 'email';
3253
+
3254
+		// let's setup the messenger tabs
3255
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3256
+			$this->_m_mt_settings['messenger_tabs'],
3257
+			'messenger_links',
3258
+			'|',
3259
+			$selected_messenger
3260
+		);
3261
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3262
+		$this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';
3263
+
3264
+		$this->display_admin_page_with_sidebar();
3265
+	}
3266
+
3267
+
3268
+	/**
3269
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3270
+	 *
3271
+	 * @access protected
3272
+	 * @return void
3273
+	 * @throws DomainException
3274
+	 */
3275
+	protected function _set_m_mt_settings()
3276
+	{
3277
+		// first if this is already set then lets get out no need to regenerate data.
3278
+		if (! empty($this->_m_mt_settings)) {
3279
+			return;
3280
+		}
3281
+
3282
+		// get all installed messengers and message_types
3283
+		/** @type EE_messenger[] $messengers */
3284
+		$messengers = $this->_message_resource_manager->installed_messengers();
3285
+		/** @type EE_message_type[] $message_types */
3286
+		$message_types = $this->_message_resource_manager->installed_message_types();
3287
+
3288
+
3289
+		// assemble the array for the _tab_text_links helper
3290
+
3291
+		foreach ($messengers as $messenger) {
3292
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array(
3293
+				'label' => ucwords($messenger->label['singular']),
3294
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3295
+					? 'messenger-active'
3296
+					: '',
3297
+				'href'  => $messenger->name,
3298
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3299
+				'slug'  => $messenger->name,
3300
+				'obj'   => $messenger,
3301
+			);
3302
+
3303
+
3304
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3305
+
3306
+			foreach ($message_types as $message_type) {
3307
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3308
+				// it shouldn't show in either the inactive OR active metabox.
3309
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3310
+					continue;
3311
+				}
3312
+
3313
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3314
+					$messenger->name,
3315
+					$message_type->name
3316
+				)
3317
+					? 'active'
3318
+					: 'inactive';
3319
+
3320
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array(
3321
+					'label'    => ucwords($message_type->label['singular']),
3322
+					'class'    => 'message-type-' . $a_or_i,
3323
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3324
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3325
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3326
+					'title'    => $a_or_i === 'active'
3327
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3328
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3329
+					'content'  => $a_or_i === 'active'
3330
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3331
+						: $this->_message_type_settings_content($message_type, $messenger),
3332
+					'slug'     => $message_type->name,
3333
+					'active'   => $a_or_i === 'active',
3334
+					'obj'      => $message_type,
3335
+				);
3336
+			}
3337
+		}
3338
+	}
3339
+
3340
+
3341
+	/**
3342
+	 * This just prepares the content for the message type settings
3343
+	 *
3344
+	 * @param  EE_message_type $message_type The message type object
3345
+	 * @param  EE_messenger    $messenger    The messenger object
3346
+	 * @param  boolean         $active       Whether the message type is active or not
3347
+	 * @return string html output for the content
3348
+	 * @throws DomainException
3349
+	 */
3350
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3351
+	{
3352
+		// get message type fields
3353
+		$fields = $message_type->get_admin_settings_fields();
3354
+		$settings_template_args['template_form_fields'] = '';
3355
+
3356
+		if (! empty($fields) && $active) {
3357
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3358
+			foreach ($fields as $fldname => $fldprops) {
3359
+				$field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3360
+				$template_form_field[ $field_id ] = array(
3361
+					'name'       => 'message_type_settings[' . $fldname . ']',
3362
+					'label'      => $fldprops['label'],
3363
+					'input'      => $fldprops['field_type'],
3364
+					'type'       => $fldprops['value_type'],
3365
+					'required'   => $fldprops['required'],
3366
+					'validation' => $fldprops['validation'],
3367
+					'value'      => isset($existing_settings[ $fldname ])
3368
+						? $existing_settings[ $fldname ]
3369
+						: $fldprops['default'],
3370
+					'options'    => isset($fldprops['options'])
3371
+						? $fldprops['options']
3372
+						: array(),
3373
+					'default'    => isset($existing_settings[ $fldname ])
3374
+						? $existing_settings[ $fldname ]
3375
+						: $fldprops['default'],
3376
+					'css_class'  => 'no-drag',
3377
+					'format'     => $fldprops['format'],
3378
+				);
3379
+			}
3380
+
3381
+
3382
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3383
+				? $this->_generate_admin_form_fields(
3384
+					$template_form_field,
3385
+					'string',
3386
+					'ee_mt_activate_form'
3387
+				)
3388
+				: '';
3389
+		}
3390
+
3391
+		$settings_template_args['description'] = $message_type->description;
3392
+		// we also need some hidden fields
3393
+		$settings_template_args['hidden_fields'] = array(
3394
+			'message_type_settings[messenger]'    => array(
3395
+				'type'  => 'hidden',
3396
+				'value' => $messenger->name,
3397
+			),
3398
+			'message_type_settings[message_type]' => array(
3399
+				'type'  => 'hidden',
3400
+				'value' => $message_type->name,
3401
+			),
3402
+			'type'                                => array(
3403
+				'type'  => 'hidden',
3404
+				'value' => 'message_type',
3405
+			),
3406
+		);
3407
+
3408
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3409
+			$settings_template_args['hidden_fields'],
3410
+			'array'
3411
+		);
3412
+		$settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3413
+			? ' hidden'
3414
+			: '';
3415
+
3416
+
3417
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3418
+		$content = EEH_Template::display_template($template, $settings_template_args, true);
3419
+
3420
+		return $content;
3421
+	}
3422
+
3423
+
3424
+	/**
3425
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3426
+	 *
3427
+	 * @access protected
3428
+	 * @return void
3429
+	 * @throws DomainException
3430
+	 */
3431
+	protected function _messages_settings_metaboxes()
3432
+	{
3433
+		$this->_set_m_mt_settings();
3434
+		$m_boxes = $mt_boxes = array();
3435
+		$m_template_args = $mt_template_args = array();
3436
+
3437
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3438
+			? $this->_req_data['selected_messenger']
3439
+			: 'email';
3440
+
3441
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3442
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3443
+				$hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3444
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3445
+				// messenger meta boxes
3446
+				$active = $selected_messenger === $messenger;
3447
+				$active_mt_tabs = isset(
3448
+					$this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3449
+				)
3450
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3451
+					: '';
3452
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3453
+					esc_html__('%s Settings', 'event_espresso'),
3454
+					$tab_array['label']
3455
+				);
3456
+				$m_template_args[ $messenger . '_a_box' ] = array(
3457
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3458
+					'inactive_message_types' => isset(
3459
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3460
+					)
3461
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3462
+						: '',
3463
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3464
+					'hidden'                 => $active ? '' : ' hidden',
3465
+					'hide_on_message'        => $hide_on_message,
3466
+					'messenger'              => $messenger,
3467
+					'active'                 => $active,
3468
+				);
3469
+				// message type meta boxes
3470
+				// (which is really just the inactive container for each messenger
3471
+				// showing inactive message types for that messenger)
3472
+				$mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso');
3473
+				$mt_template_args[ $messenger . '_i_box' ] = array(
3474
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3475
+					'inactive_message_types' => isset(
3476
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3477
+					)
3478
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3479
+						: '',
3480
+					'hidden'                 => $active ? '' : ' hidden',
3481
+					'hide_on_message'        => $hide_on_message,
3482
+					'hide_off_message'       => $hide_off_message,
3483
+					'messenger'              => $messenger,
3484
+					'active'                 => $active,
3485
+				);
3486
+			}
3487
+		}
3488
+
3489
+
3490
+		// register messenger metaboxes
3491
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3492
+		foreach ($m_boxes as $box => $label) {
3493
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]);
3494
+			$msgr = str_replace('_a_box', '', $box);
3495
+			add_meta_box(
3496
+				'espresso_' . $msgr . '_settings',
3497
+				$label,
3498
+				function ($post, $metabox) {
3499
+					echo EEH_Template::display_template(
3500
+						$metabox["args"]["template_path"],
3501
+						$metabox["args"]["template_args"],
3502
+						true
3503
+					);
3504
+				},
3505
+				$this->_current_screen->id,
3506
+				'normal',
3507
+				'high',
3508
+				$callback_args
3509
+			);
3510
+		}
3511
+
3512
+		// register message type metaboxes
3513
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3514
+		foreach ($mt_boxes as $box => $label) {
3515
+			$callback_args = array(
3516
+				'template_path' => $mt_template_path,
3517
+				'template_args' => $mt_template_args[ $box ],
3518
+			);
3519
+			$mt = str_replace('_i_box', '', $box);
3520
+			add_meta_box(
3521
+				'espresso_' . $mt . '_inactive_mts',
3522
+				$label,
3523
+				function ($post, $metabox) {
3524
+					echo EEH_Template::display_template(
3525
+						$metabox["args"]["template_path"],
3526
+						$metabox["args"]["template_args"],
3527
+						true
3528
+					);
3529
+				},
3530
+				$this->_current_screen->id,
3531
+				'side',
3532
+				'high',
3533
+				$callback_args
3534
+			);
3535
+		}
3536
+
3537
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3538
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3539
+		if (is_main_site()) {
3540
+			add_meta_box(
3541
+				'espresso_global_message_settings',
3542
+				esc_html__('Global Message Settings', 'event_espresso'),
3543
+				array($this, 'global_messages_settings_metabox_content'),
3544
+				$this->_current_screen->id,
3545
+				'normal',
3546
+				'low',
3547
+				array()
3548
+			);
3549
+		}
3550
+	}
3551
+
3552
+
3553
+	/**
3554
+	 *  This generates the content for the global messages settings metabox.
3555
+	 *
3556
+	 * @return string
3557
+	 * @throws EE_Error
3558
+	 * @throws InvalidArgumentException
3559
+	 * @throws ReflectionException
3560
+	 * @throws InvalidDataTypeException
3561
+	 * @throws InvalidInterfaceException
3562
+	 */
3563
+	public function global_messages_settings_metabox_content()
3564
+	{
3565
+		$form = $this->_generate_global_settings_form();
3566
+		echo $form->form_open(
3567
+			$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3568
+			'POST'
3569
+		)
3570
+			 . $form->get_html()
3571
+			 . $form->form_close();
3572
+	}
3573
+
3574
+
3575
+	/**
3576
+	 * This generates and returns the form object for the global messages settings.
3577
+	 *
3578
+	 * @return EE_Form_Section_Proper
3579
+	 * @throws EE_Error
3580
+	 * @throws InvalidArgumentException
3581
+	 * @throws ReflectionException
3582
+	 * @throws InvalidDataTypeException
3583
+	 * @throws InvalidInterfaceException
3584
+	 */
3585
+	protected function _generate_global_settings_form()
3586
+	{
3587
+		EE_Registry::instance()->load_helper('HTML');
3588
+		/** @var EE_Network_Core_Config $network_config */
3589
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3590
+
3591
+		return new EE_Form_Section_Proper(
3592
+			array(
3593
+				'name'            => 'global_messages_settings',
3594
+				'html_id'         => 'global_messages_settings',
3595
+				'html_class'      => 'form-table',
3596
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3597
+				'subsections'     => apply_filters(
3598
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3599
+					array(
3600
+						'do_messages_on_same_request' => new EE_Select_Input(
3601
+							array(
3602
+								true  => esc_html__("On the same request", "event_espresso"),
3603
+								false => esc_html__("On a separate request", "event_espresso"),
3604
+							),
3605
+							array(
3606
+								'default'         => $network_config->do_messages_on_same_request,
3607
+								'html_label_text' => esc_html__(
3608
+									'Generate and send all messages:',
3609
+									'event_espresso'
3610
+								),
3611
+								'html_help_text'  => esc_html__(
3612
+									'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.',
3613
+									'event_espresso'
3614
+								),
3615
+							)
3616
+						),
3617
+						'delete_threshold'            => new EE_Select_Input(
3618
+							array(
3619
+								0  => esc_html__('Forever', 'event_espresso'),
3620
+								3  => esc_html__('3 Months', 'event_espresso'),
3621
+								6  => esc_html__('6 Months', 'event_espresso'),
3622
+								9  => esc_html__('9 Months', 'event_espresso'),
3623
+								12 => esc_html__('12 Months', 'event_espresso'),
3624
+								24 => esc_html__('24 Months', 'event_espresso'),
3625
+								36 => esc_html__('36 Months', 'event_espresso'),
3626
+							),
3627
+							array(
3628
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3629
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3630
+								'html_help_text'  => esc_html__(
3631
+									'You can control how long a record of processed messages is kept via this option.',
3632
+									'event_espresso'
3633
+								),
3634
+							)
3635
+						),
3636
+						'update_settings'             => new EE_Submit_Input(
3637
+							array(
3638
+								'default'         => esc_html__('Update', 'event_espresso'),
3639
+								'html_label_text' => '&nbsp',
3640
+							)
3641
+						),
3642
+					)
3643
+				),
3644
+			)
3645
+		);
3646
+	}
3647
+
3648
+
3649
+	/**
3650
+	 * This handles updating the global settings set on the admin page.
3651
+	 *
3652
+	 * @throws EE_Error
3653
+	 * @throws InvalidDataTypeException
3654
+	 * @throws InvalidInterfaceException
3655
+	 * @throws InvalidArgumentException
3656
+	 * @throws ReflectionException
3657
+	 */
3658
+	protected function _update_global_settings()
3659
+	{
3660
+		/** @var EE_Network_Core_Config $network_config */
3661
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3662
+		$messages_config = EE_Registry::instance()->CFG->messages;
3663
+		$form = $this->_generate_global_settings_form();
3664
+		if ($form->was_submitted()) {
3665
+			$form->receive_form_submission();
3666
+			if ($form->is_valid()) {
3667
+				$valid_data = $form->valid_data();
3668
+				foreach ($valid_data as $property => $value) {
3669
+					$setter = 'set_' . $property;
3670
+					if (method_exists($network_config, $setter)) {
3671
+						$network_config->{$setter}($value);
3672
+					} elseif (property_exists($network_config, $property)
3673
+						&& $network_config->{$property} !== $value
3674
+					) {
3675
+						$network_config->{$property} = $value;
3676
+					} elseif (property_exists($messages_config, $property)
3677
+						&& $messages_config->{$property} !== $value
3678
+					) {
3679
+						$messages_config->{$property} = $value;
3680
+					}
3681
+				}
3682
+				// only update if the form submission was valid!
3683
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3684
+				EE_Registry::instance()->CFG->update_espresso_config();
3685
+				EE_Error::overwrite_success();
3686
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3687
+			}
3688
+		}
3689
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3690
+	}
3691
+
3692
+
3693
+	/**
3694
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3695
+	 *
3696
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3697
+	 * @return string html formatted tabs
3698
+	 * @throws DomainException
3699
+	 */
3700
+	protected function _get_mt_tabs($tab_array)
3701
+	{
3702
+		$tab_array = (array) $tab_array;
3703
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3704
+		$tabs = '';
3705
+
3706
+		foreach ($tab_array as $tab) {
3707
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3708
+		}
3709
+
3710
+		return $tabs;
3711
+	}
3712
+
3713
+
3714
+	/**
3715
+	 * This prepares the content of the messenger meta box admin settings
3716
+	 *
3717
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3718
+	 * @return string html formatted content
3719
+	 * @throws DomainException
3720
+	 */
3721
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3722
+	{
3723
+
3724
+		$fields = $messenger->get_admin_settings_fields();
3725
+		$settings_template_args['template_form_fields'] = '';
3726
+
3727
+		// is $messenger active?
3728
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3729
+
3730
+
3731
+		if (! empty($fields)) {
3732
+			$existing_settings = $messenger->get_existing_admin_settings();
3733
+
3734
+			foreach ($fields as $fldname => $fldprops) {
3735
+				$field_id = $messenger->name . '-' . $fldname;
3736
+				$template_form_field[ $field_id ] = array(
3737
+					'name'       => 'messenger_settings[' . $field_id . ']',
3738
+					'label'      => $fldprops['label'],
3739
+					'input'      => $fldprops['field_type'],
3740
+					'type'       => $fldprops['value_type'],
3741
+					'required'   => $fldprops['required'],
3742
+					'validation' => $fldprops['validation'],
3743
+					'value'      => isset($existing_settings[ $field_id ])
3744
+						? $existing_settings[ $field_id ]
3745
+						: $fldprops['default'],
3746
+					'css_class'  => '',
3747
+					'format'     => $fldprops['format'],
3748
+				);
3749
+			}
3750
+
3751
+
3752
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3753
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3754
+				: '';
3755
+		}
3756
+
3757
+		// we also need some hidden fields
3758
+		$settings_template_args['hidden_fields'] = array(
3759
+			'messenger_settings[messenger]' => array(
3760
+				'type'  => 'hidden',
3761
+				'value' => $messenger->name,
3762
+			),
3763
+			'type'                          => array(
3764
+				'type'  => 'hidden',
3765
+				'value' => 'messenger',
3766
+			),
3767
+		);
3768
+
3769
+		// make sure any active message types that are existing are included in the hidden fields
3770
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3771
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3772
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array(
3773
+					'type'  => 'hidden',
3774
+					'value' => $mt,
3775
+				);
3776
+			}
3777
+		}
3778
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3779
+			$settings_template_args['hidden_fields'],
3780
+			'array'
3781
+		);
3782
+		$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3783
+
3784
+		$settings_template_args['messenger'] = $messenger->name;
3785
+		$settings_template_args['description'] = $messenger->description;
3786
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3787
+
3788
+
3789
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3790
+			$messenger->name
3791
+		)
3792
+			? $settings_template_args['show_hide_edit_form']
3793
+			: ' hidden';
3794
+
3795
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3796
+			? ' hidden'
3797
+			: $settings_template_args['show_hide_edit_form'];
3798
+
3799
+
3800
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3801
+		$settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3802
+		$settings_template_args['on_off_status'] = $active ? true : false;
3803
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3804
+		$content = EEH_Template::display_template(
3805
+			$template,
3806
+			$settings_template_args,
3807
+			true
3808
+		);
3809
+
3810
+		return $content;
3811
+	}
3812
+
3813
+
3814
+	/**
3815
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3816
+	 *
3817
+	 * @throws DomainException
3818
+	 * @throws EE_Error
3819
+	 * @throws InvalidDataTypeException
3820
+	 * @throws InvalidInterfaceException
3821
+	 * @throws InvalidArgumentException
3822
+	 * @throws ReflectionException
3823
+	 */
3824
+	public function activate_messenger_toggle()
3825
+	{
3826
+		$success = true;
3827
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3828
+		// let's check that we have required data
3829
+		if (! isset($this->_req_data['messenger'])) {
3830
+			EE_Error::add_error(
3831
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3832
+				__FILE__,
3833
+				__FUNCTION__,
3834
+				__LINE__
3835
+			);
3836
+			$success = false;
3837
+		}
3838
+
3839
+		// do a nonce check here since we're not arriving via a normal route
3840
+		$nonce = isset($this->_req_data['activate_nonce'])
3841
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3842
+			: '';
3843
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3844
+
3845
+		$this->_verify_nonce($nonce, $nonce_ref);
3846
+
3847
+
3848
+		if (! isset($this->_req_data['status'])) {
3849
+			EE_Error::add_error(
3850
+				esc_html__(
3851
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3852
+					'event_espresso'
3853
+				),
3854
+				__FILE__,
3855
+				__FUNCTION__,
3856
+				__LINE__
3857
+			);
3858
+			$success = false;
3859
+		}
3860
+
3861
+		// do check to verify we have a valid status.
3862
+		$status = $this->_req_data['status'];
3863
+
3864
+		if ($status !== 'off' && $status !== 'on') {
3865
+			EE_Error::add_error(
3866
+				sprintf(
3867
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3868
+					$this->_req_data['status']
3869
+				),
3870
+				__FILE__,
3871
+				__FUNCTION__,
3872
+				__LINE__
3873
+			);
3874
+			$success = false;
3875
+		}
3876
+
3877
+		if ($success) {
3878
+			// made it here?  Stop dawdling then!!
3879
+			$success = $status === 'off'
3880
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3881
+				: $this->_activate_messenger($this->_req_data['messenger']);
3882
+		}
3883
+
3884
+		$this->_template_args['success'] = $success;
3885
+
3886
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
3887
+		$this->_return_json();
3888
+	}
3889
+
3890
+
3891
+	/**
3892
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3893
+	 *
3894
+	 * @throws DomainException
3895
+	 * @throws EE_Error
3896
+	 * @throws ReflectionException
3897
+	 * @throws InvalidDataTypeException
3898
+	 * @throws InvalidInterfaceException
3899
+	 * @throws InvalidArgumentException
3900
+	 */
3901
+	public function activate_mt_toggle()
3902
+	{
3903
+		$success = true;
3904
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3905
+
3906
+		// let's make sure we have the necessary data
3907
+		if (! isset($this->_req_data['message_type'])) {
3908
+			EE_Error::add_error(
3909
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3910
+				__FILE__,
3911
+				__FUNCTION__,
3912
+				__LINE__
3913
+			);
3914
+			$success = false;
3915
+		}
3916
+
3917
+		if (! isset($this->_req_data['messenger'])) {
3918
+			EE_Error::add_error(
3919
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3920
+				__FILE__,
3921
+				__FUNCTION__,
3922
+				__LINE__
3923
+			);
3924
+			$success = false;
3925
+		}
3926
+
3927
+		if (! isset($this->_req_data['status'])) {
3928
+			EE_Error::add_error(
3929
+				esc_html__(
3930
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3931
+					'event_espresso'
3932
+				),
3933
+				__FILE__,
3934
+				__FUNCTION__,
3935
+				__LINE__
3936
+			);
3937
+			$success = false;
3938
+		}
3939
+
3940
+
3941
+		// do check to verify we have a valid status.
3942
+		$status = $this->_req_data['status'];
3943
+
3944
+		if ($status !== 'activate' && $status !== 'deactivate') {
3945
+			EE_Error::add_error(
3946
+				sprintf(
3947
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3948
+					$this->_req_data['status']
3949
+				),
3950
+				__FILE__,
3951
+				__FUNCTION__,
3952
+				__LINE__
3953
+			);
3954
+			$success = false;
3955
+		}
3956
+
3957
+
3958
+		// do a nonce check here since we're not arriving via a normal route
3959
+		$nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3960
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3961
+
3962
+		$this->_verify_nonce($nonce, $nonce_ref);
3963
+
3964
+		if ($success) {
3965
+			// made it here? um, what are you waiting for then?
3966
+			$success = $status === 'deactivate'
3967
+				? $this->_deactivate_message_type_for_messenger(
3968
+					$this->_req_data['messenger'],
3969
+					$this->_req_data['message_type']
3970
+				)
3971
+				: $this->_activate_message_type_for_messenger(
3972
+					$this->_req_data['messenger'],
3973
+					$this->_req_data['message_type']
3974
+				);
3975
+		}
3976
+
3977
+		$this->_template_args['success'] = $success;
3978
+		$this->_return_json();
3979
+	}
3980
+
3981
+
3982
+	/**
3983
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3984
+	 *
3985
+	 * @param string $messenger_name The name of the messenger being activated
3986
+	 * @return bool
3987
+	 * @throws DomainException
3988
+	 * @throws EE_Error
3989
+	 * @throws InvalidArgumentException
3990
+	 * @throws ReflectionException
3991
+	 * @throws InvalidDataTypeException
3992
+	 * @throws InvalidInterfaceException
3993
+	 */
3994
+	protected function _activate_messenger($messenger_name)
3995
+	{
3996
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3997
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3998
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3999
+			? $active_messenger->get_default_message_types()
4000
+			: array();
4001
+
4002
+		// ensure is active
4003
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4004
+
4005
+		// set response_data for reload
4006
+		foreach ($message_types_to_activate as $message_type_name) {
4007
+			/** @var EE_message_type $message_type */
4008
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4009
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger(
4010
+				$messenger_name,
4011
+				$message_type_name
4012
+			)
4013
+				&& $message_type instanceof EE_message_type
4014
+			) {
4015
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4016
+				if ($message_type->get_admin_settings_fields()) {
4017
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4018
+				}
4019
+			}
4020
+		}
4021
+
4022
+		// add success message for activating messenger
4023
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4024
+	}
4025
+
4026
+
4027
+	/**
4028
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4029
+	 *
4030
+	 * @param string $messenger_name The name of the messenger being activated
4031
+	 * @return bool
4032
+	 * @throws DomainException
4033
+	 * @throws EE_Error
4034
+	 * @throws InvalidArgumentException
4035
+	 * @throws ReflectionException
4036
+	 * @throws InvalidDataTypeException
4037
+	 * @throws InvalidInterfaceException
4038
+	 */
4039
+	protected function _deactivate_messenger($messenger_name)
4040
+	{
4041
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4042
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4043
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4044
+
4045
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4046
+	}
4047
+
4048
+
4049
+	/**
4050
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4051
+	 *
4052
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4053
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4054
+	 * @return bool
4055
+	 * @throws DomainException
4056
+	 * @throws EE_Error
4057
+	 * @throws InvalidArgumentException
4058
+	 * @throws ReflectionException
4059
+	 * @throws InvalidDataTypeException
4060
+	 * @throws InvalidInterfaceException
4061
+	 */
4062
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4063
+	{
4064
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4065
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4066
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4067
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4068
+
4069
+		// ensure is active
4070
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4071
+
4072
+		// set response for load
4073
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger(
4074
+			$messenger_name,
4075
+			$message_type_name
4076
+		)
4077
+		) {
4078
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4079
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4080
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4081
+			}
4082
+		}
4083
+
4084
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4085
+			$active_messenger,
4086
+			$message_type_to_activate
4087
+		);
4088
+	}
4089
+
4090
+
4091
+	/**
4092
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4093
+	 *
4094
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4095
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4096
+	 * @return bool
4097
+	 * @throws DomainException
4098
+	 * @throws EE_Error
4099
+	 * @throws InvalidArgumentException
4100
+	 * @throws ReflectionException
4101
+	 * @throws InvalidDataTypeException
4102
+	 * @throws InvalidInterfaceException
4103
+	 */
4104
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4105
+	{
4106
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4107
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4108
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4109
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4110
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4111
+
4112
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4113
+			$active_messenger,
4114
+			$message_type_to_deactivate
4115
+		);
4116
+	}
4117
+
4118
+
4119
+	/**
4120
+	 * This just initializes the defaults for activating messenger and message type responses.
4121
+	 */
4122
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4123
+	{
4124
+		$this->_template_args['data']['active_mts'] = array();
4125
+		$this->_template_args['data']['mt_reload'] = array();
4126
+	}
4127
+
4128
+
4129
+	/**
4130
+	 * Setup appropriate response for activating a messenger and/or message types
4131
+	 *
4132
+	 * @param EE_messenger         $messenger
4133
+	 * @param EE_message_type|null $message_type
4134
+	 * @return bool
4135
+	 * @throws DomainException
4136
+	 * @throws EE_Error
4137
+	 * @throws InvalidArgumentException
4138
+	 * @throws ReflectionException
4139
+	 * @throws InvalidDataTypeException
4140
+	 * @throws InvalidInterfaceException
4141
+	 */
4142
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4143
+		$messenger,
4144
+		EE_Message_Type $message_type = null
4145
+	) {
4146
+		// if $messenger isn't a valid messenger object then get out.
4147
+		if (! $messenger instanceof EE_Messenger) {
4148
+			EE_Error::add_error(
4149
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4150
+				__FILE__,
4151
+				__FUNCTION__,
4152
+				__LINE__
4153
+			);
4154
+
4155
+			return false;
4156
+		}
4157
+		// activated
4158
+		if ($this->_template_args['data']['active_mts']) {
4159
+			EE_Error::overwrite_success();
4160
+			// activated a message type with the messenger
4161
+			if ($message_type instanceof EE_message_type) {
4162
+				EE_Error::add_success(
4163
+					sprintf(
4164
+						esc_html__(
4165
+							'%s message type has been successfully activated with the %s messenger',
4166
+							'event_espresso'
4167
+						),
4168
+						ucwords($message_type->label['singular']),
4169
+						ucwords($messenger->label['singular'])
4170
+					)
4171
+				);
4172
+
4173
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4174
+				if ($message_type->name === 'invoice') {
4175
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4176
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4177
+					if ($pm instanceof EE_Payment_Method) {
4178
+						EE_Error::add_attention(
4179
+							esc_html__(
4180
+								'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.',
4181
+								'event_espresso'
4182
+							)
4183
+						);
4184
+					}
4185
+				}
4186
+				// just toggles the entire messenger
4187
+			} else {
4188
+				EE_Error::add_success(
4189
+					sprintf(
4190
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4191
+						ucwords($messenger->label['singular'])
4192
+					)
4193
+				);
4194
+			}
4195
+
4196
+			return true;
4197
+
4198
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4199
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4200
+			// in which case we just give a success message for the messenger being successfully activated.
4201
+		} else {
4202
+			if (! $messenger->get_default_message_types()) {
4203
+				// messenger doesn't have any default message types so still a success.
4204
+				EE_Error::add_success(
4205
+					sprintf(
4206
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4207
+						ucwords($messenger->label['singular'])
4208
+					)
4209
+				);
4210
+
4211
+				return true;
4212
+			} else {
4213
+				EE_Error::add_error(
4214
+					$message_type instanceof EE_message_type
4215
+						? sprintf(
4216
+							esc_html__(
4217
+								'%s message type was not successfully activated with the %s messenger',
4218
+								'event_espresso'
4219
+							),
4220
+							ucwords($message_type->label['singular']),
4221
+							ucwords($messenger->label['singular'])
4222
+						)
4223
+						: sprintf(
4224
+							esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4225
+							ucwords($messenger->label['singular'])
4226
+						),
4227
+					__FILE__,
4228
+					__FUNCTION__,
4229
+					__LINE__
4230
+				);
4231
+
4232
+				return false;
4233
+			}
4234
+		}
4235
+	}
4236
+
4237
+
4238
+	/**
4239
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4240
+	 *
4241
+	 * @param EE_messenger         $messenger
4242
+	 * @param EE_message_type|null $message_type
4243
+	 * @return bool
4244
+	 * @throws DomainException
4245
+	 * @throws EE_Error
4246
+	 * @throws InvalidArgumentException
4247
+	 * @throws ReflectionException
4248
+	 * @throws InvalidDataTypeException
4249
+	 * @throws InvalidInterfaceException
4250
+	 */
4251
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4252
+		$messenger,
4253
+		EE_message_type $message_type = null
4254
+	) {
4255
+		EE_Error::overwrite_success();
4256
+
4257
+		// if $messenger isn't a valid messenger object then get out.
4258
+		if (! $messenger instanceof EE_Messenger) {
4259
+			EE_Error::add_error(
4260
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4261
+				__FILE__,
4262
+				__FUNCTION__,
4263
+				__LINE__
4264
+			);
4265
+
4266
+			return false;
4267
+		}
4268
+
4269
+		if ($message_type instanceof EE_message_type) {
4270
+			$message_type_name = $message_type->name;
4271
+			EE_Error::add_success(
4272
+				sprintf(
4273
+					esc_html__(
4274
+						'%s message type has been successfully deactivated for the %s messenger.',
4275
+						'event_espresso'
4276
+					),
4277
+					ucwords($message_type->label['singular']),
4278
+					ucwords($messenger->label['singular'])
4279
+				)
4280
+			);
4281
+		} else {
4282
+			$message_type_name = '';
4283
+			EE_Error::add_success(
4284
+				sprintf(
4285
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4286
+					ucwords($messenger->label['singular'])
4287
+				)
4288
+			);
4289
+		}
4290
+
4291
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4292
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4293
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4294
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4295
+			if ($count_updated > 0) {
4296
+				$msg = $message_type_name === 'invoice'
4297
+					? esc_html__(
4298
+						'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.',
4299
+						'event_espresso'
4300
+					)
4301
+					: esc_html__(
4302
+						'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.',
4303
+						'event_espresso'
4304
+					);
4305
+				EE_Error::add_attention($msg);
4306
+			}
4307
+		}
4308
+
4309
+		return true;
4310
+	}
4311
+
4312
+
4313
+	/**
4314
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4315
+	 *
4316
+	 * @throws DomainException
4317
+	 */
4318
+	public function update_mt_form()
4319
+	{
4320
+		if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4321
+			EE_Error::add_error(
4322
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4323
+				__FILE__,
4324
+				__FUNCTION__,
4325
+				__LINE__
4326
+			);
4327
+			$this->_return_json();
4328
+		}
4329
+
4330
+		$message_types = $this->get_installed_message_types();
4331
+
4332
+		$message_type = $message_types[ $this->_req_data['message_type'] ];
4333
+		$messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4334
+
4335
+		$content = $this->_message_type_settings_content(
4336
+			$message_type,
4337
+			$messenger,
4338
+			true
4339
+		);
4340
+		$this->_template_args['success'] = true;
4341
+		$this->_template_args['content'] = $content;
4342
+		$this->_return_json();
4343
+	}
4344
+
4345
+
4346
+	/**
4347
+	 * this handles saving the settings for a messenger or message type
4348
+	 *
4349
+	 */
4350
+	public function save_settings()
4351
+	{
4352
+		if (! isset($this->_req_data['type'])) {
4353
+			EE_Error::add_error(
4354
+				esc_html__(
4355
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4356
+					'event_espresso'
4357
+				),
4358
+				__FILE__,
4359
+				__FUNCTION__,
4360
+				__LINE__
4361
+			);
4362
+			$this->_template_args['error'] = true;
4363
+			$this->_return_json();
4364
+		}
4365
+
4366
+
4367
+		if ($this->_req_data['type'] === 'messenger') {
4368
+			// this should be an array.
4369
+			$settings = $this->_req_data['messenger_settings'];
4370
+			$messenger = $settings['messenger'];
4371
+			// let's setup the settings data
4372
+			foreach ($settings as $key => $value) {
4373
+				switch ($key) {
4374
+					case 'messenger':
4375
+						unset($settings['messenger']);
4376
+						break;
4377
+					case 'message_types':
4378
+						unset($settings['message_types']);
4379
+						break;
4380
+					default:
4381
+						$settings[ $key ] = $value;
4382
+						break;
4383
+				}
4384
+			}
4385
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4386
+		} elseif ($this->_req_data['type'] === 'message_type') {
4387
+			$settings = $this->_req_data['message_type_settings'];
4388
+			$messenger = $settings['messenger'];
4389
+			$message_type = $settings['message_type'];
4390
+
4391
+			foreach ($settings as $key => $value) {
4392
+				switch ($key) {
4393
+					case 'messenger':
4394
+						unset($settings['messenger']);
4395
+						break;
4396
+					case 'message_type':
4397
+						unset($settings['message_type']);
4398
+						break;
4399
+					default:
4400
+						$settings[ $key ] = $value;
4401
+						break;
4402
+				}
4403
+			}
4404
+
4405
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4406
+		}
4407
+
4408
+		// okay we should have the data all setup.  Now we just update!
4409
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4410
+
4411
+		if ($success) {
4412
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
4413
+		} else {
4414
+			EE_Error::add_error(
4415
+				esc_html__(
4416
+					'Settings did not get updated',
4417
+					'event_espresso'
4418
+				),
4419
+				__FILE__,
4420
+				__FUNCTION__,
4421
+				__LINE__
4422
+			);
4423
+		}
4424
+
4425
+		$this->_template_args['success'] = $success;
4426
+		$this->_return_json();
4427
+	}
4428
+
4429
+
4430
+
4431
+
4432
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4433
+
4434
+
4435
+	/**
4436
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4437
+	 * However, this does not send immediately, it just queues for sending.
4438
+	 *
4439
+	 * @since 4.9.0
4440
+	 * @throws EE_Error
4441
+	 * @throws InvalidDataTypeException
4442
+	 * @throws InvalidInterfaceException
4443
+	 * @throws InvalidArgumentException
4444
+	 * @throws ReflectionException
4445
+	 */
4446
+	protected function _generate_now()
4447
+	{
4448
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4449
+		$this->_redirect_after_action(false, '', '', array(), true);
4450
+	}
4451
+
4452
+
4453
+	/**
4454
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4455
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4456
+	 *
4457
+	 * @since 4.9.0
4458
+	 * @throws EE_Error
4459
+	 * @throws InvalidDataTypeException
4460
+	 * @throws InvalidInterfaceException
4461
+	 * @throws InvalidArgumentException
4462
+	 * @throws ReflectionException
4463
+	 */
4464
+	protected function _generate_and_send_now()
4465
+	{
4466
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4467
+		$this->_redirect_after_action(false, '', '', array(), true);
4468
+	}
4469
+
4470
+
4471
+	/**
4472
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4473
+	 *
4474
+	 * @since 4.9.0
4475
+	 * @throws EE_Error
4476
+	 * @throws InvalidDataTypeException
4477
+	 * @throws InvalidInterfaceException
4478
+	 * @throws InvalidArgumentException
4479
+	 * @throws ReflectionException
4480
+	 */
4481
+	protected function _queue_for_resending()
4482
+	{
4483
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4484
+		$this->_redirect_after_action(false, '', '', array(), true);
4485
+	}
4486
+
4487
+
4488
+	/**
4489
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4490
+	 *
4491
+	 * @since 4.9.0
4492
+	 * @throws EE_Error
4493
+	 * @throws InvalidDataTypeException
4494
+	 * @throws InvalidInterfaceException
4495
+	 * @throws InvalidArgumentException
4496
+	 * @throws ReflectionException
4497
+	 */
4498
+	protected function _send_now()
4499
+	{
4500
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4501
+		$this->_redirect_after_action(false, '', '', array(), true);
4502
+	}
4503
+
4504
+
4505
+	/**
4506
+	 * Deletes EE_messages for IDs in the request.
4507
+	 *
4508
+	 * @since 4.9.0
4509
+	 * @throws EE_Error
4510
+	 * @throws InvalidDataTypeException
4511
+	 * @throws InvalidInterfaceException
4512
+	 * @throws InvalidArgumentException
4513
+	 */
4514
+	protected function _delete_ee_messages()
4515
+	{
4516
+		$msg_ids = $this->_get_msg_ids_from_request();
4517
+		$deleted_count = 0;
4518
+		foreach ($msg_ids as $msg_id) {
4519
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4520
+				$deleted_count++;
4521
+			}
4522
+		}
4523
+		if ($deleted_count) {
4524
+			EE_Error::add_success(
4525
+				esc_html(
4526
+					_n(
4527
+						'Message successfully deleted',
4528
+						'Messages successfully deleted',
4529
+						$deleted_count,
4530
+						'event_espresso'
4531
+					)
4532
+				)
4533
+			);
4534
+			$this->_redirect_after_action(
4535
+				false,
4536
+				'',
4537
+				'',
4538
+				array(),
4539
+				true
4540
+			);
4541
+		} else {
4542
+			EE_Error::add_error(
4543
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4544
+				__FILE__,
4545
+				__FUNCTION__,
4546
+				__LINE__
4547
+			);
4548
+			$this->_redirect_after_action(false, '', '', array(), true);
4549
+		}
4550
+	}
4551
+
4552
+
4553
+	/**
4554
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4555
+	 *
4556
+	 * @since 4.9.0
4557
+	 * @return array
4558
+	 */
4559
+	protected function _get_msg_ids_from_request()
4560
+	{
4561
+		if (! isset($this->_req_data['MSG_ID'])) {
4562
+			return array();
4563
+		}
4564
+
4565
+		return is_array($this->_req_data['MSG_ID'])
4566
+			? array_keys($this->_req_data['MSG_ID'])
4567
+			: array($this->_req_data['MSG_ID']);
4568
+	}
4569 4569
 }
Please login to merge, or discard this patch.
Spacing   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
         $i = 1;
143 143
         foreach ($active_messengers as $active_messenger) {
144 144
             if ($active_messenger instanceof EE_Message) {
145
-                $m_values[ $i ]['id'] = $active_messenger->messenger();
146
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
145
+                $m_values[$i]['id'] = $active_messenger->messenger();
146
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
147 147
                 $i++;
148 148
             }
149 149
         }
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
         $i = 1;
180 180
         foreach ($active_messages as $active_message) {
181 181
             if ($active_message instanceof EE_Message) {
182
-                $mt_values[ $i ]['id'] = $active_message->message_type();
183
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
182
+                $mt_values[$i]['id'] = $active_message->message_type();
183
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
184 184
                 $i++;
185 185
             }
186 186
         }
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                 if ($message_type instanceof EE_message_type) {
220 220
                     $message_type_contexts = $message_type->get_contexts();
221 221
                     foreach ($message_type_contexts as $context => $context_details) {
222
-                        $contexts[ $context ] = $context_details['label'];
222
+                        $contexts[$context] = $context_details['label'];
223 223
                     }
224 224
                 }
225 225
             }
@@ -714,53 +714,53 @@  discard block
 block discarded – undo
714 714
 
715 715
     public function messages_help_tab()
716 716
     {
717
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
717
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
718 718
     }
719 719
 
720 720
 
721 721
     public function messengers_help_tab()
722 722
     {
723
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
723
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
724 724
     }
725 725
 
726 726
 
727 727
     public function message_types_help_tab()
728 728
     {
729
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
729
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
730 730
     }
731 731
 
732 732
 
733 733
     public function messages_overview_help_tab()
734 734
     {
735
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
735
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
736 736
     }
737 737
 
738 738
 
739 739
     public function message_templates_help_tab()
740 740
     {
741
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
741
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
742 742
     }
743 743
 
744 744
 
745 745
     public function edit_message_template_help_tab()
746 746
     {
747
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
747
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
748 748
                         . esc_attr__('Editor Title', 'event_espresso')
749 749
                         . '" />';
750
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
750
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
751 751
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
752 752
                         . '" />';
753
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
753
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
754 754
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
755 755
                         . '" />';
756
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
756
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
757 757
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
758 758
                         . '" />';
759
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
759
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
760 760
                         . esc_attr__('Publish Metabox', 'event_espresso')
761 761
                         . '" />';
762 762
         EEH_Template::display_template(
763
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
763
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
764 764
             $args
765 765
         );
766 766
     }
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
         $this->_set_shortcodes();
772 772
         $args['shortcodes'] = $this->_shortcodes;
773 773
         EEH_Template::display_template(
774
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
774
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
775 775
             $args
776 776
         );
777 777
     }
@@ -779,16 +779,16 @@  discard block
 block discarded – undo
779 779
 
780 780
     public function preview_message_help_tab()
781 781
     {
782
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
782
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
783 783
     }
784 784
 
785 785
 
786 786
     public function settings_help_tab()
787 787
     {
788
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
789
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
790
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
791
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
788
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
789
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
790
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
791
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
792 792
         $args['img3'] = '<div class="switch">'
793 793
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
794 794
                         . ' type="checkbox" checked="checked">'
@@ -799,25 +799,25 @@  discard block
 block discarded – undo
799 799
                         . ' type="checkbox">'
800 800
                         . '<label for="ee-on-off-toggle-on"></label>'
801 801
                         . '</div>';
802
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
802
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
803 803
     }
804 804
 
805 805
 
806 806
     public function load_scripts_styles()
807 807
     {
808
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
808
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
809 809
         wp_enqueue_style('espresso_ee_msg');
810 810
 
811 811
         wp_register_script(
812 812
             'ee-messages-settings',
813
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
813
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
814 814
             array('jquery-ui-droppable', 'ee-serialize-full-array'),
815 815
             EVENT_ESPRESSO_VERSION,
816 816
             true
817 817
         );
818 818
         wp_register_script(
819 819
             'ee-msg-list-table-js',
820
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
820
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
821 821
             array('ee-dialog'),
822 822
             EVENT_ESPRESSO_VERSION
823 823
         );
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
 
876 876
         wp_register_script(
877 877
             'ee_msgs_edit_js',
878
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
878
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
879 879
             array('jquery'),
880 880
             EVENT_ESPRESSO_VERSION
881 881
         );
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
     {
920 920
         wp_register_style(
921 921
             'ee-message-settings',
922
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
922
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
923 923
             array(),
924 924
             EVENT_ESPRESSO_VERSION
925 925
         );
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
             }
1006 1006
             $status_bulk_actions = $common_bulk_actions;
1007 1007
             // unset bulk actions not applying to status
1008
-            if (! empty($status_bulk_actions)) {
1008
+            if ( ! empty($status_bulk_actions)) {
1009 1009
                 switch ($status) {
1010 1010
                     case EEM_Message::status_idle:
1011 1011
                     case EEM_Message::status_resend:
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
                 continue;
1035 1035
             }
1036 1036
 
1037
-            $this->_views[ strtolower($status) ] = array(
1037
+            $this->_views[strtolower($status)] = array(
1038 1038
                 'slug'        => strtolower($status),
1039 1039
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1040 1040
                 'count'       => 0,
@@ -1073,7 +1073,7 @@  discard block
 block discarded – undo
1073 1073
             if ($action_item === 'see_notifications_for') {
1074 1074
                 continue;
1075 1075
             }
1076
-            $action_items[ $action_item ] = array(
1076
+            $action_items[$action_item] = array(
1077 1077
                 'class' => $action_details['css_class'],
1078 1078
                 'desc'  => $action_details['label'],
1079 1079
             );
@@ -1082,37 +1082,37 @@  discard block
 block discarded – undo
1082 1082
         /** @type array $status_items status legend setup */
1083 1083
         $status_items = array(
1084 1084
             'sent_status'                => array(
1085
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1085
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1086 1086
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1087 1087
             ),
1088 1088
             'idle_status'                => array(
1089
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1089
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1090 1090
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1091 1091
             ),
1092 1092
             'failed_status'              => array(
1093
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1093
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1094 1094
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1095 1095
             ),
1096 1096
             'messenger_executing_status' => array(
1097
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1097
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1098 1098
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1099 1099
             ),
1100 1100
             'resend_status'              => array(
1101
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1101
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1102 1102
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1103 1103
             ),
1104 1104
             'incomplete_status'          => array(
1105
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1105
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1106 1106
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1107 1107
             ),
1108 1108
             'retry_status'               => array(
1109
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1109
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1110 1110
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1111 1111
             ),
1112 1112
         );
1113 1113
         if (EEM_Message::debug()) {
1114 1114
             $status_items['debug_only_status'] = array(
1115
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1115
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1116 1116
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1117 1117
             );
1118 1118
         }
@@ -1124,11 +1124,11 @@  discard block
 block discarded – undo
1124 1124
     protected function _custom_mtps_preview()
1125 1125
     {
1126 1126
         $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1127
-        $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1128
-                                               . ' alt="' . esc_attr__(
1127
+        $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1128
+                                               . ' alt="'.esc_attr__(
1129 1129
                                                    'Preview Custom Message Templates screenshot',
1130 1130
                                                    'event_espresso'
1131
-                                               ) . '" />';
1131
+                                               ).'" />';
1132 1132
         $this->_template_args['preview_text'] = '<strong>'
1133 1133
                                                 . esc_html__(
1134 1134
                                                     '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.',
@@ -1208,7 +1208,7 @@  discard block
 block discarded – undo
1208 1208
         $installed = array();
1209 1209
 
1210 1210
         foreach ($installed_message_types as $message_type) {
1211
-            $installed[ $message_type->name ] = $message_type;
1211
+            $installed[$message_type->name] = $message_type;
1212 1212
         }
1213 1213
 
1214 1214
         return $installed;
@@ -1348,7 +1348,7 @@  discard block
 block discarded – undo
1348 1348
         // we need to assemble the title from Various details
1349 1349
         $context_label = sprintf(
1350 1350
             esc_html__('(%s %s)', 'event_espresso'),
1351
-            $c_config[ $context ]['label'],
1351
+            $c_config[$context]['label'],
1352 1352
             ucwords($c_label['label'])
1353 1353
         );
1354 1354
 
@@ -1370,7 +1370,7 @@  discard block
 block discarded – undo
1370 1370
             $message_template_group->message_type()
1371 1371
         );
1372 1372
 
1373
-        if (! $template_field_structure) {
1373
+        if ( ! $template_field_structure) {
1374 1374
             $template_field_structure = false;
1375 1375
             $template_fields = esc_html__(
1376 1376
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1384,21 +1384,21 @@  discard block
 block discarded – undo
1384 1384
 
1385 1385
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1386 1386
         // will get handled in the "extra" array.
1387
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1388
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1389
-                unset($template_field_structure[ $context ][ $reference_field ]);
1387
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1388
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1389
+                unset($template_field_structure[$context][$reference_field]);
1390 1390
             }
1391 1391
         }
1392 1392
 
1393 1393
         // let's loop through the template_field_structure and actually assemble the input fields!
1394
-        if (! empty($template_field_structure)) {
1395
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1394
+        if ( ! empty($template_field_structure)) {
1395
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1396 1396
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1397 1397
                 // the extra array and reset them.
1398 1398
                 if ($template_field === 'extra') {
1399 1399
                     $this->_template_args['is_extra_fields'] = true;
1400 1400
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1401
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1401
+                        $message_template = $message_templates[$context][$reference_field];
1402 1402
                         $content = $message_template instanceof EE_Message_Template
1403 1403
                             ? $message_template->get('MTP_content')
1404 1404
                             : '';
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
                             $continue = false;
1408 1408
                             if (isset($extra_array['shortcodes_required'])) {
1409 1409
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1410
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1410
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1411 1411
                                         $continue = true;
1412 1412
                                     }
1413 1413
                                 }
@@ -1420,57 +1420,57 @@  discard block
 block discarded – undo
1420 1420
                                         . '-'
1421 1421
                                         . $extra_field
1422 1422
                                         . '-content';
1423
-                            $template_form_fields[ $field_id ] = $extra_array;
1424
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1423
+                            $template_form_fields[$field_id] = $extra_array;
1424
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1425 1425
                                                                          . $reference_field
1426 1426
                                                                          . '][content]['
1427
-                                                                         . $extra_field . ']';
1427
+                                                                         . $extra_field.']';
1428 1428
                             $css_class = isset($extra_array['css_class'])
1429 1429
                                 ? $extra_array['css_class']
1430 1430
                                 : '';
1431 1431
 
1432
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1432
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1433 1433
                                                                               && in_array($extra_field, $v_fields, true)
1434 1434
                                                                               &&
1435 1435
                                                                               (
1436
-                                                                                  is_array($validators[ $extra_field ])
1437
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1436
+                                                                                  is_array($validators[$extra_field])
1437
+                                                                                  && isset($validators[$extra_field]['msg'])
1438 1438
                                                                               )
1439
-                                ? 'validate-error ' . $css_class
1439
+                                ? 'validate-error '.$css_class
1440 1440
                                 : $css_class;
1441 1441
 
1442
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1443
-                                                                          && isset($content[ $extra_field ])
1444
-                                ? $content[ $extra_field ]
1442
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1443
+                                                                          && isset($content[$extra_field])
1444
+                                ? $content[$extra_field]
1445 1445
                                 : '';
1446 1446
 
1447 1447
                             // do we have a validation error?  if we do then let's use that value instead
1448
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1449
-                                ? $validators[ $extra_field ]['value']
1450
-                                : $template_form_fields[ $field_id ]['value'];
1448
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1449
+                                ? $validators[$extra_field]['value']
1450
+                                : $template_form_fields[$field_id]['value'];
1451 1451
 
1452 1452
 
1453
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1453
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1454 1454
 
1455 1455
                             // shortcode selector
1456 1456
                             $field_name_to_use = $extra_field === 'main'
1457 1457
                                 ? 'content'
1458 1458
                                 : $extra_field;
1459
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1459
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1460 1460
                                 $field_name_to_use,
1461 1461
                                 $field_id
1462 1462
                             );
1463 1463
 
1464 1464
                             if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1465 1465
                                 // we want to decode the entities
1466
-                                $template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value'];
1466
+                                $template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value'];
1467 1467
                             }/**/
1468 1468
                         }
1469
-                        $templatefield_MTP_id = $reference_field . '-MTP_ID';
1470
-                        $templatefield_templatename_id = $reference_field . '-name';
1469
+                        $templatefield_MTP_id = $reference_field.'-MTP_ID';
1470
+                        $templatefield_templatename_id = $reference_field.'-name';
1471 1471
 
1472
-                        $template_form_fields[ $templatefield_MTP_id ] = array(
1473
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1472
+                        $template_form_fields[$templatefield_MTP_id] = array(
1473
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1474 1474
                             'label'      => null,
1475 1475
                             'input'      => 'hidden',
1476 1476
                             'type'       => 'int',
@@ -1482,8 +1482,8 @@  discard block
 block discarded – undo
1482 1482
                             'db-col'     => 'MTP_ID',
1483 1483
                         );
1484 1484
 
1485
-                        $template_form_fields[ $templatefield_templatename_id ] = array(
1486
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1485
+                        $template_form_fields[$templatefield_templatename_id] = array(
1486
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1487 1487
                             'label'      => null,
1488 1488
                             'input'      => 'hidden',
1489 1489
                             'type'       => 'string',
@@ -1497,36 +1497,36 @@  discard block
 block discarded – undo
1497 1497
                     }
1498 1498
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1499 1499
                 } else {
1500
-                    $field_id = $template_field . '-content';
1501
-                    $template_form_fields[ $field_id ] = $field_setup_array;
1502
-                    $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]';
1503
-                    $message_template = isset($message_templates[ $context ][ $template_field ])
1504
-                        ? $message_templates[ $context ][ $template_field ]
1500
+                    $field_id = $template_field.'-content';
1501
+                    $template_form_fields[$field_id] = $field_setup_array;
1502
+                    $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]';
1503
+                    $message_template = isset($message_templates[$context][$template_field])
1504
+                        ? $message_templates[$context][$template_field]
1505 1505
                         : null;
1506
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1507
-                                                                  && is_array($message_templates[ $context ])
1506
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1507
+                                                                  && is_array($message_templates[$context])
1508 1508
                                                                   && $message_template instanceof EE_Message_Template
1509 1509
                         ? $message_template->get('MTP_content')
1510 1510
                         : '';
1511 1511
 
1512 1512
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1513
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1514
-                        ? $validators[ $template_field ]['value']
1515
-                        : $template_form_fields[ $field_id ]['value'];
1513
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1514
+                        ? $validators[$template_field]['value']
1515
+                        : $template_form_fields[$field_id]['value'];
1516 1516
 
1517 1517
 
1518
-                    $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1518
+                    $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1519 1519
                     $css_class = isset($field_setup_array['css_class'])
1520 1520
                         ? $field_setup_array['css_class']
1521 1521
                         : '';
1522
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1522
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1523 1523
                                                                       && in_array($template_field, $v_fields, true)
1524
-                                                                      && isset($validators[ $template_field ]['msg'])
1525
-                        ? 'validate-error ' . $css_class
1524
+                                                                      && isset($validators[$template_field]['msg'])
1525
+                        ? 'validate-error '.$css_class
1526 1526
                         : $css_class;
1527 1527
 
1528 1528
                     // shortcode selector
1529
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1529
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1530 1530
                         $template_field,
1531 1531
                         $field_id
1532 1532
                     );
@@ -1534,12 +1534,12 @@  discard block
 block discarded – undo
1534 1534
 
1535 1535
                 // k took care of content field(s) now let's take care of others.
1536 1536
 
1537
-                $templatefield_MTP_id = $template_field . '-MTP_ID';
1538
-                $templatefield_field_templatename_id = $template_field . '-name';
1537
+                $templatefield_MTP_id = $template_field.'-MTP_ID';
1538
+                $templatefield_field_templatename_id = $template_field.'-name';
1539 1539
 
1540 1540
                 // foreach template field there are actually two form fields created
1541
-                $template_form_fields[ $templatefield_MTP_id ] = array(
1542
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1541
+                $template_form_fields[$templatefield_MTP_id] = array(
1542
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1543 1543
                     'label'      => null,
1544 1544
                     'input'      => 'hidden',
1545 1545
                     'type'       => 'int',
@@ -1551,8 +1551,8 @@  discard block
 block discarded – undo
1551 1551
                     'db-col'     => 'MTP_ID',
1552 1552
                 );
1553 1553
 
1554
-                $template_form_fields[ $templatefield_field_templatename_id ] = array(
1555
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1554
+                $template_form_fields[$templatefield_field_templatename_id] = array(
1555
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1556 1556
                     'label'      => null,
1557 1557
                     'input'      => 'hidden',
1558 1558
                     'type'       => 'string',
@@ -1695,10 +1695,10 @@  discard block
 block discarded – undo
1695 1695
                 'value' => $GRP_ID,
1696 1696
             );
1697 1697
             $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1698
-                'name'  => $action . '_nonce',
1698
+                'name'  => $action.'_nonce',
1699 1699
                 'input' => 'hidden',
1700 1700
                 'type'  => 'string',
1701
-                'value' => wp_create_nonce($action . '_nonce'),
1701
+                'value' => wp_create_nonce($action.'_nonce'),
1702 1702
             );
1703 1703
 
1704 1704
             if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
@@ -1739,7 +1739,7 @@  discard block
 block discarded – undo
1739 1739
             ),
1740 1740
             $this->_admin_base_url
1741 1741
         );
1742
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1742
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1743 1743
                           . esc_html__('Preview', 'event_espresso')
1744 1744
                           . '</a>';
1745 1745
 
@@ -1777,7 +1777,7 @@  discard block
 block discarded – undo
1777 1777
 
1778 1778
         $this->_template_path = $this->_template_args['GRP_ID']
1779 1779
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1780
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1780
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1781 1781
 
1782 1782
         // send along EE_Message_Template_Group object for further template use.
1783 1783
         $this->_template_args['MTP'] = $message_template_group;
@@ -1832,7 +1832,7 @@  discard block
 block discarded – undo
1832 1832
     ) {
1833 1833
         $template_args = array(
1834 1834
             'context'                   => $context,
1835
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1835
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1836 1836
             'is_active'                 => $message_template_group->is_context_active($context),
1837 1837
             'on_off_action'             => $message_template_group->is_context_active($context)
1838 1838
                 ? 'context-off'
@@ -1841,7 +1841,7 @@  discard block
 block discarded – undo
1841 1841
             'message_template_group_id' => $message_template_group->ID(),
1842 1842
         );
1843 1843
         return EEH_Template::display_template(
1844
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1844
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1845 1845
             $template_args,
1846 1846
             true
1847 1847
         );
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
     {
1863 1863
         $success = true;
1864 1864
         // check for required data
1865
-        if (! isset(
1865
+        if ( ! isset(
1866 1866
             $this->_req_data['message_template_group_id'],
1867 1867
             $this->_req_data['context'],
1868 1868
             $this->_req_data['status']
@@ -1879,7 +1879,7 @@  discard block
 block discarded – undo
1879 1879
         $nonce = isset($this->_req_data['toggle_context_nonce'])
1880 1880
             ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1881 1881
             : '';
1882
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1882
+        $nonce_ref = 'activate_'.$this->_req_data['context'].'_toggle_nonce';
1883 1883
         $this->_verify_nonce($nonce, $nonce_ref);
1884 1884
         $status = $this->_req_data['status'];
1885 1885
         if ($status !== 'off' && $status !== 'on') {
@@ -1897,7 +1897,7 @@  discard block
 block discarded – undo
1897 1897
         $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1898 1898
             $this->_req_data['message_template_group_id']
1899 1899
         );
1900
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1900
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1901 1901
             EE_Error::add_error(
1902 1902
                 sprintf(
1903 1903
                     esc_html__(
@@ -2026,7 +2026,7 @@  discard block
 block discarded – undo
2026 2026
         $templates = array();
2027 2027
         $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2028 2028
         // we need to make sure we've got the info we need.
2029
-        if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2029
+        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2030 2030
             EE_Error::add_error(
2031 2031
                 esc_html__(
2032 2032
                     '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.',
@@ -2068,7 +2068,7 @@  discard block
 block discarded – undo
2068 2068
         }
2069 2069
 
2070 2070
         // any error messages?
2071
-        if (! $success) {
2071
+        if ( ! $success) {
2072 2072
             EE_Error::add_error(
2073 2073
                 esc_html__(
2074 2074
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2168,7 +2168,7 @@  discard block
 block discarded – undo
2168 2168
         $preview_title = sprintf(
2169 2169
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2170 2170
             $active_messenger_label,
2171
-            ucwords($message_types[ $message_type ]->label['singular'])
2171
+            ucwords($message_types[$message_type]->label['singular'])
2172 2172
         );
2173 2173
         if (empty($preview)) {
2174 2174
             $this->noEventsErrorMessage();
@@ -2176,7 +2176,7 @@  discard block
 block discarded – undo
2176 2176
         // setup display of preview.
2177 2177
         $this->_admin_page_title = $preview_title;
2178 2178
         $this->_template_args['admin_page_title'] = $preview_title;
2179
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2179
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2180 2180
         $this->_template_args['data']['force_json'] = true;
2181 2181
 
2182 2182
         return '';
@@ -2289,10 +2289,10 @@  discard block
 block discarded – undo
2289 2289
         foreach ($tp_collection as $tp) {
2290 2290
             // only include template packs that support this messenger and message type!
2291 2291
             $supports = $tp->get_supports();
2292
-            if (! isset($supports[ $this->_message_template_group->messenger() ])
2292
+            if ( ! isset($supports[$this->_message_template_group->messenger()])
2293 2293
                 || ! in_array(
2294 2294
                     $this->_message_template_group->message_type(),
2295
-                    $supports[ $this->_message_template_group->messenger() ],
2295
+                    $supports[$this->_message_template_group->messenger()],
2296 2296
                     true
2297 2297
                 )
2298 2298
             ) {
@@ -2345,7 +2345,7 @@  discard block
 block discarded – undo
2345 2345
         $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;
2346 2346
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2347 2347
 
2348
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2348
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2349 2349
 
2350 2350
         EEH_Template::display_template($template, $template_args);
2351 2351
     }
@@ -2371,10 +2371,10 @@  discard block
 block discarded – undo
2371 2371
         // first we need to see if there are any fields
2372 2372
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2373 2373
 
2374
-        if (! empty($fields)) {
2374
+        if ( ! empty($fields)) {
2375 2375
             // yup there be fields
2376 2376
             foreach ($fields as $field => $config) {
2377
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2377
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2378 2378
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2379 2379
                 $default = isset($config['default']) ? $config['default'] : '';
2380 2380
                 $default = isset($config['value']) ? $config['value'] : $default;
@@ -2382,22 +2382,22 @@  discard block
 block discarded – undo
2382 2382
                 // if type is hidden and the value is empty
2383 2383
                 // something may have gone wrong so let's correct with the defaults
2384 2384
                 $fix = $config['input'] === 'hidden'
2385
-                       && isset($existing[ $field ])
2386
-                       && empty($existing[ $field ])
2385
+                       && isset($existing[$field])
2386
+                       && empty($existing[$field])
2387 2387
                     ? $default
2388 2388
                     : '';
2389
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2390
-                    ? $existing[ $field ]
2389
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2390
+                    ? $existing[$field]
2391 2391
                     : $fix;
2392 2392
 
2393
-                $template_form_fields[ $field_id ] = array(
2394
-                    'name'       => 'test_settings_fld[' . $field . ']',
2393
+                $template_form_fields[$field_id] = array(
2394
+                    'name'       => 'test_settings_fld['.$field.']',
2395 2395
                     'label'      => $config['label'],
2396 2396
                     'input'      => $config['input'],
2397 2397
                     'type'       => $config['type'],
2398 2398
                     'required'   => $config['required'],
2399 2399
                     'validation' => $config['validation'],
2400
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2400
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2401 2401
                     'css_class'  => $config['css_class'],
2402 2402
                     'options'    => isset($config['options']) ? $config['options'] : array(),
2403 2403
                     'default'    => $default,
@@ -2412,7 +2412,7 @@  discard block
 block discarded – undo
2412 2412
 
2413 2413
         $test_settings_html = '';
2414 2414
         // print out $test_settings_fields
2415
-        if (! empty($test_settings_fields)) {
2415
+        if ( ! empty($test_settings_fields)) {
2416 2416
             echo $test_settings_fields;
2417 2417
             $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2418 2418
             $test_settings_html .= 'name="test_button" value="';
@@ -2459,7 +2459,7 @@  discard block
 block discarded – undo
2459 2459
         );
2460 2460
 
2461 2461
         return EEH_Template::display_template(
2462
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2462
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2463 2463
             $template_args,
2464 2464
             true
2465 2465
         );
@@ -2484,7 +2484,7 @@  discard block
 block discarded – undo
2484 2484
         // $messenger = $this->_message_template_group->messenger_obj();
2485 2485
         // now let's set the content depending on the status of the shortcodes array
2486 2486
         if (empty($shortcodes)) {
2487
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2487
+            $content = '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2488 2488
             echo $content;
2489 2489
         } else {
2490 2490
             // $alt = 0;
@@ -2522,7 +2522,7 @@  discard block
 block discarded – undo
2522 2522
     {
2523 2523
 
2524 2524
         // no need to run this if the property is already set
2525
-        if (! empty($this->_shortcodes)) {
2525
+        if ( ! empty($this->_shortcodes)) {
2526 2526
             return;
2527 2527
         }
2528 2528
 
@@ -2576,7 +2576,7 @@  discard block
 block discarded – undo
2576 2576
     protected function _set_message_template_group()
2577 2577
     {
2578 2578
 
2579
-        if (! empty($this->_message_template_group)) {
2579
+        if ( ! empty($this->_message_template_group)) {
2580 2580
             return;
2581 2581
         } //get out if this is already set.
2582 2582
 
@@ -2623,7 +2623,7 @@  discard block
 block discarded – undo
2623 2623
                     <?php
2624 2624
                 }
2625 2625
                 // setup nonce_url
2626
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2626
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2627 2627
                 ?>
2628 2628
                 <select name="context">
2629 2629
                     <?php
@@ -2633,7 +2633,7 @@  discard block
 block discarded – undo
2633 2633
                             $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2634 2634
                             ?>
2635 2635
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2636
-                                <?php echo $context_details[ $context ]['label']; ?>
2636
+                                <?php echo $context_details[$context]['label']; ?>
2637 2637
                             </option>
2638 2638
                         <?php endforeach;
2639 2639
                     endif; ?>
@@ -2663,22 +2663,22 @@  discard block
 block discarded – undo
2663 2663
      */
2664 2664
     protected function _set_message_template_column_values($index)
2665 2665
     {
2666
-        if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2667
-            foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2668
-                $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2666
+        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2667
+            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2668
+                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2669 2669
             }
2670 2670
         }
2671 2671
 
2672 2672
 
2673 2673
         $set_column_values = array(
2674
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2674
+            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2675 2675
             'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2676 2676
             'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2677 2677
             'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2678 2678
             'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2679
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2679
+            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2680 2680
             'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2681
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2681
+            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2682 2682
             'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2683 2683
                 ? absint($this->_req_data['MTP_is_global'])
2684 2684
                 : 0,
@@ -2725,7 +2725,7 @@  discard block
 block discarded – undo
2725 2725
         $context = ucwords(str_replace('_', ' ', $context_slug));
2726 2726
 
2727 2727
         $item_desc = $messenger_label && $message_type_label
2728
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2728
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
2729 2729
             : '';
2730 2730
         $item_desc .= 'Message Template';
2731 2731
         $query_args = array();
@@ -2756,7 +2756,7 @@  discard block
 block discarded – undo
2756 2756
 
2757 2757
 
2758 2758
             // run update for each template field in displayed context
2759
-            if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2759
+            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2760 2760
                 EE_Error::add_error(
2761 2761
                     esc_html__(
2762 2762
                         'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
@@ -2818,10 +2818,10 @@  discard block
 block discarded – undo
2818 2818
                         $set_column_values = $this->_set_message_template_column_values($template_field);
2819 2819
 
2820 2820
                         $where_cols_n_values = array(
2821
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2821
+                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'],
2822 2822
                         );
2823 2823
                         // if they aren't allowed to use all JS, restrict them to just posty-y tags
2824
-                        if (! current_user_can('unfiltered_html')) {
2824
+                        if ( ! current_user_can('unfiltered_html')) {
2825 2825
                             if (is_array($set_column_values['MTP_content'])) {
2826 2826
                                 foreach ($set_column_values['MTP_content'] as $key => $value) {
2827 2827
                                     // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
@@ -2829,7 +2829,7 @@  discard block
 block discarded – undo
2829 2829
                                     // appear invalid.) But currently the models expect slashed data, so after wp_kses
2830 2830
                                     // runs we need to re-slash the data. Sheesh. See
2831 2831
                                     // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2832
-                                    $set_column_values['MTP_content'][ $key ] = addslashes(
2832
+                                    $set_column_values['MTP_content'][$key] = addslashes(
2833 2833
                                         wp_kses(
2834 2834
                                             stripslashes($value),
2835 2835
                                             wp_kses_allowed_html('post')
@@ -2865,14 +2865,14 @@  discard block
 block discarded – undo
2865 2865
                             }
2866 2866
                         } else {
2867 2867
                             // only do this logic if we don't have a MTP_ID for this field
2868
-                            if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2868
+                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2869 2869
                                 // this has already been through the template field validator and sanitized, so it will be
2870 2870
                                 // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2871 2871
                                 // message template field in a messenger/message type and existing users don't have the
2872 2872
                                 // default setup for it.
2873 2873
                                 // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2874 2874
                                 $updated = $MTP->insert($message_template_fields);
2875
-                                if (! $updated || is_wp_error($updated)) {
2875
+                                if ( ! $updated || is_wp_error($updated)) {
2876 2876
                                     EE_Error::add_error(
2877 2877
                                         sprintf(
2878 2878
                                             esc_html__('%s field could not be updated.', 'event_espresso'),
@@ -3103,7 +3103,7 @@  discard block
 block discarded – undo
3103 3103
         // incoming GRP_IDs
3104 3104
         if ($all) {
3105 3105
             // Checkboxes
3106
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3106
+            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3107 3107
                 // if array has more than one element then success message should be plural.
3108 3108
                 // todo: what about nonce?
3109 3109
                 $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
@@ -3111,16 +3111,16 @@  discard block
 block discarded – undo
3111 3111
                 // cycle through checkboxes
3112 3112
                 while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3113 3113
                     $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3114
-                    if (! $trashed_or_restored) {
3114
+                    if ( ! $trashed_or_restored) {
3115 3115
                         $success = 0;
3116 3116
                     }
3117 3117
                 }
3118 3118
             } else {
3119 3119
                 // grab single GRP_ID and handle
3120 3120
                 $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3121
-                if (! empty($GRP_ID)) {
3121
+                if ( ! empty($GRP_ID)) {
3122 3122
                     $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3123
-                    if (! $trashed_or_restored) {
3123
+                    if ( ! $trashed_or_restored) {
3124 3124
                         $success = 0;
3125 3125
                     }
3126 3126
                 } else {
@@ -3168,7 +3168,7 @@  discard block
 block discarded – undo
3168 3168
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3169 3169
 
3170 3170
         // checkboxes
3171
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3171
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3172 3172
             // if array has more than one element then success message should be plural
3173 3173
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3174 3174
 
@@ -3275,7 +3275,7 @@  discard block
 block discarded – undo
3275 3275
     protected function _set_m_mt_settings()
3276 3276
     {
3277 3277
         // first if this is already set then lets get out no need to regenerate data.
3278
-        if (! empty($this->_m_mt_settings)) {
3278
+        if ( ! empty($this->_m_mt_settings)) {
3279 3279
             return;
3280 3280
         }
3281 3281
 
@@ -3289,7 +3289,7 @@  discard block
 block discarded – undo
3289 3289
         // assemble the array for the _tab_text_links helper
3290 3290
 
3291 3291
         foreach ($messengers as $messenger) {
3292
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array(
3292
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
3293 3293
                 'label' => ucwords($messenger->label['singular']),
3294 3294
                 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3295 3295
                     ? 'messenger-active'
@@ -3306,7 +3306,7 @@  discard block
 block discarded – undo
3306 3306
             foreach ($message_types as $message_type) {
3307 3307
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3308 3308
                 // it shouldn't show in either the inactive OR active metabox.
3309
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3309
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3310 3310
                     continue;
3311 3311
                 }
3312 3312
 
@@ -3317,12 +3317,12 @@  discard block
 block discarded – undo
3317 3317
                     ? 'active'
3318 3318
                     : 'inactive';
3319 3319
 
3320
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array(
3320
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
3321 3321
                     'label'    => ucwords($message_type->label['singular']),
3322
-                    'class'    => 'message-type-' . $a_or_i,
3323
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3324
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3325
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3322
+                    'class'    => 'message-type-'.$a_or_i,
3323
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3324
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3325
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3326 3326
                     'title'    => $a_or_i === 'active'
3327 3327
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3328 3328
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3353,25 +3353,25 @@  discard block
 block discarded – undo
3353 3353
         $fields = $message_type->get_admin_settings_fields();
3354 3354
         $settings_template_args['template_form_fields'] = '';
3355 3355
 
3356
-        if (! empty($fields) && $active) {
3356
+        if ( ! empty($fields) && $active) {
3357 3357
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3358 3358
             foreach ($fields as $fldname => $fldprops) {
3359
-                $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3360
-                $template_form_field[ $field_id ] = array(
3361
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3359
+                $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3360
+                $template_form_field[$field_id] = array(
3361
+                    'name'       => 'message_type_settings['.$fldname.']',
3362 3362
                     'label'      => $fldprops['label'],
3363 3363
                     'input'      => $fldprops['field_type'],
3364 3364
                     'type'       => $fldprops['value_type'],
3365 3365
                     'required'   => $fldprops['required'],
3366 3366
                     'validation' => $fldprops['validation'],
3367
-                    'value'      => isset($existing_settings[ $fldname ])
3368
-                        ? $existing_settings[ $fldname ]
3367
+                    'value'      => isset($existing_settings[$fldname])
3368
+                        ? $existing_settings[$fldname]
3369 3369
                         : $fldprops['default'],
3370 3370
                     'options'    => isset($fldprops['options'])
3371 3371
                         ? $fldprops['options']
3372 3372
                         : array(),
3373
-                    'default'    => isset($existing_settings[ $fldname ])
3374
-                        ? $existing_settings[ $fldname ]
3373
+                    'default'    => isset($existing_settings[$fldname])
3374
+                        ? $existing_settings[$fldname]
3375 3375
                         : $fldprops['default'],
3376 3376
                     'css_class'  => 'no-drag',
3377 3377
                     'format'     => $fldprops['format'],
@@ -3414,7 +3414,7 @@  discard block
 block discarded – undo
3414 3414
             : '';
3415 3415
 
3416 3416
 
3417
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3417
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3418 3418
         $content = EEH_Template::display_template($template, $settings_template_args, true);
3419 3419
 
3420 3420
         return $content;
@@ -3445,20 +3445,20 @@  discard block
 block discarded – undo
3445 3445
                 // messenger meta boxes
3446 3446
                 $active = $selected_messenger === $messenger;
3447 3447
                 $active_mt_tabs = isset(
3448
-                    $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3448
+                    $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3449 3449
                 )
3450
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3450
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3451 3451
                     : '';
3452
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3452
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3453 3453
                     esc_html__('%s Settings', 'event_espresso'),
3454 3454
                     $tab_array['label']
3455 3455
                 );
3456
-                $m_template_args[ $messenger . '_a_box' ] = array(
3456
+                $m_template_args[$messenger.'_a_box'] = array(
3457 3457
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3458 3458
                     'inactive_message_types' => isset(
3459
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3459
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3460 3460
                     )
3461
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3461
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3462 3462
                         : '',
3463 3463
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3464 3464
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3469,13 +3469,13 @@  discard block
 block discarded – undo
3469 3469
                 // message type meta boxes
3470 3470
                 // (which is really just the inactive container for each messenger
3471 3471
                 // showing inactive message types for that messenger)
3472
-                $mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso');
3473
-                $mt_template_args[ $messenger . '_i_box' ] = array(
3472
+                $mt_boxes[$messenger.'_i_box'] = esc_html__('Inactive Message Types', 'event_espresso');
3473
+                $mt_template_args[$messenger.'_i_box'] = array(
3474 3474
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3475 3475
                     'inactive_message_types' => isset(
3476
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3476
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3477 3477
                     )
3478
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3478
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3479 3479
                         : '',
3480 3480
                     'hidden'                 => $active ? '' : ' hidden',
3481 3481
                     'hide_on_message'        => $hide_on_message,
@@ -3488,14 +3488,14 @@  discard block
 block discarded – undo
3488 3488
 
3489 3489
 
3490 3490
         // register messenger metaboxes
3491
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3491
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3492 3492
         foreach ($m_boxes as $box => $label) {
3493
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]);
3493
+            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
3494 3494
             $msgr = str_replace('_a_box', '', $box);
3495 3495
             add_meta_box(
3496
-                'espresso_' . $msgr . '_settings',
3496
+                'espresso_'.$msgr.'_settings',
3497 3497
                 $label,
3498
-                function ($post, $metabox) {
3498
+                function($post, $metabox) {
3499 3499
                     echo EEH_Template::display_template(
3500 3500
                         $metabox["args"]["template_path"],
3501 3501
                         $metabox["args"]["template_args"],
@@ -3510,17 +3510,17 @@  discard block
 block discarded – undo
3510 3510
         }
3511 3511
 
3512 3512
         // register message type metaboxes
3513
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3513
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3514 3514
         foreach ($mt_boxes as $box => $label) {
3515 3515
             $callback_args = array(
3516 3516
                 'template_path' => $mt_template_path,
3517
-                'template_args' => $mt_template_args[ $box ],
3517
+                'template_args' => $mt_template_args[$box],
3518 3518
             );
3519 3519
             $mt = str_replace('_i_box', '', $box);
3520 3520
             add_meta_box(
3521
-                'espresso_' . $mt . '_inactive_mts',
3521
+                'espresso_'.$mt.'_inactive_mts',
3522 3522
                 $label,
3523
-                function ($post, $metabox) {
3523
+                function($post, $metabox) {
3524 3524
                     echo EEH_Template::display_template(
3525 3525
                         $metabox["args"]["template_path"],
3526 3526
                         $metabox["args"]["template_args"],
@@ -3666,7 +3666,7 @@  discard block
 block discarded – undo
3666 3666
             if ($form->is_valid()) {
3667 3667
                 $valid_data = $form->valid_data();
3668 3668
                 foreach ($valid_data as $property => $value) {
3669
-                    $setter = 'set_' . $property;
3669
+                    $setter = 'set_'.$property;
3670 3670
                     if (method_exists($network_config, $setter)) {
3671 3671
                         $network_config->{$setter}($value);
3672 3672
                     } elseif (property_exists($network_config, $property)
@@ -3700,7 +3700,7 @@  discard block
 block discarded – undo
3700 3700
     protected function _get_mt_tabs($tab_array)
3701 3701
     {
3702 3702
         $tab_array = (array) $tab_array;
3703
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3703
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3704 3704
         $tabs = '';
3705 3705
 
3706 3706
         foreach ($tab_array as $tab) {
@@ -3728,20 +3728,20 @@  discard block
 block discarded – undo
3728 3728
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3729 3729
 
3730 3730
 
3731
-        if (! empty($fields)) {
3731
+        if ( ! empty($fields)) {
3732 3732
             $existing_settings = $messenger->get_existing_admin_settings();
3733 3733
 
3734 3734
             foreach ($fields as $fldname => $fldprops) {
3735
-                $field_id = $messenger->name . '-' . $fldname;
3736
-                $template_form_field[ $field_id ] = array(
3737
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3735
+                $field_id = $messenger->name.'-'.$fldname;
3736
+                $template_form_field[$field_id] = array(
3737
+                    'name'       => 'messenger_settings['.$field_id.']',
3738 3738
                     'label'      => $fldprops['label'],
3739 3739
                     'input'      => $fldprops['field_type'],
3740 3740
                     'type'       => $fldprops['value_type'],
3741 3741
                     'required'   => $fldprops['required'],
3742 3742
                     'validation' => $fldprops['validation'],
3743
-                    'value'      => isset($existing_settings[ $field_id ])
3744
-                        ? $existing_settings[ $field_id ]
3743
+                    'value'      => isset($existing_settings[$field_id])
3744
+                        ? $existing_settings[$field_id]
3745 3745
                         : $fldprops['default'],
3746 3746
                     'css_class'  => '',
3747 3747
                     'format'     => $fldprops['format'],
@@ -3767,9 +3767,9 @@  discard block
 block discarded – undo
3767 3767
         );
3768 3768
 
3769 3769
         // make sure any active message types that are existing are included in the hidden fields
3770
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3771
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3772
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array(
3770
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3771
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3772
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array(
3773 3773
                     'type'  => 'hidden',
3774 3774
                     'value' => $mt,
3775 3775
                 );
@@ -3798,9 +3798,9 @@  discard block
 block discarded – undo
3798 3798
 
3799 3799
 
3800 3800
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3801
-        $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3801
+        $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3802 3802
         $settings_template_args['on_off_status'] = $active ? true : false;
3803
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3803
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3804 3804
         $content = EEH_Template::display_template(
3805 3805
             $template,
3806 3806
             $settings_template_args,
@@ -3826,7 +3826,7 @@  discard block
 block discarded – undo
3826 3826
         $success = true;
3827 3827
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3828 3828
         // let's check that we have required data
3829
-        if (! isset($this->_req_data['messenger'])) {
3829
+        if ( ! isset($this->_req_data['messenger'])) {
3830 3830
             EE_Error::add_error(
3831 3831
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3832 3832
                 __FILE__,
@@ -3840,12 +3840,12 @@  discard block
 block discarded – undo
3840 3840
         $nonce = isset($this->_req_data['activate_nonce'])
3841 3841
             ? sanitize_text_field($this->_req_data['activate_nonce'])
3842 3842
             : '';
3843
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3843
+        $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce';
3844 3844
 
3845 3845
         $this->_verify_nonce($nonce, $nonce_ref);
3846 3846
 
3847 3847
 
3848
-        if (! isset($this->_req_data['status'])) {
3848
+        if ( ! isset($this->_req_data['status'])) {
3849 3849
             EE_Error::add_error(
3850 3850
                 esc_html__(
3851 3851
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -3904,7 +3904,7 @@  discard block
 block discarded – undo
3904 3904
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3905 3905
 
3906 3906
         // let's make sure we have the necessary data
3907
-        if (! isset($this->_req_data['message_type'])) {
3907
+        if ( ! isset($this->_req_data['message_type'])) {
3908 3908
             EE_Error::add_error(
3909 3909
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3910 3910
                 __FILE__,
@@ -3914,7 +3914,7 @@  discard block
 block discarded – undo
3914 3914
             $success = false;
3915 3915
         }
3916 3916
 
3917
-        if (! isset($this->_req_data['messenger'])) {
3917
+        if ( ! isset($this->_req_data['messenger'])) {
3918 3918
             EE_Error::add_error(
3919 3919
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3920 3920
                 __FILE__,
@@ -3924,7 +3924,7 @@  discard block
 block discarded – undo
3924 3924
             $success = false;
3925 3925
         }
3926 3926
 
3927
-        if (! isset($this->_req_data['status'])) {
3927
+        if ( ! isset($this->_req_data['status'])) {
3928 3928
             EE_Error::add_error(
3929 3929
                 esc_html__(
3930 3930
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -3957,7 +3957,7 @@  discard block
 block discarded – undo
3957 3957
 
3958 3958
         // do a nonce check here since we're not arriving via a normal route
3959 3959
         $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3960
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3960
+        $nonce_ref = $this->_req_data['message_type'].'_nonce';
3961 3961
 
3962 3962
         $this->_verify_nonce($nonce, $nonce_ref);
3963 3963
 
@@ -4144,7 +4144,7 @@  discard block
 block discarded – undo
4144 4144
         EE_Message_Type $message_type = null
4145 4145
     ) {
4146 4146
         // if $messenger isn't a valid messenger object then get out.
4147
-        if (! $messenger instanceof EE_Messenger) {
4147
+        if ( ! $messenger instanceof EE_Messenger) {
4148 4148
             EE_Error::add_error(
4149 4149
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4150 4150
                 __FILE__,
@@ -4199,7 +4199,7 @@  discard block
 block discarded – undo
4199 4199
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4200 4200
             // in which case we just give a success message for the messenger being successfully activated.
4201 4201
         } else {
4202
-            if (! $messenger->get_default_message_types()) {
4202
+            if ( ! $messenger->get_default_message_types()) {
4203 4203
                 // messenger doesn't have any default message types so still a success.
4204 4204
                 EE_Error::add_success(
4205 4205
                     sprintf(
@@ -4255,7 +4255,7 @@  discard block
 block discarded – undo
4255 4255
         EE_Error::overwrite_success();
4256 4256
 
4257 4257
         // if $messenger isn't a valid messenger object then get out.
4258
-        if (! $messenger instanceof EE_Messenger) {
4258
+        if ( ! $messenger instanceof EE_Messenger) {
4259 4259
             EE_Error::add_error(
4260 4260
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4261 4261
                 __FILE__,
@@ -4317,7 +4317,7 @@  discard block
 block discarded – undo
4317 4317
      */
4318 4318
     public function update_mt_form()
4319 4319
     {
4320
-        if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4320
+        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4321 4321
             EE_Error::add_error(
4322 4322
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4323 4323
                 __FILE__,
@@ -4329,7 +4329,7 @@  discard block
 block discarded – undo
4329 4329
 
4330 4330
         $message_types = $this->get_installed_message_types();
4331 4331
 
4332
-        $message_type = $message_types[ $this->_req_data['message_type'] ];
4332
+        $message_type = $message_types[$this->_req_data['message_type']];
4333 4333
         $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4334 4334
 
4335 4335
         $content = $this->_message_type_settings_content(
@@ -4349,7 +4349,7 @@  discard block
 block discarded – undo
4349 4349
      */
4350 4350
     public function save_settings()
4351 4351
     {
4352
-        if (! isset($this->_req_data['type'])) {
4352
+        if ( ! isset($this->_req_data['type'])) {
4353 4353
             EE_Error::add_error(
4354 4354
                 esc_html__(
4355 4355
                     'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
@@ -4378,7 +4378,7 @@  discard block
 block discarded – undo
4378 4378
                         unset($settings['message_types']);
4379 4379
                         break;
4380 4380
                     default:
4381
-                        $settings[ $key ] = $value;
4381
+                        $settings[$key] = $value;
4382 4382
                         break;
4383 4383
                 }
4384 4384
             }
@@ -4397,7 +4397,7 @@  discard block
 block discarded – undo
4397 4397
                         unset($settings['message_type']);
4398 4398
                         break;
4399 4399
                     default:
4400
-                        $settings[ $key ] = $value;
4400
+                        $settings[$key] = $value;
4401 4401
                         break;
4402 4402
                 }
4403 4403
             }
@@ -4558,7 +4558,7 @@  discard block
 block discarded – undo
4558 4558
      */
4559 4559
     protected function _get_msg_ids_from_request()
4560 4560
     {
4561
-        if (! isset($this->_req_data['MSG_ID'])) {
4561
+        if ( ! isset($this->_req_data['MSG_ID'])) {
4562 4562
             return array();
4563 4563
         }
4564 4564
 
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Indentation   +3712 added lines, -3712 removed lines patch added patch discarded remove patch
@@ -19,2230 +19,2230 @@  discard block
 block discarded – undo
19 19
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
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
-    private static $_reg_status;
38
-
39
-    /**
40
-     * Form for displaying the custom questions for this registration.
41
-     * This gets used a few times throughout the request so its best to cache it
42
-     *
43
-     * @var EE_Registration_Custom_Questions_Form
44
-     */
45
-    protected $_reg_custom_questions_form = null;
46
-
47
-    /**
48
-     * @var EEM_Registration $registration_model
49
-     */
50
-    private $registration_model;
51
-
52
-    /**
53
-     * @var EEM_Attendee $attendee_model
54
-     */
55
-    private $attendee_model;
56
-
57
-    /**
58
-     * @var EEM_Event $event_model
59
-     */
60
-    private $event_model;
61
-
62
-    /**
63
-     * @var EEM_Status $status_model
64
-     */
65
-    private $status_model;
66
-
67
-
68
-    /**
69
-     * @param bool $routing
70
-     * @throws EE_Error
71
-     * @throws InvalidArgumentException
72
-     * @throws InvalidDataTypeException
73
-     * @throws InvalidInterfaceException
74
-     * @throws ReflectionException
75
-     */
76
-    public function __construct($routing = true)
77
-    {
78
-        parent::__construct($routing);
79
-        add_action('wp_loaded', array($this, 'wp_loaded'));
80
-    }
81
-
82
-    /**
83
-     * @return EEM_Registration
84
-     * @throws InvalidArgumentException
85
-     * @throws InvalidDataTypeException
86
-     * @throws InvalidInterfaceException
87
-     * @since 4.10.2.p
88
-     */
89
-    protected function getRegistrationModel()
90
-    {
91
-        if (! $this->registration_model instanceof EEM_Registration) {
92
-            $this->registration_model = $this->getLoader()->getShared('EEM_Registration');
93
-        }
94
-        return $this->registration_model;
95
-    }
96
-
97
-    /**
98
-     * @return EEM_Attendee
99
-     * @throws InvalidArgumentException
100
-     * @throws InvalidDataTypeException
101
-     * @throws InvalidInterfaceException
102
-     * @since 4.10.2.p
103
-     */
104
-    protected function getAttendeeModel()
105
-    {
106
-        if (! $this->attendee_model instanceof EEM_Attendee) {
107
-            $this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
108
-        }
109
-        return $this->attendee_model;
110
-    }
111
-
112
-
113
-    /**
114
-     * @return EEM_Event
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidInterfaceException
118
-     * @since 4.10.2.p
119
-     */
120
-    protected function getEventModel()
121
-    {
122
-        if (! $this->event_model instanceof EEM_Event) {
123
-            $this->event_model = $this->getLoader()->getShared('EEM_Event');
124
-        }
125
-        return $this->event_model;
126
-    }
127
-
128
-    /**
129
-     * @return EEM_Status
130
-     * @throws InvalidArgumentException
131
-     * @throws InvalidDataTypeException
132
-     * @throws InvalidInterfaceException
133
-     * @since 4.10.2.p
134
-     */
135
-    protected function getStatusModel()
136
-    {
137
-        if (! $this->status_model instanceof EEM_Status) {
138
-            $this->status_model = $this->getLoader()->getShared('EEM_Status');
139
-        }
140
-        return $this->status_model;
141
-    }
142
-
143
-
144
-    public function wp_loaded()
145
-    {
146
-        // when adding a new registration...
147
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
148
-            EE_System::do_not_cache();
149
-            if (! isset($this->_req_data['processing_registration'])
150
-                || absint($this->_req_data['processing_registration']) !== 1
151
-            ) {
152
-                // and it's NOT the attendee information reg step
153
-                // force cookie expiration by setting time to last week
154
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
155
-                // and update the global
156
-                $_COOKIE['ee_registration_added'] = 0;
157
-            }
158
-        }
159
-    }
160
-
161
-
162
-    protected function _init_page_props()
163
-    {
164
-        $this->page_slug = REG_PG_SLUG;
165
-        $this->_admin_base_url = REG_ADMIN_URL;
166
-        $this->_admin_base_path = REG_ADMIN;
167
-        $this->page_label = esc_html__('Registrations', 'event_espresso');
168
-        $this->_cpt_routes = array(
169
-            'add_new_attendee' => 'espresso_attendees',
170
-            'edit_attendee'    => 'espresso_attendees',
171
-            'insert_attendee'  => 'espresso_attendees',
172
-            'update_attendee'  => 'espresso_attendees',
173
-        );
174
-        $this->_cpt_model_names = array(
175
-            'add_new_attendee' => 'EEM_Attendee',
176
-            'edit_attendee'    => 'EEM_Attendee',
177
-        );
178
-        $this->_cpt_edit_routes = array(
179
-            'espresso_attendees' => 'edit_attendee',
180
-        );
181
-        $this->_pagenow_map = array(
182
-            'add_new_attendee' => 'post-new.php',
183
-            'edit_attendee'    => 'post.php',
184
-            'trash'            => 'post.php',
185
-        );
186
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
187
-        // add filters so that the comment urls don't take users to a confusing 404 page
188
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
189
-    }
190
-
191
-
192
-    public function clear_comment_link($link, $comment, $args)
193
-    {
194
-        // gotta make sure this only happens on this route
195
-        $post_type = get_post_type($comment->comment_post_ID);
196
-        if ($post_type === 'espresso_attendees') {
197
-            return '#commentsdiv';
198
-        }
199
-        return $link;
200
-    }
201
-
202
-
203
-    protected function _ajax_hooks()
204
-    {
205
-        // todo: all hooks for registrations ajax goes in here
206
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
207
-    }
208
-
209
-
210
-    protected function _define_page_props()
211
-    {
212
-        $this->_admin_page_title = $this->page_label;
213
-        $this->_labels = array(
214
-            'buttons'                      => array(
215
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
216
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
217
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
218
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
219
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
220
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
221
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
222
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
223
-            ),
224
-            'publishbox'                   => array(
225
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
226
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
227
-            ),
228
-            'hide_add_button_on_cpt_route' => array(
229
-                'edit_attendee' => true,
230
-            ),
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     *        grab url requests and route them
237
-     *
238
-     * @access private
239
-     * @return void
240
-     * @throws EE_Error
241
-     */
242
-    public function _set_page_routes()
243
-    {
244
-        $this->_get_registration_status_array();
245
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
246
-            ? $this->_req_data['_REG_ID'] : 0;
247
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
248
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
249
-            : $reg_id;
250
-        $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
251
-            ? $this->_req_data['ATT_ID'] : 0;
252
-        $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
253
-            ? $this->_req_data['post']
254
-            : $att_id;
255
-        $this->_page_routes = array(
256
-            'default'                             => array(
257
-                'func'       => '_registrations_overview_list_table',
258
-                'capability' => 'ee_read_registrations',
259
-            ),
260
-            'view_registration'                   => array(
261
-                'func'       => '_registration_details',
262
-                'capability' => 'ee_read_registration',
263
-                'obj_id'     => $reg_id,
264
-            ),
265
-            'edit_registration'                   => array(
266
-                'func'               => '_update_attendee_registration_form',
267
-                'noheader'           => true,
268
-                'headers_sent_route' => 'view_registration',
269
-                'capability'         => 'ee_edit_registration',
270
-                'obj_id'             => $reg_id,
271
-                '_REG_ID'            => $reg_id,
272
-            ),
273
-            'trash_registrations'                 => array(
274
-                'func'       => '_trash_or_restore_registrations',
275
-                'args'       => array('trash' => true),
276
-                'noheader'   => true,
277
-                'capability' => 'ee_delete_registrations',
278
-            ),
279
-            'restore_registrations'               => array(
280
-                'func'       => '_trash_or_restore_registrations',
281
-                'args'       => array('trash' => false),
282
-                'noheader'   => true,
283
-                'capability' => 'ee_delete_registrations',
284
-            ),
285
-            'delete_registrations'                => array(
286
-                'func'       => '_delete_registrations',
287
-                'noheader'   => true,
288
-                'capability' => 'ee_delete_registrations',
289
-            ),
290
-            'new_registration'                    => array(
291
-                'func'       => 'new_registration',
292
-                'capability' => 'ee_edit_registrations',
293
-            ),
294
-            'process_reg_step'                    => array(
295
-                'func'       => 'process_reg_step',
296
-                'noheader'   => true,
297
-                'capability' => 'ee_edit_registrations',
298
-            ),
299
-            'redirect_to_txn'                     => array(
300
-                'func'       => 'redirect_to_txn',
301
-                'noheader'   => true,
302
-                'capability' => 'ee_edit_registrations',
303
-            ),
304
-            'change_reg_status'                   => array(
305
-                'func'       => '_change_reg_status',
306
-                'noheader'   => true,
307
-                'capability' => 'ee_edit_registration',
308
-                'obj_id'     => $reg_id,
309
-            ),
310
-            'approve_registration'                => array(
311
-                'func'       => 'approve_registration',
312
-                'noheader'   => true,
313
-                'capability' => 'ee_edit_registration',
314
-                'obj_id'     => $reg_id,
315
-            ),
316
-            'approve_and_notify_registration'     => array(
317
-                'func'       => 'approve_registration',
318
-                'noheader'   => true,
319
-                'args'       => array(true),
320
-                'capability' => 'ee_edit_registration',
321
-                'obj_id'     => $reg_id,
322
-            ),
323
-            'approve_registrations'               => array(
324
-                'func'       => 'bulk_action_on_registrations',
325
-                'noheader'   => true,
326
-                'capability' => 'ee_edit_registrations',
327
-                'args'       => array('approve'),
328
-            ),
329
-            'approve_and_notify_registrations'    => array(
330
-                'func'       => 'bulk_action_on_registrations',
331
-                'noheader'   => true,
332
-                'capability' => 'ee_edit_registrations',
333
-                'args'       => array('approve', true),
334
-            ),
335
-            'decline_registration'                => array(
336
-                'func'       => 'decline_registration',
337
-                'noheader'   => true,
338
-                'capability' => 'ee_edit_registration',
339
-                'obj_id'     => $reg_id,
340
-            ),
341
-            'decline_and_notify_registration'     => array(
342
-                'func'       => 'decline_registration',
343
-                'noheader'   => true,
344
-                'args'       => array(true),
345
-                'capability' => 'ee_edit_registration',
346
-                'obj_id'     => $reg_id,
347
-            ),
348
-            'decline_registrations'               => array(
349
-                'func'       => 'bulk_action_on_registrations',
350
-                'noheader'   => true,
351
-                'capability' => 'ee_edit_registrations',
352
-                'args'       => array('decline'),
353
-            ),
354
-            'decline_and_notify_registrations'    => array(
355
-                'func'       => 'bulk_action_on_registrations',
356
-                'noheader'   => true,
357
-                'capability' => 'ee_edit_registrations',
358
-                'args'       => array('decline', true),
359
-            ),
360
-            'pending_registration'                => array(
361
-                'func'       => 'pending_registration',
362
-                'noheader'   => true,
363
-                'capability' => 'ee_edit_registration',
364
-                'obj_id'     => $reg_id,
365
-            ),
366
-            'pending_and_notify_registration'     => array(
367
-                'func'       => 'pending_registration',
368
-                'noheader'   => true,
369
-                'args'       => array(true),
370
-                'capability' => 'ee_edit_registration',
371
-                'obj_id'     => $reg_id,
372
-            ),
373
-            'pending_registrations'               => array(
374
-                'func'       => 'bulk_action_on_registrations',
375
-                'noheader'   => true,
376
-                'capability' => 'ee_edit_registrations',
377
-                'args'       => array('pending'),
378
-            ),
379
-            'pending_and_notify_registrations'    => array(
380
-                'func'       => 'bulk_action_on_registrations',
381
-                'noheader'   => true,
382
-                'capability' => 'ee_edit_registrations',
383
-                'args'       => array('pending', true),
384
-            ),
385
-            'no_approve_registration'             => array(
386
-                'func'       => 'not_approve_registration',
387
-                'noheader'   => true,
388
-                'capability' => 'ee_edit_registration',
389
-                'obj_id'     => $reg_id,
390
-            ),
391
-            'no_approve_and_notify_registration'  => array(
392
-                'func'       => 'not_approve_registration',
393
-                'noheader'   => true,
394
-                'args'       => array(true),
395
-                'capability' => 'ee_edit_registration',
396
-                'obj_id'     => $reg_id,
397
-            ),
398
-            'no_approve_registrations'            => array(
399
-                'func'       => 'bulk_action_on_registrations',
400
-                'noheader'   => true,
401
-                'capability' => 'ee_edit_registrations',
402
-                'args'       => array('not_approve'),
403
-            ),
404
-            'no_approve_and_notify_registrations' => array(
405
-                'func'       => 'bulk_action_on_registrations',
406
-                'noheader'   => true,
407
-                'capability' => 'ee_edit_registrations',
408
-                'args'       => array('not_approve', true),
409
-            ),
410
-            'cancel_registration'                 => array(
411
-                'func'       => 'cancel_registration',
412
-                'noheader'   => true,
413
-                'capability' => 'ee_edit_registration',
414
-                'obj_id'     => $reg_id,
415
-            ),
416
-            'cancel_and_notify_registration'      => array(
417
-                'func'       => 'cancel_registration',
418
-                'noheader'   => true,
419
-                'args'       => array(true),
420
-                'capability' => 'ee_edit_registration',
421
-                'obj_id'     => $reg_id,
422
-            ),
423
-            'cancel_registrations'                => array(
424
-                'func'       => 'bulk_action_on_registrations',
425
-                'noheader'   => true,
426
-                'capability' => 'ee_edit_registrations',
427
-                'args'       => array('cancel'),
428
-            ),
429
-            'cancel_and_notify_registrations'     => array(
430
-                'func'       => 'bulk_action_on_registrations',
431
-                'noheader'   => true,
432
-                'capability' => 'ee_edit_registrations',
433
-                'args'       => array('cancel', true),
434
-            ),
435
-            'wait_list_registration'              => array(
436
-                'func'       => 'wait_list_registration',
437
-                'noheader'   => true,
438
-                'capability' => 'ee_edit_registration',
439
-                'obj_id'     => $reg_id,
440
-            ),
441
-            'wait_list_and_notify_registration'   => array(
442
-                'func'       => 'wait_list_registration',
443
-                'noheader'   => true,
444
-                'args'       => array(true),
445
-                'capability' => 'ee_edit_registration',
446
-                'obj_id'     => $reg_id,
447
-            ),
448
-            'contact_list'                        => array(
449
-                'func'       => '_attendee_contact_list_table',
450
-                'capability' => 'ee_read_contacts',
451
-            ),
452
-            'add_new_attendee'                    => array(
453
-                'func' => '_create_new_cpt_item',
454
-                'args' => array(
455
-                    'new_attendee' => true,
456
-                    'capability'   => 'ee_edit_contacts',
457
-                ),
458
-            ),
459
-            'edit_attendee'                       => array(
460
-                'func'       => '_edit_cpt_item',
461
-                'capability' => 'ee_edit_contacts',
462
-                'obj_id'     => $att_id,
463
-            ),
464
-            'duplicate_attendee'                  => array(
465
-                'func'       => '_duplicate_attendee',
466
-                'noheader'   => true,
467
-                'capability' => 'ee_edit_contacts',
468
-                'obj_id'     => $att_id,
469
-            ),
470
-            'insert_attendee'                     => array(
471
-                'func'       => '_insert_or_update_attendee',
472
-                'args'       => array(
473
-                    'new_attendee' => true,
474
-                ),
475
-                'noheader'   => true,
476
-                'capability' => 'ee_edit_contacts',
477
-            ),
478
-            'update_attendee'                     => array(
479
-                'func'       => '_insert_or_update_attendee',
480
-                'args'       => array(
481
-                    'new_attendee' => false,
482
-                ),
483
-                'noheader'   => true,
484
-                'capability' => 'ee_edit_contacts',
485
-                'obj_id'     => $att_id,
486
-            ),
487
-            'trash_attendees'                     => array(
488
-                'func'       => '_trash_or_restore_attendees',
489
-                'args'       => array(
490
-                    'trash' => 'true',
491
-                ),
492
-                'noheader'   => true,
493
-                'capability' => 'ee_delete_contacts',
494
-            ),
495
-            'trash_attendee'                      => array(
496
-                'func'       => '_trash_or_restore_attendees',
497
-                'args'       => array(
498
-                    'trash' => true,
499
-                ),
500
-                'noheader'   => true,
501
-                'capability' => 'ee_delete_contacts',
502
-                'obj_id'     => $att_id,
503
-            ),
504
-            'restore_attendees'                   => array(
505
-                'func'       => '_trash_or_restore_attendees',
506
-                'args'       => array(
507
-                    'trash' => false,
508
-                ),
509
-                'noheader'   => true,
510
-                'capability' => 'ee_delete_contacts',
511
-                'obj_id'     => $att_id,
512
-            ),
513
-            'resend_registration'                 => array(
514
-                'func'       => '_resend_registration',
515
-                'noheader'   => true,
516
-                'capability' => 'ee_send_message',
517
-            ),
518
-            'registrations_report'                => array(
519
-                'func'       => '_registrations_report',
520
-                'noheader'   => true,
521
-                'capability' => 'ee_read_registrations',
522
-            ),
523
-            'contact_list_export'                 => array(
524
-                'func'       => '_contact_list_export',
525
-                'noheader'   => true,
526
-                'capability' => 'export',
527
-            ),
528
-            'contact_list_report'                 => array(
529
-                'func'       => '_contact_list_report',
530
-                'noheader'   => true,
531
-                'capability' => 'ee_read_contacts',
532
-            ),
533
-        );
534
-    }
535
-
536
-
537
-    protected function _set_page_config()
538
-    {
539
-        $this->_page_config = array(
540
-            'default'           => array(
541
-                'nav'           => array(
542
-                    'label' => esc_html__('Overview', 'event_espresso'),
543
-                    'order' => 5,
544
-                ),
545
-                'help_tabs'     => array(
546
-                    'registrations_overview_help_tab'                       => array(
547
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
548
-                        'filename' => 'registrations_overview',
549
-                    ),
550
-                    'registrations_overview_table_column_headings_help_tab' => array(
551
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
552
-                        'filename' => 'registrations_overview_table_column_headings',
553
-                    ),
554
-                    'registrations_overview_filters_help_tab'               => array(
555
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
556
-                        'filename' => 'registrations_overview_filters',
557
-                    ),
558
-                    'registrations_overview_views_help_tab'                 => array(
559
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
560
-                        'filename' => 'registrations_overview_views',
561
-                    ),
562
-                    'registrations_regoverview_other_help_tab'              => array(
563
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
564
-                        'filename' => 'registrations_overview_other',
565
-                    ),
566
-                ),
567
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
568
-                // 'help_tour'     => array('Registration_Overview_Help_Tour'),
569
-                'qtips'         => array('Registration_List_Table_Tips'),
570
-                'list_table'    => 'EE_Registrations_List_Table',
571
-                'require_nonce' => false,
572
-            ),
573
-            'view_registration' => array(
574
-                'nav'           => array(
575
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
576
-                    'order'      => 15,
577
-                    'url'        => isset($this->_req_data['_REG_ID'])
578
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
579
-                        : $this->_admin_base_url,
580
-                    'persistent' => false,
581
-                ),
582
-                'help_tabs'     => array(
583
-                    'registrations_details_help_tab'                    => array(
584
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
585
-                        'filename' => 'registrations_details',
586
-                    ),
587
-                    'registrations_details_table_help_tab'              => array(
588
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
589
-                        'filename' => 'registrations_details_table',
590
-                    ),
591
-                    'registrations_details_form_answers_help_tab'       => array(
592
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
593
-                        'filename' => 'registrations_details_form_answers',
594
-                    ),
595
-                    'registrations_details_registrant_details_help_tab' => array(
596
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
597
-                        'filename' => 'registrations_details_registrant_details',
598
-                    ),
599
-                ),
600
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
601
-                // 'help_tour'     => array('Registration_Details_Help_Tour'),
602
-                'metaboxes'     => array_merge(
603
-                    $this->_default_espresso_metaboxes,
604
-                    array('_registration_details_metaboxes')
605
-                ),
606
-                'require_nonce' => false,
607
-            ),
608
-            'new_registration'  => array(
609
-                'nav'           => array(
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'        => array(
617
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
618
-                ),
619
-                'require_nonce' => false,
620
-            ),
621
-            'add_new_attendee'  => array(
622
-                'nav'           => array(
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
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
630
-                ),
631
-                'require_nonce' => false,
632
-            ),
633
-            'edit_attendee'     => array(
634
-                'nav'           => array(
635
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
636
-                    'order'      => 15,
637
-                    'persistent' => false,
638
-                    'url'        => isset($this->_req_data['ATT_ID'])
639
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
640
-                        : $this->_admin_base_url,
641
-                ),
642
-                'metaboxes'     => array('attendee_editor_metaboxes'),
643
-                'require_nonce' => false,
644
-            ),
645
-            'contact_list'      => array(
646
-                'nav'           => array(
647
-                    'label' => esc_html__('Contact List', 'event_espresso'),
648
-                    'order' => 20,
649
-                ),
650
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
651
-                'help_tabs'     => array(
652
-                    'registrations_contact_list_help_tab'                       => array(
653
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
654
-                        'filename' => 'registrations_contact_list',
655
-                    ),
656
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
657
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
658
-                        'filename' => 'registrations_contact_list_table_column_headings',
659
-                    ),
660
-                    'registrations_contact_list_views_help_tab'                 => array(
661
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
662
-                        'filename' => 'registrations_contact_list_views',
663
-                    ),
664
-                    'registrations_contact_list_other_help_tab'                 => array(
665
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
666
-                        'filename' => 'registrations_contact_list_other',
667
-                    ),
668
-                ),
669
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
670
-                // 'help_tour'     => array('Contact_List_Help_Tour'),
671
-                'metaboxes'     => array(),
672
-                'require_nonce' => false,
673
-            ),
674
-            // override default cpt routes
675
-            'create_new'        => '',
676
-            'edit'              => '',
677
-        );
678
-    }
679
-
680
-
681
-    /**
682
-     * The below methods aren't used by this class currently
683
-     */
684
-    protected function _add_screen_options()
685
-    {
686
-    }
687
-
688
-
689
-    protected function _add_feature_pointers()
690
-    {
691
-    }
692
-
693
-
694
-    public function admin_init()
695
-    {
696
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
697
-            'click "Update Registration Questions" to save your changes',
698
-            'event_espresso'
699
-        );
700
-    }
701
-
702
-
703
-    public function admin_notices()
704
-    {
705
-    }
706
-
707
-
708
-    public function admin_footer_scripts()
709
-    {
710
-    }
711
-
712
-
713
-    /**
714
-     *        get list of registration statuses
715
-     *
716
-     * @access private
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(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
-            array('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
-            array('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 = array(
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(true);
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
-            array('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
-            array('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 = 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 = array(
935
-            'all'   => array(
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
-                    array(
942
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
-                    )
944
-                ),
945
-            ),
946
-            'month' => array(
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
-                    array(
953
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
-                    )
955
-                ),
956
-            ),
957
-            'today' => array(
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
-                    array(
967
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
-                    )
969
-                ),
970
-            ),
971
-        );
972
-        if (EE_Registry::instance()->CAP->current_user_can(
973
-            'ee_delete_registrations',
974
-            'espresso_registrations_delete_registration'
975
-        )) {
976
-            $this->_views['incomplete'] = array(
977
-                'slug'        => 'incomplete',
978
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
979
-                'count'       => 0,
980
-                'bulk_action' => array(
981
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
982
-                ),
983
-            );
984
-            $this->_views['trash'] = array(
985
-                'slug'        => 'trash',
986
-                'label'       => esc_html__('Trash', 'event_espresso'),
987
-                'count'       => 0,
988
-                'bulk_action' => array(
989
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
990
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
991
-                ),
992
-            );
993
-        }
994
-    }
995
-
996
-
997
-    protected function _set_list_table_views_contact_list()
998
-    {
999
-        $this->_views = array(
1000
-            'in_use' => array(
1001
-                'slug'        => 'in_use',
1002
-                'label'       => esc_html__('In Use', 'event_espresso'),
1003
-                'count'       => 0,
1004
-                'bulk_action' => array(
1005
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1006
-                ),
1007
-            ),
1008
-        );
1009
-        if (EE_Registry::instance()->CAP->current_user_can(
1010
-            'ee_delete_contacts',
1011
-            'espresso_registrations_trash_attendees'
1012
-        )
1013
-        ) {
1014
-            $this->_views['trash'] = array(
1015
-                'slug'        => 'trash',
1016
-                'label'       => esc_html__('Trash', 'event_espresso'),
1017
-                'count'       => 0,
1018
-                'bulk_action' => array(
1019
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1020
-                ),
1021
-            );
1022
-        }
1023
-    }
1024
-
1025
-
1026
-    protected function _registration_legend_items()
1027
-    {
1028
-        $fc_items = array(
1029
-            'star-icon'        => array(
1030
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1031
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1032
-            ),
1033
-            'view_details'     => array(
1034
-                'class' => 'dashicons dashicons-clipboard',
1035
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1036
-            ),
1037
-            'edit_attendee'    => array(
1038
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1039
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1040
-            ),
1041
-            'view_transaction' => array(
1042
-                'class' => 'dashicons dashicons-cart',
1043
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1044
-            ),
1045
-            'view_invoice'     => array(
1046
-                'class' => 'dashicons dashicons-media-spreadsheet',
1047
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1048
-            ),
1049
-        );
1050
-        if (EE_Registry::instance()->CAP->current_user_can(
1051
-            'ee_send_message',
1052
-            'espresso_registrations_resend_registration'
1053
-        )) {
1054
-            $fc_items['resend_registration'] = array(
1055
-                'class' => 'dashicons dashicons-email-alt',
1056
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1057
-            );
1058
-        } else {
1059
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
1060
-        }
1061
-        if (EE_Registry::instance()->CAP->current_user_can(
1062
-            'ee_read_global_messages',
1063
-            'view_filtered_messages'
1064
-        )) {
1065
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1066
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1067
-                $fc_items['view_related_messages'] = array(
1068
-                    'class' => $related_for_icon['css_class'],
1069
-                    'desc'  => $related_for_icon['label'],
1070
-                );
1071
-            }
1072
-        }
1073
-        $sc_items = array(
1074
-            'approved_status'   => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1076
-                'desc'  => EEH_Template::pretty_status(
1077
-                    EEM_Registration::status_id_approved,
1078
-                    false,
1079
-                    'sentence'
1080
-                ),
1081
-            ),
1082
-            'pending_status'    => array(
1083
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1084
-                'desc'  => EEH_Template::pretty_status(
1085
-                    EEM_Registration::status_id_pending_payment,
1086
-                    false,
1087
-                    'sentence'
1088
-                ),
1089
-            ),
1090
-            'wait_list'         => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1092
-                'desc'  => EEH_Template::pretty_status(
1093
-                    EEM_Registration::status_id_wait_list,
1094
-                    false,
1095
-                    'sentence'
1096
-                ),
1097
-            ),
1098
-            'incomplete_status' => array(
1099
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1100
-                'desc'  => EEH_Template::pretty_status(
1101
-                    EEM_Registration::status_id_incomplete,
1102
-                    false,
1103
-                    'sentence'
1104
-                ),
1105
-            ),
1106
-            'not_approved'      => array(
1107
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1108
-                'desc'  => EEH_Template::pretty_status(
1109
-                    EEM_Registration::status_id_not_approved,
1110
-                    false,
1111
-                    'sentence'
1112
-                ),
1113
-            ),
1114
-            'declined_status'   => array(
1115
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1116
-                'desc'  => EEH_Template::pretty_status(
1117
-                    EEM_Registration::status_id_declined,
1118
-                    false,
1119
-                    'sentence'
1120
-                ),
1121
-            ),
1122
-            'cancelled_status'  => array(
1123
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1124
-                'desc'  => EEH_Template::pretty_status(
1125
-                    EEM_Registration::status_id_cancelled,
1126
-                    false,
1127
-                    'sentence'
1128
-                ),
1129
-            ),
1130
-        );
1131
-        return array_merge($fc_items, $sc_items);
1132
-    }
1133
-
1134
-
1135
-
1136
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1137
-
1138
-
1139
-
1140
-    /**
1141
-     * @throws DomainException
1142
-     * @throws EE_Error
1143
-     * @throws InvalidArgumentException
1144
-     * @throws InvalidDataTypeException
1145
-     * @throws InvalidInterfaceException
1146
-     * @throws ReflectionException
1147
-     */
1148
-    protected function _registrations_overview_list_table()
1149
-    {
1150
-        $this->appendAddNewRegistrationButtonToPageTitle();
1151
-        $header_text = '';
1152
-        $admin_page_header_decorators = [
1153
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1154
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1155
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1156
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1157
-        ];
1158
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1159
-            $filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1160
-            $header_text = $filter_header_decorator->getHeaderText($header_text);
1161
-        }
1162
-        $this->_template_args['admin_page_header'] = $header_text;
1163
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1164
-        $this->display_admin_list_table_page_with_no_sidebar();
1165
-    }
1166
-
1167
-
1168
-    /**
1169
-     * @throws EE_Error
1170
-     * @throws InvalidArgumentException
1171
-     * @throws InvalidDataTypeException
1172
-     * @throws InvalidInterfaceException
1173
-     */
1174
-    private function appendAddNewRegistrationButtonToPageTitle()
1175
-    {
1176
-        $EVT_ID = ! empty($this->_req_data['event_id'])
1177
-            ? absint($this->_req_data['event_id'])
1178
-            : 0;
1179
-        if ($EVT_ID
1180
-            && EE_Registry::instance()->CAP->current_user_can(
1181
-                'ee_edit_registrations',
1182
-                'espresso_registrations_new_registration',
1183
-                $EVT_ID
1184
-            )
1185
-        ) {
1186
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1187
-                'new_registration',
1188
-                'add-registrant',
1189
-                array('event_id' => $EVT_ID),
1190
-                'add-new-h2'
1191
-            );
1192
-        }
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * This sets the _registration property for the registration details screen
1198
-     *
1199
-     * @access private
1200
-     * @return bool
1201
-     * @throws EE_Error
1202
-     * @throws InvalidArgumentException
1203
-     * @throws InvalidDataTypeException
1204
-     * @throws InvalidInterfaceException
1205
-     */
1206
-    private function _set_registration_object()
1207
-    {
1208
-        // get out if we've already set the object
1209
-        if ($this->_registration instanceof EE_Registration) {
1210
-            return true;
1211
-        }
1212
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1213
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1214
-            return true;
1215
-        }
1216
-        $error_msg = sprintf(
1217
-            esc_html__(
1218
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1219
-                'event_espresso'
1220
-            ),
1221
-            $REG_ID
1222
-        );
1223
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1224
-        $this->_registration = null;
1225
-        return false;
1226
-    }
1227
-
1228
-
1229
-    /**
1230
-     * Used to retrieve registrations for the list table.
1231
-     *
1232
-     * @param int  $per_page
1233
-     * @param bool $count
1234
-     * @param bool $this_month
1235
-     * @param bool $today
1236
-     * @return EE_Registration[]|int
1237
-     * @throws EE_Error
1238
-     * @throws InvalidArgumentException
1239
-     * @throws InvalidDataTypeException
1240
-     * @throws InvalidInterfaceException
1241
-     */
1242
-    public function get_registrations(
1243
-        $per_page = 10,
1244
-        $count = false,
1245
-        $this_month = false,
1246
-        $today = false
1247
-    ) {
1248
-        if ($this_month) {
1249
-            $this->_req_data['status'] = 'month';
1250
-        }
1251
-        if ($today) {
1252
-            $this->_req_data['status'] = 'today';
1253
-        }
1254
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1255
-        /**
1256
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1257
-         *
1258
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1259
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1260
-         *                             or if you have the development copy of EE you can view this at the path:
1261
-         *                             /docs/G--Model-System/model-query-params.md
1262
-         */
1263
-        $query_params['group_by'] = '';
1264
-
1265
-        return $count
1266
-            ? $this->getRegistrationModel()->count($query_params)
1267
-            /** @type EE_Registration[] */
1268
-            : $this->getRegistrationModel()->get_all($query_params);
1269
-    }
1270
-
1271
-
1272
-    /**
1273
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1274
-     * Note: this listens to values on the request for some of the query parameters.
1275
-     *
1276
-     * @param array $request
1277
-     * @param int   $per_page
1278
-     * @param bool  $count
1279
-     * @return array
1280
-     * @throws EE_Error
1281
-     * @throws InvalidArgumentException
1282
-     * @throws InvalidDataTypeException
1283
-     * @throws InvalidInterfaceException
1284
-     */
1285
-    protected function _get_registration_query_parameters(
1286
-        $request = array(),
1287
-        $per_page = 10,
1288
-        $count = false
1289
-    ) {
1290
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1291
-        $list_table_query_builder = $this->getLoader()->getNew(
1292
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1293
-            [ $request ]
1294
-        );
1295
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1296
-    }
1297
-
1298
-
1299
-    public function get_registration_status_array()
1300
-    {
1301
-        return self::$_reg_status;
1302
-    }
1303
-
1304
-
1305
-
1306
-
1307
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1308
-    /**
1309
-     *        generates HTML for the View Registration Details Admin page
1310
-     *
1311
-     * @access protected
1312
-     * @return void
1313
-     * @throws DomainException
1314
-     * @throws EE_Error
1315
-     * @throws InvalidArgumentException
1316
-     * @throws InvalidDataTypeException
1317
-     * @throws InvalidInterfaceException
1318
-     * @throws EntityNotFoundException
1319
-     * @throws ReflectionException
1320
-     */
1321
-    protected function _registration_details()
1322
-    {
1323
-        $this->_template_args = array();
1324
-        $this->_set_registration_object();
1325
-        if (is_object($this->_registration)) {
1326
-            $transaction = $this->_registration->transaction()
1327
-                ? $this->_registration->transaction()
1328
-                : EE_Transaction::new_instance();
1329
-            $this->_session = $transaction->session_data();
1330
-            $event_id = $this->_registration->event_ID();
1331
-            $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1332
-            $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1333
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1334
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1335
-            $this->_template_args['grand_total'] = $transaction->total();
1336
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1337
-            // link back to overview
1338
-            $this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1339
-            $this->_template_args['registration'] = $this->_registration;
1340
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1341
-                array(
1342
-                    'action'   => 'default',
1343
-                    'event_id' => $event_id,
1344
-                ),
1345
-                REG_ADMIN_URL
1346
-            );
1347
-            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1348
-                array(
1349
-                    'action' => 'default',
1350
-                    'EVT_ID' => $event_id,
1351
-                    'page'   => 'espresso_transactions',
1352
-                ),
1353
-                admin_url('admin.php')
1354
-            );
1355
-            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1356
-                array(
1357
-                    'page'   => 'espresso_events',
1358
-                    'action' => 'edit',
1359
-                    'post'   => $event_id,
1360
-                ),
1361
-                admin_url('admin.php')
1362
-            );
1363
-            // next and previous links
1364
-            $next_reg = $this->_registration->next(
1365
-                null,
1366
-                array(),
1367
-                'REG_ID'
1368
-            );
1369
-            $this->_template_args['next_registration'] = $next_reg
1370
-                ? $this->_next_link(
1371
-                    EE_Admin_Page::add_query_args_and_nonce(
1372
-                        array(
1373
-                            'action'  => 'view_registration',
1374
-                            '_REG_ID' => $next_reg['REG_ID'],
1375
-                        ),
1376
-                        REG_ADMIN_URL
1377
-                    ),
1378
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1379
-                )
1380
-                : '';
1381
-            $previous_reg = $this->_registration->previous(
1382
-                null,
1383
-                array(),
1384
-                'REG_ID'
1385
-            );
1386
-            $this->_template_args['previous_registration'] = $previous_reg
1387
-                ? $this->_previous_link(
1388
-                    EE_Admin_Page::add_query_args_and_nonce(
1389
-                        array(
1390
-                            'action'  => 'view_registration',
1391
-                            '_REG_ID' => $previous_reg['REG_ID'],
1392
-                        ),
1393
-                        REG_ADMIN_URL
1394
-                    ),
1395
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1396
-                )
1397
-                : '';
1398
-            // grab header
1399
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1400
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
1401
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1402
-                $template_path,
1403
-                $this->_template_args,
1404
-                true
1405
-            );
1406
-        } else {
1407
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1408
-        }
1409
-        // the details template wrapper
1410
-        $this->display_admin_page_with_sidebar();
1411
-    }
1412
-
1413
-
1414
-    /**
1415
-     * @throws EE_Error
1416
-     * @throws InvalidArgumentException
1417
-     * @throws InvalidDataTypeException
1418
-     * @throws InvalidInterfaceException
1419
-     * @throws ReflectionException
1420
-     * @since 4.10.2.p
1421
-     */
1422
-    protected function _registration_details_metaboxes()
1423
-    {
1424
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1425
-        $this->_set_registration_object();
1426
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1427
-        add_meta_box(
1428
-            'edit-reg-status-mbox',
1429
-            esc_html__('Registration Status', 'event_espresso'),
1430
-            array($this, 'set_reg_status_buttons_metabox'),
1431
-            $this->wp_page_slug,
1432
-            'normal',
1433
-            'high'
1434
-        );
1435
-        add_meta_box(
1436
-            'edit-reg-details-mbox',
1437
-            esc_html__('Registration Details', 'event_espresso'),
1438
-            array($this, '_reg_details_meta_box'),
1439
-            $this->wp_page_slug,
1440
-            'normal',
1441
-            'high'
1442
-        );
1443
-        if ($attendee instanceof EE_Attendee
1444
-            && EE_Registry::instance()->CAP->current_user_can(
1445
-                'ee_read_registration',
1446
-                'edit-reg-questions-mbox',
1447
-                $this->_registration->ID()
1448
-            )
1449
-        ) {
1450
-            add_meta_box(
1451
-                'edit-reg-questions-mbox',
1452
-                esc_html__('Registration Form Answers', 'event_espresso'),
1453
-                array($this, '_reg_questions_meta_box'),
1454
-                $this->wp_page_slug,
1455
-                'normal',
1456
-                'high'
1457
-            );
1458
-        }
1459
-        add_meta_box(
1460
-            'edit-reg-registrant-mbox',
1461
-            esc_html__('Contact Details', 'event_espresso'),
1462
-            array($this, '_reg_registrant_side_meta_box'),
1463
-            $this->wp_page_slug,
1464
-            'side',
1465
-            'high'
1466
-        );
1467
-        if ($this->_registration->group_size() > 1) {
1468
-            add_meta_box(
1469
-                'edit-reg-attendees-mbox',
1470
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1471
-                array($this, '_reg_attendees_meta_box'),
1472
-                $this->wp_page_slug,
1473
-                'normal',
1474
-                'high'
1475
-            );
1476
-        }
1477
-    }
1478
-
1479
-
1480
-    /**
1481
-     * set_reg_status_buttons_metabox
1482
-     *
1483
-     * @access protected
1484
-     * @return string
1485
-     * @throws EE_Error
1486
-     * @throws EntityNotFoundException
1487
-     * @throws InvalidArgumentException
1488
-     * @throws InvalidDataTypeException
1489
-     * @throws InvalidInterfaceException
1490
-     * @throws ReflectionException
1491
-     */
1492
-    public function set_reg_status_buttons_metabox()
1493
-    {
1494
-        $this->_set_registration_object();
1495
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1496
-        echo $change_reg_status_form->form_open(
1497
-            self::add_query_args_and_nonce(
1498
-                array(
1499
-                    'action' => 'change_reg_status',
1500
-                ),
1501
-                REG_ADMIN_URL
1502
-            )
1503
-        );
1504
-        echo $change_reg_status_form->get_html();
1505
-        echo $change_reg_status_form->form_close();
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 = 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'     => array(
1525
-                'return'             => new EE_Hidden_Input(
1526
-                    array(
1527
-                        'name'    => 'return',
1528
-                        'default' => 'view_registration',
1529
-                    )
1530
-                ),
1531
-                'REG_ID'             => new EE_Hidden_Input(
1532
-                    array(
1533
-                        'name'    => 'REG_ID',
1534
-                        'default' => $this->_registration->ID(),
1535
-                    )
1536
-                ),
1537
-                'current_status'     => new EE_Form_Section_HTML(
1538
-                    EEH_HTML::table(
1539
-                        EEH_HTML::tr(
1540
-                            EEH_HTML::th(
1541
-                                EEH_HTML::label(
1542
-                                    EEH_HTML::strong(
1543
-                                        esc_html__('Current Registration Status', 'event_espresso')
1544
-                                    )
1545
-                                )
1546
-                            )
1547
-                            . EEH_HTML::td(
1548
-                                EEH_HTML::strong(
1549
-                                    $this->_registration->pretty_status(),
1550
-                                    '',
1551
-                                    'status-' . $this->_registration->status_ID(),
1552
-                                    'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1553
-                                )
1554
-                            )
1555
-                        )
1556
-                    )
1557
-                )
1558
-            )
1559
-        );
1560
-        if (EE_Registry::instance()->CAP->current_user_can(
1561
-            'ee_edit_registration',
1562
-            'toggle_registration_status',
1563
-            $this->_registration->ID()
1564
-        )) {
1565
-            $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1566
-                $this->_get_reg_statuses(),
1567
-                array(
1568
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1569
-                    'default'         => $this->_registration->status_ID(),
1570
-                )
1571
-            );
1572
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1573
-                array(
1574
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1575
-                    'default'         => false,
1576
-                    'html_help_text'  => esc_html__(
1577
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1578
-                        'event_espresso'
1579
-                    )
1580
-                )
1581
-            );
1582
-            $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1583
-                array(
1584
-                    'html_class'      => 'button-primary',
1585
-                    'html_label_text' => '&nbsp;',
1586
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1587
-                )
1588
-            );
1589
-        }
1590
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1591
-    }
1592
-
1593
-
1594
-    /**
1595
-     * Returns an array of all the buttons for the various statuses and switch status actions
1596
-     *
1597
-     * @return array
1598
-     * @throws EE_Error
1599
-     * @throws InvalidArgumentException
1600
-     * @throws InvalidDataTypeException
1601
-     * @throws InvalidInterfaceException
1602
-     * @throws EntityNotFoundException
1603
-     */
1604
-    protected function _get_reg_statuses()
1605
-    {
1606
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1607
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1608
-        // get current reg status
1609
-        $current_status = $this->_registration->status_ID();
1610
-        // is registration for free event? This will determine whether to display the pending payment option
1611
-        if ($current_status !== EEM_Registration::status_id_pending_payment
1612
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1613
-        ) {
1614
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1615
-        }
1616
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1617
-    }
1618
-
1619
-
1620
-    /**
1621
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1622
-     *
1623
-     * @param bool $status REG status given for changing registrations to.
1624
-     * @param bool $notify Whether to send messages notifications or not.
1625
-     * @return array (array with reg_id(s) updated and whether update was successful.
1626
-     * @throws DomainException
1627
-     * @throws EE_Error
1628
-     * @throws EntityNotFoundException
1629
-     * @throws InvalidArgumentException
1630
-     * @throws InvalidDataTypeException
1631
-     * @throws InvalidInterfaceException
1632
-     * @throws ReflectionException
1633
-     * @throws RuntimeException
1634
-     */
1635
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1636
-    {
1637
-        if (isset($this->_req_data['reg_status_change_form'])) {
1638
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1639
-                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1640
-                : array();
1641
-        } else {
1642
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1643
-                ? (array) $this->_req_data['_REG_ID']
1644
-                : array();
1645
-        }
1646
-        // sanitize $REG_IDs
1647
-        $REG_IDs = array_map('absint', $REG_IDs);
1648
-        // and remove empty entries
1649
-        $REG_IDs = array_filter($REG_IDs);
1650
-
1651
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1652
-
1653
-        /**
1654
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1655
-         * Currently this value is used downstream by the _process_resend_registration method.
1656
-         *
1657
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1658
-         * @param bool                     $status           The status registrations were changed to.
1659
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1660
-         * @param Registrations_Admin_Page $admin_page_object
1661
-         */
1662
-        $this->_req_data['_REG_ID'] = apply_filters(
1663
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1664
-            $result['REG_ID'],
1665
-            $status,
1666
-            $result['success'],
1667
-            $this
1668
-        );
1669
-
1670
-        // notify?
1671
-        if ($notify
1672
-            && $result['success']
1673
-            && ! empty($this->_req_data['_REG_ID'])
1674
-            && EE_Registry::instance()->CAP->current_user_can(
1675
-                'ee_send_message',
1676
-                'espresso_registrations_resend_registration'
1677
-            )
1678
-        ) {
1679
-            $this->_process_resend_registration();
1680
-        }
1681
-        return $result;
1682
-    }
1683
-
1684
-
1685
-    /**
1686
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1687
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1688
-     *
1689
-     * @param array  $REG_IDs
1690
-     * @param string $status
1691
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1692
-     *                        slug sent with setting the registration status.
1693
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1694
-     * @throws EE_Error
1695
-     * @throws InvalidArgumentException
1696
-     * @throws InvalidDataTypeException
1697
-     * @throws InvalidInterfaceException
1698
-     * @throws ReflectionException
1699
-     * @throws RuntimeException
1700
-     * @throws EntityNotFoundException
1701
-     * @throws DomainException
1702
-     */
1703
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1704
-    {
1705
-        $success = false;
1706
-        // typecast $REG_IDs
1707
-        $REG_IDs = (array) $REG_IDs;
1708
-        if (! empty($REG_IDs)) {
1709
-            $success = true;
1710
-            // set default status if none is passed
1711
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1712
-            $status_context = $notify
1713
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1714
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1715
-            // loop through REG_ID's and change status
1716
-            foreach ($REG_IDs as $REG_ID) {
1717
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1718
-                if ($registration instanceof EE_Registration) {
1719
-                    $registration->set_status(
1720
-                        $status,
1721
-                        false,
1722
-                        new Context(
1723
-                            $status_context,
1724
-                            esc_html__(
1725
-                                'Manually triggered status change on a Registration Admin Page route.',
1726
-                                'event_espresso'
1727
-                            )
1728
-                        )
1729
-                    );
1730
-                    $result = $registration->save();
1731
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1732
-                    $success = $result !== false ? $success : false;
1733
-                }
1734
-            }
1735
-        }
1736
-
1737
-        // return $success and processed registrations
1738
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1739
-    }
1740
-
1741
-
1742
-    /**
1743
-     * Common logic for setting up success message and redirecting to appropriate route
1744
-     *
1745
-     * @param string $STS_ID status id for the registration changed to
1746
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1747
-     * @return void
1748
-     * @throws DomainException
1749
-     * @throws EE_Error
1750
-     * @throws EntityNotFoundException
1751
-     * @throws InvalidArgumentException
1752
-     * @throws InvalidDataTypeException
1753
-     * @throws InvalidInterfaceException
1754
-     * @throws ReflectionException
1755
-     * @throws RuntimeException
1756
-     */
1757
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1758
-    {
1759
-        $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1760
-            : array('success' => false);
1761
-        $success = isset($result['success']) && $result['success'];
1762
-        // setup success message
1763
-        if ($success) {
1764
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1765
-                $msg = sprintf(
1766
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1767
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1768
-                );
1769
-            } else {
1770
-                $msg = sprintf(
1771
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1772
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1773
-                );
1774
-            }
1775
-            EE_Error::add_success($msg);
1776
-        } else {
1777
-            EE_Error::add_error(
1778
-                esc_html__(
1779
-                    'Something went wrong, and the status was not changed',
1780
-                    'event_espresso'
1781
-                ),
1782
-                __FILE__,
1783
-                __LINE__,
1784
-                __FUNCTION__
1785
-            );
1786
-        }
1787
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] === 'view_registration') {
1788
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1789
-        } else {
1790
-            $route = array('action' => 'default');
1791
-        }
1792
-        $route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1793
-        $this->_redirect_after_action($success, '', '', $route, true);
1794
-    }
1795
-
1796
-
1797
-    /**
1798
-     * incoming reg status change from reg details page.
1799
-     *
1800
-     * @return void
1801
-     * @throws EE_Error
1802
-     * @throws EntityNotFoundException
1803
-     * @throws InvalidArgumentException
1804
-     * @throws InvalidDataTypeException
1805
-     * @throws InvalidInterfaceException
1806
-     * @throws ReflectionException
1807
-     * @throws RuntimeException
1808
-     * @throws DomainException
1809
-     */
1810
-    protected function _change_reg_status()
1811
-    {
1812
-        $this->_req_data['return'] = 'view_registration';
1813
-        // set notify based on whether the send notifications toggle is set or not
1814
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1815
-        // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1816
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1817
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1818
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1819
-            case EEM_Registration::status_id_approved:
1820
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1821
-                $this->approve_registration($notify);
1822
-                break;
1823
-            case EEM_Registration::status_id_pending_payment:
1824
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1825
-                $this->pending_registration($notify);
1826
-                break;
1827
-            case EEM_Registration::status_id_not_approved:
1828
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1829
-                $this->not_approve_registration($notify);
1830
-                break;
1831
-            case EEM_Registration::status_id_declined:
1832
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1833
-                $this->decline_registration($notify);
1834
-                break;
1835
-            case EEM_Registration::status_id_cancelled:
1836
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1837
-                $this->cancel_registration($notify);
1838
-                break;
1839
-            case EEM_Registration::status_id_wait_list:
1840
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1841
-                $this->wait_list_registration($notify);
1842
-                break;
1843
-            case EEM_Registration::status_id_incomplete:
1844
-            default:
1845
-                $result['success'] = false;
1846
-                unset($this->_req_data['return']);
1847
-                $this->_reg_status_change_return('', false);
1848
-                break;
1849
-        }
1850
-    }
1851
-
1852
-
1853
-    /**
1854
-     * Callback for bulk action routes.
1855
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1856
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1857
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1858
-     * when an action is happening on just a single registration).
1859
-     *
1860
-     * @param      $action
1861
-     * @param bool $notify
1862
-     */
1863
-    protected function bulk_action_on_registrations($action, $notify = false)
1864
-    {
1865
-        do_action(
1866
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1867
-            $this,
1868
-            $action,
1869
-            $notify
1870
-        );
1871
-        $method = $action . '_registration';
1872
-        if (method_exists($this, $method)) {
1873
-            $this->$method($notify);
1874
-        }
1875
-    }
1876
-
1877
-
1878
-    /**
1879
-     * approve_registration
1880
-     *
1881
-     * @access protected
1882
-     * @param bool $notify whether or not to notify the registrant about their approval.
1883
-     * @return void
1884
-     * @throws EE_Error
1885
-     * @throws EntityNotFoundException
1886
-     * @throws InvalidArgumentException
1887
-     * @throws InvalidDataTypeException
1888
-     * @throws InvalidInterfaceException
1889
-     * @throws ReflectionException
1890
-     * @throws RuntimeException
1891
-     * @throws DomainException
1892
-     */
1893
-    protected function approve_registration($notify = false)
1894
-    {
1895
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1896
-    }
1897
-
1898
-
1899
-    /**
1900
-     *        decline_registration
1901
-     *
1902
-     * @access protected
1903
-     * @param bool $notify whether or not to notify the registrant about their status change.
1904
-     * @return void
1905
-     * @throws EE_Error
1906
-     * @throws EntityNotFoundException
1907
-     * @throws InvalidArgumentException
1908
-     * @throws InvalidDataTypeException
1909
-     * @throws InvalidInterfaceException
1910
-     * @throws ReflectionException
1911
-     * @throws RuntimeException
1912
-     * @throws DomainException
1913
-     */
1914
-    protected function decline_registration($notify = false)
1915
-    {
1916
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1917
-    }
1918
-
1919
-
1920
-    /**
1921
-     *        cancel_registration
1922
-     *
1923
-     * @access protected
1924
-     * @param bool $notify whether or not to notify the registrant about their status change.
1925
-     * @return void
1926
-     * @throws EE_Error
1927
-     * @throws EntityNotFoundException
1928
-     * @throws InvalidArgumentException
1929
-     * @throws InvalidDataTypeException
1930
-     * @throws InvalidInterfaceException
1931
-     * @throws ReflectionException
1932
-     * @throws RuntimeException
1933
-     * @throws DomainException
1934
-     */
1935
-    protected function cancel_registration($notify = false)
1936
-    {
1937
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1938
-    }
1939
-
1940
-
1941
-    /**
1942
-     *        not_approve_registration
1943
-     *
1944
-     * @access protected
1945
-     * @param bool $notify whether or not to notify the registrant about their status change.
1946
-     * @return void
1947
-     * @throws EE_Error
1948
-     * @throws EntityNotFoundException
1949
-     * @throws InvalidArgumentException
1950
-     * @throws InvalidDataTypeException
1951
-     * @throws InvalidInterfaceException
1952
-     * @throws ReflectionException
1953
-     * @throws RuntimeException
1954
-     * @throws DomainException
1955
-     */
1956
-    protected function not_approve_registration($notify = false)
1957
-    {
1958
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1959
-    }
1960
-
1961
-
1962
-    /**
1963
-     *        decline_registration
1964
-     *
1965
-     * @access protected
1966
-     * @param bool $notify whether or not to notify the registrant about their status change.
1967
-     * @return void
1968
-     * @throws EE_Error
1969
-     * @throws EntityNotFoundException
1970
-     * @throws InvalidArgumentException
1971
-     * @throws InvalidDataTypeException
1972
-     * @throws InvalidInterfaceException
1973
-     * @throws ReflectionException
1974
-     * @throws RuntimeException
1975
-     * @throws DomainException
1976
-     */
1977
-    protected function pending_registration($notify = false)
1978
-    {
1979
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1980
-    }
1981
-
1982
-
1983
-    /**
1984
-     * waitlist_registration
1985
-     *
1986
-     * @access protected
1987
-     * @param bool $notify whether or not to notify the registrant about their status change.
1988
-     * @return void
1989
-     * @throws EE_Error
1990
-     * @throws EntityNotFoundException
1991
-     * @throws InvalidArgumentException
1992
-     * @throws InvalidDataTypeException
1993
-     * @throws InvalidInterfaceException
1994
-     * @throws ReflectionException
1995
-     * @throws RuntimeException
1996
-     * @throws DomainException
1997
-     */
1998
-    protected function wait_list_registration($notify = false)
1999
-    {
2000
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2001
-    }
2002
-
2003
-
2004
-    /**
2005
-     *        generates HTML for the Registration main meta box
2006
-     *
2007
-     * @access public
2008
-     * @return void
2009
-     * @throws DomainException
2010
-     * @throws EE_Error
2011
-     * @throws InvalidArgumentException
2012
-     * @throws InvalidDataTypeException
2013
-     * @throws InvalidInterfaceException
2014
-     * @throws ReflectionException
2015
-     * @throws EntityNotFoundException
2016
-     */
2017
-    public function _reg_details_meta_box()
2018
-    {
2019
-        EEH_Autoloader::register_line_item_display_autoloaders();
2020
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2021
-        EE_Registry::instance()->load_helper('Line_Item');
2022
-        $transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2023
-            : EE_Transaction::new_instance();
2024
-        $this->_session = $transaction->session_data();
2025
-        $filters = new EE_Line_Item_Filter_Collection();
2026
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2027
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
2028
-        $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2029
-            $filters,
2030
-            $transaction->total_line_item()
2031
-        );
2032
-        $filtered_line_item_tree = $line_item_filter_processor->process();
2033
-        $line_item_display = new EE_Line_Item_Display(
2034
-            'reg_admin_table',
2035
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2036
-        );
2037
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2038
-            $filtered_line_item_tree,
2039
-            array('EE_Registration' => $this->_registration)
2040
-        );
2041
-        $attendee = $this->_registration->attendee();
2042
-        if (EE_Registry::instance()->CAP->current_user_can(
2043
-            'ee_read_transaction',
2044
-            'espresso_transactions_view_transaction'
2045
-        )) {
2046
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2047
-                EE_Admin_Page::add_query_args_and_nonce(
2048
-                    array(
2049
-                        'action' => 'view_transaction',
2050
-                        'TXN_ID' => $transaction->ID(),
2051
-                    ),
2052
-                    TXN_ADMIN_URL
2053
-                ),
2054
-                esc_html__(' View Transaction', 'event_espresso'),
2055
-                'button secondary-button right',
2056
-                'dashicons dashicons-cart'
2057
-            );
2058
-        } else {
2059
-            $this->_template_args['view_transaction_button'] = '';
2060
-        }
2061
-        if ($attendee instanceof EE_Attendee
2062
-            && EE_Registry::instance()->CAP->current_user_can(
2063
-                'ee_send_message',
2064
-                'espresso_registrations_resend_registration'
2065
-            )
2066
-        ) {
2067
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2068
-                EE_Admin_Page::add_query_args_and_nonce(
2069
-                    array(
2070
-                        'action'      => 'resend_registration',
2071
-                        '_REG_ID'     => $this->_registration->ID(),
2072
-                        'redirect_to' => 'view_registration',
2073
-                    ),
2074
-                    REG_ADMIN_URL
2075
-                ),
2076
-                esc_html__(' Resend Registration', 'event_espresso'),
2077
-                'button secondary-button right',
2078
-                'dashicons dashicons-email-alt'
2079
-            );
2080
-        } else {
2081
-            $this->_template_args['resend_registration_button'] = '';
2082
-        }
2083
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2084
-        $payment = $transaction->get_first_related('Payment');
2085
-        $payment = ! $payment instanceof EE_Payment
2086
-            ? EE_Payment::new_instance()
2087
-            : $payment;
2088
-        $payment_method = $payment->get_first_related('Payment_Method');
2089
-        $payment_method = ! $payment_method instanceof EE_Payment_Method
2090
-            ? EE_Payment_Method::new_instance()
2091
-            : $payment_method;
2092
-        $reg_details = array(
2093
-            'payment_method'       => $payment_method->name(),
2094
-            'response_msg'         => $payment->gateway_response(),
2095
-            'registration_id'      => $this->_registration->get('REG_code'),
2096
-            'registration_session' => $this->_registration->session_ID(),
2097
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2098
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2099
-        );
2100
-        if (isset($reg_details['registration_id'])) {
2101
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2102
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2103
-                'Registration ID',
2104
-                'event_espresso'
2105
-            );
2106
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2107
-        }
2108
-        if (isset($reg_details['payment_method'])) {
2109
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2110
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2111
-                'Most Recent Payment Method',
2112
-                'event_espresso'
2113
-            );
2114
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2115
-            $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2116
-            $this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2117
-                'Payment method response',
2118
-                'event_espresso'
2119
-            );
2120
-            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2121
-        }
2122
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2123
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2124
-            'Registration Session',
2125
-            'event_espresso'
2126
-        );
2127
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2128
-        $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2129
-        $this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2130
-            'Registration placed from IP',
2131
-            'event_espresso'
2132
-        );
2133
-        $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2134
-        $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2135
-        $this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2136
-            'Registrant User Agent',
2137
-            'event_espresso'
2138
-        );
2139
-        $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2140
-        $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2141
-            array(
2142
-                'action'   => 'default',
2143
-                'event_id' => $this->_registration->event_ID(),
2144
-            ),
2145
-            REG_ADMIN_URL
2146
-        );
2147
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2148
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2149
-        $template_path =
2150
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2151
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2152
-    }
2153
-
2154
-
2155
-    /**
2156
-     * generates HTML for the Registration Questions meta box.
2157
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2158
-     * otherwise uses new forms system
2159
-     *
2160
-     * @access public
2161
-     * @return void
2162
-     * @throws DomainException
2163
-     * @throws EE_Error
2164
-     * @throws InvalidArgumentException
2165
-     * @throws InvalidDataTypeException
2166
-     * @throws InvalidInterfaceException
2167
-     * @throws ReflectionException
2168
-     */
2169
-    public function _reg_questions_meta_box()
2170
-    {
2171
-        // allow someone to override this method entirely
2172
-        if (apply_filters(
2173
-            'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2174
-            true,
2175
-            $this,
2176
-            $this->_registration
2177
-        )) {
2178
-            $form = $this->_get_reg_custom_questions_form(
2179
-                $this->_registration->ID()
2180
-            );
2181
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2182
-                ? $form->get_html_and_js()
2183
-                : '';
2184
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2185
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2186
-            $template_path =
2187
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2188
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2189
-        }
2190
-    }
2191
-
2192
-
2193
-    /**
2194
-     * form_before_question_group
2195
-     *
2196
-     * @deprecated    as of 4.8.32.rc.000
2197
-     * @access        public
2198
-     * @param        string $output
2199
-     * @return        string
2200
-     */
2201
-    public function form_before_question_group($output)
2202
-    {
2203
-        EE_Error::doing_it_wrong(
2204
-            __CLASS__ . '::' . __FUNCTION__,
2205
-            esc_html__(
2206
-                '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.',
2207
-                'event_espresso'
2208
-            ),
2209
-            '4.8.32.rc.000'
2210
-        );
2211
-        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
+	private static $_reg_status;
38
+
39
+	/**
40
+	 * Form for displaying the custom questions for this registration.
41
+	 * This gets used a few times throughout the request so its best to cache it
42
+	 *
43
+	 * @var EE_Registration_Custom_Questions_Form
44
+	 */
45
+	protected $_reg_custom_questions_form = null;
46
+
47
+	/**
48
+	 * @var EEM_Registration $registration_model
49
+	 */
50
+	private $registration_model;
51
+
52
+	/**
53
+	 * @var EEM_Attendee $attendee_model
54
+	 */
55
+	private $attendee_model;
56
+
57
+	/**
58
+	 * @var EEM_Event $event_model
59
+	 */
60
+	private $event_model;
61
+
62
+	/**
63
+	 * @var EEM_Status $status_model
64
+	 */
65
+	private $status_model;
66
+
67
+
68
+	/**
69
+	 * @param bool $routing
70
+	 * @throws EE_Error
71
+	 * @throws InvalidArgumentException
72
+	 * @throws InvalidDataTypeException
73
+	 * @throws InvalidInterfaceException
74
+	 * @throws ReflectionException
75
+	 */
76
+	public function __construct($routing = true)
77
+	{
78
+		parent::__construct($routing);
79
+		add_action('wp_loaded', array($this, 'wp_loaded'));
80
+	}
81
+
82
+	/**
83
+	 * @return EEM_Registration
84
+	 * @throws InvalidArgumentException
85
+	 * @throws InvalidDataTypeException
86
+	 * @throws InvalidInterfaceException
87
+	 * @since 4.10.2.p
88
+	 */
89
+	protected function getRegistrationModel()
90
+	{
91
+		if (! $this->registration_model instanceof EEM_Registration) {
92
+			$this->registration_model = $this->getLoader()->getShared('EEM_Registration');
93
+		}
94
+		return $this->registration_model;
95
+	}
96
+
97
+	/**
98
+	 * @return EEM_Attendee
99
+	 * @throws InvalidArgumentException
100
+	 * @throws InvalidDataTypeException
101
+	 * @throws InvalidInterfaceException
102
+	 * @since 4.10.2.p
103
+	 */
104
+	protected function getAttendeeModel()
105
+	{
106
+		if (! $this->attendee_model instanceof EEM_Attendee) {
107
+			$this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
108
+		}
109
+		return $this->attendee_model;
110
+	}
111
+
112
+
113
+	/**
114
+	 * @return EEM_Event
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidInterfaceException
118
+	 * @since 4.10.2.p
119
+	 */
120
+	protected function getEventModel()
121
+	{
122
+		if (! $this->event_model instanceof EEM_Event) {
123
+			$this->event_model = $this->getLoader()->getShared('EEM_Event');
124
+		}
125
+		return $this->event_model;
126
+	}
127
+
128
+	/**
129
+	 * @return EEM_Status
130
+	 * @throws InvalidArgumentException
131
+	 * @throws InvalidDataTypeException
132
+	 * @throws InvalidInterfaceException
133
+	 * @since 4.10.2.p
134
+	 */
135
+	protected function getStatusModel()
136
+	{
137
+		if (! $this->status_model instanceof EEM_Status) {
138
+			$this->status_model = $this->getLoader()->getShared('EEM_Status');
139
+		}
140
+		return $this->status_model;
141
+	}
142
+
143
+
144
+	public function wp_loaded()
145
+	{
146
+		// when adding a new registration...
147
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
148
+			EE_System::do_not_cache();
149
+			if (! isset($this->_req_data['processing_registration'])
150
+				|| absint($this->_req_data['processing_registration']) !== 1
151
+			) {
152
+				// and it's NOT the attendee information reg step
153
+				// force cookie expiration by setting time to last week
154
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
155
+				// and update the global
156
+				$_COOKIE['ee_registration_added'] = 0;
157
+			}
158
+		}
159
+	}
160
+
161
+
162
+	protected function _init_page_props()
163
+	{
164
+		$this->page_slug = REG_PG_SLUG;
165
+		$this->_admin_base_url = REG_ADMIN_URL;
166
+		$this->_admin_base_path = REG_ADMIN;
167
+		$this->page_label = esc_html__('Registrations', 'event_espresso');
168
+		$this->_cpt_routes = array(
169
+			'add_new_attendee' => 'espresso_attendees',
170
+			'edit_attendee'    => 'espresso_attendees',
171
+			'insert_attendee'  => 'espresso_attendees',
172
+			'update_attendee'  => 'espresso_attendees',
173
+		);
174
+		$this->_cpt_model_names = array(
175
+			'add_new_attendee' => 'EEM_Attendee',
176
+			'edit_attendee'    => 'EEM_Attendee',
177
+		);
178
+		$this->_cpt_edit_routes = array(
179
+			'espresso_attendees' => 'edit_attendee',
180
+		);
181
+		$this->_pagenow_map = array(
182
+			'add_new_attendee' => 'post-new.php',
183
+			'edit_attendee'    => 'post.php',
184
+			'trash'            => 'post.php',
185
+		);
186
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
187
+		// add filters so that the comment urls don't take users to a confusing 404 page
188
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
189
+	}
190
+
191
+
192
+	public function clear_comment_link($link, $comment, $args)
193
+	{
194
+		// gotta make sure this only happens on this route
195
+		$post_type = get_post_type($comment->comment_post_ID);
196
+		if ($post_type === 'espresso_attendees') {
197
+			return '#commentsdiv';
198
+		}
199
+		return $link;
200
+	}
201
+
202
+
203
+	protected function _ajax_hooks()
204
+	{
205
+		// todo: all hooks for registrations ajax goes in here
206
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
207
+	}
208
+
209
+
210
+	protected function _define_page_props()
211
+	{
212
+		$this->_admin_page_title = $this->page_label;
213
+		$this->_labels = array(
214
+			'buttons'                      => array(
215
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
216
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
217
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
218
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
219
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
220
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
221
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
222
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
223
+			),
224
+			'publishbox'                   => array(
225
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
226
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
227
+			),
228
+			'hide_add_button_on_cpt_route' => array(
229
+				'edit_attendee' => true,
230
+			),
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 *        grab url requests and route them
237
+	 *
238
+	 * @access private
239
+	 * @return void
240
+	 * @throws EE_Error
241
+	 */
242
+	public function _set_page_routes()
243
+	{
244
+		$this->_get_registration_status_array();
245
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
246
+			? $this->_req_data['_REG_ID'] : 0;
247
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
248
+			? $this->_req_data['reg_status_change_form']['REG_ID']
249
+			: $reg_id;
250
+		$att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
251
+			? $this->_req_data['ATT_ID'] : 0;
252
+		$att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
253
+			? $this->_req_data['post']
254
+			: $att_id;
255
+		$this->_page_routes = array(
256
+			'default'                             => array(
257
+				'func'       => '_registrations_overview_list_table',
258
+				'capability' => 'ee_read_registrations',
259
+			),
260
+			'view_registration'                   => array(
261
+				'func'       => '_registration_details',
262
+				'capability' => 'ee_read_registration',
263
+				'obj_id'     => $reg_id,
264
+			),
265
+			'edit_registration'                   => array(
266
+				'func'               => '_update_attendee_registration_form',
267
+				'noheader'           => true,
268
+				'headers_sent_route' => 'view_registration',
269
+				'capability'         => 'ee_edit_registration',
270
+				'obj_id'             => $reg_id,
271
+				'_REG_ID'            => $reg_id,
272
+			),
273
+			'trash_registrations'                 => array(
274
+				'func'       => '_trash_or_restore_registrations',
275
+				'args'       => array('trash' => true),
276
+				'noheader'   => true,
277
+				'capability' => 'ee_delete_registrations',
278
+			),
279
+			'restore_registrations'               => array(
280
+				'func'       => '_trash_or_restore_registrations',
281
+				'args'       => array('trash' => false),
282
+				'noheader'   => true,
283
+				'capability' => 'ee_delete_registrations',
284
+			),
285
+			'delete_registrations'                => array(
286
+				'func'       => '_delete_registrations',
287
+				'noheader'   => true,
288
+				'capability' => 'ee_delete_registrations',
289
+			),
290
+			'new_registration'                    => array(
291
+				'func'       => 'new_registration',
292
+				'capability' => 'ee_edit_registrations',
293
+			),
294
+			'process_reg_step'                    => array(
295
+				'func'       => 'process_reg_step',
296
+				'noheader'   => true,
297
+				'capability' => 'ee_edit_registrations',
298
+			),
299
+			'redirect_to_txn'                     => array(
300
+				'func'       => 'redirect_to_txn',
301
+				'noheader'   => true,
302
+				'capability' => 'ee_edit_registrations',
303
+			),
304
+			'change_reg_status'                   => array(
305
+				'func'       => '_change_reg_status',
306
+				'noheader'   => true,
307
+				'capability' => 'ee_edit_registration',
308
+				'obj_id'     => $reg_id,
309
+			),
310
+			'approve_registration'                => array(
311
+				'func'       => 'approve_registration',
312
+				'noheader'   => true,
313
+				'capability' => 'ee_edit_registration',
314
+				'obj_id'     => $reg_id,
315
+			),
316
+			'approve_and_notify_registration'     => array(
317
+				'func'       => 'approve_registration',
318
+				'noheader'   => true,
319
+				'args'       => array(true),
320
+				'capability' => 'ee_edit_registration',
321
+				'obj_id'     => $reg_id,
322
+			),
323
+			'approve_registrations'               => array(
324
+				'func'       => 'bulk_action_on_registrations',
325
+				'noheader'   => true,
326
+				'capability' => 'ee_edit_registrations',
327
+				'args'       => array('approve'),
328
+			),
329
+			'approve_and_notify_registrations'    => array(
330
+				'func'       => 'bulk_action_on_registrations',
331
+				'noheader'   => true,
332
+				'capability' => 'ee_edit_registrations',
333
+				'args'       => array('approve', true),
334
+			),
335
+			'decline_registration'                => array(
336
+				'func'       => 'decline_registration',
337
+				'noheader'   => true,
338
+				'capability' => 'ee_edit_registration',
339
+				'obj_id'     => $reg_id,
340
+			),
341
+			'decline_and_notify_registration'     => array(
342
+				'func'       => 'decline_registration',
343
+				'noheader'   => true,
344
+				'args'       => array(true),
345
+				'capability' => 'ee_edit_registration',
346
+				'obj_id'     => $reg_id,
347
+			),
348
+			'decline_registrations'               => array(
349
+				'func'       => 'bulk_action_on_registrations',
350
+				'noheader'   => true,
351
+				'capability' => 'ee_edit_registrations',
352
+				'args'       => array('decline'),
353
+			),
354
+			'decline_and_notify_registrations'    => array(
355
+				'func'       => 'bulk_action_on_registrations',
356
+				'noheader'   => true,
357
+				'capability' => 'ee_edit_registrations',
358
+				'args'       => array('decline', true),
359
+			),
360
+			'pending_registration'                => array(
361
+				'func'       => 'pending_registration',
362
+				'noheader'   => true,
363
+				'capability' => 'ee_edit_registration',
364
+				'obj_id'     => $reg_id,
365
+			),
366
+			'pending_and_notify_registration'     => array(
367
+				'func'       => 'pending_registration',
368
+				'noheader'   => true,
369
+				'args'       => array(true),
370
+				'capability' => 'ee_edit_registration',
371
+				'obj_id'     => $reg_id,
372
+			),
373
+			'pending_registrations'               => array(
374
+				'func'       => 'bulk_action_on_registrations',
375
+				'noheader'   => true,
376
+				'capability' => 'ee_edit_registrations',
377
+				'args'       => array('pending'),
378
+			),
379
+			'pending_and_notify_registrations'    => array(
380
+				'func'       => 'bulk_action_on_registrations',
381
+				'noheader'   => true,
382
+				'capability' => 'ee_edit_registrations',
383
+				'args'       => array('pending', true),
384
+			),
385
+			'no_approve_registration'             => array(
386
+				'func'       => 'not_approve_registration',
387
+				'noheader'   => true,
388
+				'capability' => 'ee_edit_registration',
389
+				'obj_id'     => $reg_id,
390
+			),
391
+			'no_approve_and_notify_registration'  => array(
392
+				'func'       => 'not_approve_registration',
393
+				'noheader'   => true,
394
+				'args'       => array(true),
395
+				'capability' => 'ee_edit_registration',
396
+				'obj_id'     => $reg_id,
397
+			),
398
+			'no_approve_registrations'            => array(
399
+				'func'       => 'bulk_action_on_registrations',
400
+				'noheader'   => true,
401
+				'capability' => 'ee_edit_registrations',
402
+				'args'       => array('not_approve'),
403
+			),
404
+			'no_approve_and_notify_registrations' => array(
405
+				'func'       => 'bulk_action_on_registrations',
406
+				'noheader'   => true,
407
+				'capability' => 'ee_edit_registrations',
408
+				'args'       => array('not_approve', true),
409
+			),
410
+			'cancel_registration'                 => array(
411
+				'func'       => 'cancel_registration',
412
+				'noheader'   => true,
413
+				'capability' => 'ee_edit_registration',
414
+				'obj_id'     => $reg_id,
415
+			),
416
+			'cancel_and_notify_registration'      => array(
417
+				'func'       => 'cancel_registration',
418
+				'noheader'   => true,
419
+				'args'       => array(true),
420
+				'capability' => 'ee_edit_registration',
421
+				'obj_id'     => $reg_id,
422
+			),
423
+			'cancel_registrations'                => array(
424
+				'func'       => 'bulk_action_on_registrations',
425
+				'noheader'   => true,
426
+				'capability' => 'ee_edit_registrations',
427
+				'args'       => array('cancel'),
428
+			),
429
+			'cancel_and_notify_registrations'     => array(
430
+				'func'       => 'bulk_action_on_registrations',
431
+				'noheader'   => true,
432
+				'capability' => 'ee_edit_registrations',
433
+				'args'       => array('cancel', true),
434
+			),
435
+			'wait_list_registration'              => array(
436
+				'func'       => 'wait_list_registration',
437
+				'noheader'   => true,
438
+				'capability' => 'ee_edit_registration',
439
+				'obj_id'     => $reg_id,
440
+			),
441
+			'wait_list_and_notify_registration'   => array(
442
+				'func'       => 'wait_list_registration',
443
+				'noheader'   => true,
444
+				'args'       => array(true),
445
+				'capability' => 'ee_edit_registration',
446
+				'obj_id'     => $reg_id,
447
+			),
448
+			'contact_list'                        => array(
449
+				'func'       => '_attendee_contact_list_table',
450
+				'capability' => 'ee_read_contacts',
451
+			),
452
+			'add_new_attendee'                    => array(
453
+				'func' => '_create_new_cpt_item',
454
+				'args' => array(
455
+					'new_attendee' => true,
456
+					'capability'   => 'ee_edit_contacts',
457
+				),
458
+			),
459
+			'edit_attendee'                       => array(
460
+				'func'       => '_edit_cpt_item',
461
+				'capability' => 'ee_edit_contacts',
462
+				'obj_id'     => $att_id,
463
+			),
464
+			'duplicate_attendee'                  => array(
465
+				'func'       => '_duplicate_attendee',
466
+				'noheader'   => true,
467
+				'capability' => 'ee_edit_contacts',
468
+				'obj_id'     => $att_id,
469
+			),
470
+			'insert_attendee'                     => array(
471
+				'func'       => '_insert_or_update_attendee',
472
+				'args'       => array(
473
+					'new_attendee' => true,
474
+				),
475
+				'noheader'   => true,
476
+				'capability' => 'ee_edit_contacts',
477
+			),
478
+			'update_attendee'                     => array(
479
+				'func'       => '_insert_or_update_attendee',
480
+				'args'       => array(
481
+					'new_attendee' => false,
482
+				),
483
+				'noheader'   => true,
484
+				'capability' => 'ee_edit_contacts',
485
+				'obj_id'     => $att_id,
486
+			),
487
+			'trash_attendees'                     => array(
488
+				'func'       => '_trash_or_restore_attendees',
489
+				'args'       => array(
490
+					'trash' => 'true',
491
+				),
492
+				'noheader'   => true,
493
+				'capability' => 'ee_delete_contacts',
494
+			),
495
+			'trash_attendee'                      => array(
496
+				'func'       => '_trash_or_restore_attendees',
497
+				'args'       => array(
498
+					'trash' => true,
499
+				),
500
+				'noheader'   => true,
501
+				'capability' => 'ee_delete_contacts',
502
+				'obj_id'     => $att_id,
503
+			),
504
+			'restore_attendees'                   => array(
505
+				'func'       => '_trash_or_restore_attendees',
506
+				'args'       => array(
507
+					'trash' => false,
508
+				),
509
+				'noheader'   => true,
510
+				'capability' => 'ee_delete_contacts',
511
+				'obj_id'     => $att_id,
512
+			),
513
+			'resend_registration'                 => array(
514
+				'func'       => '_resend_registration',
515
+				'noheader'   => true,
516
+				'capability' => 'ee_send_message',
517
+			),
518
+			'registrations_report'                => array(
519
+				'func'       => '_registrations_report',
520
+				'noheader'   => true,
521
+				'capability' => 'ee_read_registrations',
522
+			),
523
+			'contact_list_export'                 => array(
524
+				'func'       => '_contact_list_export',
525
+				'noheader'   => true,
526
+				'capability' => 'export',
527
+			),
528
+			'contact_list_report'                 => array(
529
+				'func'       => '_contact_list_report',
530
+				'noheader'   => true,
531
+				'capability' => 'ee_read_contacts',
532
+			),
533
+		);
534
+	}
535
+
536
+
537
+	protected function _set_page_config()
538
+	{
539
+		$this->_page_config = array(
540
+			'default'           => array(
541
+				'nav'           => array(
542
+					'label' => esc_html__('Overview', 'event_espresso'),
543
+					'order' => 5,
544
+				),
545
+				'help_tabs'     => array(
546
+					'registrations_overview_help_tab'                       => array(
547
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
548
+						'filename' => 'registrations_overview',
549
+					),
550
+					'registrations_overview_table_column_headings_help_tab' => array(
551
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
552
+						'filename' => 'registrations_overview_table_column_headings',
553
+					),
554
+					'registrations_overview_filters_help_tab'               => array(
555
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
556
+						'filename' => 'registrations_overview_filters',
557
+					),
558
+					'registrations_overview_views_help_tab'                 => array(
559
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
560
+						'filename' => 'registrations_overview_views',
561
+					),
562
+					'registrations_regoverview_other_help_tab'              => array(
563
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
564
+						'filename' => 'registrations_overview_other',
565
+					),
566
+				),
567
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
568
+				// 'help_tour'     => array('Registration_Overview_Help_Tour'),
569
+				'qtips'         => array('Registration_List_Table_Tips'),
570
+				'list_table'    => 'EE_Registrations_List_Table',
571
+				'require_nonce' => false,
572
+			),
573
+			'view_registration' => array(
574
+				'nav'           => array(
575
+					'label'      => esc_html__('REG Details', 'event_espresso'),
576
+					'order'      => 15,
577
+					'url'        => isset($this->_req_data['_REG_ID'])
578
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
579
+						: $this->_admin_base_url,
580
+					'persistent' => false,
581
+				),
582
+				'help_tabs'     => array(
583
+					'registrations_details_help_tab'                    => array(
584
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
585
+						'filename' => 'registrations_details',
586
+					),
587
+					'registrations_details_table_help_tab'              => array(
588
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
589
+						'filename' => 'registrations_details_table',
590
+					),
591
+					'registrations_details_form_answers_help_tab'       => array(
592
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
593
+						'filename' => 'registrations_details_form_answers',
594
+					),
595
+					'registrations_details_registrant_details_help_tab' => array(
596
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
597
+						'filename' => 'registrations_details_registrant_details',
598
+					),
599
+				),
600
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
601
+				// 'help_tour'     => array('Registration_Details_Help_Tour'),
602
+				'metaboxes'     => array_merge(
603
+					$this->_default_espresso_metaboxes,
604
+					array('_registration_details_metaboxes')
605
+				),
606
+				'require_nonce' => false,
607
+			),
608
+			'new_registration'  => array(
609
+				'nav'           => array(
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'        => array(
617
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
618
+				),
619
+				'require_nonce' => false,
620
+			),
621
+			'add_new_attendee'  => array(
622
+				'nav'           => array(
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
+					array('_publish_post_box', 'attendee_editor_metaboxes')
630
+				),
631
+				'require_nonce' => false,
632
+			),
633
+			'edit_attendee'     => array(
634
+				'nav'           => array(
635
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
636
+					'order'      => 15,
637
+					'persistent' => false,
638
+					'url'        => isset($this->_req_data['ATT_ID'])
639
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
640
+						: $this->_admin_base_url,
641
+				),
642
+				'metaboxes'     => array('attendee_editor_metaboxes'),
643
+				'require_nonce' => false,
644
+			),
645
+			'contact_list'      => array(
646
+				'nav'           => array(
647
+					'label' => esc_html__('Contact List', 'event_espresso'),
648
+					'order' => 20,
649
+				),
650
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
651
+				'help_tabs'     => array(
652
+					'registrations_contact_list_help_tab'                       => array(
653
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
654
+						'filename' => 'registrations_contact_list',
655
+					),
656
+					'registrations_contact-list_table_column_headings_help_tab' => array(
657
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
658
+						'filename' => 'registrations_contact_list_table_column_headings',
659
+					),
660
+					'registrations_contact_list_views_help_tab'                 => array(
661
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
662
+						'filename' => 'registrations_contact_list_views',
663
+					),
664
+					'registrations_contact_list_other_help_tab'                 => array(
665
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
666
+						'filename' => 'registrations_contact_list_other',
667
+					),
668
+				),
669
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
670
+				// 'help_tour'     => array('Contact_List_Help_Tour'),
671
+				'metaboxes'     => array(),
672
+				'require_nonce' => false,
673
+			),
674
+			// override default cpt routes
675
+			'create_new'        => '',
676
+			'edit'              => '',
677
+		);
678
+	}
679
+
680
+
681
+	/**
682
+	 * The below methods aren't used by this class currently
683
+	 */
684
+	protected function _add_screen_options()
685
+	{
686
+	}
687
+
688
+
689
+	protected function _add_feature_pointers()
690
+	{
691
+	}
692
+
693
+
694
+	public function admin_init()
695
+	{
696
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
697
+			'click "Update Registration Questions" to save your changes',
698
+			'event_espresso'
699
+		);
700
+	}
701
+
702
+
703
+	public function admin_notices()
704
+	{
705
+	}
706
+
707
+
708
+	public function admin_footer_scripts()
709
+	{
710
+	}
711
+
712
+
713
+	/**
714
+	 *        get list of registration statuses
715
+	 *
716
+	 * @access private
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(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
+			array('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
+			array('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 = array(
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(true);
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
+			array('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
+			array('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 = 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 = array(
935
+			'all'   => array(
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
+					array(
942
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
943
+					)
944
+				),
945
+			),
946
+			'month' => array(
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
+					array(
953
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
954
+					)
955
+				),
956
+			),
957
+			'today' => array(
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
+					array(
967
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
968
+					)
969
+				),
970
+			),
971
+		);
972
+		if (EE_Registry::instance()->CAP->current_user_can(
973
+			'ee_delete_registrations',
974
+			'espresso_registrations_delete_registration'
975
+		)) {
976
+			$this->_views['incomplete'] = array(
977
+				'slug'        => 'incomplete',
978
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
979
+				'count'       => 0,
980
+				'bulk_action' => array(
981
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
982
+				),
983
+			);
984
+			$this->_views['trash'] = array(
985
+				'slug'        => 'trash',
986
+				'label'       => esc_html__('Trash', 'event_espresso'),
987
+				'count'       => 0,
988
+				'bulk_action' => array(
989
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
990
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
991
+				),
992
+			);
993
+		}
994
+	}
995
+
996
+
997
+	protected function _set_list_table_views_contact_list()
998
+	{
999
+		$this->_views = array(
1000
+			'in_use' => array(
1001
+				'slug'        => 'in_use',
1002
+				'label'       => esc_html__('In Use', 'event_espresso'),
1003
+				'count'       => 0,
1004
+				'bulk_action' => array(
1005
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1006
+				),
1007
+			),
1008
+		);
1009
+		if (EE_Registry::instance()->CAP->current_user_can(
1010
+			'ee_delete_contacts',
1011
+			'espresso_registrations_trash_attendees'
1012
+		)
1013
+		) {
1014
+			$this->_views['trash'] = array(
1015
+				'slug'        => 'trash',
1016
+				'label'       => esc_html__('Trash', 'event_espresso'),
1017
+				'count'       => 0,
1018
+				'bulk_action' => array(
1019
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1020
+				),
1021
+			);
1022
+		}
1023
+	}
1024
+
1025
+
1026
+	protected function _registration_legend_items()
1027
+	{
1028
+		$fc_items = array(
1029
+			'star-icon'        => array(
1030
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1031
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1032
+			),
1033
+			'view_details'     => array(
1034
+				'class' => 'dashicons dashicons-clipboard',
1035
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1036
+			),
1037
+			'edit_attendee'    => array(
1038
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1039
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1040
+			),
1041
+			'view_transaction' => array(
1042
+				'class' => 'dashicons dashicons-cart',
1043
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1044
+			),
1045
+			'view_invoice'     => array(
1046
+				'class' => 'dashicons dashicons-media-spreadsheet',
1047
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1048
+			),
1049
+		);
1050
+		if (EE_Registry::instance()->CAP->current_user_can(
1051
+			'ee_send_message',
1052
+			'espresso_registrations_resend_registration'
1053
+		)) {
1054
+			$fc_items['resend_registration'] = array(
1055
+				'class' => 'dashicons dashicons-email-alt',
1056
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1057
+			);
1058
+		} else {
1059
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
1060
+		}
1061
+		if (EE_Registry::instance()->CAP->current_user_can(
1062
+			'ee_read_global_messages',
1063
+			'view_filtered_messages'
1064
+		)) {
1065
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1066
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1067
+				$fc_items['view_related_messages'] = array(
1068
+					'class' => $related_for_icon['css_class'],
1069
+					'desc'  => $related_for_icon['label'],
1070
+				);
1071
+			}
1072
+		}
1073
+		$sc_items = array(
1074
+			'approved_status'   => array(
1075
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1076
+				'desc'  => EEH_Template::pretty_status(
1077
+					EEM_Registration::status_id_approved,
1078
+					false,
1079
+					'sentence'
1080
+				),
1081
+			),
1082
+			'pending_status'    => array(
1083
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1084
+				'desc'  => EEH_Template::pretty_status(
1085
+					EEM_Registration::status_id_pending_payment,
1086
+					false,
1087
+					'sentence'
1088
+				),
1089
+			),
1090
+			'wait_list'         => array(
1091
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1092
+				'desc'  => EEH_Template::pretty_status(
1093
+					EEM_Registration::status_id_wait_list,
1094
+					false,
1095
+					'sentence'
1096
+				),
1097
+			),
1098
+			'incomplete_status' => array(
1099
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1100
+				'desc'  => EEH_Template::pretty_status(
1101
+					EEM_Registration::status_id_incomplete,
1102
+					false,
1103
+					'sentence'
1104
+				),
1105
+			),
1106
+			'not_approved'      => array(
1107
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1108
+				'desc'  => EEH_Template::pretty_status(
1109
+					EEM_Registration::status_id_not_approved,
1110
+					false,
1111
+					'sentence'
1112
+				),
1113
+			),
1114
+			'declined_status'   => array(
1115
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1116
+				'desc'  => EEH_Template::pretty_status(
1117
+					EEM_Registration::status_id_declined,
1118
+					false,
1119
+					'sentence'
1120
+				),
1121
+			),
1122
+			'cancelled_status'  => array(
1123
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1124
+				'desc'  => EEH_Template::pretty_status(
1125
+					EEM_Registration::status_id_cancelled,
1126
+					false,
1127
+					'sentence'
1128
+				),
1129
+			),
1130
+		);
1131
+		return array_merge($fc_items, $sc_items);
1132
+	}
1133
+
1134
+
1135
+
1136
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1137
+
1138
+
1139
+
1140
+	/**
1141
+	 * @throws DomainException
1142
+	 * @throws EE_Error
1143
+	 * @throws InvalidArgumentException
1144
+	 * @throws InvalidDataTypeException
1145
+	 * @throws InvalidInterfaceException
1146
+	 * @throws ReflectionException
1147
+	 */
1148
+	protected function _registrations_overview_list_table()
1149
+	{
1150
+		$this->appendAddNewRegistrationButtonToPageTitle();
1151
+		$header_text = '';
1152
+		$admin_page_header_decorators = [
1153
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1154
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1155
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1156
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1157
+		];
1158
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1159
+			$filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1160
+			$header_text = $filter_header_decorator->getHeaderText($header_text);
1161
+		}
1162
+		$this->_template_args['admin_page_header'] = $header_text;
1163
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1164
+		$this->display_admin_list_table_page_with_no_sidebar();
1165
+	}
1166
+
1167
+
1168
+	/**
1169
+	 * @throws EE_Error
1170
+	 * @throws InvalidArgumentException
1171
+	 * @throws InvalidDataTypeException
1172
+	 * @throws InvalidInterfaceException
1173
+	 */
1174
+	private function appendAddNewRegistrationButtonToPageTitle()
1175
+	{
1176
+		$EVT_ID = ! empty($this->_req_data['event_id'])
1177
+			? absint($this->_req_data['event_id'])
1178
+			: 0;
1179
+		if ($EVT_ID
1180
+			&& EE_Registry::instance()->CAP->current_user_can(
1181
+				'ee_edit_registrations',
1182
+				'espresso_registrations_new_registration',
1183
+				$EVT_ID
1184
+			)
1185
+		) {
1186
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1187
+				'new_registration',
1188
+				'add-registrant',
1189
+				array('event_id' => $EVT_ID),
1190
+				'add-new-h2'
1191
+			);
1192
+		}
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * This sets the _registration property for the registration details screen
1198
+	 *
1199
+	 * @access private
1200
+	 * @return bool
1201
+	 * @throws EE_Error
1202
+	 * @throws InvalidArgumentException
1203
+	 * @throws InvalidDataTypeException
1204
+	 * @throws InvalidInterfaceException
1205
+	 */
1206
+	private function _set_registration_object()
1207
+	{
1208
+		// get out if we've already set the object
1209
+		if ($this->_registration instanceof EE_Registration) {
1210
+			return true;
1211
+		}
1212
+		$REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1213
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1214
+			return true;
1215
+		}
1216
+		$error_msg = sprintf(
1217
+			esc_html__(
1218
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1219
+				'event_espresso'
1220
+			),
1221
+			$REG_ID
1222
+		);
1223
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1224
+		$this->_registration = null;
1225
+		return false;
1226
+	}
1227
+
1228
+
1229
+	/**
1230
+	 * Used to retrieve registrations for the list table.
1231
+	 *
1232
+	 * @param int  $per_page
1233
+	 * @param bool $count
1234
+	 * @param bool $this_month
1235
+	 * @param bool $today
1236
+	 * @return EE_Registration[]|int
1237
+	 * @throws EE_Error
1238
+	 * @throws InvalidArgumentException
1239
+	 * @throws InvalidDataTypeException
1240
+	 * @throws InvalidInterfaceException
1241
+	 */
1242
+	public function get_registrations(
1243
+		$per_page = 10,
1244
+		$count = false,
1245
+		$this_month = false,
1246
+		$today = false
1247
+	) {
1248
+		if ($this_month) {
1249
+			$this->_req_data['status'] = 'month';
1250
+		}
1251
+		if ($today) {
1252
+			$this->_req_data['status'] = 'today';
1253
+		}
1254
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1255
+		/**
1256
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1257
+		 *
1258
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1259
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1260
+		 *                             or if you have the development copy of EE you can view this at the path:
1261
+		 *                             /docs/G--Model-System/model-query-params.md
1262
+		 */
1263
+		$query_params['group_by'] = '';
1264
+
1265
+		return $count
1266
+			? $this->getRegistrationModel()->count($query_params)
1267
+			/** @type EE_Registration[] */
1268
+			: $this->getRegistrationModel()->get_all($query_params);
1269
+	}
1270
+
1271
+
1272
+	/**
1273
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1274
+	 * Note: this listens to values on the request for some of the query parameters.
1275
+	 *
1276
+	 * @param array $request
1277
+	 * @param int   $per_page
1278
+	 * @param bool  $count
1279
+	 * @return array
1280
+	 * @throws EE_Error
1281
+	 * @throws InvalidArgumentException
1282
+	 * @throws InvalidDataTypeException
1283
+	 * @throws InvalidInterfaceException
1284
+	 */
1285
+	protected function _get_registration_query_parameters(
1286
+		$request = array(),
1287
+		$per_page = 10,
1288
+		$count = false
1289
+	) {
1290
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1291
+		$list_table_query_builder = $this->getLoader()->getNew(
1292
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1293
+			[ $request ]
1294
+		);
1295
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1296
+	}
1297
+
1298
+
1299
+	public function get_registration_status_array()
1300
+	{
1301
+		return self::$_reg_status;
1302
+	}
1303
+
1304
+
1305
+
1306
+
1307
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1308
+	/**
1309
+	 *        generates HTML for the View Registration Details Admin page
1310
+	 *
1311
+	 * @access protected
1312
+	 * @return void
1313
+	 * @throws DomainException
1314
+	 * @throws EE_Error
1315
+	 * @throws InvalidArgumentException
1316
+	 * @throws InvalidDataTypeException
1317
+	 * @throws InvalidInterfaceException
1318
+	 * @throws EntityNotFoundException
1319
+	 * @throws ReflectionException
1320
+	 */
1321
+	protected function _registration_details()
1322
+	{
1323
+		$this->_template_args = array();
1324
+		$this->_set_registration_object();
1325
+		if (is_object($this->_registration)) {
1326
+			$transaction = $this->_registration->transaction()
1327
+				? $this->_registration->transaction()
1328
+				: EE_Transaction::new_instance();
1329
+			$this->_session = $transaction->session_data();
1330
+			$event_id = $this->_registration->event_ID();
1331
+			$this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1332
+			$this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1333
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1334
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1335
+			$this->_template_args['grand_total'] = $transaction->total();
1336
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1337
+			// link back to overview
1338
+			$this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1339
+			$this->_template_args['registration'] = $this->_registration;
1340
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1341
+				array(
1342
+					'action'   => 'default',
1343
+					'event_id' => $event_id,
1344
+				),
1345
+				REG_ADMIN_URL
1346
+			);
1347
+			$this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1348
+				array(
1349
+					'action' => 'default',
1350
+					'EVT_ID' => $event_id,
1351
+					'page'   => 'espresso_transactions',
1352
+				),
1353
+				admin_url('admin.php')
1354
+			);
1355
+			$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1356
+				array(
1357
+					'page'   => 'espresso_events',
1358
+					'action' => 'edit',
1359
+					'post'   => $event_id,
1360
+				),
1361
+				admin_url('admin.php')
1362
+			);
1363
+			// next and previous links
1364
+			$next_reg = $this->_registration->next(
1365
+				null,
1366
+				array(),
1367
+				'REG_ID'
1368
+			);
1369
+			$this->_template_args['next_registration'] = $next_reg
1370
+				? $this->_next_link(
1371
+					EE_Admin_Page::add_query_args_and_nonce(
1372
+						array(
1373
+							'action'  => 'view_registration',
1374
+							'_REG_ID' => $next_reg['REG_ID'],
1375
+						),
1376
+						REG_ADMIN_URL
1377
+					),
1378
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1379
+				)
1380
+				: '';
1381
+			$previous_reg = $this->_registration->previous(
1382
+				null,
1383
+				array(),
1384
+				'REG_ID'
1385
+			);
1386
+			$this->_template_args['previous_registration'] = $previous_reg
1387
+				? $this->_previous_link(
1388
+					EE_Admin_Page::add_query_args_and_nonce(
1389
+						array(
1390
+							'action'  => 'view_registration',
1391
+							'_REG_ID' => $previous_reg['REG_ID'],
1392
+						),
1393
+						REG_ADMIN_URL
1394
+					),
1395
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1396
+				)
1397
+				: '';
1398
+			// grab header
1399
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1400
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
1401
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1402
+				$template_path,
1403
+				$this->_template_args,
1404
+				true
1405
+			);
1406
+		} else {
1407
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1408
+		}
1409
+		// the details template wrapper
1410
+		$this->display_admin_page_with_sidebar();
1411
+	}
1412
+
1413
+
1414
+	/**
1415
+	 * @throws EE_Error
1416
+	 * @throws InvalidArgumentException
1417
+	 * @throws InvalidDataTypeException
1418
+	 * @throws InvalidInterfaceException
1419
+	 * @throws ReflectionException
1420
+	 * @since 4.10.2.p
1421
+	 */
1422
+	protected function _registration_details_metaboxes()
1423
+	{
1424
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1425
+		$this->_set_registration_object();
1426
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1427
+		add_meta_box(
1428
+			'edit-reg-status-mbox',
1429
+			esc_html__('Registration Status', 'event_espresso'),
1430
+			array($this, 'set_reg_status_buttons_metabox'),
1431
+			$this->wp_page_slug,
1432
+			'normal',
1433
+			'high'
1434
+		);
1435
+		add_meta_box(
1436
+			'edit-reg-details-mbox',
1437
+			esc_html__('Registration Details', 'event_espresso'),
1438
+			array($this, '_reg_details_meta_box'),
1439
+			$this->wp_page_slug,
1440
+			'normal',
1441
+			'high'
1442
+		);
1443
+		if ($attendee instanceof EE_Attendee
1444
+			&& EE_Registry::instance()->CAP->current_user_can(
1445
+				'ee_read_registration',
1446
+				'edit-reg-questions-mbox',
1447
+				$this->_registration->ID()
1448
+			)
1449
+		) {
1450
+			add_meta_box(
1451
+				'edit-reg-questions-mbox',
1452
+				esc_html__('Registration Form Answers', 'event_espresso'),
1453
+				array($this, '_reg_questions_meta_box'),
1454
+				$this->wp_page_slug,
1455
+				'normal',
1456
+				'high'
1457
+			);
1458
+		}
1459
+		add_meta_box(
1460
+			'edit-reg-registrant-mbox',
1461
+			esc_html__('Contact Details', 'event_espresso'),
1462
+			array($this, '_reg_registrant_side_meta_box'),
1463
+			$this->wp_page_slug,
1464
+			'side',
1465
+			'high'
1466
+		);
1467
+		if ($this->_registration->group_size() > 1) {
1468
+			add_meta_box(
1469
+				'edit-reg-attendees-mbox',
1470
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1471
+				array($this, '_reg_attendees_meta_box'),
1472
+				$this->wp_page_slug,
1473
+				'normal',
1474
+				'high'
1475
+			);
1476
+		}
1477
+	}
1478
+
1479
+
1480
+	/**
1481
+	 * set_reg_status_buttons_metabox
1482
+	 *
1483
+	 * @access protected
1484
+	 * @return string
1485
+	 * @throws EE_Error
1486
+	 * @throws EntityNotFoundException
1487
+	 * @throws InvalidArgumentException
1488
+	 * @throws InvalidDataTypeException
1489
+	 * @throws InvalidInterfaceException
1490
+	 * @throws ReflectionException
1491
+	 */
1492
+	public function set_reg_status_buttons_metabox()
1493
+	{
1494
+		$this->_set_registration_object();
1495
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1496
+		echo $change_reg_status_form->form_open(
1497
+			self::add_query_args_and_nonce(
1498
+				array(
1499
+					'action' => 'change_reg_status',
1500
+				),
1501
+				REG_ADMIN_URL
1502
+			)
1503
+		);
1504
+		echo $change_reg_status_form->get_html();
1505
+		echo $change_reg_status_form->form_close();
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 = 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'     => array(
1525
+				'return'             => new EE_Hidden_Input(
1526
+					array(
1527
+						'name'    => 'return',
1528
+						'default' => 'view_registration',
1529
+					)
1530
+				),
1531
+				'REG_ID'             => new EE_Hidden_Input(
1532
+					array(
1533
+						'name'    => 'REG_ID',
1534
+						'default' => $this->_registration->ID(),
1535
+					)
1536
+				),
1537
+				'current_status'     => new EE_Form_Section_HTML(
1538
+					EEH_HTML::table(
1539
+						EEH_HTML::tr(
1540
+							EEH_HTML::th(
1541
+								EEH_HTML::label(
1542
+									EEH_HTML::strong(
1543
+										esc_html__('Current Registration Status', 'event_espresso')
1544
+									)
1545
+								)
1546
+							)
1547
+							. EEH_HTML::td(
1548
+								EEH_HTML::strong(
1549
+									$this->_registration->pretty_status(),
1550
+									'',
1551
+									'status-' . $this->_registration->status_ID(),
1552
+									'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1553
+								)
1554
+							)
1555
+						)
1556
+					)
1557
+				)
1558
+			)
1559
+		);
1560
+		if (EE_Registry::instance()->CAP->current_user_can(
1561
+			'ee_edit_registration',
1562
+			'toggle_registration_status',
1563
+			$this->_registration->ID()
1564
+		)) {
1565
+			$reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1566
+				$this->_get_reg_statuses(),
1567
+				array(
1568
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1569
+					'default'         => $this->_registration->status_ID(),
1570
+				)
1571
+			);
1572
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1573
+				array(
1574
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1575
+					'default'         => false,
1576
+					'html_help_text'  => esc_html__(
1577
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1578
+						'event_espresso'
1579
+					)
1580
+				)
1581
+			);
1582
+			$reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1583
+				array(
1584
+					'html_class'      => 'button-primary',
1585
+					'html_label_text' => '&nbsp;',
1586
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1587
+				)
1588
+			);
1589
+		}
1590
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1591
+	}
1592
+
1593
+
1594
+	/**
1595
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1596
+	 *
1597
+	 * @return array
1598
+	 * @throws EE_Error
1599
+	 * @throws InvalidArgumentException
1600
+	 * @throws InvalidDataTypeException
1601
+	 * @throws InvalidInterfaceException
1602
+	 * @throws EntityNotFoundException
1603
+	 */
1604
+	protected function _get_reg_statuses()
1605
+	{
1606
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1607
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1608
+		// get current reg status
1609
+		$current_status = $this->_registration->status_ID();
1610
+		// is registration for free event? This will determine whether to display the pending payment option
1611
+		if ($current_status !== EEM_Registration::status_id_pending_payment
1612
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1613
+		) {
1614
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1615
+		}
1616
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1617
+	}
1618
+
1619
+
1620
+	/**
1621
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1622
+	 *
1623
+	 * @param bool $status REG status given for changing registrations to.
1624
+	 * @param bool $notify Whether to send messages notifications or not.
1625
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1626
+	 * @throws DomainException
1627
+	 * @throws EE_Error
1628
+	 * @throws EntityNotFoundException
1629
+	 * @throws InvalidArgumentException
1630
+	 * @throws InvalidDataTypeException
1631
+	 * @throws InvalidInterfaceException
1632
+	 * @throws ReflectionException
1633
+	 * @throws RuntimeException
1634
+	 */
1635
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1636
+	{
1637
+		if (isset($this->_req_data['reg_status_change_form'])) {
1638
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1639
+				? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1640
+				: array();
1641
+		} else {
1642
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1643
+				? (array) $this->_req_data['_REG_ID']
1644
+				: array();
1645
+		}
1646
+		// sanitize $REG_IDs
1647
+		$REG_IDs = array_map('absint', $REG_IDs);
1648
+		// and remove empty entries
1649
+		$REG_IDs = array_filter($REG_IDs);
1650
+
1651
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1652
+
1653
+		/**
1654
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1655
+		 * Currently this value is used downstream by the _process_resend_registration method.
1656
+		 *
1657
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1658
+		 * @param bool                     $status           The status registrations were changed to.
1659
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1660
+		 * @param Registrations_Admin_Page $admin_page_object
1661
+		 */
1662
+		$this->_req_data['_REG_ID'] = apply_filters(
1663
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1664
+			$result['REG_ID'],
1665
+			$status,
1666
+			$result['success'],
1667
+			$this
1668
+		);
1669
+
1670
+		// notify?
1671
+		if ($notify
1672
+			&& $result['success']
1673
+			&& ! empty($this->_req_data['_REG_ID'])
1674
+			&& EE_Registry::instance()->CAP->current_user_can(
1675
+				'ee_send_message',
1676
+				'espresso_registrations_resend_registration'
1677
+			)
1678
+		) {
1679
+			$this->_process_resend_registration();
1680
+		}
1681
+		return $result;
1682
+	}
1683
+
1684
+
1685
+	/**
1686
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1687
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1688
+	 *
1689
+	 * @param array  $REG_IDs
1690
+	 * @param string $status
1691
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1692
+	 *                        slug sent with setting the registration status.
1693
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1694
+	 * @throws EE_Error
1695
+	 * @throws InvalidArgumentException
1696
+	 * @throws InvalidDataTypeException
1697
+	 * @throws InvalidInterfaceException
1698
+	 * @throws ReflectionException
1699
+	 * @throws RuntimeException
1700
+	 * @throws EntityNotFoundException
1701
+	 * @throws DomainException
1702
+	 */
1703
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1704
+	{
1705
+		$success = false;
1706
+		// typecast $REG_IDs
1707
+		$REG_IDs = (array) $REG_IDs;
1708
+		if (! empty($REG_IDs)) {
1709
+			$success = true;
1710
+			// set default status if none is passed
1711
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1712
+			$status_context = $notify
1713
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1714
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1715
+			// loop through REG_ID's and change status
1716
+			foreach ($REG_IDs as $REG_ID) {
1717
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1718
+				if ($registration instanceof EE_Registration) {
1719
+					$registration->set_status(
1720
+						$status,
1721
+						false,
1722
+						new Context(
1723
+							$status_context,
1724
+							esc_html__(
1725
+								'Manually triggered status change on a Registration Admin Page route.',
1726
+								'event_espresso'
1727
+							)
1728
+						)
1729
+					);
1730
+					$result = $registration->save();
1731
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1732
+					$success = $result !== false ? $success : false;
1733
+				}
1734
+			}
1735
+		}
1736
+
1737
+		// return $success and processed registrations
1738
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1739
+	}
1740
+
1741
+
1742
+	/**
1743
+	 * Common logic for setting up success message and redirecting to appropriate route
1744
+	 *
1745
+	 * @param string $STS_ID status id for the registration changed to
1746
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1747
+	 * @return void
1748
+	 * @throws DomainException
1749
+	 * @throws EE_Error
1750
+	 * @throws EntityNotFoundException
1751
+	 * @throws InvalidArgumentException
1752
+	 * @throws InvalidDataTypeException
1753
+	 * @throws InvalidInterfaceException
1754
+	 * @throws ReflectionException
1755
+	 * @throws RuntimeException
1756
+	 */
1757
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1758
+	{
1759
+		$result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1760
+			: array('success' => false);
1761
+		$success = isset($result['success']) && $result['success'];
1762
+		// setup success message
1763
+		if ($success) {
1764
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1765
+				$msg = sprintf(
1766
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1767
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1768
+				);
1769
+			} else {
1770
+				$msg = sprintf(
1771
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1772
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1773
+				);
1774
+			}
1775
+			EE_Error::add_success($msg);
1776
+		} else {
1777
+			EE_Error::add_error(
1778
+				esc_html__(
1779
+					'Something went wrong, and the status was not changed',
1780
+					'event_espresso'
1781
+				),
1782
+				__FILE__,
1783
+				__LINE__,
1784
+				__FUNCTION__
1785
+			);
1786
+		}
1787
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] === 'view_registration') {
1788
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1789
+		} else {
1790
+			$route = array('action' => 'default');
1791
+		}
1792
+		$route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1793
+		$this->_redirect_after_action($success, '', '', $route, true);
1794
+	}
1795
+
1796
+
1797
+	/**
1798
+	 * incoming reg status change from reg details page.
1799
+	 *
1800
+	 * @return void
1801
+	 * @throws EE_Error
1802
+	 * @throws EntityNotFoundException
1803
+	 * @throws InvalidArgumentException
1804
+	 * @throws InvalidDataTypeException
1805
+	 * @throws InvalidInterfaceException
1806
+	 * @throws ReflectionException
1807
+	 * @throws RuntimeException
1808
+	 * @throws DomainException
1809
+	 */
1810
+	protected function _change_reg_status()
1811
+	{
1812
+		$this->_req_data['return'] = 'view_registration';
1813
+		// set notify based on whether the send notifications toggle is set or not
1814
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1815
+		// $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1816
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1817
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1818
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1819
+			case EEM_Registration::status_id_approved:
1820
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1821
+				$this->approve_registration($notify);
1822
+				break;
1823
+			case EEM_Registration::status_id_pending_payment:
1824
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1825
+				$this->pending_registration($notify);
1826
+				break;
1827
+			case EEM_Registration::status_id_not_approved:
1828
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1829
+				$this->not_approve_registration($notify);
1830
+				break;
1831
+			case EEM_Registration::status_id_declined:
1832
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1833
+				$this->decline_registration($notify);
1834
+				break;
1835
+			case EEM_Registration::status_id_cancelled:
1836
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1837
+				$this->cancel_registration($notify);
1838
+				break;
1839
+			case EEM_Registration::status_id_wait_list:
1840
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1841
+				$this->wait_list_registration($notify);
1842
+				break;
1843
+			case EEM_Registration::status_id_incomplete:
1844
+			default:
1845
+				$result['success'] = false;
1846
+				unset($this->_req_data['return']);
1847
+				$this->_reg_status_change_return('', false);
1848
+				break;
1849
+		}
1850
+	}
1851
+
1852
+
1853
+	/**
1854
+	 * Callback for bulk action routes.
1855
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1856
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1857
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1858
+	 * when an action is happening on just a single registration).
1859
+	 *
1860
+	 * @param      $action
1861
+	 * @param bool $notify
1862
+	 */
1863
+	protected function bulk_action_on_registrations($action, $notify = false)
1864
+	{
1865
+		do_action(
1866
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1867
+			$this,
1868
+			$action,
1869
+			$notify
1870
+		);
1871
+		$method = $action . '_registration';
1872
+		if (method_exists($this, $method)) {
1873
+			$this->$method($notify);
1874
+		}
1875
+	}
1876
+
1877
+
1878
+	/**
1879
+	 * approve_registration
1880
+	 *
1881
+	 * @access protected
1882
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1883
+	 * @return void
1884
+	 * @throws EE_Error
1885
+	 * @throws EntityNotFoundException
1886
+	 * @throws InvalidArgumentException
1887
+	 * @throws InvalidDataTypeException
1888
+	 * @throws InvalidInterfaceException
1889
+	 * @throws ReflectionException
1890
+	 * @throws RuntimeException
1891
+	 * @throws DomainException
1892
+	 */
1893
+	protected function approve_registration($notify = false)
1894
+	{
1895
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1896
+	}
1897
+
1898
+
1899
+	/**
1900
+	 *        decline_registration
1901
+	 *
1902
+	 * @access protected
1903
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1904
+	 * @return void
1905
+	 * @throws EE_Error
1906
+	 * @throws EntityNotFoundException
1907
+	 * @throws InvalidArgumentException
1908
+	 * @throws InvalidDataTypeException
1909
+	 * @throws InvalidInterfaceException
1910
+	 * @throws ReflectionException
1911
+	 * @throws RuntimeException
1912
+	 * @throws DomainException
1913
+	 */
1914
+	protected function decline_registration($notify = false)
1915
+	{
1916
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1917
+	}
1918
+
1919
+
1920
+	/**
1921
+	 *        cancel_registration
1922
+	 *
1923
+	 * @access protected
1924
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1925
+	 * @return void
1926
+	 * @throws EE_Error
1927
+	 * @throws EntityNotFoundException
1928
+	 * @throws InvalidArgumentException
1929
+	 * @throws InvalidDataTypeException
1930
+	 * @throws InvalidInterfaceException
1931
+	 * @throws ReflectionException
1932
+	 * @throws RuntimeException
1933
+	 * @throws DomainException
1934
+	 */
1935
+	protected function cancel_registration($notify = false)
1936
+	{
1937
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1938
+	}
1939
+
1940
+
1941
+	/**
1942
+	 *        not_approve_registration
1943
+	 *
1944
+	 * @access protected
1945
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1946
+	 * @return void
1947
+	 * @throws EE_Error
1948
+	 * @throws EntityNotFoundException
1949
+	 * @throws InvalidArgumentException
1950
+	 * @throws InvalidDataTypeException
1951
+	 * @throws InvalidInterfaceException
1952
+	 * @throws ReflectionException
1953
+	 * @throws RuntimeException
1954
+	 * @throws DomainException
1955
+	 */
1956
+	protected function not_approve_registration($notify = false)
1957
+	{
1958
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1959
+	}
1960
+
1961
+
1962
+	/**
1963
+	 *        decline_registration
1964
+	 *
1965
+	 * @access protected
1966
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1967
+	 * @return void
1968
+	 * @throws EE_Error
1969
+	 * @throws EntityNotFoundException
1970
+	 * @throws InvalidArgumentException
1971
+	 * @throws InvalidDataTypeException
1972
+	 * @throws InvalidInterfaceException
1973
+	 * @throws ReflectionException
1974
+	 * @throws RuntimeException
1975
+	 * @throws DomainException
1976
+	 */
1977
+	protected function pending_registration($notify = false)
1978
+	{
1979
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1980
+	}
1981
+
1982
+
1983
+	/**
1984
+	 * waitlist_registration
1985
+	 *
1986
+	 * @access protected
1987
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1988
+	 * @return void
1989
+	 * @throws EE_Error
1990
+	 * @throws EntityNotFoundException
1991
+	 * @throws InvalidArgumentException
1992
+	 * @throws InvalidDataTypeException
1993
+	 * @throws InvalidInterfaceException
1994
+	 * @throws ReflectionException
1995
+	 * @throws RuntimeException
1996
+	 * @throws DomainException
1997
+	 */
1998
+	protected function wait_list_registration($notify = false)
1999
+	{
2000
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2001
+	}
2002
+
2003
+
2004
+	/**
2005
+	 *        generates HTML for the Registration main meta box
2006
+	 *
2007
+	 * @access public
2008
+	 * @return void
2009
+	 * @throws DomainException
2010
+	 * @throws EE_Error
2011
+	 * @throws InvalidArgumentException
2012
+	 * @throws InvalidDataTypeException
2013
+	 * @throws InvalidInterfaceException
2014
+	 * @throws ReflectionException
2015
+	 * @throws EntityNotFoundException
2016
+	 */
2017
+	public function _reg_details_meta_box()
2018
+	{
2019
+		EEH_Autoloader::register_line_item_display_autoloaders();
2020
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2021
+		EE_Registry::instance()->load_helper('Line_Item');
2022
+		$transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2023
+			: EE_Transaction::new_instance();
2024
+		$this->_session = $transaction->session_data();
2025
+		$filters = new EE_Line_Item_Filter_Collection();
2026
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2027
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
2028
+		$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2029
+			$filters,
2030
+			$transaction->total_line_item()
2031
+		);
2032
+		$filtered_line_item_tree = $line_item_filter_processor->process();
2033
+		$line_item_display = new EE_Line_Item_Display(
2034
+			'reg_admin_table',
2035
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2036
+		);
2037
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2038
+			$filtered_line_item_tree,
2039
+			array('EE_Registration' => $this->_registration)
2040
+		);
2041
+		$attendee = $this->_registration->attendee();
2042
+		if (EE_Registry::instance()->CAP->current_user_can(
2043
+			'ee_read_transaction',
2044
+			'espresso_transactions_view_transaction'
2045
+		)) {
2046
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2047
+				EE_Admin_Page::add_query_args_and_nonce(
2048
+					array(
2049
+						'action' => 'view_transaction',
2050
+						'TXN_ID' => $transaction->ID(),
2051
+					),
2052
+					TXN_ADMIN_URL
2053
+				),
2054
+				esc_html__(' View Transaction', 'event_espresso'),
2055
+				'button secondary-button right',
2056
+				'dashicons dashicons-cart'
2057
+			);
2058
+		} else {
2059
+			$this->_template_args['view_transaction_button'] = '';
2060
+		}
2061
+		if ($attendee instanceof EE_Attendee
2062
+			&& EE_Registry::instance()->CAP->current_user_can(
2063
+				'ee_send_message',
2064
+				'espresso_registrations_resend_registration'
2065
+			)
2066
+		) {
2067
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2068
+				EE_Admin_Page::add_query_args_and_nonce(
2069
+					array(
2070
+						'action'      => 'resend_registration',
2071
+						'_REG_ID'     => $this->_registration->ID(),
2072
+						'redirect_to' => 'view_registration',
2073
+					),
2074
+					REG_ADMIN_URL
2075
+				),
2076
+				esc_html__(' Resend Registration', 'event_espresso'),
2077
+				'button secondary-button right',
2078
+				'dashicons dashicons-email-alt'
2079
+			);
2080
+		} else {
2081
+			$this->_template_args['resend_registration_button'] = '';
2082
+		}
2083
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2084
+		$payment = $transaction->get_first_related('Payment');
2085
+		$payment = ! $payment instanceof EE_Payment
2086
+			? EE_Payment::new_instance()
2087
+			: $payment;
2088
+		$payment_method = $payment->get_first_related('Payment_Method');
2089
+		$payment_method = ! $payment_method instanceof EE_Payment_Method
2090
+			? EE_Payment_Method::new_instance()
2091
+			: $payment_method;
2092
+		$reg_details = array(
2093
+			'payment_method'       => $payment_method->name(),
2094
+			'response_msg'         => $payment->gateway_response(),
2095
+			'registration_id'      => $this->_registration->get('REG_code'),
2096
+			'registration_session' => $this->_registration->session_ID(),
2097
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2098
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2099
+		);
2100
+		if (isset($reg_details['registration_id'])) {
2101
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2102
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2103
+				'Registration ID',
2104
+				'event_espresso'
2105
+			);
2106
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2107
+		}
2108
+		if (isset($reg_details['payment_method'])) {
2109
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2110
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2111
+				'Most Recent Payment Method',
2112
+				'event_espresso'
2113
+			);
2114
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2115
+			$this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2116
+			$this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2117
+				'Payment method response',
2118
+				'event_espresso'
2119
+			);
2120
+			$this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2121
+		}
2122
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2123
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2124
+			'Registration Session',
2125
+			'event_espresso'
2126
+		);
2127
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2128
+		$this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2129
+		$this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2130
+			'Registration placed from IP',
2131
+			'event_espresso'
2132
+		);
2133
+		$this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2134
+		$this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2135
+		$this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2136
+			'Registrant User Agent',
2137
+			'event_espresso'
2138
+		);
2139
+		$this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2140
+		$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2141
+			array(
2142
+				'action'   => 'default',
2143
+				'event_id' => $this->_registration->event_ID(),
2144
+			),
2145
+			REG_ADMIN_URL
2146
+		);
2147
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2148
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2149
+		$template_path =
2150
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2151
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2152
+	}
2153
+
2154
+
2155
+	/**
2156
+	 * generates HTML for the Registration Questions meta box.
2157
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2158
+	 * otherwise uses new forms system
2159
+	 *
2160
+	 * @access public
2161
+	 * @return void
2162
+	 * @throws DomainException
2163
+	 * @throws EE_Error
2164
+	 * @throws InvalidArgumentException
2165
+	 * @throws InvalidDataTypeException
2166
+	 * @throws InvalidInterfaceException
2167
+	 * @throws ReflectionException
2168
+	 */
2169
+	public function _reg_questions_meta_box()
2170
+	{
2171
+		// allow someone to override this method entirely
2172
+		if (apply_filters(
2173
+			'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2174
+			true,
2175
+			$this,
2176
+			$this->_registration
2177
+		)) {
2178
+			$form = $this->_get_reg_custom_questions_form(
2179
+				$this->_registration->ID()
2180
+			);
2181
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2182
+				? $form->get_html_and_js()
2183
+				: '';
2184
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2185
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2186
+			$template_path =
2187
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2188
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2189
+		}
2190
+	}
2191
+
2192
+
2193
+	/**
2194
+	 * form_before_question_group
2195
+	 *
2196
+	 * @deprecated    as of 4.8.32.rc.000
2197
+	 * @access        public
2198
+	 * @param        string $output
2199
+	 * @return        string
2200
+	 */
2201
+	public function form_before_question_group($output)
2202
+	{
2203
+		EE_Error::doing_it_wrong(
2204
+			__CLASS__ . '::' . __FUNCTION__,
2205
+			esc_html__(
2206
+				'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.',
2207
+				'event_espresso'
2208
+			),
2209
+			'4.8.32.rc.000'
2210
+		);
2211
+		return '
2212 2212
 	<table class="form-table ee-width-100">
2213 2213
 		<tbody>
2214 2214
 			';
2215
-    }
2216
-
2217
-
2218
-    /**
2219
-     * form_after_question_group
2220
-     *
2221
-     * @deprecated    as of 4.8.32.rc.000
2222
-     * @access        public
2223
-     * @param        string $output
2224
-     * @return        string
2225
-     */
2226
-    public function form_after_question_group($output)
2227
-    {
2228
-        EE_Error::doing_it_wrong(
2229
-            __CLASS__ . '::' . __FUNCTION__,
2230
-            esc_html__(
2231
-                '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.',
2232
-                'event_espresso'
2233
-            ),
2234
-            '4.8.32.rc.000'
2235
-        );
2236
-        return '
2215
+	}
2216
+
2217
+
2218
+	/**
2219
+	 * form_after_question_group
2220
+	 *
2221
+	 * @deprecated    as of 4.8.32.rc.000
2222
+	 * @access        public
2223
+	 * @param        string $output
2224
+	 * @return        string
2225
+	 */
2226
+	public function form_after_question_group($output)
2227
+	{
2228
+		EE_Error::doing_it_wrong(
2229
+			__CLASS__ . '::' . __FUNCTION__,
2230
+			esc_html__(
2231
+				'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.',
2232
+				'event_espresso'
2233
+			),
2234
+			'4.8.32.rc.000'
2235
+		);
2236
+		return '
2237 2237
 			<tr class="hide-if-no-js">
2238 2238
 				<th> </th>
2239 2239
 				<td class="reg-admin-edit-attendee-question-td">
2240 2240
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2241
-               . esc_attr__('click to edit question', 'event_espresso')
2242
-               . '">
2241
+			   . esc_attr__('click to edit question', 'event_espresso')
2242
+			   . '">
2243 2243
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2244
-               . esc_html__('edit the above question group', 'event_espresso')
2245
-               . '</span>
2244
+			   . esc_html__('edit the above question group', 'event_espresso')
2245
+			   . '</span>
2246 2246
 						<div class="dashicons dashicons-edit"></div>
2247 2247
 					</a>
2248 2248
 				</td>
@@ -2250,644 +2250,644 @@  discard block
 block discarded – undo
2250 2250
 		</tbody>
2251 2251
 	</table>
2252 2252
 ';
2253
-    }
2254
-
2255
-
2256
-    /**
2257
-     * form_form_field_label_wrap
2258
-     *
2259
-     * @deprecated    as of 4.8.32.rc.000
2260
-     * @access        public
2261
-     * @param        string $label
2262
-     * @return        string
2263
-     */
2264
-    public function form_form_field_label_wrap($label)
2265
-    {
2266
-        EE_Error::doing_it_wrong(
2267
-            __CLASS__ . '::' . __FUNCTION__,
2268
-            esc_html__(
2269
-                '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.',
2270
-                'event_espresso'
2271
-            ),
2272
-            '4.8.32.rc.000'
2273
-        );
2274
-        return '
2253
+	}
2254
+
2255
+
2256
+	/**
2257
+	 * form_form_field_label_wrap
2258
+	 *
2259
+	 * @deprecated    as of 4.8.32.rc.000
2260
+	 * @access        public
2261
+	 * @param        string $label
2262
+	 * @return        string
2263
+	 */
2264
+	public function form_form_field_label_wrap($label)
2265
+	{
2266
+		EE_Error::doing_it_wrong(
2267
+			__CLASS__ . '::' . __FUNCTION__,
2268
+			esc_html__(
2269
+				'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.',
2270
+				'event_espresso'
2271
+			),
2272
+			'4.8.32.rc.000'
2273
+		);
2274
+		return '
2275 2275
 			<tr>
2276 2276
 				<th>
2277 2277
 					' . $label . '
2278 2278
 				</th>';
2279
-    }
2280
-
2281
-
2282
-    /**
2283
-     * form_form_field_input__wrap
2284
-     *
2285
-     * @deprecated    as of 4.8.32.rc.000
2286
-     * @access        public
2287
-     * @param        string $input
2288
-     * @return        string
2289
-     */
2290
-    public function form_form_field_input__wrap($input)
2291
-    {
2292
-        EE_Error::doing_it_wrong(
2293
-            __CLASS__ . '::' . __FUNCTION__,
2294
-            esc_html__(
2295
-                '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.',
2296
-                'event_espresso'
2297
-            ),
2298
-            '4.8.32.rc.000'
2299
-        );
2300
-        return '
2279
+	}
2280
+
2281
+
2282
+	/**
2283
+	 * form_form_field_input__wrap
2284
+	 *
2285
+	 * @deprecated    as of 4.8.32.rc.000
2286
+	 * @access        public
2287
+	 * @param        string $input
2288
+	 * @return        string
2289
+	 */
2290
+	public function form_form_field_input__wrap($input)
2291
+	{
2292
+		EE_Error::doing_it_wrong(
2293
+			__CLASS__ . '::' . __FUNCTION__,
2294
+			esc_html__(
2295
+				'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.',
2296
+				'event_espresso'
2297
+			),
2298
+			'4.8.32.rc.000'
2299
+		);
2300
+		return '
2301 2301
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2302 2302
 					' . $input . '
2303 2303
 				</td>
2304 2304
 			</tr>';
2305
-    }
2306
-
2307
-
2308
-    /**
2309
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2310
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2311
-     * to display the page
2312
-     *
2313
-     * @access protected
2314
-     * @return void
2315
-     * @throws EE_Error
2316
-     * @throws InvalidArgumentException
2317
-     * @throws InvalidDataTypeException
2318
-     * @throws InvalidInterfaceException
2319
-     * @throws ReflectionException
2320
-     */
2321
-    protected function _update_attendee_registration_form()
2322
-    {
2323
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2324
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2325
-            $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2326
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2327
-            if ($success) {
2328
-                $what = esc_html__('Registration Form', 'event_espresso');
2329
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2330
-                    : array('action' => 'default');
2331
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2332
-            }
2333
-        }
2334
-    }
2335
-
2336
-
2337
-    /**
2338
-     * Gets the form for saving registrations custom questions (if done
2339
-     * previously retrieves the cached form object, which may have validation errors in it)
2340
-     *
2341
-     * @param int $REG_ID
2342
-     * @return EE_Registration_Custom_Questions_Form
2343
-     * @throws EE_Error
2344
-     * @throws InvalidArgumentException
2345
-     * @throws InvalidDataTypeException
2346
-     * @throws InvalidInterfaceException
2347
-     */
2348
-    protected function _get_reg_custom_questions_form($REG_ID)
2349
-    {
2350
-        if (! $this->_reg_custom_questions_form) {
2351
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2352
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2353
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2354
-            );
2355
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2356
-        }
2357
-        return $this->_reg_custom_questions_form;
2358
-    }
2359
-
2360
-
2361
-    /**
2362
-     * Saves
2363
-     *
2364
-     * @access private
2365
-     * @param bool $REG_ID
2366
-     * @return bool
2367
-     * @throws EE_Error
2368
-     * @throws InvalidArgumentException
2369
-     * @throws InvalidDataTypeException
2370
-     * @throws InvalidInterfaceException
2371
-     * @throws ReflectionException
2372
-     */
2373
-    private function _save_reg_custom_questions_form($REG_ID = false)
2374
-    {
2375
-        if (! $REG_ID) {
2376
-            EE_Error::add_error(
2377
-                esc_html__(
2378
-                    'An error occurred. No registration ID was received.',
2379
-                    'event_espresso'
2380
-                ),
2381
-                __FILE__,
2382
-                __FUNCTION__,
2383
-                __LINE__
2384
-            );
2385
-        }
2386
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2387
-        $form->receive_form_submission($this->_req_data);
2388
-        $success = false;
2389
-        if ($form->is_valid()) {
2390
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2391
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2392
-                    $where_conditions = array(
2393
-                        'QST_ID' => $question_id,
2394
-                        'REG_ID' => $REG_ID,
2395
-                    );
2396
-                    $possibly_new_values = array(
2397
-                        'ANS_value' => $input->normalized_value(),
2398
-                    );
2399
-                    $answer = EEM_Answer::instance()->get_one(array($where_conditions));
2400
-                    if ($answer instanceof EE_Answer) {
2401
-                        $success = $answer->save($possibly_new_values);
2402
-                    } else {
2403
-                        // insert it then
2404
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2405
-                        $answer = EE_Answer::new_instance($cols_n_vals);
2406
-                        $success = $answer->save();
2407
-                    }
2408
-                }
2409
-            }
2410
-        } else {
2411
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2412
-        }
2413
-        return $success;
2414
-    }
2415
-
2416
-
2417
-    /**
2418
-     *        generates HTML for the Registration main meta box
2419
-     *
2420
-     * @access public
2421
-     * @return void
2422
-     * @throws DomainException
2423
-     * @throws EE_Error
2424
-     * @throws InvalidArgumentException
2425
-     * @throws InvalidDataTypeException
2426
-     * @throws InvalidInterfaceException
2427
-     * @throws ReflectionException
2428
-     */
2429
-    public function _reg_attendees_meta_box()
2430
-    {
2431
-        $REG = $this->getRegistrationModel();
2432
-        // get all other registrations on this transaction, and cache
2433
-        // the attendees for them so we don't have to run another query using force_join
2434
-        $registrations = $REG->get_all(
2435
-            array(
2436
-                array(
2437
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2438
-                    'REG_ID' => array('!=', $this->_registration->ID()),
2439
-                ),
2440
-                'force_join' => array('Attendee'),
2441
-                'default_where_conditions' => 'other_models_only',
2442
-            )
2443
-        );
2444
-        $this->_template_args['attendees'] = array();
2445
-        $this->_template_args['attendee_notice'] = '';
2446
-        if (empty($registrations)
2447
-            || (is_array($registrations)
2448
-                && ! EEH_Array::get_one_item_from_array($registrations))
2449
-        ) {
2450
-            EE_Error::add_error(
2451
-                esc_html__(
2452
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2453
-                    'event_espresso'
2454
-                ),
2455
-                __FILE__,
2456
-                __FUNCTION__,
2457
-                __LINE__
2458
-            );
2459
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2460
-        } else {
2461
-            $att_nmbr = 1;
2462
-            foreach ($registrations as $registration) {
2463
-                /* @var $registration EE_Registration */
2464
-                $attendee = $registration->attendee()
2465
-                    ? $registration->attendee()
2466
-                    : $this->getAttendeeModel()->create_default_object();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2468
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2469
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2470
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2471
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2472
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2473
-                    ', ',
2474
-                    $attendee->full_address_as_array()
2475
-                );
2476
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2477
-                    array(
2478
-                        'action' => 'edit_attendee',
2479
-                        'post'   => $attendee->ID(),
2480
-                    ),
2481
-                    REG_ADMIN_URL
2482
-                );
2483
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2484
-                    ? $registration->event_obj()->name()
2485
-                    : '';
2486
-                $att_nmbr++;
2487
-            }
2488
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2489
-        }
2490
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2491
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2492
-    }
2493
-
2494
-
2495
-    /**
2496
-     *        generates HTML for the Edit Registration side meta box
2497
-     *
2498
-     * @access public
2499
-     * @return void
2500
-     * @throws DomainException
2501
-     * @throws EE_Error
2502
-     * @throws InvalidArgumentException
2503
-     * @throws InvalidDataTypeException
2504
-     * @throws InvalidInterfaceException
2505
-     * @throws ReflectionException
2506
-     */
2507
-    public function _reg_registrant_side_meta_box()
2508
-    {
2509
-        /*@var $attendee EE_Attendee */
2510
-        $att_check = $this->_registration->attendee();
2511
-        $attendee = $att_check instanceof EE_Attendee
2512
-            ? $att_check
2513
-            : $this->getAttendeeModel()->create_default_object();
2514
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2515
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2516
-        // primary registration object (that way we know if we need to show create button or not)
2517
-        if (! $this->_registration->is_primary_registrant()) {
2518
-            $primary_registration = $this->_registration->get_primary_registration();
2519
-            $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2520
-                : null;
2521
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2522
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2523
-                // custom attendee object so let's not worry about the primary reg.
2524
-                $primary_registration = null;
2525
-            }
2526
-        } else {
2527
-            $primary_registration = null;
2528
-        }
2529
-        $this->_template_args['ATT_ID'] = $attendee->ID();
2530
-        $this->_template_args['fname'] = $attendee->fname();
2531
-        $this->_template_args['lname'] = $attendee->lname();
2532
-        $this->_template_args['email'] = $attendee->email();
2533
-        $this->_template_args['phone'] = $attendee->phone();
2534
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2535
-        // edit link
2536
-        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2537
-            array(
2538
-                'action' => 'edit_attendee',
2539
-                'post'   => $attendee->ID(),
2540
-            ),
2541
-            REG_ADMIN_URL
2542
-        );
2543
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2544
-        // create link
2545
-        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2546
-            ? EE_Admin_Page::add_query_args_and_nonce(
2547
-                array(
2548
-                    'action'  => 'duplicate_attendee',
2549
-                    '_REG_ID' => $this->_registration->ID(),
2550
-                ),
2551
-                REG_ADMIN_URL
2552
-            ) : '';
2553
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2554
-        $this->_template_args['att_check'] = $att_check;
2555
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2556
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2557
-    }
2558
-
2559
-
2560
-    /**
2561
-     * trash or restore registrations
2562
-     *
2563
-     * @param  boolean $trash whether to archive or restore
2564
-     * @return void
2565
-     * @throws EE_Error
2566
-     * @throws InvalidArgumentException
2567
-     * @throws InvalidDataTypeException
2568
-     * @throws InvalidInterfaceException
2569
-     * @throws RuntimeException
2570
-     * @access protected
2571
-     */
2572
-    protected function _trash_or_restore_registrations($trash = true)
2573
-    {
2574
-        // if empty _REG_ID then get out because there's nothing to do
2575
-        if (empty($this->_req_data['_REG_ID'])) {
2576
-            EE_Error::add_error(
2577
-                sprintf(
2578
-                    esc_html__(
2579
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2580
-                        'event_espresso'
2581
-                    ),
2582
-                    $trash ? 'trash' : 'restore'
2583
-                ),
2584
-                __FILE__,
2585
-                __LINE__,
2586
-                __FUNCTION__
2587
-            );
2588
-            $this->_redirect_after_action(false, '', '', array(), true);
2589
-        }
2590
-        $success = 0;
2591
-        $overwrite_msgs = false;
2592
-        // Checkboxes
2593
-        if (! is_array($this->_req_data['_REG_ID'])) {
2594
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2595
-        }
2596
-        $reg_count = count($this->_req_data['_REG_ID']);
2597
-        // cycle thru checkboxes
2598
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2599
-            /** @var EE_Registration $REG */
2600
-            $REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2601
-            $payments = $REG->registration_payments();
2602
-            if (! empty($payments)) {
2603
-                $name = $REG->attendee() instanceof EE_Attendee
2604
-                    ? $REG->attendee()->full_name()
2605
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2606
-                $overwrite_msgs = true;
2607
-                EE_Error::add_error(
2608
-                    sprintf(
2609
-                        esc_html__(
2610
-                            '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.',
2611
-                            'event_espresso'
2612
-                        ),
2613
-                        $name
2614
-                    ),
2615
-                    __FILE__,
2616
-                    __FUNCTION__,
2617
-                    __LINE__
2618
-                );
2619
-                // can't trash this registration because it has payments.
2620
-                continue;
2621
-            }
2622
-            $updated = $trash ? $REG->delete() : $REG->restore();
2623
-            if ($updated) {
2624
-                $success++;
2625
-            }
2626
-        }
2627
-        $this->_redirect_after_action(
2628
-            $success === $reg_count, // were ALL registrations affected?
2629
-            $success > 1
2630
-                ? esc_html__('Registrations', 'event_espresso')
2631
-                : esc_html__('Registration', 'event_espresso'),
2632
-            $trash
2633
-                ? esc_html__('moved to the trash', 'event_espresso')
2634
-                : esc_html__('restored', 'event_espresso'),
2635
-            $this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2636
-            $overwrite_msgs
2637
-        );
2638
-    }
2639
-
2640
-
2641
-    /**
2642
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2643
-     * registration but also.
2644
-     * 1. Removing relations to EE_Attendee
2645
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2646
-     * ALSO trashed.
2647
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2648
-     * 4. Removing relationships between all tickets and the related registrations
2649
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2650
-     * 6. Deleting permanently any related Checkins.
2651
-     *
2652
-     * @return void
2653
-     * @throws EE_Error
2654
-     * @throws InvalidArgumentException
2655
-     * @throws InvalidDataTypeException
2656
-     * @throws InvalidInterfaceException
2657
-     * @throws ReflectionException
2658
-     */
2659
-    protected function _delete_registrations()
2660
-    {
2661
-        $REG_MDL = $this->getRegistrationModel();
2662
-        $success = 1;
2663
-        // Checkboxes
2664
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2665
-            // if array has more than one element than success message should be plural
2666
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2667
-            // cycle thru checkboxes
2668
-            foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2669
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2670
-                if (! $REG instanceof EE_Registration) {
2671
-                    continue;
2672
-                }
2673
-                $deleted = $this->_delete_registration($REG);
2674
-                if (! $deleted) {
2675
-                    $success = 0;
2676
-                }
2677
-            }
2678
-        } else {
2679
-            // grab single id and delete
2680
-            $REG_ID = $this->_req_data['_REG_ID'];
2681
-            /** @var EE_Registration $REG */
2682
-            $REG = $REG_MDL->get_one_by_ID($REG_ID);
2683
-            $deleted = $this->_delete_registration($REG);
2684
-            if (! $deleted) {
2685
-                $success = 0;
2686
-            }
2687
-        }
2688
-        $what = $success > 1
2689
-            ? esc_html__('Registrations', 'event_espresso')
2690
-            : esc_html__('Registration', 'event_espresso');
2691
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2692
-        $this->_redirect_after_action(
2693
-            $success,
2694
-            $what,
2695
-            $action_desc,
2696
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2697
-            true
2698
-        );
2699
-    }
2700
-
2701
-
2702
-    /**
2703
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2704
-     * models get affected.
2705
-     *
2706
-     * @param EE_Registration $REG registration to be deleted permanently
2707
-     * @return bool true = successful deletion, false = fail.
2708
-     * @throws EE_Error
2709
-     * @throws InvalidArgumentException
2710
-     * @throws InvalidDataTypeException
2711
-     * @throws InvalidInterfaceException
2712
-     * @throws ReflectionException
2713
-     */
2714
-    protected function _delete_registration(EE_Registration $REG)
2715
-    {
2716
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2717
-        // registrations on the transaction that are NOT trashed.
2718
-        $TXN = $REG->get_first_related('Transaction');
2719
-        if (! $TXN instanceof EE_Transaction) {
2720
-            EE_Error::add_error(
2721
-                sprintf(
2722
-                    esc_html__(
2723
-                        '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.',
2724
-                        'event_espresso'
2725
-                    ),
2726
-                    $REG->id()
2727
-                ),
2728
-                __FILE__,
2729
-                __FUNCTION__,
2730
-                __LINE__
2731
-            );
2732
-            return false;
2733
-        }
2734
-        $REGS = $TXN->get_many_related('Registration');
2735
-        $all_trashed = true;
2736
-        foreach ($REGS as $registration) {
2737
-            if (! $registration->get('REG_deleted')) {
2738
-                $all_trashed = false;
2739
-            }
2740
-        }
2741
-        if (! $all_trashed) {
2742
-            EE_Error::add_error(
2743
-                esc_html__(
2744
-                    '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.',
2745
-                    'event_espresso'
2746
-                ),
2747
-                __FILE__,
2748
-                __FUNCTION__,
2749
-                __LINE__
2750
-            );
2751
-            return false;
2752
-        }
2753
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2754
-        // separately from THIS one).
2755
-        foreach ($REGS as $registration) {
2756
-            // delete related answers
2757
-            $registration->delete_related_permanently('Answer');
2758
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2759
-            $attendee = $registration->get_first_related('Attendee');
2760
-            if ($attendee instanceof EE_Attendee) {
2761
-                $registration->_remove_relation_to($attendee, 'Attendee');
2762
-            }
2763
-            // now remove relationships to tickets on this registration.
2764
-            $registration->_remove_relations('Ticket');
2765
-            // now delete permanently the checkins related to this registration.
2766
-            $registration->delete_related_permanently('Checkin');
2767
-            if ($registration->ID() === $REG->ID()) {
2768
-                continue;
2769
-            } //we don't want to delete permanently the existing registration just yet.
2770
-            // remove relation to transaction for these registrations if NOT the existing registrations
2771
-            $registration->_remove_relations('Transaction');
2772
-            // delete permanently any related messages.
2773
-            $registration->delete_related_permanently('Message');
2774
-            // now delete this registration permanently
2775
-            $registration->delete_permanently();
2776
-        }
2777
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2778
-        // (the transaction and line items should be all that's left).
2779
-        // delete the line items related to the transaction for this registration.
2780
-        $TXN->delete_related_permanently('Line_Item');
2781
-        // we need to remove all the relationships on the transaction
2782
-        $TXN->delete_related_permanently('Payment');
2783
-        $TXN->delete_related_permanently('Extra_Meta');
2784
-        $TXN->delete_related_permanently('Message');
2785
-        // now we can delete this REG permanently (and the transaction of course)
2786
-        $REG->delete_related_permanently('Transaction');
2787
-        return $REG->delete_permanently();
2788
-    }
2789
-
2790
-
2791
-    /**
2792
-     *    generates HTML for the Register New Attendee Admin page
2793
-     *
2794
-     * @access private
2795
-     * @throws DomainException
2796
-     * @throws EE_Error
2797
-     * @throws InvalidArgumentException
2798
-     * @throws InvalidDataTypeException
2799
-     * @throws InvalidInterfaceException
2800
-     * @throws ReflectionException
2801
-     */
2802
-    public function new_registration()
2803
-    {
2804
-        if (! $this->_set_reg_event()) {
2805
-            throw new EE_Error(
2806
-                esc_html__(
2807
-                    'Unable to continue with registering because there is no Event ID in the request',
2808
-                    'event_espresso'
2809
-                )
2810
-            );
2811
-        }
2812
-        /** @var CurrentPage $current_page */
2813
-        $current_page = $this->loader->getShared(CurrentPage::class);
2814
-        $current_page->setEspressoPage(true);
2815
-        // gotta start with a clean slate if we're not coming here via ajax
2816
-        if (! defined('DOING_AJAX')
2817
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2818
-        ) {
2819
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2820
-        }
2821
-        $this->_template_args['event_name'] = '';
2822
-        // event name
2823
-        if ($this->_reg_event) {
2824
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2825
-            $edit_event_url = self::add_query_args_and_nonce(
2826
-                array(
2827
-                    'action' => 'edit',
2828
-                    'post'   => $this->_reg_event->ID(),
2829
-                ),
2830
-                EVENTS_ADMIN_URL
2831
-            );
2832
-            $edit_event_lnk = '<a href="'
2833
-                              . $edit_event_url
2834
-                              . '" title="'
2835
-                              . esc_attr__('Edit ', 'event_espresso')
2836
-                              . $this->_reg_event->name()
2837
-                              . '">'
2838
-                              . esc_html__('Edit Event', 'event_espresso')
2839
-                              . '</a>';
2840
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2841
-                                                   . $edit_event_lnk
2842
-                                                   . '</span>';
2843
-        }
2844
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2845
-        if (defined('DOING_AJAX')) {
2846
-            $this->_return_json();
2847
-        }
2848
-        // grab header
2849
-        $template_path =
2850
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2851
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2852
-            $template_path,
2853
-            $this->_template_args,
2854
-            true
2855
-        );
2856
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2857
-        // the details template wrapper
2858
-        $this->display_admin_page_with_sidebar();
2859
-    }
2860
-
2861
-
2862
-    /**
2863
-     * This returns the content for a registration step
2864
-     *
2865
-     * @access protected
2866
-     * @return string html
2867
-     * @throws DomainException
2868
-     * @throws EE_Error
2869
-     * @throws InvalidArgumentException
2870
-     * @throws InvalidDataTypeException
2871
-     * @throws InvalidInterfaceException
2872
-     */
2873
-    protected function _get_registration_step_content()
2874
-    {
2875
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2876
-            $warning_msg = sprintf(
2877
-                esc_html__(
2878
-                    '%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',
2879
-                    'event_espresso'
2880
-                ),
2881
-                '<br />',
2882
-                '<h3 class="important-notice">',
2883
-                '</h3>',
2884
-                '<div class="float-right">',
2885
-                '<span id="redirect_timer" class="important-notice">30</span>',
2886
-                '</div>',
2887
-                '<b>',
2888
-                '</b>'
2889
-            );
2890
-            return '
2305
+	}
2306
+
2307
+
2308
+	/**
2309
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2310
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2311
+	 * to display the page
2312
+	 *
2313
+	 * @access protected
2314
+	 * @return void
2315
+	 * @throws EE_Error
2316
+	 * @throws InvalidArgumentException
2317
+	 * @throws InvalidDataTypeException
2318
+	 * @throws InvalidInterfaceException
2319
+	 * @throws ReflectionException
2320
+	 */
2321
+	protected function _update_attendee_registration_form()
2322
+	{
2323
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2324
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2325
+			$REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2326
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2327
+			if ($success) {
2328
+				$what = esc_html__('Registration Form', 'event_espresso');
2329
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2330
+					: array('action' => 'default');
2331
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2332
+			}
2333
+		}
2334
+	}
2335
+
2336
+
2337
+	/**
2338
+	 * Gets the form for saving registrations custom questions (if done
2339
+	 * previously retrieves the cached form object, which may have validation errors in it)
2340
+	 *
2341
+	 * @param int $REG_ID
2342
+	 * @return EE_Registration_Custom_Questions_Form
2343
+	 * @throws EE_Error
2344
+	 * @throws InvalidArgumentException
2345
+	 * @throws InvalidDataTypeException
2346
+	 * @throws InvalidInterfaceException
2347
+	 */
2348
+	protected function _get_reg_custom_questions_form($REG_ID)
2349
+	{
2350
+		if (! $this->_reg_custom_questions_form) {
2351
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2352
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2353
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2354
+			);
2355
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2356
+		}
2357
+		return $this->_reg_custom_questions_form;
2358
+	}
2359
+
2360
+
2361
+	/**
2362
+	 * Saves
2363
+	 *
2364
+	 * @access private
2365
+	 * @param bool $REG_ID
2366
+	 * @return bool
2367
+	 * @throws EE_Error
2368
+	 * @throws InvalidArgumentException
2369
+	 * @throws InvalidDataTypeException
2370
+	 * @throws InvalidInterfaceException
2371
+	 * @throws ReflectionException
2372
+	 */
2373
+	private function _save_reg_custom_questions_form($REG_ID = false)
2374
+	{
2375
+		if (! $REG_ID) {
2376
+			EE_Error::add_error(
2377
+				esc_html__(
2378
+					'An error occurred. No registration ID was received.',
2379
+					'event_espresso'
2380
+				),
2381
+				__FILE__,
2382
+				__FUNCTION__,
2383
+				__LINE__
2384
+			);
2385
+		}
2386
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2387
+		$form->receive_form_submission($this->_req_data);
2388
+		$success = false;
2389
+		if ($form->is_valid()) {
2390
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2391
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2392
+					$where_conditions = array(
2393
+						'QST_ID' => $question_id,
2394
+						'REG_ID' => $REG_ID,
2395
+					);
2396
+					$possibly_new_values = array(
2397
+						'ANS_value' => $input->normalized_value(),
2398
+					);
2399
+					$answer = EEM_Answer::instance()->get_one(array($where_conditions));
2400
+					if ($answer instanceof EE_Answer) {
2401
+						$success = $answer->save($possibly_new_values);
2402
+					} else {
2403
+						// insert it then
2404
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2405
+						$answer = EE_Answer::new_instance($cols_n_vals);
2406
+						$success = $answer->save();
2407
+					}
2408
+				}
2409
+			}
2410
+		} else {
2411
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2412
+		}
2413
+		return $success;
2414
+	}
2415
+
2416
+
2417
+	/**
2418
+	 *        generates HTML for the Registration main meta box
2419
+	 *
2420
+	 * @access public
2421
+	 * @return void
2422
+	 * @throws DomainException
2423
+	 * @throws EE_Error
2424
+	 * @throws InvalidArgumentException
2425
+	 * @throws InvalidDataTypeException
2426
+	 * @throws InvalidInterfaceException
2427
+	 * @throws ReflectionException
2428
+	 */
2429
+	public function _reg_attendees_meta_box()
2430
+	{
2431
+		$REG = $this->getRegistrationModel();
2432
+		// get all other registrations on this transaction, and cache
2433
+		// the attendees for them so we don't have to run another query using force_join
2434
+		$registrations = $REG->get_all(
2435
+			array(
2436
+				array(
2437
+					'TXN_ID' => $this->_registration->transaction_ID(),
2438
+					'REG_ID' => array('!=', $this->_registration->ID()),
2439
+				),
2440
+				'force_join' => array('Attendee'),
2441
+				'default_where_conditions' => 'other_models_only',
2442
+			)
2443
+		);
2444
+		$this->_template_args['attendees'] = array();
2445
+		$this->_template_args['attendee_notice'] = '';
2446
+		if (empty($registrations)
2447
+			|| (is_array($registrations)
2448
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2449
+		) {
2450
+			EE_Error::add_error(
2451
+				esc_html__(
2452
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2453
+					'event_espresso'
2454
+				),
2455
+				__FILE__,
2456
+				__FUNCTION__,
2457
+				__LINE__
2458
+			);
2459
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2460
+		} else {
2461
+			$att_nmbr = 1;
2462
+			foreach ($registrations as $registration) {
2463
+				/* @var $registration EE_Registration */
2464
+				$attendee = $registration->attendee()
2465
+					? $registration->attendee()
2466
+					: $this->getAttendeeModel()->create_default_object();
2467
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2468
+				$this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2469
+				$this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2470
+				$this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2471
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2472
+				$this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2473
+					', ',
2474
+					$attendee->full_address_as_array()
2475
+				);
2476
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2477
+					array(
2478
+						'action' => 'edit_attendee',
2479
+						'post'   => $attendee->ID(),
2480
+					),
2481
+					REG_ADMIN_URL
2482
+				);
2483
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2484
+					? $registration->event_obj()->name()
2485
+					: '';
2486
+				$att_nmbr++;
2487
+			}
2488
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2489
+		}
2490
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2491
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2492
+	}
2493
+
2494
+
2495
+	/**
2496
+	 *        generates HTML for the Edit Registration side meta box
2497
+	 *
2498
+	 * @access public
2499
+	 * @return void
2500
+	 * @throws DomainException
2501
+	 * @throws EE_Error
2502
+	 * @throws InvalidArgumentException
2503
+	 * @throws InvalidDataTypeException
2504
+	 * @throws InvalidInterfaceException
2505
+	 * @throws ReflectionException
2506
+	 */
2507
+	public function _reg_registrant_side_meta_box()
2508
+	{
2509
+		/*@var $attendee EE_Attendee */
2510
+		$att_check = $this->_registration->attendee();
2511
+		$attendee = $att_check instanceof EE_Attendee
2512
+			? $att_check
2513
+			: $this->getAttendeeModel()->create_default_object();
2514
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2515
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2516
+		// primary registration object (that way we know if we need to show create button or not)
2517
+		if (! $this->_registration->is_primary_registrant()) {
2518
+			$primary_registration = $this->_registration->get_primary_registration();
2519
+			$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2520
+				: null;
2521
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2522
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2523
+				// custom attendee object so let's not worry about the primary reg.
2524
+				$primary_registration = null;
2525
+			}
2526
+		} else {
2527
+			$primary_registration = null;
2528
+		}
2529
+		$this->_template_args['ATT_ID'] = $attendee->ID();
2530
+		$this->_template_args['fname'] = $attendee->fname();
2531
+		$this->_template_args['lname'] = $attendee->lname();
2532
+		$this->_template_args['email'] = $attendee->email();
2533
+		$this->_template_args['phone'] = $attendee->phone();
2534
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2535
+		// edit link
2536
+		$this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2537
+			array(
2538
+				'action' => 'edit_attendee',
2539
+				'post'   => $attendee->ID(),
2540
+			),
2541
+			REG_ADMIN_URL
2542
+		);
2543
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2544
+		// create link
2545
+		$this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2546
+			? EE_Admin_Page::add_query_args_and_nonce(
2547
+				array(
2548
+					'action'  => 'duplicate_attendee',
2549
+					'_REG_ID' => $this->_registration->ID(),
2550
+				),
2551
+				REG_ADMIN_URL
2552
+			) : '';
2553
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2554
+		$this->_template_args['att_check'] = $att_check;
2555
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2556
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2557
+	}
2558
+
2559
+
2560
+	/**
2561
+	 * trash or restore registrations
2562
+	 *
2563
+	 * @param  boolean $trash whether to archive or restore
2564
+	 * @return void
2565
+	 * @throws EE_Error
2566
+	 * @throws InvalidArgumentException
2567
+	 * @throws InvalidDataTypeException
2568
+	 * @throws InvalidInterfaceException
2569
+	 * @throws RuntimeException
2570
+	 * @access protected
2571
+	 */
2572
+	protected function _trash_or_restore_registrations($trash = true)
2573
+	{
2574
+		// if empty _REG_ID then get out because there's nothing to do
2575
+		if (empty($this->_req_data['_REG_ID'])) {
2576
+			EE_Error::add_error(
2577
+				sprintf(
2578
+					esc_html__(
2579
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2580
+						'event_espresso'
2581
+					),
2582
+					$trash ? 'trash' : 'restore'
2583
+				),
2584
+				__FILE__,
2585
+				__LINE__,
2586
+				__FUNCTION__
2587
+			);
2588
+			$this->_redirect_after_action(false, '', '', array(), true);
2589
+		}
2590
+		$success = 0;
2591
+		$overwrite_msgs = false;
2592
+		// Checkboxes
2593
+		if (! is_array($this->_req_data['_REG_ID'])) {
2594
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2595
+		}
2596
+		$reg_count = count($this->_req_data['_REG_ID']);
2597
+		// cycle thru checkboxes
2598
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2599
+			/** @var EE_Registration $REG */
2600
+			$REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2601
+			$payments = $REG->registration_payments();
2602
+			if (! empty($payments)) {
2603
+				$name = $REG->attendee() instanceof EE_Attendee
2604
+					? $REG->attendee()->full_name()
2605
+					: esc_html__('Unknown Attendee', 'event_espresso');
2606
+				$overwrite_msgs = true;
2607
+				EE_Error::add_error(
2608
+					sprintf(
2609
+						esc_html__(
2610
+							'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.',
2611
+							'event_espresso'
2612
+						),
2613
+						$name
2614
+					),
2615
+					__FILE__,
2616
+					__FUNCTION__,
2617
+					__LINE__
2618
+				);
2619
+				// can't trash this registration because it has payments.
2620
+				continue;
2621
+			}
2622
+			$updated = $trash ? $REG->delete() : $REG->restore();
2623
+			if ($updated) {
2624
+				$success++;
2625
+			}
2626
+		}
2627
+		$this->_redirect_after_action(
2628
+			$success === $reg_count, // were ALL registrations affected?
2629
+			$success > 1
2630
+				? esc_html__('Registrations', 'event_espresso')
2631
+				: esc_html__('Registration', 'event_espresso'),
2632
+			$trash
2633
+				? esc_html__('moved to the trash', 'event_espresso')
2634
+				: esc_html__('restored', 'event_espresso'),
2635
+			$this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2636
+			$overwrite_msgs
2637
+		);
2638
+	}
2639
+
2640
+
2641
+	/**
2642
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2643
+	 * registration but also.
2644
+	 * 1. Removing relations to EE_Attendee
2645
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2646
+	 * ALSO trashed.
2647
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2648
+	 * 4. Removing relationships between all tickets and the related registrations
2649
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2650
+	 * 6. Deleting permanently any related Checkins.
2651
+	 *
2652
+	 * @return void
2653
+	 * @throws EE_Error
2654
+	 * @throws InvalidArgumentException
2655
+	 * @throws InvalidDataTypeException
2656
+	 * @throws InvalidInterfaceException
2657
+	 * @throws ReflectionException
2658
+	 */
2659
+	protected function _delete_registrations()
2660
+	{
2661
+		$REG_MDL = $this->getRegistrationModel();
2662
+		$success = 1;
2663
+		// Checkboxes
2664
+		if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2665
+			// if array has more than one element than success message should be plural
2666
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2667
+			// cycle thru checkboxes
2668
+			foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2669
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2670
+				if (! $REG instanceof EE_Registration) {
2671
+					continue;
2672
+				}
2673
+				$deleted = $this->_delete_registration($REG);
2674
+				if (! $deleted) {
2675
+					$success = 0;
2676
+				}
2677
+			}
2678
+		} else {
2679
+			// grab single id and delete
2680
+			$REG_ID = $this->_req_data['_REG_ID'];
2681
+			/** @var EE_Registration $REG */
2682
+			$REG = $REG_MDL->get_one_by_ID($REG_ID);
2683
+			$deleted = $this->_delete_registration($REG);
2684
+			if (! $deleted) {
2685
+				$success = 0;
2686
+			}
2687
+		}
2688
+		$what = $success > 1
2689
+			? esc_html__('Registrations', 'event_espresso')
2690
+			: esc_html__('Registration', 'event_espresso');
2691
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2692
+		$this->_redirect_after_action(
2693
+			$success,
2694
+			$what,
2695
+			$action_desc,
2696
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2697
+			true
2698
+		);
2699
+	}
2700
+
2701
+
2702
+	/**
2703
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2704
+	 * models get affected.
2705
+	 *
2706
+	 * @param EE_Registration $REG registration to be deleted permanently
2707
+	 * @return bool true = successful deletion, false = fail.
2708
+	 * @throws EE_Error
2709
+	 * @throws InvalidArgumentException
2710
+	 * @throws InvalidDataTypeException
2711
+	 * @throws InvalidInterfaceException
2712
+	 * @throws ReflectionException
2713
+	 */
2714
+	protected function _delete_registration(EE_Registration $REG)
2715
+	{
2716
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2717
+		// registrations on the transaction that are NOT trashed.
2718
+		$TXN = $REG->get_first_related('Transaction');
2719
+		if (! $TXN instanceof EE_Transaction) {
2720
+			EE_Error::add_error(
2721
+				sprintf(
2722
+					esc_html__(
2723
+						'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.',
2724
+						'event_espresso'
2725
+					),
2726
+					$REG->id()
2727
+				),
2728
+				__FILE__,
2729
+				__FUNCTION__,
2730
+				__LINE__
2731
+			);
2732
+			return false;
2733
+		}
2734
+		$REGS = $TXN->get_many_related('Registration');
2735
+		$all_trashed = true;
2736
+		foreach ($REGS as $registration) {
2737
+			if (! $registration->get('REG_deleted')) {
2738
+				$all_trashed = false;
2739
+			}
2740
+		}
2741
+		if (! $all_trashed) {
2742
+			EE_Error::add_error(
2743
+				esc_html__(
2744
+					'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.',
2745
+					'event_espresso'
2746
+				),
2747
+				__FILE__,
2748
+				__FUNCTION__,
2749
+				__LINE__
2750
+			);
2751
+			return false;
2752
+		}
2753
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2754
+		// separately from THIS one).
2755
+		foreach ($REGS as $registration) {
2756
+			// delete related answers
2757
+			$registration->delete_related_permanently('Answer');
2758
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2759
+			$attendee = $registration->get_first_related('Attendee');
2760
+			if ($attendee instanceof EE_Attendee) {
2761
+				$registration->_remove_relation_to($attendee, 'Attendee');
2762
+			}
2763
+			// now remove relationships to tickets on this registration.
2764
+			$registration->_remove_relations('Ticket');
2765
+			// now delete permanently the checkins related to this registration.
2766
+			$registration->delete_related_permanently('Checkin');
2767
+			if ($registration->ID() === $REG->ID()) {
2768
+				continue;
2769
+			} //we don't want to delete permanently the existing registration just yet.
2770
+			// remove relation to transaction for these registrations if NOT the existing registrations
2771
+			$registration->_remove_relations('Transaction');
2772
+			// delete permanently any related messages.
2773
+			$registration->delete_related_permanently('Message');
2774
+			// now delete this registration permanently
2775
+			$registration->delete_permanently();
2776
+		}
2777
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2778
+		// (the transaction and line items should be all that's left).
2779
+		// delete the line items related to the transaction for this registration.
2780
+		$TXN->delete_related_permanently('Line_Item');
2781
+		// we need to remove all the relationships on the transaction
2782
+		$TXN->delete_related_permanently('Payment');
2783
+		$TXN->delete_related_permanently('Extra_Meta');
2784
+		$TXN->delete_related_permanently('Message');
2785
+		// now we can delete this REG permanently (and the transaction of course)
2786
+		$REG->delete_related_permanently('Transaction');
2787
+		return $REG->delete_permanently();
2788
+	}
2789
+
2790
+
2791
+	/**
2792
+	 *    generates HTML for the Register New Attendee Admin page
2793
+	 *
2794
+	 * @access private
2795
+	 * @throws DomainException
2796
+	 * @throws EE_Error
2797
+	 * @throws InvalidArgumentException
2798
+	 * @throws InvalidDataTypeException
2799
+	 * @throws InvalidInterfaceException
2800
+	 * @throws ReflectionException
2801
+	 */
2802
+	public function new_registration()
2803
+	{
2804
+		if (! $this->_set_reg_event()) {
2805
+			throw new EE_Error(
2806
+				esc_html__(
2807
+					'Unable to continue with registering because there is no Event ID in the request',
2808
+					'event_espresso'
2809
+				)
2810
+			);
2811
+		}
2812
+		/** @var CurrentPage $current_page */
2813
+		$current_page = $this->loader->getShared(CurrentPage::class);
2814
+		$current_page->setEspressoPage(true);
2815
+		// gotta start with a clean slate if we're not coming here via ajax
2816
+		if (! defined('DOING_AJAX')
2817
+			&& (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2818
+		) {
2819
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2820
+		}
2821
+		$this->_template_args['event_name'] = '';
2822
+		// event name
2823
+		if ($this->_reg_event) {
2824
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2825
+			$edit_event_url = self::add_query_args_and_nonce(
2826
+				array(
2827
+					'action' => 'edit',
2828
+					'post'   => $this->_reg_event->ID(),
2829
+				),
2830
+				EVENTS_ADMIN_URL
2831
+			);
2832
+			$edit_event_lnk = '<a href="'
2833
+							  . $edit_event_url
2834
+							  . '" title="'
2835
+							  . esc_attr__('Edit ', 'event_espresso')
2836
+							  . $this->_reg_event->name()
2837
+							  . '">'
2838
+							  . esc_html__('Edit Event', 'event_espresso')
2839
+							  . '</a>';
2840
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2841
+												   . $edit_event_lnk
2842
+												   . '</span>';
2843
+		}
2844
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2845
+		if (defined('DOING_AJAX')) {
2846
+			$this->_return_json();
2847
+		}
2848
+		// grab header
2849
+		$template_path =
2850
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2851
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2852
+			$template_path,
2853
+			$this->_template_args,
2854
+			true
2855
+		);
2856
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2857
+		// the details template wrapper
2858
+		$this->display_admin_page_with_sidebar();
2859
+	}
2860
+
2861
+
2862
+	/**
2863
+	 * This returns the content for a registration step
2864
+	 *
2865
+	 * @access protected
2866
+	 * @return string html
2867
+	 * @throws DomainException
2868
+	 * @throws EE_Error
2869
+	 * @throws InvalidArgumentException
2870
+	 * @throws InvalidDataTypeException
2871
+	 * @throws InvalidInterfaceException
2872
+	 */
2873
+	protected function _get_registration_step_content()
2874
+	{
2875
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2876
+			$warning_msg = sprintf(
2877
+				esc_html__(
2878
+					'%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',
2879
+					'event_espresso'
2880
+				),
2881
+				'<br />',
2882
+				'<h3 class="important-notice">',
2883
+				'</h3>',
2884
+				'<div class="float-right">',
2885
+				'<span id="redirect_timer" class="important-notice">30</span>',
2886
+				'</div>',
2887
+				'<b>',
2888
+				'</b>'
2889
+			);
2890
+			return '
2891 2891
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2892 2892
 	<script >
2893 2893
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2900,870 +2900,870 @@  discard block
 block discarded – undo
2900 2900
 	        }
2901 2901
 	    }, 800 );
2902 2902
 	</script >';
2903
-        }
2904
-        $template_args = array(
2905
-            'title'                    => '',
2906
-            'content'                  => '',
2907
-            'step_button_text'         => '',
2908
-            'show_notification_toggle' => false,
2909
-        );
2910
-        // to indicate we're processing a new registration
2911
-        $hidden_fields = array(
2912
-            'processing_registration' => array(
2913
-                'type'  => 'hidden',
2914
-                'value' => 0,
2915
-            ),
2916
-            'event_id'                => array(
2917
-                'type'  => 'hidden',
2918
-                'value' => $this->_reg_event->ID(),
2919
-            ),
2920
-        );
2921
-        // if the cart is empty then we know we're at step one so we'll display ticket selector
2922
-        $cart = EE_Registry::instance()->SSN->cart();
2923
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2924
-        switch ($step) {
2925
-            case 'ticket':
2926
-                $hidden_fields['processing_registration']['value'] = 1;
2927
-                $template_args['title'] = esc_html__(
2928
-                    'Step One: Select the Ticket for this registration',
2929
-                    'event_espresso'
2930
-                );
2931
-                $template_args['content'] =
2932
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2933
-                $template_args['content'] .= '</div>';
2934
-                $template_args['step_button_text'] = esc_html__(
2935
-                    'Add Tickets and Continue to Registrant Details',
2936
-                    'event_espresso'
2937
-                );
2938
-                $template_args['show_notification_toggle'] = false;
2939
-                break;
2940
-            case 'questions':
2941
-                $hidden_fields['processing_registration']['value'] = 2;
2942
-                $template_args['title'] = esc_html__(
2943
-                    'Step Two: Add Registrant Details for this Registration',
2944
-                    'event_espresso'
2945
-                );
2946
-                // in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2947
-                // properly by the first process_reg_step run.
2948
-                $template_args['content'] =
2949
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2950
-                $template_args['step_button_text'] = esc_html__(
2951
-                    'Save Registration and Continue to Details',
2952
-                    'event_espresso'
2953
-                );
2954
-                $template_args['show_notification_toggle'] = true;
2955
-                break;
2956
-        }
2957
-        // we come back to the process_registration_step route.
2958
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2959
-        return EEH_Template::display_template(
2960
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2961
-            $template_args,
2962
-            true
2963
-        );
2964
-    }
2965
-
2966
-
2967
-    /**
2968
-     *        set_reg_event
2969
-     *
2970
-     * @access private
2971
-     * @return bool
2972
-     * @throws EE_Error
2973
-     * @throws InvalidArgumentException
2974
-     * @throws InvalidDataTypeException
2975
-     * @throws InvalidInterfaceException
2976
-     */
2977
-    private function _set_reg_event()
2978
-    {
2979
-        if (is_object($this->_reg_event)) {
2980
-            return true;
2981
-        }
2982
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2983
-        if (! $EVT_ID) {
2984
-            return false;
2985
-        }
2986
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2987
-        return true;
2988
-    }
2989
-
2990
-
2991
-    /**
2992
-     * process_reg_step
2993
-     *
2994
-     * @access        public
2995
-     * @return string
2996
-     * @throws DomainException
2997
-     * @throws EE_Error
2998
-     * @throws InvalidArgumentException
2999
-     * @throws InvalidDataTypeException
3000
-     * @throws InvalidInterfaceException
3001
-     * @throws ReflectionException
3002
-     * @throws RuntimeException
3003
-     */
3004
-    public function process_reg_step()
3005
-    {
3006
-        EE_System::do_not_cache();
3007
-        $this->_set_reg_event();
3008
-        /** @var CurrentPage $current_page */
3009
-        $current_page = $this->loader->getShared(CurrentPage::class);
3010
-        $current_page->setEspressoPage(true);
3011
-        $this->request->setRequestParam('uts', time());
3012
-        // what step are we on?
3013
-        $cart = EE_Registry::instance()->SSN->cart();
3014
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3015
-        // if doing ajax then we need to verify the nonce
3016
-        if (defined('DOING_AJAX')) {
3017
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3018
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3019
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3020
-        }
3021
-        switch ($step) {
3022
-            case 'ticket':
3023
-                // process ticket selection
3024
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3025
-                if ($success) {
3026
-                    EE_Error::add_success(
3027
-                        esc_html__(
3028
-                            'Tickets Selected. Now complete the registration.',
3029
-                            'event_espresso'
3030
-                        )
3031
-                    );
3032
-                } else {
3033
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3034
-                }
3035
-                if (defined('DOING_AJAX')) {
3036
-                    $this->new_registration(); // display next step
3037
-                } else {
3038
-                    $query_args = array(
3039
-                        'action'                  => 'new_registration',
3040
-                        'processing_registration' => 1,
3041
-                        'event_id'                => $this->_reg_event->ID(),
3042
-                        'uts'                     => time(),
3043
-                    );
3044
-                    $this->_redirect_after_action(
3045
-                        false,
3046
-                        '',
3047
-                        '',
3048
-                        $query_args,
3049
-                        true
3050
-                    );
3051
-                }
3052
-                break;
3053
-            case 'questions':
3054
-                if (! isset(
3055
-                    $this->_req_data['txn_reg_status_change'],
3056
-                    $this->_req_data['txn_reg_status_change']['send_notifications']
3057
-                )
3058
-                ) {
3059
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3060
-                }
3061
-                // process registration
3062
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3063
-                if ($cart instanceof EE_Cart) {
3064
-                    $grand_total = $cart->get_cart_grand_total();
3065
-                    if ($grand_total instanceof EE_Line_Item) {
3066
-                        $grand_total->save_this_and_descendants_to_txn();
3067
-                    }
3068
-                }
3069
-                if (! $transaction instanceof EE_Transaction) {
3070
-                    $query_args = array(
3071
-                        'action'                  => 'new_registration',
3072
-                        'processing_registration' => 2,
3073
-                        'event_id'                => $this->_reg_event->ID(),
3074
-                        'uts'                     => time(),
3075
-                    );
3076
-                    if (defined('DOING_AJAX')) {
3077
-                        // display registration form again because there are errors (maybe validation?)
3078
-                        $this->new_registration();
3079
-                        return;
3080
-                    }
3081
-                    $this->_redirect_after_action(
3082
-                        false,
3083
-                        '',
3084
-                        '',
3085
-                        $query_args,
3086
-                        true
3087
-                    );
3088
-                    return;
3089
-                }
3090
-                // maybe update status, and make sure to save transaction if not done already
3091
-                if (! $transaction->update_status_based_on_total_paid()) {
3092
-                    $transaction->save();
3093
-                }
3094
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3095
-                $this->_req_data = array();
3096
-                $query_args = array(
3097
-                    'action'        => 'redirect_to_txn',
3098
-                    'TXN_ID'        => $transaction->ID(),
3099
-                    'EVT_ID'        => $this->_reg_event->ID(),
3100
-                    'event_name'    => urlencode($this->_reg_event->name()),
3101
-                    'redirect_from' => 'new_registration',
3102
-                );
3103
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3104
-                break;
3105
-        }
3106
-        // what are you looking here for?  Should be nothing to do at this point.
3107
-    }
3108
-
3109
-
3110
-    /**
3111
-     * redirect_to_txn
3112
-     *
3113
-     * @access public
3114
-     * @return void
3115
-     * @throws EE_Error
3116
-     * @throws InvalidArgumentException
3117
-     * @throws InvalidDataTypeException
3118
-     * @throws InvalidInterfaceException
3119
-     * @throws ReflectionException
3120
-     */
3121
-    public function redirect_to_txn()
3122
-    {
3123
-        EE_System::do_not_cache();
3124
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3125
-        $query_args = array(
3126
-            'action' => 'view_transaction',
3127
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3128
-            'page'   => 'espresso_transactions',
3129
-        );
3130
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3131
-            $query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3132
-            $query_args['event_name'] = urlencode($this->_req_data['event_name']);
3133
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3134
-        }
3135
-        EE_Error::add_success(
3136
-            esc_html__(
3137
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3138
-                'event_espresso'
3139
-            )
3140
-        );
3141
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3142
-    }
3143
-
3144
-
3145
-    /**
3146
-     *        generates HTML for the Attendee Contact List
3147
-     *
3148
-     * @access protected
3149
-     * @return void
3150
-     * @throws DomainException
3151
-     * @throws EE_Error
3152
-     */
3153
-    protected function _attendee_contact_list_table()
3154
-    {
3155
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3156
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3157
-        $this->display_admin_list_table_page_with_no_sidebar();
3158
-    }
3159
-
3160
-
3161
-    /**
3162
-     *        get_attendees
3163
-     *
3164
-     * @param      $per_page
3165
-     * @param bool $count whether to return count or data.
3166
-     * @param bool $trash
3167
-     * @return array
3168
-     * @throws EE_Error
3169
-     * @throws InvalidArgumentException
3170
-     * @throws InvalidDataTypeException
3171
-     * @throws InvalidInterfaceException
3172
-     * @access public
3173
-     */
3174
-    public function get_attendees($per_page, $count = false, $trash = false)
3175
-    {
3176
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3177
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3178
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3179
-        switch ($this->_req_data['orderby']) {
3180
-            case 'ATT_ID':
3181
-                $orderby = 'ATT_ID';
3182
-                break;
3183
-            case 'ATT_fname':
3184
-                $orderby = 'ATT_fname';
3185
-                break;
3186
-            case 'ATT_email':
3187
-                $orderby = 'ATT_email';
3188
-                break;
3189
-            case 'ATT_city':
3190
-                $orderby = 'ATT_city';
3191
-                break;
3192
-            case 'STA_ID':
3193
-                $orderby = 'STA_ID';
3194
-                break;
3195
-            case 'CNT_ID':
3196
-                $orderby = 'CNT_ID';
3197
-                break;
3198
-            case 'Registration_Count':
3199
-                $orderby = 'Registration_Count';
3200
-                break;
3201
-            default:
3202
-                $orderby = 'ATT_lname';
3203
-        }
3204
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3205
-            ? $this->_req_data['order']
3206
-            : 'ASC';
3207
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3208
-            ? $this->_req_data['paged']
3209
-            : 1;
3210
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3211
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3212
-            ? $this->_req_data['perpage']
3213
-            : $per_page;
3214
-        $_where = array();
3215
-        if (! empty($this->_req_data['s'])) {
3216
-            $sstr = '%' . $this->_req_data['s'] . '%';
3217
-            $_where['OR'] = array(
3218
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3219
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3220
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3221
-                'ATT_fname'                         => array('LIKE', $sstr),
3222
-                'ATT_lname'                         => array('LIKE', $sstr),
3223
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3224
-                'ATT_email'                         => array('LIKE', $sstr),
3225
-                'ATT_address'                       => array('LIKE', $sstr),
3226
-                'ATT_address2'                      => array('LIKE', $sstr),
3227
-                'ATT_city'                          => array('LIKE', $sstr),
3228
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3229
-                'State.STA_name'                    => array('LIKE', $sstr),
3230
-                'ATT_phone'                         => array('LIKE', $sstr),
3231
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3232
-                'Registration.REG_code'             => array('LIKE', $sstr),
3233
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3234
-            );
3235
-        }
3236
-        $offset = ($current_page - 1) * $per_page;
3237
-        $limit = $count ? null : array($offset, $per_page);
3238
-        $query_args = array(
3239
-            $_where,
3240
-            'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3241
-            'limit'         => $limit,
3242
-        );
3243
-        if (! $count) {
3244
-            $query_args['order_by'] = array($orderby => $sort);
3245
-        }
3246
-        if ($trash) {
3247
-            $query_args[0]['status'] = array('!=', 'publish');
3248
-            $all_attendees = $count
3249
-                ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3250
-                : $this->getAttendeeModel()->get_all($query_args);
3251
-        } else {
3252
-            $query_args[0]['status'] = array('IN', array('publish'));
3253
-            $all_attendees = $count
3254
-                ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3255
-                : $this->getAttendeeModel()->get_all($query_args);
3256
-        }
3257
-        return $all_attendees;
3258
-    }
3259
-
3260
-
3261
-    /**
3262
-     * This is just taking care of resending the registration confirmation
3263
-     *
3264
-     * @access protected
3265
-     * @return void
3266
-     * @throws EE_Error
3267
-     * @throws InvalidArgumentException
3268
-     * @throws InvalidDataTypeException
3269
-     * @throws InvalidInterfaceException
3270
-     * @throws ReflectionException
3271
-     */
3272
-    protected function _resend_registration()
3273
-    {
3274
-        $this->_process_resend_registration();
3275
-        $query_args = isset($this->_req_data['redirect_to'])
3276
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3277
-            : array('action' => 'default');
3278
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3279
-    }
3280
-
3281
-    /**
3282
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3283
-     * to use when selecting registrations
3284
-     *
3285
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3286
-     *                                                     the query parameters from the request
3287
-     * @return void ends the request with a redirect or download
3288
-     */
3289
-    public function _registrations_report_base($method_name_for_getting_query_params)
3290
-    {
3291
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3292
-            wp_redirect(
3293
-                EE_Admin_Page::add_query_args_and_nonce(
3294
-                    array(
3295
-                        'page'        => 'espresso_batch',
3296
-                        'batch'       => 'file',
3297
-                        'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3298
-                        'filters'     => urlencode(
3299
-                            serialize(
3300
-                                $this->$method_name_for_getting_query_params(
3301
-                                    EEH_Array::is_set(
3302
-                                        $this->_req_data,
3303
-                                        'filters',
3304
-                                        array()
3305
-                                    )
3306
-                                )
3307
-                            )
3308
-                        ),
3309
-                        'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3310
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3311
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3312
-                    )
3313
-                )
3314
-            );
3315
-        } else {
3316
-            $new_request_args = array(
3317
-                'export' => 'report',
3318
-                'action' => 'registrations_report_for_event',
3319
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3320
-            );
3321
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3322
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3323
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3324
-                $EE_Export = EE_Export::instance($this->_req_data);
3325
-                $EE_Export->export();
3326
-            }
3327
-        }
3328
-    }
3329
-
3330
-
3331
-    /**
3332
-     * Creates a registration report using only query parameters in the request
3333
-     *
3334
-     * @return void
3335
-     */
3336
-    public function _registrations_report()
3337
-    {
3338
-        $this->_registrations_report_base('_get_registration_query_parameters');
3339
-    }
3340
-
3341
-
3342
-    public function _contact_list_export()
3343
-    {
3344
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3345
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3346
-            $EE_Export = EE_Export::instance($this->_req_data);
3347
-            $EE_Export->export_attendees();
3348
-        }
3349
-    }
3350
-
3351
-
3352
-    public function _contact_list_report()
3353
-    {
3354
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3355
-            wp_redirect(
3356
-                EE_Admin_Page::add_query_args_and_nonce(
3357
-                    array(
3358
-                        'page'        => 'espresso_batch',
3359
-                        'batch'       => 'file',
3360
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3361
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3362
-                    )
3363
-                )
3364
-            );
3365
-        } else {
3366
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3367
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3368
-                $EE_Export = EE_Export::instance($this->_req_data);
3369
-                $EE_Export->report_attendees();
3370
-            }
3371
-        }
3372
-    }
3373
-
3374
-
3375
-
3376
-
3377
-
3378
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3379
-    /**
3380
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3381
-     *
3382
-     * @return void
3383
-     * @throws EE_Error
3384
-     * @throws InvalidArgumentException
3385
-     * @throws InvalidDataTypeException
3386
-     * @throws InvalidInterfaceException
3387
-     * @throws ReflectionException
3388
-     */
3389
-    protected function _duplicate_attendee()
3390
-    {
3391
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3392
-        // verify we have necessary info
3393
-        if (empty($this->_req_data['_REG_ID'])) {
3394
-            EE_Error::add_error(
3395
-                esc_html__(
3396
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3397
-                    'event_espresso'
3398
-                ),
3399
-                __FILE__,
3400
-                __LINE__,
3401
-                __FUNCTION__
3402
-            );
3403
-            $query_args = array('action' => $action);
3404
-            $this->_redirect_after_action('', '', '', $query_args, true);
3405
-        }
3406
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3407
-        $registration = $this->getRegistrationModel()->get_one_by_ID($this->_req_data['_REG_ID']);
3408
-        $attendee = $registration->attendee();
3409
-        // remove relation of existing attendee on registration
3410
-        $registration->_remove_relation_to($attendee, 'Attendee');
3411
-        // new attendee
3412
-        $new_attendee = clone $attendee;
3413
-        $new_attendee->set('ATT_ID', 0);
3414
-        $new_attendee->save();
3415
-        // add new attendee to reg
3416
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3417
-        EE_Error::add_success(
3418
-            esc_html__(
3419
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3420
-                'event_espresso'
3421
-            )
3422
-        );
3423
-        // redirect to edit page for attendee
3424
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3425
-        $this->_redirect_after_action('', '', '', $query_args, true);
3426
-    }
3427
-
3428
-
3429
-    /**
3430
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3431
-     *
3432
-     * @param int     $post_id
3433
-     * @param WP_POST $post
3434
-     * @throws DomainException
3435
-     * @throws EE_Error
3436
-     * @throws InvalidArgumentException
3437
-     * @throws InvalidDataTypeException
3438
-     * @throws InvalidInterfaceException
3439
-     * @throws LogicException
3440
-     * @throws InvalidFormSubmissionException
3441
-     * @throws ReflectionException
3442
-     */
3443
-    protected function _insert_update_cpt_item($post_id, $post)
3444
-    {
3445
-        $success = true;
3446
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3447
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3448
-            : null;
3449
-        // for attendee updates
3450
-        if ($attendee instanceof EE_Attendee) {
3451
-            // note we should only be UPDATING attendees at this point.
3452
-            $updated_fields = array(
3453
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3454
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3455
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3456
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3457
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3458
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3459
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3460
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3461
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3462
-            );
3463
-            foreach ($updated_fields as $field => $value) {
3464
-                $attendee->set($field, $value);
3465
-            }
3466
-
3467
-            // process contact details metabox form handler (which will also save the attendee)
3468
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3469
-            $success = $contact_details_form->process($this->_req_data);
3470
-
3471
-            $attendee_update_callbacks = apply_filters(
3472
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3473
-                array()
3474
-            );
3475
-            foreach ($attendee_update_callbacks as $a_callback) {
3476
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3477
-                    throw new EE_Error(
3478
-                        sprintf(
3479
-                            esc_html__(
3480
-                                '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.',
3481
-                                'event_espresso'
3482
-                            ),
3483
-                            $a_callback
3484
-                        )
3485
-                    );
3486
-                }
3487
-            }
3488
-        }
3489
-
3490
-        if ($success === false) {
3491
-            EE_Error::add_error(
3492
-                esc_html__(
3493
-                    'Something went wrong with updating the meta table data for the registration.',
3494
-                    'event_espresso'
3495
-                ),
3496
-                __FILE__,
3497
-                __FUNCTION__,
3498
-                __LINE__
3499
-            );
3500
-        }
3501
-    }
3502
-
3503
-
3504
-    public function trash_cpt_item($post_id)
3505
-    {
3506
-    }
3507
-
3508
-
3509
-    public function delete_cpt_item($post_id)
3510
-    {
3511
-    }
3512
-
3513
-
3514
-    public function restore_cpt_item($post_id)
3515
-    {
3516
-    }
3517
-
3518
-
3519
-    protected function _restore_cpt_item($post_id, $revision_id)
3520
-    {
3521
-    }
3522
-
3523
-
3524
-    /**
3525
-     * @throws EE_Error
3526
-     * @since 4.10.2.p
3527
-     */
3528
-    public function attendee_editor_metaboxes()
3529
-    {
3530
-        $this->verify_cpt_object();
3531
-        remove_meta_box(
3532
-            'postexcerpt',
3533
-            $this->_cpt_routes[ $this->_req_action ],
3534
-            'normal'
3535
-        );
3536
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3537
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3538
-            add_meta_box(
3539
-                'postexcerpt',
3540
-                esc_html__('Short Biography', 'event_espresso'),
3541
-                'post_excerpt_meta_box',
3542
-                $this->_cpt_routes[ $this->_req_action ],
3543
-                'normal'
3544
-            );
3545
-        }
3546
-        if (post_type_supports('espresso_attendees', 'comments')) {
3547
-            add_meta_box(
3548
-                'commentsdiv',
3549
-                esc_html__('Notes on the Contact', 'event_espresso'),
3550
-                'post_comment_meta_box',
3551
-                $this->_cpt_routes[ $this->_req_action ],
3552
-                'normal',
3553
-                'core'
3554
-            );
3555
-        }
3556
-        add_meta_box(
3557
-            'attendee_contact_info',
3558
-            esc_html__('Contact Info', 'event_espresso'),
3559
-            array($this, 'attendee_contact_info'),
3560
-            $this->_cpt_routes[ $this->_req_action ],
3561
-            'side',
3562
-            'core'
3563
-        );
3564
-        add_meta_box(
3565
-            'attendee_details_address',
3566
-            esc_html__('Address Details', 'event_espresso'),
3567
-            array($this, 'attendee_address_details'),
3568
-            $this->_cpt_routes[ $this->_req_action ],
3569
-            'normal',
3570
-            'core'
3571
-        );
3572
-        add_meta_box(
3573
-            'attendee_registrations',
3574
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3575
-            array($this, 'attendee_registrations_meta_box'),
3576
-            $this->_cpt_routes[ $this->_req_action ],
3577
-            'normal',
3578
-            'high'
3579
-        );
3580
-    }
3581
-
3582
-
3583
-    /**
3584
-     * Metabox for attendee contact info
3585
-     *
3586
-     * @param  WP_Post $post wp post object
3587
-     * @return string attendee contact info ( and form )
3588
-     * @throws EE_Error
3589
-     * @throws InvalidArgumentException
3590
-     * @throws InvalidDataTypeException
3591
-     * @throws InvalidInterfaceException
3592
-     * @throws LogicException
3593
-     * @throws DomainException
3594
-     */
3595
-    public function attendee_contact_info($post)
3596
-    {
3597
-        // get attendee object ( should already have it )
3598
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3599
-        $form->enqueueStylesAndScripts();
3600
-        echo $form->display();
3601
-    }
3602
-
3603
-
3604
-    /**
3605
-     * Return form handler for the contact details metabox
3606
-     *
3607
-     * @param EE_Attendee $attendee
3608
-     * @return AttendeeContactDetailsMetaboxFormHandler
3609
-     * @throws DomainException
3610
-     * @throws InvalidArgumentException
3611
-     * @throws InvalidDataTypeException
3612
-     * @throws InvalidInterfaceException
3613
-     */
3614
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3615
-    {
3616
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3617
-    }
3618
-
3619
-
3620
-    /**
3621
-     * Metabox for attendee details
3622
-     *
3623
-     * @param  WP_Post $post wp post object
3624
-     * @throws DomainException
3625
-     */
3626
-    public function attendee_address_details($post)
3627
-    {
3628
-        // get attendee object (should already have it)
3629
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3630
-        $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3631
-            new EE_Question_Form_Input(
3632
-                EE_Question::new_instance(
3633
-                    array(
3634
-                        'QST_ID'           => 0,
3635
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3636
-                        'QST_system'       => 'admin-state',
3637
-                    )
3638
-                ),
3639
-                EE_Answer::new_instance(
3640
-                    array(
3641
-                        'ANS_ID'    => 0,
3642
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3643
-                    )
3644
-                ),
3645
-                array(
3646
-                    'input_id'       => 'STA_ID',
3647
-                    'input_name'     => 'STA_ID',
3648
-                    'input_prefix'   => '',
3649
-                    'append_qstn_id' => false,
3650
-                )
3651
-            )
3652
-        );
3653
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3654
-            new EE_Question_Form_Input(
3655
-                EE_Question::new_instance(
3656
-                    array(
3657
-                        'QST_ID'           => 0,
3658
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3659
-                        'QST_system'       => 'admin-country',
3660
-                    )
3661
-                ),
3662
-                EE_Answer::new_instance(
3663
-                    array(
3664
-                        'ANS_ID'    => 0,
3665
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3666
-                    )
3667
-                ),
3668
-                array(
3669
-                    'input_id'       => 'CNT_ISO',
3670
-                    'input_name'     => 'CNT_ISO',
3671
-                    'input_prefix'   => '',
3672
-                    'append_qstn_id' => false,
3673
-                )
3674
-            )
3675
-        );
3676
-        $template =
3677
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3678
-        EEH_Template::display_template($template, $this->_template_args);
3679
-    }
3680
-
3681
-
3682
-    /**
3683
-     *        _attendee_details
3684
-     *
3685
-     * @access protected
3686
-     * @param $post
3687
-     * @return void
3688
-     * @throws DomainException
3689
-     * @throws EE_Error
3690
-     * @throws InvalidArgumentException
3691
-     * @throws InvalidDataTypeException
3692
-     * @throws InvalidInterfaceException
3693
-     * @throws ReflectionException
3694
-     */
3695
-    public function attendee_registrations_meta_box($post)
3696
-    {
3697
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3698
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3699
-        $template =
3700
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3701
-        EEH_Template::display_template($template, $this->_template_args);
3702
-    }
3703
-
3704
-
3705
-    /**
3706
-     * add in the form fields for the attendee edit
3707
-     *
3708
-     * @param  WP_Post $post wp post object
3709
-     * @return string html for new form.
3710
-     * @throws DomainException
3711
-     */
3712
-    public function after_title_form_fields($post)
3713
-    {
3714
-        if ($post->post_type === 'espresso_attendees') {
3715
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3716
-            $template_args['attendee'] = $this->_cpt_model_obj;
3717
-            EEH_Template::display_template($template, $template_args);
3718
-        }
3719
-    }
3720
-
3721
-
3722
-    /**
3723
-     *        _trash_or_restore_attendee
3724
-     *
3725
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3726
-     * @return void
3727
-     * @throws EE_Error
3728
-     * @throws InvalidArgumentException
3729
-     * @throws InvalidDataTypeException
3730
-     * @throws InvalidInterfaceException
3731
-     * @throws ReflectionException
3732
-     * @access protected
3733
-     */
3734
-    protected function _trash_or_restore_attendees($trash = true)
3735
-    {
3736
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3737
-        $success = 1;
3738
-        // Checkboxes
3739
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3740
-            // if array has more than one element than success message should be plural
3741
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3742
-            // cycle thru checkboxes
3743
-            foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3744
-                $updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3745
-                    : $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3746
-                if (! $updated) {
3747
-                    $success = 0;
3748
-                }
3749
-            }
3750
-        } else {
3751
-            // grab single id and delete
3752
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3753
-            // get attendee
3754
-            $att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3755
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3756
-            $updated = $att->save() && $updated;
3757
-            if (! $updated) {
3758
-                $success = 0;
3759
-            }
3760
-        }
3761
-        $what = $success > 1
3762
-            ? esc_html__('Contacts', 'event_espresso')
3763
-            : esc_html__('Contact', 'event_espresso');
3764
-        $action_desc = $trash
3765
-            ? esc_html__('moved to the trash', 'event_espresso')
3766
-            : esc_html__('restored', 'event_espresso');
3767
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3768
-    }
2903
+		}
2904
+		$template_args = array(
2905
+			'title'                    => '',
2906
+			'content'                  => '',
2907
+			'step_button_text'         => '',
2908
+			'show_notification_toggle' => false,
2909
+		);
2910
+		// to indicate we're processing a new registration
2911
+		$hidden_fields = array(
2912
+			'processing_registration' => array(
2913
+				'type'  => 'hidden',
2914
+				'value' => 0,
2915
+			),
2916
+			'event_id'                => array(
2917
+				'type'  => 'hidden',
2918
+				'value' => $this->_reg_event->ID(),
2919
+			),
2920
+		);
2921
+		// if the cart is empty then we know we're at step one so we'll display ticket selector
2922
+		$cart = EE_Registry::instance()->SSN->cart();
2923
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2924
+		switch ($step) {
2925
+			case 'ticket':
2926
+				$hidden_fields['processing_registration']['value'] = 1;
2927
+				$template_args['title'] = esc_html__(
2928
+					'Step One: Select the Ticket for this registration',
2929
+					'event_espresso'
2930
+				);
2931
+				$template_args['content'] =
2932
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2933
+				$template_args['content'] .= '</div>';
2934
+				$template_args['step_button_text'] = esc_html__(
2935
+					'Add Tickets and Continue to Registrant Details',
2936
+					'event_espresso'
2937
+				);
2938
+				$template_args['show_notification_toggle'] = false;
2939
+				break;
2940
+			case 'questions':
2941
+				$hidden_fields['processing_registration']['value'] = 2;
2942
+				$template_args['title'] = esc_html__(
2943
+					'Step Two: Add Registrant Details for this Registration',
2944
+					'event_espresso'
2945
+				);
2946
+				// in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2947
+				// properly by the first process_reg_step run.
2948
+				$template_args['content'] =
2949
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2950
+				$template_args['step_button_text'] = esc_html__(
2951
+					'Save Registration and Continue to Details',
2952
+					'event_espresso'
2953
+				);
2954
+				$template_args['show_notification_toggle'] = true;
2955
+				break;
2956
+		}
2957
+		// we come back to the process_registration_step route.
2958
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2959
+		return EEH_Template::display_template(
2960
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2961
+			$template_args,
2962
+			true
2963
+		);
2964
+	}
2965
+
2966
+
2967
+	/**
2968
+	 *        set_reg_event
2969
+	 *
2970
+	 * @access private
2971
+	 * @return bool
2972
+	 * @throws EE_Error
2973
+	 * @throws InvalidArgumentException
2974
+	 * @throws InvalidDataTypeException
2975
+	 * @throws InvalidInterfaceException
2976
+	 */
2977
+	private function _set_reg_event()
2978
+	{
2979
+		if (is_object($this->_reg_event)) {
2980
+			return true;
2981
+		}
2982
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2983
+		if (! $EVT_ID) {
2984
+			return false;
2985
+		}
2986
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2987
+		return true;
2988
+	}
2989
+
2990
+
2991
+	/**
2992
+	 * process_reg_step
2993
+	 *
2994
+	 * @access        public
2995
+	 * @return string
2996
+	 * @throws DomainException
2997
+	 * @throws EE_Error
2998
+	 * @throws InvalidArgumentException
2999
+	 * @throws InvalidDataTypeException
3000
+	 * @throws InvalidInterfaceException
3001
+	 * @throws ReflectionException
3002
+	 * @throws RuntimeException
3003
+	 */
3004
+	public function process_reg_step()
3005
+	{
3006
+		EE_System::do_not_cache();
3007
+		$this->_set_reg_event();
3008
+		/** @var CurrentPage $current_page */
3009
+		$current_page = $this->loader->getShared(CurrentPage::class);
3010
+		$current_page->setEspressoPage(true);
3011
+		$this->request->setRequestParam('uts', time());
3012
+		// what step are we on?
3013
+		$cart = EE_Registry::instance()->SSN->cart();
3014
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3015
+		// if doing ajax then we need to verify the nonce
3016
+		if (defined('DOING_AJAX')) {
3017
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
3018
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3019
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3020
+		}
3021
+		switch ($step) {
3022
+			case 'ticket':
3023
+				// process ticket selection
3024
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3025
+				if ($success) {
3026
+					EE_Error::add_success(
3027
+						esc_html__(
3028
+							'Tickets Selected. Now complete the registration.',
3029
+							'event_espresso'
3030
+						)
3031
+					);
3032
+				} else {
3033
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3034
+				}
3035
+				if (defined('DOING_AJAX')) {
3036
+					$this->new_registration(); // display next step
3037
+				} else {
3038
+					$query_args = array(
3039
+						'action'                  => 'new_registration',
3040
+						'processing_registration' => 1,
3041
+						'event_id'                => $this->_reg_event->ID(),
3042
+						'uts'                     => time(),
3043
+					);
3044
+					$this->_redirect_after_action(
3045
+						false,
3046
+						'',
3047
+						'',
3048
+						$query_args,
3049
+						true
3050
+					);
3051
+				}
3052
+				break;
3053
+			case 'questions':
3054
+				if (! isset(
3055
+					$this->_req_data['txn_reg_status_change'],
3056
+					$this->_req_data['txn_reg_status_change']['send_notifications']
3057
+				)
3058
+				) {
3059
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3060
+				}
3061
+				// process registration
3062
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3063
+				if ($cart instanceof EE_Cart) {
3064
+					$grand_total = $cart->get_cart_grand_total();
3065
+					if ($grand_total instanceof EE_Line_Item) {
3066
+						$grand_total->save_this_and_descendants_to_txn();
3067
+					}
3068
+				}
3069
+				if (! $transaction instanceof EE_Transaction) {
3070
+					$query_args = array(
3071
+						'action'                  => 'new_registration',
3072
+						'processing_registration' => 2,
3073
+						'event_id'                => $this->_reg_event->ID(),
3074
+						'uts'                     => time(),
3075
+					);
3076
+					if (defined('DOING_AJAX')) {
3077
+						// display registration form again because there are errors (maybe validation?)
3078
+						$this->new_registration();
3079
+						return;
3080
+					}
3081
+					$this->_redirect_after_action(
3082
+						false,
3083
+						'',
3084
+						'',
3085
+						$query_args,
3086
+						true
3087
+					);
3088
+					return;
3089
+				}
3090
+				// maybe update status, and make sure to save transaction if not done already
3091
+				if (! $transaction->update_status_based_on_total_paid()) {
3092
+					$transaction->save();
3093
+				}
3094
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3095
+				$this->_req_data = array();
3096
+				$query_args = array(
3097
+					'action'        => 'redirect_to_txn',
3098
+					'TXN_ID'        => $transaction->ID(),
3099
+					'EVT_ID'        => $this->_reg_event->ID(),
3100
+					'event_name'    => urlencode($this->_reg_event->name()),
3101
+					'redirect_from' => 'new_registration',
3102
+				);
3103
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3104
+				break;
3105
+		}
3106
+		// what are you looking here for?  Should be nothing to do at this point.
3107
+	}
3108
+
3109
+
3110
+	/**
3111
+	 * redirect_to_txn
3112
+	 *
3113
+	 * @access public
3114
+	 * @return void
3115
+	 * @throws EE_Error
3116
+	 * @throws InvalidArgumentException
3117
+	 * @throws InvalidDataTypeException
3118
+	 * @throws InvalidInterfaceException
3119
+	 * @throws ReflectionException
3120
+	 */
3121
+	public function redirect_to_txn()
3122
+	{
3123
+		EE_System::do_not_cache();
3124
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3125
+		$query_args = array(
3126
+			'action' => 'view_transaction',
3127
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3128
+			'page'   => 'espresso_transactions',
3129
+		);
3130
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3131
+			$query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3132
+			$query_args['event_name'] = urlencode($this->_req_data['event_name']);
3133
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3134
+		}
3135
+		EE_Error::add_success(
3136
+			esc_html__(
3137
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3138
+				'event_espresso'
3139
+			)
3140
+		);
3141
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3142
+	}
3143
+
3144
+
3145
+	/**
3146
+	 *        generates HTML for the Attendee Contact List
3147
+	 *
3148
+	 * @access protected
3149
+	 * @return void
3150
+	 * @throws DomainException
3151
+	 * @throws EE_Error
3152
+	 */
3153
+	protected function _attendee_contact_list_table()
3154
+	{
3155
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3156
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3157
+		$this->display_admin_list_table_page_with_no_sidebar();
3158
+	}
3159
+
3160
+
3161
+	/**
3162
+	 *        get_attendees
3163
+	 *
3164
+	 * @param      $per_page
3165
+	 * @param bool $count whether to return count or data.
3166
+	 * @param bool $trash
3167
+	 * @return array
3168
+	 * @throws EE_Error
3169
+	 * @throws InvalidArgumentException
3170
+	 * @throws InvalidDataTypeException
3171
+	 * @throws InvalidInterfaceException
3172
+	 * @access public
3173
+	 */
3174
+	public function get_attendees($per_page, $count = false, $trash = false)
3175
+	{
3176
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3177
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3178
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3179
+		switch ($this->_req_data['orderby']) {
3180
+			case 'ATT_ID':
3181
+				$orderby = 'ATT_ID';
3182
+				break;
3183
+			case 'ATT_fname':
3184
+				$orderby = 'ATT_fname';
3185
+				break;
3186
+			case 'ATT_email':
3187
+				$orderby = 'ATT_email';
3188
+				break;
3189
+			case 'ATT_city':
3190
+				$orderby = 'ATT_city';
3191
+				break;
3192
+			case 'STA_ID':
3193
+				$orderby = 'STA_ID';
3194
+				break;
3195
+			case 'CNT_ID':
3196
+				$orderby = 'CNT_ID';
3197
+				break;
3198
+			case 'Registration_Count':
3199
+				$orderby = 'Registration_Count';
3200
+				break;
3201
+			default:
3202
+				$orderby = 'ATT_lname';
3203
+		}
3204
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3205
+			? $this->_req_data['order']
3206
+			: 'ASC';
3207
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3208
+			? $this->_req_data['paged']
3209
+			: 1;
3210
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3211
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3212
+			? $this->_req_data['perpage']
3213
+			: $per_page;
3214
+		$_where = array();
3215
+		if (! empty($this->_req_data['s'])) {
3216
+			$sstr = '%' . $this->_req_data['s'] . '%';
3217
+			$_where['OR'] = array(
3218
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3219
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3220
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3221
+				'ATT_fname'                         => array('LIKE', $sstr),
3222
+				'ATT_lname'                         => array('LIKE', $sstr),
3223
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3224
+				'ATT_email'                         => array('LIKE', $sstr),
3225
+				'ATT_address'                       => array('LIKE', $sstr),
3226
+				'ATT_address2'                      => array('LIKE', $sstr),
3227
+				'ATT_city'                          => array('LIKE', $sstr),
3228
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3229
+				'State.STA_name'                    => array('LIKE', $sstr),
3230
+				'ATT_phone'                         => array('LIKE', $sstr),
3231
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3232
+				'Registration.REG_code'             => array('LIKE', $sstr),
3233
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3234
+			);
3235
+		}
3236
+		$offset = ($current_page - 1) * $per_page;
3237
+		$limit = $count ? null : array($offset, $per_page);
3238
+		$query_args = array(
3239
+			$_where,
3240
+			'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3241
+			'limit'         => $limit,
3242
+		);
3243
+		if (! $count) {
3244
+			$query_args['order_by'] = array($orderby => $sort);
3245
+		}
3246
+		if ($trash) {
3247
+			$query_args[0]['status'] = array('!=', 'publish');
3248
+			$all_attendees = $count
3249
+				? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3250
+				: $this->getAttendeeModel()->get_all($query_args);
3251
+		} else {
3252
+			$query_args[0]['status'] = array('IN', array('publish'));
3253
+			$all_attendees = $count
3254
+				? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3255
+				: $this->getAttendeeModel()->get_all($query_args);
3256
+		}
3257
+		return $all_attendees;
3258
+	}
3259
+
3260
+
3261
+	/**
3262
+	 * This is just taking care of resending the registration confirmation
3263
+	 *
3264
+	 * @access protected
3265
+	 * @return void
3266
+	 * @throws EE_Error
3267
+	 * @throws InvalidArgumentException
3268
+	 * @throws InvalidDataTypeException
3269
+	 * @throws InvalidInterfaceException
3270
+	 * @throws ReflectionException
3271
+	 */
3272
+	protected function _resend_registration()
3273
+	{
3274
+		$this->_process_resend_registration();
3275
+		$query_args = isset($this->_req_data['redirect_to'])
3276
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3277
+			: array('action' => 'default');
3278
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3279
+	}
3280
+
3281
+	/**
3282
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3283
+	 * to use when selecting registrations
3284
+	 *
3285
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3286
+	 *                                                     the query parameters from the request
3287
+	 * @return void ends the request with a redirect or download
3288
+	 */
3289
+	public function _registrations_report_base($method_name_for_getting_query_params)
3290
+	{
3291
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3292
+			wp_redirect(
3293
+				EE_Admin_Page::add_query_args_and_nonce(
3294
+					array(
3295
+						'page'        => 'espresso_batch',
3296
+						'batch'       => 'file',
3297
+						'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3298
+						'filters'     => urlencode(
3299
+							serialize(
3300
+								$this->$method_name_for_getting_query_params(
3301
+									EEH_Array::is_set(
3302
+										$this->_req_data,
3303
+										'filters',
3304
+										array()
3305
+									)
3306
+								)
3307
+							)
3308
+						),
3309
+						'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3310
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3311
+						'return_url'  => urlencode($this->_req_data['return_url']),
3312
+					)
3313
+				)
3314
+			);
3315
+		} else {
3316
+			$new_request_args = array(
3317
+				'export' => 'report',
3318
+				'action' => 'registrations_report_for_event',
3319
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3320
+			);
3321
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3322
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3323
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3324
+				$EE_Export = EE_Export::instance($this->_req_data);
3325
+				$EE_Export->export();
3326
+			}
3327
+		}
3328
+	}
3329
+
3330
+
3331
+	/**
3332
+	 * Creates a registration report using only query parameters in the request
3333
+	 *
3334
+	 * @return void
3335
+	 */
3336
+	public function _registrations_report()
3337
+	{
3338
+		$this->_registrations_report_base('_get_registration_query_parameters');
3339
+	}
3340
+
3341
+
3342
+	public function _contact_list_export()
3343
+	{
3344
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3345
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3346
+			$EE_Export = EE_Export::instance($this->_req_data);
3347
+			$EE_Export->export_attendees();
3348
+		}
3349
+	}
3350
+
3351
+
3352
+	public function _contact_list_report()
3353
+	{
3354
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3355
+			wp_redirect(
3356
+				EE_Admin_Page::add_query_args_and_nonce(
3357
+					array(
3358
+						'page'        => 'espresso_batch',
3359
+						'batch'       => 'file',
3360
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3361
+						'return_url'  => urlencode($this->_req_data['return_url']),
3362
+					)
3363
+				)
3364
+			);
3365
+		} else {
3366
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3367
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3368
+				$EE_Export = EE_Export::instance($this->_req_data);
3369
+				$EE_Export->report_attendees();
3370
+			}
3371
+		}
3372
+	}
3373
+
3374
+
3375
+
3376
+
3377
+
3378
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3379
+	/**
3380
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3381
+	 *
3382
+	 * @return void
3383
+	 * @throws EE_Error
3384
+	 * @throws InvalidArgumentException
3385
+	 * @throws InvalidDataTypeException
3386
+	 * @throws InvalidInterfaceException
3387
+	 * @throws ReflectionException
3388
+	 */
3389
+	protected function _duplicate_attendee()
3390
+	{
3391
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3392
+		// verify we have necessary info
3393
+		if (empty($this->_req_data['_REG_ID'])) {
3394
+			EE_Error::add_error(
3395
+				esc_html__(
3396
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3397
+					'event_espresso'
3398
+				),
3399
+				__FILE__,
3400
+				__LINE__,
3401
+				__FUNCTION__
3402
+			);
3403
+			$query_args = array('action' => $action);
3404
+			$this->_redirect_after_action('', '', '', $query_args, true);
3405
+		}
3406
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3407
+		$registration = $this->getRegistrationModel()->get_one_by_ID($this->_req_data['_REG_ID']);
3408
+		$attendee = $registration->attendee();
3409
+		// remove relation of existing attendee on registration
3410
+		$registration->_remove_relation_to($attendee, 'Attendee');
3411
+		// new attendee
3412
+		$new_attendee = clone $attendee;
3413
+		$new_attendee->set('ATT_ID', 0);
3414
+		$new_attendee->save();
3415
+		// add new attendee to reg
3416
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3417
+		EE_Error::add_success(
3418
+			esc_html__(
3419
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3420
+				'event_espresso'
3421
+			)
3422
+		);
3423
+		// redirect to edit page for attendee
3424
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3425
+		$this->_redirect_after_action('', '', '', $query_args, true);
3426
+	}
3427
+
3428
+
3429
+	/**
3430
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3431
+	 *
3432
+	 * @param int     $post_id
3433
+	 * @param WP_POST $post
3434
+	 * @throws DomainException
3435
+	 * @throws EE_Error
3436
+	 * @throws InvalidArgumentException
3437
+	 * @throws InvalidDataTypeException
3438
+	 * @throws InvalidInterfaceException
3439
+	 * @throws LogicException
3440
+	 * @throws InvalidFormSubmissionException
3441
+	 * @throws ReflectionException
3442
+	 */
3443
+	protected function _insert_update_cpt_item($post_id, $post)
3444
+	{
3445
+		$success = true;
3446
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3447
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3448
+			: null;
3449
+		// for attendee updates
3450
+		if ($attendee instanceof EE_Attendee) {
3451
+			// note we should only be UPDATING attendees at this point.
3452
+			$updated_fields = array(
3453
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3454
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3455
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3456
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3457
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3458
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3459
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3460
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3461
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3462
+			);
3463
+			foreach ($updated_fields as $field => $value) {
3464
+				$attendee->set($field, $value);
3465
+			}
3466
+
3467
+			// process contact details metabox form handler (which will also save the attendee)
3468
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3469
+			$success = $contact_details_form->process($this->_req_data);
3470
+
3471
+			$attendee_update_callbacks = apply_filters(
3472
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3473
+				array()
3474
+			);
3475
+			foreach ($attendee_update_callbacks as $a_callback) {
3476
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3477
+					throw new EE_Error(
3478
+						sprintf(
3479
+							esc_html__(
3480
+								'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.',
3481
+								'event_espresso'
3482
+							),
3483
+							$a_callback
3484
+						)
3485
+					);
3486
+				}
3487
+			}
3488
+		}
3489
+
3490
+		if ($success === false) {
3491
+			EE_Error::add_error(
3492
+				esc_html__(
3493
+					'Something went wrong with updating the meta table data for the registration.',
3494
+					'event_espresso'
3495
+				),
3496
+				__FILE__,
3497
+				__FUNCTION__,
3498
+				__LINE__
3499
+			);
3500
+		}
3501
+	}
3502
+
3503
+
3504
+	public function trash_cpt_item($post_id)
3505
+	{
3506
+	}
3507
+
3508
+
3509
+	public function delete_cpt_item($post_id)
3510
+	{
3511
+	}
3512
+
3513
+
3514
+	public function restore_cpt_item($post_id)
3515
+	{
3516
+	}
3517
+
3518
+
3519
+	protected function _restore_cpt_item($post_id, $revision_id)
3520
+	{
3521
+	}
3522
+
3523
+
3524
+	/**
3525
+	 * @throws EE_Error
3526
+	 * @since 4.10.2.p
3527
+	 */
3528
+	public function attendee_editor_metaboxes()
3529
+	{
3530
+		$this->verify_cpt_object();
3531
+		remove_meta_box(
3532
+			'postexcerpt',
3533
+			$this->_cpt_routes[ $this->_req_action ],
3534
+			'normal'
3535
+		);
3536
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3537
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3538
+			add_meta_box(
3539
+				'postexcerpt',
3540
+				esc_html__('Short Biography', 'event_espresso'),
3541
+				'post_excerpt_meta_box',
3542
+				$this->_cpt_routes[ $this->_req_action ],
3543
+				'normal'
3544
+			);
3545
+		}
3546
+		if (post_type_supports('espresso_attendees', 'comments')) {
3547
+			add_meta_box(
3548
+				'commentsdiv',
3549
+				esc_html__('Notes on the Contact', 'event_espresso'),
3550
+				'post_comment_meta_box',
3551
+				$this->_cpt_routes[ $this->_req_action ],
3552
+				'normal',
3553
+				'core'
3554
+			);
3555
+		}
3556
+		add_meta_box(
3557
+			'attendee_contact_info',
3558
+			esc_html__('Contact Info', 'event_espresso'),
3559
+			array($this, 'attendee_contact_info'),
3560
+			$this->_cpt_routes[ $this->_req_action ],
3561
+			'side',
3562
+			'core'
3563
+		);
3564
+		add_meta_box(
3565
+			'attendee_details_address',
3566
+			esc_html__('Address Details', 'event_espresso'),
3567
+			array($this, 'attendee_address_details'),
3568
+			$this->_cpt_routes[ $this->_req_action ],
3569
+			'normal',
3570
+			'core'
3571
+		);
3572
+		add_meta_box(
3573
+			'attendee_registrations',
3574
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3575
+			array($this, 'attendee_registrations_meta_box'),
3576
+			$this->_cpt_routes[ $this->_req_action ],
3577
+			'normal',
3578
+			'high'
3579
+		);
3580
+	}
3581
+
3582
+
3583
+	/**
3584
+	 * Metabox for attendee contact info
3585
+	 *
3586
+	 * @param  WP_Post $post wp post object
3587
+	 * @return string attendee contact info ( and form )
3588
+	 * @throws EE_Error
3589
+	 * @throws InvalidArgumentException
3590
+	 * @throws InvalidDataTypeException
3591
+	 * @throws InvalidInterfaceException
3592
+	 * @throws LogicException
3593
+	 * @throws DomainException
3594
+	 */
3595
+	public function attendee_contact_info($post)
3596
+	{
3597
+		// get attendee object ( should already have it )
3598
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3599
+		$form->enqueueStylesAndScripts();
3600
+		echo $form->display();
3601
+	}
3602
+
3603
+
3604
+	/**
3605
+	 * Return form handler for the contact details metabox
3606
+	 *
3607
+	 * @param EE_Attendee $attendee
3608
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3609
+	 * @throws DomainException
3610
+	 * @throws InvalidArgumentException
3611
+	 * @throws InvalidDataTypeException
3612
+	 * @throws InvalidInterfaceException
3613
+	 */
3614
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3615
+	{
3616
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3617
+	}
3618
+
3619
+
3620
+	/**
3621
+	 * Metabox for attendee details
3622
+	 *
3623
+	 * @param  WP_Post $post wp post object
3624
+	 * @throws DomainException
3625
+	 */
3626
+	public function attendee_address_details($post)
3627
+	{
3628
+		// get attendee object (should already have it)
3629
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3630
+		$this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3631
+			new EE_Question_Form_Input(
3632
+				EE_Question::new_instance(
3633
+					array(
3634
+						'QST_ID'           => 0,
3635
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3636
+						'QST_system'       => 'admin-state',
3637
+					)
3638
+				),
3639
+				EE_Answer::new_instance(
3640
+					array(
3641
+						'ANS_ID'    => 0,
3642
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3643
+					)
3644
+				),
3645
+				array(
3646
+					'input_id'       => 'STA_ID',
3647
+					'input_name'     => 'STA_ID',
3648
+					'input_prefix'   => '',
3649
+					'append_qstn_id' => false,
3650
+				)
3651
+			)
3652
+		);
3653
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3654
+			new EE_Question_Form_Input(
3655
+				EE_Question::new_instance(
3656
+					array(
3657
+						'QST_ID'           => 0,
3658
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3659
+						'QST_system'       => 'admin-country',
3660
+					)
3661
+				),
3662
+				EE_Answer::new_instance(
3663
+					array(
3664
+						'ANS_ID'    => 0,
3665
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3666
+					)
3667
+				),
3668
+				array(
3669
+					'input_id'       => 'CNT_ISO',
3670
+					'input_name'     => 'CNT_ISO',
3671
+					'input_prefix'   => '',
3672
+					'append_qstn_id' => false,
3673
+				)
3674
+			)
3675
+		);
3676
+		$template =
3677
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3678
+		EEH_Template::display_template($template, $this->_template_args);
3679
+	}
3680
+
3681
+
3682
+	/**
3683
+	 *        _attendee_details
3684
+	 *
3685
+	 * @access protected
3686
+	 * @param $post
3687
+	 * @return void
3688
+	 * @throws DomainException
3689
+	 * @throws EE_Error
3690
+	 * @throws InvalidArgumentException
3691
+	 * @throws InvalidDataTypeException
3692
+	 * @throws InvalidInterfaceException
3693
+	 * @throws ReflectionException
3694
+	 */
3695
+	public function attendee_registrations_meta_box($post)
3696
+	{
3697
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3698
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3699
+		$template =
3700
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3701
+		EEH_Template::display_template($template, $this->_template_args);
3702
+	}
3703
+
3704
+
3705
+	/**
3706
+	 * add in the form fields for the attendee edit
3707
+	 *
3708
+	 * @param  WP_Post $post wp post object
3709
+	 * @return string html for new form.
3710
+	 * @throws DomainException
3711
+	 */
3712
+	public function after_title_form_fields($post)
3713
+	{
3714
+		if ($post->post_type === 'espresso_attendees') {
3715
+			$template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3716
+			$template_args['attendee'] = $this->_cpt_model_obj;
3717
+			EEH_Template::display_template($template, $template_args);
3718
+		}
3719
+	}
3720
+
3721
+
3722
+	/**
3723
+	 *        _trash_or_restore_attendee
3724
+	 *
3725
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3726
+	 * @return void
3727
+	 * @throws EE_Error
3728
+	 * @throws InvalidArgumentException
3729
+	 * @throws InvalidDataTypeException
3730
+	 * @throws InvalidInterfaceException
3731
+	 * @throws ReflectionException
3732
+	 * @access protected
3733
+	 */
3734
+	protected function _trash_or_restore_attendees($trash = true)
3735
+	{
3736
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3737
+		$success = 1;
3738
+		// Checkboxes
3739
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3740
+			// if array has more than one element than success message should be plural
3741
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3742
+			// cycle thru checkboxes
3743
+			foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3744
+				$updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3745
+					: $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3746
+				if (! $updated) {
3747
+					$success = 0;
3748
+				}
3749
+			}
3750
+		} else {
3751
+			// grab single id and delete
3752
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3753
+			// get attendee
3754
+			$att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3755
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3756
+			$updated = $att->save() && $updated;
3757
+			if (! $updated) {
3758
+				$success = 0;
3759
+			}
3760
+		}
3761
+		$what = $success > 1
3762
+			? esc_html__('Contacts', 'event_espresso')
3763
+			: esc_html__('Contact', 'event_espresso');
3764
+		$action_desc = $trash
3765
+			? esc_html__('moved to the trash', 'event_espresso')
3766
+			: esc_html__('restored', 'event_espresso');
3767
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3768
+	}
3769 3769
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      */
89 89
     protected function getRegistrationModel()
90 90
     {
91
-        if (! $this->registration_model instanceof EEM_Registration) {
91
+        if ( ! $this->registration_model instanceof EEM_Registration) {
92 92
             $this->registration_model = $this->getLoader()->getShared('EEM_Registration');
93 93
         }
94 94
         return $this->registration_model;
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     protected function getAttendeeModel()
105 105
     {
106
-        if (! $this->attendee_model instanceof EEM_Attendee) {
106
+        if ( ! $this->attendee_model instanceof EEM_Attendee) {
107 107
             $this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
108 108
         }
109 109
         return $this->attendee_model;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     protected function getEventModel()
121 121
     {
122
-        if (! $this->event_model instanceof EEM_Event) {
122
+        if ( ! $this->event_model instanceof EEM_Event) {
123 123
             $this->event_model = $this->getLoader()->getShared('EEM_Event');
124 124
         }
125 125
         return $this->event_model;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      */
135 135
     protected function getStatusModel()
136 136
     {
137
-        if (! $this->status_model instanceof EEM_Status) {
137
+        if ( ! $this->status_model instanceof EEM_Status) {
138 138
             $this->status_model = $this->getLoader()->getShared('EEM_Status');
139 139
         }
140 140
         return $this->status_model;
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
         // when adding a new registration...
147 147
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
148 148
             EE_System::do_not_cache();
149
-            if (! isset($this->_req_data['processing_registration'])
149
+            if ( ! isset($this->_req_data['processing_registration'])
150 150
                 || absint($this->_req_data['processing_registration']) !== 1
151 151
             ) {
152 152
                 // and it's NOT the attendee information reg step
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
         // style
756 756
         wp_register_style(
757 757
             'espresso_reg',
758
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
758
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
759 759
             array('ee-admin-css'),
760 760
             EVENT_ESPRESSO_VERSION
761 761
         );
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
         // script
764 764
         wp_register_script(
765 765
             'espresso_reg',
766
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
766
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
767 767
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
768 768
             EVENT_ESPRESSO_VERSION,
769 769
             true
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
             'att_publish_text' => sprintf(
788 788
                 /* translators: The date and time */
789 789
                 wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
790
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
790
+                '<b>'.$this->_cpt_model_obj->get_datetime('ATT_created').'</b>'
791 791
             ),
792 792
         );
793 793
         wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
         wp_dequeue_style('espresso_reg');
819 819
         wp_register_style(
820 820
             'espresso_att',
821
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
821
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
822 822
             array('ee-admin-css'),
823 823
             EVENT_ESPRESSO_VERSION
824 824
         );
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
     {
831 831
         wp_register_script(
832 832
             'ee-spco-for-admin',
833
-            REG_ASSETS_URL . 'spco_for_admin.js',
833
+            REG_ASSETS_URL.'spco_for_admin.js',
834 834
             array('underscore', 'jquery'),
835 835
             EVENT_ESPRESSO_VERSION,
836 836
             true
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
         }
1073 1073
         $sc_items = array(
1074 1074
             'approved_status'   => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1075
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1076 1076
                 'desc'  => EEH_Template::pretty_status(
1077 1077
                     EEM_Registration::status_id_approved,
1078 1078
                     false,
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
                 ),
1081 1081
             ),
1082 1082
             'pending_status'    => array(
1083
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1083
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1084 1084
                 'desc'  => EEH_Template::pretty_status(
1085 1085
                     EEM_Registration::status_id_pending_payment,
1086 1086
                     false,
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
                 ),
1089 1089
             ),
1090 1090
             'wait_list'         => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1091
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1092 1092
                 'desc'  => EEH_Template::pretty_status(
1093 1093
                     EEM_Registration::status_id_wait_list,
1094 1094
                     false,
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
                 ),
1097 1097
             ),
1098 1098
             'incomplete_status' => array(
1099
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1099
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
1100 1100
                 'desc'  => EEH_Template::pretty_status(
1101 1101
                     EEM_Registration::status_id_incomplete,
1102 1102
                     false,
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
                 ),
1105 1105
             ),
1106 1106
             'not_approved'      => array(
1107
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1107
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1108 1108
                 'desc'  => EEH_Template::pretty_status(
1109 1109
                     EEM_Registration::status_id_not_approved,
1110 1110
                     false,
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
                 ),
1113 1113
             ),
1114 1114
             'declined_status'   => array(
1115
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1115
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1116 1116
                 'desc'  => EEH_Template::pretty_status(
1117 1117
                     EEM_Registration::status_id_declined,
1118 1118
                     false,
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
                 ),
1121 1121
             ),
1122 1122
             'cancelled_status'  => array(
1123
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1123
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1124 1124
                 'desc'  => EEH_Template::pretty_status(
1125 1125
                     EEM_Registration::status_id_cancelled,
1126 1126
                     false,
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
                 $EVT_ID
1184 1184
             )
1185 1185
         ) {
1186
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1186
+            $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1187 1187
                 'new_registration',
1188 1188
                 'add-registrant',
1189 1189
                 array('event_id' => $EVT_ID),
@@ -1209,7 +1209,7 @@  discard block
 block discarded – undo
1209 1209
         if ($this->_registration instanceof EE_Registration) {
1210 1210
             return true;
1211 1211
         }
1212
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1212
+        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1213 1213
         if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1214 1214
             return true;
1215 1215
         }
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
         /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1291 1291
         $list_table_query_builder = $this->getLoader()->getNew(
1292 1292
             'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1293
-            [ $request ]
1293
+            [$request]
1294 1294
         );
1295 1295
         return $list_table_query_builder->getQueryParams($per_page, $count);
1296 1296
     }
@@ -1396,7 +1396,7 @@  discard block
 block discarded – undo
1396 1396
                 )
1397 1397
                 : '';
1398 1398
             // grab header
1399
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1399
+            $template_path = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1400 1400
             $this->_template_args['REG_ID'] = $this->_registration->ID();
1401 1401
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1402 1402
                 $template_path,
@@ -1548,7 +1548,7 @@  discard block
 block discarded – undo
1548 1548
                                 EEH_HTML::strong(
1549 1549
                                     $this->_registration->pretty_status(),
1550 1550
                                     '',
1551
-                                    'status-' . $this->_registration->status_ID(),
1551
+                                    'status-'.$this->_registration->status_ID(),
1552 1552
                                     'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1553 1553
                                 )
1554 1554
                             )
@@ -1604,14 +1604,14 @@  discard block
 block discarded – undo
1604 1604
     protected function _get_reg_statuses()
1605 1605
     {
1606 1606
         $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1607
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1607
+        unset($reg_status_array[EEM_Registration::status_id_incomplete]);
1608 1608
         // get current reg status
1609 1609
         $current_status = $this->_registration->status_ID();
1610 1610
         // is registration for free event? This will determine whether to display the pending payment option
1611 1611
         if ($current_status !== EEM_Registration::status_id_pending_payment
1612 1612
             && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1613 1613
         ) {
1614
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1614
+            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1615 1615
         }
1616 1616
         return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1617 1617
     }
@@ -1705,7 +1705,7 @@  discard block
 block discarded – undo
1705 1705
         $success = false;
1706 1706
         // typecast $REG_IDs
1707 1707
         $REG_IDs = (array) $REG_IDs;
1708
-        if (! empty($REG_IDs)) {
1708
+        if ( ! empty($REG_IDs)) {
1709 1709
             $success = true;
1710 1710
             // set default status if none is passed
1711 1711
             $status = $status ? $status : EEM_Registration::status_id_pending_payment;
@@ -1868,7 +1868,7 @@  discard block
 block discarded – undo
1868 1868
             $action,
1869 1869
             $notify
1870 1870
         );
1871
-        $method = $action . '_registration';
1871
+        $method = $action.'_registration';
1872 1872
         if (method_exists($this, $method)) {
1873 1873
             $this->$method($notify);
1874 1874
         }
@@ -2147,7 +2147,7 @@  discard block
 block discarded – undo
2147 2147
         $this->_template_args['REG_ID'] = $this->_registration->ID();
2148 2148
         $this->_template_args['event_id'] = $this->_registration->event_ID();
2149 2149
         $template_path =
2150
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2150
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2151 2151
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2152 2152
     }
2153 2153
 
@@ -2184,7 +2184,7 @@  discard block
 block discarded – undo
2184 2184
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2185 2185
             $this->_template_args['REG_ID'] = $this->_registration->ID();
2186 2186
             $template_path =
2187
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2187
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2188 2188
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2189 2189
         }
2190 2190
     }
@@ -2201,7 +2201,7 @@  discard block
 block discarded – undo
2201 2201
     public function form_before_question_group($output)
2202 2202
     {
2203 2203
         EE_Error::doing_it_wrong(
2204
-            __CLASS__ . '::' . __FUNCTION__,
2204
+            __CLASS__.'::'.__FUNCTION__,
2205 2205
             esc_html__(
2206 2206
                 '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.',
2207 2207
                 'event_espresso'
@@ -2226,7 +2226,7 @@  discard block
 block discarded – undo
2226 2226
     public function form_after_question_group($output)
2227 2227
     {
2228 2228
         EE_Error::doing_it_wrong(
2229
-            __CLASS__ . '::' . __FUNCTION__,
2229
+            __CLASS__.'::'.__FUNCTION__,
2230 2230
             esc_html__(
2231 2231
                 '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.',
2232 2232
                 'event_espresso'
@@ -2264,7 +2264,7 @@  discard block
 block discarded – undo
2264 2264
     public function form_form_field_label_wrap($label)
2265 2265
     {
2266 2266
         EE_Error::doing_it_wrong(
2267
-            __CLASS__ . '::' . __FUNCTION__,
2267
+            __CLASS__.'::'.__FUNCTION__,
2268 2268
             esc_html__(
2269 2269
                 '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.',
2270 2270
                 'event_espresso'
@@ -2274,7 +2274,7 @@  discard block
 block discarded – undo
2274 2274
         return '
2275 2275
 			<tr>
2276 2276
 				<th>
2277
-					' . $label . '
2277
+					' . $label.'
2278 2278
 				</th>';
2279 2279
     }
2280 2280
 
@@ -2290,7 +2290,7 @@  discard block
 block discarded – undo
2290 2290
     public function form_form_field_input__wrap($input)
2291 2291
     {
2292 2292
         EE_Error::doing_it_wrong(
2293
-            __CLASS__ . '::' . __FUNCTION__,
2293
+            __CLASS__.'::'.__FUNCTION__,
2294 2294
             esc_html__(
2295 2295
                 '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.',
2296 2296
                 'event_espresso'
@@ -2299,7 +2299,7 @@  discard block
 block discarded – undo
2299 2299
         );
2300 2300
         return '
2301 2301
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2302
-					' . $input . '
2302
+					' . $input.'
2303 2303
 				</td>
2304 2304
 			</tr>';
2305 2305
     }
@@ -2347,8 +2347,8 @@  discard block
 block discarded – undo
2347 2347
      */
2348 2348
     protected function _get_reg_custom_questions_form($REG_ID)
2349 2349
     {
2350
-        if (! $this->_reg_custom_questions_form) {
2351
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2350
+        if ( ! $this->_reg_custom_questions_form) {
2351
+            require_once(REG_ADMIN.'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2352 2352
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2353 2353
                 $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2354 2354
             );
@@ -2372,7 +2372,7 @@  discard block
 block discarded – undo
2372 2372
      */
2373 2373
     private function _save_reg_custom_questions_form($REG_ID = false)
2374 2374
     {
2375
-        if (! $REG_ID) {
2375
+        if ( ! $REG_ID) {
2376 2376
             EE_Error::add_error(
2377 2377
                 esc_html__(
2378 2378
                     'An error occurred. No registration ID was received.',
@@ -2464,30 +2464,30 @@  discard block
 block discarded – undo
2464 2464
                 $attendee = $registration->attendee()
2465 2465
                     ? $registration->attendee()
2466 2466
                     : $this->getAttendeeModel()->create_default_object();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2468
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2469
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2470
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2471
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2472
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2467
+                $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID();
2468
+                $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();
2469
+                $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();
2470
+                $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();
2471
+                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2472
+                $this->_template_args['attendees'][$att_nmbr]['address'] = implode(
2473 2473
                     ', ',
2474 2474
                     $attendee->full_address_as_array()
2475 2475
                 );
2476
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2476
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2477 2477
                     array(
2478 2478
                         'action' => 'edit_attendee',
2479 2479
                         'post'   => $attendee->ID(),
2480 2480
                     ),
2481 2481
                     REG_ADMIN_URL
2482 2482
                 );
2483
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2483
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj() instanceof EE_Event
2484 2484
                     ? $registration->event_obj()->name()
2485 2485
                     : '';
2486 2486
                 $att_nmbr++;
2487 2487
             }
2488 2488
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2489 2489
         }
2490
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2490
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2491 2491
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2492 2492
     }
2493 2493
 
@@ -2514,11 +2514,11 @@  discard block
 block discarded – undo
2514 2514
         // now let's determine if this is not the primary registration.  If it isn't then we set the
2515 2515
         // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2516 2516
         // primary registration object (that way we know if we need to show create button or not)
2517
-        if (! $this->_registration->is_primary_registrant()) {
2517
+        if ( ! $this->_registration->is_primary_registrant()) {
2518 2518
             $primary_registration = $this->_registration->get_primary_registration();
2519 2519
             $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2520 2520
                 : null;
2521
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2521
+            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2522 2522
                 // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2523 2523
                 // custom attendee object so let's not worry about the primary reg.
2524 2524
                 $primary_registration = null;
@@ -2552,7 +2552,7 @@  discard block
 block discarded – undo
2552 2552
             ) : '';
2553 2553
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2554 2554
         $this->_template_args['att_check'] = $att_check;
2555
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2555
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2556 2556
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2557 2557
     }
2558 2558
 
@@ -2590,7 +2590,7 @@  discard block
 block discarded – undo
2590 2590
         $success = 0;
2591 2591
         $overwrite_msgs = false;
2592 2592
         // Checkboxes
2593
-        if (! is_array($this->_req_data['_REG_ID'])) {
2593
+        if ( ! is_array($this->_req_data['_REG_ID'])) {
2594 2594
             $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2595 2595
         }
2596 2596
         $reg_count = count($this->_req_data['_REG_ID']);
@@ -2599,7 +2599,7 @@  discard block
 block discarded – undo
2599 2599
             /** @var EE_Registration $REG */
2600 2600
             $REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2601 2601
             $payments = $REG->registration_payments();
2602
-            if (! empty($payments)) {
2602
+            if ( ! empty($payments)) {
2603 2603
                 $name = $REG->attendee() instanceof EE_Attendee
2604 2604
                     ? $REG->attendee()->full_name()
2605 2605
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2661,17 +2661,17 @@  discard block
 block discarded – undo
2661 2661
         $REG_MDL = $this->getRegistrationModel();
2662 2662
         $success = 1;
2663 2663
         // Checkboxes
2664
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2664
+        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2665 2665
             // if array has more than one element than success message should be plural
2666 2666
             $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2667 2667
             // cycle thru checkboxes
2668 2668
             foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2669 2669
                 $REG = $REG_MDL->get_one_by_ID($REG_ID);
2670
-                if (! $REG instanceof EE_Registration) {
2670
+                if ( ! $REG instanceof EE_Registration) {
2671 2671
                     continue;
2672 2672
                 }
2673 2673
                 $deleted = $this->_delete_registration($REG);
2674
-                if (! $deleted) {
2674
+                if ( ! $deleted) {
2675 2675
                     $success = 0;
2676 2676
                 }
2677 2677
             }
@@ -2681,7 +2681,7 @@  discard block
 block discarded – undo
2681 2681
             /** @var EE_Registration $REG */
2682 2682
             $REG = $REG_MDL->get_one_by_ID($REG_ID);
2683 2683
             $deleted = $this->_delete_registration($REG);
2684
-            if (! $deleted) {
2684
+            if ( ! $deleted) {
2685 2685
                 $success = 0;
2686 2686
             }
2687 2687
         }
@@ -2716,7 +2716,7 @@  discard block
 block discarded – undo
2716 2716
         // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2717 2717
         // registrations on the transaction that are NOT trashed.
2718 2718
         $TXN = $REG->get_first_related('Transaction');
2719
-        if (! $TXN instanceof EE_Transaction) {
2719
+        if ( ! $TXN instanceof EE_Transaction) {
2720 2720
             EE_Error::add_error(
2721 2721
                 sprintf(
2722 2722
                     esc_html__(
@@ -2734,11 +2734,11 @@  discard block
 block discarded – undo
2734 2734
         $REGS = $TXN->get_many_related('Registration');
2735 2735
         $all_trashed = true;
2736 2736
         foreach ($REGS as $registration) {
2737
-            if (! $registration->get('REG_deleted')) {
2737
+            if ( ! $registration->get('REG_deleted')) {
2738 2738
                 $all_trashed = false;
2739 2739
             }
2740 2740
         }
2741
-        if (! $all_trashed) {
2741
+        if ( ! $all_trashed) {
2742 2742
             EE_Error::add_error(
2743 2743
                 esc_html__(
2744 2744
                     '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.',
@@ -2801,7 +2801,7 @@  discard block
 block discarded – undo
2801 2801
      */
2802 2802
     public function new_registration()
2803 2803
     {
2804
-        if (! $this->_set_reg_event()) {
2804
+        if ( ! $this->_set_reg_event()) {
2805 2805
             throw new EE_Error(
2806 2806
                 esc_html__(
2807 2807
                     'Unable to continue with registering because there is no Event ID in the request',
@@ -2813,8 +2813,8 @@  discard block
 block discarded – undo
2813 2813
         $current_page = $this->loader->getShared(CurrentPage::class);
2814 2814
         $current_page->setEspressoPage(true);
2815 2815
         // gotta start with a clean slate if we're not coming here via ajax
2816
-        if (! defined('DOING_AJAX')
2817
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2816
+        if ( ! defined('DOING_AJAX')
2817
+            && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2818 2818
         ) {
2819 2819
             EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2820 2820
         }
@@ -2847,7 +2847,7 @@  discard block
 block discarded – undo
2847 2847
         }
2848 2848
         // grab header
2849 2849
         $template_path =
2850
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2850
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2851 2851
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2852 2852
             $template_path,
2853 2853
             $this->_template_args,
@@ -2888,7 +2888,7 @@  discard block
 block discarded – undo
2888 2888
                 '</b>'
2889 2889
             );
2890 2890
             return '
2891
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2891
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2892 2892
 	<script >
2893 2893
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2894 2894
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2957,7 +2957,7 @@  discard block
 block discarded – undo
2957 2957
         // we come back to the process_registration_step route.
2958 2958
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2959 2959
         return EEH_Template::display_template(
2960
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2960
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2961 2961
             $template_args,
2962 2962
             true
2963 2963
         );
@@ -2979,8 +2979,8 @@  discard block
 block discarded – undo
2979 2979
         if (is_object($this->_reg_event)) {
2980 2980
             return true;
2981 2981
         }
2982
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2983
-        if (! $EVT_ID) {
2982
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2983
+        if ( ! $EVT_ID) {
2984 2984
             return false;
2985 2985
         }
2986 2986
         $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
@@ -3014,8 +3014,8 @@  discard block
 block discarded – undo
3014 3014
         $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3015 3015
         // if doing ajax then we need to verify the nonce
3016 3016
         if (defined('DOING_AJAX')) {
3017
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3018
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3017
+            $nonce = isset($this->_req_data[$this->_req_nonce])
3018
+                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3019 3019
             $this->_verify_nonce($nonce, $this->_req_nonce);
3020 3020
         }
3021 3021
         switch ($step) {
@@ -3051,7 +3051,7 @@  discard block
 block discarded – undo
3051 3051
                 }
3052 3052
                 break;
3053 3053
             case 'questions':
3054
-                if (! isset(
3054
+                if ( ! isset(
3055 3055
                     $this->_req_data['txn_reg_status_change'],
3056 3056
                     $this->_req_data['txn_reg_status_change']['send_notifications']
3057 3057
                 )
@@ -3066,7 +3066,7 @@  discard block
 block discarded – undo
3066 3066
                         $grand_total->save_this_and_descendants_to_txn();
3067 3067
                     }
3068 3068
                 }
3069
-                if (! $transaction instanceof EE_Transaction) {
3069
+                if ( ! $transaction instanceof EE_Transaction) {
3070 3070
                     $query_args = array(
3071 3071
                         'action'                  => 'new_registration',
3072 3072
                         'processing_registration' => 2,
@@ -3088,7 +3088,7 @@  discard block
 block discarded – undo
3088 3088
                     return;
3089 3089
                 }
3090 3090
                 // maybe update status, and make sure to save transaction if not done already
3091
-                if (! $transaction->update_status_based_on_total_paid()) {
3091
+                if ( ! $transaction->update_status_based_on_total_paid()) {
3092 3092
                     $transaction->save();
3093 3093
                 }
3094 3094
                 EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
@@ -3174,7 +3174,7 @@  discard block
 block discarded – undo
3174 3174
     public function get_attendees($per_page, $count = false, $trash = false)
3175 3175
     {
3176 3176
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3177
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3177
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3178 3178
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3179 3179
         switch ($this->_req_data['orderby']) {
3180 3180
             case 'ATT_ID':
@@ -3212,8 +3212,8 @@  discard block
 block discarded – undo
3212 3212
             ? $this->_req_data['perpage']
3213 3213
             : $per_page;
3214 3214
         $_where = array();
3215
-        if (! empty($this->_req_data['s'])) {
3216
-            $sstr = '%' . $this->_req_data['s'] . '%';
3215
+        if ( ! empty($this->_req_data['s'])) {
3216
+            $sstr = '%'.$this->_req_data['s'].'%';
3217 3217
             $_where['OR'] = array(
3218 3218
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3219 3219
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3240,7 +3240,7 @@  discard block
 block discarded – undo
3240 3240
             'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3241 3241
             'limit'         => $limit,
3242 3242
         );
3243
-        if (! $count) {
3243
+        if ( ! $count) {
3244 3244
             $query_args['order_by'] = array($orderby => $sort);
3245 3245
         }
3246 3246
         if ($trash) {
@@ -3288,7 +3288,7 @@  discard block
 block discarded – undo
3288 3288
      */
3289 3289
     public function _registrations_report_base($method_name_for_getting_query_params)
3290 3290
     {
3291
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3291
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3292 3292
             wp_redirect(
3293 3293
                 EE_Admin_Page::add_query_args_and_nonce(
3294 3294
                     array(
@@ -3319,8 +3319,8 @@  discard block
 block discarded – undo
3319 3319
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3320 3320
             );
3321 3321
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3322
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3323
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3322
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3323
+                require_once(EE_CLASSES.'EE_Export.class.php');
3324 3324
                 $EE_Export = EE_Export::instance($this->_req_data);
3325 3325
                 $EE_Export->export();
3326 3326
             }
@@ -3341,8 +3341,8 @@  discard block
 block discarded – undo
3341 3341
 
3342 3342
     public function _contact_list_export()
3343 3343
     {
3344
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3345
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3344
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3345
+            require_once(EE_CLASSES.'EE_Export.class.php');
3346 3346
             $EE_Export = EE_Export::instance($this->_req_data);
3347 3347
             $EE_Export->export_attendees();
3348 3348
         }
@@ -3351,7 +3351,7 @@  discard block
 block discarded – undo
3351 3351
 
3352 3352
     public function _contact_list_report()
3353 3353
     {
3354
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3354
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3355 3355
             wp_redirect(
3356 3356
                 EE_Admin_Page::add_query_args_and_nonce(
3357 3357
                     array(
@@ -3363,8 +3363,8 @@  discard block
 block discarded – undo
3363 3363
                 )
3364 3364
             );
3365 3365
         } else {
3366
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3367
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3366
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3367
+                require_once(EE_CLASSES.'EE_Export.class.php');
3368 3368
                 $EE_Export = EE_Export::instance($this->_req_data);
3369 3369
                 $EE_Export->report_attendees();
3370 3370
             }
@@ -3452,7 +3452,7 @@  discard block
 block discarded – undo
3452 3452
             $updated_fields = array(
3453 3453
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3454 3454
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3455
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3455
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3456 3456
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3457 3457
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3458 3458
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3530,16 +3530,16 @@  discard block
 block discarded – undo
3530 3530
         $this->verify_cpt_object();
3531 3531
         remove_meta_box(
3532 3532
             'postexcerpt',
3533
-            $this->_cpt_routes[ $this->_req_action ],
3533
+            $this->_cpt_routes[$this->_req_action],
3534 3534
             'normal'
3535 3535
         );
3536
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3536
+        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3537 3537
         if (post_type_supports('espresso_attendees', 'excerpt')) {
3538 3538
             add_meta_box(
3539 3539
                 'postexcerpt',
3540 3540
                 esc_html__('Short Biography', 'event_espresso'),
3541 3541
                 'post_excerpt_meta_box',
3542
-                $this->_cpt_routes[ $this->_req_action ],
3542
+                $this->_cpt_routes[$this->_req_action],
3543 3543
                 'normal'
3544 3544
             );
3545 3545
         }
@@ -3548,7 +3548,7 @@  discard block
 block discarded – undo
3548 3548
                 'commentsdiv',
3549 3549
                 esc_html__('Notes on the Contact', 'event_espresso'),
3550 3550
                 'post_comment_meta_box',
3551
-                $this->_cpt_routes[ $this->_req_action ],
3551
+                $this->_cpt_routes[$this->_req_action],
3552 3552
                 'normal',
3553 3553
                 'core'
3554 3554
             );
@@ -3557,7 +3557,7 @@  discard block
 block discarded – undo
3557 3557
             'attendee_contact_info',
3558 3558
             esc_html__('Contact Info', 'event_espresso'),
3559 3559
             array($this, 'attendee_contact_info'),
3560
-            $this->_cpt_routes[ $this->_req_action ],
3560
+            $this->_cpt_routes[$this->_req_action],
3561 3561
             'side',
3562 3562
             'core'
3563 3563
         );
@@ -3565,7 +3565,7 @@  discard block
 block discarded – undo
3565 3565
             'attendee_details_address',
3566 3566
             esc_html__('Address Details', 'event_espresso'),
3567 3567
             array($this, 'attendee_address_details'),
3568
-            $this->_cpt_routes[ $this->_req_action ],
3568
+            $this->_cpt_routes[$this->_req_action],
3569 3569
             'normal',
3570 3570
             'core'
3571 3571
         );
@@ -3573,7 +3573,7 @@  discard block
 block discarded – undo
3573 3573
             'attendee_registrations',
3574 3574
             esc_html__('Registrations for this Contact', 'event_espresso'),
3575 3575
             array($this, 'attendee_registrations_meta_box'),
3576
-            $this->_cpt_routes[ $this->_req_action ],
3576
+            $this->_cpt_routes[$this->_req_action],
3577 3577
             'normal',
3578 3578
             'high'
3579 3579
         );
@@ -3674,7 +3674,7 @@  discard block
 block discarded – undo
3674 3674
             )
3675 3675
         );
3676 3676
         $template =
3677
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3677
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3678 3678
         EEH_Template::display_template($template, $this->_template_args);
3679 3679
     }
3680 3680
 
@@ -3697,7 +3697,7 @@  discard block
 block discarded – undo
3697 3697
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3698 3698
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3699 3699
         $template =
3700
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3700
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3701 3701
         EEH_Template::display_template($template, $this->_template_args);
3702 3702
     }
3703 3703
 
@@ -3712,7 +3712,7 @@  discard block
 block discarded – undo
3712 3712
     public function after_title_form_fields($post)
3713 3713
     {
3714 3714
         if ($post->post_type === 'espresso_attendees') {
3715
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3715
+            $template = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3716 3716
             $template_args['attendee'] = $this->_cpt_model_obj;
3717 3717
             EEH_Template::display_template($template, $template_args);
3718 3718
         }
@@ -3736,14 +3736,14 @@  discard block
 block discarded – undo
3736 3736
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3737 3737
         $success = 1;
3738 3738
         // Checkboxes
3739
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3739
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3740 3740
             // if array has more than one element than success message should be plural
3741 3741
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3742 3742
             // cycle thru checkboxes
3743 3743
             foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3744 3744
                 $updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3745 3745
                     : $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3746
-                if (! $updated) {
3746
+                if ( ! $updated) {
3747 3747
                     $success = 0;
3748 3748
                 }
3749 3749
             }
@@ -3754,7 +3754,7 @@  discard block
 block discarded – undo
3754 3754
             $att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3755 3755
             $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3756 3756
             $updated = $att->save() && $updated;
3757
-            if (! $updated) {
3757
+            if ( ! $updated) {
3758 3758
                 $success = 0;
3759 3759
             }
3760 3760
         }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha/EED_Recaptcha.module.php 1 patch
Indentation   +375 added lines, -375 removed lines patch added patch discarded remove patch
@@ -18,379 +18,379 @@
 block discarded – undo
18 18
 class EED_Recaptcha extends EED_Module
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Registration_Config $config
23
-     */
24
-    private static $config;
25
-
26
-    /**
27
-     * @type bool $_not_a_robot
28
-     */
29
-    private static $_not_a_robot;
30
-
31
-    /**
32
-     * @type string $_recaptcha_response
33
-     */
34
-    private static $_recaptcha_response;
35
-
36
-
37
-    /**
38
-     * @return EED_Module|EED_Recaptcha
39
-     */
40
-    public static function instance()
41
-    {
42
-        return parent::get_instance(__CLASS__);
43
-    }
44
-
45
-
46
-    /**
47
-     * set_hooks - for hooking into EE Core, other modules, etc
48
-     *
49
-     * @return void
50
-     * @throws InvalidArgumentException
51
-     * @throws InvalidInterfaceException
52
-     * @throws InvalidDataTypeException
53
-     */
54
-    public static function set_hooks()
55
-    {
56
-        EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
57
-        // use_captcha ?
58
-        if (EED_Recaptcha::useRecaptcha()
59
-            && EED_Recaptcha::notPaymentOptionsRevisit()
60
-        ) {
61
-            EED_Recaptcha::set_definitions();
62
-            EED_Recaptcha::enqueue_styles_and_scripts();
63
-            add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0);
64
-            add_action(
65
-                'AHEE__before_spco_whats_next_buttons',
66
-                array('EED_Recaptcha', 'display_recaptcha'),
67
-                10,
68
-                0
69
-            );
70
-            add_filter(
71
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
72
-                array('EED_Recaptcha', 'not_a_robot')
73
-            );
74
-            add_filter(
75
-                'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
76
-                array('EED_Recaptcha', 'not_a_robot')
77
-            );
78
-            add_filter(
79
-                'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
80
-                array('EED_Recaptcha', 'recaptcha_response')
81
-            );
82
-            add_filter(
83
-                'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
84
-                array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method')
85
-            );
86
-        }
87
-    }
88
-
89
-
90
-    /**
91
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
92
-     *
93
-     * @return void
94
-     * @throws InvalidArgumentException
95
-     * @throws InvalidInterfaceException
96
-     * @throws InvalidDataTypeException
97
-     */
98
-    public static function set_hooks_admin()
99
-    {
100
-        EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
101
-        EED_Recaptcha::set_definitions();
102
-        // use_captcha ?
103
-        if (EED_Recaptcha::useRecaptcha()
104
-            && EED_Recaptcha::notPaymentOptionsRevisit()
105
-            && EED_Recaptcha::getRequest()->getRequestParam('step', '') !== ''
106
-        ) {
107
-            EED_Recaptcha::enqueue_styles_and_scripts();
108
-            add_filter(
109
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
110
-                array('EED_Recaptcha', 'not_a_robot')
111
-            );
112
-            add_filter(
113
-                'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
114
-                array('EED_Recaptcha', 'not_a_robot')
115
-            );
116
-            add_filter(
117
-                'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
118
-                array('EED_Recaptcha', 'recaptcha_response')
119
-            );
120
-        }
121
-    }
122
-
123
-
124
-    /**
125
-     * @return void
126
-     */
127
-    public static function set_definitions()
128
-    {
129
-        if (is_user_logged_in()) {
130
-            EED_Recaptcha::$_not_a_robot = true;
131
-        }
132
-        define(
133
-            'RECAPTCHA_BASE_PATH',
134
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
135
-        );
136
-        define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
137
-    }
138
-
139
-
140
-    /**
141
-     * @return void
142
-     */
143
-    public static function set_late_hooks()
144
-    {
145
-        add_filter(
146
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
147
-            array('EED_Recaptcha', 'not_a_robot')
148
-        );
149
-    }
150
-
151
-
152
-    /**
153
-     * @return boolean
154
-     */
155
-    public static function useRecaptcha()
156
-    {
157
-        return EED_Recaptcha::$config->use_captcha
158
-               && EED_Recaptcha::$config->recaptcha_theme !== 'invisible';
159
-    }
160
-
161
-
162
-    /**
163
-     * @return boolean
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidInterfaceException
166
-     * @throws InvalidDataTypeException
167
-     */
168
-    public static function notPaymentOptionsRevisit()
169
-    {
170
-        $request = EED_Recaptcha::getRequest();
171
-        return ! (
172
-            $request->getRequestParam('step', '') === 'payment_options'
173
-            && $request->getRequestParam('revisit', false, 'bool') === true
174
-        );
175
-    }
176
-
177
-
178
-    /**
179
-     * @return void
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidInterfaceException
182
-     * @throws InvalidDataTypeException
183
-     */
184
-    public static function enqueue_styles_and_scripts()
185
-    {
186
-        wp_register_script(
187
-            'espresso_recaptcha',
188
-            RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
189
-            array('single_page_checkout'),
190
-            EVENT_ESPRESSO_VERSION,
191
-            true
192
-        );
193
-        wp_register_script(
194
-            'google_recaptcha',
195
-            'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
196
-            array('espresso_recaptcha'),
197
-            EVENT_ESPRESSO_VERSION,
198
-            true
199
-        );
200
-        EE_Registry::$i18n_js_strings['no_SPCO_error'] = __(
201
-            'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.',
202
-            'event_espresso'
203
-        );
204
-        EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __(
205
-            'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.',
206
-            'event_espresso'
207
-        );
208
-        EE_Registry::$i18n_js_strings['recaptcha_fail'] = __(
209
-            'Please complete the anti-spam test before proceeding.',
210
-            'event_espresso'
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     * @param WP $WP
217
-     */
218
-    public function run($WP)
219
-    {
220
-    }
221
-
222
-
223
-    /**
224
-     * @return boolean
225
-     * @throws InvalidArgumentException
226
-     * @throws InvalidInterfaceException
227
-     * @throws InvalidDataTypeException
228
-     */
229
-    public static function not_a_robot()
230
-    {
231
-        return is_bool(EED_Recaptcha::$_not_a_robot)
232
-            ? EED_Recaptcha::$_not_a_robot
233
-            : EED_Recaptcha::recaptcha_passed();
234
-    }
235
-
236
-
237
-    /**
238
-     * @return void
239
-     * @throws DomainException
240
-     * @throws InvalidArgumentException
241
-     * @throws InvalidInterfaceException
242
-     * @throws InvalidDataTypeException
243
-     */
244
-    public static function display_recaptcha()
245
-    {
246
-        // logged in means you have already passed a turing test of sorts
247
-        if (is_user_logged_in()) {
248
-            return;
249
-        }
250
-        // don't display if not using recaptcha or user is logged in
251
-        if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
252
-            // only display if they have NOT passed the test yet
253
-            EEH_Template::display_template(
254
-                RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
255
-                array(
256
-                    'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
257
-                    'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
258
-                    'recaptcha_type'      => EED_Recaptcha::$config->recaptcha_type,
259
-                )
260
-            );
261
-            wp_enqueue_script('google_recaptcha');
262
-        }
263
-    }
264
-
265
-
266
-    /**
267
-     * @return array
268
-     * @throws InvalidArgumentException
269
-     * @throws InvalidInterfaceException
270
-     * @throws InvalidDataTypeException
271
-     */
272
-    public static function bypass_recaptcha_for_spco_load_payment_method()
273
-    {
274
-        return array(
275
-            'EESID'  => EE_Registry::instance()->SSN->id(),
276
-            'step'   => 'payment_options',
277
-            'action' => 'switch_spco_billing_form',
278
-        );
279
-    }
280
-
281
-
282
-    /**
283
-     * @return boolean
284
-     * @throws InvalidArgumentException
285
-     * @throws InvalidInterfaceException
286
-     * @throws InvalidDataTypeException
287
-     */
288
-    public static function recaptcha_passed()
289
-    {
290
-        // logged in means you have already passed a turing test of sorts
291
-        if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) {
292
-            return true;
293
-        }
294
-        // was test already passed?
295
-        $recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed');
296
-        $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
297
-        // verify recaptcha
298
-        EED_Recaptcha::_get_recaptcha_response();
299
-        if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
300
-            $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
301
-            EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
302
-        }
303
-        EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
304
-        return $recaptcha_passed;
305
-    }
306
-
307
-
308
-    /**
309
-     * @param array $recaptcha_response
310
-     * @return array
311
-     */
312
-    public static function recaptcha_response($recaptcha_response = array())
313
-    {
314
-        if (EED_Recaptcha::_bypass_recaptcha()) {
315
-            $recaptcha_response['bypass_recaptcha'] = true;
316
-            $recaptcha_response['recaptcha_passed'] = true;
317
-        } else {
318
-            $recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot;
319
-        }
320
-        return $recaptcha_response;
321
-    }
322
-
323
-
324
-    /**
325
-     * @return boolean
326
-     */
327
-    private static function _bypass_recaptcha()
328
-    {
329
-        // an array of key value pairs that must match exactly with the incoming request,
330
-        // in order to bypass recaptcha for the current request ONLY
331
-        $bypass_request_params_array = (array) apply_filters(
332
-            'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
333
-            array()
334
-        );
335
-        // does $bypass_request_params_array have any values ?
336
-        if (empty($bypass_request_params_array)) {
337
-            return false;
338
-        }
339
-        // initially set bypass to TRUE
340
-        $bypass_recaptcha = true;
341
-        foreach ($bypass_request_params_array as $key => $value) {
342
-            // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE,
343
-            // otherwise carry over it's value. This way, one missed setting results in no bypass
344
-            $bypass_recaptcha = isset($_REQUEST[ $key ]) && $_REQUEST[ $key ] === $value
345
-                ? $bypass_recaptcha
346
-                : false;
347
-        }
348
-        return $bypass_recaptcha;
349
-    }
350
-
351
-
352
-    /**
353
-     * @return void
354
-     * @throws InvalidArgumentException
355
-     * @throws InvalidInterfaceException
356
-     * @throws InvalidDataTypeException
357
-     */
358
-    private static function _get_recaptcha_response()
359
-    {
360
-        EED_Recaptcha::$_recaptcha_response = EED_Recaptcha::getRequest()->getRequestParam(
361
-            'g-recaptcha-response'
362
-        );
363
-    }
364
-
365
-
366
-    /**
367
-     * @return boolean
368
-     * @throws InvalidArgumentException
369
-     * @throws InvalidInterfaceException
370
-     * @throws InvalidDataTypeException
371
-     */
372
-    private static function _process_recaptcha_response()
373
-    {
374
-        // verify library is loaded
375
-        if (! class_exists('\ReCaptcha\ReCaptcha')) {
376
-            require_once RECAPTCHA_BASE_PATH . '/autoload.php';
377
-        }
378
-        // The response from reCAPTCHA
379
-        EED_Recaptcha::_get_recaptcha_response();
380
-        $recaptcha_response = EED_Recaptcha::$_recaptcha_response;
381
-        // Was there a reCAPTCHA response?
382
-        if ($recaptcha_response) {
383
-            // if allow_url_fopen is Off, then set a different request method
384
-            $request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null;
385
-            $recaptcha = new ReCaptcha(
386
-                EED_Recaptcha::$config->recaptcha_privatekey,
387
-                $request_method
388
-            );
389
-            $recaptcha_response = $recaptcha->verify(
390
-                EED_Recaptcha::$_recaptcha_response,
391
-                $_SERVER['REMOTE_ADDR']
392
-            );
393
-        }
394
-        return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess();
395
-    }
21
+	/**
22
+	 * @var EE_Registration_Config $config
23
+	 */
24
+	private static $config;
25
+
26
+	/**
27
+	 * @type bool $_not_a_robot
28
+	 */
29
+	private static $_not_a_robot;
30
+
31
+	/**
32
+	 * @type string $_recaptcha_response
33
+	 */
34
+	private static $_recaptcha_response;
35
+
36
+
37
+	/**
38
+	 * @return EED_Module|EED_Recaptcha
39
+	 */
40
+	public static function instance()
41
+	{
42
+		return parent::get_instance(__CLASS__);
43
+	}
44
+
45
+
46
+	/**
47
+	 * set_hooks - for hooking into EE Core, other modules, etc
48
+	 *
49
+	 * @return void
50
+	 * @throws InvalidArgumentException
51
+	 * @throws InvalidInterfaceException
52
+	 * @throws InvalidDataTypeException
53
+	 */
54
+	public static function set_hooks()
55
+	{
56
+		EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
57
+		// use_captcha ?
58
+		if (EED_Recaptcha::useRecaptcha()
59
+			&& EED_Recaptcha::notPaymentOptionsRevisit()
60
+		) {
61
+			EED_Recaptcha::set_definitions();
62
+			EED_Recaptcha::enqueue_styles_and_scripts();
63
+			add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0);
64
+			add_action(
65
+				'AHEE__before_spco_whats_next_buttons',
66
+				array('EED_Recaptcha', 'display_recaptcha'),
67
+				10,
68
+				0
69
+			);
70
+			add_filter(
71
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
72
+				array('EED_Recaptcha', 'not_a_robot')
73
+			);
74
+			add_filter(
75
+				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
76
+				array('EED_Recaptcha', 'not_a_robot')
77
+			);
78
+			add_filter(
79
+				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
80
+				array('EED_Recaptcha', 'recaptcha_response')
81
+			);
82
+			add_filter(
83
+				'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
84
+				array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method')
85
+			);
86
+		}
87
+	}
88
+
89
+
90
+	/**
91
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
92
+	 *
93
+	 * @return void
94
+	 * @throws InvalidArgumentException
95
+	 * @throws InvalidInterfaceException
96
+	 * @throws InvalidDataTypeException
97
+	 */
98
+	public static function set_hooks_admin()
99
+	{
100
+		EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
101
+		EED_Recaptcha::set_definitions();
102
+		// use_captcha ?
103
+		if (EED_Recaptcha::useRecaptcha()
104
+			&& EED_Recaptcha::notPaymentOptionsRevisit()
105
+			&& EED_Recaptcha::getRequest()->getRequestParam('step', '') !== ''
106
+		) {
107
+			EED_Recaptcha::enqueue_styles_and_scripts();
108
+			add_filter(
109
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
110
+				array('EED_Recaptcha', 'not_a_robot')
111
+			);
112
+			add_filter(
113
+				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
114
+				array('EED_Recaptcha', 'not_a_robot')
115
+			);
116
+			add_filter(
117
+				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
118
+				array('EED_Recaptcha', 'recaptcha_response')
119
+			);
120
+		}
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return void
126
+	 */
127
+	public static function set_definitions()
128
+	{
129
+		if (is_user_logged_in()) {
130
+			EED_Recaptcha::$_not_a_robot = true;
131
+		}
132
+		define(
133
+			'RECAPTCHA_BASE_PATH',
134
+			rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
135
+		);
136
+		define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
137
+	}
138
+
139
+
140
+	/**
141
+	 * @return void
142
+	 */
143
+	public static function set_late_hooks()
144
+	{
145
+		add_filter(
146
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
147
+			array('EED_Recaptcha', 'not_a_robot')
148
+		);
149
+	}
150
+
151
+
152
+	/**
153
+	 * @return boolean
154
+	 */
155
+	public static function useRecaptcha()
156
+	{
157
+		return EED_Recaptcha::$config->use_captcha
158
+			   && EED_Recaptcha::$config->recaptcha_theme !== 'invisible';
159
+	}
160
+
161
+
162
+	/**
163
+	 * @return boolean
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidInterfaceException
166
+	 * @throws InvalidDataTypeException
167
+	 */
168
+	public static function notPaymentOptionsRevisit()
169
+	{
170
+		$request = EED_Recaptcha::getRequest();
171
+		return ! (
172
+			$request->getRequestParam('step', '') === 'payment_options'
173
+			&& $request->getRequestParam('revisit', false, 'bool') === true
174
+		);
175
+	}
176
+
177
+
178
+	/**
179
+	 * @return void
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidInterfaceException
182
+	 * @throws InvalidDataTypeException
183
+	 */
184
+	public static function enqueue_styles_and_scripts()
185
+	{
186
+		wp_register_script(
187
+			'espresso_recaptcha',
188
+			RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
189
+			array('single_page_checkout'),
190
+			EVENT_ESPRESSO_VERSION,
191
+			true
192
+		);
193
+		wp_register_script(
194
+			'google_recaptcha',
195
+			'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
196
+			array('espresso_recaptcha'),
197
+			EVENT_ESPRESSO_VERSION,
198
+			true
199
+		);
200
+		EE_Registry::$i18n_js_strings['no_SPCO_error'] = __(
201
+			'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.',
202
+			'event_espresso'
203
+		);
204
+		EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __(
205
+			'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.',
206
+			'event_espresso'
207
+		);
208
+		EE_Registry::$i18n_js_strings['recaptcha_fail'] = __(
209
+			'Please complete the anti-spam test before proceeding.',
210
+			'event_espresso'
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 * @param WP $WP
217
+	 */
218
+	public function run($WP)
219
+	{
220
+	}
221
+
222
+
223
+	/**
224
+	 * @return boolean
225
+	 * @throws InvalidArgumentException
226
+	 * @throws InvalidInterfaceException
227
+	 * @throws InvalidDataTypeException
228
+	 */
229
+	public static function not_a_robot()
230
+	{
231
+		return is_bool(EED_Recaptcha::$_not_a_robot)
232
+			? EED_Recaptcha::$_not_a_robot
233
+			: EED_Recaptcha::recaptcha_passed();
234
+	}
235
+
236
+
237
+	/**
238
+	 * @return void
239
+	 * @throws DomainException
240
+	 * @throws InvalidArgumentException
241
+	 * @throws InvalidInterfaceException
242
+	 * @throws InvalidDataTypeException
243
+	 */
244
+	public static function display_recaptcha()
245
+	{
246
+		// logged in means you have already passed a turing test of sorts
247
+		if (is_user_logged_in()) {
248
+			return;
249
+		}
250
+		// don't display if not using recaptcha or user is logged in
251
+		if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
252
+			// only display if they have NOT passed the test yet
253
+			EEH_Template::display_template(
254
+				RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
255
+				array(
256
+					'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
257
+					'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
258
+					'recaptcha_type'      => EED_Recaptcha::$config->recaptcha_type,
259
+				)
260
+			);
261
+			wp_enqueue_script('google_recaptcha');
262
+		}
263
+	}
264
+
265
+
266
+	/**
267
+	 * @return array
268
+	 * @throws InvalidArgumentException
269
+	 * @throws InvalidInterfaceException
270
+	 * @throws InvalidDataTypeException
271
+	 */
272
+	public static function bypass_recaptcha_for_spco_load_payment_method()
273
+	{
274
+		return array(
275
+			'EESID'  => EE_Registry::instance()->SSN->id(),
276
+			'step'   => 'payment_options',
277
+			'action' => 'switch_spco_billing_form',
278
+		);
279
+	}
280
+
281
+
282
+	/**
283
+	 * @return boolean
284
+	 * @throws InvalidArgumentException
285
+	 * @throws InvalidInterfaceException
286
+	 * @throws InvalidDataTypeException
287
+	 */
288
+	public static function recaptcha_passed()
289
+	{
290
+		// logged in means you have already passed a turing test of sorts
291
+		if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) {
292
+			return true;
293
+		}
294
+		// was test already passed?
295
+		$recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed');
296
+		$recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
297
+		// verify recaptcha
298
+		EED_Recaptcha::_get_recaptcha_response();
299
+		if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
300
+			$recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
301
+			EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
302
+		}
303
+		EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
304
+		return $recaptcha_passed;
305
+	}
306
+
307
+
308
+	/**
309
+	 * @param array $recaptcha_response
310
+	 * @return array
311
+	 */
312
+	public static function recaptcha_response($recaptcha_response = array())
313
+	{
314
+		if (EED_Recaptcha::_bypass_recaptcha()) {
315
+			$recaptcha_response['bypass_recaptcha'] = true;
316
+			$recaptcha_response['recaptcha_passed'] = true;
317
+		} else {
318
+			$recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot;
319
+		}
320
+		return $recaptcha_response;
321
+	}
322
+
323
+
324
+	/**
325
+	 * @return boolean
326
+	 */
327
+	private static function _bypass_recaptcha()
328
+	{
329
+		// an array of key value pairs that must match exactly with the incoming request,
330
+		// in order to bypass recaptcha for the current request ONLY
331
+		$bypass_request_params_array = (array) apply_filters(
332
+			'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
333
+			array()
334
+		);
335
+		// does $bypass_request_params_array have any values ?
336
+		if (empty($bypass_request_params_array)) {
337
+			return false;
338
+		}
339
+		// initially set bypass to TRUE
340
+		$bypass_recaptcha = true;
341
+		foreach ($bypass_request_params_array as $key => $value) {
342
+			// if $key is not found or value doesn't match exactly, then toggle bypass to FALSE,
343
+			// otherwise carry over it's value. This way, one missed setting results in no bypass
344
+			$bypass_recaptcha = isset($_REQUEST[ $key ]) && $_REQUEST[ $key ] === $value
345
+				? $bypass_recaptcha
346
+				: false;
347
+		}
348
+		return $bypass_recaptcha;
349
+	}
350
+
351
+
352
+	/**
353
+	 * @return void
354
+	 * @throws InvalidArgumentException
355
+	 * @throws InvalidInterfaceException
356
+	 * @throws InvalidDataTypeException
357
+	 */
358
+	private static function _get_recaptcha_response()
359
+	{
360
+		EED_Recaptcha::$_recaptcha_response = EED_Recaptcha::getRequest()->getRequestParam(
361
+			'g-recaptcha-response'
362
+		);
363
+	}
364
+
365
+
366
+	/**
367
+	 * @return boolean
368
+	 * @throws InvalidArgumentException
369
+	 * @throws InvalidInterfaceException
370
+	 * @throws InvalidDataTypeException
371
+	 */
372
+	private static function _process_recaptcha_response()
373
+	{
374
+		// verify library is loaded
375
+		if (! class_exists('\ReCaptcha\ReCaptcha')) {
376
+			require_once RECAPTCHA_BASE_PATH . '/autoload.php';
377
+		}
378
+		// The response from reCAPTCHA
379
+		EED_Recaptcha::_get_recaptcha_response();
380
+		$recaptcha_response = EED_Recaptcha::$_recaptcha_response;
381
+		// Was there a reCAPTCHA response?
382
+		if ($recaptcha_response) {
383
+			// if allow_url_fopen is Off, then set a different request method
384
+			$request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null;
385
+			$recaptcha = new ReCaptcha(
386
+				EED_Recaptcha::$config->recaptcha_privatekey,
387
+				$request_method
388
+			);
389
+			$recaptcha_response = $recaptcha->verify(
390
+				EED_Recaptcha::$_recaptcha_response,
391
+				$_SERVER['REMOTE_ADDR']
392
+			);
393
+		}
394
+		return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess();
395
+	}
396 396
 }
Please login to merge, or discard this patch.
core/EES_Shortcode.shortcode.php 1 patch
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -15,186 +15,186 @@
 block discarded – undo
15 15
 abstract class EES_Shortcode extends EE_Base
16 16
 {
17 17
 
18
-    /**
19
-     * @protected   public
20
-     * @var     array $_attributes
21
-     */
22
-    protected $_attributes = array();
23
-
24
-
25
-
26
-    /**
27
-     * class constructor - should ONLY be instantiated by EE_Front_Controller
28
-     */
29
-    final public function __construct()
30
-    {
31
-        $shortcode = LegacyShortcodesManager::generateShortcodeTagFromClassName(get_class($this));
32
-        // assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier
33
-        add_shortcode($shortcode, array($this, 'process_shortcode'));
34
-        // make sure system knows this is an EE page
35
-        /** @var CurrentPage $current_page */
36
-        $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
37
-        $current_page->setEspressoPage(true);
38
-    }
39
-
40
-
41
-
42
-    /**
43
-     * run - initial shortcode module setup called during "parse_request" hook by
44
-     * \EE_Front_Controller::_initialize_shortcodes() IF this shortcode is going to execute during this request !
45
-     * It may also get called by \EES_Shortcode::fallback_shortcode_processor() if the shortcode is being implemented
46
-     * by a theme or plugin in a non-standard way.
47
-     * Basically this method is primarily used for loading resources and assets like CSS or JS
48
-     * that will be required by the shortcode when it is actually processed.
49
-     * Please note that assets may not load if the fallback_shortcode_processor() is being used.
50
-     *
51
-     * @access    public
52
-     * @param WP $WP
53
-     * @return    void
54
-     */
55
-    abstract public function run(WP $WP);
56
-
57
-
58
-
59
-    /**
60
-     *  process_shortcode
61
-     *  this method is the callback function for the actual shortcode, and is what runs when WP encounters the shortcode within the_content
62
-     *
63
-     *  @access     public
64
-     *  @param      array   $attributes
65
-     *  @return     mixed
66
-     */
67
-    abstract public function process_shortcode($attributes = array());
68
-
69
-
70
-
71
-    /**
72
-     *    instance - returns instance of child class object
73
-     *
74
-     * @access  public
75
-     * @param   string $shortcode_class
76
-     * @return  \EES_Shortcode
77
-     */
78
-    final public static function instance($shortcode_class = null)
79
-    {
80
-        $shortcode_class = ! empty($shortcode_class) ? $shortcode_class : get_called_class();
81
-        if ($shortcode_class === 'EES_Shortcode' || empty($shortcode_class)) {
82
-            return null;
83
-        }
84
-        $shortcode = str_replace('EES_', '', strtoupper($shortcode_class));
85
-        $shortcode_obj = isset(EE_Registry::instance()->shortcodes->{$shortcode})
86
-            ? EE_Registry::instance()->shortcodes->{$shortcode}
87
-            : null;
88
-        return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self'
89
-            ? $shortcode_obj
90
-            : new $shortcode_class();
91
-    }
92
-
93
-
94
-
95
-
96
-    /**
97
-     *    fallback_shortcode_processor - create instance and call process_shortcode
98
-     *    NOTE: shortcode may not function perfectly dues to missing assets, but it's better than not having things work at all
99
-     *
100
-     * @access  public
101
-     * @param   $attributes
102
-     * @return  mixed
103
-     */
104
-    final public static function fallback_shortcode_processor($attributes)
105
-    {
106
-        if (EE_Maintenance_Mode::disable_frontend_for_maintenance()) {
107
-            return null;
108
-        }
109
-        // what shortcode was actually parsed ?
110
-        $shortcode_class = get_called_class();
111
-        // notify rest of system that fallback processor was triggered
112
-        add_filter('FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true');
113
-        // get instance of actual shortcode
114
-        $shortcode_obj = self::instance($shortcode_class);
115
-        // verify class
116
-        if ($shortcode_obj instanceof EES_Shortcode) {
117
-            global $wp;
118
-            $shortcode_obj->run($wp);
119
-            // set attributes and run the shortcode
120
-            $shortcode_obj->_attributes = (array) $attributes;
121
-            return $shortcode_obj->process_shortcode($shortcode_obj->_attributes);
122
-        } else {
123
-            return null;
124
-        }
125
-    }
126
-
127
-
128
-
129
-
130
-    /**
131
-     *    invalid_shortcode_processor -  used in cases where we know the shortcode is invalid, most likely due to a deactivated addon, and simply returns an empty string
132
-     *
133
-     * @access  public
134
-     * @param   $attributes
135
-     * @return  string
136
-     */
137
-    final public static function invalid_shortcode_processor($attributes)
138
-    {
139
-        return '';
140
-    }
141
-
142
-
143
-
144
-
145
-
146
-    /**
147
-     * Performs basic sanitization on shortcode attributes
148
-     * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
149
-     * most attributes will by default be sanitized using the sanitize_text_field() function.
150
-     * This can be overridden by supplying an array for the $custom_sanitization param,
151
-     * where keys match keys in your attributes array,
152
-     * and values represent the sanitization function you wish to be applied to that attribute.
153
-     * So for example, if you had an integer attribute named "event_id"
154
-     * that you wanted to be sanitized using absint(),
155
-     * then you would pass the following for your $custom_sanitization array:
156
-     *      array('event_id' => 'absint')
157
-     * all other attributes would be sanitized using the defaults in the switch statement below
158
-     *
159
-     * @param array $attributes
160
-     * @param array $custom_sanitization
161
-     * @return array
162
-     */
163
-    public static function sanitize_attributes(array $attributes, $custom_sanitization = array())
164
-    {
165
-        foreach ($attributes as $key => $value) {
166
-            // is a custom sanitization callback specified ?
167
-            if (isset($custom_sanitization[ $key ])) {
168
-                $callback = $custom_sanitization[ $key ];
169
-                if ($callback === 'skip_sanitization') {
170
-                    $attributes[ $key ] = $value;
171
-                    continue;
172
-                } elseif (function_exists($callback)) {
173
-                    $attributes[ $key ] = $callback($value);
174
-                    continue;
175
-                }
176
-            }
177
-            switch (true) {
178
-                case $value === null:
179
-                case is_int($value):
180
-                case is_float($value):
181
-                    // typical booleans
182
-                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true):
183
-                    $attributes[ $key ] = $value;
184
-                    break;
185
-                case is_string($value):
186
-                    $attributes[ $key ] = sanitize_text_field($value);
187
-                    break;
188
-                case is_array($value):
189
-                    $attributes[ $key ] = \EES_Shortcode::sanitize_attributes($value);
190
-                    break;
191
-                default:
192
-                    // only remaining data types are Object and Resource
193
-                    // which are not allowed as shortcode attributes
194
-                    $attributes[ $key ] = null;
195
-                    break;
196
-            }
197
-        }
198
-        return $attributes;
199
-    }
18
+	/**
19
+	 * @protected   public
20
+	 * @var     array $_attributes
21
+	 */
22
+	protected $_attributes = array();
23
+
24
+
25
+
26
+	/**
27
+	 * class constructor - should ONLY be instantiated by EE_Front_Controller
28
+	 */
29
+	final public function __construct()
30
+	{
31
+		$shortcode = LegacyShortcodesManager::generateShortcodeTagFromClassName(get_class($this));
32
+		// assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier
33
+		add_shortcode($shortcode, array($this, 'process_shortcode'));
34
+		// make sure system knows this is an EE page
35
+		/** @var CurrentPage $current_page */
36
+		$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
37
+		$current_page->setEspressoPage(true);
38
+	}
39
+
40
+
41
+
42
+	/**
43
+	 * run - initial shortcode module setup called during "parse_request" hook by
44
+	 * \EE_Front_Controller::_initialize_shortcodes() IF this shortcode is going to execute during this request !
45
+	 * It may also get called by \EES_Shortcode::fallback_shortcode_processor() if the shortcode is being implemented
46
+	 * by a theme or plugin in a non-standard way.
47
+	 * Basically this method is primarily used for loading resources and assets like CSS or JS
48
+	 * that will be required by the shortcode when it is actually processed.
49
+	 * Please note that assets may not load if the fallback_shortcode_processor() is being used.
50
+	 *
51
+	 * @access    public
52
+	 * @param WP $WP
53
+	 * @return    void
54
+	 */
55
+	abstract public function run(WP $WP);
56
+
57
+
58
+
59
+	/**
60
+	 *  process_shortcode
61
+	 *  this method is the callback function for the actual shortcode, and is what runs when WP encounters the shortcode within the_content
62
+	 *
63
+	 *  @access     public
64
+	 *  @param      array   $attributes
65
+	 *  @return     mixed
66
+	 */
67
+	abstract public function process_shortcode($attributes = array());
68
+
69
+
70
+
71
+	/**
72
+	 *    instance - returns instance of child class object
73
+	 *
74
+	 * @access  public
75
+	 * @param   string $shortcode_class
76
+	 * @return  \EES_Shortcode
77
+	 */
78
+	final public static function instance($shortcode_class = null)
79
+	{
80
+		$shortcode_class = ! empty($shortcode_class) ? $shortcode_class : get_called_class();
81
+		if ($shortcode_class === 'EES_Shortcode' || empty($shortcode_class)) {
82
+			return null;
83
+		}
84
+		$shortcode = str_replace('EES_', '', strtoupper($shortcode_class));
85
+		$shortcode_obj = isset(EE_Registry::instance()->shortcodes->{$shortcode})
86
+			? EE_Registry::instance()->shortcodes->{$shortcode}
87
+			: null;
88
+		return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self'
89
+			? $shortcode_obj
90
+			: new $shortcode_class();
91
+	}
92
+
93
+
94
+
95
+
96
+	/**
97
+	 *    fallback_shortcode_processor - create instance and call process_shortcode
98
+	 *    NOTE: shortcode may not function perfectly dues to missing assets, but it's better than not having things work at all
99
+	 *
100
+	 * @access  public
101
+	 * @param   $attributes
102
+	 * @return  mixed
103
+	 */
104
+	final public static function fallback_shortcode_processor($attributes)
105
+	{
106
+		if (EE_Maintenance_Mode::disable_frontend_for_maintenance()) {
107
+			return null;
108
+		}
109
+		// what shortcode was actually parsed ?
110
+		$shortcode_class = get_called_class();
111
+		// notify rest of system that fallback processor was triggered
112
+		add_filter('FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true');
113
+		// get instance of actual shortcode
114
+		$shortcode_obj = self::instance($shortcode_class);
115
+		// verify class
116
+		if ($shortcode_obj instanceof EES_Shortcode) {
117
+			global $wp;
118
+			$shortcode_obj->run($wp);
119
+			// set attributes and run the shortcode
120
+			$shortcode_obj->_attributes = (array) $attributes;
121
+			return $shortcode_obj->process_shortcode($shortcode_obj->_attributes);
122
+		} else {
123
+			return null;
124
+		}
125
+	}
126
+
127
+
128
+
129
+
130
+	/**
131
+	 *    invalid_shortcode_processor -  used in cases where we know the shortcode is invalid, most likely due to a deactivated addon, and simply returns an empty string
132
+	 *
133
+	 * @access  public
134
+	 * @param   $attributes
135
+	 * @return  string
136
+	 */
137
+	final public static function invalid_shortcode_processor($attributes)
138
+	{
139
+		return '';
140
+	}
141
+
142
+
143
+
144
+
145
+
146
+	/**
147
+	 * Performs basic sanitization on shortcode attributes
148
+	 * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
149
+	 * most attributes will by default be sanitized using the sanitize_text_field() function.
150
+	 * This can be overridden by supplying an array for the $custom_sanitization param,
151
+	 * where keys match keys in your attributes array,
152
+	 * and values represent the sanitization function you wish to be applied to that attribute.
153
+	 * So for example, if you had an integer attribute named "event_id"
154
+	 * that you wanted to be sanitized using absint(),
155
+	 * then you would pass the following for your $custom_sanitization array:
156
+	 *      array('event_id' => 'absint')
157
+	 * all other attributes would be sanitized using the defaults in the switch statement below
158
+	 *
159
+	 * @param array $attributes
160
+	 * @param array $custom_sanitization
161
+	 * @return array
162
+	 */
163
+	public static function sanitize_attributes(array $attributes, $custom_sanitization = array())
164
+	{
165
+		foreach ($attributes as $key => $value) {
166
+			// is a custom sanitization callback specified ?
167
+			if (isset($custom_sanitization[ $key ])) {
168
+				$callback = $custom_sanitization[ $key ];
169
+				if ($callback === 'skip_sanitization') {
170
+					$attributes[ $key ] = $value;
171
+					continue;
172
+				} elseif (function_exists($callback)) {
173
+					$attributes[ $key ] = $callback($value);
174
+					continue;
175
+				}
176
+			}
177
+			switch (true) {
178
+				case $value === null:
179
+				case is_int($value):
180
+				case is_float($value):
181
+					// typical booleans
182
+				case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true):
183
+					$attributes[ $key ] = $value;
184
+					break;
185
+				case is_string($value):
186
+					$attributes[ $key ] = sanitize_text_field($value);
187
+					break;
188
+				case is_array($value):
189
+					$attributes[ $key ] = \EES_Shortcode::sanitize_attributes($value);
190
+					break;
191
+				default:
192
+					// only remaining data types are Object and Resource
193
+					// which are not allowed as shortcode attributes
194
+					$attributes[ $key ] = null;
195
+					break;
196
+			}
197
+		}
198
+		return $attributes;
199
+	}
200 200
 }
Please login to merge, or discard this patch.
core/services/request/CurrentPage.php 2 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -7,286 +7,286 @@
 block discarded – undo
7 7
 
8 8
 class CurrentPage
9 9
 {
10
-    /**
11
-     * @var EE_CPT_Strategy
12
-     */
13
-    private $cpt_strategy;
14
-
15
-    /**
16
-     * @var bool
17
-     */
18
-    private $initialized;
19
-
20
-    /**
21
-     * @var bool
22
-     */
23
-    private $is_espresso_page = false;
24
-
25
-    /**
26
-     * @var int
27
-     */
28
-    private $post_id = 0;
29
-
30
-    /**
31
-     * @var string
32
-     */
33
-    private $post_name = '';
34
-
35
-    /**
36
-     * @var array
37
-     */
38
-    private $post_type = [];
39
-
40
-    /**
41
-     * @var RequestInterface $request
42
-     */
43
-    private $request;
44
-
45
-
46
-    /**
47
-     * CurrentPage constructor.
48
-     *
49
-     * @param EE_CPT_Strategy  $cpt_strategy
50
-     * @param RequestInterface $request
51
-     */
52
-    public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request)
53
-    {
54
-        $this->cpt_strategy = $cpt_strategy;
55
-        $this->request      = $request;
56
-        $this->initialized  = is_admin();
57
-        // analyse the incoming WP request
58
-        add_action('parse_request', [$this, 'parseQueryVars'], 2, 1);
59
-    }
60
-
61
-
62
-    /**
63
-     * @param WP $WP
64
-     * @return void
65
-     */
66
-    public function parseQueryVars(WP $WP = null)
67
-    {
68
-        if ($this->initialized) {
69
-            return;
70
-        }
71
-        // if somebody forgot to provide us with WP, that's ok because its global
72
-        if (! $WP instanceof WP) {
73
-            global $WP;
74
-        }
75
-        $this->post_id   = $this->getPostId($WP);
76
-        $this->post_name = $this->getPostName($WP);
77
-        $this->post_type = $this->getPostType($WP);
78
-        // true or false ? is this page being used by EE ?
79
-        $this->setEspressoPage();
80
-        remove_action('parse_request', [$this, 'parseRequest'], 2);
81
-        $this->initialized   = true;
82
-    }
83
-
84
-
85
-    /**
86
-     * Just a helper method for getting the url for the displayed page.
87
-     *
88
-     * @param WP|null $WP
89
-     * @return string
90
-     */
91
-    public function getPermalink(WP $WP = null)
92
-    {
93
-        $post_id = $this->post_id ?: $this->getPostId($WP);
94
-        if ($post_id) {
95
-            return get_permalink($post_id);
96
-        }
97
-        if (! $WP instanceof WP) {
98
-            global $WP;
99
-        }
100
-        if ($WP->request) {
101
-            return site_url($WP->request);
102
-        }
103
-        return esc_url_raw(site_url($_SERVER['REQUEST_URI']));
104
-    }
105
-
106
-
107
-    /**
108
-     * @return array
109
-     */
110
-    public function espressoPostType()
111
-    {
112
-        return array_filter(
113
-            $this->post_type,
114
-            function ($post_type) {
115
-                return strpos($post_type, 'espresso_') === 0;
116
-            }
117
-        );
118
-    }
119
-
120
-
121
-    /**
122
-     * @param WP $WP
123
-     * @return int
124
-     */
125
-    private function getPostId(WP $WP)
126
-    {
127
-        $post_id = null;
128
-        if (isset($WP->query_vars['p'])) {
129
-            $post_id = $WP->query_vars['p'];
130
-        }
131
-        if (! $post_id && isset($WP->query_vars['page_id'])) {
132
-            $post_id = $WP->query_vars['page_id'];
133
-        }
134
-        if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) {
135
-            $post_id = basename($WP->request);
136
-        }
137
-        if (! $post_id && $this->request->requestParamIsSet('post_id')) {
138
-            $post_id = $this->request->getRequestParam('post_id');
139
-        }
140
-        return $post_id;
141
-    }
142
-
143
-
144
-    /**
145
-     * @param WP $WP
146
-     * @return string
147
-     */
148
-    private function getPostName(WP $WP)
149
-    {
150
-        global $wpdb;
151
-        $post_name = null;
152
-        if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) {
153
-            $post_name = $WP->query_vars['name'];
154
-        }
155
-        if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) {
156
-            $post_name = $WP->query_vars['pagename'];
157
-        }
158
-        if (! $post_name && $WP->request !== null && ! empty($WP->request)) {
159
-            $possible_post_name = basename($WP->request);
160
-            if (! is_numeric($possible_post_name)) {
161
-                $SQL                = "SELECT ID from {$wpdb->posts}";
162
-                $SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
163
-                $SQL                .= ' AND post_name=%s';
164
-                $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
165
-                if ($possible_post_name) {
166
-                    $post_name = $possible_post_name;
167
-                }
168
-            }
169
-        }
170
-        if (! $post_name && $this->post_id) {
171
-            $SQL                = "SELECT post_name from {$wpdb->posts}";
172
-            $SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
173
-            $SQL                .= ' AND ID=%d';
174
-            $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id));
175
-            if ($possible_post_name) {
176
-                $post_name = $possible_post_name;
177
-            }
178
-        }
179
-        if (! $post_name && $this->request->requestParamIsSet('post_name')) {
180
-            $post_name = $this->request->getRequestParam('post_name');
181
-        }
182
-        return $post_name;
183
-    }
184
-
185
-
186
-    /**
187
-     * @param WP $WP
188
-     * @return array
189
-     */
190
-    private function getPostType(WP $WP)
191
-    {
192
-        $post_types = isset($WP->query_vars['post_type'])
193
-            ? (array) $WP->query_vars['post_type']
194
-            : [];
195
-        if (empty($post_types) && $this->request->requestParamIsSet('post_type')) {
196
-            $post_types = $this->request->getRequestParam('post_type');
197
-        }
198
-        return (array) $post_types;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return bool
204
-     */
205
-    public function isEspressoPage()
206
-    {
207
-        return $this->is_espresso_page;
208
-    }
209
-
210
-
211
-    /**
212
-     * @return int
213
-     */
214
-    public function postId()
215
-    {
216
-        return $this->post_id;
217
-    }
218
-
219
-
220
-    /**
221
-     * @return string
222
-     */
223
-    public function postName()
224
-    {
225
-        return $this->post_name;
226
-    }
227
-
228
-
229
-    /**
230
-     * @return array
231
-     */
232
-    public function postType()
233
-    {
234
-        return $this->post_type;
235
-    }
236
-
237
-
238
-    /**
239
-     * @param null|bool $value
240
-     * @return void
241
-     */
242
-    public function setEspressoPage($value = null)
243
-    {
244
-        $this->is_espresso_page = $value !== null
245
-            ? filter_var($value, FILTER_VALIDATE_BOOLEAN)
246
-            : $this->testForEspressoPage();
247
-    }
248
-
249
-
250
-    /**
251
-     * @return bool
252
-     */
253
-    private function testForEspressoPage()
254
-    {
255
-        // in case it has already been set
256
-        if ($this->is_espresso_page) {
257
-            return true;
258
-        }
259
-        global $WP;
260
-        $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies();
261
-        if (is_array($espresso_CPT_taxonomies)) {
262
-            foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
263
-                if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) {
264
-                    return true;
265
-                }
266
-            }
267
-        }
268
-        // load espresso CPT endpoints
269
-        $espresso_CPT_endpoints  = $this->cpt_strategy->get_CPT_endpoints();
270
-        $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
271
-        foreach ($this->post_type as $post_type) {
272
-            // was a post name passed ?
273
-            if (isset($post_type_CPT_endpoints[ $post_type ])) {
274
-                // kk we know this is an espresso page, but is it a specific post ?
275
-                if (! $this->post_name) {
276
-                    $espresso_post_type = $this->request->getRequestParam('post_type');
277
-                    // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
278
-                    // this essentially sets the post_name to "events" (or whatever EE CPT)
279
-                    $post_name = isset($post_type_CPT_endpoints[ $espresso_post_type ])
280
-                        ? $post_type_CPT_endpoints[ $espresso_post_type ]
281
-                        : '';
282
-                    // if the post type matches one of ours then set the post name to the endpoint
283
-                    if ($post_name) {
284
-                        $this->post_name = $post_name;
285
-                    }
286
-                }
287
-                return true;
288
-            }
289
-        }
290
-        return false;
291
-    }
10
+	/**
11
+	 * @var EE_CPT_Strategy
12
+	 */
13
+	private $cpt_strategy;
14
+
15
+	/**
16
+	 * @var bool
17
+	 */
18
+	private $initialized;
19
+
20
+	/**
21
+	 * @var bool
22
+	 */
23
+	private $is_espresso_page = false;
24
+
25
+	/**
26
+	 * @var int
27
+	 */
28
+	private $post_id = 0;
29
+
30
+	/**
31
+	 * @var string
32
+	 */
33
+	private $post_name = '';
34
+
35
+	/**
36
+	 * @var array
37
+	 */
38
+	private $post_type = [];
39
+
40
+	/**
41
+	 * @var RequestInterface $request
42
+	 */
43
+	private $request;
44
+
45
+
46
+	/**
47
+	 * CurrentPage constructor.
48
+	 *
49
+	 * @param EE_CPT_Strategy  $cpt_strategy
50
+	 * @param RequestInterface $request
51
+	 */
52
+	public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request)
53
+	{
54
+		$this->cpt_strategy = $cpt_strategy;
55
+		$this->request      = $request;
56
+		$this->initialized  = is_admin();
57
+		// analyse the incoming WP request
58
+		add_action('parse_request', [$this, 'parseQueryVars'], 2, 1);
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param WP $WP
64
+	 * @return void
65
+	 */
66
+	public function parseQueryVars(WP $WP = null)
67
+	{
68
+		if ($this->initialized) {
69
+			return;
70
+		}
71
+		// if somebody forgot to provide us with WP, that's ok because its global
72
+		if (! $WP instanceof WP) {
73
+			global $WP;
74
+		}
75
+		$this->post_id   = $this->getPostId($WP);
76
+		$this->post_name = $this->getPostName($WP);
77
+		$this->post_type = $this->getPostType($WP);
78
+		// true or false ? is this page being used by EE ?
79
+		$this->setEspressoPage();
80
+		remove_action('parse_request', [$this, 'parseRequest'], 2);
81
+		$this->initialized   = true;
82
+	}
83
+
84
+
85
+	/**
86
+	 * Just a helper method for getting the url for the displayed page.
87
+	 *
88
+	 * @param WP|null $WP
89
+	 * @return string
90
+	 */
91
+	public function getPermalink(WP $WP = null)
92
+	{
93
+		$post_id = $this->post_id ?: $this->getPostId($WP);
94
+		if ($post_id) {
95
+			return get_permalink($post_id);
96
+		}
97
+		if (! $WP instanceof WP) {
98
+			global $WP;
99
+		}
100
+		if ($WP->request) {
101
+			return site_url($WP->request);
102
+		}
103
+		return esc_url_raw(site_url($_SERVER['REQUEST_URI']));
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function espressoPostType()
111
+	{
112
+		return array_filter(
113
+			$this->post_type,
114
+			function ($post_type) {
115
+				return strpos($post_type, 'espresso_') === 0;
116
+			}
117
+		);
118
+	}
119
+
120
+
121
+	/**
122
+	 * @param WP $WP
123
+	 * @return int
124
+	 */
125
+	private function getPostId(WP $WP)
126
+	{
127
+		$post_id = null;
128
+		if (isset($WP->query_vars['p'])) {
129
+			$post_id = $WP->query_vars['p'];
130
+		}
131
+		if (! $post_id && isset($WP->query_vars['page_id'])) {
132
+			$post_id = $WP->query_vars['page_id'];
133
+		}
134
+		if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) {
135
+			$post_id = basename($WP->request);
136
+		}
137
+		if (! $post_id && $this->request->requestParamIsSet('post_id')) {
138
+			$post_id = $this->request->getRequestParam('post_id');
139
+		}
140
+		return $post_id;
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param WP $WP
146
+	 * @return string
147
+	 */
148
+	private function getPostName(WP $WP)
149
+	{
150
+		global $wpdb;
151
+		$post_name = null;
152
+		if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) {
153
+			$post_name = $WP->query_vars['name'];
154
+		}
155
+		if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) {
156
+			$post_name = $WP->query_vars['pagename'];
157
+		}
158
+		if (! $post_name && $WP->request !== null && ! empty($WP->request)) {
159
+			$possible_post_name = basename($WP->request);
160
+			if (! is_numeric($possible_post_name)) {
161
+				$SQL                = "SELECT ID from {$wpdb->posts}";
162
+				$SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
163
+				$SQL                .= ' AND post_name=%s';
164
+				$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
165
+				if ($possible_post_name) {
166
+					$post_name = $possible_post_name;
167
+				}
168
+			}
169
+		}
170
+		if (! $post_name && $this->post_id) {
171
+			$SQL                = "SELECT post_name from {$wpdb->posts}";
172
+			$SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
173
+			$SQL                .= ' AND ID=%d';
174
+			$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id));
175
+			if ($possible_post_name) {
176
+				$post_name = $possible_post_name;
177
+			}
178
+		}
179
+		if (! $post_name && $this->request->requestParamIsSet('post_name')) {
180
+			$post_name = $this->request->getRequestParam('post_name');
181
+		}
182
+		return $post_name;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @param WP $WP
188
+	 * @return array
189
+	 */
190
+	private function getPostType(WP $WP)
191
+	{
192
+		$post_types = isset($WP->query_vars['post_type'])
193
+			? (array) $WP->query_vars['post_type']
194
+			: [];
195
+		if (empty($post_types) && $this->request->requestParamIsSet('post_type')) {
196
+			$post_types = $this->request->getRequestParam('post_type');
197
+		}
198
+		return (array) $post_types;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return bool
204
+	 */
205
+	public function isEspressoPage()
206
+	{
207
+		return $this->is_espresso_page;
208
+	}
209
+
210
+
211
+	/**
212
+	 * @return int
213
+	 */
214
+	public function postId()
215
+	{
216
+		return $this->post_id;
217
+	}
218
+
219
+
220
+	/**
221
+	 * @return string
222
+	 */
223
+	public function postName()
224
+	{
225
+		return $this->post_name;
226
+	}
227
+
228
+
229
+	/**
230
+	 * @return array
231
+	 */
232
+	public function postType()
233
+	{
234
+		return $this->post_type;
235
+	}
236
+
237
+
238
+	/**
239
+	 * @param null|bool $value
240
+	 * @return void
241
+	 */
242
+	public function setEspressoPage($value = null)
243
+	{
244
+		$this->is_espresso_page = $value !== null
245
+			? filter_var($value, FILTER_VALIDATE_BOOLEAN)
246
+			: $this->testForEspressoPage();
247
+	}
248
+
249
+
250
+	/**
251
+	 * @return bool
252
+	 */
253
+	private function testForEspressoPage()
254
+	{
255
+		// in case it has already been set
256
+		if ($this->is_espresso_page) {
257
+			return true;
258
+		}
259
+		global $WP;
260
+		$espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies();
261
+		if (is_array($espresso_CPT_taxonomies)) {
262
+			foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
263
+				if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) {
264
+					return true;
265
+				}
266
+			}
267
+		}
268
+		// load espresso CPT endpoints
269
+		$espresso_CPT_endpoints  = $this->cpt_strategy->get_CPT_endpoints();
270
+		$post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
271
+		foreach ($this->post_type as $post_type) {
272
+			// was a post name passed ?
273
+			if (isset($post_type_CPT_endpoints[ $post_type ])) {
274
+				// kk we know this is an espresso page, but is it a specific post ?
275
+				if (! $this->post_name) {
276
+					$espresso_post_type = $this->request->getRequestParam('post_type');
277
+					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
278
+					// this essentially sets the post_name to "events" (or whatever EE CPT)
279
+					$post_name = isset($post_type_CPT_endpoints[ $espresso_post_type ])
280
+						? $post_type_CPT_endpoints[ $espresso_post_type ]
281
+						: '';
282
+					// if the post type matches one of ours then set the post name to the endpoint
283
+					if ($post_name) {
284
+						$this->post_name = $post_name;
285
+					}
286
+				}
287
+				return true;
288
+			}
289
+		}
290
+		return false;
291
+	}
292 292
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
             return;
70 70
         }
71 71
         // if somebody forgot to provide us with WP, that's ok because its global
72
-        if (! $WP instanceof WP) {
72
+        if ( ! $WP instanceof WP) {
73 73
             global $WP;
74 74
         }
75 75
         $this->post_id   = $this->getPostId($WP);
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         // true or false ? is this page being used by EE ?
79 79
         $this->setEspressoPage();
80 80
         remove_action('parse_request', [$this, 'parseRequest'], 2);
81
-        $this->initialized   = true;
81
+        $this->initialized = true;
82 82
     }
83 83
 
84 84
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
         if ($post_id) {
95 95
             return get_permalink($post_id);
96 96
         }
97
-        if (! $WP instanceof WP) {
97
+        if ( ! $WP instanceof WP) {
98 98
             global $WP;
99 99
         }
100 100
         if ($WP->request) {
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
     {
112 112
         return array_filter(
113 113
             $this->post_type,
114
-            function ($post_type) {
114
+            function($post_type) {
115 115
                 return strpos($post_type, 'espresso_') === 0;
116 116
             }
117 117
         );
@@ -128,13 +128,13 @@  discard block
 block discarded – undo
128 128
         if (isset($WP->query_vars['p'])) {
129 129
             $post_id = $WP->query_vars['p'];
130 130
         }
131
-        if (! $post_id && isset($WP->query_vars['page_id'])) {
131
+        if ( ! $post_id && isset($WP->query_vars['page_id'])) {
132 132
             $post_id = $WP->query_vars['page_id'];
133 133
         }
134
-        if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) {
134
+        if ( ! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) {
135 135
             $post_id = basename($WP->request);
136 136
         }
137
-        if (! $post_id && $this->request->requestParamIsSet('post_id')) {
137
+        if ( ! $post_id && $this->request->requestParamIsSet('post_id')) {
138 138
             $post_id = $this->request->getRequestParam('post_id');
139 139
         }
140 140
         return $post_id;
@@ -152,12 +152,12 @@  discard block
 block discarded – undo
152 152
         if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) {
153 153
             $post_name = $WP->query_vars['name'];
154 154
         }
155
-        if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) {
155
+        if ( ! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) {
156 156
             $post_name = $WP->query_vars['pagename'];
157 157
         }
158
-        if (! $post_name && $WP->request !== null && ! empty($WP->request)) {
158
+        if ( ! $post_name && $WP->request !== null && ! empty($WP->request)) {
159 159
             $possible_post_name = basename($WP->request);
160
-            if (! is_numeric($possible_post_name)) {
160
+            if ( ! is_numeric($possible_post_name)) {
161 161
                 $SQL                = "SELECT ID from {$wpdb->posts}";
162 162
                 $SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
163 163
                 $SQL                .= ' AND post_name=%s';
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
                 }
168 168
             }
169 169
         }
170
-        if (! $post_name && $this->post_id) {
170
+        if ( ! $post_name && $this->post_id) {
171 171
             $SQL                = "SELECT post_name from {$wpdb->posts}";
172 172
             $SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
173 173
             $SQL                .= ' AND ID=%d';
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
                 $post_name = $possible_post_name;
177 177
             }
178 178
         }
179
-        if (! $post_name && $this->request->requestParamIsSet('post_name')) {
179
+        if ( ! $post_name && $this->request->requestParamIsSet('post_name')) {
180 180
             $post_name = $this->request->getRequestParam('post_name');
181 181
         }
182 182
         return $post_name;
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
         $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies();
261 261
         if (is_array($espresso_CPT_taxonomies)) {
262 262
             foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
263
-                if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) {
263
+                if (isset($WP->query_vars, $WP->query_vars[$espresso_CPT_taxonomy])) {
264 264
                     return true;
265 265
                 }
266 266
             }
@@ -270,14 +270,14 @@  discard block
 block discarded – undo
270 270
         $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
271 271
         foreach ($this->post_type as $post_type) {
272 272
             // was a post name passed ?
273
-            if (isset($post_type_CPT_endpoints[ $post_type ])) {
273
+            if (isset($post_type_CPT_endpoints[$post_type])) {
274 274
                 // kk we know this is an espresso page, but is it a specific post ?
275
-                if (! $this->post_name) {
275
+                if ( ! $this->post_name) {
276 276
                     $espresso_post_type = $this->request->getRequestParam('post_type');
277 277
                     // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
278 278
                     // this essentially sets the post_name to "events" (or whatever EE CPT)
279
-                    $post_name = isset($post_type_CPT_endpoints[ $espresso_post_type ])
280
-                        ? $post_type_CPT_endpoints[ $espresso_post_type ]
279
+                    $post_name = isset($post_type_CPT_endpoints[$espresso_post_type])
280
+                        ? $post_type_CPT_endpoints[$espresso_post_type]
281 281
                         : '';
282 282
                     // if the post type matches one of ours then set the post name to the endpoint
283 283
                     if ($post_name) {
Please login to merge, or discard this patch.
core/services/request/ResponseInterface.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -12,54 +12,54 @@
 block discarded – undo
12 12
 interface ResponseInterface
13 13
 {
14 14
 
15
-    /**
16
-     * @param $key
17
-     * @param $value
18
-     * @return    void
19
-     */
20
-    public function setNotice($key, $value);
15
+	/**
16
+	 * @param $key
17
+	 * @param $value
18
+	 * @return    void
19
+	 */
20
+	public function setNotice($key, $value);
21 21
 
22
-    /**
23
-     * @param $key
24
-     * @return    mixed
25
-     */
26
-    public function getNotice($key);
22
+	/**
23
+	 * @param $key
24
+	 * @return    mixed
25
+	 */
26
+	public function getNotice($key);
27 27
 
28
-    /**
29
-     * @return    array
30
-     */
31
-    public function getNotices();
28
+	/**
29
+	 * @return    array
30
+	 */
31
+	public function getNotices();
32 32
 
33
-    /**
34
-     * @param string $string
35
-     * @param bool   $append
36
-     */
37
-    public function addOutput($string, $append = true);
33
+	/**
34
+	 * @param string $string
35
+	 * @param bool   $append
36
+	 */
37
+	public function addOutput($string, $append = true);
38 38
 
39
-    /**
40
-     * @param bool   $as_string
41
-     * @param string $separator
42
-     * @return array|string
43
-     */
44
-    public function getOutput($as_string = true, $separator = PHP_EOL);
39
+	/**
40
+	 * @param bool   $as_string
41
+	 * @param string $separator
42
+	 * @return array|string
43
+	 */
44
+	public function getOutput($as_string = true, $separator = PHP_EOL);
45 45
 
46
-    /**
47
-     * @return boolean
48
-     */
49
-    public function requestTerminated();
46
+	/**
47
+	 * @return boolean
48
+	 */
49
+	public function requestTerminated();
50 50
 
51
-    /**
52
-     * @param boolean $request_terminated
53
-     */
54
-    public function terminateRequest($request_terminated = true);
51
+	/**
52
+	 * @param boolean $request_terminated
53
+	 */
54
+	public function terminateRequest($request_terminated = true);
55 55
 
56
-    /**
57
-     * @return boolean
58
-     */
59
-    public function pluginDeactivated();
56
+	/**
57
+	 * @return boolean
58
+	 */
59
+	public function pluginDeactivated();
60 60
 
61
-    /**
62
-     * sets $deactivate_plugin to true
63
-     */
64
-    public function deactivatePlugin();
61
+	/**
62
+	 * sets $deactivate_plugin to true
63
+	 */
64
+	public function deactivatePlugin();
65 65
 }
Please login to merge, or discard this patch.
core/services/request/RequestInterface.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -16,159 +16,159 @@
 block discarded – undo
16 16
 interface RequestInterface extends RequestTypeContextCheckerInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @param RequestTypeContextCheckerInterface $type
21
-     */
22
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
23
-
24
-    /**
25
-     * @return array
26
-     */
27
-    public function getParams();
28
-
29
-
30
-    /**
31
-     * @return array
32
-     */
33
-    public function postParams();
34
-
35
-
36
-    /**
37
-     * @return array
38
-     */
39
-    public function cookieParams();
40
-
41
-
42
-    /**
43
-     * @return array
44
-     */
45
-    public function serverParams();
46
-
47
-
48
-    /**
49
-     * @return array
50
-     */
51
-    public function filesParams();
52
-
53
-
54
-    /**
55
-     * returns contents of $_REQUEST
56
-     *
57
-     * @return array
58
-     */
59
-    public function requestParams();
60
-
61
-
62
-    /**
63
-     * @param string $key
64
-     * @param string $value
65
-     * @param bool   $override_ee
66
-     * @return    void
67
-     */
68
-    public function setRequestParam($key, $value, $override_ee = false);
19
+	/**
20
+	 * @param RequestTypeContextCheckerInterface $type
21
+	 */
22
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
23
+
24
+	/**
25
+	 * @return array
26
+	 */
27
+	public function getParams();
28
+
29
+
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function postParams();
34
+
35
+
36
+	/**
37
+	 * @return array
38
+	 */
39
+	public function cookieParams();
40
+
41
+
42
+	/**
43
+	 * @return array
44
+	 */
45
+	public function serverParams();
46
+
47
+
48
+	/**
49
+	 * @return array
50
+	 */
51
+	public function filesParams();
52
+
53
+
54
+	/**
55
+	 * returns contents of $_REQUEST
56
+	 *
57
+	 * @return array
58
+	 */
59
+	public function requestParams();
60
+
61
+
62
+	/**
63
+	 * @param string $key
64
+	 * @param string $value
65
+	 * @param bool   $override_ee
66
+	 * @return    void
67
+	 */
68
+	public function setRequestParam($key, $value, $override_ee = false);
69 69
 
70 70
 
71
-    /**
72
-     * returns   the value for a request param if the given key exists
73
-     *
74
-     * @param string     $key
75
-     * @param mixed|null $default
76
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
77
-     * @param string     $delimiter for CSV type strings that should be returned as an array
78
-     * @return mixed
79
-     */
80
-    public function getRequestParam($key, $default = null, $type = 'string', $delimiter = ',');
81
-
82
-
83
-    /**
84
-     * check if param exists
85
-     *
86
-     * @param string $key
87
-     * @return bool
88
-     */
89
-    public function requestParamIsSet($key);
90
-
91
-
92
-    /**
93
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
94
-     * and return the value for the first match found
95
-     * wildcards can be either of the following:
96
-     *      ? to represent a single character of any type
97
-     *      * to represent one or more characters of any type
98
-     *
99
-     * @param string     $pattern
100
-     * @param mixed|null $default
101
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
102
-     * @param string     $delimiter for CSV type strings that should be returned as an array
103
-     * @return mixed
104
-     */
105
-    public function getMatch($pattern, $default = null, $type = 'string', $delimiter = ',');
106
-
107
-
108
-    /**
109
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
110
-     * wildcards can be either of the following:
111
-     *      ? to represent a single character of any type
112
-     *      * to represent one or more characters of any type
113
-     * returns true if a match is found or false if not
114
-     *
115
-     * @param string $pattern
116
-     * @return false|int
117
-     */
118
-    public function matches($pattern);
119
-
120
-
121
-    /**
122
-     * remove param
123
-     *
124
-     * @param string $key
125
-     * @param bool   $unset_from_global_too
126
-     */
127
-    public function unSetRequestParam($key, $unset_from_global_too = false);
128
-
129
-
130
-    /**
131
-     * remove params
132
-     *
133
-     * @param array $keys
134
-     * @param bool   $unset_from_global_too
135
-     */
136
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false);
137
-
138
-
139
-    /**
140
-     * @return string
141
-     */
142
-    public function ipAddress();
143
-
144
-
145
-    /**
146
-     * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
147
-     * @return string
148
-     */
149
-    public function requestUri($relativeToWpRoot = false);
150
-
151
-
152
-    /**
153
-     * @return string
154
-     */
155
-    public function userAgent();
156
-
157
-
158
-    /**
159
-     * @param string $user_agent
160
-     */
161
-    public function setUserAgent($user_agent = '');
162
-
163
-
164
-    /**
165
-     * @return bool
166
-     */
167
-    public function isBot();
168
-
169
-
170
-    /**
171
-     * @param bool $is_bot
172
-     */
173
-    public function setIsBot($is_bot);
71
+	/**
72
+	 * returns   the value for a request param if the given key exists
73
+	 *
74
+	 * @param string     $key
75
+	 * @param mixed|null $default
76
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
77
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
78
+	 * @return mixed
79
+	 */
80
+	public function getRequestParam($key, $default = null, $type = 'string', $delimiter = ',');
81
+
82
+
83
+	/**
84
+	 * check if param exists
85
+	 *
86
+	 * @param string $key
87
+	 * @return bool
88
+	 */
89
+	public function requestParamIsSet($key);
90
+
91
+
92
+	/**
93
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
94
+	 * and return the value for the first match found
95
+	 * wildcards can be either of the following:
96
+	 *      ? to represent a single character of any type
97
+	 *      * to represent one or more characters of any type
98
+	 *
99
+	 * @param string     $pattern
100
+	 * @param mixed|null $default
101
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
102
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
103
+	 * @return mixed
104
+	 */
105
+	public function getMatch($pattern, $default = null, $type = 'string', $delimiter = ',');
106
+
107
+
108
+	/**
109
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
110
+	 * wildcards can be either of the following:
111
+	 *      ? to represent a single character of any type
112
+	 *      * to represent one or more characters of any type
113
+	 * returns true if a match is found or false if not
114
+	 *
115
+	 * @param string $pattern
116
+	 * @return false|int
117
+	 */
118
+	public function matches($pattern);
119
+
120
+
121
+	/**
122
+	 * remove param
123
+	 *
124
+	 * @param string $key
125
+	 * @param bool   $unset_from_global_too
126
+	 */
127
+	public function unSetRequestParam($key, $unset_from_global_too = false);
128
+
129
+
130
+	/**
131
+	 * remove params
132
+	 *
133
+	 * @param array $keys
134
+	 * @param bool   $unset_from_global_too
135
+	 */
136
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false);
137
+
138
+
139
+	/**
140
+	 * @return string
141
+	 */
142
+	public function ipAddress();
143
+
144
+
145
+	/**
146
+	 * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
147
+	 * @return string
148
+	 */
149
+	public function requestUri($relativeToWpRoot = false);
150
+
151
+
152
+	/**
153
+	 * @return string
154
+	 */
155
+	public function userAgent();
156
+
157
+
158
+	/**
159
+	 * @param string $user_agent
160
+	 */
161
+	public function setUserAgent($user_agent = '');
162
+
163
+
164
+	/**
165
+	 * @return bool
166
+	 */
167
+	public function isBot();
168
+
169
+
170
+	/**
171
+	 * @param bool $is_bot
172
+	 */
173
+	public function setIsBot($is_bot);
174 174
 }
Please login to merge, or discard this patch.
core/services/request/Request.php 2 patches
Indentation   +715 added lines, -715 removed lines patch added patch discarded remove patch
@@ -17,719 +17,719 @@
 block discarded – undo
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19 19
 
20
-    /**
21
-     * $_GET parameters
22
-     *
23
-     * @var array $get
24
-     */
25
-    protected $get;
26
-
27
-    /**
28
-     * $_POST parameters
29
-     *
30
-     * @var array $post
31
-     */
32
-    protected $post;
33
-
34
-    /**
35
-     * $_COOKIE parameters
36
-     *
37
-     * @var array $cookie
38
-     */
39
-    protected $cookie;
40
-
41
-    /**
42
-     * $_SERVER parameters
43
-     *
44
-     * @var array $server
45
-     */
46
-    protected $server;
47
-
48
-    /**
49
-     * $_FILES parameters
50
-     *
51
-     * @var array $files
52
-     */
53
-    protected $files;
54
-
55
-    /**
56
-     * $_REQUEST parameters
57
-     *
58
-     * @var array $request
59
-     */
60
-    protected $request;
61
-
62
-    /**
63
-     * @var RequestTypeContextCheckerInterface
64
-     */
65
-    protected $request_type;
66
-
67
-    /**
68
-     * IP address for request
69
-     *
70
-     * @var string $ip_address
71
-     */
72
-    protected $ip_address;
73
-
74
-    /**
75
-     * @var string $user_agent
76
-     */
77
-    protected $user_agent;
78
-
79
-    /**
80
-     * true if current user appears to be some kind of bot
81
-     *
82
-     * @var bool $is_bot
83
-     */
84
-    protected $is_bot;
85
-
86
-
87
-    /**
88
-     * @param array $get
89
-     * @param array $post
90
-     * @param array $cookie
91
-     * @param array $server
92
-     * @param array $files
93
-     */
94
-    public function __construct(array $get, array $post, array $cookie, array $server, array $files = [])
95
-    {
96
-        // grab request vars
97
-        $this->get        = $get;
98
-        $this->post       = $post;
99
-        $this->cookie     = $cookie;
100
-        $this->server     = $server;
101
-        $this->files      = $files;
102
-        $this->request    = array_merge($this->get, $this->post);
103
-        $this->ip_address = $this->visitorIp();
104
-    }
105
-
106
-
107
-    /**
108
-     * @param RequestTypeContextCheckerInterface $type
109
-     */
110
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
-    {
112
-        $this->request_type = $type;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return array
118
-     */
119
-    public function getParams()
120
-    {
121
-        return $this->get;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return array
127
-     */
128
-    public function postParams()
129
-    {
130
-        return $this->post;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return array
136
-     */
137
-    public function cookieParams()
138
-    {
139
-        return $this->cookie;
140
-    }
141
-
142
-
143
-    /**
144
-     * @return array
145
-     */
146
-    public function serverParams()
147
-    {
148
-        return $this->server;
149
-    }
150
-
151
-
152
-    /**
153
-     * @return array
154
-     */
155
-    public function filesParams()
156
-    {
157
-        return $this->files;
158
-    }
159
-
160
-
161
-    /**
162
-     * returns contents of $_REQUEST
163
-     *
164
-     * @return array
165
-     */
166
-    public function requestParams()
167
-    {
168
-        return $this->request;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param string     $key
174
-     * @param mixed|null $value
175
-     * @param bool       $override_ee
176
-     * @return    void
177
-     */
178
-    public function setRequestParam($key, $value, $override_ee = false)
179
-    {
180
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
181
-        if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
182
-            $this->request[ $key ] = $value;
183
-        }
184
-    }
185
-
186
-
187
-    /**
188
-     * returns   the value for a request param if the given key exists
189
-     *
190
-     * @param string     $key
191
-     * @param mixed|null $default
192
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
193
-     * @param string     $delimiter for CSV type strings that should be returned as an array
194
-     * @return mixed
195
-     */
196
-    public function getRequestParam($key, $default = null, $type = 'string', $delimiter = ',')
197
-    {
198
-        return $this->sanitizeRequestParam(
199
-            $this->requestParameterDrillDown($key, $default, 'get'),
200
-            $type
201
-        );
202
-    }
203
-
204
-
205
-    /**
206
-     * check if param exists
207
-     *
208
-     * @param string $key
209
-     * @return bool
210
-     */
211
-    public function requestParamIsSet($key)
212
-    {
213
-        return (bool) $this->requestParameterDrillDown($key);
214
-    }
215
-
216
-
217
-    /**
218
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
219
-     * and return the value for the first match found
220
-     * wildcards can be either of the following:
221
-     *      ? to represent a single character of any type
222
-     *      * to represent one or more characters of any type
223
-     *
224
-     * @param string     $pattern
225
-     * @param mixed|null $default
226
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
227
-     * @param string     $delimiter for CSV type strings that should be returned as an array
228
-     * @return mixed
229
-     */
230
-    public function getMatch($pattern, $default = null, $type = 'string', $delimiter = ',')
231
-    {
232
-        return $this->sanitizeRequestParam(
233
-            $this->requestParameterDrillDown($pattern, $default, 'match'),
234
-            $type
235
-        );
236
-    }
237
-
238
-
239
-    /**
240
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
241
-     * wildcards can be either of the following:
242
-     *      ? to represent a single character of any type
243
-     *      * to represent one or more characters of any type
244
-     * returns true if a match is found or false if not
245
-     *
246
-     * @param string $pattern
247
-     * @return bool
248
-     */
249
-    public function matches($pattern)
250
-    {
251
-        return (bool) $this->requestParameterDrillDown($pattern, false, 'match', 'bool');
252
-    }
253
-
254
-
255
-    /**
256
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
257
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
258
-     *                                      and used to search through the current request's parameter keys
259
-     * @param array  $request_params        The array of request parameters to search through
260
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
261
-     *                                      Default is null
262
-     * @param string $return                [optional] Controls what kind of value is returned.
263
-     *                                      Options are:
264
-     *                                      'bool' will return true or false if match is found or not
265
-     *                                      'key' will return the first key found that matches the supplied pattern
266
-     *                                      'value' will return the value for the first request parameter
267
-     *                                      whose key matches the supplied pattern
268
-     *                                      Default is 'value'
269
-     * @return boolean|string
270
-     */
271
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
272
-    {
273
-        $return = in_array($return, ['bool', 'key', 'value'], true)
274
-            ? $return
275
-            : 'is_set';
276
-        // replace wildcard chars with regex chars
277
-        $pattern = str_replace(
278
-            ["\*", "\?"],
279
-            ['.*', '.'],
280
-            preg_quote($pattern, '/')
281
-        );
282
-        foreach ($request_params as $key => $request_param) {
283
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
284
-                // return value for request param
285
-                if ($return === 'value') {
286
-                    return $request_param;
287
-                }
288
-                // or actual key or true just to indicate it was found
289
-                return $return === 'key' ? $key : true;
290
-            }
291
-        }
292
-        // match not found so return default value or false
293
-        return $return === 'value' ? $default : false;
294
-    }
295
-
296
-
297
-    /**
298
-     * the supplied key can be a simple string to represent a "top-level" request parameter
299
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
300
-     * by using square brackets to surround keys for deeper array elements.
301
-     * For example :
302
-     * if the supplied $key was: "first[second][third]"
303
-     * then this will attempt to drill down into the request parameter array to find a value.
304
-     * Given the following request parameters:
305
-     *  array(
306
-     *      'first' => array(
307
-     *          'second' => array(
308
-     *              'third' => 'has a value'
309
-     *          )
310
-     *      )
311
-     *  )
312
-     * would return true if default parameters were set
313
-     *
314
-     * @param string $callback
315
-     * @param        $key
316
-     * @param null   $default
317
-     * @param string $return
318
-     * @param array  $request_params
319
-     * @return bool|mixed|null
320
-     */
321
-    private function requestParameterDrillDown(
322
-        $key,
323
-        $default = null,
324
-        $callback = 'is_set',
325
-        $return = 'value',
326
-        array $request_params = []
327
-    ) {
328
-        $callback       = in_array($callback, ['is_set', 'get', 'match'], true)
329
-            ? $callback
330
-            : 'is_set';
331
-        $request_params = ! empty($request_params)
332
-            ? $request_params
333
-            : $this->request;
334
-        // does incoming key represent an array like 'first[second][third]'  ?
335
-        if (strpos($key, '[') !== false) {
336
-            // turn it into an actual array
337
-            $key  = str_replace(']', '', $key);
338
-            $keys = explode('[', $key);
339
-            $key  = array_shift($keys);
340
-            if ($callback === 'match') {
341
-                $real_key = $this->match($key, $request_params, $default, 'key');
342
-                $key      = $real_key ?: $key;
343
-            }
344
-            // check if top level key exists
345
-            if (isset($request_params[ $key ])) {
346
-                // build a new key to pass along like: 'second[third]'
347
-                // or just 'second' depending on depth of keys
348
-                $key_string = array_shift($keys);
349
-                if (! empty($keys)) {
350
-                    $key_string .= '[' . implode('][', $keys) . ']';
351
-                }
352
-                return $this->requestParameterDrillDown(
353
-                    $key_string,
354
-                    $default,
355
-                    $callback,
356
-                    $return,
357
-                    $request_params[ $key ]
358
-                );
359
-            }
360
-        }
361
-        if ($callback === 'is_set') {
362
-            return isset($request_params[ $key ]);
363
-        }
364
-        if ($callback === 'match') {
365
-            return $this->match($key, $request_params, $default, $return);
366
-        }
367
-        return isset($request_params[ $key ])
368
-            ? $request_params[ $key ]
369
-            : $default;
370
-    }
371
-
372
-
373
-    /**
374
-     * remove param
375
-     *
376
-     * @param      $key
377
-     * @param bool $unset_from_global_too
378
-     */
379
-    public function unSetRequestParam($key, $unset_from_global_too = false)
380
-    {
381
-        // because unset may not actually remove var
382
-        $this->request[ $key ] = null;
383
-        unset($this->request[ $key ]);
384
-        if ($unset_from_global_too) {
385
-            unset($_REQUEST[ $key ]);
386
-        }
387
-    }
388
-
389
-
390
-    /**
391
-     * remove params
392
-     *
393
-     * @param array $keys
394
-     * @param bool  $unset_from_global_too
395
-     */
396
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
397
-    {
398
-        foreach ($keys as $key) {
399
-            $this->unSetRequestParam($key, $unset_from_global_too);
400
-        }
401
-    }
402
-
403
-
404
-    /**
405
-     * @return string
406
-     */
407
-    public function ipAddress()
408
-    {
409
-        return $this->ip_address;
410
-    }
411
-
412
-
413
-    /**
414
-     * attempt to get IP address of current visitor from server
415
-     * plz see: http://stackoverflow.com/a/2031935/1475279
416
-     *
417
-     * @access public
418
-     * @return string
419
-     */
420
-    private function visitorIp()
421
-    {
422
-        $visitor_ip  = '0.0.0.0';
423
-        $server_keys = [
424
-            'HTTP_CLIENT_IP',
425
-            'HTTP_X_FORWARDED_FOR',
426
-            'HTTP_X_FORWARDED',
427
-            'HTTP_X_CLUSTER_CLIENT_IP',
428
-            'HTTP_FORWARDED_FOR',
429
-            'HTTP_FORWARDED',
430
-            'REMOTE_ADDR',
431
-        ];
432
-        foreach ($server_keys as $key) {
433
-            if (isset($this->server[ $key ])) {
434
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
435
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
436
-                        $visitor_ip = $ip;
437
-                    }
438
-                }
439
-            }
440
-        }
441
-        return $visitor_ip;
442
-    }
443
-
444
-
445
-    /**
446
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
447
-     *
448
-     * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
449
-     *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
450
-     *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
451
-     * @return string
452
-     */
453
-    public function requestUri($relativeToWpRoot = false)
454
-    {
455
-        $request_uri = filter_input(
456
-            INPUT_SERVER,
457
-            'REQUEST_URI',
458
-            FILTER_SANITIZE_URL,
459
-            FILTER_NULL_ON_FAILURE
460
-        );
461
-        if (empty($request_uri) && isset($this->server['REQUEST_URI'])) {
462
-            // fallback sanitization if the above fails
463
-            $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
464
-        }
465
-        if ($relativeToWpRoot) {
466
-            $home_path   = untrailingslashit(
467
-                parse_url(
468
-                    home_url(),
469
-                    PHP_URL_PATH
470
-                )
471
-            );
472
-            $request_uri = str_replace(
473
-                $home_path,
474
-                '',
475
-                $request_uri
476
-            );
477
-        }
478
-        return $request_uri;
479
-    }
480
-
481
-
482
-    /**
483
-     * @return string
484
-     */
485
-    public function userAgent()
486
-    {
487
-        return $this->user_agent;
488
-    }
489
-
490
-
491
-    /**
492
-     * @param string $user_agent
493
-     */
494
-    public function setUserAgent($user_agent = '')
495
-    {
496
-        if ($user_agent === '' || ! is_string($user_agent)) {
497
-            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
498
-        }
499
-        $this->user_agent = $user_agent;
500
-    }
501
-
502
-
503
-    /**
504
-     * @return bool
505
-     */
506
-    public function isBot()
507
-    {
508
-        return $this->is_bot;
509
-    }
510
-
511
-
512
-    /**
513
-     * @param bool $is_bot
514
-     */
515
-    public function setIsBot($is_bot)
516
-    {
517
-        $this->is_bot = $this->sanitizeRequestParam($is_bot, 'bool');
518
-    }
519
-
520
-
521
-    /**
522
-     * @return bool
523
-     */
524
-    public function isActivation()
525
-    {
526
-        return $this->request_type->isActivation();
527
-    }
528
-
529
-
530
-    /**
531
-     * @param $is_activation
532
-     * @return bool
533
-     */
534
-    public function setIsActivation($is_activation)
535
-    {
536
-        return $this->request_type->setIsActivation($is_activation);
537
-    }
538
-
539
-
540
-    /**
541
-     * @return bool
542
-     */
543
-    public function isAdmin()
544
-    {
545
-        return $this->request_type->isAdmin();
546
-    }
547
-
548
-
549
-    /**
550
-     * @return bool
551
-     */
552
-    public function isAdminAjax()
553
-    {
554
-        return $this->request_type->isAdminAjax();
555
-    }
556
-
557
-
558
-    /**
559
-     * @return bool
560
-     */
561
-    public function isAjax()
562
-    {
563
-        return $this->request_type->isAjax();
564
-    }
565
-
566
-
567
-    /**
568
-     * @return bool
569
-     */
570
-    public function isEeAjax()
571
-    {
572
-        return $this->request_type->isEeAjax();
573
-    }
574
-
575
-
576
-    /**
577
-     * @return bool
578
-     */
579
-    public function isOtherAjax()
580
-    {
581
-        return $this->request_type->isOtherAjax();
582
-    }
583
-
584
-
585
-    /**
586
-     * @return bool
587
-     */
588
-    public function isApi()
589
-    {
590
-        return $this->request_type->isApi();
591
-    }
592
-
593
-
594
-    /**
595
-     * @return bool
596
-     */
597
-    public function isCli()
598
-    {
599
-        return $this->request_type->isCli();
600
-    }
601
-
602
-
603
-    /**
604
-     * @return bool
605
-     */
606
-    public function isCron()
607
-    {
608
-        return $this->request_type->isCron();
609
-    }
610
-
611
-
612
-    /**
613
-     * @return bool
614
-     */
615
-    public function isFeed()
616
-    {
617
-        return $this->request_type->isFeed();
618
-    }
619
-
620
-
621
-    /**
622
-     * @return bool
623
-     */
624
-    public function isFrontend()
625
-    {
626
-        return $this->request_type->isFrontend();
627
-    }
628
-
629
-
630
-    /**
631
-     * @return bool
632
-     */
633
-    public function isFrontAjax()
634
-    {
635
-        return $this->request_type->isFrontAjax();
636
-    }
637
-
638
-
639
-    /**
640
-     * @return bool
641
-     */
642
-    public function isIframe()
643
-    {
644
-        return $this->request_type->isIframe();
645
-    }
646
-
647
-
648
-    /**
649
-     * @return bool
650
-     */
651
-    public function isWordPressApi()
652
-    {
653
-        return $this->request_type->isWordPressApi();
654
-    }
655
-
656
-
657
-    /**
658
-     * @return bool
659
-     */
660
-    public function isWordPressHeartbeat()
661
-    {
662
-        return $this->request_type->isWordPressHeartbeat();
663
-    }
664
-
665
-
666
-    /**
667
-     * @return bool
668
-     */
669
-    public function isWordPressScrape()
670
-    {
671
-        return $this->request_type->isWordPressScrape();
672
-    }
673
-
674
-
675
-    /**
676
-     * @return string
677
-     */
678
-    public function slug()
679
-    {
680
-        return $this->request_type->slug();
681
-    }
682
-
683
-
684
-    /**
685
-     * @return RequestTypeContextCheckerInterface
686
-     */
687
-    public function getRequestType()
688
-    {
689
-        return $this->request_type;
690
-    }
691
-
692
-
693
-
694
-
695
-    /**
696
-     * Will sanitize the supplied request parameter based on the specified data type
697
-     *
698
-     * @param mixed  $param     the supplied request parameter
699
-     * @param string $type      the specified data type (default: "string")
700
-     *                          valid values: "bool", "float", "int", "key", "url", "string", or "arrayOf|*"
701
-     *                          where * is any of the other valid values ex: "arrayOf|int", "arrayOf|string"
702
-     * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator
703
-     *                          (default: ",")
704
-     * @return array|string
705
-     * @since $VID:$
706
-     */
707
-    public function sanitizeRequestParam($param, $type = 'string', $delimiter = ',')
708
-    {
709
-        switch ($type) {
710
-            case 'bool':
711
-                return filter_var($param, FILTER_VALIDATE_BOOLEAN);
712
-            case 'float':
713
-                return (float) $param;
714
-            case 'int':
715
-                return (int) $param;
716
-            case 'key':
717
-                return sanitize_key($param);
718
-            case 'url':
719
-                return esc_url_raw($param);
720
-            case 'string':
721
-                return sanitize_text_field($param);
722
-            default:
723
-                if (strpos($type, 'arrayOf|') === 0) {
724
-                    $values = [];
725
-                    $array_of_type = substr($type, 8);
726
-                    $list = is_string($param) ? explode($delimiter, $param) : (array) $param;
727
-                    foreach ($list as $item) {
728
-                        $values[] = $this->sanitizeRequestParam($item, $array_of_type, $delimiter);
729
-                    }
730
-                    return $values;
731
-                }
732
-                return sanitize_text_field($param);
733
-        }
734
-    }
20
+	/**
21
+	 * $_GET parameters
22
+	 *
23
+	 * @var array $get
24
+	 */
25
+	protected $get;
26
+
27
+	/**
28
+	 * $_POST parameters
29
+	 *
30
+	 * @var array $post
31
+	 */
32
+	protected $post;
33
+
34
+	/**
35
+	 * $_COOKIE parameters
36
+	 *
37
+	 * @var array $cookie
38
+	 */
39
+	protected $cookie;
40
+
41
+	/**
42
+	 * $_SERVER parameters
43
+	 *
44
+	 * @var array $server
45
+	 */
46
+	protected $server;
47
+
48
+	/**
49
+	 * $_FILES parameters
50
+	 *
51
+	 * @var array $files
52
+	 */
53
+	protected $files;
54
+
55
+	/**
56
+	 * $_REQUEST parameters
57
+	 *
58
+	 * @var array $request
59
+	 */
60
+	protected $request;
61
+
62
+	/**
63
+	 * @var RequestTypeContextCheckerInterface
64
+	 */
65
+	protected $request_type;
66
+
67
+	/**
68
+	 * IP address for request
69
+	 *
70
+	 * @var string $ip_address
71
+	 */
72
+	protected $ip_address;
73
+
74
+	/**
75
+	 * @var string $user_agent
76
+	 */
77
+	protected $user_agent;
78
+
79
+	/**
80
+	 * true if current user appears to be some kind of bot
81
+	 *
82
+	 * @var bool $is_bot
83
+	 */
84
+	protected $is_bot;
85
+
86
+
87
+	/**
88
+	 * @param array $get
89
+	 * @param array $post
90
+	 * @param array $cookie
91
+	 * @param array $server
92
+	 * @param array $files
93
+	 */
94
+	public function __construct(array $get, array $post, array $cookie, array $server, array $files = [])
95
+	{
96
+		// grab request vars
97
+		$this->get        = $get;
98
+		$this->post       = $post;
99
+		$this->cookie     = $cookie;
100
+		$this->server     = $server;
101
+		$this->files      = $files;
102
+		$this->request    = array_merge($this->get, $this->post);
103
+		$this->ip_address = $this->visitorIp();
104
+	}
105
+
106
+
107
+	/**
108
+	 * @param RequestTypeContextCheckerInterface $type
109
+	 */
110
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
+	{
112
+		$this->request_type = $type;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return array
118
+	 */
119
+	public function getParams()
120
+	{
121
+		return $this->get;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return array
127
+	 */
128
+	public function postParams()
129
+	{
130
+		return $this->post;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return array
136
+	 */
137
+	public function cookieParams()
138
+	{
139
+		return $this->cookie;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @return array
145
+	 */
146
+	public function serverParams()
147
+	{
148
+		return $this->server;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @return array
154
+	 */
155
+	public function filesParams()
156
+	{
157
+		return $this->files;
158
+	}
159
+
160
+
161
+	/**
162
+	 * returns contents of $_REQUEST
163
+	 *
164
+	 * @return array
165
+	 */
166
+	public function requestParams()
167
+	{
168
+		return $this->request;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param string     $key
174
+	 * @param mixed|null $value
175
+	 * @param bool       $override_ee
176
+	 * @return    void
177
+	 */
178
+	public function setRequestParam($key, $value, $override_ee = false)
179
+	{
180
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
181
+		if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
182
+			$this->request[ $key ] = $value;
183
+		}
184
+	}
185
+
186
+
187
+	/**
188
+	 * returns   the value for a request param if the given key exists
189
+	 *
190
+	 * @param string     $key
191
+	 * @param mixed|null $default
192
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
193
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
194
+	 * @return mixed
195
+	 */
196
+	public function getRequestParam($key, $default = null, $type = 'string', $delimiter = ',')
197
+	{
198
+		return $this->sanitizeRequestParam(
199
+			$this->requestParameterDrillDown($key, $default, 'get'),
200
+			$type
201
+		);
202
+	}
203
+
204
+
205
+	/**
206
+	 * check if param exists
207
+	 *
208
+	 * @param string $key
209
+	 * @return bool
210
+	 */
211
+	public function requestParamIsSet($key)
212
+	{
213
+		return (bool) $this->requestParameterDrillDown($key);
214
+	}
215
+
216
+
217
+	/**
218
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
219
+	 * and return the value for the first match found
220
+	 * wildcards can be either of the following:
221
+	 *      ? to represent a single character of any type
222
+	 *      * to represent one or more characters of any type
223
+	 *
224
+	 * @param string     $pattern
225
+	 * @param mixed|null $default
226
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
227
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
228
+	 * @return mixed
229
+	 */
230
+	public function getMatch($pattern, $default = null, $type = 'string', $delimiter = ',')
231
+	{
232
+		return $this->sanitizeRequestParam(
233
+			$this->requestParameterDrillDown($pattern, $default, 'match'),
234
+			$type
235
+		);
236
+	}
237
+
238
+
239
+	/**
240
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
241
+	 * wildcards can be either of the following:
242
+	 *      ? to represent a single character of any type
243
+	 *      * to represent one or more characters of any type
244
+	 * returns true if a match is found or false if not
245
+	 *
246
+	 * @param string $pattern
247
+	 * @return bool
248
+	 */
249
+	public function matches($pattern)
250
+	{
251
+		return (bool) $this->requestParameterDrillDown($pattern, false, 'match', 'bool');
252
+	}
253
+
254
+
255
+	/**
256
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
257
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
258
+	 *                                      and used to search through the current request's parameter keys
259
+	 * @param array  $request_params        The array of request parameters to search through
260
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
261
+	 *                                      Default is null
262
+	 * @param string $return                [optional] Controls what kind of value is returned.
263
+	 *                                      Options are:
264
+	 *                                      'bool' will return true or false if match is found or not
265
+	 *                                      'key' will return the first key found that matches the supplied pattern
266
+	 *                                      'value' will return the value for the first request parameter
267
+	 *                                      whose key matches the supplied pattern
268
+	 *                                      Default is 'value'
269
+	 * @return boolean|string
270
+	 */
271
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
272
+	{
273
+		$return = in_array($return, ['bool', 'key', 'value'], true)
274
+			? $return
275
+			: 'is_set';
276
+		// replace wildcard chars with regex chars
277
+		$pattern = str_replace(
278
+			["\*", "\?"],
279
+			['.*', '.'],
280
+			preg_quote($pattern, '/')
281
+		);
282
+		foreach ($request_params as $key => $request_param) {
283
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
284
+				// return value for request param
285
+				if ($return === 'value') {
286
+					return $request_param;
287
+				}
288
+				// or actual key or true just to indicate it was found
289
+				return $return === 'key' ? $key : true;
290
+			}
291
+		}
292
+		// match not found so return default value or false
293
+		return $return === 'value' ? $default : false;
294
+	}
295
+
296
+
297
+	/**
298
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
299
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
300
+	 * by using square brackets to surround keys for deeper array elements.
301
+	 * For example :
302
+	 * if the supplied $key was: "first[second][third]"
303
+	 * then this will attempt to drill down into the request parameter array to find a value.
304
+	 * Given the following request parameters:
305
+	 *  array(
306
+	 *      'first' => array(
307
+	 *          'second' => array(
308
+	 *              'third' => 'has a value'
309
+	 *          )
310
+	 *      )
311
+	 *  )
312
+	 * would return true if default parameters were set
313
+	 *
314
+	 * @param string $callback
315
+	 * @param        $key
316
+	 * @param null   $default
317
+	 * @param string $return
318
+	 * @param array  $request_params
319
+	 * @return bool|mixed|null
320
+	 */
321
+	private function requestParameterDrillDown(
322
+		$key,
323
+		$default = null,
324
+		$callback = 'is_set',
325
+		$return = 'value',
326
+		array $request_params = []
327
+	) {
328
+		$callback       = in_array($callback, ['is_set', 'get', 'match'], true)
329
+			? $callback
330
+			: 'is_set';
331
+		$request_params = ! empty($request_params)
332
+			? $request_params
333
+			: $this->request;
334
+		// does incoming key represent an array like 'first[second][third]'  ?
335
+		if (strpos($key, '[') !== false) {
336
+			// turn it into an actual array
337
+			$key  = str_replace(']', '', $key);
338
+			$keys = explode('[', $key);
339
+			$key  = array_shift($keys);
340
+			if ($callback === 'match') {
341
+				$real_key = $this->match($key, $request_params, $default, 'key');
342
+				$key      = $real_key ?: $key;
343
+			}
344
+			// check if top level key exists
345
+			if (isset($request_params[ $key ])) {
346
+				// build a new key to pass along like: 'second[third]'
347
+				// or just 'second' depending on depth of keys
348
+				$key_string = array_shift($keys);
349
+				if (! empty($keys)) {
350
+					$key_string .= '[' . implode('][', $keys) . ']';
351
+				}
352
+				return $this->requestParameterDrillDown(
353
+					$key_string,
354
+					$default,
355
+					$callback,
356
+					$return,
357
+					$request_params[ $key ]
358
+				);
359
+			}
360
+		}
361
+		if ($callback === 'is_set') {
362
+			return isset($request_params[ $key ]);
363
+		}
364
+		if ($callback === 'match') {
365
+			return $this->match($key, $request_params, $default, $return);
366
+		}
367
+		return isset($request_params[ $key ])
368
+			? $request_params[ $key ]
369
+			: $default;
370
+	}
371
+
372
+
373
+	/**
374
+	 * remove param
375
+	 *
376
+	 * @param      $key
377
+	 * @param bool $unset_from_global_too
378
+	 */
379
+	public function unSetRequestParam($key, $unset_from_global_too = false)
380
+	{
381
+		// because unset may not actually remove var
382
+		$this->request[ $key ] = null;
383
+		unset($this->request[ $key ]);
384
+		if ($unset_from_global_too) {
385
+			unset($_REQUEST[ $key ]);
386
+		}
387
+	}
388
+
389
+
390
+	/**
391
+	 * remove params
392
+	 *
393
+	 * @param array $keys
394
+	 * @param bool  $unset_from_global_too
395
+	 */
396
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
397
+	{
398
+		foreach ($keys as $key) {
399
+			$this->unSetRequestParam($key, $unset_from_global_too);
400
+		}
401
+	}
402
+
403
+
404
+	/**
405
+	 * @return string
406
+	 */
407
+	public function ipAddress()
408
+	{
409
+		return $this->ip_address;
410
+	}
411
+
412
+
413
+	/**
414
+	 * attempt to get IP address of current visitor from server
415
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
416
+	 *
417
+	 * @access public
418
+	 * @return string
419
+	 */
420
+	private function visitorIp()
421
+	{
422
+		$visitor_ip  = '0.0.0.0';
423
+		$server_keys = [
424
+			'HTTP_CLIENT_IP',
425
+			'HTTP_X_FORWARDED_FOR',
426
+			'HTTP_X_FORWARDED',
427
+			'HTTP_X_CLUSTER_CLIENT_IP',
428
+			'HTTP_FORWARDED_FOR',
429
+			'HTTP_FORWARDED',
430
+			'REMOTE_ADDR',
431
+		];
432
+		foreach ($server_keys as $key) {
433
+			if (isset($this->server[ $key ])) {
434
+				foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
435
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
436
+						$visitor_ip = $ip;
437
+					}
438
+				}
439
+			}
440
+		}
441
+		return $visitor_ip;
442
+	}
443
+
444
+
445
+	/**
446
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
447
+	 *
448
+	 * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
449
+	 *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
450
+	 *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
451
+	 * @return string
452
+	 */
453
+	public function requestUri($relativeToWpRoot = false)
454
+	{
455
+		$request_uri = filter_input(
456
+			INPUT_SERVER,
457
+			'REQUEST_URI',
458
+			FILTER_SANITIZE_URL,
459
+			FILTER_NULL_ON_FAILURE
460
+		);
461
+		if (empty($request_uri) && isset($this->server['REQUEST_URI'])) {
462
+			// fallback sanitization if the above fails
463
+			$request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
464
+		}
465
+		if ($relativeToWpRoot) {
466
+			$home_path   = untrailingslashit(
467
+				parse_url(
468
+					home_url(),
469
+					PHP_URL_PATH
470
+				)
471
+			);
472
+			$request_uri = str_replace(
473
+				$home_path,
474
+				'',
475
+				$request_uri
476
+			);
477
+		}
478
+		return $request_uri;
479
+	}
480
+
481
+
482
+	/**
483
+	 * @return string
484
+	 */
485
+	public function userAgent()
486
+	{
487
+		return $this->user_agent;
488
+	}
489
+
490
+
491
+	/**
492
+	 * @param string $user_agent
493
+	 */
494
+	public function setUserAgent($user_agent = '')
495
+	{
496
+		if ($user_agent === '' || ! is_string($user_agent)) {
497
+			$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
498
+		}
499
+		$this->user_agent = $user_agent;
500
+	}
501
+
502
+
503
+	/**
504
+	 * @return bool
505
+	 */
506
+	public function isBot()
507
+	{
508
+		return $this->is_bot;
509
+	}
510
+
511
+
512
+	/**
513
+	 * @param bool $is_bot
514
+	 */
515
+	public function setIsBot($is_bot)
516
+	{
517
+		$this->is_bot = $this->sanitizeRequestParam($is_bot, 'bool');
518
+	}
519
+
520
+
521
+	/**
522
+	 * @return bool
523
+	 */
524
+	public function isActivation()
525
+	{
526
+		return $this->request_type->isActivation();
527
+	}
528
+
529
+
530
+	/**
531
+	 * @param $is_activation
532
+	 * @return bool
533
+	 */
534
+	public function setIsActivation($is_activation)
535
+	{
536
+		return $this->request_type->setIsActivation($is_activation);
537
+	}
538
+
539
+
540
+	/**
541
+	 * @return bool
542
+	 */
543
+	public function isAdmin()
544
+	{
545
+		return $this->request_type->isAdmin();
546
+	}
547
+
548
+
549
+	/**
550
+	 * @return bool
551
+	 */
552
+	public function isAdminAjax()
553
+	{
554
+		return $this->request_type->isAdminAjax();
555
+	}
556
+
557
+
558
+	/**
559
+	 * @return bool
560
+	 */
561
+	public function isAjax()
562
+	{
563
+		return $this->request_type->isAjax();
564
+	}
565
+
566
+
567
+	/**
568
+	 * @return bool
569
+	 */
570
+	public function isEeAjax()
571
+	{
572
+		return $this->request_type->isEeAjax();
573
+	}
574
+
575
+
576
+	/**
577
+	 * @return bool
578
+	 */
579
+	public function isOtherAjax()
580
+	{
581
+		return $this->request_type->isOtherAjax();
582
+	}
583
+
584
+
585
+	/**
586
+	 * @return bool
587
+	 */
588
+	public function isApi()
589
+	{
590
+		return $this->request_type->isApi();
591
+	}
592
+
593
+
594
+	/**
595
+	 * @return bool
596
+	 */
597
+	public function isCli()
598
+	{
599
+		return $this->request_type->isCli();
600
+	}
601
+
602
+
603
+	/**
604
+	 * @return bool
605
+	 */
606
+	public function isCron()
607
+	{
608
+		return $this->request_type->isCron();
609
+	}
610
+
611
+
612
+	/**
613
+	 * @return bool
614
+	 */
615
+	public function isFeed()
616
+	{
617
+		return $this->request_type->isFeed();
618
+	}
619
+
620
+
621
+	/**
622
+	 * @return bool
623
+	 */
624
+	public function isFrontend()
625
+	{
626
+		return $this->request_type->isFrontend();
627
+	}
628
+
629
+
630
+	/**
631
+	 * @return bool
632
+	 */
633
+	public function isFrontAjax()
634
+	{
635
+		return $this->request_type->isFrontAjax();
636
+	}
637
+
638
+
639
+	/**
640
+	 * @return bool
641
+	 */
642
+	public function isIframe()
643
+	{
644
+		return $this->request_type->isIframe();
645
+	}
646
+
647
+
648
+	/**
649
+	 * @return bool
650
+	 */
651
+	public function isWordPressApi()
652
+	{
653
+		return $this->request_type->isWordPressApi();
654
+	}
655
+
656
+
657
+	/**
658
+	 * @return bool
659
+	 */
660
+	public function isWordPressHeartbeat()
661
+	{
662
+		return $this->request_type->isWordPressHeartbeat();
663
+	}
664
+
665
+
666
+	/**
667
+	 * @return bool
668
+	 */
669
+	public function isWordPressScrape()
670
+	{
671
+		return $this->request_type->isWordPressScrape();
672
+	}
673
+
674
+
675
+	/**
676
+	 * @return string
677
+	 */
678
+	public function slug()
679
+	{
680
+		return $this->request_type->slug();
681
+	}
682
+
683
+
684
+	/**
685
+	 * @return RequestTypeContextCheckerInterface
686
+	 */
687
+	public function getRequestType()
688
+	{
689
+		return $this->request_type;
690
+	}
691
+
692
+
693
+
694
+
695
+	/**
696
+	 * Will sanitize the supplied request parameter based on the specified data type
697
+	 *
698
+	 * @param mixed  $param     the supplied request parameter
699
+	 * @param string $type      the specified data type (default: "string")
700
+	 *                          valid values: "bool", "float", "int", "key", "url", "string", or "arrayOf|*"
701
+	 *                          where * is any of the other valid values ex: "arrayOf|int", "arrayOf|string"
702
+	 * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator
703
+	 *                          (default: ",")
704
+	 * @return array|string
705
+	 * @since $VID:$
706
+	 */
707
+	public function sanitizeRequestParam($param, $type = 'string', $delimiter = ',')
708
+	{
709
+		switch ($type) {
710
+			case 'bool':
711
+				return filter_var($param, FILTER_VALIDATE_BOOLEAN);
712
+			case 'float':
713
+				return (float) $param;
714
+			case 'int':
715
+				return (int) $param;
716
+			case 'key':
717
+				return sanitize_key($param);
718
+			case 'url':
719
+				return esc_url_raw($param);
720
+			case 'string':
721
+				return sanitize_text_field($param);
722
+			default:
723
+				if (strpos($type, 'arrayOf|') === 0) {
724
+					$values = [];
725
+					$array_of_type = substr($type, 8);
726
+					$list = is_string($param) ? explode($delimiter, $param) : (array) $param;
727
+					foreach ($list as $item) {
728
+						$values[] = $this->sanitizeRequestParam($item, $array_of_type, $delimiter);
729
+					}
730
+					return $values;
731
+				}
732
+				return sanitize_text_field($param);
733
+		}
734
+	}
735 735
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
     {
180 180
         // don't allow "ee" to be overwritten unless explicitly instructed to do so
181 181
         if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
182
-            $this->request[ $key ] = $value;
182
+            $this->request[$key] = $value;
183 183
         }
184 184
     }
185 185
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
             preg_quote($pattern, '/')
281 281
         );
282 282
         foreach ($request_params as $key => $request_param) {
283
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
283
+            if (preg_match('/^'.$pattern.'$/is', $key)) {
284 284
                 // return value for request param
285 285
                 if ($return === 'value') {
286 286
                     return $request_param;
@@ -342,30 +342,30 @@  discard block
 block discarded – undo
342 342
                 $key      = $real_key ?: $key;
343 343
             }
344 344
             // check if top level key exists
345
-            if (isset($request_params[ $key ])) {
345
+            if (isset($request_params[$key])) {
346 346
                 // build a new key to pass along like: 'second[third]'
347 347
                 // or just 'second' depending on depth of keys
348 348
                 $key_string = array_shift($keys);
349
-                if (! empty($keys)) {
350
-                    $key_string .= '[' . implode('][', $keys) . ']';
349
+                if ( ! empty($keys)) {
350
+                    $key_string .= '['.implode('][', $keys).']';
351 351
                 }
352 352
                 return $this->requestParameterDrillDown(
353 353
                     $key_string,
354 354
                     $default,
355 355
                     $callback,
356 356
                     $return,
357
-                    $request_params[ $key ]
357
+                    $request_params[$key]
358 358
                 );
359 359
             }
360 360
         }
361 361
         if ($callback === 'is_set') {
362
-            return isset($request_params[ $key ]);
362
+            return isset($request_params[$key]);
363 363
         }
364 364
         if ($callback === 'match') {
365 365
             return $this->match($key, $request_params, $default, $return);
366 366
         }
367
-        return isset($request_params[ $key ])
368
-            ? $request_params[ $key ]
367
+        return isset($request_params[$key])
368
+            ? $request_params[$key]
369 369
             : $default;
370 370
     }
371 371
 
@@ -379,10 +379,10 @@  discard block
 block discarded – undo
379 379
     public function unSetRequestParam($key, $unset_from_global_too = false)
380 380
     {
381 381
         // because unset may not actually remove var
382
-        $this->request[ $key ] = null;
383
-        unset($this->request[ $key ]);
382
+        $this->request[$key] = null;
383
+        unset($this->request[$key]);
384 384
         if ($unset_from_global_too) {
385
-            unset($_REQUEST[ $key ]);
385
+            unset($_REQUEST[$key]);
386 386
         }
387 387
     }
388 388
 
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
             'REMOTE_ADDR',
431 431
         ];
432 432
         foreach ($server_keys as $key) {
433
-            if (isset($this->server[ $key ])) {
434
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
433
+            if (isset($this->server[$key])) {
434
+                foreach (array_map('trim', explode(',', $this->server[$key])) as $ip) {
435 435
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
436 436
                         $visitor_ip = $ip;
437 437
                     }
Please login to merge, or discard this patch.
core/services/request/Response.php 2 patches
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@
 block discarded – undo
15 15
 class Response implements ResponseInterface, ReservedInstanceInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @var array $notice
20
-     */
21
-    protected $notice = [];
22
-
23
-    /**
24
-     * rendered output to be returned to WP
25
-     *
26
-     * @var array
27
-     */
28
-    protected $output = [];
29
-
30
-    /**
31
-     * @var bool
32
-     */
33
-    protected $request_terminated = false;
34
-
35
-    /**
36
-     * @var bool $deactivate_plugin
37
-     */
38
-    protected $deactivate_plugin = false;
39
-
40
-
41
-    /**
42
-     * EE_Response constructor.
43
-     */
44
-    public function __construct()
45
-    {
46
-        $this->terminateRequest(false);
47
-    }
48
-
49
-
50
-    /**
51
-     * @param $key
52
-     * @param $value
53
-     * @return    void
54
-     */
55
-    public function setNotice($key, $value)
56
-    {
57
-        $this->notice[ $key ] = $value;
58
-    }
59
-
60
-
61
-    /**
62
-     * @param $key
63
-     * @return    mixed
64
-     */
65
-    public function getNotice($key)
66
-    {
67
-        return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return array
73
-     */
74
-    public function getNotices()
75
-    {
76
-        return $this->notice;
77
-    }
78
-
79
-
80
-    /**
81
-     * @param string $string
82
-     * @param bool   $append
83
-     */
84
-    public function addOutput($string, $append = true)
85
-    {
86
-        if ($append) {
87
-            $this->output[] = $string;
88
-            return;
89
-        }
90
-        array_unshift($this->output, $string);
91
-    }
92
-
93
-
94
-    /**
95
-     * @param bool   $as_string
96
-     * @param string $separator
97
-     * @return array|string
98
-     */
99
-    public function getOutput($as_string = true, $separator = PHP_EOL)
100
-    {
101
-        return $as_string ? implode($separator, $this->output) : $this->output ;
102
-    }
103
-
104
-
105
-    /**
106
-     * @return boolean
107
-     */
108
-    public function requestTerminated()
109
-    {
110
-        return $this->request_terminated;
111
-    }
112
-
113
-
114
-    /**
115
-     * @param boolean $request_terminated
116
-     */
117
-    public function terminateRequest($request_terminated = true)
118
-    {
119
-        $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
120
-    }
121
-
122
-
123
-    /**
124
-     * @return boolean
125
-     */
126
-    public function pluginDeactivated()
127
-    {
128
-        return $this->deactivate_plugin;
129
-    }
130
-
131
-
132
-    /**
133
-     * sets $deactivate_plugin to true
134
-     */
135
-    public function deactivatePlugin()
136
-    {
137
-        $this->deactivate_plugin = true;
138
-    }
18
+	/**
19
+	 * @var array $notice
20
+	 */
21
+	protected $notice = [];
22
+
23
+	/**
24
+	 * rendered output to be returned to WP
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected $output = [];
29
+
30
+	/**
31
+	 * @var bool
32
+	 */
33
+	protected $request_terminated = false;
34
+
35
+	/**
36
+	 * @var bool $deactivate_plugin
37
+	 */
38
+	protected $deactivate_plugin = false;
39
+
40
+
41
+	/**
42
+	 * EE_Response constructor.
43
+	 */
44
+	public function __construct()
45
+	{
46
+		$this->terminateRequest(false);
47
+	}
48
+
49
+
50
+	/**
51
+	 * @param $key
52
+	 * @param $value
53
+	 * @return    void
54
+	 */
55
+	public function setNotice($key, $value)
56
+	{
57
+		$this->notice[ $key ] = $value;
58
+	}
59
+
60
+
61
+	/**
62
+	 * @param $key
63
+	 * @return    mixed
64
+	 */
65
+	public function getNotice($key)
66
+	{
67
+		return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return array
73
+	 */
74
+	public function getNotices()
75
+	{
76
+		return $this->notice;
77
+	}
78
+
79
+
80
+	/**
81
+	 * @param string $string
82
+	 * @param bool   $append
83
+	 */
84
+	public function addOutput($string, $append = true)
85
+	{
86
+		if ($append) {
87
+			$this->output[] = $string;
88
+			return;
89
+		}
90
+		array_unshift($this->output, $string);
91
+	}
92
+
93
+
94
+	/**
95
+	 * @param bool   $as_string
96
+	 * @param string $separator
97
+	 * @return array|string
98
+	 */
99
+	public function getOutput($as_string = true, $separator = PHP_EOL)
100
+	{
101
+		return $as_string ? implode($separator, $this->output) : $this->output ;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @return boolean
107
+	 */
108
+	public function requestTerminated()
109
+	{
110
+		return $this->request_terminated;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @param boolean $request_terminated
116
+	 */
117
+	public function terminateRequest($request_terminated = true)
118
+	{
119
+		$this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
120
+	}
121
+
122
+
123
+	/**
124
+	 * @return boolean
125
+	 */
126
+	public function pluginDeactivated()
127
+	{
128
+		return $this->deactivate_plugin;
129
+	}
130
+
131
+
132
+	/**
133
+	 * sets $deactivate_plugin to true
134
+	 */
135
+	public function deactivatePlugin()
136
+	{
137
+		$this->deactivate_plugin = true;
138
+	}
139 139
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function setNotice($key, $value)
56 56
     {
57
-        $this->notice[ $key ] = $value;
57
+        $this->notice[$key] = $value;
58 58
     }
59 59
 
60 60
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function getNotice($key)
66 66
     {
67
-        return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
67
+        return isset($this->notice[$key]) ? $this->notice[$key] : null;
68 68
     }
69 69
 
70 70
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function getOutput($as_string = true, $separator = PHP_EOL)
100 100
     {
101
-        return $as_string ? implode($separator, $this->output) : $this->output ;
101
+        return $as_string ? implode($separator, $this->output) : $this->output;
102 102
     }
103 103
 
104 104
 
Please login to merge, or discard this patch.