Completed
Branch master (8de7dd)
by
unknown
06:29
created
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +4106 added lines, -4106 removed lines patch added patch discarded remove patch
@@ -19,2522 +19,2522 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class Messages_Admin_Page extends EE_Admin_Page
21 21
 {
22
-    private ?EEM_Message $MSG_MODEL                 = null;
22
+	private ?EEM_Message $MSG_MODEL                 = null;
23 23
 
24
-    private ?EEM_Message_Template $MTP_MODEL                 = null;
24
+	private ?EEM_Message_Template $MTP_MODEL                 = null;
25 25
 
26
-    private ?EEM_Message_Template_Group $MTG_MODEL                 = null;
26
+	private ?EEM_Message_Template_Group $MTG_MODEL                 = null;
27 27
 
28
-    protected ?EE_Message_Resource_Manager $_message_resource_manager = null;
28
+	protected ?EE_Message_Resource_Manager $_message_resource_manager = null;
29 29
 
30
-    protected ?EE_Message_Template_Group $_message_template_group   = null;
30
+	protected ?EE_Message_Template_Group $_message_template_group   = null;
31 31
 
32
-    protected ?EE_messenger $_active_messenger         = null;
32
+	protected ?EE_messenger $_active_messenger         = null;
33 33
 
34
-    protected ?MessageTemplateManager $message_template_manager  = null;
34
+	protected ?MessageTemplateManager $message_template_manager  = null;
35 35
 
36 36
 
37
-    /**
38
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
39
-     * IF there is no group then it gets automatically set to the Default template pack.
40
-     *
41
-     * @since 4.5.0
42
-     */
43
-    protected ?EE_Messages_Template_Pack $_template_pack            = null;
37
+	/**
38
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
39
+	 * IF there is no group then it gets automatically set to the Default template pack.
40
+	 *
41
+	 * @since 4.5.0
42
+	 */
43
+	protected ?EE_Messages_Template_Pack $_template_pack            = null;
44 44
 
45
-    protected array $_active_messengers        = [];
46
-
47
-    protected array $_active_message_types     = [];
45
+	protected array $_active_messengers        = [];
46
+
47
+	protected array $_active_message_types     = [];
48 48
 
49
-    protected array $_shortcodes               = [];
50
-
51
-    protected array $_m_mt_settings            = [];
49
+	protected array $_shortcodes               = [];
50
+
51
+	protected array $_m_mt_settings            = [];
52 52
 
53
-    protected string $_active_message_type_name = '';
53
+	protected string $_active_message_type_name = '';
54 54
 
55
-    protected string $_active_messenger_name    = '';
56
-
57
-    protected string $_context_switcher         = '';
55
+	protected string $_active_messenger_name    = '';
56
+
57
+	protected string $_context_switcher         = '';
58 58
 
59 59
 
60
-    /**
61
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
62
-     * group is.  If there is no group then it automatically gets set to default.
63
-     *
64
-     * @since 4.5.0
65
-     */
66
-    protected string $_variation = '';
67
-
68
-
69
-    /**
70
-     * @param bool $routing
71
-     * @throws EE_Error
72
-     * @throws ReflectionException
73
-     */
74
-    public function __construct($routing = true)
75
-    {
76
-        // make sure messages autoloader is running
77
-        EED_Messages::set_autoloaders();
78
-        parent::__construct($routing);
79
-    }
80
-
81
-
82
-    /**
83
-     * @return EEM_Message
84
-     * @throws EE_Error
85
-     * @throws ReflectionException
86
-     */
87
-    public function getMsgModel(): EEM_Message
88
-    {
89
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
90
-            $this->MSG_MODEL = EEM_Message::instance();
91
-        }
92
-        return $this->MSG_MODEL;
93
-    }
94
-
95
-
96
-    /**
97
-     * @return EEM_Message_Template
98
-     * @throws EE_Error
99
-     * @throws ReflectionException
100
-     */
101
-    public function getMtpModel(): EEM_Message_Template
102
-    {
103
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
104
-            $this->MTP_MODEL = EEM_Message_Template::instance();
105
-        }
106
-        return $this->MTP_MODEL;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return EEM_Message_Template_Group
112
-     * @throws EE_Error
113
-     * @throws ReflectionException
114
-     */
115
-    public function getMtgModel(): EEM_Message_Template_Group
116
-    {
117
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
118
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
119
-        }
120
-        return $this->MTG_MODEL;
121
-    }
122
-
123
-
124
-    public function getMessageTemplateManager(): MessageTemplateManager
125
-    {
126
-        if (! $this->message_template_manager instanceof MessageTemplateManager) {
127
-            $this->message_template_manager = $this->loader->getShared(MessageTemplateManager::class);
128
-        }
129
-        return $this->message_template_manager;
130
-    }
131
-
132
-
133
-    /**
134
-     * @throws EE_Error
135
-     * @throws ReflectionException
136
-     */
137
-    protected function _init_page_props()
138
-    {
139
-        $this->page_slug        = EE_MSG_PG_SLUG;
140
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
141
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
142
-        $this->_admin_base_path = EE_MSG_ADMIN;
143
-
144
-        $messenger                       = $this->request->getRequestParam('messenger', '');
145
-        $message_type                    = $this->request->getRequestParam('message_type', '');
146
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
147
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
148
-
149
-        $this->_load_message_resource_manager();
150
-    }
151
-
152
-
153
-    protected function _load_message_resource_manager()
154
-    {
155
-        if (! $this->_message_resource_manager instanceof EE_Message_Resource_Manager) {
156
-            $this->_message_resource_manager = $this->loader->getShared(EE_Message_Resource_Manager::class);
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * Generate select input with provided messenger options array.
163
-     *
164
-     * @param array $messenger_options Array of messengers indexed by slug and values are the messenger labels.
165
-     * @return string
166
-     * @throws EE_Error
167
-     */
168
-    public function get_messengers_select_input($messenger_options)
169
-    {
170
-        // if empty or just one value then just return an empty string
171
-        if (
172
-            empty($messenger_options)
173
-            || ! is_array($messenger_options)
174
-            || count($messenger_options) === 1
175
-        ) {
176
-            return '';
177
-        }
178
-        // merge in default
179
-        $messenger_options = array_merge(
180
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
181
-            $messenger_options
182
-        );
183
-        $input             = new EE_Select_Input(
184
-            $messenger_options,
185
-            [
186
-                'html_name'  => 'ee_messenger_filter_by',
187
-                'html_id'    => 'ee_messenger_filter_by',
188
-                'html_class' => 'wide',
189
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
190
-            ]
191
-        );
192
-
193
-        return $input->get_html_for_input();
194
-    }
195
-
196
-
197
-    /**
198
-     * Generate select input with provided message type options array.
199
-     *
200
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
201
-     *                                    message type labels
202
-     * @return string
203
-     * @throws EE_Error
204
-     */
205
-    public function get_message_types_select_input($message_type_options)
206
-    {
207
-        // if empty or count of options is 1 then just return an empty string
208
-        if (
209
-            empty($message_type_options)
210
-            || ! is_array($message_type_options)
211
-            || count($message_type_options) === 1
212
-        ) {
213
-            return '';
214
-        }
215
-        // merge in default
216
-        $message_type_options = array_merge(
217
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
218
-            $message_type_options
219
-        );
220
-        $input                = new EE_Select_Input(
221
-            $message_type_options,
222
-            [
223
-                'html_name'  => 'ee_message_type_filter_by',
224
-                'html_id'    => 'ee_message_type_filter_by',
225
-                'html_class' => 'wide',
226
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
227
-            ]
228
-        );
229
-
230
-        return $input->get_html_for_input();
231
-    }
232
-
233
-
234
-    /**
235
-     * Generate select input with provide message type contexts array.
236
-     *
237
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
238
-     *                               context label.
239
-     * @return string
240
-     * @throws EE_Error
241
-     */
242
-    public function get_contexts_for_message_types_select_input($context_options)
243
-    {
244
-        // if empty or count of options is one then just return empty string
245
-        if (
246
-            empty($context_options)
247
-            || ! is_array($context_options)
248
-            || count($context_options) === 1
249
-        ) {
250
-            return '';
251
-        }
252
-        // merge in default
253
-        $context_options = array_merge(
254
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
255
-            $context_options
256
-        );
257
-        $input           = new EE_Select_Input(
258
-            $context_options,
259
-            [
260
-                'html_name'  => 'ee_context_filter_by',
261
-                'html_id'    => 'ee_context_filter_by',
262
-                'html_class' => 'wide',
263
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
264
-            ]
265
-        );
266
-
267
-        return $input->get_html_for_input();
268
-    }
269
-
270
-
271
-    protected function _ajax_hooks()
272
-    {
273
-        if (! $this->capabilities->current_user_can('ee_edit_messages', 'edit-message-settings')) {
274
-            return;
275
-        }
276
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
277
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
278
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
279
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
280
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
281
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
282
-    }
283
-
284
-
285
-    protected function _define_page_props()
286
-    {
287
-        $this->_admin_page_title = $this->page_label;
288
-        $this->_labels           = [
289
-            'buttons'    => [
290
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
291
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
292
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
293
-            ],
294
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
295
-        ];
296
-    }
297
-
298
-
299
-    /**
300
-     *        an array for storing key => value pairs of request actions and their corresponding methods
301
-     *
302
-     * @access protected
303
-     * @return void
304
-     */
305
-    protected function _set_page_routes()
306
-    {
307
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
308
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, DataType::INTEGER);
309
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, DataType::INTEGER);
310
-
311
-        $this->_page_routes = [
312
-            'default'                          => [
313
-                'func'       => [$this, '_message_queue_list_table'],
314
-                'capability' => 'ee_read_global_messages',
315
-            ],
316
-            'global_mtps'                      => [
317
-                'func'       => [$this, '_ee_default_messages_overview_list_table'],
318
-                'capability' => 'ee_read_global_messages',
319
-            ],
320
-            'custom_mtps'                      => [
321
-                'func'       => [$this, '_custom_mtps_preview'],
322
-                'capability' => 'ee_read_messages',
323
-            ],
324
-            'add_new_message_template'         => [
325
-                'func'       => [$this, 'insertMessageTemplate'],
326
-                'capability' => 'ee_edit_messages',
327
-                'noheader'   => true,
328
-            ],
329
-            'edit_message_template'            => [
330
-                'func'       => [$this, '_edit_message_template'],
331
-                'capability' => 'ee_edit_message',
332
-                'obj_id'     => $GRP_ID,
333
-            ],
334
-            'preview_message'                  => [
335
-                'func'               => [$this, '_preview_message'],
336
-                'capability'         => 'ee_read_message',
337
-                'obj_id'             => $GRP_ID,
338
-                'noheader'           => true,
339
-                'headers_sent_route' => 'display_preview_message',
340
-            ],
341
-            'display_preview_message'          => [
342
-                'func'       => [$this, '_display_preview_message'],
343
-                'capability' => 'ee_read_message',
344
-                'obj_id'     => $GRP_ID,
345
-            ],
346
-            'insert_message_template'          => [
347
-                'func'       => [$this, 'insertMessageTemplate'],
348
-                'capability' => 'ee_edit_messages',
349
-                'noheader'   => true,
350
-            ],
351
-            'update_message_template'          => [
352
-                'func'       => [$this, 'updateMessageTemplate'],
353
-                'capability' => 'ee_edit_message',
354
-                'obj_id'     => $GRP_ID,
355
-                'noheader'   => true,
356
-            ],
357
-            'trash_message_template'           => [
358
-                'func'       => [$this, '_trash_or_restore_message_template'],
359
-                'capability' => 'ee_delete_message',
360
-                'obj_id'     => $GRP_ID,
361
-                'args'       => ['trash' => true, 'all' => true],
362
-                'noheader'   => true,
363
-            ],
364
-            'trash_message_template_context'   => [
365
-                'func'       => [$this, '_trash_or_restore_message_template'],
366
-                'capability' => 'ee_delete_message',
367
-                'obj_id'     => $GRP_ID,
368
-                'args'       => ['trash' => true],
369
-                'noheader'   => true,
370
-            ],
371
-            'restore_message_template'         => [
372
-                'func'       => [$this, '_trash_or_restore_message_template'],
373
-                'capability' => 'ee_delete_message',
374
-                'obj_id'     => $GRP_ID,
375
-                'args'       => ['trash' => false, 'all' => true],
376
-                'noheader'   => true,
377
-            ],
378
-            'restore_message_template_context' => [
379
-                'func'       => [$this, '_trash_or_restore_message_template'],
380
-                'capability' => 'ee_delete_message',
381
-                'obj_id'     => $GRP_ID,
382
-                'args'       => ['trash' => false],
383
-                'noheader'   => true,
384
-            ],
385
-            'delete_message_template'          => [
386
-                'func'       => [$this, '_delete_message_template'],
387
-                'capability' => 'ee_delete_message',
388
-                'obj_id'     => $GRP_ID,
389
-                'noheader'   => true,
390
-            ],
391
-            'reset_to_default'                 => [
392
-                'func'       => [$this, '_reset_to_default_template'],
393
-                'capability' => 'ee_edit_message',
394
-                'obj_id'     => $GRP_ID,
395
-                'noheader'   => true,
396
-            ],
397
-            'settings'                         => [
398
-                'func'       => [$this, '_settings'],
399
-                'capability' => 'manage_options',
400
-            ],
401
-            'update_global_settings'           => [
402
-                'func'       => [$this, '_update_global_settings'],
403
-                'capability' => 'manage_options',
404
-                'noheader'   => true,
405
-            ],
406
-            'generate_now'                     => [
407
-                'func'       => [$this, '_generate_now'],
408
-                'capability' => 'ee_send_message',
409
-                'noheader'   => true,
410
-            ],
411
-            'generate_and_send_now'            => [
412
-                'func'       => [$this, '_generate_and_send_now'],
413
-                'capability' => 'ee_send_message',
414
-                'noheader'   => true,
415
-            ],
416
-            'queue_for_resending'              => [
417
-                'func'       => [$this, '_queue_for_resending'],
418
-                'capability' => 'ee_send_message',
419
-                'noheader'   => true,
420
-            ],
421
-            'send_now'                         => [
422
-                'func'       => [$this, '_send_now'],
423
-                'capability' => 'ee_send_message',
424
-                'noheader'   => true,
425
-            ],
426
-            'delete_ee_message'                => [
427
-                'func'       => [$this, '_delete_ee_messages'],
428
-                'capability' => 'ee_delete_messages',
429
-                'noheader'   => true,
430
-            ],
431
-            'delete_ee_messages'               => [
432
-                'func'       => [$this, '_delete_ee_messages'],
433
-                'capability' => 'ee_delete_messages',
434
-                'noheader'   => true,
435
-                'obj_id'     => $MSG_ID,
436
-            ],
437
-        ];
438
-    }
439
-
440
-
441
-    protected function _set_page_config()
442
-    {
443
-        $this->_page_config = [
444
-            'default'                  => [
445
-                'nav'           => [
446
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
447
-                    'icon'  => 'dashicons-email',
448
-                    'order' => 10,
449
-                ],
450
-                'list_table'    => 'EE_Message_List_Table',
451
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
452
-                'require_nonce' => false,
453
-            ],
454
-            'global_mtps'              => [
455
-                'nav'           => [
456
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
457
-                    'icon'  => 'dashicons-layout',
458
-                    'order' => 20,
459
-                ],
460
-                'list_table'    => 'Messages_Template_List_Table',
461
-                'help_tabs'     => [
462
-                    'messages_overview_help_tab'                                => [
463
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
464
-                        'filename' => 'messages_overview',
465
-                    ],
466
-                    'messages_overview_messages_table_column_headings_help_tab' => [
467
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
468
-                        'filename' => 'messages_overview_table_column_headings',
469
-                    ],
470
-                    'messages_overview_messages_filters_help_tab'               => [
471
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
472
-                        'filename' => 'messages_overview_filters',
473
-                    ],
474
-                    'messages_overview_messages_views_help_tab'                 => [
475
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
476
-                        'filename' => 'messages_overview_views',
477
-                    ],
478
-                    'message_overview_message_types_help_tab'                   => [
479
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
480
-                        'filename' => 'messages_overview_types',
481
-                    ],
482
-                    'messages_overview_messengers_help_tab'                     => [
483
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
484
-                        'filename' => 'messages_overview_messengers',
485
-                    ],
486
-                ],
487
-                'require_nonce' => false,
488
-            ],
489
-            'custom_mtps'              => [
490
-                'nav'           => [
491
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
492
-                    'icon'  => 'dashicons-admin-customizer',
493
-                    'order' => 30,
494
-                ],
495
-                'help_tabs'     => [],
496
-                'require_nonce' => false,
497
-            ],
498
-            'add_new_message_template' => [
499
-                'nav'           => [
500
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
501
-                    'icon'       => 'dashicons-plus-alt',
502
-                    'order'      => 5,
503
-                    'persistent' => false,
504
-                ],
505
-                'require_nonce' => false,
506
-            ],
507
-            'edit_message_template'    => [
508
-                'labels'        => [
509
-                    'buttons'    => [
510
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
511
-                    ],
512
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
513
-                ],
514
-                'nav'           => [
515
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
516
-                    'icon'       => 'dashicons-edit-large',
517
-                    'order'      => 5,
518
-                    'persistent' => false,
519
-                    'url'        => '',
520
-                ],
521
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
522
-                'has_metaboxes' => true,
523
-                'help_tabs'     => [
524
-                    'edit_message_template'            => [
525
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
526
-                        'callback' => 'edit_message_template_help_tab',
527
-                    ],
528
-                    'message_templates_help_tab'       => [
529
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
530
-                        'filename' => 'messages_templates',
531
-                    ],
532
-                    'message_template_shortcodes'      => [
533
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
534
-                        'callback' => 'message_template_shortcodes_help_tab',
535
-                    ],
536
-                    'message_preview_help_tab'         => [
537
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
538
-                        'filename' => 'messages_preview',
539
-                    ],
540
-                    'messages_overview_other_help_tab' => [
541
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
542
-                        'filename' => 'messages_overview_other',
543
-                    ],
544
-                ],
545
-                'require_nonce' => false,
546
-            ],
547
-            'display_preview_message'  => [
548
-                'nav'           => [
549
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
550
-                    'icon'       => 'dashicons-visibility-bar',
551
-                    'order'      => 5,
552
-                    'url'        => '',
553
-                    'persistent' => false,
554
-                ],
555
-                'help_tabs'     => [
556
-                    'preview_message' => [
557
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
558
-                        'callback' => 'preview_message_help_tab',
559
-                    ],
560
-                ],
561
-                'require_nonce' => false,
562
-            ],
563
-            'settings'                 => [
564
-                'nav'           => [
565
-                    'label' => esc_html__('Settings', 'event_espresso'),
566
-                    'icon'  => 'dashicons-admin-generic',
567
-                    'order' => 40,
568
-                ],
569
-                'metaboxes'     => ['_messages_settings_metaboxes'],
570
-                'help_tabs'     => [
571
-                    'messages_settings_help_tab'               => [
572
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
573
-                        'filename' => 'messages_settings',
574
-                    ],
575
-                    'messages_settings_message_types_help_tab' => [
576
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
577
-                        'filename' => 'messages_settings_message_types',
578
-                    ],
579
-                    'messages_settings_messengers_help_tab'    => [
580
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
581
-                        'filename' => 'messages_settings_messengers',
582
-                    ],
583
-                ],
584
-                'require_nonce' => false,
585
-            ],
586
-        ];
587
-    }
588
-
589
-
590
-    protected function _add_screen_options()
591
-    {
592
-        // todo
593
-    }
594
-
595
-
596
-    protected function _add_screen_options_global_mtps()
597
-    {
598
-        /**
599
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
600
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
601
-         */
602
-        $page_title              = $this->_admin_page_title;
603
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
604
-        $this->_per_page_screen_option();
605
-        $this->_admin_page_title = $page_title;
606
-    }
607
-
608
-
609
-    protected function _add_screen_options_default()
610
-    {
611
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
612
-        $this->_per_page_screen_option();
613
-    }
614
-
615
-
616
-    // none of the below group are currently used for Messages
617
-    protected function _add_feature_pointers()
618
-    {
619
-    }
620
-
621
-
622
-    public function admin_init()
623
-    {
624
-    }
625
-
626
-
627
-    public function admin_notices()
628
-    {
629
-    }
630
-
631
-
632
-    public function admin_footer_scripts()
633
-    {
634
-    }
635
-
636
-
637
-    public function messages_help_tab()
638
-    {
639
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
640
-    }
641
-
642
-
643
-    public function messengers_help_tab()
644
-    {
645
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
646
-    }
647
-
648
-
649
-    public function message_types_help_tab()
650
-    {
651
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
652
-    }
653
-
654
-
655
-    public function messages_overview_help_tab()
656
-    {
657
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
658
-    }
659
-
660
-
661
-    public function message_templates_help_tab()
662
-    {
663
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
664
-    }
665
-
666
-
667
-    public function edit_message_template_help_tab()
668
-    {
669
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
670
-                        . esc_attr__('Editor Title', 'event_espresso')
671
-                        . '" />';
672
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
673
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
674
-                        . '" />';
675
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
676
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
677
-                        . '" />';
678
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
679
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
680
-                        . '" />';
681
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
682
-                        . esc_attr__('Publish Metabox', 'event_espresso')
683
-                        . '" />';
684
-        EEH_Template::display_template(
685
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
686
-            $args
687
-        );
688
-    }
689
-
690
-
691
-    /**
692
-     * @throws ReflectionException
693
-     * @throws EE_Error
694
-     */
695
-    public function message_template_shortcodes_help_tab()
696
-    {
697
-        $this->_set_shortcodes();
698
-        $args['shortcodes'] = $this->_shortcodes;
699
-        EEH_Template::display_template(
700
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
701
-            $args
702
-        );
703
-    }
704
-
705
-
706
-    public function preview_message_help_tab()
707
-    {
708
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
709
-    }
710
-
711
-
712
-    public function settings_help_tab()
713
-    {
714
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
715
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
716
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
717
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
718
-        $args['img3'] = '<div class="ee-switch">'
719
-                        . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
720
-                        . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
721
-                        . '</div>';
722
-        $args['img4'] = '<div class="switch">'
723
-                        . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
724
-                        . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
725
-                        . '</div>';
726
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
727
-    }
728
-
729
-
730
-    public function load_scripts_styles()
731
-    {
732
-        wp_enqueue_style(
733
-            'espresso_ee_msg',
734
-            EE_MSG_ASSETS_URL . 'ee_message_admin.css',
735
-            [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
736
-            EVENT_ESPRESSO_VERSION
737
-        );
738
-        wp_enqueue_style(
739
-            'ee_message_shortcodes',
740
-            EE_MSG_ASSETS_URL . 'ee_message_shortcodes.css',
741
-            [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
742
-            EVENT_ESPRESSO_VERSION
743
-        );
744
-
745
-        wp_register_script(
746
-            'ee-messages-settings',
747
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
748
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
749
-            EVENT_ESPRESSO_VERSION,
750
-            true
751
-        );
752
-        wp_register_script(
753
-            'ee-msg-list-table-js',
754
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
755
-            ['ee-dialog'],
756
-            EVENT_ESPRESSO_VERSION
757
-        );
758
-    }
759
-
760
-
761
-    public function load_scripts_styles_default()
762
-    {
763
-        wp_enqueue_script('ee-msg-list-table-js');
764
-    }
765
-
766
-
767
-    public function wp_editor_css($mce_css)
768
-    {
769
-        // if we're on the edit_message_template route
770
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
771
-            $message_type_name = $this->_active_message_type_name;
772
-
773
-            // we're going to REPLACE the existing mce css
774
-            // we need to get the css file location from the active messenger
775
-            $mce_css = $this->_active_messenger->get_variation(
776
-                $this->_template_pack,
777
-                $message_type_name,
778
-                true,
779
-                'wpeditor',
780
-                $this->_variation
781
-            );
782
-        }
783
-
784
-        return $mce_css;
785
-    }
786
-
787
-
788
-    /**
789
-     * @throws EE_Error
790
-     * @throws ReflectionException
791
-     */
792
-    public function load_scripts_styles_edit_message_template()
793
-    {
794
-        $this->_set_shortcodes();
795
-
796
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
797
-            esc_html__(
798
-                '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.',
799
-                'event_espresso'
800
-            ),
801
-            $this->_message_template_group->messenger_obj()->label['singular'],
802
-            $this->_message_template_group->message_type_obj()->label['singular']
803
-        );
804
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
805
-            '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?',
806
-            'event_espresso'
807
-        );
808
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
809
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
810
-            'event_espresso'
811
-        );
812
-
813
-        wp_register_script(
814
-            'ee_msgs_edit_js',
815
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
816
-            ['jquery'],
817
-            EVENT_ESPRESSO_VERSION
818
-        );
819
-
820
-        wp_enqueue_script('ee_admin_js');
821
-        wp_enqueue_script('ee_msgs_edit_js');
822
-
823
-        // add in special css for tiny_mce
824
-        add_filter('mce_css', [$this, 'wp_editor_css']);
825
-    }
826
-
827
-
828
-    /**
829
-     * @throws EE_Error
830
-     * @throws ReflectionException
831
-     */
832
-    public function load_scripts_styles_display_preview_message()
833
-    {
834
-        $this->_set_message_template_group();
835
-        if ($this->_active_messenger_name) {
836
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
837
-                $this->_active_messenger_name
838
-            );
839
-        }
840
-
841
-        wp_enqueue_style(
842
-            'espresso_preview_css',
843
-            $this->_active_messenger->get_variation(
844
-                $this->_template_pack,
845
-                $this->_active_message_type_name,
846
-                true,
847
-                'preview',
848
-                $this->_variation
849
-            )
850
-        );
851
-    }
852
-
853
-
854
-    public function load_scripts_styles_settings()
855
-    {
856
-        wp_register_style(
857
-            'ee-message-settings',
858
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
859
-            [],
860
-            EVENT_ESPRESSO_VERSION
861
-        );
862
-        wp_enqueue_style('ee-text-links');
863
-        wp_enqueue_style('ee-message-settings');
864
-        wp_enqueue_script('ee-messages-settings');
865
-    }
866
-
867
-
868
-    /**
869
-     * set views array for List Table
870
-     */
871
-    public function _set_list_table_views_global_mtps()
872
-    {
873
-        $this->_views = [
874
-            'in_use' => [
875
-                'slug'  => 'in_use',
876
-                'label' => esc_html__('In Use', 'event_espresso'),
877
-                'count' => 0,
878
-            ],
879
-        ];
880
-    }
881
-
882
-
883
-    /**
884
-     * Set views array for the Custom Template List Table
885
-     */
886
-    public function _set_list_table_views_custom_mtps()
887
-    {
888
-        $this->_set_list_table_views_global_mtps();
889
-        $this->_views['in_use']['bulk_action'] = [
890
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
891
-        ];
892
-    }
893
-
894
-
895
-    /**
896
-     * set views array for message queue list table
897
-     *
898
-     * @throws InvalidDataTypeException
899
-     * @throws InvalidInterfaceException
900
-     * @throws InvalidArgumentException
901
-     * @throws EE_Error
902
-     * @throws ReflectionException
903
-     */
904
-    public function _set_list_table_views_default()
905
-    {
906
-        EE_Registry::instance()->load_helper('Template');
907
-
908
-        $common_bulk_actions = $this->capabilities->current_user_can(
909
-            'ee_send_message',
910
-            'message_list_table_bulk_actions'
911
-        )
912
-            ? [
913
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
914
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
915
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
916
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
917
-            ]
918
-            : [];
919
-
920
-        $delete_bulk_action = $this->capabilities->current_user_can(
921
-            'ee_delete_messages',
922
-            'message_list_table_bulk_actions'
923
-        )
924
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
925
-            : [];
926
-
927
-
928
-        $this->_views = [
929
-            'all' => [
930
-                'slug'        => 'all',
931
-                'label'       => esc_html__('All', 'event_espresso'),
932
-                'count'       => 0,
933
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
934
-            ],
935
-        ];
936
-
937
-
938
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
939
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
940
-                continue;
941
-            }
942
-            $status_bulk_actions = $common_bulk_actions;
943
-            // unset bulk actions not applying to status
944
-            if (! empty($status_bulk_actions)) {
945
-                switch ($status) {
946
-                    case EEM_Message::status_idle:
947
-                    case EEM_Message::status_resend:
948
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
949
-                        break;
950
-
951
-                    case EEM_Message::status_failed:
952
-                    case EEM_Message::status_debug_only:
953
-                    case EEM_Message::status_messenger_executing:
954
-                        $status_bulk_actions = [];
955
-                        break;
956
-
957
-                    case EEM_Message::status_incomplete:
958
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
959
-                        break;
960
-
961
-                    case EEM_Message::status_retry:
962
-                    case EEM_Message::status_sent:
963
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
964
-                        break;
965
-                }
966
-            }
967
-
968
-            // skip adding messenger executing status to views because it will be included with the Failed view.
969
-            if ($status === EEM_Message::status_messenger_executing) {
970
-                continue;
971
-            }
972
-
973
-            $this->_views[ strtolower($status) ] = [
974
-                'slug'        => strtolower($status),
975
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
976
-                'count'       => 0,
977
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
978
-            ];
979
-        }
980
-    }
981
-
982
-
983
-    /**
984
-     * @throws EE_Error
985
-     */
986
-    protected function _ee_default_messages_overview_list_table()
987
-    {
988
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
989
-        $this->display_admin_list_table_page_with_no_sidebar();
990
-    }
991
-
992
-
993
-    /**
994
-     * @throws EE_Error
995
-     * @throws ReflectionException
996
-     */
997
-    protected function _message_queue_list_table()
998
-    {
999
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1000
-        $this->_template_args['per_column']        = 6;
1001
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1002
-        $message_results                           = trim(EEM_Message::instance()->get_pretty_label_for_results());
1003
-        $this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1004
-        $this->display_admin_list_table_page_with_no_sidebar();
1005
-    }
1006
-
1007
-
1008
-    /**
1009
-     * @throws EE_Error
1010
-     */
1011
-    protected function _message_legend_items()
1012
-    {
1013
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1014
-        $action_items       = [];
1015
-
1016
-        foreach ($action_css_classes as $action_item => $action_details) {
1017
-            if ($action_item === 'see_notifications_for') {
1018
-                continue;
1019
-            }
1020
-            $action_items[ $action_item ] = [
1021
-                'class' => $action_details['css_class'],
1022
-                'desc'  => $action_details['label'],
1023
-            ];
1024
-        }
1025
-
1026
-        /** @var array $status_items status legend setup */
1027
-        $status_items = [
1028
-            'sent_status'                => [
1029
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1030
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1031
-            ],
1032
-            'idle_status'                => [
1033
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1034
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1035
-            ],
1036
-            'failed_status'              => [
1037
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1038
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1039
-            ],
1040
-            'messenger_executing_status' => [
1041
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1042
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1043
-            ],
1044
-            'resend_status'              => [
1045
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1046
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1047
-            ],
1048
-            'incomplete_status'          => [
1049
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1050
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1051
-            ],
1052
-            'retry_status'               => [
1053
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1054
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1055
-            ],
1056
-        ];
1057
-        if (EEM_Message::debug()) {
1058
-            $status_items['debug_only_status'] = [
1059
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1060
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1061
-            ];
1062
-        }
1063
-
1064
-        return array_merge($action_items, $status_items);
1065
-    }
1066
-
1067
-
1068
-    /**
1069
-     * @throws EE_Error
1070
-     */
1071
-    protected function _custom_mtps_preview()
1072
-    {
1073
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1074
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1075
-                                                . ' alt="' . esc_attr__(
1076
-                                                    'Preview Custom Message Templates screenshot',
1077
-                                                    'event_espresso'
1078
-                                                ) . '" />';
1079
-        $this->_template_args['preview_text'] = '<strong>'
1080
-                                                . esc_html__(
1081
-                                                    '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.',
1082
-                                                    'event_espresso'
1083
-                                                )
1084
-                                                . '</strong>';
1085
-
1086
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1087
-    }
1088
-
1089
-
1090
-    /**
1091
-     * get_message_templates
1092
-     * This gets all the message templates for listing on the overview list.
1093
-     *
1094
-     * @param int    $per_page the amount of templates groups to show per page
1095
-     * @param string $type     the current _view we're getting templates for
1096
-     * @param bool   $count    return count?
1097
-     * @param bool   $all      disregard any paging info (get all data);
1098
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1099
-     * @return array|int
1100
-     * @throws EE_Error
1101
-     * @throws InvalidArgumentException
1102
-     * @throws InvalidDataTypeException
1103
-     * @throws InvalidInterfaceException
1104
-     * @throws ReflectionException
1105
-     */
1106
-    public function get_message_templates(
1107
-        int $per_page = 10,
1108
-        string $type = 'in_use',
1109
-        bool $count = false,
1110
-        bool $all = false,
1111
-        bool $global = true
1112
-    ) {
1113
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1114
-        // ensure that the orderby param is actually set within the request data
1115
-        $this->request->setRequestParam('orderby', $orderby);
1116
-        $order        = $this->request->getRequestParam('order', 'ASC');
1117
-        $current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
1118
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
1119
-
1120
-        $offset = ($current_page - 1) * $per_page;
1121
-        $limit  = $all ? null : [$offset, $per_page];
1122
-
1123
-        // options will match what is in the _views array property
1124
-        return $type === 'in_use'
1125
-            ? $this->getMtgModel()->get_all_active_message_templates(
1126
-                $orderby,
1127
-                $order,
1128
-                $limit,
1129
-                $count,
1130
-                $global,
1131
-                true
1132
-            )
1133
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1134
-                $orderby,
1135
-                $order,
1136
-                $limit,
1137
-                $count,
1138
-                $global
1139
-            );
1140
-    }
1141
-
1142
-
1143
-    /**
1144
-     * filters etc might need a list of installed message_types
1145
-     *
1146
-     * @return array an array of message type objects
1147
-     */
1148
-    public function get_installed_message_types(): array
1149
-    {
1150
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1151
-        $installed               = [];
1152
-
1153
-        foreach ($installed_message_types as $message_type) {
1154
-            $installed[ $message_type->name ] = $message_type;
1155
-        }
1156
-
1157
-        return $installed;
1158
-    }
1159
-
1160
-
1161
-    /**
1162
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1163
-     *
1164
-     * @param string     $message_type
1165
-     * @param string     $messenger
1166
-     * @param int|string $GRP_ID
1167
-     * @throws EE_error
1168
-     * @throws ReflectionException
1169
-     * @deprecated 5.0.8.p
1170
-     */
1171
-    public function add_message_template(string $message_type = '', string $messenger = '', $GRP_ID = '')
1172
-    {
1173
-        $this->insertMessageTemplate();
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * @param string $message_type     message type slug
1179
-     * @param string $messenger        messenger slug
1180
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1181
-     *                                 off of.
1182
-     * @throws EE_error
1183
-     * @throws ReflectionException
1184
-     * @deprecated 4.10.29.p
1185
-     */
1186
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1187
-    {
1188
-        $this->insertMessageTemplate($message_type, $messenger, $GRP_ID);
1189
-    }
1190
-
1191
-
1192
-    /**
1193
-     * _edit_message_template
1194
-     *
1195
-     * @access protected
1196
-     * @return void
1197
-     * @throws InvalidIdentifierException
1198
-     * @throws DomainException
1199
-     * @throws EE_Error
1200
-     * @throws InvalidArgumentException
1201
-     * @throws ReflectionException
1202
-     * @throws InvalidDataTypeException
1203
-     * @throws InvalidInterfaceException
1204
-     */
1205
-    protected function _edit_message_template()
1206
-    {
1207
-        $template_fields = '';
1208
-        $sidebar_fields  = '';
1209
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1210
-        // valid html in the templates.
1211
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1212
-
1213
-        $GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
1214
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', $GRP_ID, DataType::INTEGER);
1215
-
1216
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, DataType::INTEGER);
1217
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, DataType::INTEGER);
1218
-
1219
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1220
-        $message_template_group = $this->_message_template_group;
1221
-        $c_label                = $message_template_group->context_label();
1222
-        $c_config               = $message_template_group->contexts_config();
1223
-
1224
-        reset($c_config);
1225
-        $context = $this->request->getRequestParam('context', key($c_config));
1226
-        $context = strtolower($context);
1227
-
1228
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1229
-
1230
-        $edit_message_template_form_url = add_query_arg(
1231
-            ['action' => $action, 'noheader' => true],
1232
-            EE_MSG_ADMIN_URL
1233
-        );
1234
-
1235
-        // set active messenger for this view
1236
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1237
-            $message_template_group->messenger()
1238
-        );
1239
-        $this->_active_message_type_name = $message_template_group->message_type();
1240
-
1241
-
1242
-        // Do we have any validation errors?
1243
-        $validators = $this->_get_transient();
1244
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1245
-
1246
-
1247
-        // we need to assemble the title from Various details
1248
-        $context_label = sprintf(
1249
-            esc_html__('(%s %s)', 'event_espresso'),
1250
-            $c_config[ $context ]['label'],
1251
-            ucwords($c_label['label'])
1252
-        );
1253
-
1254
-        $title = sprintf(
1255
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1256
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1257
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1258
-            $context_label
1259
-        );
1260
-
1261
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1262
-        $this->_template_args['message_template'] = $message_template_group;
1263
-        $this->_template_args['is_extra_fields']  = false;
1264
-
1265
-
1266
-        // let's get EEH_MSG_Template so we can get template form fields
1267
-        $template_field_structure = EEH_MSG_Template::get_fields(
1268
-            $message_template_group->messenger(),
1269
-            $message_template_group->message_type()
1270
-        );
1271
-
1272
-        if (! $template_field_structure) {
1273
-            $template_field_structure = false;
1274
-            $template_fields          = esc_html__(
1275
-                'There was an error in assembling the fields for this display (you should see an error message)',
1276
-                'event_espresso'
1277
-            );
1278
-        }
1279
-
1280
-        $message_templates = $message_template_group->context_templates();
1281
-
1282
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1283
-        // will get handled in the "extra" array.
1284
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1285
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1286
-                unset($template_field_structure[ $context ][ $reference_field ]);
1287
-            }
1288
-        }
1289
-
1290
-        // let's loop through the template_field_structure and actually assemble the input fields!
1291
-        if (! empty($template_field_structure)) {
1292
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1293
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1294
-                // the extra array and reset them.
1295
-                if ($template_field === 'extra') {
1296
-                    $this->_template_args['is_extra_fields'] = true;
1297
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1298
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1299
-                        $content          = $message_template instanceof EE_Message_Template
1300
-                            ? $message_template->get('MTP_content')
1301
-                            : '';
1302
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1303
-                            // let's verify if we need this extra field via the shortcodes parameter.
1304
-                            $continue = false;
1305
-                            if (isset($extra_array['shortcodes_required'])) {
1306
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1307
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1308
-                                        $continue = true;
1309
-                                    }
1310
-                                }
1311
-                                if ($continue) {
1312
-                                    continue;
1313
-                                }
1314
-                            }
1315
-
1316
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1317
-
1318
-                            $template_form_fields[ $field_id ]         = $extra_array;
1319
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1320
-                                                                         . $reference_field
1321
-                                                                         . '][content]['
1322
-                                                                         . $extra_field . ']';
1323
-                            $css_class                                 = $extra_array['css_class'] ?? '';
1324
-
1325
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1326
-                                                                              && in_array($extra_field, $v_fields, true)
1327
-                                                                              && (
1328
-                                                                                  is_array($validators[ $extra_field ])
1329
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1330
-                                                                              )
1331
-                                ? 'validate-error ' . $css_class
1332
-                                : $css_class;
1333
-
1334
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1335
-                                                                          && isset($content[ $extra_field ])
1336
-                                ? $content[ $extra_field ]
1337
-                                : '';
1338
-
1339
-                            // do we have a validation error?  if we do then let's use that value instead
1340
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1341
-                                ? $validators[ $extra_field ]['value']
1342
-                                : $template_form_fields[ $field_id ]['value'];
1343
-
1344
-
1345
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1346
-
1347
-                            // shortcode selector
1348
-                            $field_name_to_use                                   = $extra_field === 'main'
1349
-                                ? 'content'
1350
-                                : $extra_field;
1351
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1352
-                                $field_name_to_use,
1353
-                                $field_id
1354
-                            );
1355
-                        }
1356
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1357
-                        $template_field_template_name_id = $reference_field . '-name';
1358
-
1359
-                        $template_form_fields[ $template_field_MTP_id ] = [
1360
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1361
-                            'label'      => null,
1362
-                            'input'      => 'hidden',
1363
-                            'type'       => 'int',
1364
-                            'required'   => false,
1365
-                            'validation' => false,
1366
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1367
-                            'css_class'  => '',
1368
-                            'format'     => '%d',
1369
-                            'db-col'     => 'MTP_ID',
1370
-                        ];
1371
-
1372
-                        $template_form_fields[ $template_field_template_name_id ] = [
1373
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1374
-                            'label'      => null,
1375
-                            'input'      => 'hidden',
1376
-                            'type'       => 'string',
1377
-                            'required'   => false,
1378
-                            'validation' => true,
1379
-                            'value'      => $reference_field,
1380
-                            'css_class'  => '',
1381
-                            'format'     => '%s',
1382
-                            'db-col'     => 'MTP_template_field',
1383
-                        ];
1384
-                    }
1385
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1386
-                } else {
1387
-                    $field_id                                   = $template_field . '-content';
1388
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1389
-                    $template_form_fields[ $field_id ]['name']  =
1390
-                        'MTP_template_fields[' . $template_field . '][content]';
1391
-                    $message_template                           =
1392
-                        $message_templates[ $context ][ $template_field ] ?? null;
1393
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1394
-                                                                  && is_array($message_templates[ $context ])
1395
-                                                                  && $message_template instanceof EE_Message_Template
1396
-                        ? $message_template->get('MTP_content')
1397
-                        : '';
1398
-
1399
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1400
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1401
-                        ? $validators[ $template_field ]['value']
1402
-                        : $template_form_fields[ $field_id ]['value'];
1403
-
1404
-
1405
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1406
-                    $css_class                                      = $field_setup_array['css_class'] ?? '';
1407
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1408
-                                                                      && in_array($template_field, $v_fields, true)
1409
-                                                                      && isset($validators[ $template_field ]['msg'])
1410
-                        ? 'validate-error ' . $css_class
1411
-                        : $css_class;
1412
-
1413
-                    // shortcode selector
1414
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1415
-                        $template_field,
1416
-                        $field_id
1417
-                    );
1418
-                }
1419
-
1420
-                // k took care of content field(s) now let's take care of others.
1421
-
1422
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1423
-                $template_field_field_template_name_id = $template_field . '-name';
1424
-
1425
-                // foreach template field there are actually two form fields created
1426
-                $template_form_fields[ $template_field_MTP_id ] = [
1427
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1428
-                    'label'      => null,
1429
-                    'input'      => 'hidden',
1430
-                    'type'       => 'int',
1431
-                    'required'   => false,
1432
-                    'validation' => true,
1433
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1434
-                    'css_class'  => '',
1435
-                    'format'     => '%d',
1436
-                    'db-col'     => 'MTP_ID',
1437
-                ];
1438
-
1439
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1440
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1441
-                    'label'      => null,
1442
-                    'input'      => 'hidden',
1443
-                    'type'       => 'string',
1444
-                    'required'   => false,
1445
-                    'validation' => true,
1446
-                    'value'      => $template_field,
1447
-                    'css_class'  => '',
1448
-                    'format'     => '%s',
1449
-                    'db-col'     => 'MTP_template_field',
1450
-                ];
1451
-            }
1452
-
1453
-            // add other fields
1454
-            $template_form_fields['ee-msg-current-context'] = [
1455
-                'name'       => 'MTP_context',
1456
-                'label'      => null,
1457
-                'input'      => 'hidden',
1458
-                'type'       => 'string',
1459
-                'required'   => false,
1460
-                'validation' => true,
1461
-                'value'      => $context,
1462
-                'css_class'  => '',
1463
-                'format'     => '%s',
1464
-                'db-col'     => 'MTP_context',
1465
-            ];
1466
-
1467
-            $template_form_fields['ee-msg-grp-id'] = [
1468
-                'name'       => 'GRP_ID',
1469
-                'label'      => null,
1470
-                'input'      => 'hidden',
1471
-                'type'       => 'int',
1472
-                'required'   => false,
1473
-                'validation' => true,
1474
-                'value'      => $GRP_ID,
1475
-                'css_class'  => '',
1476
-                'format'     => '%d',
1477
-                'db-col'     => 'GRP_ID',
1478
-            ];
1479
-
1480
-            $template_form_fields['ee-msg-messenger'] = [
1481
-                'name'       => 'MTP_messenger',
1482
-                'label'      => null,
1483
-                'input'      => 'hidden',
1484
-                'type'       => 'string',
1485
-                'required'   => false,
1486
-                'validation' => true,
1487
-                'value'      => $message_template_group->messenger(),
1488
-                'css_class'  => '',
1489
-                'format'     => '%s',
1490
-                'db-col'     => 'MTP_messenger',
1491
-            ];
1492
-
1493
-            $template_form_fields['ee-msg-message-type'] = [
1494
-                'name'       => 'MTP_message_type',
1495
-                'label'      => null,
1496
-                'input'      => 'hidden',
1497
-                'type'       => 'string',
1498
-                'required'   => false,
1499
-                'validation' => true,
1500
-                'value'      => $message_template_group->message_type(),
1501
-                'css_class'  => '',
1502
-                'format'     => '%s',
1503
-                'db-col'     => 'MTP_message_type',
1504
-            ];
1505
-
1506
-            $sidebar_form_fields['ee-msg-is-global'] = [
1507
-                'name'       => 'MTP_is_global',
1508
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1509
-                'input'      => 'hidden',
1510
-                'type'       => 'int',
1511
-                'required'   => false,
1512
-                'validation' => true,
1513
-                'value'      => $message_template_group->get('MTP_is_global'),
1514
-                'css_class'  => '',
1515
-                'format'     => '%d',
1516
-                'db-col'     => 'MTP_is_global',
1517
-            ];
1518
-
1519
-            $sidebar_form_fields['ee-msg-is-override'] = [
1520
-                'name'       => 'MTP_is_override',
1521
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1522
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1523
-                'type'       => 'int',
1524
-                'required'   => false,
1525
-                'validation' => true,
1526
-                'value'      => $message_template_group->get('MTP_is_override'),
1527
-                'css_class'  => '',
1528
-                'format'     => '%d',
1529
-                'db-col'     => 'MTP_is_override',
1530
-            ];
1531
-
1532
-            $sidebar_form_fields['ee-msg-is-active'] = [
1533
-                'name'       => 'MTP_is_active',
1534
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1535
-                'input'      => 'hidden',
1536
-                'type'       => 'int',
1537
-                'required'   => false,
1538
-                'validation' => true,
1539
-                'value'      => $message_template_group->is_active(),
1540
-                'css_class'  => '',
1541
-                'format'     => '%d',
1542
-                'db-col'     => 'MTP_is_active',
1543
-            ];
1544
-
1545
-            $sidebar_form_fields['ee-msg-deleted'] = [
1546
-                'name'       => 'MTP_deleted',
1547
-                'label'      => null,
1548
-                'input'      => 'hidden',
1549
-                'type'       => 'int',
1550
-                'required'   => false,
1551
-                'validation' => true,
1552
-                'value'      => $message_template_group->get('MTP_deleted'),
1553
-                'css_class'  => '',
1554
-                'format'     => '%d',
1555
-                'db-col'     => 'MTP_deleted',
1556
-            ];
1557
-            $sidebar_form_fields['ee-msg-author']  = [
1558
-                'name'       => 'MTP_user_id',
1559
-                'label'      => esc_html__('Author', 'event_espresso'),
1560
-                'input'      => 'hidden',
1561
-                'type'       => 'int',
1562
-                'required'   => false,
1563
-                'validation' => false,
1564
-                'value'      => $message_template_group->user(),
1565
-                'format'     => '%d',
1566
-                'db-col'     => 'MTP_user_id',
1567
-            ];
1568
-
1569
-            $sidebar_form_fields['ee-msg-route'] = [
1570
-                'name'  => 'action',
1571
-                'input' => 'hidden',
1572
-                'type'  => 'string',
1573
-                'value' => $action,
1574
-            ];
1575
-
1576
-            $sidebar_form_fields['ee-msg-id']        = [
1577
-                'name'  => 'id',
1578
-                'input' => 'hidden',
1579
-                'type'  => 'int',
1580
-                'value' => $GRP_ID,
1581
-            ];
1582
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1583
-                'name'  => $action . '_nonce',
1584
-                'input' => 'hidden',
1585
-                'type'  => 'string',
1586
-                'value' => wp_create_nonce($action . '_nonce'),
1587
-            ];
1588
-
1589
-            $template_switch = $this->request->getRequestParam('template_switch');
1590
-            if ($template_switch) {
1591
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1592
-                    'name'  => 'template_switch',
1593
-                    'input' => 'hidden',
1594
-                    'type'  => 'int',
1595
-                    'value' => 1,
1596
-                ];
1597
-            }
1598
-
1599
-
1600
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1601
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1602
-        } //end if ( !empty($template_field_structure) )
1603
-
1604
-        // set extra content for publish box
1605
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1606
-        $this->_set_publish_post_box_vars(
1607
-            'id',
1608
-            $GRP_ID,
1609
-            '',
1610
-            add_query_arg(
1611
-                ['action' => $message_template_group->is_global() ? 'global_mtps' : 'custom_mtps'],
1612
-                $this->_admin_base_url
1613
-            ),
1614
-            true
1615
-        );
1616
-
1617
-        // add preview button
1618
-        $preview_url    = parent::add_query_args_and_nonce(
1619
-            [
1620
-                'message_type' => $message_template_group->message_type(),
1621
-                'messenger'    => $message_template_group->messenger(),
1622
-                'context'      => $context,
1623
-                'GRP_ID'       => $GRP_ID,
1624
-                'evt_id'       => $EVT_ID ?: false,
1625
-                'action'       => 'preview_message',
1626
-            ],
1627
-            $this->_admin_base_url
1628
-        );
1629
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1630
-                          . esc_html__('Preview', 'event_espresso')
1631
-                          . '</a>';
1632
-
1633
-
1634
-        // setup context switcher
1635
-        $this->_set_context_switcher(
1636
-            $message_template_group,
1637
-            [
1638
-                'page'    => 'espresso_messages',
1639
-                'action'  => 'edit_message_template',
1640
-                'id'      => $GRP_ID,
1641
-                'evt_id'  => $EVT_ID,
1642
-                'context' => $context,
1643
-                'extra'   => $preview_button,
1644
-            ]
1645
-        );
1646
-
1647
-        // main box
1648
-        $this->_template_args['template_fields']                         = $template_fields;
1649
-        $this->_template_args['sidebar_box_id']                          = 'details';
1650
-        $this->_template_args['action']                                  = $action;
1651
-        $this->_template_args['context']                                 = $context;
1652
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1653
-        $this->_template_args['learn_more_about_message_templates_link'] =
1654
-            $this->_learn_more_about_message_templates_link();
1655
-
1656
-        $this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1657
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1658
-            $message_template_group,
1659
-            $context,
1660
-            $context_label
1661
-        );
1662
-        $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1663
-        $this->_template_args['before_admin_page_content'] .= '</div>';
1664
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1665
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1666
-
1667
-        $this->_template_path = $this->_template_args['GRP_ID']
1668
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1669
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1670
-
1671
-        // send along EE_Message_Template_Group object for further template use.
1672
-        $this->_template_args['MTP'] = $message_template_group;
1673
-
1674
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1675
-            $this->_template_path,
1676
-            $this->_template_args,
1677
-            true
1678
-        );
1679
-
1680
-        // finally, let's set the admin_page title
1681
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1682
-
1683
-        // we need to take care of setting the shortcodes property for use elsewhere.
1684
-        $this->_set_shortcodes();
1685
-
1686
-        // final template wrapper
1687
-        $this->display_admin_page_with_sidebar();
1688
-    }
1689
-
1690
-
1691
-    public function filter_tinymce_init($mceInit, $editor_id)
1692
-    {
1693
-        return $mceInit;
1694
-    }
1695
-
1696
-
1697
-    public function add_context_switcher()
1698
-    {
1699
-        return $this->_context_switcher;
1700
-    }
1701
-
1702
-
1703
-    /**
1704
-     * Adds the activation/deactivation toggle for the message template context.
1705
-     *
1706
-     * @param EE_Message_Template_Group $message_template_group
1707
-     * @param string                    $context
1708
-     * @param string                    $context_label
1709
-     * @return string
1710
-     * @throws DomainException
1711
-     * @throws EE_Error
1712
-     * @throws InvalidIdentifierException
1713
-     * @throws ReflectionException
1714
-     */
1715
-    protected function add_active_context_element(
1716
-        EE_Message_Template_Group $message_template_group,
1717
-        $context,
1718
-        $context_label
1719
-    ) {
1720
-        $template_args = [
1721
-            'context'                   => $context,
1722
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1723
-            'is_active'                 => $message_template_group->is_context_active($context),
1724
-            'on_off_action'             => $message_template_group->is_context_active($context)
1725
-                ? 'context-off'
1726
-                : 'context-on',
1727
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1728
-            'message_template_group_id' => $message_template_group->ID(),
1729
-        ];
1730
-        return EEH_Template::display_template(
1731
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1732
-            $template_args,
1733
-            true
1734
-        );
1735
-    }
1736
-
1737
-
1738
-    /**
1739
-     * Ajax callback for `toggle_context_template` ajax action.
1740
-     * Handles toggling the message context on or off.
1741
-     *
1742
-     * @throws EE_Error
1743
-     * @throws InvalidArgumentException
1744
-     * @throws InvalidDataTypeException
1745
-     * @throws InvalidIdentifierException
1746
-     * @throws InvalidInterfaceException
1747
-     * @throws ReflectionException
1748
-     */
1749
-    public function toggle_context_template()
1750
-    {
1751
-        if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
1752
-            wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
1753
-        }
1754
-        $success = true;
1755
-        // check for required data
1756
-        if (
1757
-            ! (
1758
-                $this->request->requestParamIsSet('message_template_group_id')
1759
-                && $this->request->requestParamIsSet('context')
1760
-                && $this->request->requestParamIsSet('status')
1761
-            )
1762
-        ) {
1763
-            EE_Error::add_error(
1764
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1765
-                __FILE__,
1766
-                __FUNCTION__,
1767
-                __LINE__
1768
-            );
1769
-            $success = false;
1770
-        }
1771
-
1772
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1773
-        $context = $this->request->getRequestParam('context', '');
1774
-        $status  = $this->request->getRequestParam('status', '');
1775
-
1776
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1777
-
1778
-        if ($status !== 'off' && $status !== 'on') {
1779
-            EE_Error::add_error(
1780
-                sprintf(
1781
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1782
-                    $status
1783
-                ),
1784
-                __FILE__,
1785
-                __FUNCTION__,
1786
-                __LINE__
1787
-            );
1788
-            $success = false;
1789
-        }
1790
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, DataType::INTEGER);
1791
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1792
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1793
-            EE_Error::add_error(
1794
-                sprintf(
1795
-                    esc_html__(
1796
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1797
-                        'event_espresso'
1798
-                    ),
1799
-                    $message_template_group_id,
1800
-                    'EE_Message_Template_Group'
1801
-                ),
1802
-                __FILE__,
1803
-                __FUNCTION__,
1804
-                __LINE__
1805
-            );
1806
-            $success = false;
1807
-        }
1808
-        if ($success) {
1809
-            $success = $status === 'off'
1810
-                ? $message_template_group->deactivate_context($context)
1811
-                : $message_template_group->activate_context($context);
1812
-        }
1813
-        $this->_template_args['success'] = $success;
1814
-        $this->_return_json();
1815
-    }
1816
-
1817
-
1818
-    public function _add_form_element_before()
1819
-    {
1820
-        return '<form method="post" action="'
1821
-               . $this->_template_args['edit_message_template_form_url']
1822
-               . '" id="ee-msg-edit-frm">';
1823
-    }
1824
-
1825
-
1826
-    public function _add_form_element_after()
1827
-    {
1828
-        return '</form>';
1829
-    }
1830
-
1831
-
1832
-    /**
1833
-     * This executes switching the template pack for a message template.
1834
-     *
1835
-     * @throws EE_Error
1836
-     * @throws InvalidDataTypeException
1837
-     * @throws InvalidInterfaceException
1838
-     * @throws InvalidArgumentException
1839
-     * @throws ReflectionException
1840
-     * @since 4.5.0
1841
-     */
1842
-    public function switch_template_pack()
1843
-    {
1844
-        if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
1845
-            wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
1846
-        }
1847
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
1848
-        $template_pack = $this->request->getRequestParam('template_pack', '');
1849
-
1850
-        // verify we have needed values.
1851
-        if (empty($GRP_ID) || empty($template_pack)) {
1852
-            $this->_template_args['error'] = true;
1853
-            EE_Error::add_error(
1854
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1855
-                __FILE__,
1856
-                __FUNCTION__,
1857
-                __LINE__
1858
-            );
1859
-        } else {
1860
-            // get template, set the new template_pack and then reset to default
1861
-            /** @var EE_Message_Template_Group $message_template_group */
1862
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
1863
-
1864
-            $message_template_group->set_template_pack_name($template_pack);
1865
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
1866
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
1867
-
1868
-            $query_args = $this->_reset_to_default_template();
1869
-
1870
-            if (empty($query_args['id'])) {
1871
-                EE_Error::add_error(
1872
-                    esc_html__(
1873
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1874
-                        'event_espresso'
1875
-                    ),
1876
-                    __FILE__,
1877
-                    __FUNCTION__,
1878
-                    __LINE__
1879
-                );
1880
-                $this->_template_args['error'] = true;
1881
-            } else {
1882
-                $template_label       = $message_template_group->get_template_pack()->label;
1883
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1884
-                EE_Error::add_success(
1885
-                    sprintf(
1886
-                        esc_html__(
1887
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1888
-                            'event_espresso'
1889
-                        ),
1890
-                        $template_label,
1891
-                        $template_pack_labels->template_pack
1892
-                    )
1893
-                );
1894
-                // generate the redirect url for js.
1895
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1896
-
1897
-                $this->_template_args['data']['redirect_url'] = $url;
1898
-                $this->_template_args['success']              = true;
1899
-            }
1900
-
1901
-            $this->_return_json();
1902
-        }
1903
-    }
1904
-
1905
-
1906
-    /**
1907
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1908
-     * they want.
1909
-     *
1910
-     * @access protected
1911
-     * @return array|void
1912
-     * @throws EE_Error
1913
-     * @throws InvalidArgumentException
1914
-     * @throws InvalidDataTypeException
1915
-     * @throws InvalidInterfaceException
1916
-     * @throws ReflectionException
1917
-     */
1918
-    protected function _reset_to_default_template()
1919
-    {
1920
-        $templates    = [];
1921
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
1922
-        $messenger    = $this->request->getRequestParam('msgr');
1923
-        $message_type = $this->request->getRequestParam('mt');
1924
-        // we need to make sure we've got the info we need.
1925
-        if (! ($GRP_ID && $messenger && $message_type)) {
1926
-            EE_Error::add_error(
1927
-                esc_html__(
1928
-                    '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.',
1929
-                    'event_espresso'
1930
-                ),
1931
-                __FILE__,
1932
-                __FUNCTION__,
1933
-                __LINE__
1934
-            );
1935
-        }
1936
-
1937
-        // all templates will be reset to whatever the defaults are
1938
-        // for the global template matching the messenger and message type.
1939
-        $success = ! empty($GRP_ID);
1940
-
1941
-        if ($success) {
1942
-            // let's first determine if the incoming template is a global template,
1943
-            // if it isn't then we need to get the global template matching messenger and message type.
1944
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
1945
-
1946
-
1947
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1948
-            $success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplates($GRP_ID);
1949
-
1950
-            if ($success) {
1951
-                // if successfully deleted, lets generate the new ones.
1952
-                // Note. We set GLOBAL to true, because resets on ANY template
1953
-                // will use the related global template defaults for regeneration.
1954
-                // This means that if a custom template is reset it resets to whatever the related global template is.
1955
-                // HOWEVER, we DO keep the template pack and template variation set
1956
-                // for the current custom template when resetting.
1957
-                $templates = $this->getMessageTemplateManager()->generateNewTemplates(
1958
-                    $messenger,
1959
-                    $message_type,
1960
-                    $GRP_ID,
1961
-                    true
1962
-                );
1963
-            }
1964
-        }
1965
-
1966
-        // any error messages?
1967
-        if (! $success) {
1968
-            EE_Error::add_error(
1969
-                esc_html__(
1970
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
1971
-                    'event_espresso'
1972
-                ),
1973
-                __FILE__,
1974
-                __FUNCTION__,
1975
-                __LINE__
1976
-            );
1977
-        }
1978
-
1979
-        // all good, let's add a success message!
1980
-        if ($success && ! empty($templates)) {
1981
-            // the info for the template we generated is the first element in the returned array
1982
-            EE_Error::overwrite_success();
1983
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
1984
-        }
1985
-
1986
-
1987
-        $query_args = [
1988
-            'id'      => $templates['GRP_ID'] ?? null,
1989
-            'context' => $templates['MTP_context'] ?? null,
1990
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
1991
-        ];
1992
-
1993
-        // if called via ajax then we return query args otherwise redirect
1994
-        if ($this->request->isAjax()) {
1995
-            return $query_args;
1996
-        }
1997
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1998
-    }
1999
-
2000
-
2001
-    /**
2002
-     * Retrieve and set the message preview for display.
2003
-     *
2004
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2005
-     * @return string
2006
-     * @throws ReflectionException
2007
-     * @throws EE_Error
2008
-     * @throws InvalidArgumentException
2009
-     * @throws InvalidDataTypeException
2010
-     * @throws InvalidInterfaceException
2011
-     */
2012
-    public function _preview_message($send = false)
2013
-    {
2014
-        // first make sure we've got the necessary parameters
2015
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2016
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2017
-            EE_Error::add_error(
2018
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2019
-                __FILE__,
2020
-                __FUNCTION__,
2021
-                __LINE__
2022
-            );
2023
-        }
2024
-
2025
-        $context = $this->request->getRequestParam('context');
2026
-        // get the preview!
2027
-        $preview = EED_Messages::preview_message(
2028
-            $this->_active_message_type_name,
2029
-            $context,
2030
-            $this->_active_messenger_name,
2031
-            $send
2032
-        );
2033
-
2034
-        if ($send) {
2035
-            return $preview;
2036
-        }
2037
-
2038
-        // if we have an evt_id set on the request, use it.
2039
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, DataType::INTEGER);
2040
-
2041
-        // let's add a button to go back to the edit view
2042
-        $query_args             = [
2043
-            'id'      => $GRP_ID,
2044
-            'evt_id'  => $EVT_ID,
2045
-            'context' => $context,
2046
-            'action'  => 'edit_message_template',
2047
-        ];
2048
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2049
-        $preview_button         = '<a href="'
2050
-                                  . $go_back_url
2051
-                                  . '" class="button--secondary messages-preview-go-back-button">'
2052
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2053
-                                  . '</a>';
2054
-        $message_types          = $this->get_installed_message_types();
2055
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2056
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2057
-            ? ucwords($active_messenger->label['singular'])
2058
-            : esc_html__('Unknown Messenger', 'event_espresso');
2059
-        // let's provide a helpful title for context
2060
-        $preview_title = sprintf(
2061
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2062
-            $active_messenger_label,
2063
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2064
-        );
2065
-        if (empty($preview)) {
2066
-            $this->noEventsErrorMessage();
2067
-        }
2068
-        // setup display of preview.
2069
-        $this->_admin_page_title                    = $preview_title;
2070
-        $this->_template_args['admin_page_title']   = $preview_title;
2071
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2072
-        $this->_template_args['data']['force_json'] = true;
2073
-
2074
-        return '';
2075
-    }
2076
-
2077
-
2078
-    /**
2079
-     * Used to set an error if there are no events available for generating a preview/test send.
2080
-     *
2081
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2082
-     */
2083
-    protected function noEventsErrorMessage($test_send = false)
2084
-    {
2085
-        $events_url = parent::add_query_args_and_nonce(
2086
-            [
2087
-                'action' => 'default',
2088
-                'page'   => 'espresso_events',
2089
-            ],
2090
-            admin_url('admin.php')
2091
-        );
2092
-        $message    = $test_send
2093
-            ? esc_html__(
2094
-                '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!',
2095
-                'event_espresso'
2096
-            )
2097
-            : esc_html__(
2098
-                '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!',
2099
-                'event_espresso'
2100
-            );
2101
-
2102
-        EE_Error::add_attention(
2103
-            sprintf(
2104
-                $message,
2105
-                "<a href='{$events_url}'>",
2106
-                '</a>'
2107
-            )
2108
-        );
2109
-    }
2110
-
2111
-
2112
-    /**
2113
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2114
-     * gets called automatically.
2115
-     *
2116
-     * @return void
2117
-     * @throws EE_Error
2118
-     * @since 4.5.0
2119
-     */
2120
-    protected function _display_preview_message()
2121
-    {
2122
-        $this->display_admin_page_with_no_sidebar();
2123
-    }
2124
-
2125
-
2126
-    /**
2127
-     * registers metaboxes that should show up on the "edit_message_template" page
2128
-     *
2129
-     * @access protected
2130
-     * @return void
2131
-     */
2132
-    protected function _register_edit_meta_boxes()
2133
-    {
2134
-        $this->addMetaBox(
2135
-            'mtp_valid_shortcodes',
2136
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2137
-            [$this, 'shortcode_meta_box'],
2138
-            $this->_current_screen->id,
2139
-            'side'
2140
-        );
2141
-        $this->addMetaBox(
2142
-            'mtp_extra_actions',
2143
-            esc_html__('Extra Actions', 'event_espresso'),
2144
-            [$this, 'extra_actions_meta_box'],
2145
-            $this->_current_screen->id,
2146
-            'side',
2147
-            'high'
2148
-        );
2149
-        $this->addMetaBox(
2150
-            'mtp_templates',
2151
-            esc_html__('Template Styles', 'event_espresso'),
2152
-            [$this, 'template_pack_meta_box'],
2153
-            $this->_current_screen->id,
2154
-            'side',
2155
-            'high'
2156
-        );
2157
-    }
2158
-
2159
-
2160
-    /**
2161
-     * metabox content for all template pack and variation selection.
2162
-     *
2163
-     * @return void
2164
-     * @throws DomainException
2165
-     * @throws EE_Error
2166
-     * @throws InvalidArgumentException
2167
-     * @throws ReflectionException
2168
-     * @throws InvalidDataTypeException
2169
-     * @throws InvalidInterfaceException
2170
-     * @since 4.5.0
2171
-     */
2172
-    public function template_pack_meta_box()
2173
-    {
2174
-        $this->_set_message_template_group();
2175
-
2176
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2177
-
2178
-        $tp_select_values = [];
2179
-
2180
-        foreach ($tp_collection as $tp) {
2181
-            // only include template packs that support this messenger and message type!
2182
-            $supports = $tp->get_supports();
2183
-            if (
2184
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2185
-                || ! in_array(
2186
-                    $this->_message_template_group->message_type(),
2187
-                    $supports[ $this->_message_template_group->messenger() ],
2188
-                    true
2189
-                )
2190
-            ) {
2191
-                // not supported
2192
-                continue;
2193
-            }
2194
-
2195
-            $tp_select_values[] = [
2196
-                'text' => $tp->label,
2197
-                'id'   => $tp->dbref,
2198
-            ];
2199
-        }
2200
-
2201
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2202
-        // the default template pack.  This still allows for the odd template pack to override.
2203
-        if (empty($tp_select_values)) {
2204
-            $tp_select_values[] = [
2205
-                'text' => esc_html__('Default', 'event_espresso'),
2206
-                'id'   => 'default',
2207
-            ];
2208
-        }
2209
-
2210
-        // setup variation select values for the currently selected template.
2211
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2212
-            $this->_message_template_group->messenger(),
2213
-            $this->_message_template_group->message_type()
2214
-        );
2215
-        $variations_select_values = [];
2216
-        foreach ($variations as $variation => $label) {
2217
-            $variations_select_values[] = [
2218
-                'text' => $label,
2219
-                'id'   => $variation,
2220
-            ];
2221
-        }
2222
-
2223
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2224
-
2225
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2226
-            'MTP_template_pack',
2227
-            $tp_select_values,
2228
-            $this->_message_template_group->get_template_pack_name()
2229
-        );
2230
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2231
-            'MTP_template_variation',
2232
-            $variations_select_values,
2233
-            $this->_message_template_group->get_template_pack_variation()
2234
-        );
2235
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2236
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2237
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2238
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2239
-
2240
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2241
-
2242
-        EEH_Template::display_template($template, $template_args);
2243
-    }
2244
-
2245
-
2246
-    /**
2247
-     * This meta box holds any extra actions related to Message Templates
2248
-     * For now, this includes Resetting templates to defaults and sending a test email.
2249
-     *
2250
-     * @access  public
2251
-     * @return void
2252
-     * @throws EE_Error
2253
-     */
2254
-    public function extra_actions_meta_box()
2255
-    {
2256
-        $template_form_fields = [];
2257
-
2258
-        $extra_args = [
2259
-            'msgr'   => $this->_message_template_group->messenger(),
2260
-            'mt'     => $this->_message_template_group->message_type(),
2261
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2262
-        ];
2263
-        // first we need to see if there are any fields
2264
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2265
-
2266
-        if (! empty($fields)) {
2267
-            // yup there be fields
2268
-            foreach ($fields as $field => $config) {
2269
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2270
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2271
-                $default  = $config['default'] ?? '';
2272
-                $default  = $config['value'] ?? $default;
2273
-
2274
-                // if type is hidden and the value is empty
2275
-                // something may have gone wrong so let's correct with the defaults
2276
-                $fix                = $config['input'] === 'hidden'
2277
-                                      && isset($existing[ $field ])
2278
-                                      && empty($existing[ $field ])
2279
-                    ? $default
2280
-                    : '';
2281
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2282
-                    ? $existing[ $field ]
2283
-                    : $fix;
2284
-
2285
-                $template_form_fields[ $field_id ] = [
2286
-                    'name'       => 'test_settings_fld[' . $field . ']',
2287
-                    'label'      => $config['label'],
2288
-                    'input'      => $config['input'],
2289
-                    'type'       => $config['type'],
2290
-                    'required'   => $config['required'],
2291
-                    'validation' => $config['validation'],
2292
-                    'value'      => $existing[ $field ] ?? $default,
2293
-                    'css_class'  => $config['css_class'],
2294
-                    'options'    => $config['options'] ?? [],
2295
-                    'default'    => $default,
2296
-                    'format'     => $config['format'],
2297
-                ];
2298
-            }
2299
-        }
2300
-
2301
-        $test_settings_html = ! empty($template_form_fields)
2302
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2303
-            : '';
2304
-
2305
-        // print out $test_settings_fields
2306
-        if (! empty($test_settings_html)) {
2307
-            $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2308
-            $test_settings_html .= 'name="test_button" value="';
2309
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2310
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2311
-        }
2312
-
2313
-        // and button
2314
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2315
-        $test_settings_html .= '<p>';
2316
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2317
-        $test_settings_html .= '</p>';
2318
-        $test_settings_html .= $this->get_action_link_or_button(
2319
-            'reset_to_default',
2320
-            'reset',
2321
-            $extra_args,
2322
-            'button--primary reset-default-button'
2323
-        );
2324
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2325
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2326
-    }
2327
-
2328
-
2329
-    /**
2330
-     * This returns the shortcode selector skeleton for a given context and field.
2331
-     *
2332
-     * @param string $field           The name of the field retrieving shortcodes for.
2333
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2334
-     * @return string
2335
-     * @throws DomainException
2336
-     * @throws EE_Error
2337
-     * @throws InvalidArgumentException
2338
-     * @throws ReflectionException
2339
-     * @throws InvalidDataTypeException
2340
-     * @throws InvalidInterfaceException
2341
-     * @since 4.9.rc.000
2342
-     */
2343
-    protected function _get_shortcode_selector($field, $linked_input_id)
2344
-    {
2345
-        $template_args = [
2346
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2347
-            'fieldname'       => $field,
2348
-            'linked_input_id' => $linked_input_id,
2349
-        ];
2350
-
2351
-        return EEH_Template::display_template(
2352
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2353
-            $template_args,
2354
-            true
2355
-        );
2356
-    }
2357
-
2358
-
2359
-    /**
2360
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2361
-     * page)
2362
-     *
2363
-     * @access public
2364
-     * @return void
2365
-     * @throws EE_Error
2366
-     * @throws InvalidArgumentException
2367
-     * @throws ReflectionException
2368
-     * @throws InvalidDataTypeException
2369
-     * @throws InvalidInterfaceException
2370
-     */
2371
-    public function shortcode_meta_box()
2372
-    {
2373
-        $shortcodes = $this->_get_shortcodes([], false);
2374
-        // just make sure the shortcodes property is set
2375
-        // $messenger = $this->_message_template_group->messenger_obj();
2376
-        // now let's set the content depending on the status of the shortcodes array
2377
-        if (empty($shortcodes)) {
2378
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2379
-            return;
2380
-        }
2381
-        ?>
60
+	/**
61
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
62
+	 * group is.  If there is no group then it automatically gets set to default.
63
+	 *
64
+	 * @since 4.5.0
65
+	 */
66
+	protected string $_variation = '';
67
+
68
+
69
+	/**
70
+	 * @param bool $routing
71
+	 * @throws EE_Error
72
+	 * @throws ReflectionException
73
+	 */
74
+	public function __construct($routing = true)
75
+	{
76
+		// make sure messages autoloader is running
77
+		EED_Messages::set_autoloaders();
78
+		parent::__construct($routing);
79
+	}
80
+
81
+
82
+	/**
83
+	 * @return EEM_Message
84
+	 * @throws EE_Error
85
+	 * @throws ReflectionException
86
+	 */
87
+	public function getMsgModel(): EEM_Message
88
+	{
89
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
90
+			$this->MSG_MODEL = EEM_Message::instance();
91
+		}
92
+		return $this->MSG_MODEL;
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return EEM_Message_Template
98
+	 * @throws EE_Error
99
+	 * @throws ReflectionException
100
+	 */
101
+	public function getMtpModel(): EEM_Message_Template
102
+	{
103
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
104
+			$this->MTP_MODEL = EEM_Message_Template::instance();
105
+		}
106
+		return $this->MTP_MODEL;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return EEM_Message_Template_Group
112
+	 * @throws EE_Error
113
+	 * @throws ReflectionException
114
+	 */
115
+	public function getMtgModel(): EEM_Message_Template_Group
116
+	{
117
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
118
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
119
+		}
120
+		return $this->MTG_MODEL;
121
+	}
122
+
123
+
124
+	public function getMessageTemplateManager(): MessageTemplateManager
125
+	{
126
+		if (! $this->message_template_manager instanceof MessageTemplateManager) {
127
+			$this->message_template_manager = $this->loader->getShared(MessageTemplateManager::class);
128
+		}
129
+		return $this->message_template_manager;
130
+	}
131
+
132
+
133
+	/**
134
+	 * @throws EE_Error
135
+	 * @throws ReflectionException
136
+	 */
137
+	protected function _init_page_props()
138
+	{
139
+		$this->page_slug        = EE_MSG_PG_SLUG;
140
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
141
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
142
+		$this->_admin_base_path = EE_MSG_ADMIN;
143
+
144
+		$messenger                       = $this->request->getRequestParam('messenger', '');
145
+		$message_type                    = $this->request->getRequestParam('message_type', '');
146
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
147
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
148
+
149
+		$this->_load_message_resource_manager();
150
+	}
151
+
152
+
153
+	protected function _load_message_resource_manager()
154
+	{
155
+		if (! $this->_message_resource_manager instanceof EE_Message_Resource_Manager) {
156
+			$this->_message_resource_manager = $this->loader->getShared(EE_Message_Resource_Manager::class);
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * Generate select input with provided messenger options array.
163
+	 *
164
+	 * @param array $messenger_options Array of messengers indexed by slug and values are the messenger labels.
165
+	 * @return string
166
+	 * @throws EE_Error
167
+	 */
168
+	public function get_messengers_select_input($messenger_options)
169
+	{
170
+		// if empty or just one value then just return an empty string
171
+		if (
172
+			empty($messenger_options)
173
+			|| ! is_array($messenger_options)
174
+			|| count($messenger_options) === 1
175
+		) {
176
+			return '';
177
+		}
178
+		// merge in default
179
+		$messenger_options = array_merge(
180
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
181
+			$messenger_options
182
+		);
183
+		$input             = new EE_Select_Input(
184
+			$messenger_options,
185
+			[
186
+				'html_name'  => 'ee_messenger_filter_by',
187
+				'html_id'    => 'ee_messenger_filter_by',
188
+				'html_class' => 'wide',
189
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
190
+			]
191
+		);
192
+
193
+		return $input->get_html_for_input();
194
+	}
195
+
196
+
197
+	/**
198
+	 * Generate select input with provided message type options array.
199
+	 *
200
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
201
+	 *                                    message type labels
202
+	 * @return string
203
+	 * @throws EE_Error
204
+	 */
205
+	public function get_message_types_select_input($message_type_options)
206
+	{
207
+		// if empty or count of options is 1 then just return an empty string
208
+		if (
209
+			empty($message_type_options)
210
+			|| ! is_array($message_type_options)
211
+			|| count($message_type_options) === 1
212
+		) {
213
+			return '';
214
+		}
215
+		// merge in default
216
+		$message_type_options = array_merge(
217
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
218
+			$message_type_options
219
+		);
220
+		$input                = new EE_Select_Input(
221
+			$message_type_options,
222
+			[
223
+				'html_name'  => 'ee_message_type_filter_by',
224
+				'html_id'    => 'ee_message_type_filter_by',
225
+				'html_class' => 'wide',
226
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
227
+			]
228
+		);
229
+
230
+		return $input->get_html_for_input();
231
+	}
232
+
233
+
234
+	/**
235
+	 * Generate select input with provide message type contexts array.
236
+	 *
237
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
238
+	 *                               context label.
239
+	 * @return string
240
+	 * @throws EE_Error
241
+	 */
242
+	public function get_contexts_for_message_types_select_input($context_options)
243
+	{
244
+		// if empty or count of options is one then just return empty string
245
+		if (
246
+			empty($context_options)
247
+			|| ! is_array($context_options)
248
+			|| count($context_options) === 1
249
+		) {
250
+			return '';
251
+		}
252
+		// merge in default
253
+		$context_options = array_merge(
254
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
255
+			$context_options
256
+		);
257
+		$input           = new EE_Select_Input(
258
+			$context_options,
259
+			[
260
+				'html_name'  => 'ee_context_filter_by',
261
+				'html_id'    => 'ee_context_filter_by',
262
+				'html_class' => 'wide',
263
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
264
+			]
265
+		);
266
+
267
+		return $input->get_html_for_input();
268
+	}
269
+
270
+
271
+	protected function _ajax_hooks()
272
+	{
273
+		if (! $this->capabilities->current_user_can('ee_edit_messages', 'edit-message-settings')) {
274
+			return;
275
+		}
276
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
277
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
278
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
279
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
280
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
281
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
282
+	}
283
+
284
+
285
+	protected function _define_page_props()
286
+	{
287
+		$this->_admin_page_title = $this->page_label;
288
+		$this->_labels           = [
289
+			'buttons'    => [
290
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
291
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
292
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
293
+			],
294
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
295
+		];
296
+	}
297
+
298
+
299
+	/**
300
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
301
+	 *
302
+	 * @access protected
303
+	 * @return void
304
+	 */
305
+	protected function _set_page_routes()
306
+	{
307
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
308
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, DataType::INTEGER);
309
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, DataType::INTEGER);
310
+
311
+		$this->_page_routes = [
312
+			'default'                          => [
313
+				'func'       => [$this, '_message_queue_list_table'],
314
+				'capability' => 'ee_read_global_messages',
315
+			],
316
+			'global_mtps'                      => [
317
+				'func'       => [$this, '_ee_default_messages_overview_list_table'],
318
+				'capability' => 'ee_read_global_messages',
319
+			],
320
+			'custom_mtps'                      => [
321
+				'func'       => [$this, '_custom_mtps_preview'],
322
+				'capability' => 'ee_read_messages',
323
+			],
324
+			'add_new_message_template'         => [
325
+				'func'       => [$this, 'insertMessageTemplate'],
326
+				'capability' => 'ee_edit_messages',
327
+				'noheader'   => true,
328
+			],
329
+			'edit_message_template'            => [
330
+				'func'       => [$this, '_edit_message_template'],
331
+				'capability' => 'ee_edit_message',
332
+				'obj_id'     => $GRP_ID,
333
+			],
334
+			'preview_message'                  => [
335
+				'func'               => [$this, '_preview_message'],
336
+				'capability'         => 'ee_read_message',
337
+				'obj_id'             => $GRP_ID,
338
+				'noheader'           => true,
339
+				'headers_sent_route' => 'display_preview_message',
340
+			],
341
+			'display_preview_message'          => [
342
+				'func'       => [$this, '_display_preview_message'],
343
+				'capability' => 'ee_read_message',
344
+				'obj_id'     => $GRP_ID,
345
+			],
346
+			'insert_message_template'          => [
347
+				'func'       => [$this, 'insertMessageTemplate'],
348
+				'capability' => 'ee_edit_messages',
349
+				'noheader'   => true,
350
+			],
351
+			'update_message_template'          => [
352
+				'func'       => [$this, 'updateMessageTemplate'],
353
+				'capability' => 'ee_edit_message',
354
+				'obj_id'     => $GRP_ID,
355
+				'noheader'   => true,
356
+			],
357
+			'trash_message_template'           => [
358
+				'func'       => [$this, '_trash_or_restore_message_template'],
359
+				'capability' => 'ee_delete_message',
360
+				'obj_id'     => $GRP_ID,
361
+				'args'       => ['trash' => true, 'all' => true],
362
+				'noheader'   => true,
363
+			],
364
+			'trash_message_template_context'   => [
365
+				'func'       => [$this, '_trash_or_restore_message_template'],
366
+				'capability' => 'ee_delete_message',
367
+				'obj_id'     => $GRP_ID,
368
+				'args'       => ['trash' => true],
369
+				'noheader'   => true,
370
+			],
371
+			'restore_message_template'         => [
372
+				'func'       => [$this, '_trash_or_restore_message_template'],
373
+				'capability' => 'ee_delete_message',
374
+				'obj_id'     => $GRP_ID,
375
+				'args'       => ['trash' => false, 'all' => true],
376
+				'noheader'   => true,
377
+			],
378
+			'restore_message_template_context' => [
379
+				'func'       => [$this, '_trash_or_restore_message_template'],
380
+				'capability' => 'ee_delete_message',
381
+				'obj_id'     => $GRP_ID,
382
+				'args'       => ['trash' => false],
383
+				'noheader'   => true,
384
+			],
385
+			'delete_message_template'          => [
386
+				'func'       => [$this, '_delete_message_template'],
387
+				'capability' => 'ee_delete_message',
388
+				'obj_id'     => $GRP_ID,
389
+				'noheader'   => true,
390
+			],
391
+			'reset_to_default'                 => [
392
+				'func'       => [$this, '_reset_to_default_template'],
393
+				'capability' => 'ee_edit_message',
394
+				'obj_id'     => $GRP_ID,
395
+				'noheader'   => true,
396
+			],
397
+			'settings'                         => [
398
+				'func'       => [$this, '_settings'],
399
+				'capability' => 'manage_options',
400
+			],
401
+			'update_global_settings'           => [
402
+				'func'       => [$this, '_update_global_settings'],
403
+				'capability' => 'manage_options',
404
+				'noheader'   => true,
405
+			],
406
+			'generate_now'                     => [
407
+				'func'       => [$this, '_generate_now'],
408
+				'capability' => 'ee_send_message',
409
+				'noheader'   => true,
410
+			],
411
+			'generate_and_send_now'            => [
412
+				'func'       => [$this, '_generate_and_send_now'],
413
+				'capability' => 'ee_send_message',
414
+				'noheader'   => true,
415
+			],
416
+			'queue_for_resending'              => [
417
+				'func'       => [$this, '_queue_for_resending'],
418
+				'capability' => 'ee_send_message',
419
+				'noheader'   => true,
420
+			],
421
+			'send_now'                         => [
422
+				'func'       => [$this, '_send_now'],
423
+				'capability' => 'ee_send_message',
424
+				'noheader'   => true,
425
+			],
426
+			'delete_ee_message'                => [
427
+				'func'       => [$this, '_delete_ee_messages'],
428
+				'capability' => 'ee_delete_messages',
429
+				'noheader'   => true,
430
+			],
431
+			'delete_ee_messages'               => [
432
+				'func'       => [$this, '_delete_ee_messages'],
433
+				'capability' => 'ee_delete_messages',
434
+				'noheader'   => true,
435
+				'obj_id'     => $MSG_ID,
436
+			],
437
+		];
438
+	}
439
+
440
+
441
+	protected function _set_page_config()
442
+	{
443
+		$this->_page_config = [
444
+			'default'                  => [
445
+				'nav'           => [
446
+					'label' => esc_html__('Message Activity', 'event_espresso'),
447
+					'icon'  => 'dashicons-email',
448
+					'order' => 10,
449
+				],
450
+				'list_table'    => 'EE_Message_List_Table',
451
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
452
+				'require_nonce' => false,
453
+			],
454
+			'global_mtps'              => [
455
+				'nav'           => [
456
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
457
+					'icon'  => 'dashicons-layout',
458
+					'order' => 20,
459
+				],
460
+				'list_table'    => 'Messages_Template_List_Table',
461
+				'help_tabs'     => [
462
+					'messages_overview_help_tab'                                => [
463
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
464
+						'filename' => 'messages_overview',
465
+					],
466
+					'messages_overview_messages_table_column_headings_help_tab' => [
467
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
468
+						'filename' => 'messages_overview_table_column_headings',
469
+					],
470
+					'messages_overview_messages_filters_help_tab'               => [
471
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
472
+						'filename' => 'messages_overview_filters',
473
+					],
474
+					'messages_overview_messages_views_help_tab'                 => [
475
+						'title'    => esc_html__('Message Views', 'event_espresso'),
476
+						'filename' => 'messages_overview_views',
477
+					],
478
+					'message_overview_message_types_help_tab'                   => [
479
+						'title'    => esc_html__('Message Types', 'event_espresso'),
480
+						'filename' => 'messages_overview_types',
481
+					],
482
+					'messages_overview_messengers_help_tab'                     => [
483
+						'title'    => esc_html__('Messengers', 'event_espresso'),
484
+						'filename' => 'messages_overview_messengers',
485
+					],
486
+				],
487
+				'require_nonce' => false,
488
+			],
489
+			'custom_mtps'              => [
490
+				'nav'           => [
491
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
492
+					'icon'  => 'dashicons-admin-customizer',
493
+					'order' => 30,
494
+				],
495
+				'help_tabs'     => [],
496
+				'require_nonce' => false,
497
+			],
498
+			'add_new_message_template' => [
499
+				'nav'           => [
500
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
501
+					'icon'       => 'dashicons-plus-alt',
502
+					'order'      => 5,
503
+					'persistent' => false,
504
+				],
505
+				'require_nonce' => false,
506
+			],
507
+			'edit_message_template'    => [
508
+				'labels'        => [
509
+					'buttons'    => [
510
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
511
+					],
512
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
513
+				],
514
+				'nav'           => [
515
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
516
+					'icon'       => 'dashicons-edit-large',
517
+					'order'      => 5,
518
+					'persistent' => false,
519
+					'url'        => '',
520
+				],
521
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
522
+				'has_metaboxes' => true,
523
+				'help_tabs'     => [
524
+					'edit_message_template'            => [
525
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
526
+						'callback' => 'edit_message_template_help_tab',
527
+					],
528
+					'message_templates_help_tab'       => [
529
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
530
+						'filename' => 'messages_templates',
531
+					],
532
+					'message_template_shortcodes'      => [
533
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
534
+						'callback' => 'message_template_shortcodes_help_tab',
535
+					],
536
+					'message_preview_help_tab'         => [
537
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
538
+						'filename' => 'messages_preview',
539
+					],
540
+					'messages_overview_other_help_tab' => [
541
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
542
+						'filename' => 'messages_overview_other',
543
+					],
544
+				],
545
+				'require_nonce' => false,
546
+			],
547
+			'display_preview_message'  => [
548
+				'nav'           => [
549
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
550
+					'icon'       => 'dashicons-visibility-bar',
551
+					'order'      => 5,
552
+					'url'        => '',
553
+					'persistent' => false,
554
+				],
555
+				'help_tabs'     => [
556
+					'preview_message' => [
557
+						'title'    => esc_html__('About Previews', 'event_espresso'),
558
+						'callback' => 'preview_message_help_tab',
559
+					],
560
+				],
561
+				'require_nonce' => false,
562
+			],
563
+			'settings'                 => [
564
+				'nav'           => [
565
+					'label' => esc_html__('Settings', 'event_espresso'),
566
+					'icon'  => 'dashicons-admin-generic',
567
+					'order' => 40,
568
+				],
569
+				'metaboxes'     => ['_messages_settings_metaboxes'],
570
+				'help_tabs'     => [
571
+					'messages_settings_help_tab'               => [
572
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
573
+						'filename' => 'messages_settings',
574
+					],
575
+					'messages_settings_message_types_help_tab' => [
576
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
577
+						'filename' => 'messages_settings_message_types',
578
+					],
579
+					'messages_settings_messengers_help_tab'    => [
580
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
581
+						'filename' => 'messages_settings_messengers',
582
+					],
583
+				],
584
+				'require_nonce' => false,
585
+			],
586
+		];
587
+	}
588
+
589
+
590
+	protected function _add_screen_options()
591
+	{
592
+		// todo
593
+	}
594
+
595
+
596
+	protected function _add_screen_options_global_mtps()
597
+	{
598
+		/**
599
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
600
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
601
+		 */
602
+		$page_title              = $this->_admin_page_title;
603
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
604
+		$this->_per_page_screen_option();
605
+		$this->_admin_page_title = $page_title;
606
+	}
607
+
608
+
609
+	protected function _add_screen_options_default()
610
+	{
611
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
612
+		$this->_per_page_screen_option();
613
+	}
614
+
615
+
616
+	// none of the below group are currently used for Messages
617
+	protected function _add_feature_pointers()
618
+	{
619
+	}
620
+
621
+
622
+	public function admin_init()
623
+	{
624
+	}
625
+
626
+
627
+	public function admin_notices()
628
+	{
629
+	}
630
+
631
+
632
+	public function admin_footer_scripts()
633
+	{
634
+	}
635
+
636
+
637
+	public function messages_help_tab()
638
+	{
639
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
640
+	}
641
+
642
+
643
+	public function messengers_help_tab()
644
+	{
645
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
646
+	}
647
+
648
+
649
+	public function message_types_help_tab()
650
+	{
651
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
652
+	}
653
+
654
+
655
+	public function messages_overview_help_tab()
656
+	{
657
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
658
+	}
659
+
660
+
661
+	public function message_templates_help_tab()
662
+	{
663
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
664
+	}
665
+
666
+
667
+	public function edit_message_template_help_tab()
668
+	{
669
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
670
+						. esc_attr__('Editor Title', 'event_espresso')
671
+						. '" />';
672
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
673
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
674
+						. '" />';
675
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
676
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
677
+						. '" />';
678
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
679
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
680
+						. '" />';
681
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
682
+						. esc_attr__('Publish Metabox', 'event_espresso')
683
+						. '" />';
684
+		EEH_Template::display_template(
685
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
686
+			$args
687
+		);
688
+	}
689
+
690
+
691
+	/**
692
+	 * @throws ReflectionException
693
+	 * @throws EE_Error
694
+	 */
695
+	public function message_template_shortcodes_help_tab()
696
+	{
697
+		$this->_set_shortcodes();
698
+		$args['shortcodes'] = $this->_shortcodes;
699
+		EEH_Template::display_template(
700
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
701
+			$args
702
+		);
703
+	}
704
+
705
+
706
+	public function preview_message_help_tab()
707
+	{
708
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
709
+	}
710
+
711
+
712
+	public function settings_help_tab()
713
+	{
714
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
715
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
716
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
717
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
718
+		$args['img3'] = '<div class="ee-switch">'
719
+						. '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
720
+						. '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
721
+						. '</div>';
722
+		$args['img4'] = '<div class="switch">'
723
+						. '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
724
+						. '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
725
+						. '</div>';
726
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
727
+	}
728
+
729
+
730
+	public function load_scripts_styles()
731
+	{
732
+		wp_enqueue_style(
733
+			'espresso_ee_msg',
734
+			EE_MSG_ASSETS_URL . 'ee_message_admin.css',
735
+			[EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
736
+			EVENT_ESPRESSO_VERSION
737
+		);
738
+		wp_enqueue_style(
739
+			'ee_message_shortcodes',
740
+			EE_MSG_ASSETS_URL . 'ee_message_shortcodes.css',
741
+			[EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
742
+			EVENT_ESPRESSO_VERSION
743
+		);
744
+
745
+		wp_register_script(
746
+			'ee-messages-settings',
747
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
748
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
749
+			EVENT_ESPRESSO_VERSION,
750
+			true
751
+		);
752
+		wp_register_script(
753
+			'ee-msg-list-table-js',
754
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
755
+			['ee-dialog'],
756
+			EVENT_ESPRESSO_VERSION
757
+		);
758
+	}
759
+
760
+
761
+	public function load_scripts_styles_default()
762
+	{
763
+		wp_enqueue_script('ee-msg-list-table-js');
764
+	}
765
+
766
+
767
+	public function wp_editor_css($mce_css)
768
+	{
769
+		// if we're on the edit_message_template route
770
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
771
+			$message_type_name = $this->_active_message_type_name;
772
+
773
+			// we're going to REPLACE the existing mce css
774
+			// we need to get the css file location from the active messenger
775
+			$mce_css = $this->_active_messenger->get_variation(
776
+				$this->_template_pack,
777
+				$message_type_name,
778
+				true,
779
+				'wpeditor',
780
+				$this->_variation
781
+			);
782
+		}
783
+
784
+		return $mce_css;
785
+	}
786
+
787
+
788
+	/**
789
+	 * @throws EE_Error
790
+	 * @throws ReflectionException
791
+	 */
792
+	public function load_scripts_styles_edit_message_template()
793
+	{
794
+		$this->_set_shortcodes();
795
+
796
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
797
+			esc_html__(
798
+				'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.',
799
+				'event_espresso'
800
+			),
801
+			$this->_message_template_group->messenger_obj()->label['singular'],
802
+			$this->_message_template_group->message_type_obj()->label['singular']
803
+		);
804
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
805
+			'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?',
806
+			'event_espresso'
807
+		);
808
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
809
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
810
+			'event_espresso'
811
+		);
812
+
813
+		wp_register_script(
814
+			'ee_msgs_edit_js',
815
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
816
+			['jquery'],
817
+			EVENT_ESPRESSO_VERSION
818
+		);
819
+
820
+		wp_enqueue_script('ee_admin_js');
821
+		wp_enqueue_script('ee_msgs_edit_js');
822
+
823
+		// add in special css for tiny_mce
824
+		add_filter('mce_css', [$this, 'wp_editor_css']);
825
+	}
826
+
827
+
828
+	/**
829
+	 * @throws EE_Error
830
+	 * @throws ReflectionException
831
+	 */
832
+	public function load_scripts_styles_display_preview_message()
833
+	{
834
+		$this->_set_message_template_group();
835
+		if ($this->_active_messenger_name) {
836
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
837
+				$this->_active_messenger_name
838
+			);
839
+		}
840
+
841
+		wp_enqueue_style(
842
+			'espresso_preview_css',
843
+			$this->_active_messenger->get_variation(
844
+				$this->_template_pack,
845
+				$this->_active_message_type_name,
846
+				true,
847
+				'preview',
848
+				$this->_variation
849
+			)
850
+		);
851
+	}
852
+
853
+
854
+	public function load_scripts_styles_settings()
855
+	{
856
+		wp_register_style(
857
+			'ee-message-settings',
858
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
859
+			[],
860
+			EVENT_ESPRESSO_VERSION
861
+		);
862
+		wp_enqueue_style('ee-text-links');
863
+		wp_enqueue_style('ee-message-settings');
864
+		wp_enqueue_script('ee-messages-settings');
865
+	}
866
+
867
+
868
+	/**
869
+	 * set views array for List Table
870
+	 */
871
+	public function _set_list_table_views_global_mtps()
872
+	{
873
+		$this->_views = [
874
+			'in_use' => [
875
+				'slug'  => 'in_use',
876
+				'label' => esc_html__('In Use', 'event_espresso'),
877
+				'count' => 0,
878
+			],
879
+		];
880
+	}
881
+
882
+
883
+	/**
884
+	 * Set views array for the Custom Template List Table
885
+	 */
886
+	public function _set_list_table_views_custom_mtps()
887
+	{
888
+		$this->_set_list_table_views_global_mtps();
889
+		$this->_views['in_use']['bulk_action'] = [
890
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
891
+		];
892
+	}
893
+
894
+
895
+	/**
896
+	 * set views array for message queue list table
897
+	 *
898
+	 * @throws InvalidDataTypeException
899
+	 * @throws InvalidInterfaceException
900
+	 * @throws InvalidArgumentException
901
+	 * @throws EE_Error
902
+	 * @throws ReflectionException
903
+	 */
904
+	public function _set_list_table_views_default()
905
+	{
906
+		EE_Registry::instance()->load_helper('Template');
907
+
908
+		$common_bulk_actions = $this->capabilities->current_user_can(
909
+			'ee_send_message',
910
+			'message_list_table_bulk_actions'
911
+		)
912
+			? [
913
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
914
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
915
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
916
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
917
+			]
918
+			: [];
919
+
920
+		$delete_bulk_action = $this->capabilities->current_user_can(
921
+			'ee_delete_messages',
922
+			'message_list_table_bulk_actions'
923
+		)
924
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
925
+			: [];
926
+
927
+
928
+		$this->_views = [
929
+			'all' => [
930
+				'slug'        => 'all',
931
+				'label'       => esc_html__('All', 'event_espresso'),
932
+				'count'       => 0,
933
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
934
+			],
935
+		];
936
+
937
+
938
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
939
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
940
+				continue;
941
+			}
942
+			$status_bulk_actions = $common_bulk_actions;
943
+			// unset bulk actions not applying to status
944
+			if (! empty($status_bulk_actions)) {
945
+				switch ($status) {
946
+					case EEM_Message::status_idle:
947
+					case EEM_Message::status_resend:
948
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
949
+						break;
950
+
951
+					case EEM_Message::status_failed:
952
+					case EEM_Message::status_debug_only:
953
+					case EEM_Message::status_messenger_executing:
954
+						$status_bulk_actions = [];
955
+						break;
956
+
957
+					case EEM_Message::status_incomplete:
958
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
959
+						break;
960
+
961
+					case EEM_Message::status_retry:
962
+					case EEM_Message::status_sent:
963
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
964
+						break;
965
+				}
966
+			}
967
+
968
+			// skip adding messenger executing status to views because it will be included with the Failed view.
969
+			if ($status === EEM_Message::status_messenger_executing) {
970
+				continue;
971
+			}
972
+
973
+			$this->_views[ strtolower($status) ] = [
974
+				'slug'        => strtolower($status),
975
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
976
+				'count'       => 0,
977
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
978
+			];
979
+		}
980
+	}
981
+
982
+
983
+	/**
984
+	 * @throws EE_Error
985
+	 */
986
+	protected function _ee_default_messages_overview_list_table()
987
+	{
988
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
989
+		$this->display_admin_list_table_page_with_no_sidebar();
990
+	}
991
+
992
+
993
+	/**
994
+	 * @throws EE_Error
995
+	 * @throws ReflectionException
996
+	 */
997
+	protected function _message_queue_list_table()
998
+	{
999
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1000
+		$this->_template_args['per_column']        = 6;
1001
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1002
+		$message_results                           = trim(EEM_Message::instance()->get_pretty_label_for_results());
1003
+		$this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1004
+		$this->display_admin_list_table_page_with_no_sidebar();
1005
+	}
1006
+
1007
+
1008
+	/**
1009
+	 * @throws EE_Error
1010
+	 */
1011
+	protected function _message_legend_items()
1012
+	{
1013
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1014
+		$action_items       = [];
1015
+
1016
+		foreach ($action_css_classes as $action_item => $action_details) {
1017
+			if ($action_item === 'see_notifications_for') {
1018
+				continue;
1019
+			}
1020
+			$action_items[ $action_item ] = [
1021
+				'class' => $action_details['css_class'],
1022
+				'desc'  => $action_details['label'],
1023
+			];
1024
+		}
1025
+
1026
+		/** @var array $status_items status legend setup */
1027
+		$status_items = [
1028
+			'sent_status'                => [
1029
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1030
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1031
+			],
1032
+			'idle_status'                => [
1033
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1034
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1035
+			],
1036
+			'failed_status'              => [
1037
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1038
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1039
+			],
1040
+			'messenger_executing_status' => [
1041
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1042
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1043
+			],
1044
+			'resend_status'              => [
1045
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1046
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1047
+			],
1048
+			'incomplete_status'          => [
1049
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1050
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1051
+			],
1052
+			'retry_status'               => [
1053
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1054
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1055
+			],
1056
+		];
1057
+		if (EEM_Message::debug()) {
1058
+			$status_items['debug_only_status'] = [
1059
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1060
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1061
+			];
1062
+		}
1063
+
1064
+		return array_merge($action_items, $status_items);
1065
+	}
1066
+
1067
+
1068
+	/**
1069
+	 * @throws EE_Error
1070
+	 */
1071
+	protected function _custom_mtps_preview()
1072
+	{
1073
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1074
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1075
+												. ' alt="' . esc_attr__(
1076
+													'Preview Custom Message Templates screenshot',
1077
+													'event_espresso'
1078
+												) . '" />';
1079
+		$this->_template_args['preview_text'] = '<strong>'
1080
+												. esc_html__(
1081
+													'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.',
1082
+													'event_espresso'
1083
+												)
1084
+												. '</strong>';
1085
+
1086
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1087
+	}
1088
+
1089
+
1090
+	/**
1091
+	 * get_message_templates
1092
+	 * This gets all the message templates for listing on the overview list.
1093
+	 *
1094
+	 * @param int    $per_page the amount of templates groups to show per page
1095
+	 * @param string $type     the current _view we're getting templates for
1096
+	 * @param bool   $count    return count?
1097
+	 * @param bool   $all      disregard any paging info (get all data);
1098
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1099
+	 * @return array|int
1100
+	 * @throws EE_Error
1101
+	 * @throws InvalidArgumentException
1102
+	 * @throws InvalidDataTypeException
1103
+	 * @throws InvalidInterfaceException
1104
+	 * @throws ReflectionException
1105
+	 */
1106
+	public function get_message_templates(
1107
+		int $per_page = 10,
1108
+		string $type = 'in_use',
1109
+		bool $count = false,
1110
+		bool $all = false,
1111
+		bool $global = true
1112
+	) {
1113
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1114
+		// ensure that the orderby param is actually set within the request data
1115
+		$this->request->setRequestParam('orderby', $orderby);
1116
+		$order        = $this->request->getRequestParam('order', 'ASC');
1117
+		$current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
1118
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
1119
+
1120
+		$offset = ($current_page - 1) * $per_page;
1121
+		$limit  = $all ? null : [$offset, $per_page];
1122
+
1123
+		// options will match what is in the _views array property
1124
+		return $type === 'in_use'
1125
+			? $this->getMtgModel()->get_all_active_message_templates(
1126
+				$orderby,
1127
+				$order,
1128
+				$limit,
1129
+				$count,
1130
+				$global,
1131
+				true
1132
+			)
1133
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1134
+				$orderby,
1135
+				$order,
1136
+				$limit,
1137
+				$count,
1138
+				$global
1139
+			);
1140
+	}
1141
+
1142
+
1143
+	/**
1144
+	 * filters etc might need a list of installed message_types
1145
+	 *
1146
+	 * @return array an array of message type objects
1147
+	 */
1148
+	public function get_installed_message_types(): array
1149
+	{
1150
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1151
+		$installed               = [];
1152
+
1153
+		foreach ($installed_message_types as $message_type) {
1154
+			$installed[ $message_type->name ] = $message_type;
1155
+		}
1156
+
1157
+		return $installed;
1158
+	}
1159
+
1160
+
1161
+	/**
1162
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1163
+	 *
1164
+	 * @param string     $message_type
1165
+	 * @param string     $messenger
1166
+	 * @param int|string $GRP_ID
1167
+	 * @throws EE_error
1168
+	 * @throws ReflectionException
1169
+	 * @deprecated 5.0.8.p
1170
+	 */
1171
+	public function add_message_template(string $message_type = '', string $messenger = '', $GRP_ID = '')
1172
+	{
1173
+		$this->insertMessageTemplate();
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * @param string $message_type     message type slug
1179
+	 * @param string $messenger        messenger slug
1180
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1181
+	 *                                 off of.
1182
+	 * @throws EE_error
1183
+	 * @throws ReflectionException
1184
+	 * @deprecated 4.10.29.p
1185
+	 */
1186
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1187
+	{
1188
+		$this->insertMessageTemplate($message_type, $messenger, $GRP_ID);
1189
+	}
1190
+
1191
+
1192
+	/**
1193
+	 * _edit_message_template
1194
+	 *
1195
+	 * @access protected
1196
+	 * @return void
1197
+	 * @throws InvalidIdentifierException
1198
+	 * @throws DomainException
1199
+	 * @throws EE_Error
1200
+	 * @throws InvalidArgumentException
1201
+	 * @throws ReflectionException
1202
+	 * @throws InvalidDataTypeException
1203
+	 * @throws InvalidInterfaceException
1204
+	 */
1205
+	protected function _edit_message_template()
1206
+	{
1207
+		$template_fields = '';
1208
+		$sidebar_fields  = '';
1209
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1210
+		// valid html in the templates.
1211
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1212
+
1213
+		$GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
1214
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', $GRP_ID, DataType::INTEGER);
1215
+
1216
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, DataType::INTEGER);
1217
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, DataType::INTEGER);
1218
+
1219
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1220
+		$message_template_group = $this->_message_template_group;
1221
+		$c_label                = $message_template_group->context_label();
1222
+		$c_config               = $message_template_group->contexts_config();
1223
+
1224
+		reset($c_config);
1225
+		$context = $this->request->getRequestParam('context', key($c_config));
1226
+		$context = strtolower($context);
1227
+
1228
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1229
+
1230
+		$edit_message_template_form_url = add_query_arg(
1231
+			['action' => $action, 'noheader' => true],
1232
+			EE_MSG_ADMIN_URL
1233
+		);
1234
+
1235
+		// set active messenger for this view
1236
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1237
+			$message_template_group->messenger()
1238
+		);
1239
+		$this->_active_message_type_name = $message_template_group->message_type();
1240
+
1241
+
1242
+		// Do we have any validation errors?
1243
+		$validators = $this->_get_transient();
1244
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1245
+
1246
+
1247
+		// we need to assemble the title from Various details
1248
+		$context_label = sprintf(
1249
+			esc_html__('(%s %s)', 'event_espresso'),
1250
+			$c_config[ $context ]['label'],
1251
+			ucwords($c_label['label'])
1252
+		);
1253
+
1254
+		$title = sprintf(
1255
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1256
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1257
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1258
+			$context_label
1259
+		);
1260
+
1261
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1262
+		$this->_template_args['message_template'] = $message_template_group;
1263
+		$this->_template_args['is_extra_fields']  = false;
1264
+
1265
+
1266
+		// let's get EEH_MSG_Template so we can get template form fields
1267
+		$template_field_structure = EEH_MSG_Template::get_fields(
1268
+			$message_template_group->messenger(),
1269
+			$message_template_group->message_type()
1270
+		);
1271
+
1272
+		if (! $template_field_structure) {
1273
+			$template_field_structure = false;
1274
+			$template_fields          = esc_html__(
1275
+				'There was an error in assembling the fields for this display (you should see an error message)',
1276
+				'event_espresso'
1277
+			);
1278
+		}
1279
+
1280
+		$message_templates = $message_template_group->context_templates();
1281
+
1282
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1283
+		// will get handled in the "extra" array.
1284
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1285
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1286
+				unset($template_field_structure[ $context ][ $reference_field ]);
1287
+			}
1288
+		}
1289
+
1290
+		// let's loop through the template_field_structure and actually assemble the input fields!
1291
+		if (! empty($template_field_structure)) {
1292
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1293
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1294
+				// the extra array and reset them.
1295
+				if ($template_field === 'extra') {
1296
+					$this->_template_args['is_extra_fields'] = true;
1297
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1298
+						$message_template = $message_templates[ $context ][ $reference_field ];
1299
+						$content          = $message_template instanceof EE_Message_Template
1300
+							? $message_template->get('MTP_content')
1301
+							: '';
1302
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1303
+							// let's verify if we need this extra field via the shortcodes parameter.
1304
+							$continue = false;
1305
+							if (isset($extra_array['shortcodes_required'])) {
1306
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1307
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1308
+										$continue = true;
1309
+									}
1310
+								}
1311
+								if ($continue) {
1312
+									continue;
1313
+								}
1314
+							}
1315
+
1316
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1317
+
1318
+							$template_form_fields[ $field_id ]         = $extra_array;
1319
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1320
+																		 . $reference_field
1321
+																		 . '][content]['
1322
+																		 . $extra_field . ']';
1323
+							$css_class                                 = $extra_array['css_class'] ?? '';
1324
+
1325
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1326
+																			  && in_array($extra_field, $v_fields, true)
1327
+																			  && (
1328
+																				  is_array($validators[ $extra_field ])
1329
+																				  && isset($validators[ $extra_field ]['msg'])
1330
+																			  )
1331
+								? 'validate-error ' . $css_class
1332
+								: $css_class;
1333
+
1334
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1335
+																		  && isset($content[ $extra_field ])
1336
+								? $content[ $extra_field ]
1337
+								: '';
1338
+
1339
+							// do we have a validation error?  if we do then let's use that value instead
1340
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1341
+								? $validators[ $extra_field ]['value']
1342
+								: $template_form_fields[ $field_id ]['value'];
1343
+
1344
+
1345
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1346
+
1347
+							// shortcode selector
1348
+							$field_name_to_use                                   = $extra_field === 'main'
1349
+								? 'content'
1350
+								: $extra_field;
1351
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1352
+								$field_name_to_use,
1353
+								$field_id
1354
+							);
1355
+						}
1356
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1357
+						$template_field_template_name_id = $reference_field . '-name';
1358
+
1359
+						$template_form_fields[ $template_field_MTP_id ] = [
1360
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1361
+							'label'      => null,
1362
+							'input'      => 'hidden',
1363
+							'type'       => 'int',
1364
+							'required'   => false,
1365
+							'validation' => false,
1366
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1367
+							'css_class'  => '',
1368
+							'format'     => '%d',
1369
+							'db-col'     => 'MTP_ID',
1370
+						];
1371
+
1372
+						$template_form_fields[ $template_field_template_name_id ] = [
1373
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1374
+							'label'      => null,
1375
+							'input'      => 'hidden',
1376
+							'type'       => 'string',
1377
+							'required'   => false,
1378
+							'validation' => true,
1379
+							'value'      => $reference_field,
1380
+							'css_class'  => '',
1381
+							'format'     => '%s',
1382
+							'db-col'     => 'MTP_template_field',
1383
+						];
1384
+					}
1385
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1386
+				} else {
1387
+					$field_id                                   = $template_field . '-content';
1388
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1389
+					$template_form_fields[ $field_id ]['name']  =
1390
+						'MTP_template_fields[' . $template_field . '][content]';
1391
+					$message_template                           =
1392
+						$message_templates[ $context ][ $template_field ] ?? null;
1393
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1394
+																  && is_array($message_templates[ $context ])
1395
+																  && $message_template instanceof EE_Message_Template
1396
+						? $message_template->get('MTP_content')
1397
+						: '';
1398
+
1399
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1400
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1401
+						? $validators[ $template_field ]['value']
1402
+						: $template_form_fields[ $field_id ]['value'];
1403
+
1404
+
1405
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1406
+					$css_class                                      = $field_setup_array['css_class'] ?? '';
1407
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1408
+																	  && in_array($template_field, $v_fields, true)
1409
+																	  && isset($validators[ $template_field ]['msg'])
1410
+						? 'validate-error ' . $css_class
1411
+						: $css_class;
1412
+
1413
+					// shortcode selector
1414
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1415
+						$template_field,
1416
+						$field_id
1417
+					);
1418
+				}
1419
+
1420
+				// k took care of content field(s) now let's take care of others.
1421
+
1422
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1423
+				$template_field_field_template_name_id = $template_field . '-name';
1424
+
1425
+				// foreach template field there are actually two form fields created
1426
+				$template_form_fields[ $template_field_MTP_id ] = [
1427
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1428
+					'label'      => null,
1429
+					'input'      => 'hidden',
1430
+					'type'       => 'int',
1431
+					'required'   => false,
1432
+					'validation' => true,
1433
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1434
+					'css_class'  => '',
1435
+					'format'     => '%d',
1436
+					'db-col'     => 'MTP_ID',
1437
+				];
1438
+
1439
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1440
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1441
+					'label'      => null,
1442
+					'input'      => 'hidden',
1443
+					'type'       => 'string',
1444
+					'required'   => false,
1445
+					'validation' => true,
1446
+					'value'      => $template_field,
1447
+					'css_class'  => '',
1448
+					'format'     => '%s',
1449
+					'db-col'     => 'MTP_template_field',
1450
+				];
1451
+			}
1452
+
1453
+			// add other fields
1454
+			$template_form_fields['ee-msg-current-context'] = [
1455
+				'name'       => 'MTP_context',
1456
+				'label'      => null,
1457
+				'input'      => 'hidden',
1458
+				'type'       => 'string',
1459
+				'required'   => false,
1460
+				'validation' => true,
1461
+				'value'      => $context,
1462
+				'css_class'  => '',
1463
+				'format'     => '%s',
1464
+				'db-col'     => 'MTP_context',
1465
+			];
1466
+
1467
+			$template_form_fields['ee-msg-grp-id'] = [
1468
+				'name'       => 'GRP_ID',
1469
+				'label'      => null,
1470
+				'input'      => 'hidden',
1471
+				'type'       => 'int',
1472
+				'required'   => false,
1473
+				'validation' => true,
1474
+				'value'      => $GRP_ID,
1475
+				'css_class'  => '',
1476
+				'format'     => '%d',
1477
+				'db-col'     => 'GRP_ID',
1478
+			];
1479
+
1480
+			$template_form_fields['ee-msg-messenger'] = [
1481
+				'name'       => 'MTP_messenger',
1482
+				'label'      => null,
1483
+				'input'      => 'hidden',
1484
+				'type'       => 'string',
1485
+				'required'   => false,
1486
+				'validation' => true,
1487
+				'value'      => $message_template_group->messenger(),
1488
+				'css_class'  => '',
1489
+				'format'     => '%s',
1490
+				'db-col'     => 'MTP_messenger',
1491
+			];
1492
+
1493
+			$template_form_fields['ee-msg-message-type'] = [
1494
+				'name'       => 'MTP_message_type',
1495
+				'label'      => null,
1496
+				'input'      => 'hidden',
1497
+				'type'       => 'string',
1498
+				'required'   => false,
1499
+				'validation' => true,
1500
+				'value'      => $message_template_group->message_type(),
1501
+				'css_class'  => '',
1502
+				'format'     => '%s',
1503
+				'db-col'     => 'MTP_message_type',
1504
+			];
1505
+
1506
+			$sidebar_form_fields['ee-msg-is-global'] = [
1507
+				'name'       => 'MTP_is_global',
1508
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1509
+				'input'      => 'hidden',
1510
+				'type'       => 'int',
1511
+				'required'   => false,
1512
+				'validation' => true,
1513
+				'value'      => $message_template_group->get('MTP_is_global'),
1514
+				'css_class'  => '',
1515
+				'format'     => '%d',
1516
+				'db-col'     => 'MTP_is_global',
1517
+			];
1518
+
1519
+			$sidebar_form_fields['ee-msg-is-override'] = [
1520
+				'name'       => 'MTP_is_override',
1521
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1522
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1523
+				'type'       => 'int',
1524
+				'required'   => false,
1525
+				'validation' => true,
1526
+				'value'      => $message_template_group->get('MTP_is_override'),
1527
+				'css_class'  => '',
1528
+				'format'     => '%d',
1529
+				'db-col'     => 'MTP_is_override',
1530
+			];
1531
+
1532
+			$sidebar_form_fields['ee-msg-is-active'] = [
1533
+				'name'       => 'MTP_is_active',
1534
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1535
+				'input'      => 'hidden',
1536
+				'type'       => 'int',
1537
+				'required'   => false,
1538
+				'validation' => true,
1539
+				'value'      => $message_template_group->is_active(),
1540
+				'css_class'  => '',
1541
+				'format'     => '%d',
1542
+				'db-col'     => 'MTP_is_active',
1543
+			];
1544
+
1545
+			$sidebar_form_fields['ee-msg-deleted'] = [
1546
+				'name'       => 'MTP_deleted',
1547
+				'label'      => null,
1548
+				'input'      => 'hidden',
1549
+				'type'       => 'int',
1550
+				'required'   => false,
1551
+				'validation' => true,
1552
+				'value'      => $message_template_group->get('MTP_deleted'),
1553
+				'css_class'  => '',
1554
+				'format'     => '%d',
1555
+				'db-col'     => 'MTP_deleted',
1556
+			];
1557
+			$sidebar_form_fields['ee-msg-author']  = [
1558
+				'name'       => 'MTP_user_id',
1559
+				'label'      => esc_html__('Author', 'event_espresso'),
1560
+				'input'      => 'hidden',
1561
+				'type'       => 'int',
1562
+				'required'   => false,
1563
+				'validation' => false,
1564
+				'value'      => $message_template_group->user(),
1565
+				'format'     => '%d',
1566
+				'db-col'     => 'MTP_user_id',
1567
+			];
1568
+
1569
+			$sidebar_form_fields['ee-msg-route'] = [
1570
+				'name'  => 'action',
1571
+				'input' => 'hidden',
1572
+				'type'  => 'string',
1573
+				'value' => $action,
1574
+			];
1575
+
1576
+			$sidebar_form_fields['ee-msg-id']        = [
1577
+				'name'  => 'id',
1578
+				'input' => 'hidden',
1579
+				'type'  => 'int',
1580
+				'value' => $GRP_ID,
1581
+			];
1582
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1583
+				'name'  => $action . '_nonce',
1584
+				'input' => 'hidden',
1585
+				'type'  => 'string',
1586
+				'value' => wp_create_nonce($action . '_nonce'),
1587
+			];
1588
+
1589
+			$template_switch = $this->request->getRequestParam('template_switch');
1590
+			if ($template_switch) {
1591
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1592
+					'name'  => 'template_switch',
1593
+					'input' => 'hidden',
1594
+					'type'  => 'int',
1595
+					'value' => 1,
1596
+				];
1597
+			}
1598
+
1599
+
1600
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1601
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1602
+		} //end if ( !empty($template_field_structure) )
1603
+
1604
+		// set extra content for publish box
1605
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1606
+		$this->_set_publish_post_box_vars(
1607
+			'id',
1608
+			$GRP_ID,
1609
+			'',
1610
+			add_query_arg(
1611
+				['action' => $message_template_group->is_global() ? 'global_mtps' : 'custom_mtps'],
1612
+				$this->_admin_base_url
1613
+			),
1614
+			true
1615
+		);
1616
+
1617
+		// add preview button
1618
+		$preview_url    = parent::add_query_args_and_nonce(
1619
+			[
1620
+				'message_type' => $message_template_group->message_type(),
1621
+				'messenger'    => $message_template_group->messenger(),
1622
+				'context'      => $context,
1623
+				'GRP_ID'       => $GRP_ID,
1624
+				'evt_id'       => $EVT_ID ?: false,
1625
+				'action'       => 'preview_message',
1626
+			],
1627
+			$this->_admin_base_url
1628
+		);
1629
+		$preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1630
+						  . esc_html__('Preview', 'event_espresso')
1631
+						  . '</a>';
1632
+
1633
+
1634
+		// setup context switcher
1635
+		$this->_set_context_switcher(
1636
+			$message_template_group,
1637
+			[
1638
+				'page'    => 'espresso_messages',
1639
+				'action'  => 'edit_message_template',
1640
+				'id'      => $GRP_ID,
1641
+				'evt_id'  => $EVT_ID,
1642
+				'context' => $context,
1643
+				'extra'   => $preview_button,
1644
+			]
1645
+		);
1646
+
1647
+		// main box
1648
+		$this->_template_args['template_fields']                         = $template_fields;
1649
+		$this->_template_args['sidebar_box_id']                          = 'details';
1650
+		$this->_template_args['action']                                  = $action;
1651
+		$this->_template_args['context']                                 = $context;
1652
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1653
+		$this->_template_args['learn_more_about_message_templates_link'] =
1654
+			$this->_learn_more_about_message_templates_link();
1655
+
1656
+		$this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1657
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1658
+			$message_template_group,
1659
+			$context,
1660
+			$context_label
1661
+		);
1662
+		$this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1663
+		$this->_template_args['before_admin_page_content'] .= '</div>';
1664
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1665
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1666
+
1667
+		$this->_template_path = $this->_template_args['GRP_ID']
1668
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1669
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1670
+
1671
+		// send along EE_Message_Template_Group object for further template use.
1672
+		$this->_template_args['MTP'] = $message_template_group;
1673
+
1674
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1675
+			$this->_template_path,
1676
+			$this->_template_args,
1677
+			true
1678
+		);
1679
+
1680
+		// finally, let's set the admin_page title
1681
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1682
+
1683
+		// we need to take care of setting the shortcodes property for use elsewhere.
1684
+		$this->_set_shortcodes();
1685
+
1686
+		// final template wrapper
1687
+		$this->display_admin_page_with_sidebar();
1688
+	}
1689
+
1690
+
1691
+	public function filter_tinymce_init($mceInit, $editor_id)
1692
+	{
1693
+		return $mceInit;
1694
+	}
1695
+
1696
+
1697
+	public function add_context_switcher()
1698
+	{
1699
+		return $this->_context_switcher;
1700
+	}
1701
+
1702
+
1703
+	/**
1704
+	 * Adds the activation/deactivation toggle for the message template context.
1705
+	 *
1706
+	 * @param EE_Message_Template_Group $message_template_group
1707
+	 * @param string                    $context
1708
+	 * @param string                    $context_label
1709
+	 * @return string
1710
+	 * @throws DomainException
1711
+	 * @throws EE_Error
1712
+	 * @throws InvalidIdentifierException
1713
+	 * @throws ReflectionException
1714
+	 */
1715
+	protected function add_active_context_element(
1716
+		EE_Message_Template_Group $message_template_group,
1717
+		$context,
1718
+		$context_label
1719
+	) {
1720
+		$template_args = [
1721
+			'context'                   => $context,
1722
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1723
+			'is_active'                 => $message_template_group->is_context_active($context),
1724
+			'on_off_action'             => $message_template_group->is_context_active($context)
1725
+				? 'context-off'
1726
+				: 'context-on',
1727
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1728
+			'message_template_group_id' => $message_template_group->ID(),
1729
+		];
1730
+		return EEH_Template::display_template(
1731
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1732
+			$template_args,
1733
+			true
1734
+		);
1735
+	}
1736
+
1737
+
1738
+	/**
1739
+	 * Ajax callback for `toggle_context_template` ajax action.
1740
+	 * Handles toggling the message context on or off.
1741
+	 *
1742
+	 * @throws EE_Error
1743
+	 * @throws InvalidArgumentException
1744
+	 * @throws InvalidDataTypeException
1745
+	 * @throws InvalidIdentifierException
1746
+	 * @throws InvalidInterfaceException
1747
+	 * @throws ReflectionException
1748
+	 */
1749
+	public function toggle_context_template()
1750
+	{
1751
+		if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
1752
+			wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
1753
+		}
1754
+		$success = true;
1755
+		// check for required data
1756
+		if (
1757
+			! (
1758
+				$this->request->requestParamIsSet('message_template_group_id')
1759
+				&& $this->request->requestParamIsSet('context')
1760
+				&& $this->request->requestParamIsSet('status')
1761
+			)
1762
+		) {
1763
+			EE_Error::add_error(
1764
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1765
+				__FILE__,
1766
+				__FUNCTION__,
1767
+				__LINE__
1768
+			);
1769
+			$success = false;
1770
+		}
1771
+
1772
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1773
+		$context = $this->request->getRequestParam('context', '');
1774
+		$status  = $this->request->getRequestParam('status', '');
1775
+
1776
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1777
+
1778
+		if ($status !== 'off' && $status !== 'on') {
1779
+			EE_Error::add_error(
1780
+				sprintf(
1781
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1782
+					$status
1783
+				),
1784
+				__FILE__,
1785
+				__FUNCTION__,
1786
+				__LINE__
1787
+			);
1788
+			$success = false;
1789
+		}
1790
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, DataType::INTEGER);
1791
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1792
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1793
+			EE_Error::add_error(
1794
+				sprintf(
1795
+					esc_html__(
1796
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1797
+						'event_espresso'
1798
+					),
1799
+					$message_template_group_id,
1800
+					'EE_Message_Template_Group'
1801
+				),
1802
+				__FILE__,
1803
+				__FUNCTION__,
1804
+				__LINE__
1805
+			);
1806
+			$success = false;
1807
+		}
1808
+		if ($success) {
1809
+			$success = $status === 'off'
1810
+				? $message_template_group->deactivate_context($context)
1811
+				: $message_template_group->activate_context($context);
1812
+		}
1813
+		$this->_template_args['success'] = $success;
1814
+		$this->_return_json();
1815
+	}
1816
+
1817
+
1818
+	public function _add_form_element_before()
1819
+	{
1820
+		return '<form method="post" action="'
1821
+			   . $this->_template_args['edit_message_template_form_url']
1822
+			   . '" id="ee-msg-edit-frm">';
1823
+	}
1824
+
1825
+
1826
+	public function _add_form_element_after()
1827
+	{
1828
+		return '</form>';
1829
+	}
1830
+
1831
+
1832
+	/**
1833
+	 * This executes switching the template pack for a message template.
1834
+	 *
1835
+	 * @throws EE_Error
1836
+	 * @throws InvalidDataTypeException
1837
+	 * @throws InvalidInterfaceException
1838
+	 * @throws InvalidArgumentException
1839
+	 * @throws ReflectionException
1840
+	 * @since 4.5.0
1841
+	 */
1842
+	public function switch_template_pack()
1843
+	{
1844
+		if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
1845
+			wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
1846
+		}
1847
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
1848
+		$template_pack = $this->request->getRequestParam('template_pack', '');
1849
+
1850
+		// verify we have needed values.
1851
+		if (empty($GRP_ID) || empty($template_pack)) {
1852
+			$this->_template_args['error'] = true;
1853
+			EE_Error::add_error(
1854
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1855
+				__FILE__,
1856
+				__FUNCTION__,
1857
+				__LINE__
1858
+			);
1859
+		} else {
1860
+			// get template, set the new template_pack and then reset to default
1861
+			/** @var EE_Message_Template_Group $message_template_group */
1862
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
1863
+
1864
+			$message_template_group->set_template_pack_name($template_pack);
1865
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
1866
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
1867
+
1868
+			$query_args = $this->_reset_to_default_template();
1869
+
1870
+			if (empty($query_args['id'])) {
1871
+				EE_Error::add_error(
1872
+					esc_html__(
1873
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1874
+						'event_espresso'
1875
+					),
1876
+					__FILE__,
1877
+					__FUNCTION__,
1878
+					__LINE__
1879
+				);
1880
+				$this->_template_args['error'] = true;
1881
+			} else {
1882
+				$template_label       = $message_template_group->get_template_pack()->label;
1883
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1884
+				EE_Error::add_success(
1885
+					sprintf(
1886
+						esc_html__(
1887
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1888
+							'event_espresso'
1889
+						),
1890
+						$template_label,
1891
+						$template_pack_labels->template_pack
1892
+					)
1893
+				);
1894
+				// generate the redirect url for js.
1895
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1896
+
1897
+				$this->_template_args['data']['redirect_url'] = $url;
1898
+				$this->_template_args['success']              = true;
1899
+			}
1900
+
1901
+			$this->_return_json();
1902
+		}
1903
+	}
1904
+
1905
+
1906
+	/**
1907
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1908
+	 * they want.
1909
+	 *
1910
+	 * @access protected
1911
+	 * @return array|void
1912
+	 * @throws EE_Error
1913
+	 * @throws InvalidArgumentException
1914
+	 * @throws InvalidDataTypeException
1915
+	 * @throws InvalidInterfaceException
1916
+	 * @throws ReflectionException
1917
+	 */
1918
+	protected function _reset_to_default_template()
1919
+	{
1920
+		$templates    = [];
1921
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
1922
+		$messenger    = $this->request->getRequestParam('msgr');
1923
+		$message_type = $this->request->getRequestParam('mt');
1924
+		// we need to make sure we've got the info we need.
1925
+		if (! ($GRP_ID && $messenger && $message_type)) {
1926
+			EE_Error::add_error(
1927
+				esc_html__(
1928
+					'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.',
1929
+					'event_espresso'
1930
+				),
1931
+				__FILE__,
1932
+				__FUNCTION__,
1933
+				__LINE__
1934
+			);
1935
+		}
1936
+
1937
+		// all templates will be reset to whatever the defaults are
1938
+		// for the global template matching the messenger and message type.
1939
+		$success = ! empty($GRP_ID);
1940
+
1941
+		if ($success) {
1942
+			// let's first determine if the incoming template is a global template,
1943
+			// if it isn't then we need to get the global template matching messenger and message type.
1944
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
1945
+
1946
+
1947
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1948
+			$success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplates($GRP_ID);
1949
+
1950
+			if ($success) {
1951
+				// if successfully deleted, lets generate the new ones.
1952
+				// Note. We set GLOBAL to true, because resets on ANY template
1953
+				// will use the related global template defaults for regeneration.
1954
+				// This means that if a custom template is reset it resets to whatever the related global template is.
1955
+				// HOWEVER, we DO keep the template pack and template variation set
1956
+				// for the current custom template when resetting.
1957
+				$templates = $this->getMessageTemplateManager()->generateNewTemplates(
1958
+					$messenger,
1959
+					$message_type,
1960
+					$GRP_ID,
1961
+					true
1962
+				);
1963
+			}
1964
+		}
1965
+
1966
+		// any error messages?
1967
+		if (! $success) {
1968
+			EE_Error::add_error(
1969
+				esc_html__(
1970
+					'Something went wrong with deleting existing templates. Unable to reset to default',
1971
+					'event_espresso'
1972
+				),
1973
+				__FILE__,
1974
+				__FUNCTION__,
1975
+				__LINE__
1976
+			);
1977
+		}
1978
+
1979
+		// all good, let's add a success message!
1980
+		if ($success && ! empty($templates)) {
1981
+			// the info for the template we generated is the first element in the returned array
1982
+			EE_Error::overwrite_success();
1983
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
1984
+		}
1985
+
1986
+
1987
+		$query_args = [
1988
+			'id'      => $templates['GRP_ID'] ?? null,
1989
+			'context' => $templates['MTP_context'] ?? null,
1990
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
1991
+		];
1992
+
1993
+		// if called via ajax then we return query args otherwise redirect
1994
+		if ($this->request->isAjax()) {
1995
+			return $query_args;
1996
+		}
1997
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1998
+	}
1999
+
2000
+
2001
+	/**
2002
+	 * Retrieve and set the message preview for display.
2003
+	 *
2004
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2005
+	 * @return string
2006
+	 * @throws ReflectionException
2007
+	 * @throws EE_Error
2008
+	 * @throws InvalidArgumentException
2009
+	 * @throws InvalidDataTypeException
2010
+	 * @throws InvalidInterfaceException
2011
+	 */
2012
+	public function _preview_message($send = false)
2013
+	{
2014
+		// first make sure we've got the necessary parameters
2015
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2016
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2017
+			EE_Error::add_error(
2018
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2019
+				__FILE__,
2020
+				__FUNCTION__,
2021
+				__LINE__
2022
+			);
2023
+		}
2024
+
2025
+		$context = $this->request->getRequestParam('context');
2026
+		// get the preview!
2027
+		$preview = EED_Messages::preview_message(
2028
+			$this->_active_message_type_name,
2029
+			$context,
2030
+			$this->_active_messenger_name,
2031
+			$send
2032
+		);
2033
+
2034
+		if ($send) {
2035
+			return $preview;
2036
+		}
2037
+
2038
+		// if we have an evt_id set on the request, use it.
2039
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, DataType::INTEGER);
2040
+
2041
+		// let's add a button to go back to the edit view
2042
+		$query_args             = [
2043
+			'id'      => $GRP_ID,
2044
+			'evt_id'  => $EVT_ID,
2045
+			'context' => $context,
2046
+			'action'  => 'edit_message_template',
2047
+		];
2048
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2049
+		$preview_button         = '<a href="'
2050
+								  . $go_back_url
2051
+								  . '" class="button--secondary messages-preview-go-back-button">'
2052
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2053
+								  . '</a>';
2054
+		$message_types          = $this->get_installed_message_types();
2055
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2056
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2057
+			? ucwords($active_messenger->label['singular'])
2058
+			: esc_html__('Unknown Messenger', 'event_espresso');
2059
+		// let's provide a helpful title for context
2060
+		$preview_title = sprintf(
2061
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2062
+			$active_messenger_label,
2063
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2064
+		);
2065
+		if (empty($preview)) {
2066
+			$this->noEventsErrorMessage();
2067
+		}
2068
+		// setup display of preview.
2069
+		$this->_admin_page_title                    = $preview_title;
2070
+		$this->_template_args['admin_page_title']   = $preview_title;
2071
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2072
+		$this->_template_args['data']['force_json'] = true;
2073
+
2074
+		return '';
2075
+	}
2076
+
2077
+
2078
+	/**
2079
+	 * Used to set an error if there are no events available for generating a preview/test send.
2080
+	 *
2081
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2082
+	 */
2083
+	protected function noEventsErrorMessage($test_send = false)
2084
+	{
2085
+		$events_url = parent::add_query_args_and_nonce(
2086
+			[
2087
+				'action' => 'default',
2088
+				'page'   => 'espresso_events',
2089
+			],
2090
+			admin_url('admin.php')
2091
+		);
2092
+		$message    = $test_send
2093
+			? esc_html__(
2094
+				'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!',
2095
+				'event_espresso'
2096
+			)
2097
+			: esc_html__(
2098
+				'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!',
2099
+				'event_espresso'
2100
+			);
2101
+
2102
+		EE_Error::add_attention(
2103
+			sprintf(
2104
+				$message,
2105
+				"<a href='{$events_url}'>",
2106
+				'</a>'
2107
+			)
2108
+		);
2109
+	}
2110
+
2111
+
2112
+	/**
2113
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2114
+	 * gets called automatically.
2115
+	 *
2116
+	 * @return void
2117
+	 * @throws EE_Error
2118
+	 * @since 4.5.0
2119
+	 */
2120
+	protected function _display_preview_message()
2121
+	{
2122
+		$this->display_admin_page_with_no_sidebar();
2123
+	}
2124
+
2125
+
2126
+	/**
2127
+	 * registers metaboxes that should show up on the "edit_message_template" page
2128
+	 *
2129
+	 * @access protected
2130
+	 * @return void
2131
+	 */
2132
+	protected function _register_edit_meta_boxes()
2133
+	{
2134
+		$this->addMetaBox(
2135
+			'mtp_valid_shortcodes',
2136
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2137
+			[$this, 'shortcode_meta_box'],
2138
+			$this->_current_screen->id,
2139
+			'side'
2140
+		);
2141
+		$this->addMetaBox(
2142
+			'mtp_extra_actions',
2143
+			esc_html__('Extra Actions', 'event_espresso'),
2144
+			[$this, 'extra_actions_meta_box'],
2145
+			$this->_current_screen->id,
2146
+			'side',
2147
+			'high'
2148
+		);
2149
+		$this->addMetaBox(
2150
+			'mtp_templates',
2151
+			esc_html__('Template Styles', 'event_espresso'),
2152
+			[$this, 'template_pack_meta_box'],
2153
+			$this->_current_screen->id,
2154
+			'side',
2155
+			'high'
2156
+		);
2157
+	}
2158
+
2159
+
2160
+	/**
2161
+	 * metabox content for all template pack and variation selection.
2162
+	 *
2163
+	 * @return void
2164
+	 * @throws DomainException
2165
+	 * @throws EE_Error
2166
+	 * @throws InvalidArgumentException
2167
+	 * @throws ReflectionException
2168
+	 * @throws InvalidDataTypeException
2169
+	 * @throws InvalidInterfaceException
2170
+	 * @since 4.5.0
2171
+	 */
2172
+	public function template_pack_meta_box()
2173
+	{
2174
+		$this->_set_message_template_group();
2175
+
2176
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2177
+
2178
+		$tp_select_values = [];
2179
+
2180
+		foreach ($tp_collection as $tp) {
2181
+			// only include template packs that support this messenger and message type!
2182
+			$supports = $tp->get_supports();
2183
+			if (
2184
+				! isset($supports[ $this->_message_template_group->messenger() ])
2185
+				|| ! in_array(
2186
+					$this->_message_template_group->message_type(),
2187
+					$supports[ $this->_message_template_group->messenger() ],
2188
+					true
2189
+				)
2190
+			) {
2191
+				// not supported
2192
+				continue;
2193
+			}
2194
+
2195
+			$tp_select_values[] = [
2196
+				'text' => $tp->label,
2197
+				'id'   => $tp->dbref,
2198
+			];
2199
+		}
2200
+
2201
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2202
+		// the default template pack.  This still allows for the odd template pack to override.
2203
+		if (empty($tp_select_values)) {
2204
+			$tp_select_values[] = [
2205
+				'text' => esc_html__('Default', 'event_espresso'),
2206
+				'id'   => 'default',
2207
+			];
2208
+		}
2209
+
2210
+		// setup variation select values for the currently selected template.
2211
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2212
+			$this->_message_template_group->messenger(),
2213
+			$this->_message_template_group->message_type()
2214
+		);
2215
+		$variations_select_values = [];
2216
+		foreach ($variations as $variation => $label) {
2217
+			$variations_select_values[] = [
2218
+				'text' => $label,
2219
+				'id'   => $variation,
2220
+			];
2221
+		}
2222
+
2223
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2224
+
2225
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2226
+			'MTP_template_pack',
2227
+			$tp_select_values,
2228
+			$this->_message_template_group->get_template_pack_name()
2229
+		);
2230
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2231
+			'MTP_template_variation',
2232
+			$variations_select_values,
2233
+			$this->_message_template_group->get_template_pack_variation()
2234
+		);
2235
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2236
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2237
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2238
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2239
+
2240
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2241
+
2242
+		EEH_Template::display_template($template, $template_args);
2243
+	}
2244
+
2245
+
2246
+	/**
2247
+	 * This meta box holds any extra actions related to Message Templates
2248
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2249
+	 *
2250
+	 * @access  public
2251
+	 * @return void
2252
+	 * @throws EE_Error
2253
+	 */
2254
+	public function extra_actions_meta_box()
2255
+	{
2256
+		$template_form_fields = [];
2257
+
2258
+		$extra_args = [
2259
+			'msgr'   => $this->_message_template_group->messenger(),
2260
+			'mt'     => $this->_message_template_group->message_type(),
2261
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2262
+		];
2263
+		// first we need to see if there are any fields
2264
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2265
+
2266
+		if (! empty($fields)) {
2267
+			// yup there be fields
2268
+			foreach ($fields as $field => $config) {
2269
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2270
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2271
+				$default  = $config['default'] ?? '';
2272
+				$default  = $config['value'] ?? $default;
2273
+
2274
+				// if type is hidden and the value is empty
2275
+				// something may have gone wrong so let's correct with the defaults
2276
+				$fix                = $config['input'] === 'hidden'
2277
+									  && isset($existing[ $field ])
2278
+									  && empty($existing[ $field ])
2279
+					? $default
2280
+					: '';
2281
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2282
+					? $existing[ $field ]
2283
+					: $fix;
2284
+
2285
+				$template_form_fields[ $field_id ] = [
2286
+					'name'       => 'test_settings_fld[' . $field . ']',
2287
+					'label'      => $config['label'],
2288
+					'input'      => $config['input'],
2289
+					'type'       => $config['type'],
2290
+					'required'   => $config['required'],
2291
+					'validation' => $config['validation'],
2292
+					'value'      => $existing[ $field ] ?? $default,
2293
+					'css_class'  => $config['css_class'],
2294
+					'options'    => $config['options'] ?? [],
2295
+					'default'    => $default,
2296
+					'format'     => $config['format'],
2297
+				];
2298
+			}
2299
+		}
2300
+
2301
+		$test_settings_html = ! empty($template_form_fields)
2302
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2303
+			: '';
2304
+
2305
+		// print out $test_settings_fields
2306
+		if (! empty($test_settings_html)) {
2307
+			$test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2308
+			$test_settings_html .= 'name="test_button" value="';
2309
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2310
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2311
+		}
2312
+
2313
+		// and button
2314
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2315
+		$test_settings_html .= '<p>';
2316
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2317
+		$test_settings_html .= '</p>';
2318
+		$test_settings_html .= $this->get_action_link_or_button(
2319
+			'reset_to_default',
2320
+			'reset',
2321
+			$extra_args,
2322
+			'button--primary reset-default-button'
2323
+		);
2324
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2325
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2326
+	}
2327
+
2328
+
2329
+	/**
2330
+	 * This returns the shortcode selector skeleton for a given context and field.
2331
+	 *
2332
+	 * @param string $field           The name of the field retrieving shortcodes for.
2333
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2334
+	 * @return string
2335
+	 * @throws DomainException
2336
+	 * @throws EE_Error
2337
+	 * @throws InvalidArgumentException
2338
+	 * @throws ReflectionException
2339
+	 * @throws InvalidDataTypeException
2340
+	 * @throws InvalidInterfaceException
2341
+	 * @since 4.9.rc.000
2342
+	 */
2343
+	protected function _get_shortcode_selector($field, $linked_input_id)
2344
+	{
2345
+		$template_args = [
2346
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2347
+			'fieldname'       => $field,
2348
+			'linked_input_id' => $linked_input_id,
2349
+		];
2350
+
2351
+		return EEH_Template::display_template(
2352
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2353
+			$template_args,
2354
+			true
2355
+		);
2356
+	}
2357
+
2358
+
2359
+	/**
2360
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2361
+	 * page)
2362
+	 *
2363
+	 * @access public
2364
+	 * @return void
2365
+	 * @throws EE_Error
2366
+	 * @throws InvalidArgumentException
2367
+	 * @throws ReflectionException
2368
+	 * @throws InvalidDataTypeException
2369
+	 * @throws InvalidInterfaceException
2370
+	 */
2371
+	public function shortcode_meta_box()
2372
+	{
2373
+		$shortcodes = $this->_get_shortcodes([], false);
2374
+		// just make sure the shortcodes property is set
2375
+		// $messenger = $this->_message_template_group->messenger_obj();
2376
+		// now let's set the content depending on the status of the shortcodes array
2377
+		if (empty($shortcodes)) {
2378
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2379
+			return;
2380
+		}
2381
+		?>
2382 2382
         <div style="float:right; margin-top:10px">
2383 2383
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2384
-            ?>
2384
+			?>
2385 2385
         </div>
2386 2386
         <p class="small-text">
2387 2387
             <?php printf(
2388
-                esc_html__(
2389
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2390
-                    'event_espresso'
2391
-                ),
2392
-                '<span class="dashicons dashicons-shortcode"></span>'
2393
-            ); ?>
2388
+				esc_html__(
2389
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2390
+					'event_espresso'
2391
+				),
2392
+				'<span class="dashicons dashicons-shortcode"></span>'
2393
+			); ?>
2394 2394
         </p>
2395 2395
         <?php
2396
-        do_action('AHEE__Messages_Admin_Page__shortcode_meta_box', $shortcodes, $this);
2397
-    }
2398
-
2399
-
2400
-    /**
2401
-     * used to set the $_shortcodes property for when its needed elsewhere.
2402
-     *
2403
-     * @access protected
2404
-     * @return void
2405
-     * @throws EE_Error
2406
-     * @throws InvalidArgumentException
2407
-     * @throws ReflectionException
2408
-     * @throws InvalidDataTypeException
2409
-     * @throws InvalidInterfaceException
2410
-     */
2411
-    protected function _set_shortcodes()
2412
-    {
2413
-        // no need to run this if the property is already set
2414
-        if (! empty($this->_shortcodes)) {
2415
-            return;
2416
-        }
2417
-
2418
-        $this->_shortcodes = $this->_get_shortcodes();
2419
-    }
2420
-
2421
-
2422
-    /**
2423
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2424
-     * property)
2425
-     *
2426
-     * @access  protected
2427
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2428
-     *                         for. Defaults to all (for the given context)
2429
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2430
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2431
-     *                         true just an array of shortcode/label pairs.
2432
-     * @throws EE_Error
2433
-     * @throws InvalidArgumentException
2434
-     * @throws ReflectionException
2435
-     * @throws InvalidDataTypeException
2436
-     * @throws InvalidInterfaceException
2437
-     */
2438
-    protected function _get_shortcodes(array $fields = [], bool $merged = true): array
2439
-    {
2440
-        $this->_set_message_template_group();
2441
-
2442
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2443
-        $GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2444
-        if (empty($GRP_ID)) {
2445
-            return [];
2446
-        }
2447
-        $context = $this->request->getRequestParam(
2448
-            'messenger',
2449
-            key($this->_message_template_group->contexts_config())
2450
-        );
2451
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2452
-    }
2453
-
2454
-
2455
-    /**
2456
-     * This sets the _message_template property (containing the called message_template object)
2457
-     *
2458
-     * @access protected
2459
-     * @return void
2460
-     * @throws EE_Error
2461
-     * @throws InvalidArgumentException
2462
-     * @throws ReflectionException
2463
-     * @throws InvalidDataTypeException
2464
-     * @throws InvalidInterfaceException
2465
-     */
2466
-    protected function _set_message_template_group()
2467
-    {
2468
-        // get out if this is already set.
2469
-        if (! empty($this->_message_template_group)) {
2470
-            return;
2471
-        }
2472
-
2473
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2474
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, DataType::INTEGER);
2475
-
2476
-        // let's get the message templates
2477
-        $this->_message_template_group = ! empty($GRP_ID)
2478
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2479
-            : $this->getMtgModel()->create_default_object();
2480
-
2481
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2482
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2483
-    }
2484
-
2485
-
2486
-    /**
2487
-     * sets up a context switcher for edit forms
2488
-     *
2489
-     * @access  protected
2490
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2491
-     * @param array                     $args                  various things the context switcher needs.
2492
-     * @throws EE_Error
2493
-     */
2494
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, array $args)
2495
-    {
2496
-        $context_details = $template_group_object->contexts_config();
2497
-        $context_label   = $template_group_object->context_label();
2498
-        ob_start();
2499
-        ?>
2396
+		do_action('AHEE__Messages_Admin_Page__shortcode_meta_box', $shortcodes, $this);
2397
+	}
2398
+
2399
+
2400
+	/**
2401
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2402
+	 *
2403
+	 * @access protected
2404
+	 * @return void
2405
+	 * @throws EE_Error
2406
+	 * @throws InvalidArgumentException
2407
+	 * @throws ReflectionException
2408
+	 * @throws InvalidDataTypeException
2409
+	 * @throws InvalidInterfaceException
2410
+	 */
2411
+	protected function _set_shortcodes()
2412
+	{
2413
+		// no need to run this if the property is already set
2414
+		if (! empty($this->_shortcodes)) {
2415
+			return;
2416
+		}
2417
+
2418
+		$this->_shortcodes = $this->_get_shortcodes();
2419
+	}
2420
+
2421
+
2422
+	/**
2423
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2424
+	 * property)
2425
+	 *
2426
+	 * @access  protected
2427
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2428
+	 *                         for. Defaults to all (for the given context)
2429
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2430
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2431
+	 *                         true just an array of shortcode/label pairs.
2432
+	 * @throws EE_Error
2433
+	 * @throws InvalidArgumentException
2434
+	 * @throws ReflectionException
2435
+	 * @throws InvalidDataTypeException
2436
+	 * @throws InvalidInterfaceException
2437
+	 */
2438
+	protected function _get_shortcodes(array $fields = [], bool $merged = true): array
2439
+	{
2440
+		$this->_set_message_template_group();
2441
+
2442
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2443
+		$GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2444
+		if (empty($GRP_ID)) {
2445
+			return [];
2446
+		}
2447
+		$context = $this->request->getRequestParam(
2448
+			'messenger',
2449
+			key($this->_message_template_group->contexts_config())
2450
+		);
2451
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2452
+	}
2453
+
2454
+
2455
+	/**
2456
+	 * This sets the _message_template property (containing the called message_template object)
2457
+	 *
2458
+	 * @access protected
2459
+	 * @return void
2460
+	 * @throws EE_Error
2461
+	 * @throws InvalidArgumentException
2462
+	 * @throws ReflectionException
2463
+	 * @throws InvalidDataTypeException
2464
+	 * @throws InvalidInterfaceException
2465
+	 */
2466
+	protected function _set_message_template_group()
2467
+	{
2468
+		// get out if this is already set.
2469
+		if (! empty($this->_message_template_group)) {
2470
+			return;
2471
+		}
2472
+
2473
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2474
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, DataType::INTEGER);
2475
+
2476
+		// let's get the message templates
2477
+		$this->_message_template_group = ! empty($GRP_ID)
2478
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2479
+			: $this->getMtgModel()->create_default_object();
2480
+
2481
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2482
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2483
+	}
2484
+
2485
+
2486
+	/**
2487
+	 * sets up a context switcher for edit forms
2488
+	 *
2489
+	 * @access  protected
2490
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2491
+	 * @param array                     $args                  various things the context switcher needs.
2492
+	 * @throws EE_Error
2493
+	 */
2494
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, array $args)
2495
+	{
2496
+		$context_details = $template_group_object->contexts_config();
2497
+		$context_label   = $template_group_object->context_label();
2498
+		ob_start();
2499
+		?>
2500 2500
         <div class="ee-msg-switcher-container">
2501 2501
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2502 2502
                 <?php
2503
-                foreach ($args as $name => $value) {
2504
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2505
-                        continue;
2506
-                    }
2507
-                    ?>
2503
+				foreach ($args as $name => $value) {
2504
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2505
+						continue;
2506
+					}
2507
+					?>
2508 2508
                     <input type="hidden"
2509 2509
                            name="<?php echo esc_attr($name); ?>"
2510 2510
                            value="<?php echo esc_attr($value); ?>"
2511 2511
                     />
2512 2512
                     <?php
2513
-                }
2514
-                // setup nonce_url
2515
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2516
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2517
-                ?>
2513
+				}
2514
+				// setup nonce_url
2515
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2516
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2517
+				?>
2518 2518
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2519 2519
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2520 2520
                 </label>
2521 2521
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2522 2522
                     <?php
2523
-                    $context_templates = $template_group_object->context_templates();
2524
-                    if (is_array($context_templates)) :
2525
-                        foreach ($context_templates as $context => $template_fields) :
2526
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2527
-                            ?>
2523
+					$context_templates = $template_group_object->context_templates();
2524
+					if (is_array($context_templates)) :
2525
+						foreach ($context_templates as $context => $template_fields) :
2526
+							$checked = ($context === $args['context']) ? 'selected' : '';
2527
+							?>
2528 2528
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2529 2529
                                 <?php echo esc_html($context_details[ $context ]['label']); ?>
2530 2530
                             </option>
2531 2531
                         <?php endforeach;
2532
-                    endif; ?>
2532
+					endif; ?>
2533 2533
                 </select>
2534 2534
                 <?php $button_text = sprintf(
2535
-                    esc_html__('Switch %s', 'event_espresso'),
2536
-                    ucwords($context_label['label'])
2537
-                ); ?>
2535
+					esc_html__('Switch %s', 'event_espresso'),
2536
+					ucwords($context_label['label'])
2537
+				); ?>
2538 2538
                 <input class='button--secondary'
2539 2539
                        id="submit-msg-context-switcher-sbmt"
2540 2540
                        type="submit"
@@ -2544,1634 +2544,1634 @@  discard block
 block discarded – undo
2544 2544
             <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>
2545 2545
         </div> <!-- end .ee-msg-switcher-container -->
2546 2546
         <?php $this->_context_switcher = ob_get_clean();
2547
-    }
2548
-
2549
-
2550
-    /**
2551
-     * @throws EE_Error
2552
-     * @throws ReflectionException
2553
-     * @deprecated 5.0.8.p
2554
-     */
2555
-    protected function _insert_or_update_message_template($new = false)
2556
-    {
2557
-        if ($new) {
2558
-            $this->insertMessageTemplate();
2559
-        } else {
2560
-            $this->updateMessageTemplate();
2561
-        }
2562
-    }
2563
-
2564
-
2565
-    /**
2566
-     * @throws EE_Error
2567
-     * @throws ReflectionException
2568
-     */
2569
-    protected function insertMessageTemplate(): void
2570
-    {
2571
-        $success   = true;
2572
-        $templates = [];
2573
-        try {
2574
-            $templates = $this->getMessageTemplateManager()->generateNewTemplates();
2575
-        } catch (Exception $exception) {
2576
-            $success = false;
2577
-            EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2578
-        }
2579
-
2580
-        /** @var MessageTemplateRequestData $form_data */
2581
-        $form_data = $this->loader->getShared(MessageTemplateRequestData::class);
2582
-        $this->_redirect_after_action(
2583
-            $success && isset($templates['GRP_ID'], $templates['MTP_context']),
2584
-            $this->generateUpdateDescription($form_data->messenger(), $form_data->messageType(), $form_data->context()),
2585
-            'created',
2586
-            [
2587
-                'id'      => $templates['GRP_ID'] ?? 0,
2588
-                'context' => $templates['MTP_context'] ?? '',
2589
-                'action'  => 'edit_message_template',
2590
-            ],
2591
-            $this->performTestSendAfterUpdate($form_data->messenger(), $form_data->messageType(), $form_data->context())
2592
-        );
2593
-    }
2594
-
2595
-
2596
-    /**
2597
-     * @throws EE_Error
2598
-     * @throws ReflectionException
2599
-     */
2600
-    protected function updateMessageTemplate(): void
2601
-    {
2602
-        $success = true;
2603
-        try {
2604
-            $this->getMessageTemplateManager()->updateExistingTemplates();
2605
-        } catch (Exception $exception) {
2606
-            $success = false;
2607
-            EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2608
-        }
2609
-
2610
-        /** @var MessageTemplateRequestData $form_data */
2611
-        $form_data = $this->loader->getShared(MessageTemplateRequestData::class);
2612
-
2613
-        $this->_redirect_after_action(
2614
-            $success,
2615
-            $this->generateUpdateDescription($form_data->messenger(), $form_data->messageType(), $form_data->context()),
2616
-            'updated',
2617
-            [
2618
-                'id'      => $form_data->groupID(),
2619
-                'context' => $form_data->context(),
2620
-                'action'  => 'edit_message_template',
2621
-            ],
2622
-            $this->performTestSendAfterUpdate($form_data->messenger(), $form_data->messageType(), $form_data->context())
2623
-        );
2624
-    }
2625
-
2626
-
2627
-    /**
2628
-     * @param string $messenger
2629
-     * @param string $message_type
2630
-     * @param string $context
2631
-     * @return string
2632
-     * @since 4.10.29.p
2633
-     */
2634
-    private function generateUpdateDescription(string $messenger, string $message_type, string $context): string
2635
-    {
2636
-        // need the message type and messenger objects to be able to use the labels for the notices
2637
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
2638
-        $messenger_label  = $messenger_object instanceof EE_messenger
2639
-            ? ucwords($messenger_object->label['singular'])
2640
-            : '';
2641
-
2642
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
2643
-        $message_type_label  = $message_type_object instanceof EE_message_type
2644
-            ? ucwords($message_type_object->label['singular'])
2645
-            : '';
2646
-
2647
-        $context   = ucwords(str_replace('_', ' ', $context));
2648
-        $item_desc = $messenger_label && $message_type_label
2649
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2650
-            : '';
2651
-        $item_desc .= 'Message Template';
2652
-        return $item_desc;
2653
-    }
2654
-
2655
-
2656
-    /**
2657
-     * @param string $messenger
2658
-     * @param string $message_type
2659
-     * @param string $context
2660
-     * @return bool
2661
-     * @throws EE_Error
2662
-     * @throws ReflectionException
2663
-     * @since 4.10.29.p
2664
-     */
2665
-    private function performTestSendAfterUpdate(string $messenger, string $message_type, string $context): bool
2666
-    {
2667
-        // was a test send triggered?
2668
-        if ($this->request->requestParamIsSet('test_button')) {
2669
-            EE_Error::overwrite_success();
2670
-            $this->_do_test_send($context, $messenger, $message_type);
2671
-            return true;
2672
-        }
2673
-        return false;
2674
-    }
2675
-
2676
-
2677
-    /**
2678
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2679
-     *
2680
-     * @param string $context      what context being tested
2681
-     * @param string $messenger    messenger being tested
2682
-     * @param string $message_type message type being tested
2683
-     * @throws EE_Error
2684
-     * @throws InvalidArgumentException
2685
-     * @throws InvalidDataTypeException
2686
-     * @throws InvalidInterfaceException
2687
-     * @throws ReflectionException
2688
-     */
2689
-    protected function _do_test_send(string $context, string $messenger, string $message_type)
2690
-    {
2691
-        // set things up for preview
2692
-        $this->request->setRequestParam('messenger', $messenger);
2693
-        $this->request->setRequestParam('message_type', $message_type);
2694
-        $this->request->setRequestParam('context', $context);
2695
-        $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2696
-
2697
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
2698
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
2699
-
2700
-        // let's save any existing fields that might be required by the messenger
2701
-        if (
2702
-            ! empty($test_settings_fld)
2703
-            && $active_messenger instanceof EE_messenger
2704
-            && apply_filters(
2705
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2706
-                true,
2707
-                $test_settings_fld,
2708
-                $active_messenger
2709
-            )
2710
-        ) {
2711
-            $active_messenger->set_existing_test_settings($test_settings_fld);
2712
-        }
2713
-
2714
-        /**
2715
-         * Use filter to add additional controls on whether message can send or not
2716
-         */
2717
-        if (
2718
-            apply_filters(
2719
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
2720
-                true,
2721
-                $context,
2722
-                $this->request->requestParams(),
2723
-                $messenger,
2724
-                $message_type
2725
-            )
2726
-        ) {
2727
-            if (EEM_Event::instance()->count() > 0) {
2728
-                $success = $this->_preview_message(true);
2729
-                if ($success) {
2730
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
2731
-                } else {
2732
-                    EE_Error::add_error(
2733
-                        esc_html__('The test message was not sent', 'event_espresso'),
2734
-                        __FILE__,
2735
-                        __FUNCTION__,
2736
-                        __LINE__
2737
-                    );
2738
-                }
2739
-            } else {
2740
-                $this->noEventsErrorMessage(true);
2741
-            }
2742
-        }
2743
-    }
2744
-
2745
-
2746
-    /**
2747
-     * [_trash_or_restore_message_template]
2748
-     *
2749
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2750
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2751
-     *                        an individual context (FALSE).
2752
-     * @return void
2753
-     * @throws EE_Error
2754
-     * @throws InvalidArgumentException
2755
-     * @throws InvalidDataTypeException
2756
-     * @throws InvalidInterfaceException
2757
-     * @throws ReflectionException
2758
-     */
2759
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2760
-    {
2761
-        $success = 1;
2762
-
2763
-        // incoming GRP_IDs
2764
-        if ($all) {
2765
-            // Checkboxes
2766
-            $checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2767
-            if (! empty($checkboxes)) {
2768
-                // if array has more than one element then success message should be plural.
2769
-                // todo: what about nonce?
2770
-                $success = count($checkboxes) > 1 ? 2 : 1;
2771
-
2772
-                // cycle through checkboxes
2773
-                foreach (array_keys($checkboxes) as $GRP_ID) {
2774
-                    $trashed_or_restored = $trash
2775
-                        ? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2776
-                        : $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2777
-                    if (! $trashed_or_restored) {
2778
-                        $success = 0;
2779
-                    }
2780
-                }
2781
-            } else {
2782
-                // grab single GRP_ID and handle
2783
-                $GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2784
-                if (! empty($GRP_ID)) {
2785
-                    $trashed_or_restored = $trash
2786
-                        ? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2787
-                        : $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2788
-                    if (! $trashed_or_restored) {
2789
-                        $success = 0;
2790
-                    }
2791
-                } else {
2792
-                    $success = 0;
2793
-                }
2794
-            }
2795
-        }
2796
-
2797
-        $action_desc = $trash
2798
-            ? esc_html__('moved to the trash', 'event_espresso')
2799
-            : esc_html__('restored', 'event_espresso');
2800
-
2801
-        $template_switch = $this->request->getRequestParam('template_switch', false, DataType::BOOLEAN);
2802
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
2803
-
2804
-        $item_desc = $all ? _n(
2805
-            'Message Template Group',
2806
-            'Message Template Groups',
2807
-            $success,
2808
-            'event_espresso'
2809
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2810
-
2811
-        $item_desc = $template_switch
2812
-            ? _n('template', 'templates', $success, 'event_espresso')
2813
-            : $item_desc;
2814
-
2815
-        $this->_redirect_after_action(
2816
-            $success,
2817
-            $item_desc,
2818
-            $action_desc,
2819
-            [
2820
-                'action' => $this->request->getRequestParam('return'),
2821
-            ]
2822
-        );
2823
-    }
2824
-
2825
-
2826
-    /**
2827
-     * [_delete_message_template]
2828
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2829
-     *
2830
-     * @return void
2831
-     * @throws EE_Error
2832
-     * @throws InvalidArgumentException
2833
-     * @throws InvalidDataTypeException
2834
-     * @throws InvalidInterfaceException
2835
-     * @throws ReflectionException
2836
-     */
2837
-    protected function _delete_message_template()
2838
-    {
2839
-        // checkboxes
2840
-        $checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2841
-        if (! empty($checkboxes)) {
2842
-            // if array has more than one element then success message should be plural
2843
-            $success = count($checkboxes) > 1 ? 2 : 1;
2844
-
2845
-            // cycle through bulk action checkboxes
2846
-            foreach (array_keys($checkboxes) as $GRP_ID) {
2847
-                $success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplateGroup($GRP_ID) ? $success
2848
-                    : false;
2849
-            }
2850
-        } else {
2851
-            // grab single grp_id and delete
2852
-            $GRP_ID  = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2853
-            $success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplateGroup($GRP_ID);
2854
-        }
2855
-
2856
-        $this->_redirect_after_action(
2857
-            $success,
2858
-            'Message Templates',
2859
-            'deleted',
2860
-            [
2861
-                'action' => $this->request->getRequestParam('return'),
2862
-            ]
2863
-        );
2864
-    }
2865
-
2866
-
2867
-    /**
2868
-     *    _learn_more_about_message_templates_link
2869
-     *
2870
-     * @access protected
2871
-     * @return string
2872
-     */
2873
-    protected function _learn_more_about_message_templates_link()
2874
-    {
2875
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
2876
-               . esc_html__('learn more about how message templates works', 'event_espresso')
2877
-               . '</a>';
2878
-    }
2879
-
2880
-
2881
-    /**
2882
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2883
-     * ajax and other routes.
2884
-     *
2885
-     * @return void
2886
-     * @throws DomainException
2887
-     * @throws EE_Error
2888
-     */
2889
-    protected function _settings()
2890
-    {
2891
-        $this->_set_m_mt_settings();
2892
-        // let's setup the messenger tabs
2893
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
2894
-            $this->_m_mt_settings['messenger_tabs'],
2895
-            'messenger_links',
2896
-            '|',
2897
-            $this->request->getRequestParam('selected_messenger', 'email')
2898
-        );
2899
-
2900
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2901
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2902
-
2903
-        $this->display_admin_page_with_sidebar();
2904
-    }
2905
-
2906
-
2907
-    /**
2908
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2909
-     *
2910
-     * @access protected
2911
-     * @return void
2912
-     * @throws DomainException
2913
-     */
2914
-    protected function _set_m_mt_settings()
2915
-    {
2916
-        // first if this is already set then lets get out no need to regenerate data.
2917
-        if (! empty($this->_m_mt_settings)) {
2918
-            return;
2919
-        }
2920
-
2921
-        // get all installed messengers and message_types
2922
-        $messengers    = $this->_message_resource_manager->installed_messengers();
2923
-        $message_types = $this->_message_resource_manager->installed_message_types();
2924
-
2925
-
2926
-        // assemble the array for the _tab_text_links helper
2927
-
2928
-        foreach ($messengers as $messenger) {
2929
-            $active                                                     =
2930
-                $this->_message_resource_manager->is_messenger_active($messenger->name);
2931
-            $class                                                      =
2932
-                'ee-messenger-' . sanitize_key($messenger->label['singular']);
2933
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
2934
-                'label' => ucwords($messenger->label['singular']),
2935
-                'class' => $active ? "{$class} messenger-active" : $class,
2936
-                'href'  => $messenger->name,
2937
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
2938
-                'slug'  => $messenger->name,
2939
-                'obj'   => $messenger,
2940
-                'icon'  => $active
2941
-                    ? '<span class="dashicons dashicons-yes-alt"></span>'
2942
-                    : '<span class="dashicons dashicons-remove"></span>',
2943
-            ];
2944
-
2945
-
2946
-            $message_types_for_messenger = $messenger->get_valid_message_types();
2947
-
2948
-            foreach ($message_types as $message_type) {
2949
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
2950
-                // it shouldn't show in either the inactive OR active metabox.
2951
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
2952
-                    continue;
2953
-                }
2954
-
2955
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
2956
-                    $messenger->name,
2957
-                    $message_type->name
2958
-                )
2959
-                    ? 'active'
2960
-                    : 'inactive';
2961
-
2962
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
2963
-                    'label'    => ucwords($message_type->label['singular']),
2964
-                    'class'    => 'message-type-' . $a_or_i,
2965
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2966
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2967
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2968
-                    'title'    => $a_or_i === 'active'
2969
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2970
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
2971
-                    'content'  => $a_or_i === 'active'
2972
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
2973
-                        : $this->_message_type_settings_content($message_type, $messenger),
2974
-                    'slug'     => $message_type->name,
2975
-                    'active'   => $a_or_i === 'active',
2976
-                    'obj'      => $message_type,
2977
-                ];
2978
-            }
2979
-        }
2980
-    }
2981
-
2982
-
2983
-    /**
2984
-     * This just prepares the content for the message type settings
2985
-     *
2986
-     * @param EE_message_type $message_type The message type object
2987
-     * @param EE_messenger    $messenger    The messenger object
2988
-     * @param boolean         $active       Whether the message type is active or not
2989
-     * @return string html output for the content
2990
-     * @throws DomainException
2991
-     */
2992
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
2993
-    {
2994
-        // get message type fields
2995
-        $fields                                         = $message_type->get_admin_settings_fields();
2996
-        $settings_template_args['template_form_fields'] = '';
2997
-
2998
-        if (! empty($fields) && $active) {
2999
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3000
-            foreach ($fields as $fldname => $fldprops) {
3001
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3002
-                $template_form_field[ $field_id ] = [
3003
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3004
-                    'label'      => $fldprops['label'],
3005
-                    'input'      => $fldprops['field_type'],
3006
-                    'type'       => $fldprops['value_type'],
3007
-                    'required'   => $fldprops['required'],
3008
-                    'validation' => $fldprops['validation'],
3009
-                    'value'      => $existing_settings[ $fldname ] ?? $fldprops['default'],
3010
-                    'options'    => $fldprops['options'] ?? [],
3011
-                    'default'    => $existing_settings[ $fldname ] ?? $fldprops['default'],
3012
-                    'css_class'  => 'no-drag',
3013
-                    'format'     => $fldprops['format'],
3014
-                ];
3015
-            }
3016
-
3017
-
3018
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3019
-                ? $this->_generate_admin_form_fields(
3020
-                    $template_form_field,
3021
-                    'string',
3022
-                    'ee_mt_activate_form'
3023
-                )
3024
-                : '';
3025
-        }
3026
-
3027
-        $settings_template_args['description'] = $message_type->description;
3028
-        // we also need some hidden fields
3029
-        $hidden_fields = [
3030
-            'message_type_settings[messenger]' . $message_type->name    => [
3031
-                'type'  => 'hidden',
3032
-                'value' => $messenger->name,
3033
-            ],
3034
-            'message_type_settings[message_type]' . $message_type->name => [
3035
-                'type'  => 'hidden',
3036
-                'value' => $message_type->name,
3037
-            ],
3038
-            'type' . $message_type->name                                => [
3039
-                'type'  => 'hidden',
3040
-                'value' => 'message_type',
3041
-            ],
3042
-        ];
3043
-
3044
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3045
-            $hidden_fields,
3046
-            'array'
3047
-        );
3048
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3049
-            ? ' hidden'
3050
-            : '';
3051
-
3052
-
3053
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3054
-        return EEH_Template::display_template($template, $settings_template_args, true);
3055
-    }
3056
-
3057
-
3058
-    /**
3059
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3060
-     *
3061
-     * @access protected
3062
-     * @return void
3063
-     * @throws DomainException
3064
-     */
3065
-    protected function _messages_settings_metaboxes()
3066
-    {
3067
-        $this->_set_m_mt_settings();
3068
-        $m_boxes         = $mt_boxes = [];
3069
-        $m_template_args = $mt_template_args = [];
3070
-
3071
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3072
-
3073
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3074
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3075
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3076
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3077
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3078
-
3079
-                // messenger meta boxes
3080
-                $active         = $selected_messenger === $messenger;
3081
-                $active_mt_tabs = $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] ?? '';
3082
-
3083
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3084
-                    esc_html__('%s Settings', 'event_espresso'),
3085
-                    $tab_array['label']
3086
-                );
3087
-
3088
-                $m_template_args[ $messenger . '_a_box' ] = [
3089
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3090
-                    'inactive_message_types' => isset(
3091
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3092
-                    )
3093
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3094
-                        : '',
3095
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3096
-                    'hidden'                 => $active ? '' : ' hidden',
3097
-                    'hide_on_message'        => $hide_on_message,
3098
-                    'messenger'              => $messenger,
3099
-                    'active'                 => $active,
3100
-                ];
3101
-
3102
-                // message type meta boxes
3103
-                // (which is really just the inactive container for each messenger
3104
-                // showing inactive message types for that messenger)
3105
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3106
-                $mt_template_args[ $messenger . '_i_box' ] = [
3107
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3108
-                    'inactive_message_types' => isset(
3109
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3110
-                    )
3111
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3112
-                        : '',
3113
-                    'hidden'                 => $active ? '' : ' hidden',
3114
-                    'hide_on_message'        => $hide_on_message,
3115
-                    'hide_off_message'       => $hide_off_message,
3116
-                    'messenger'              => $messenger,
3117
-                    'active'                 => $active,
3118
-                ];
3119
-            }
3120
-        }
3121
-
3122
-
3123
-        // register messenger metaboxes
3124
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3125
-        foreach ($m_boxes as $box => $label) {
3126
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3127
-            $msgr          = str_replace('_a_box', '', $box);
3128
-            $this->addMetaBox(
3129
-                'espresso_' . $msgr . '_settings',
3130
-                $label,
3131
-                function ($post, $metabox) {
3132
-                    EEH_Template::display_template(
3133
-                        $metabox['args']['template_path'],
3134
-                        $metabox['args']['template_args']
3135
-                    );
3136
-                },
3137
-                $this->_current_screen->id,
3138
-                'normal',
3139
-                'high',
3140
-                $callback_args
3141
-            );
3142
-        }
3143
-
3144
-        // register message type metaboxes
3145
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3146
-        foreach ($mt_boxes as $box => $label) {
3147
-            $callback_args = [
3148
-                'template_path' => $mt_template_path,
3149
-                'template_args' => $mt_template_args[ $box ],
3150
-            ];
3151
-            $mt            = str_replace('_i_box', '', $box);
3152
-            $this->addMetaBox(
3153
-                'espresso_' . $mt . '_inactive_mts',
3154
-                $label,
3155
-                function ($post, $metabox) {
3156
-                    EEH_Template::display_template(
3157
-                        $metabox['args']['template_path'],
3158
-                        $metabox['args']['template_args']
3159
-                    );
3160
-                },
3161
-                $this->_current_screen->id,
3162
-                'side',
3163
-                'high',
3164
-                $callback_args
3165
-            );
3166
-        }
3167
-
3168
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3169
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3170
-        if (is_main_site()) {
3171
-            $this->addMetaBox(
3172
-                'espresso_global_message_settings',
3173
-                esc_html__('Global Message Settings', 'event_espresso'),
3174
-                [$this, 'global_messages_settings_metabox_content'],
3175
-                $this->_current_screen->id,
3176
-                'normal',
3177
-                'low',
3178
-                []
3179
-            );
3180
-        }
3181
-    }
3182
-
3183
-
3184
-    /**
3185
-     *  This generates the content for the global messages settings metabox.
3186
-     *
3187
-     * @return void
3188
-     * @throws EE_Error
3189
-     * @throws InvalidArgumentException
3190
-     * @throws ReflectionException
3191
-     * @throws InvalidDataTypeException
3192
-     * @throws InvalidInterfaceException
3193
-     */
3194
-    public function global_messages_settings_metabox_content()
3195
-    {
3196
-        $form = $this->_generate_global_settings_form();
3197
-        echo wp_kses(
3198
-            $form->form_open(
3199
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3200
-                'POST'
3201
-            ),
3202
-            AllowedTags::getWithFormTags()
3203
-        );
3204
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3205
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3206
-    }
3207
-
3208
-
3209
-    /**
3210
-     * This generates and returns the form object for the global messages settings.
3211
-     *
3212
-     * @return EE_Form_Section_Proper
3213
-     * @throws EE_Error
3214
-     * @throws InvalidArgumentException
3215
-     * @throws ReflectionException
3216
-     * @throws InvalidDataTypeException
3217
-     * @throws InvalidInterfaceException
3218
-     */
3219
-    protected function _generate_global_settings_form()
3220
-    {
3221
-        /** @var EE_Network_Core_Config $network_config */
3222
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3223
-
3224
-        return new EE_Form_Section_Proper(
3225
-            [
3226
-                'name'            => 'global_messages_settings',
3227
-                'html_id'         => 'global_messages_settings',
3228
-                'html_class'      => 'form-table',
3229
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3230
-                'subsections'     => apply_filters(
3231
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3232
-                    [
3233
-                        'do_messages_on_same_request' => new EE_Select_Input(
3234
-                            [
3235
-                                true  => esc_html__('On the same request', 'event_espresso'),
3236
-                                false => esc_html__('On a separate request', 'event_espresso'),
3237
-                            ],
3238
-                            [
3239
-                                'default'         => $network_config->do_messages_on_same_request,
3240
-                                'html_label_text' => esc_html__(
3241
-                                    'Generate and send all messages:',
3242
-                                    'event_espresso'
3243
-                                ),
3244
-                                'html_help_text'  => esc_html__(
3245
-                                    '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.',
3246
-                                    'event_espresso'
3247
-                                ),
3248
-                            ]
3249
-                        ),
3250
-                        'delete_threshold'            => new EE_Select_Input(
3251
-                            [
3252
-                                0  => esc_html__('Forever', 'event_espresso'),
3253
-                                3  => esc_html__('3 Months', 'event_espresso'),
3254
-                                6  => esc_html__('6 Months', 'event_espresso'),
3255
-                                9  => esc_html__('9 Months', 'event_espresso'),
3256
-                                12 => esc_html__('12 Months', 'event_espresso'),
3257
-                                24 => esc_html__('24 Months', 'event_espresso'),
3258
-                                36 => esc_html__('36 Months', 'event_espresso'),
3259
-                            ],
3260
-                            [
3261
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3262
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3263
-                                'html_help_text'  => esc_html__(
3264
-                                    'You can control how long a record of processed messages is kept via this option.',
3265
-                                    'event_espresso'
3266
-                                ),
3267
-                            ]
3268
-                        ),
3269
-                        'update_settings'             => new EE_Submit_Input(
3270
-                            [
3271
-                                'default'         => esc_html__('Update', 'event_espresso'),
3272
-                                'html_label_text' => '',
3273
-                            ]
3274
-                        ),
3275
-                    ]
3276
-                ),
3277
-            ]
3278
-        );
3279
-    }
3280
-
3281
-
3282
-    /**
3283
-     * This handles updating the global settings set on the admin page.
3284
-     *
3285
-     * @throws EE_Error
3286
-     * @throws InvalidDataTypeException
3287
-     * @throws InvalidInterfaceException
3288
-     * @throws InvalidArgumentException
3289
-     * @throws ReflectionException
3290
-     */
3291
-    protected function _update_global_settings()
3292
-    {
3293
-        /** @var EE_Network_Core_Config $network_config */
3294
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3295
-        $messages_config = EE_Registry::instance()->CFG->messages;
3296
-        $form            = $this->_generate_global_settings_form();
3297
-        if ($form->was_submitted()) {
3298
-            $form->receive_form_submission();
3299
-            if ($form->is_valid()) {
3300
-                $valid_data = $form->valid_data();
3301
-                // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
3302
-                foreach ($valid_data as $property => $value) {
3303
-                    $setter = 'set_' . $property;
3304
-                    if (method_exists($network_config, $setter)) {
3305
-                        $network_config->{$setter}($value);
3306
-                    } elseif (
3307
-                        property_exists($network_config, $property)
3308
-                        && $network_config->{$property} !== $value
3309
-                    ) {
3310
-                        $network_config->{$property} = $value;
3311
-                    } elseif (
3312
-                        property_exists($messages_config, $property)
3313
-                        && $messages_config->{$property} !== $value
3314
-                    ) {
3315
-                        $messages_config->{$property} = $value;
3316
-                    }
3317
-                }
3318
-                // only update if the form submission was valid!
3319
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3320
-                EE_Registry::instance()->CFG->update_espresso_config();
3321
-                EE_Error::overwrite_success();
3322
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3323
-            }
3324
-        }
3325
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3326
-    }
3327
-
3328
-
3329
-    /**
3330
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3331
-     *
3332
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3333
-     * @return string html formatted tabs
3334
-     * @throws DomainException
3335
-     */
3336
-    protected function _get_mt_tabs($tab_array)
3337
-    {
3338
-        $tab_array = (array) $tab_array;
3339
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3340
-        $tabs      = '';
3341
-
3342
-        foreach ($tab_array as $tab) {
3343
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3344
-        }
3345
-
3346
-        return $tabs;
3347
-    }
3348
-
3349
-
3350
-    /**
3351
-     * This prepares the content of the messenger meta box admin settings
3352
-     *
3353
-     * @param EE_messenger $messenger The messenger we're setting up content for
3354
-     * @return string html formatted content
3355
-     * @throws DomainException
3356
-     */
3357
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3358
-    {
3359
-        $fields = $messenger->get_admin_settings_fields();
3360
-
3361
-        $settings_template_args['template_form_fields'] = '';
3362
-        // is $messenger active?
3363
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3364
-
3365
-
3366
-        if (! empty($fields)) {
3367
-            $existing_settings = $messenger->get_existing_admin_settings();
3368
-
3369
-            foreach ($fields as $field_name => $field_props) {
3370
-                $field_id                         = $messenger->name . '-' . $field_name;
3371
-                $template_form_field[ $field_id ] = [
3372
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3373
-                    'label'      => $field_props['label'],
3374
-                    'input'      => $field_props['field_type'],
3375
-                    'type'       => $field_props['value_type'],
3376
-                    'required'   => $field_props['required'],
3377
-                    'validation' => $field_props['validation'],
3378
-                    'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3379
-                    'css_class'  => '',
3380
-                    'format'     => $field_props['format'],
3381
-                ];
3382
-            }
3383
-
3384
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3385
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3386
-                : '';
3387
-        }
3388
-
3389
-        // we also need some hidden fields
3390
-        $settings_template_args['hidden_fields'] = [
3391
-            'messenger_settings[messenger]' . $messenger->name => [
3392
-                'type'  => 'hidden',
3393
-                'value' => $messenger->name,
3394
-            ],
3395
-            'type' . $messenger->name                          => [
3396
-                'type'  => 'hidden',
3397
-                'value' => 'messenger',
3398
-            ],
3399
-        ];
3400
-
3401
-        // make sure any active message types that are existing are included in the hidden fields
3402
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3403
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3404
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3405
-                    'type'  => 'hidden',
3406
-                    'value' => $mt,
3407
-                ];
3408
-            }
3409
-        }
3410
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3411
-            $settings_template_args['hidden_fields'],
3412
-            'array'
3413
-        );
3414
-        $active                                  =
3415
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3416
-
3417
-        $settings_template_args['messenger']           = $messenger->name;
3418
-        $settings_template_args['description']         = $messenger->description;
3419
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3420
-
3421
-
3422
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3423
-            $messenger->name
3424
-        )
3425
-            ? $settings_template_args['show_hide_edit_form']
3426
-            : ' hidden';
3427
-
3428
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3429
-            ? ' hidden'
3430
-            : $settings_template_args['show_hide_edit_form'];
3431
-
3432
-
3433
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3434
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3435
-        $settings_template_args['on_off_status'] = $active;
3436
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3437
-        return EEH_Template::display_template(
3438
-            $template,
3439
-            $settings_template_args,
3440
-            true
3441
-        );
3442
-    }
3443
-
3444
-
3445
-    /**
3446
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3447
-     *
3448
-     * @throws DomainException
3449
-     * @throws EE_Error
3450
-     * @throws InvalidDataTypeException
3451
-     * @throws InvalidInterfaceException
3452
-     * @throws InvalidArgumentException
3453
-     * @throws ReflectionException
3454
-     */
3455
-    public function activate_messenger_toggle()
3456
-    {
3457
-        if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
3458
-            wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
3459
-        }
3460
-        $success = true;
3461
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3462
-        // let's check that we have required data
3463
-
3464
-        if (! $this->_active_messenger_name) {
3465
-            EE_Error::add_error(
3466
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3467
-                __FILE__,
3468
-                __FUNCTION__,
3469
-                __LINE__
3470
-            );
3471
-            $success = false;
3472
-        }
3473
-
3474
-        // do a nonce check here since we're not arriving via a normal route
3475
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
3476
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
3477
-
3478
-        $this->_verify_nonce($nonce, $nonce_ref);
3479
-
3480
-
3481
-        $status = $this->request->getRequestParam('status');
3482
-        if (! $status) {
3483
-            EE_Error::add_error(
3484
-                esc_html__(
3485
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3486
-                    'event_espresso'
3487
-                ),
3488
-                __FILE__,
3489
-                __FUNCTION__,
3490
-                __LINE__
3491
-            );
3492
-            $success = false;
3493
-        }
3494
-
3495
-        // do check to verify we have a valid status.
3496
-        if ($status !== 'off' && $status !== 'on') {
3497
-            EE_Error::add_error(
3498
-                sprintf(
3499
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3500
-                    $status
3501
-                ),
3502
-                __FILE__,
3503
-                __FUNCTION__,
3504
-                __LINE__
3505
-            );
3506
-            $success = false;
3507
-        }
3508
-
3509
-        if ($success) {
3510
-            // made it here?  Stop dawdling then!!
3511
-            $success = $status === 'off'
3512
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
3513
-                : $this->_activate_messenger($this->_active_messenger_name);
3514
-        }
3515
-
3516
-        $this->_template_args['success'] = $success;
3517
-
3518
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
3519
-        $this->_return_json();
3520
-    }
3521
-
3522
-
3523
-    /**
3524
-     * used by ajax from the messages settings page to activate|deactivate a message type
3525
-     *
3526
-     * @throws DomainException
3527
-     * @throws EE_Error
3528
-     * @throws ReflectionException
3529
-     * @throws InvalidDataTypeException
3530
-     * @throws InvalidInterfaceException
3531
-     * @throws InvalidArgumentException
3532
-     */
3533
-    public function activate_mt_toggle()
3534
-    {
3535
-        if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
3536
-            wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
3537
-        }
3538
-        $success = true;
3539
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3540
-
3541
-        // let's make sure we have the necessary data
3542
-        if (! $this->_active_message_type_name) {
3543
-            EE_Error::add_error(
3544
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3545
-                __FILE__,
3546
-                __FUNCTION__,
3547
-                __LINE__
3548
-            );
3549
-            $success = false;
3550
-        }
3551
-
3552
-        if (! $this->_active_messenger_name) {
3553
-            EE_Error::add_error(
3554
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3555
-                __FILE__,
3556
-                __FUNCTION__,
3557
-                __LINE__
3558
-            );
3559
-            $success = false;
3560
-        }
3561
-
3562
-        $status = $this->request->getRequestParam('status');
3563
-        if (! $status) {
3564
-            EE_Error::add_error(
3565
-                esc_html__(
3566
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3567
-                    'event_espresso'
3568
-                ),
3569
-                __FILE__,
3570
-                __FUNCTION__,
3571
-                __LINE__
3572
-            );
3573
-            $success = false;
3574
-        }
3575
-
3576
-
3577
-        // do check to verify we have a valid status.
3578
-        if ($status !== 'activate' && $status !== 'deactivate') {
3579
-            EE_Error::add_error(
3580
-                sprintf(
3581
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3582
-                    $status
3583
-                ),
3584
-                __FILE__,
3585
-                __FUNCTION__,
3586
-                __LINE__
3587
-            );
3588
-            $success = false;
3589
-        }
3590
-
3591
-
3592
-        // do a nonce check here since we're not arriving via a normal route
3593
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
3594
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
3595
-
3596
-        if ($success) {
3597
-            // made it here? um, what are you waiting for then?
3598
-            $success = $status === 'deactivate'
3599
-                ? $this->_deactivate_message_type_for_messenger(
3600
-                    $this->_active_messenger_name,
3601
-                    $this->_active_message_type_name
3602
-                )
3603
-                : $this->_activate_message_type_for_messenger(
3604
-                    $this->_active_messenger_name,
3605
-                    $this->_active_message_type_name
3606
-                );
3607
-        }
3608
-
3609
-        $this->_template_args['success'] = $success;
3610
-        $this->_return_json();
3611
-    }
3612
-
3613
-
3614
-    /**
3615
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3616
-     *
3617
-     * @param string $messenger_name The name of the messenger being activated
3618
-     * @return bool
3619
-     * @throws DomainException
3620
-     * @throws EE_Error
3621
-     * @throws InvalidArgumentException
3622
-     * @throws ReflectionException
3623
-     * @throws InvalidDataTypeException
3624
-     * @throws InvalidInterfaceException
3625
-     */
3626
-    protected function _activate_messenger($messenger_name)
3627
-    {
3628
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3629
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3630
-            ? $active_messenger->get_default_message_types()
3631
-            : [];
3632
-
3633
-        // ensure is active
3634
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
3635
-
3636
-        // set response_data for reload
3637
-        foreach ($message_types_to_activate as $message_type_name) {
3638
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3639
-            if (
3640
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
3641
-                    $messenger_name,
3642
-                    $message_type_name
3643
-                )
3644
-                && $message_type instanceof EE_message_type
3645
-            ) {
3646
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3647
-                if ($message_type->get_admin_settings_fields()) {
3648
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3649
-                }
3650
-            }
3651
-        }
3652
-
3653
-        // add success message for activating messenger
3654
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3655
-    }
3656
-
3657
-
3658
-    /**
3659
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3660
-     *
3661
-     * @param string $messenger_name The name of the messenger being activated
3662
-     * @return bool
3663
-     * @throws DomainException
3664
-     * @throws EE_Error
3665
-     * @throws InvalidArgumentException
3666
-     * @throws ReflectionException
3667
-     * @throws InvalidDataTypeException
3668
-     * @throws InvalidInterfaceException
3669
-     */
3670
-    protected function _deactivate_messenger($messenger_name)
3671
-    {
3672
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3673
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3674
-
3675
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3676
-    }
3677
-
3678
-
3679
-    /**
3680
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3681
-     *
3682
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3683
-     * @param string $message_type_name The name of the message type being activated for the messenger
3684
-     * @return bool
3685
-     * @throws DomainException
3686
-     * @throws EE_Error
3687
-     * @throws InvalidArgumentException
3688
-     * @throws ReflectionException
3689
-     * @throws InvalidDataTypeException
3690
-     * @throws InvalidInterfaceException
3691
-     */
3692
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3693
-    {
3694
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
3695
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3696
-
3697
-        // ensure is active
3698
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
3699
-
3700
-        // set response for load
3701
-        if (
3702
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
3703
-                $messenger_name,
3704
-                $message_type_name
3705
-            )
3706
-        ) {
3707
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3708
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3709
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3710
-            }
3711
-        }
3712
-
3713
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
3714
-            $active_messenger,
3715
-            $message_type_to_activate
3716
-        );
3717
-    }
3718
-
3719
-
3720
-    /**
3721
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3722
-     *
3723
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3724
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3725
-     * @return bool
3726
-     * @throws DomainException
3727
-     * @throws EE_Error
3728
-     * @throws InvalidArgumentException
3729
-     * @throws ReflectionException
3730
-     * @throws InvalidDataTypeException
3731
-     * @throws InvalidInterfaceException
3732
-     */
3733
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3734
-    {
3735
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3736
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3737
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3738
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3739
-
3740
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
3741
-            $active_messenger,
3742
-            $message_type_to_deactivate
3743
-        );
3744
-    }
3745
-
3746
-
3747
-    /**
3748
-     * This just initializes the defaults for activating messenger and message type responses.
3749
-     */
3750
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
3751
-    {
3752
-        $this->_template_args['data']['active_mts'] = [];
3753
-        $this->_template_args['data']['mt_reload']  = [];
3754
-    }
3755
-
3756
-
3757
-    /**
3758
-     * Setup appropriate response for activating a messenger and/or message types
3759
-     *
3760
-     * @param EE_messenger         $messenger
3761
-     * @param EE_message_type|null $message_type
3762
-     * @return bool
3763
-     * @throws DomainException
3764
-     * @throws EE_Error
3765
-     * @throws InvalidArgumentException
3766
-     * @throws ReflectionException
3767
-     * @throws InvalidDataTypeException
3768
-     * @throws InvalidInterfaceException
3769
-     */
3770
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
3771
-        $messenger,
3772
-        EE_Message_Type $message_type = null
3773
-    ) {
3774
-        // if $messenger isn't a valid messenger object then get out.
3775
-        if (! $messenger instanceof EE_Messenger) {
3776
-            EE_Error::add_error(
3777
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
3778
-                __FILE__,
3779
-                __FUNCTION__,
3780
-                __LINE__
3781
-            );
3782
-            return false;
3783
-        }
3784
-        // activated
3785
-        if ($this->_template_args['data']['active_mts']) {
3786
-            EE_Error::overwrite_success();
3787
-            // activated a message type with the messenger
3788
-            if ($message_type instanceof EE_message_type) {
3789
-                EE_Error::add_success(
3790
-                    sprintf(
3791
-                        esc_html__(
3792
-                            '%s message type has been successfully activated with the %s messenger',
3793
-                            'event_espresso'
3794
-                        ),
3795
-                        ucwords($message_type->label['singular']),
3796
-                        ucwords($messenger->label['singular'])
3797
-                    )
3798
-                );
3799
-
3800
-                // if message type was invoice then let's make sure we activate the invoice payment method.
3801
-                if ($message_type->name === 'invoice') {
3802
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
3803
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3804
-                    if ($pm instanceof EE_Payment_Method) {
3805
-                        EE_Error::add_attention(
3806
-                            esc_html__(
3807
-                                '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.',
3808
-                                'event_espresso'
3809
-                            )
3810
-                        );
3811
-                    }
3812
-                }
3813
-                // just toggles the entire messenger
3814
-            } else {
3815
-                EE_Error::add_success(
3816
-                    sprintf(
3817
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
3818
-                        ucwords($messenger->label['singular'])
3819
-                    )
3820
-                );
3821
-            }
3822
-
3823
-            return true;
3824
-
3825
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3826
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3827
-            // in which case we just give a success message for the messenger being successfully activated.
3828
-        } else {
3829
-            if (! $messenger->get_default_message_types()) {
3830
-                // messenger doesn't have any default message types so still a success.
3831
-                EE_Error::add_success(
3832
-                    sprintf(
3833
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
3834
-                        ucwords($messenger->label['singular'])
3835
-                    )
3836
-                );
3837
-
3838
-                return true;
3839
-            } else {
3840
-                EE_Error::add_error(
3841
-                    $message_type instanceof EE_message_type
3842
-                        ? sprintf(
3843
-                            esc_html__(
3844
-                                '%s message type was not successfully activated with the %s messenger',
3845
-                                'event_espresso'
3846
-                            ),
3847
-                            ucwords($message_type->label['singular']),
3848
-                            ucwords($messenger->label['singular'])
3849
-                        )
3850
-                        : sprintf(
3851
-                            esc_html__('%s messenger was not successfully activated', 'event_espresso'),
3852
-                            ucwords($messenger->label['singular'])
3853
-                        ),
3854
-                    __FILE__,
3855
-                    __FUNCTION__,
3856
-                    __LINE__
3857
-                );
3858
-
3859
-                return false;
3860
-            }
3861
-        }
3862
-    }
3863
-
3864
-
3865
-    /**
3866
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
3867
-     *
3868
-     * @param EE_messenger         $messenger
3869
-     * @param EE_message_type|null $message_type
3870
-     * @return bool
3871
-     * @throws DomainException
3872
-     * @throws EE_Error
3873
-     * @throws InvalidArgumentException
3874
-     * @throws ReflectionException
3875
-     * @throws InvalidDataTypeException
3876
-     * @throws InvalidInterfaceException
3877
-     */
3878
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3879
-        $messenger,
3880
-        EE_message_type $message_type = null
3881
-    ) {
3882
-        EE_Error::overwrite_success();
3883
-
3884
-        // if $messenger isn't a valid messenger object then get out.
3885
-        if (! $messenger instanceof EE_Messenger) {
3886
-            EE_Error::add_error(
3887
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3888
-                __FILE__,
3889
-                __FUNCTION__,
3890
-                __LINE__
3891
-            );
3892
-
3893
-            return false;
3894
-        }
3895
-
3896
-        if ($message_type instanceof EE_message_type) {
3897
-            $message_type_name = $message_type->name;
3898
-            EE_Error::add_success(
3899
-                sprintf(
3900
-                    esc_html__(
3901
-                        '%s message type has been successfully deactivated for the %s messenger.',
3902
-                        'event_espresso'
3903
-                    ),
3904
-                    ucwords($message_type->label['singular']),
3905
-                    ucwords($messenger->label['singular'])
3906
-                )
3907
-            );
3908
-        } else {
3909
-            $message_type_name = '';
3910
-            EE_Error::add_success(
3911
-                sprintf(
3912
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
3913
-                    ucwords($messenger->label['singular'])
3914
-                )
3915
-            );
3916
-        }
3917
-
3918
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3919
-        if (
3920
-            $messenger->name === 'html'
3921
-            && (
3922
-                is_null($message_type)
3923
-                || $message_type_name === 'invoice'
3924
-            )
3925
-        ) {
3926
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
3927
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3928
-            if ($count_updated > 0) {
3929
-                $msg = $message_type_name === 'invoice'
3930
-                    ? esc_html__(
3931
-                        '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.',
3932
-                        'event_espresso'
3933
-                    )
3934
-                    : esc_html__(
3935
-                        '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.',
3936
-                        'event_espresso'
3937
-                    );
3938
-                EE_Error::add_attention($msg);
3939
-            }
3940
-        }
3941
-
3942
-        return true;
3943
-    }
3944
-
3945
-
3946
-    /**
3947
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3948
-     *
3949
-     * @throws DomainException
3950
-     * @throws EE_Error
3951
-     * @throws EE_Error
3952
-     */
3953
-    public function update_mt_form()
3954
-    {
3955
-        if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
3956
-            wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
3957
-        }
3958
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
3959
-            EE_Error::add_error(
3960
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
3961
-                __FILE__,
3962
-                __FUNCTION__,
3963
-                __LINE__
3964
-            );
3965
-            $this->_return_json();
3966
-        }
3967
-
3968
-        $message_types = $this->get_installed_message_types();
3969
-        $message_type  = $message_types[ $this->_active_message_type_name ];
3970
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
3971
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
3972
-
3973
-        $this->_template_args['success'] = true;
3974
-        $this->_template_args['content'] = $content;
3975
-        $this->_return_json();
3976
-    }
3977
-
3978
-
3979
-    /**
3980
-     * this handles saving the settings for a messenger or message type
3981
-     *
3982
-     * @throws EE_Error
3983
-     * @throws EE_Error
3984
-     */
3985
-    public function save_settings()
3986
-    {
3987
-        if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
3988
-            wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
3989
-        }
3990
-        $type = $this->request->getRequestParam('type');
3991
-        if (! $type) {
3992
-            EE_Error::add_error(
3993
-                esc_html__(
3994
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
3995
-                    'event_espresso'
3996
-                ),
3997
-                __FILE__,
3998
-                __FUNCTION__,
3999
-                __LINE__
4000
-            );
4001
-            $this->_template_args['error'] = true;
4002
-            $this->_return_json();
4003
-        }
4004
-
4005
-
4006
-        if ($type === 'messenger') {
4007
-            // this should be an array.
4008
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4009
-            $messenger = $settings['messenger'];
4010
-            // remove messenger and message_types from settings array
4011
-            unset($settings['messenger'], $settings['message_types']);
4012
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4013
-        } elseif ($type === 'message_type') {
4014
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4015
-            $messenger    = $settings['messenger'];
4016
-            $message_type = $settings['message_type'];
4017
-            // remove messenger and message_types from settings array
4018
-            unset($settings['messenger'], $settings['message_types']);
4019
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4020
-        }
4021
-
4022
-        // okay we should have the data all setup.  Now we just update!
4023
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4024
-
4025
-        if ($success) {
4026
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4027
-        } else {
4028
-            EE_Error::add_error(
4029
-                esc_html__('Settings did not get updated', 'event_espresso'),
4030
-                __FILE__,
4031
-                __FUNCTION__,
4032
-                __LINE__
4033
-            );
4034
-        }
4035
-
4036
-        $this->_template_args['success'] = $success;
4037
-        $this->_return_json();
4038
-    }
4039
-
4040
-
4041
-
4042
-
4043
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4044
-
4045
-
4046
-    /**
4047
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4048
-     * However, this does not send immediately, it just queues for sending.
4049
-     *
4050
-     * @throws EE_Error
4051
-     * @throws InvalidDataTypeException
4052
-     * @throws InvalidInterfaceException
4053
-     * @throws InvalidArgumentException
4054
-     * @throws ReflectionException
4055
-     * @since 4.9.0
4056
-     */
4057
-    protected function _generate_now()
4058
-    {
4059
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4060
-        $this->_redirect_after_action(false, '', '', [], true);
4061
-    }
4062
-
4063
-
4064
-    /**
4065
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4066
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4067
-     *
4068
-     * @throws EE_Error
4069
-     * @throws InvalidDataTypeException
4070
-     * @throws InvalidInterfaceException
4071
-     * @throws InvalidArgumentException
4072
-     * @throws ReflectionException
4073
-     * @since 4.9.0
4074
-     */
4075
-    protected function _generate_and_send_now()
4076
-    {
4077
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4078
-        $this->_redirect_after_action(false, '', '', [], true);
4079
-    }
4080
-
4081
-
4082
-    /**
4083
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4084
-     *
4085
-     * @throws EE_Error
4086
-     * @throws InvalidDataTypeException
4087
-     * @throws InvalidInterfaceException
4088
-     * @throws InvalidArgumentException
4089
-     * @throws ReflectionException
4090
-     * @since 4.9.0
4091
-     */
4092
-    protected function _queue_for_resending()
4093
-    {
4094
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4095
-        $this->_redirect_after_action(false, '', '', [], true);
4096
-    }
4097
-
4098
-
4099
-    /**
4100
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4101
-     *
4102
-     * @throws EE_Error
4103
-     * @throws InvalidDataTypeException
4104
-     * @throws InvalidInterfaceException
4105
-     * @throws InvalidArgumentException
4106
-     * @throws ReflectionException
4107
-     * @since 4.9.0
4108
-     */
4109
-    protected function _send_now()
4110
-    {
4111
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4112
-        $this->_redirect_after_action(false, '', '', [], true);
4113
-    }
4114
-
4115
-
4116
-    /**
4117
-     * Deletes EE_messages for IDs in the request.
4118
-     *
4119
-     * @throws EE_Error
4120
-     * @throws InvalidDataTypeException
4121
-     * @throws InvalidInterfaceException
4122
-     * @throws InvalidArgumentException
4123
-     * @throws ReflectionException
4124
-     * @since 4.9.0
4125
-     */
4126
-    protected function _delete_ee_messages()
4127
-    {
4128
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4129
-        $deleted_count = 0;
4130
-        foreach ($MSG_IDs as $MSG_ID) {
4131
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4132
-                $deleted_count++;
4133
-            }
4134
-        }
4135
-        if ($deleted_count) {
4136
-            EE_Error::add_success(
4137
-                esc_html(
4138
-                    _n(
4139
-                        'Message successfully deleted',
4140
-                        'Messages successfully deleted',
4141
-                        $deleted_count,
4142
-                        'event_espresso'
4143
-                    )
4144
-                )
4145
-            );
4146
-        } else {
4147
-            EE_Error::add_error(
4148
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4149
-                __FILE__,
4150
-                __FUNCTION__,
4151
-                __LINE__
4152
-            );
4153
-        }
4154
-        $this->_redirect_after_action(false, '', '', [], true);
4155
-    }
4156
-
4157
-
4158
-    /**
4159
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4160
-     *
4161
-     * @return array
4162
-     * @since 4.9.0
4163
-     */
4164
-    protected function _get_msg_ids_from_request()
4165
-    {
4166
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4167
-        if (empty($MSG_IDs)) {
4168
-            return [];
4169
-        }
4170
-        // if 'MSG_ID' was just a single ID (not an array)
4171
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4172
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4173
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4174
-            ? $MSG_IDs
4175
-            : array_keys($MSG_IDs);
4176
-    }
2547
+	}
2548
+
2549
+
2550
+	/**
2551
+	 * @throws EE_Error
2552
+	 * @throws ReflectionException
2553
+	 * @deprecated 5.0.8.p
2554
+	 */
2555
+	protected function _insert_or_update_message_template($new = false)
2556
+	{
2557
+		if ($new) {
2558
+			$this->insertMessageTemplate();
2559
+		} else {
2560
+			$this->updateMessageTemplate();
2561
+		}
2562
+	}
2563
+
2564
+
2565
+	/**
2566
+	 * @throws EE_Error
2567
+	 * @throws ReflectionException
2568
+	 */
2569
+	protected function insertMessageTemplate(): void
2570
+	{
2571
+		$success   = true;
2572
+		$templates = [];
2573
+		try {
2574
+			$templates = $this->getMessageTemplateManager()->generateNewTemplates();
2575
+		} catch (Exception $exception) {
2576
+			$success = false;
2577
+			EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2578
+		}
2579
+
2580
+		/** @var MessageTemplateRequestData $form_data */
2581
+		$form_data = $this->loader->getShared(MessageTemplateRequestData::class);
2582
+		$this->_redirect_after_action(
2583
+			$success && isset($templates['GRP_ID'], $templates['MTP_context']),
2584
+			$this->generateUpdateDescription($form_data->messenger(), $form_data->messageType(), $form_data->context()),
2585
+			'created',
2586
+			[
2587
+				'id'      => $templates['GRP_ID'] ?? 0,
2588
+				'context' => $templates['MTP_context'] ?? '',
2589
+				'action'  => 'edit_message_template',
2590
+			],
2591
+			$this->performTestSendAfterUpdate($form_data->messenger(), $form_data->messageType(), $form_data->context())
2592
+		);
2593
+	}
2594
+
2595
+
2596
+	/**
2597
+	 * @throws EE_Error
2598
+	 * @throws ReflectionException
2599
+	 */
2600
+	protected function updateMessageTemplate(): void
2601
+	{
2602
+		$success = true;
2603
+		try {
2604
+			$this->getMessageTemplateManager()->updateExistingTemplates();
2605
+		} catch (Exception $exception) {
2606
+			$success = false;
2607
+			EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2608
+		}
2609
+
2610
+		/** @var MessageTemplateRequestData $form_data */
2611
+		$form_data = $this->loader->getShared(MessageTemplateRequestData::class);
2612
+
2613
+		$this->_redirect_after_action(
2614
+			$success,
2615
+			$this->generateUpdateDescription($form_data->messenger(), $form_data->messageType(), $form_data->context()),
2616
+			'updated',
2617
+			[
2618
+				'id'      => $form_data->groupID(),
2619
+				'context' => $form_data->context(),
2620
+				'action'  => 'edit_message_template',
2621
+			],
2622
+			$this->performTestSendAfterUpdate($form_data->messenger(), $form_data->messageType(), $form_data->context())
2623
+		);
2624
+	}
2625
+
2626
+
2627
+	/**
2628
+	 * @param string $messenger
2629
+	 * @param string $message_type
2630
+	 * @param string $context
2631
+	 * @return string
2632
+	 * @since 4.10.29.p
2633
+	 */
2634
+	private function generateUpdateDescription(string $messenger, string $message_type, string $context): string
2635
+	{
2636
+		// need the message type and messenger objects to be able to use the labels for the notices
2637
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
2638
+		$messenger_label  = $messenger_object instanceof EE_messenger
2639
+			? ucwords($messenger_object->label['singular'])
2640
+			: '';
2641
+
2642
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
2643
+		$message_type_label  = $message_type_object instanceof EE_message_type
2644
+			? ucwords($message_type_object->label['singular'])
2645
+			: '';
2646
+
2647
+		$context   = ucwords(str_replace('_', ' ', $context));
2648
+		$item_desc = $messenger_label && $message_type_label
2649
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2650
+			: '';
2651
+		$item_desc .= 'Message Template';
2652
+		return $item_desc;
2653
+	}
2654
+
2655
+
2656
+	/**
2657
+	 * @param string $messenger
2658
+	 * @param string $message_type
2659
+	 * @param string $context
2660
+	 * @return bool
2661
+	 * @throws EE_Error
2662
+	 * @throws ReflectionException
2663
+	 * @since 4.10.29.p
2664
+	 */
2665
+	private function performTestSendAfterUpdate(string $messenger, string $message_type, string $context): bool
2666
+	{
2667
+		// was a test send triggered?
2668
+		if ($this->request->requestParamIsSet('test_button')) {
2669
+			EE_Error::overwrite_success();
2670
+			$this->_do_test_send($context, $messenger, $message_type);
2671
+			return true;
2672
+		}
2673
+		return false;
2674
+	}
2675
+
2676
+
2677
+	/**
2678
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2679
+	 *
2680
+	 * @param string $context      what context being tested
2681
+	 * @param string $messenger    messenger being tested
2682
+	 * @param string $message_type message type being tested
2683
+	 * @throws EE_Error
2684
+	 * @throws InvalidArgumentException
2685
+	 * @throws InvalidDataTypeException
2686
+	 * @throws InvalidInterfaceException
2687
+	 * @throws ReflectionException
2688
+	 */
2689
+	protected function _do_test_send(string $context, string $messenger, string $message_type)
2690
+	{
2691
+		// set things up for preview
2692
+		$this->request->setRequestParam('messenger', $messenger);
2693
+		$this->request->setRequestParam('message_type', $message_type);
2694
+		$this->request->setRequestParam('context', $context);
2695
+		$this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2696
+
2697
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
2698
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
2699
+
2700
+		// let's save any existing fields that might be required by the messenger
2701
+		if (
2702
+			! empty($test_settings_fld)
2703
+			&& $active_messenger instanceof EE_messenger
2704
+			&& apply_filters(
2705
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2706
+				true,
2707
+				$test_settings_fld,
2708
+				$active_messenger
2709
+			)
2710
+		) {
2711
+			$active_messenger->set_existing_test_settings($test_settings_fld);
2712
+		}
2713
+
2714
+		/**
2715
+		 * Use filter to add additional controls on whether message can send or not
2716
+		 */
2717
+		if (
2718
+			apply_filters(
2719
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
2720
+				true,
2721
+				$context,
2722
+				$this->request->requestParams(),
2723
+				$messenger,
2724
+				$message_type
2725
+			)
2726
+		) {
2727
+			if (EEM_Event::instance()->count() > 0) {
2728
+				$success = $this->_preview_message(true);
2729
+				if ($success) {
2730
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
2731
+				} else {
2732
+					EE_Error::add_error(
2733
+						esc_html__('The test message was not sent', 'event_espresso'),
2734
+						__FILE__,
2735
+						__FUNCTION__,
2736
+						__LINE__
2737
+					);
2738
+				}
2739
+			} else {
2740
+				$this->noEventsErrorMessage(true);
2741
+			}
2742
+		}
2743
+	}
2744
+
2745
+
2746
+	/**
2747
+	 * [_trash_or_restore_message_template]
2748
+	 *
2749
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2750
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2751
+	 *                        an individual context (FALSE).
2752
+	 * @return void
2753
+	 * @throws EE_Error
2754
+	 * @throws InvalidArgumentException
2755
+	 * @throws InvalidDataTypeException
2756
+	 * @throws InvalidInterfaceException
2757
+	 * @throws ReflectionException
2758
+	 */
2759
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2760
+	{
2761
+		$success = 1;
2762
+
2763
+		// incoming GRP_IDs
2764
+		if ($all) {
2765
+			// Checkboxes
2766
+			$checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2767
+			if (! empty($checkboxes)) {
2768
+				// if array has more than one element then success message should be plural.
2769
+				// todo: what about nonce?
2770
+				$success = count($checkboxes) > 1 ? 2 : 1;
2771
+
2772
+				// cycle through checkboxes
2773
+				foreach (array_keys($checkboxes) as $GRP_ID) {
2774
+					$trashed_or_restored = $trash
2775
+						? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2776
+						: $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2777
+					if (! $trashed_or_restored) {
2778
+						$success = 0;
2779
+					}
2780
+				}
2781
+			} else {
2782
+				// grab single GRP_ID and handle
2783
+				$GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2784
+				if (! empty($GRP_ID)) {
2785
+					$trashed_or_restored = $trash
2786
+						? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2787
+						: $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2788
+					if (! $trashed_or_restored) {
2789
+						$success = 0;
2790
+					}
2791
+				} else {
2792
+					$success = 0;
2793
+				}
2794
+			}
2795
+		}
2796
+
2797
+		$action_desc = $trash
2798
+			? esc_html__('moved to the trash', 'event_espresso')
2799
+			: esc_html__('restored', 'event_espresso');
2800
+
2801
+		$template_switch = $this->request->getRequestParam('template_switch', false, DataType::BOOLEAN);
2802
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
2803
+
2804
+		$item_desc = $all ? _n(
2805
+			'Message Template Group',
2806
+			'Message Template Groups',
2807
+			$success,
2808
+			'event_espresso'
2809
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2810
+
2811
+		$item_desc = $template_switch
2812
+			? _n('template', 'templates', $success, 'event_espresso')
2813
+			: $item_desc;
2814
+
2815
+		$this->_redirect_after_action(
2816
+			$success,
2817
+			$item_desc,
2818
+			$action_desc,
2819
+			[
2820
+				'action' => $this->request->getRequestParam('return'),
2821
+			]
2822
+		);
2823
+	}
2824
+
2825
+
2826
+	/**
2827
+	 * [_delete_message_template]
2828
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2829
+	 *
2830
+	 * @return void
2831
+	 * @throws EE_Error
2832
+	 * @throws InvalidArgumentException
2833
+	 * @throws InvalidDataTypeException
2834
+	 * @throws InvalidInterfaceException
2835
+	 * @throws ReflectionException
2836
+	 */
2837
+	protected function _delete_message_template()
2838
+	{
2839
+		// checkboxes
2840
+		$checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2841
+		if (! empty($checkboxes)) {
2842
+			// if array has more than one element then success message should be plural
2843
+			$success = count($checkboxes) > 1 ? 2 : 1;
2844
+
2845
+			// cycle through bulk action checkboxes
2846
+			foreach (array_keys($checkboxes) as $GRP_ID) {
2847
+				$success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplateGroup($GRP_ID) ? $success
2848
+					: false;
2849
+			}
2850
+		} else {
2851
+			// grab single grp_id and delete
2852
+			$GRP_ID  = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2853
+			$success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplateGroup($GRP_ID);
2854
+		}
2855
+
2856
+		$this->_redirect_after_action(
2857
+			$success,
2858
+			'Message Templates',
2859
+			'deleted',
2860
+			[
2861
+				'action' => $this->request->getRequestParam('return'),
2862
+			]
2863
+		);
2864
+	}
2865
+
2866
+
2867
+	/**
2868
+	 *    _learn_more_about_message_templates_link
2869
+	 *
2870
+	 * @access protected
2871
+	 * @return string
2872
+	 */
2873
+	protected function _learn_more_about_message_templates_link()
2874
+	{
2875
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
2876
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
2877
+			   . '</a>';
2878
+	}
2879
+
2880
+
2881
+	/**
2882
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2883
+	 * ajax and other routes.
2884
+	 *
2885
+	 * @return void
2886
+	 * @throws DomainException
2887
+	 * @throws EE_Error
2888
+	 */
2889
+	protected function _settings()
2890
+	{
2891
+		$this->_set_m_mt_settings();
2892
+		// let's setup the messenger tabs
2893
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
2894
+			$this->_m_mt_settings['messenger_tabs'],
2895
+			'messenger_links',
2896
+			'|',
2897
+			$this->request->getRequestParam('selected_messenger', 'email')
2898
+		);
2899
+
2900
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2901
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2902
+
2903
+		$this->display_admin_page_with_sidebar();
2904
+	}
2905
+
2906
+
2907
+	/**
2908
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2909
+	 *
2910
+	 * @access protected
2911
+	 * @return void
2912
+	 * @throws DomainException
2913
+	 */
2914
+	protected function _set_m_mt_settings()
2915
+	{
2916
+		// first if this is already set then lets get out no need to regenerate data.
2917
+		if (! empty($this->_m_mt_settings)) {
2918
+			return;
2919
+		}
2920
+
2921
+		// get all installed messengers and message_types
2922
+		$messengers    = $this->_message_resource_manager->installed_messengers();
2923
+		$message_types = $this->_message_resource_manager->installed_message_types();
2924
+
2925
+
2926
+		// assemble the array for the _tab_text_links helper
2927
+
2928
+		foreach ($messengers as $messenger) {
2929
+			$active                                                     =
2930
+				$this->_message_resource_manager->is_messenger_active($messenger->name);
2931
+			$class                                                      =
2932
+				'ee-messenger-' . sanitize_key($messenger->label['singular']);
2933
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
2934
+				'label' => ucwords($messenger->label['singular']),
2935
+				'class' => $active ? "{$class} messenger-active" : $class,
2936
+				'href'  => $messenger->name,
2937
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
2938
+				'slug'  => $messenger->name,
2939
+				'obj'   => $messenger,
2940
+				'icon'  => $active
2941
+					? '<span class="dashicons dashicons-yes-alt"></span>'
2942
+					: '<span class="dashicons dashicons-remove"></span>',
2943
+			];
2944
+
2945
+
2946
+			$message_types_for_messenger = $messenger->get_valid_message_types();
2947
+
2948
+			foreach ($message_types as $message_type) {
2949
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
2950
+				// it shouldn't show in either the inactive OR active metabox.
2951
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
2952
+					continue;
2953
+				}
2954
+
2955
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
2956
+					$messenger->name,
2957
+					$message_type->name
2958
+				)
2959
+					? 'active'
2960
+					: 'inactive';
2961
+
2962
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
2963
+					'label'    => ucwords($message_type->label['singular']),
2964
+					'class'    => 'message-type-' . $a_or_i,
2965
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2966
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2967
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2968
+					'title'    => $a_or_i === 'active'
2969
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2970
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
2971
+					'content'  => $a_or_i === 'active'
2972
+						? $this->_message_type_settings_content($message_type, $messenger, true)
2973
+						: $this->_message_type_settings_content($message_type, $messenger),
2974
+					'slug'     => $message_type->name,
2975
+					'active'   => $a_or_i === 'active',
2976
+					'obj'      => $message_type,
2977
+				];
2978
+			}
2979
+		}
2980
+	}
2981
+
2982
+
2983
+	/**
2984
+	 * This just prepares the content for the message type settings
2985
+	 *
2986
+	 * @param EE_message_type $message_type The message type object
2987
+	 * @param EE_messenger    $messenger    The messenger object
2988
+	 * @param boolean         $active       Whether the message type is active or not
2989
+	 * @return string html output for the content
2990
+	 * @throws DomainException
2991
+	 */
2992
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
2993
+	{
2994
+		// get message type fields
2995
+		$fields                                         = $message_type->get_admin_settings_fields();
2996
+		$settings_template_args['template_form_fields'] = '';
2997
+
2998
+		if (! empty($fields) && $active) {
2999
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3000
+			foreach ($fields as $fldname => $fldprops) {
3001
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3002
+				$template_form_field[ $field_id ] = [
3003
+					'name'       => 'message_type_settings[' . $fldname . ']',
3004
+					'label'      => $fldprops['label'],
3005
+					'input'      => $fldprops['field_type'],
3006
+					'type'       => $fldprops['value_type'],
3007
+					'required'   => $fldprops['required'],
3008
+					'validation' => $fldprops['validation'],
3009
+					'value'      => $existing_settings[ $fldname ] ?? $fldprops['default'],
3010
+					'options'    => $fldprops['options'] ?? [],
3011
+					'default'    => $existing_settings[ $fldname ] ?? $fldprops['default'],
3012
+					'css_class'  => 'no-drag',
3013
+					'format'     => $fldprops['format'],
3014
+				];
3015
+			}
3016
+
3017
+
3018
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3019
+				? $this->_generate_admin_form_fields(
3020
+					$template_form_field,
3021
+					'string',
3022
+					'ee_mt_activate_form'
3023
+				)
3024
+				: '';
3025
+		}
3026
+
3027
+		$settings_template_args['description'] = $message_type->description;
3028
+		// we also need some hidden fields
3029
+		$hidden_fields = [
3030
+			'message_type_settings[messenger]' . $message_type->name    => [
3031
+				'type'  => 'hidden',
3032
+				'value' => $messenger->name,
3033
+			],
3034
+			'message_type_settings[message_type]' . $message_type->name => [
3035
+				'type'  => 'hidden',
3036
+				'value' => $message_type->name,
3037
+			],
3038
+			'type' . $message_type->name                                => [
3039
+				'type'  => 'hidden',
3040
+				'value' => 'message_type',
3041
+			],
3042
+		];
3043
+
3044
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3045
+			$hidden_fields,
3046
+			'array'
3047
+		);
3048
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3049
+			? ' hidden'
3050
+			: '';
3051
+
3052
+
3053
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3054
+		return EEH_Template::display_template($template, $settings_template_args, true);
3055
+	}
3056
+
3057
+
3058
+	/**
3059
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3060
+	 *
3061
+	 * @access protected
3062
+	 * @return void
3063
+	 * @throws DomainException
3064
+	 */
3065
+	protected function _messages_settings_metaboxes()
3066
+	{
3067
+		$this->_set_m_mt_settings();
3068
+		$m_boxes         = $mt_boxes = [];
3069
+		$m_template_args = $mt_template_args = [];
3070
+
3071
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3072
+
3073
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3074
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3075
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3076
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3077
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3078
+
3079
+				// messenger meta boxes
3080
+				$active         = $selected_messenger === $messenger;
3081
+				$active_mt_tabs = $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] ?? '';
3082
+
3083
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3084
+					esc_html__('%s Settings', 'event_espresso'),
3085
+					$tab_array['label']
3086
+				);
3087
+
3088
+				$m_template_args[ $messenger . '_a_box' ] = [
3089
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3090
+					'inactive_message_types' => isset(
3091
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3092
+					)
3093
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3094
+						: '',
3095
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3096
+					'hidden'                 => $active ? '' : ' hidden',
3097
+					'hide_on_message'        => $hide_on_message,
3098
+					'messenger'              => $messenger,
3099
+					'active'                 => $active,
3100
+				];
3101
+
3102
+				// message type meta boxes
3103
+				// (which is really just the inactive container for each messenger
3104
+				// showing inactive message types for that messenger)
3105
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3106
+				$mt_template_args[ $messenger . '_i_box' ] = [
3107
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3108
+					'inactive_message_types' => isset(
3109
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3110
+					)
3111
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3112
+						: '',
3113
+					'hidden'                 => $active ? '' : ' hidden',
3114
+					'hide_on_message'        => $hide_on_message,
3115
+					'hide_off_message'       => $hide_off_message,
3116
+					'messenger'              => $messenger,
3117
+					'active'                 => $active,
3118
+				];
3119
+			}
3120
+		}
3121
+
3122
+
3123
+		// register messenger metaboxes
3124
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3125
+		foreach ($m_boxes as $box => $label) {
3126
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3127
+			$msgr          = str_replace('_a_box', '', $box);
3128
+			$this->addMetaBox(
3129
+				'espresso_' . $msgr . '_settings',
3130
+				$label,
3131
+				function ($post, $metabox) {
3132
+					EEH_Template::display_template(
3133
+						$metabox['args']['template_path'],
3134
+						$metabox['args']['template_args']
3135
+					);
3136
+				},
3137
+				$this->_current_screen->id,
3138
+				'normal',
3139
+				'high',
3140
+				$callback_args
3141
+			);
3142
+		}
3143
+
3144
+		// register message type metaboxes
3145
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3146
+		foreach ($mt_boxes as $box => $label) {
3147
+			$callback_args = [
3148
+				'template_path' => $mt_template_path,
3149
+				'template_args' => $mt_template_args[ $box ],
3150
+			];
3151
+			$mt            = str_replace('_i_box', '', $box);
3152
+			$this->addMetaBox(
3153
+				'espresso_' . $mt . '_inactive_mts',
3154
+				$label,
3155
+				function ($post, $metabox) {
3156
+					EEH_Template::display_template(
3157
+						$metabox['args']['template_path'],
3158
+						$metabox['args']['template_args']
3159
+					);
3160
+				},
3161
+				$this->_current_screen->id,
3162
+				'side',
3163
+				'high',
3164
+				$callback_args
3165
+			);
3166
+		}
3167
+
3168
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3169
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3170
+		if (is_main_site()) {
3171
+			$this->addMetaBox(
3172
+				'espresso_global_message_settings',
3173
+				esc_html__('Global Message Settings', 'event_espresso'),
3174
+				[$this, 'global_messages_settings_metabox_content'],
3175
+				$this->_current_screen->id,
3176
+				'normal',
3177
+				'low',
3178
+				[]
3179
+			);
3180
+		}
3181
+	}
3182
+
3183
+
3184
+	/**
3185
+	 *  This generates the content for the global messages settings metabox.
3186
+	 *
3187
+	 * @return void
3188
+	 * @throws EE_Error
3189
+	 * @throws InvalidArgumentException
3190
+	 * @throws ReflectionException
3191
+	 * @throws InvalidDataTypeException
3192
+	 * @throws InvalidInterfaceException
3193
+	 */
3194
+	public function global_messages_settings_metabox_content()
3195
+	{
3196
+		$form = $this->_generate_global_settings_form();
3197
+		echo wp_kses(
3198
+			$form->form_open(
3199
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3200
+				'POST'
3201
+			),
3202
+			AllowedTags::getWithFormTags()
3203
+		);
3204
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3205
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3206
+	}
3207
+
3208
+
3209
+	/**
3210
+	 * This generates and returns the form object for the global messages settings.
3211
+	 *
3212
+	 * @return EE_Form_Section_Proper
3213
+	 * @throws EE_Error
3214
+	 * @throws InvalidArgumentException
3215
+	 * @throws ReflectionException
3216
+	 * @throws InvalidDataTypeException
3217
+	 * @throws InvalidInterfaceException
3218
+	 */
3219
+	protected function _generate_global_settings_form()
3220
+	{
3221
+		/** @var EE_Network_Core_Config $network_config */
3222
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3223
+
3224
+		return new EE_Form_Section_Proper(
3225
+			[
3226
+				'name'            => 'global_messages_settings',
3227
+				'html_id'         => 'global_messages_settings',
3228
+				'html_class'      => 'form-table',
3229
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3230
+				'subsections'     => apply_filters(
3231
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3232
+					[
3233
+						'do_messages_on_same_request' => new EE_Select_Input(
3234
+							[
3235
+								true  => esc_html__('On the same request', 'event_espresso'),
3236
+								false => esc_html__('On a separate request', 'event_espresso'),
3237
+							],
3238
+							[
3239
+								'default'         => $network_config->do_messages_on_same_request,
3240
+								'html_label_text' => esc_html__(
3241
+									'Generate and send all messages:',
3242
+									'event_espresso'
3243
+								),
3244
+								'html_help_text'  => esc_html__(
3245
+									'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.',
3246
+									'event_espresso'
3247
+								),
3248
+							]
3249
+						),
3250
+						'delete_threshold'            => new EE_Select_Input(
3251
+							[
3252
+								0  => esc_html__('Forever', 'event_espresso'),
3253
+								3  => esc_html__('3 Months', 'event_espresso'),
3254
+								6  => esc_html__('6 Months', 'event_espresso'),
3255
+								9  => esc_html__('9 Months', 'event_espresso'),
3256
+								12 => esc_html__('12 Months', 'event_espresso'),
3257
+								24 => esc_html__('24 Months', 'event_espresso'),
3258
+								36 => esc_html__('36 Months', 'event_espresso'),
3259
+							],
3260
+							[
3261
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3262
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3263
+								'html_help_text'  => esc_html__(
3264
+									'You can control how long a record of processed messages is kept via this option.',
3265
+									'event_espresso'
3266
+								),
3267
+							]
3268
+						),
3269
+						'update_settings'             => new EE_Submit_Input(
3270
+							[
3271
+								'default'         => esc_html__('Update', 'event_espresso'),
3272
+								'html_label_text' => '',
3273
+							]
3274
+						),
3275
+					]
3276
+				),
3277
+			]
3278
+		);
3279
+	}
3280
+
3281
+
3282
+	/**
3283
+	 * This handles updating the global settings set on the admin page.
3284
+	 *
3285
+	 * @throws EE_Error
3286
+	 * @throws InvalidDataTypeException
3287
+	 * @throws InvalidInterfaceException
3288
+	 * @throws InvalidArgumentException
3289
+	 * @throws ReflectionException
3290
+	 */
3291
+	protected function _update_global_settings()
3292
+	{
3293
+		/** @var EE_Network_Core_Config $network_config */
3294
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3295
+		$messages_config = EE_Registry::instance()->CFG->messages;
3296
+		$form            = $this->_generate_global_settings_form();
3297
+		if ($form->was_submitted()) {
3298
+			$form->receive_form_submission();
3299
+			if ($form->is_valid()) {
3300
+				$valid_data = $form->valid_data();
3301
+				// \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
3302
+				foreach ($valid_data as $property => $value) {
3303
+					$setter = 'set_' . $property;
3304
+					if (method_exists($network_config, $setter)) {
3305
+						$network_config->{$setter}($value);
3306
+					} elseif (
3307
+						property_exists($network_config, $property)
3308
+						&& $network_config->{$property} !== $value
3309
+					) {
3310
+						$network_config->{$property} = $value;
3311
+					} elseif (
3312
+						property_exists($messages_config, $property)
3313
+						&& $messages_config->{$property} !== $value
3314
+					) {
3315
+						$messages_config->{$property} = $value;
3316
+					}
3317
+				}
3318
+				// only update if the form submission was valid!
3319
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3320
+				EE_Registry::instance()->CFG->update_espresso_config();
3321
+				EE_Error::overwrite_success();
3322
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3323
+			}
3324
+		}
3325
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3326
+	}
3327
+
3328
+
3329
+	/**
3330
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3331
+	 *
3332
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3333
+	 * @return string html formatted tabs
3334
+	 * @throws DomainException
3335
+	 */
3336
+	protected function _get_mt_tabs($tab_array)
3337
+	{
3338
+		$tab_array = (array) $tab_array;
3339
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3340
+		$tabs      = '';
3341
+
3342
+		foreach ($tab_array as $tab) {
3343
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3344
+		}
3345
+
3346
+		return $tabs;
3347
+	}
3348
+
3349
+
3350
+	/**
3351
+	 * This prepares the content of the messenger meta box admin settings
3352
+	 *
3353
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3354
+	 * @return string html formatted content
3355
+	 * @throws DomainException
3356
+	 */
3357
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3358
+	{
3359
+		$fields = $messenger->get_admin_settings_fields();
3360
+
3361
+		$settings_template_args['template_form_fields'] = '';
3362
+		// is $messenger active?
3363
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3364
+
3365
+
3366
+		if (! empty($fields)) {
3367
+			$existing_settings = $messenger->get_existing_admin_settings();
3368
+
3369
+			foreach ($fields as $field_name => $field_props) {
3370
+				$field_id                         = $messenger->name . '-' . $field_name;
3371
+				$template_form_field[ $field_id ] = [
3372
+					'name'       => 'messenger_settings[' . $field_id . ']',
3373
+					'label'      => $field_props['label'],
3374
+					'input'      => $field_props['field_type'],
3375
+					'type'       => $field_props['value_type'],
3376
+					'required'   => $field_props['required'],
3377
+					'validation' => $field_props['validation'],
3378
+					'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3379
+					'css_class'  => '',
3380
+					'format'     => $field_props['format'],
3381
+				];
3382
+			}
3383
+
3384
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3385
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3386
+				: '';
3387
+		}
3388
+
3389
+		// we also need some hidden fields
3390
+		$settings_template_args['hidden_fields'] = [
3391
+			'messenger_settings[messenger]' . $messenger->name => [
3392
+				'type'  => 'hidden',
3393
+				'value' => $messenger->name,
3394
+			],
3395
+			'type' . $messenger->name                          => [
3396
+				'type'  => 'hidden',
3397
+				'value' => 'messenger',
3398
+			],
3399
+		];
3400
+
3401
+		// make sure any active message types that are existing are included in the hidden fields
3402
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3403
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3404
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3405
+					'type'  => 'hidden',
3406
+					'value' => $mt,
3407
+				];
3408
+			}
3409
+		}
3410
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3411
+			$settings_template_args['hidden_fields'],
3412
+			'array'
3413
+		);
3414
+		$active                                  =
3415
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3416
+
3417
+		$settings_template_args['messenger']           = $messenger->name;
3418
+		$settings_template_args['description']         = $messenger->description;
3419
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3420
+
3421
+
3422
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3423
+			$messenger->name
3424
+		)
3425
+			? $settings_template_args['show_hide_edit_form']
3426
+			: ' hidden';
3427
+
3428
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3429
+			? ' hidden'
3430
+			: $settings_template_args['show_hide_edit_form'];
3431
+
3432
+
3433
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3434
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3435
+		$settings_template_args['on_off_status'] = $active;
3436
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3437
+		return EEH_Template::display_template(
3438
+			$template,
3439
+			$settings_template_args,
3440
+			true
3441
+		);
3442
+	}
3443
+
3444
+
3445
+	/**
3446
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3447
+	 *
3448
+	 * @throws DomainException
3449
+	 * @throws EE_Error
3450
+	 * @throws InvalidDataTypeException
3451
+	 * @throws InvalidInterfaceException
3452
+	 * @throws InvalidArgumentException
3453
+	 * @throws ReflectionException
3454
+	 */
3455
+	public function activate_messenger_toggle()
3456
+	{
3457
+		if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
3458
+			wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
3459
+		}
3460
+		$success = true;
3461
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3462
+		// let's check that we have required data
3463
+
3464
+		if (! $this->_active_messenger_name) {
3465
+			EE_Error::add_error(
3466
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3467
+				__FILE__,
3468
+				__FUNCTION__,
3469
+				__LINE__
3470
+			);
3471
+			$success = false;
3472
+		}
3473
+
3474
+		// do a nonce check here since we're not arriving via a normal route
3475
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
3476
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
3477
+
3478
+		$this->_verify_nonce($nonce, $nonce_ref);
3479
+
3480
+
3481
+		$status = $this->request->getRequestParam('status');
3482
+		if (! $status) {
3483
+			EE_Error::add_error(
3484
+				esc_html__(
3485
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3486
+					'event_espresso'
3487
+				),
3488
+				__FILE__,
3489
+				__FUNCTION__,
3490
+				__LINE__
3491
+			);
3492
+			$success = false;
3493
+		}
3494
+
3495
+		// do check to verify we have a valid status.
3496
+		if ($status !== 'off' && $status !== 'on') {
3497
+			EE_Error::add_error(
3498
+				sprintf(
3499
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3500
+					$status
3501
+				),
3502
+				__FILE__,
3503
+				__FUNCTION__,
3504
+				__LINE__
3505
+			);
3506
+			$success = false;
3507
+		}
3508
+
3509
+		if ($success) {
3510
+			// made it here?  Stop dawdling then!!
3511
+			$success = $status === 'off'
3512
+				? $this->_deactivate_messenger($this->_active_messenger_name)
3513
+				: $this->_activate_messenger($this->_active_messenger_name);
3514
+		}
3515
+
3516
+		$this->_template_args['success'] = $success;
3517
+
3518
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
3519
+		$this->_return_json();
3520
+	}
3521
+
3522
+
3523
+	/**
3524
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3525
+	 *
3526
+	 * @throws DomainException
3527
+	 * @throws EE_Error
3528
+	 * @throws ReflectionException
3529
+	 * @throws InvalidDataTypeException
3530
+	 * @throws InvalidInterfaceException
3531
+	 * @throws InvalidArgumentException
3532
+	 */
3533
+	public function activate_mt_toggle()
3534
+	{
3535
+		if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
3536
+			wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
3537
+		}
3538
+		$success = true;
3539
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3540
+
3541
+		// let's make sure we have the necessary data
3542
+		if (! $this->_active_message_type_name) {
3543
+			EE_Error::add_error(
3544
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3545
+				__FILE__,
3546
+				__FUNCTION__,
3547
+				__LINE__
3548
+			);
3549
+			$success = false;
3550
+		}
3551
+
3552
+		if (! $this->_active_messenger_name) {
3553
+			EE_Error::add_error(
3554
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3555
+				__FILE__,
3556
+				__FUNCTION__,
3557
+				__LINE__
3558
+			);
3559
+			$success = false;
3560
+		}
3561
+
3562
+		$status = $this->request->getRequestParam('status');
3563
+		if (! $status) {
3564
+			EE_Error::add_error(
3565
+				esc_html__(
3566
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3567
+					'event_espresso'
3568
+				),
3569
+				__FILE__,
3570
+				__FUNCTION__,
3571
+				__LINE__
3572
+			);
3573
+			$success = false;
3574
+		}
3575
+
3576
+
3577
+		// do check to verify we have a valid status.
3578
+		if ($status !== 'activate' && $status !== 'deactivate') {
3579
+			EE_Error::add_error(
3580
+				sprintf(
3581
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3582
+					$status
3583
+				),
3584
+				__FILE__,
3585
+				__FUNCTION__,
3586
+				__LINE__
3587
+			);
3588
+			$success = false;
3589
+		}
3590
+
3591
+
3592
+		// do a nonce check here since we're not arriving via a normal route
3593
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
3594
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
3595
+
3596
+		if ($success) {
3597
+			// made it here? um, what are you waiting for then?
3598
+			$success = $status === 'deactivate'
3599
+				? $this->_deactivate_message_type_for_messenger(
3600
+					$this->_active_messenger_name,
3601
+					$this->_active_message_type_name
3602
+				)
3603
+				: $this->_activate_message_type_for_messenger(
3604
+					$this->_active_messenger_name,
3605
+					$this->_active_message_type_name
3606
+				);
3607
+		}
3608
+
3609
+		$this->_template_args['success'] = $success;
3610
+		$this->_return_json();
3611
+	}
3612
+
3613
+
3614
+	/**
3615
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3616
+	 *
3617
+	 * @param string $messenger_name The name of the messenger being activated
3618
+	 * @return bool
3619
+	 * @throws DomainException
3620
+	 * @throws EE_Error
3621
+	 * @throws InvalidArgumentException
3622
+	 * @throws ReflectionException
3623
+	 * @throws InvalidDataTypeException
3624
+	 * @throws InvalidInterfaceException
3625
+	 */
3626
+	protected function _activate_messenger($messenger_name)
3627
+	{
3628
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3629
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3630
+			? $active_messenger->get_default_message_types()
3631
+			: [];
3632
+
3633
+		// ensure is active
3634
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
3635
+
3636
+		// set response_data for reload
3637
+		foreach ($message_types_to_activate as $message_type_name) {
3638
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3639
+			if (
3640
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
3641
+					$messenger_name,
3642
+					$message_type_name
3643
+				)
3644
+				&& $message_type instanceof EE_message_type
3645
+			) {
3646
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3647
+				if ($message_type->get_admin_settings_fields()) {
3648
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3649
+				}
3650
+			}
3651
+		}
3652
+
3653
+		// add success message for activating messenger
3654
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3655
+	}
3656
+
3657
+
3658
+	/**
3659
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3660
+	 *
3661
+	 * @param string $messenger_name The name of the messenger being activated
3662
+	 * @return bool
3663
+	 * @throws DomainException
3664
+	 * @throws EE_Error
3665
+	 * @throws InvalidArgumentException
3666
+	 * @throws ReflectionException
3667
+	 * @throws InvalidDataTypeException
3668
+	 * @throws InvalidInterfaceException
3669
+	 */
3670
+	protected function _deactivate_messenger($messenger_name)
3671
+	{
3672
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3673
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3674
+
3675
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3676
+	}
3677
+
3678
+
3679
+	/**
3680
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3681
+	 *
3682
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3683
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3684
+	 * @return bool
3685
+	 * @throws DomainException
3686
+	 * @throws EE_Error
3687
+	 * @throws InvalidArgumentException
3688
+	 * @throws ReflectionException
3689
+	 * @throws InvalidDataTypeException
3690
+	 * @throws InvalidInterfaceException
3691
+	 */
3692
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3693
+	{
3694
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
3695
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3696
+
3697
+		// ensure is active
3698
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
3699
+
3700
+		// set response for load
3701
+		if (
3702
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
3703
+				$messenger_name,
3704
+				$message_type_name
3705
+			)
3706
+		) {
3707
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3708
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3709
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3710
+			}
3711
+		}
3712
+
3713
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
3714
+			$active_messenger,
3715
+			$message_type_to_activate
3716
+		);
3717
+	}
3718
+
3719
+
3720
+	/**
3721
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3722
+	 *
3723
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3724
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3725
+	 * @return bool
3726
+	 * @throws DomainException
3727
+	 * @throws EE_Error
3728
+	 * @throws InvalidArgumentException
3729
+	 * @throws ReflectionException
3730
+	 * @throws InvalidDataTypeException
3731
+	 * @throws InvalidInterfaceException
3732
+	 */
3733
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3734
+	{
3735
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3736
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3737
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3738
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3739
+
3740
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
3741
+			$active_messenger,
3742
+			$message_type_to_deactivate
3743
+		);
3744
+	}
3745
+
3746
+
3747
+	/**
3748
+	 * This just initializes the defaults for activating messenger and message type responses.
3749
+	 */
3750
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
3751
+	{
3752
+		$this->_template_args['data']['active_mts'] = [];
3753
+		$this->_template_args['data']['mt_reload']  = [];
3754
+	}
3755
+
3756
+
3757
+	/**
3758
+	 * Setup appropriate response for activating a messenger and/or message types
3759
+	 *
3760
+	 * @param EE_messenger         $messenger
3761
+	 * @param EE_message_type|null $message_type
3762
+	 * @return bool
3763
+	 * @throws DomainException
3764
+	 * @throws EE_Error
3765
+	 * @throws InvalidArgumentException
3766
+	 * @throws ReflectionException
3767
+	 * @throws InvalidDataTypeException
3768
+	 * @throws InvalidInterfaceException
3769
+	 */
3770
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
3771
+		$messenger,
3772
+		EE_Message_Type $message_type = null
3773
+	) {
3774
+		// if $messenger isn't a valid messenger object then get out.
3775
+		if (! $messenger instanceof EE_Messenger) {
3776
+			EE_Error::add_error(
3777
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
3778
+				__FILE__,
3779
+				__FUNCTION__,
3780
+				__LINE__
3781
+			);
3782
+			return false;
3783
+		}
3784
+		// activated
3785
+		if ($this->_template_args['data']['active_mts']) {
3786
+			EE_Error::overwrite_success();
3787
+			// activated a message type with the messenger
3788
+			if ($message_type instanceof EE_message_type) {
3789
+				EE_Error::add_success(
3790
+					sprintf(
3791
+						esc_html__(
3792
+							'%s message type has been successfully activated with the %s messenger',
3793
+							'event_espresso'
3794
+						),
3795
+						ucwords($message_type->label['singular']),
3796
+						ucwords($messenger->label['singular'])
3797
+					)
3798
+				);
3799
+
3800
+				// if message type was invoice then let's make sure we activate the invoice payment method.
3801
+				if ($message_type->name === 'invoice') {
3802
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
3803
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3804
+					if ($pm instanceof EE_Payment_Method) {
3805
+						EE_Error::add_attention(
3806
+							esc_html__(
3807
+								'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.',
3808
+								'event_espresso'
3809
+							)
3810
+						);
3811
+					}
3812
+				}
3813
+				// just toggles the entire messenger
3814
+			} else {
3815
+				EE_Error::add_success(
3816
+					sprintf(
3817
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
3818
+						ucwords($messenger->label['singular'])
3819
+					)
3820
+				);
3821
+			}
3822
+
3823
+			return true;
3824
+
3825
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3826
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3827
+			// in which case we just give a success message for the messenger being successfully activated.
3828
+		} else {
3829
+			if (! $messenger->get_default_message_types()) {
3830
+				// messenger doesn't have any default message types so still a success.
3831
+				EE_Error::add_success(
3832
+					sprintf(
3833
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
3834
+						ucwords($messenger->label['singular'])
3835
+					)
3836
+				);
3837
+
3838
+				return true;
3839
+			} else {
3840
+				EE_Error::add_error(
3841
+					$message_type instanceof EE_message_type
3842
+						? sprintf(
3843
+							esc_html__(
3844
+								'%s message type was not successfully activated with the %s messenger',
3845
+								'event_espresso'
3846
+							),
3847
+							ucwords($message_type->label['singular']),
3848
+							ucwords($messenger->label['singular'])
3849
+						)
3850
+						: sprintf(
3851
+							esc_html__('%s messenger was not successfully activated', 'event_espresso'),
3852
+							ucwords($messenger->label['singular'])
3853
+						),
3854
+					__FILE__,
3855
+					__FUNCTION__,
3856
+					__LINE__
3857
+				);
3858
+
3859
+				return false;
3860
+			}
3861
+		}
3862
+	}
3863
+
3864
+
3865
+	/**
3866
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
3867
+	 *
3868
+	 * @param EE_messenger         $messenger
3869
+	 * @param EE_message_type|null $message_type
3870
+	 * @return bool
3871
+	 * @throws DomainException
3872
+	 * @throws EE_Error
3873
+	 * @throws InvalidArgumentException
3874
+	 * @throws ReflectionException
3875
+	 * @throws InvalidDataTypeException
3876
+	 * @throws InvalidInterfaceException
3877
+	 */
3878
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3879
+		$messenger,
3880
+		EE_message_type $message_type = null
3881
+	) {
3882
+		EE_Error::overwrite_success();
3883
+
3884
+		// if $messenger isn't a valid messenger object then get out.
3885
+		if (! $messenger instanceof EE_Messenger) {
3886
+			EE_Error::add_error(
3887
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3888
+				__FILE__,
3889
+				__FUNCTION__,
3890
+				__LINE__
3891
+			);
3892
+
3893
+			return false;
3894
+		}
3895
+
3896
+		if ($message_type instanceof EE_message_type) {
3897
+			$message_type_name = $message_type->name;
3898
+			EE_Error::add_success(
3899
+				sprintf(
3900
+					esc_html__(
3901
+						'%s message type has been successfully deactivated for the %s messenger.',
3902
+						'event_espresso'
3903
+					),
3904
+					ucwords($message_type->label['singular']),
3905
+					ucwords($messenger->label['singular'])
3906
+				)
3907
+			);
3908
+		} else {
3909
+			$message_type_name = '';
3910
+			EE_Error::add_success(
3911
+				sprintf(
3912
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
3913
+					ucwords($messenger->label['singular'])
3914
+				)
3915
+			);
3916
+		}
3917
+
3918
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3919
+		if (
3920
+			$messenger->name === 'html'
3921
+			&& (
3922
+				is_null($message_type)
3923
+				|| $message_type_name === 'invoice'
3924
+			)
3925
+		) {
3926
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
3927
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3928
+			if ($count_updated > 0) {
3929
+				$msg = $message_type_name === 'invoice'
3930
+					? esc_html__(
3931
+						'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.',
3932
+						'event_espresso'
3933
+					)
3934
+					: esc_html__(
3935
+						'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.',
3936
+						'event_espresso'
3937
+					);
3938
+				EE_Error::add_attention($msg);
3939
+			}
3940
+		}
3941
+
3942
+		return true;
3943
+	}
3944
+
3945
+
3946
+	/**
3947
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3948
+	 *
3949
+	 * @throws DomainException
3950
+	 * @throws EE_Error
3951
+	 * @throws EE_Error
3952
+	 */
3953
+	public function update_mt_form()
3954
+	{
3955
+		if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
3956
+			wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
3957
+		}
3958
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
3959
+			EE_Error::add_error(
3960
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
3961
+				__FILE__,
3962
+				__FUNCTION__,
3963
+				__LINE__
3964
+			);
3965
+			$this->_return_json();
3966
+		}
3967
+
3968
+		$message_types = $this->get_installed_message_types();
3969
+		$message_type  = $message_types[ $this->_active_message_type_name ];
3970
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
3971
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
3972
+
3973
+		$this->_template_args['success'] = true;
3974
+		$this->_template_args['content'] = $content;
3975
+		$this->_return_json();
3976
+	}
3977
+
3978
+
3979
+	/**
3980
+	 * this handles saving the settings for a messenger or message type
3981
+	 *
3982
+	 * @throws EE_Error
3983
+	 * @throws EE_Error
3984
+	 */
3985
+	public function save_settings()
3986
+	{
3987
+		if (! $this->capabilities->current_user_can('ee_edit_messages', __FUNCTION__)) {
3988
+			wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
3989
+		}
3990
+		$type = $this->request->getRequestParam('type');
3991
+		if (! $type) {
3992
+			EE_Error::add_error(
3993
+				esc_html__(
3994
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
3995
+					'event_espresso'
3996
+				),
3997
+				__FILE__,
3998
+				__FUNCTION__,
3999
+				__LINE__
4000
+			);
4001
+			$this->_template_args['error'] = true;
4002
+			$this->_return_json();
4003
+		}
4004
+
4005
+
4006
+		if ($type === 'messenger') {
4007
+			// this should be an array.
4008
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4009
+			$messenger = $settings['messenger'];
4010
+			// remove messenger and message_types from settings array
4011
+			unset($settings['messenger'], $settings['message_types']);
4012
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4013
+		} elseif ($type === 'message_type') {
4014
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4015
+			$messenger    = $settings['messenger'];
4016
+			$message_type = $settings['message_type'];
4017
+			// remove messenger and message_types from settings array
4018
+			unset($settings['messenger'], $settings['message_types']);
4019
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4020
+		}
4021
+
4022
+		// okay we should have the data all setup.  Now we just update!
4023
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4024
+
4025
+		if ($success) {
4026
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4027
+		} else {
4028
+			EE_Error::add_error(
4029
+				esc_html__('Settings did not get updated', 'event_espresso'),
4030
+				__FILE__,
4031
+				__FUNCTION__,
4032
+				__LINE__
4033
+			);
4034
+		}
4035
+
4036
+		$this->_template_args['success'] = $success;
4037
+		$this->_return_json();
4038
+	}
4039
+
4040
+
4041
+
4042
+
4043
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4044
+
4045
+
4046
+	/**
4047
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4048
+	 * However, this does not send immediately, it just queues for sending.
4049
+	 *
4050
+	 * @throws EE_Error
4051
+	 * @throws InvalidDataTypeException
4052
+	 * @throws InvalidInterfaceException
4053
+	 * @throws InvalidArgumentException
4054
+	 * @throws ReflectionException
4055
+	 * @since 4.9.0
4056
+	 */
4057
+	protected function _generate_now()
4058
+	{
4059
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4060
+		$this->_redirect_after_action(false, '', '', [], true);
4061
+	}
4062
+
4063
+
4064
+	/**
4065
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4066
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4067
+	 *
4068
+	 * @throws EE_Error
4069
+	 * @throws InvalidDataTypeException
4070
+	 * @throws InvalidInterfaceException
4071
+	 * @throws InvalidArgumentException
4072
+	 * @throws ReflectionException
4073
+	 * @since 4.9.0
4074
+	 */
4075
+	protected function _generate_and_send_now()
4076
+	{
4077
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4078
+		$this->_redirect_after_action(false, '', '', [], true);
4079
+	}
4080
+
4081
+
4082
+	/**
4083
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4084
+	 *
4085
+	 * @throws EE_Error
4086
+	 * @throws InvalidDataTypeException
4087
+	 * @throws InvalidInterfaceException
4088
+	 * @throws InvalidArgumentException
4089
+	 * @throws ReflectionException
4090
+	 * @since 4.9.0
4091
+	 */
4092
+	protected function _queue_for_resending()
4093
+	{
4094
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4095
+		$this->_redirect_after_action(false, '', '', [], true);
4096
+	}
4097
+
4098
+
4099
+	/**
4100
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4101
+	 *
4102
+	 * @throws EE_Error
4103
+	 * @throws InvalidDataTypeException
4104
+	 * @throws InvalidInterfaceException
4105
+	 * @throws InvalidArgumentException
4106
+	 * @throws ReflectionException
4107
+	 * @since 4.9.0
4108
+	 */
4109
+	protected function _send_now()
4110
+	{
4111
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4112
+		$this->_redirect_after_action(false, '', '', [], true);
4113
+	}
4114
+
4115
+
4116
+	/**
4117
+	 * Deletes EE_messages for IDs in the request.
4118
+	 *
4119
+	 * @throws EE_Error
4120
+	 * @throws InvalidDataTypeException
4121
+	 * @throws InvalidInterfaceException
4122
+	 * @throws InvalidArgumentException
4123
+	 * @throws ReflectionException
4124
+	 * @since 4.9.0
4125
+	 */
4126
+	protected function _delete_ee_messages()
4127
+	{
4128
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4129
+		$deleted_count = 0;
4130
+		foreach ($MSG_IDs as $MSG_ID) {
4131
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4132
+				$deleted_count++;
4133
+			}
4134
+		}
4135
+		if ($deleted_count) {
4136
+			EE_Error::add_success(
4137
+				esc_html(
4138
+					_n(
4139
+						'Message successfully deleted',
4140
+						'Messages successfully deleted',
4141
+						$deleted_count,
4142
+						'event_espresso'
4143
+					)
4144
+				)
4145
+			);
4146
+		} else {
4147
+			EE_Error::add_error(
4148
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4149
+				__FILE__,
4150
+				__FUNCTION__,
4151
+				__LINE__
4152
+			);
4153
+		}
4154
+		$this->_redirect_after_action(false, '', '', [], true);
4155
+	}
4156
+
4157
+
4158
+	/**
4159
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4160
+	 *
4161
+	 * @return array
4162
+	 * @since 4.9.0
4163
+	 */
4164
+	protected function _get_msg_ids_from_request()
4165
+	{
4166
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4167
+		if (empty($MSG_IDs)) {
4168
+			return [];
4169
+		}
4170
+		// if 'MSG_ID' was just a single ID (not an array)
4171
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4172
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4173
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4174
+			? $MSG_IDs
4175
+			: array_keys($MSG_IDs);
4176
+	}
4177 4177
 }
Please login to merge, or discard this patch.
admin_pages/other_services/Other_Services_Admin_Page.core.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -15,94 +15,94 @@
 block discarded – undo
15 15
  */
16 16
 class Other_Services_Admin_Page extends EE_Admin_Page
17 17
 {
18
-    protected function _init_page_props()
19
-    {
20
-        $this->page_slug = EE_OTHER_SERVICES_PG_SLUG;
21
-        $this->page_label = esc_html__('Extensions & Services', 'event_espresso');
22
-        $this->_admin_base_url = EE_OTHER_SERVICES_ADMIN_URL;
23
-        $this->_admin_base_path = EE_OTHER_SERVICES_ADMIN;
24
-    }
25
-
26
-
27
-    protected function _ajax_hooks()
28
-    {
29
-        // todo: all hooks for ajax goes here.
30
-    }
31
-
32
-
33
-    protected function _define_page_props()
34
-    {
35
-        $this->_labels = array();
36
-        $this->_admin_page_title = $this->page_label;
37
-    }
38
-
39
-
40
-    protected function _set_page_routes()
41
-    {
42
-        $this->_page_routes = array(
43
-            'default' => array(
44
-                'func'       => [$this, '_other_services'],
45
-                'capability' => 'ee_read_ee',
46
-            ),
47
-        );
48
-    }
49
-
50
-
51
-    protected function _set_page_config()
52
-    {
53
-        $this->_page_config = array(
54
-            'default' => array(
55
-                'nav'           => array(
56
-                    'label' => esc_html__('Other Available Services', 'event_espresso'),
57
-                    'order' => 10,
58
-                ),
59
-                'require_nonce' => false,
60
-            ),
61
-        );
62
-    }
63
-
64
-
65
-    // none of the below group are currently used for Support pages
66
-    protected function _add_screen_options()
67
-    {
68
-    }
69
-
70
-    protected function _add_feature_pointers()
71
-    {
72
-    }
73
-
74
-    public function admin_init()
75
-    {
76
-    }
77
-
78
-    public function admin_notices()
79
-    {
80
-    }
81
-
82
-    public function admin_footer_scripts()
83
-    {
84
-    }
85
-
86
-
87
-    public function load_scripts_styles()
88
-    {
89
-        wp_register_style(
90
-            'ee-other-services-css',
91
-            EE_OTHER_SERVICES_ASSETS_URL . 'other-services.css',
92
-            array('ee-admin-css'),
93
-            EVENT_ESPRESSO_VERSION
94
-        );
95
-        wp_enqueue_style('ee-other-services-css');
96
-    }
97
-
98
-
99
-    protected function _other_services()
100
-    {
101
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
102
-            EE_OTHER_SERVICES_ADMIN_TEMPLATE_PATH . 'other_services_content.template.php',
103
-            array(),
104
-            true
105
-        );
106
-        $this->display_admin_page_with_no_sidebar();
107
-    }
18
+	protected function _init_page_props()
19
+	{
20
+		$this->page_slug = EE_OTHER_SERVICES_PG_SLUG;
21
+		$this->page_label = esc_html__('Extensions & Services', 'event_espresso');
22
+		$this->_admin_base_url = EE_OTHER_SERVICES_ADMIN_URL;
23
+		$this->_admin_base_path = EE_OTHER_SERVICES_ADMIN;
24
+	}
25
+
26
+
27
+	protected function _ajax_hooks()
28
+	{
29
+		// todo: all hooks for ajax goes here.
30
+	}
31
+
32
+
33
+	protected function _define_page_props()
34
+	{
35
+		$this->_labels = array();
36
+		$this->_admin_page_title = $this->page_label;
37
+	}
38
+
39
+
40
+	protected function _set_page_routes()
41
+	{
42
+		$this->_page_routes = array(
43
+			'default' => array(
44
+				'func'       => [$this, '_other_services'],
45
+				'capability' => 'ee_read_ee',
46
+			),
47
+		);
48
+	}
49
+
50
+
51
+	protected function _set_page_config()
52
+	{
53
+		$this->_page_config = array(
54
+			'default' => array(
55
+				'nav'           => array(
56
+					'label' => esc_html__('Other Available Services', 'event_espresso'),
57
+					'order' => 10,
58
+				),
59
+				'require_nonce' => false,
60
+			),
61
+		);
62
+	}
63
+
64
+
65
+	// none of the below group are currently used for Support pages
66
+	protected function _add_screen_options()
67
+	{
68
+	}
69
+
70
+	protected function _add_feature_pointers()
71
+	{
72
+	}
73
+
74
+	public function admin_init()
75
+	{
76
+	}
77
+
78
+	public function admin_notices()
79
+	{
80
+	}
81
+
82
+	public function admin_footer_scripts()
83
+	{
84
+	}
85
+
86
+
87
+	public function load_scripts_styles()
88
+	{
89
+		wp_register_style(
90
+			'ee-other-services-css',
91
+			EE_OTHER_SERVICES_ASSETS_URL . 'other-services.css',
92
+			array('ee-admin-css'),
93
+			EVENT_ESPRESSO_VERSION
94
+		);
95
+		wp_enqueue_style('ee-other-services-css');
96
+	}
97
+
98
+
99
+	protected function _other_services()
100
+	{
101
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
102
+			EE_OTHER_SERVICES_ADMIN_TEMPLATE_PATH . 'other_services_content.template.php',
103
+			array(),
104
+			true
105
+		);
106
+		$this->display_admin_page_with_no_sidebar();
107
+	}
108 108
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/about/Extend_About_Admin_Page.core.php 1 patch
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -18,197 +18,197 @@
 block discarded – undo
18 18
  */
19 19
 class Extend_About_Admin_Page extends About_Admin_Page
20 20
 {
21
-    public function __construct($routing = true)
22
-    {
23
-        parent::__construct($routing);
24
-        define('EE_ABOUT_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'about/templates/');
25
-    }
26
-
27
-
28
-    protected function _set_page_routes()
29
-    {
30
-        $this->_page_routes = [
31
-            'default'  => [
32
-                'func'       => [$this, '_whats_new'],
33
-                'capability' => 'manage_options',
34
-            ],
35
-            'overview' => [
36
-                'func'       => [$this, '_overview'],
37
-                'capability' => 'manage_options',
38
-            ],
39
-            'credits'  => [
40
-                'func'       => [$this, '_credits'],
41
-                'capability' => 'manage_options',
42
-            ],
43
-            /*'decafvpro' => array(
21
+	public function __construct($routing = true)
22
+	{
23
+		parent::__construct($routing);
24
+		define('EE_ABOUT_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'about/templates/');
25
+	}
26
+
27
+
28
+	protected function _set_page_routes()
29
+	{
30
+		$this->_page_routes = [
31
+			'default'  => [
32
+				'func'       => [$this, '_whats_new'],
33
+				'capability' => 'manage_options',
34
+			],
35
+			'overview' => [
36
+				'func'       => [$this, '_overview'],
37
+				'capability' => 'manage_options',
38
+			],
39
+			'credits'  => [
40
+				'func'       => [$this, '_credits'],
41
+				'capability' => 'manage_options',
42
+			],
43
+			/*'decafvpro' => array(
44 44
                 'func'       => [$this, '_decafvpro'],
45 45
                 'capability' => 'manage_options'
46 46
                 ),*/
47
-            'reviews'  => [
48
-                'func'       => [$this, '_reviews'],
49
-                'capability' => 'manage_options',
50
-            ],
51
-
52
-
53
-        ];
54
-    }
55
-
56
-
57
-    protected function _set_page_config()
58
-    {
59
-        parent::_set_page_config();
60
-
61
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'about';
62
-        $this->_page_config     = [
63
-            'default'  => [
64
-                'nav'           => [
65
-                    'label' => esc_html__('What\'s New', 'event_espresso'),
66
-                    'icon'  => 'dashicons-bell',
67
-                    'order' => 10,
68
-                ],
69
-                'require_nonce' => false,
70
-            ],
71
-            'overview' => [
72
-                'nav'           => [
73
-                    'label' => esc_html__('About', 'event_espresso'),
74
-                    'icon'  => 'dashicons-info',
75
-                    'order' => 20,
76
-                ],
77
-                'require_nonce' => false,
78
-            ],
79
-            'credits'  => [
80
-                'nav'           => [
81
-                    'label' => esc_html__('Credits', 'event_espresso'),
82
-                    'icon'  => 'dashicons-thumbs-up',
83
-                    'order' => 30,
84
-                ],
85
-                'require_nonce' => false,
86
-            ],
87
-            /*'decafvpro' => array(
47
+			'reviews'  => [
48
+				'func'       => [$this, '_reviews'],
49
+				'capability' => 'manage_options',
50
+			],
51
+
52
+
53
+		];
54
+	}
55
+
56
+
57
+	protected function _set_page_config()
58
+	{
59
+		parent::_set_page_config();
60
+
61
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'about';
62
+		$this->_page_config     = [
63
+			'default'  => [
64
+				'nav'           => [
65
+					'label' => esc_html__('What\'s New', 'event_espresso'),
66
+					'icon'  => 'dashicons-bell',
67
+					'order' => 10,
68
+				],
69
+				'require_nonce' => false,
70
+			],
71
+			'overview' => [
72
+				'nav'           => [
73
+					'label' => esc_html__('About', 'event_espresso'),
74
+					'icon'  => 'dashicons-info',
75
+					'order' => 20,
76
+				],
77
+				'require_nonce' => false,
78
+			],
79
+			'credits'  => [
80
+				'nav'           => [
81
+					'label' => esc_html__('Credits', 'event_espresso'),
82
+					'icon'  => 'dashicons-thumbs-up',
83
+					'order' => 30,
84
+				],
85
+				'require_nonce' => false,
86
+			],
87
+			/*'decafvpro' => array(
88 88
                 'nav' => array(
89 89
                     'label' => esc_html__('Decaf vs Regular', 'event_espresso'),
90 90
                     'order' => 40),
91 91
                 'require_nonce' => FALSE
92 92
                 ),*/
93
-            'reviews'  => [
94
-                'nav'           => [
95
-                    'label' => esc_html__('Reviews', 'event_espresso'),
96
-                    'icon'  => 'dashicons-star-filled',
97
-                    'order' => 50,
98
-                ],
99
-                'require_nonce' => false,
100
-            ],
101
-
102
-        ];
103
-    }
104
-
105
-
106
-    protected function _whats_new()
107
-    {
108
-        $steps = MaintenanceStatus::isNotDisabled() ? $this->_get_started_steps() : '';
109
-        $this->_admin_page_title                          = sprintf(
110
-            esc_html__('Welcome to Event Espresso %s', 'event_espresso'),
111
-            EVENT_ESPRESSO_VERSION
112
-        );
113
-        $settings_message                                 = $steps;
114
-        $this->_template_args['admin_page_subtitle']      = esc_html__(
115
-            'Thank you for choosing Event Espresso, the most powerful Event Management plugin for WordPress.',
116
-            'event_espresso'
117
-        ) . $settings_message;
118
-        $template                                         =
119
-            is_readable(EE_ABOUT_CAF_TEMPLATE_PATH . 'whats_new.template.php')
120
-                ? EE_ABOUT_CAF_TEMPLATE_PATH . 'whats_new.template.php'
121
-                : EE_ABOUT_TEMPLATE_PATH
122
-                  . 'whats_new.template.php';
123
-        $this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
124
-            $template,
125
-            $this->_template_args,
126
-            true
127
-        );
128
-        $this->display_about_admin_page();
129
-    }
130
-
131
-
132
-    protected function _overview()
133
-    {
134
-        $this->_admin_page_title                          = esc_html__('About Event Espresso', 'event_espresso');
135
-        $this->_template_args['admin_page_subtitle']      = esc_html__(
136
-            'Thank you for choosing Event Espresso, the most powerful Event Management plugin for WordPress.',
137
-            'event_espresso'
138
-        );
139
-        $template                                         =
140
-            is_readable(EE_ABOUT_CAF_TEMPLATE_PATH . 'ee4-overview.template.php')
141
-                ? EE_ABOUT_CAF_TEMPLATE_PATH . 'ee4-overview.template.php'
142
-                : EE_ABOUT_TEMPLATE_PATH . 'ee4-overview.template.php';
143
-        $this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
144
-            $template,
145
-            $this->_template_args,
146
-            true
147
-        );
148
-        $this->display_about_admin_page();
149
-    }
150
-
151
-
152
-    protected function _credits()
153
-    {
154
-        // $this->_template_args['admin_page_title'] = sprintf(
155
-        //     esc_html__('Welcome to Event Espresso %s', 'event_espresso'),
156
-        //     EVENT_ESPRESSO_VERSION
157
-        // );
158
-        $this->_template_args['admin_page_subtitle']      = esc_html__(
159
-            'Thank you for choosing Event Espresso, the most powerful Event Management plugin for WordPress.',
160
-            'event_espresso'
161
-        );
162
-        $template                                         = EE_ABOUT_TEMPLATE_PATH . 'credits.template.php';
163
-        $this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
164
-            $template,
165
-            $this->_template_args,
166
-            true
167
-        );
168
-        $this->display_about_admin_page();
169
-    }
170
-
171
-
172
-    protected function _decafvpro()
173
-    {
174
-        $this->_template_args['admin_page_title']         = sprintf(
175
-            esc_html__('Welcome to Event Espresso %s', 'event_espresso'),
176
-            EVENT_ESPRESSO_VERSION
177
-        );
178
-        $this->_template_args['admin_page_subtitle']      = sprintf(
179
-            esc_html__(
180
-                'Event Espresso lets you focus on doing %swhat you love%s — %sorganizing your events%s',
181
-                'event_espresso'
182
-            ),
183
-            '<em>',
184
-            '</em>',
185
-            '<strong>',
186
-            '</strong>'
187
-        );
188
-        $template                                         = EE_ABOUT_TEMPLATE_PATH . 'decafvpro.template.php';
189
-        $this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
190
-            $template,
191
-            $this->_template_args,
192
-            true
193
-        );
194
-        $this->display_about_admin_page();
195
-    }
196
-
197
-
198
-    protected function _reviews()
199
-    {
200
-        $this->_template_args['admin_page_title']         =
201
-            esc_html__('Rave Reviews About Event Espresso 4', 'event_espresso');
202
-        $this->_template_args['admin_page_subtitle']      = esc_html__(
203
-            'At Event Espresso, customer satisfaction is our ultimate goal.',
204
-            'event_espresso'
205
-        );
206
-        $template                                         = EE_ABOUT_TEMPLATE_PATH . 'reviews.template.php';
207
-        $this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
208
-            $template,
209
-            $this->_template_args,
210
-            true
211
-        );
212
-        $this->display_about_admin_page();
213
-    }
93
+			'reviews'  => [
94
+				'nav'           => [
95
+					'label' => esc_html__('Reviews', 'event_espresso'),
96
+					'icon'  => 'dashicons-star-filled',
97
+					'order' => 50,
98
+				],
99
+				'require_nonce' => false,
100
+			],
101
+
102
+		];
103
+	}
104
+
105
+
106
+	protected function _whats_new()
107
+	{
108
+		$steps = MaintenanceStatus::isNotDisabled() ? $this->_get_started_steps() : '';
109
+		$this->_admin_page_title                          = sprintf(
110
+			esc_html__('Welcome to Event Espresso %s', 'event_espresso'),
111
+			EVENT_ESPRESSO_VERSION
112
+		);
113
+		$settings_message                                 = $steps;
114
+		$this->_template_args['admin_page_subtitle']      = esc_html__(
115
+			'Thank you for choosing Event Espresso, the most powerful Event Management plugin for WordPress.',
116
+			'event_espresso'
117
+		) . $settings_message;
118
+		$template                                         =
119
+			is_readable(EE_ABOUT_CAF_TEMPLATE_PATH . 'whats_new.template.php')
120
+				? EE_ABOUT_CAF_TEMPLATE_PATH . 'whats_new.template.php'
121
+				: EE_ABOUT_TEMPLATE_PATH
122
+				  . 'whats_new.template.php';
123
+		$this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
124
+			$template,
125
+			$this->_template_args,
126
+			true
127
+		);
128
+		$this->display_about_admin_page();
129
+	}
130
+
131
+
132
+	protected function _overview()
133
+	{
134
+		$this->_admin_page_title                          = esc_html__('About Event Espresso', 'event_espresso');
135
+		$this->_template_args['admin_page_subtitle']      = esc_html__(
136
+			'Thank you for choosing Event Espresso, the most powerful Event Management plugin for WordPress.',
137
+			'event_espresso'
138
+		);
139
+		$template                                         =
140
+			is_readable(EE_ABOUT_CAF_TEMPLATE_PATH . 'ee4-overview.template.php')
141
+				? EE_ABOUT_CAF_TEMPLATE_PATH . 'ee4-overview.template.php'
142
+				: EE_ABOUT_TEMPLATE_PATH . 'ee4-overview.template.php';
143
+		$this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
144
+			$template,
145
+			$this->_template_args,
146
+			true
147
+		);
148
+		$this->display_about_admin_page();
149
+	}
150
+
151
+
152
+	protected function _credits()
153
+	{
154
+		// $this->_template_args['admin_page_title'] = sprintf(
155
+		//     esc_html__('Welcome to Event Espresso %s', 'event_espresso'),
156
+		//     EVENT_ESPRESSO_VERSION
157
+		// );
158
+		$this->_template_args['admin_page_subtitle']      = esc_html__(
159
+			'Thank you for choosing Event Espresso, the most powerful Event Management plugin for WordPress.',
160
+			'event_espresso'
161
+		);
162
+		$template                                         = EE_ABOUT_TEMPLATE_PATH . 'credits.template.php';
163
+		$this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
164
+			$template,
165
+			$this->_template_args,
166
+			true
167
+		);
168
+		$this->display_about_admin_page();
169
+	}
170
+
171
+
172
+	protected function _decafvpro()
173
+	{
174
+		$this->_template_args['admin_page_title']         = sprintf(
175
+			esc_html__('Welcome to Event Espresso %s', 'event_espresso'),
176
+			EVENT_ESPRESSO_VERSION
177
+		);
178
+		$this->_template_args['admin_page_subtitle']      = sprintf(
179
+			esc_html__(
180
+				'Event Espresso lets you focus on doing %swhat you love%s — %sorganizing your events%s',
181
+				'event_espresso'
182
+			),
183
+			'<em>',
184
+			'</em>',
185
+			'<strong>',
186
+			'</strong>'
187
+		);
188
+		$template                                         = EE_ABOUT_TEMPLATE_PATH . 'decafvpro.template.php';
189
+		$this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
190
+			$template,
191
+			$this->_template_args,
192
+			true
193
+		);
194
+		$this->display_about_admin_page();
195
+	}
196
+
197
+
198
+	protected function _reviews()
199
+	{
200
+		$this->_template_args['admin_page_title']         =
201
+			esc_html__('Rave Reviews About Event Espresso 4', 'event_espresso');
202
+		$this->_template_args['admin_page_subtitle']      = esc_html__(
203
+			'At Event Espresso, customer satisfaction is our ultimate goal.',
204
+			'event_espresso'
205
+		);
206
+		$template                                         = EE_ABOUT_TEMPLATE_PATH . 'reviews.template.php';
207
+		$this->_template_args['about_admin_page_content'] = EEH_Template::display_template(
208
+			$template,
209
+			$this->_template_args,
210
+			true
211
+		);
212
+		$this->display_about_admin_page();
213
+	}
214 214
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 1 patch
Indentation   +1297 added lines, -1297 removed lines patch added patch discarded remove patch
@@ -19,1307 +19,1307 @@
 block discarded – undo
19 19
  */
20 20
 class Extend_Events_Admin_Page extends Events_Admin_Page
21 21
 {
22
-    /**
23
-     * Extend_Events_Admin_Page constructor.
24
-     *
25
-     * @param bool $routing
26
-     * @throws ReflectionException
27
-     */
28
-    public function __construct($routing = true)
29
-    {
30
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
31
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
32
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
33
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
34
-        }
35
-        parent::__construct($routing);
36
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
37
-    }
38
-
39
-
40
-    protected function _set_page_config()
41
-    {
42
-        parent::_set_page_config();
43
-
44
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
45
-        // is there an evt_id in the request?
46
-        $EVT_ID                                          = $this->request->getRequestParam('EVT_ID', 0, 'int');
47
-        $EVT_ID                                          = $this->request->getRequestParam('post', $EVT_ID, 'int');
48
-        $TKT_ID                                          = $this->request->getRequestParam('TKT_ID', 0, 'int');
49
-        $new_page_routes                                 = [
50
-            'duplicate_event'          => [
51
-                'func'       => [$this, '_duplicate_event'],
52
-                'capability' => 'ee_edit_event',
53
-                'obj_id'     => $EVT_ID,
54
-                'noheader'   => true,
55
-            ],
56
-            'import_page'              => [
57
-                'func'       => [$this, '_import_page'],
58
-                'capability' => 'import',
59
-            ],
60
-            'import'                   => [
61
-                'func'       => [$this, '_import_events'],
62
-                'capability' => 'import',
63
-                'noheader'   => true,
64
-            ],
65
-            'import_events'            => [
66
-                'func'       => [$this, '_import_events'],
67
-                'capability' => 'import',
68
-                'noheader'   => true,
69
-            ],
70
-            'export_events'            => [
71
-                'func'       => [$this, '_events_export'],
72
-                'capability' => 'export',
73
-                'noheader'   => true,
74
-            ],
75
-            'export_categories'        => [
76
-                'func'       => [$this, '_categories_export'],
77
-                'capability' => 'export',
78
-                'noheader'   => true,
79
-            ],
80
-            'sample_export_file'       => [
81
-                'func'       => [$this, '_sample_export_file'],
82
-                'capability' => 'export',
83
-                'noheader'   => true,
84
-            ],
85
-            'update_template_settings' => [
86
-                'func'       => [$this, '_update_template_settings'],
87
-                'capability' => 'manage_options',
88
-                'noheader'   => true,
89
-            ],
90
-            'ticket_list_table'        => [
91
-                'func'       => [$this, '_tickets_overview_list_table'],
92
-                'capability' => 'ee_read_default_tickets',
93
-            ],
94
-        ];
95
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
96
-        $this->_page_config['edit']['metaboxes'][]       = '_premium_event_editor_meta_boxes';
97
-        // don't load these meta boxes if using the advanced editor
98
-        if (
99
-            ! $this->admin_config->useAdvancedEditor()
100
-            || ! $this->feature->allowed('use_default_ticket_manager')
101
-        ) {
102
-            $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
103
-            $this->_page_config['edit']['qtips'][]       = 'EE_Event_Editor_Tips';
104
-
105
-            $legacy_editor_page_routes = [
106
-                'trash_ticket'    => [
107
-                    'func'       => [$this, '_trash_or_restore_ticket'],
108
-                    'capability' => 'ee_delete_default_ticket',
109
-                    'obj_id'     => $TKT_ID,
110
-                    'noheader'   => true,
111
-                    'args'       => ['trash' => true],
112
-                ],
113
-                'trash_tickets'   => [
114
-                    'func'       => [$this, '_trash_or_restore_ticket'],
115
-                    'capability' => 'ee_delete_default_tickets',
116
-                    'noheader'   => true,
117
-                    'args'       => ['trash' => true],
118
-                ],
119
-                'restore_ticket'  => [
120
-                    'func'       => [$this, '_trash_or_restore_ticket'],
121
-                    'capability' => 'ee_delete_default_ticket',
122
-                    'obj_id'     => $TKT_ID,
123
-                    'noheader'   => true,
124
-                ],
125
-                'restore_tickets' => [
126
-                    'func'       => [$this, '_trash_or_restore_ticket'],
127
-                    'capability' => 'ee_delete_default_tickets',
128
-                    'noheader'   => true,
129
-                ],
130
-                'delete_ticket'   => [
131
-                    'func'       => [$this, '_delete_ticket'],
132
-                    'capability' => 'ee_delete_default_ticket',
133
-                    'obj_id'     => $TKT_ID,
134
-                    'noheader'   => true,
135
-                ],
136
-                'delete_tickets'  => [
137
-                    'func'       => [$this, '_delete_ticket'],
138
-                    'capability' => 'ee_delete_default_tickets',
139
-                    'noheader'   => true,
140
-                ],
141
-            ];
142
-            $new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
143
-        }
144
-
145
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
146
-        // partial route/config override
147
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
148
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
149
-
150
-        // add default tickets tab and template settings nav tabs (note union at end)
151
-        $this->_page_config = [
152
-                                  'ticket_list_table' => [
153
-                                      'nav'           => [
154
-                                          'label' => esc_html__('Default Tickets', 'event_espresso'),
155
-                                          'icon'  => 'dashicons-tickets-alt',
156
-                                          'order' => 60,
157
-                                      ],
158
-                                      'list_table'    => 'Tickets_List_Table',
159
-                                      'require_nonce' => false,
160
-                                  ],
161
-                                  'template_settings' => [
162
-                                      'nav'           => [
163
-                                          'label' => esc_html__('Templates', 'event_espresso'),
164
-                                          'icon'  => 'dashicons-layout',
165
-                                          'order' => 30,
166
-                                      ],
167
-                                      'metaboxes'     => array_merge(
168
-                                          ['_publish_post_box'],
169
-                                          $this->_default_espresso_metaboxes
170
-                                      ),
171
-                                      'help_tabs'     => [
172
-                                          'general_settings_templates_help_tab' => [
173
-                                              'title'    => esc_html__('Templates', 'event_espresso'),
174
-                                              'filename' => 'general_settings_templates',
175
-                                          ],
176
-                                      ],
177
-                                      'require_nonce' => false,
178
-                                  ],
179
-                              ] + $this->_page_config;
180
-
181
-        // add filters and actions
182
-        // modifying _views
183
-        add_filter(
184
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
185
-            [$this, 'add_additional_datetime_button'],
186
-            10,
187
-            2
188
-        );
189
-        add_filter(
190
-            'FHEE_event_datetime_metabox_clone_button_template',
191
-            [$this, 'add_datetime_clone_button'],
192
-            10,
193
-            2
194
-        );
195
-        add_filter(
196
-            'FHEE_event_datetime_metabox_timezones_template',
197
-            [$this, 'datetime_timezones_template'],
198
-            10,
199
-            2
200
-        );
201
-        // filters for event list table
202
-        add_filter(
203
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
204
-            [$this, 'extra_list_table_actions'],
205
-            10,
206
-            2
207
-        );
208
-        // legend item
209
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
210
-        add_action('admin_init', [$this, 'admin_init']);
211
-        // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
212
-        // add_filter('get_sample_permalink_html', [DuplicateEventButton::class, 'addButton'], 8, 2);
213
-        DuplicateEventButton::addEventEditorPermalinkButton(8);
214
-    }
215
-
216
-
217
-    /**
218
-     * admin_init
219
-     */
220
-    public function admin_init()
221
-    {
222
-        EE_Registry::$i18n_js_strings['image_confirm']          = esc_html__(
223
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
224
-            'event_espresso'
225
-        );
226
-        EE_Registry::$i18n_js_strings['event_starts_on']        = esc_html__('Event Starts on', 'event_espresso');
227
-        EE_Registry::$i18n_js_strings['event_ends_on']          = esc_html__('Event Ends on', 'event_espresso');
228
-        EE_Registry::$i18n_js_strings['event_datetime_actions'] = esc_html__('Actions', 'event_espresso');
229
-        EE_Registry::$i18n_js_strings['event_clone_dt_msg']     = esc_html__(
230
-            'Clone this Event Date and Time',
231
-            'event_espresso'
232
-        );
233
-        EE_Registry::$i18n_js_strings['remove_event_dt_msg']    = esc_html__(
234
-            'Remove this Event Time',
235
-            'event_espresso'
236
-        );
237
-    }
238
-
239
-
240
-    /**
241
-     * Add per page screen options to the default ticket list table view.
242
-     *
243
-     * @throws InvalidArgumentException
244
-     * @throws InvalidDataTypeException
245
-     * @throws InvalidInterfaceException
246
-     */
247
-    protected function _add_screen_options_ticket_list_table()
248
-    {
249
-        $this->_per_page_screen_option();
250
-    }
251
-
252
-
253
-    /**
254
-     * @param string      $return    the current html
255
-     * @param int         $id        the post id for the page
256
-     * @param string|null $new_title What the title is
257
-     * @param string|null $new_slug  what the slug is
258
-     * @return string
259
-     * @deprecated 5.0.0.p
260
-     */
261
-    public function extra_permalink_field_buttons(
262
-        string $return,
263
-        int $id,
264
-        ?string $new_title,
265
-        ?string $new_slug
266
-    ): string {
267
-        $return = DuplicateEventButton::addButton($return, $id, $new_title, $new_slug);
268
-        return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug);
269
-    }
270
-
271
-
272
-    /**
273
-     * Set the list table views for the default ticket list table view.
274
-     */
275
-    public function _set_list_table_views_ticket_list_table()
276
-    {
277
-        $this->_views = [
278
-            'all'     => [
279
-                'slug'        => 'all',
280
-                'label'       => esc_html__('All', 'event_espresso'),
281
-                'count'       => 0,
282
-                'bulk_action' => [
283
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
284
-                ],
285
-            ],
286
-            'trashed' => [
287
-                'slug'        => 'trashed',
288
-                'label'       => esc_html__('Trash', 'event_espresso'),
289
-                'count'       => 0,
290
-                'bulk_action' => [
291
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
292
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
293
-                ],
294
-            ],
295
-        ];
296
-    }
297
-
298
-
299
-    /**
300
-     * Enqueue scripts and styles for the event editor.
301
-     */
302
-    public function load_scripts_styles_edit()
303
-    {
304
-        parent::load_scripts_styles_edit();
305
-        if (! $this->admin_config->useAdvancedEditor()) {
306
-            wp_register_script(
307
-                'ee-event-editor-heartbeat',
308
-                EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
309
-                ['ee_admin_js', 'heartbeat'],
310
-                EVENT_ESPRESSO_VERSION,
311
-                true
312
-            );
313
-            wp_enqueue_script('ee-accounting');
314
-            wp_enqueue_script('ee-event-editor-heartbeat');
315
-        }
316
-        wp_enqueue_script('event_editor_js');
317
-        wp_register_style(
318
-            'event-editor-css',
319
-            EVENTS_ASSETS_URL . 'event-editor.css',
320
-            ['ee-admin-css'],
321
-            EVENT_ESPRESSO_VERSION
322
-        );
323
-        wp_enqueue_style('event-editor-css');
324
-        // styles
325
-        wp_enqueue_style('espresso-ui-theme');
326
-    }
327
-
328
-
329
-    /**
330
-     * Sets the views for the default list table view.
331
-     *
332
-     * @throws EE_Error
333
-     * @throws ReflectionException
334
-     */
335
-    protected function _set_list_table_views_default()
336
-    {
337
-        parent::_set_list_table_views_default();
338
-        $new_views    = [
339
-            'today' => [
340
-                'slug'        => 'today',
341
-                'label'       => esc_html__('Today', 'event_espresso'),
342
-                'count'       => $this->total_events_today(),
343
-                'bulk_action' => [
344
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
345
-                ],
346
-            ],
347
-            'month' => [
348
-                'slug'        => 'month',
349
-                'label'       => esc_html__('This Month', 'event_espresso'),
350
-                'count'       => $this->total_events_this_month(),
351
-                'bulk_action' => [
352
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
353
-                ],
354
-            ],
355
-        ];
356
-        $this->_views = array_merge($this->_views, $new_views);
357
-    }
358
-
359
-
360
-    /**
361
-     * Returns the extra action links for the default list table view.
362
-     *
363
-     * @param array    $action_links
364
-     * @param EE_Event $event
365
-     * @return array
366
-     * @throws EE_Error
367
-     * @throws ReflectionException
368
-     */
369
-    public function extra_list_table_actions(array $action_links, EE_Event $event): array
370
-    {
371
-        if (
372
-            EE_Registry::instance()->CAP->current_user_can(
373
-                'ee_read_registrations',
374
-                'espresso_registrations_reports',
375
-                $event->ID()
376
-            )
377
-        ) {
378
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce(
379
-                [
380
-                    'action' => 'reports',
381
-                    'EVT_ID' => $event->ID(),
382
-                ],
383
-                REG_ADMIN_URL
384
-            );
385
-
386
-            $action_links[] = '
22
+	/**
23
+	 * Extend_Events_Admin_Page constructor.
24
+	 *
25
+	 * @param bool $routing
26
+	 * @throws ReflectionException
27
+	 */
28
+	public function __construct($routing = true)
29
+	{
30
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
31
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
32
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
33
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
34
+		}
35
+		parent::__construct($routing);
36
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
37
+	}
38
+
39
+
40
+	protected function _set_page_config()
41
+	{
42
+		parent::_set_page_config();
43
+
44
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
45
+		// is there an evt_id in the request?
46
+		$EVT_ID                                          = $this->request->getRequestParam('EVT_ID', 0, 'int');
47
+		$EVT_ID                                          = $this->request->getRequestParam('post', $EVT_ID, 'int');
48
+		$TKT_ID                                          = $this->request->getRequestParam('TKT_ID', 0, 'int');
49
+		$new_page_routes                                 = [
50
+			'duplicate_event'          => [
51
+				'func'       => [$this, '_duplicate_event'],
52
+				'capability' => 'ee_edit_event',
53
+				'obj_id'     => $EVT_ID,
54
+				'noheader'   => true,
55
+			],
56
+			'import_page'              => [
57
+				'func'       => [$this, '_import_page'],
58
+				'capability' => 'import',
59
+			],
60
+			'import'                   => [
61
+				'func'       => [$this, '_import_events'],
62
+				'capability' => 'import',
63
+				'noheader'   => true,
64
+			],
65
+			'import_events'            => [
66
+				'func'       => [$this, '_import_events'],
67
+				'capability' => 'import',
68
+				'noheader'   => true,
69
+			],
70
+			'export_events'            => [
71
+				'func'       => [$this, '_events_export'],
72
+				'capability' => 'export',
73
+				'noheader'   => true,
74
+			],
75
+			'export_categories'        => [
76
+				'func'       => [$this, '_categories_export'],
77
+				'capability' => 'export',
78
+				'noheader'   => true,
79
+			],
80
+			'sample_export_file'       => [
81
+				'func'       => [$this, '_sample_export_file'],
82
+				'capability' => 'export',
83
+				'noheader'   => true,
84
+			],
85
+			'update_template_settings' => [
86
+				'func'       => [$this, '_update_template_settings'],
87
+				'capability' => 'manage_options',
88
+				'noheader'   => true,
89
+			],
90
+			'ticket_list_table'        => [
91
+				'func'       => [$this, '_tickets_overview_list_table'],
92
+				'capability' => 'ee_read_default_tickets',
93
+			],
94
+		];
95
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
96
+		$this->_page_config['edit']['metaboxes'][]       = '_premium_event_editor_meta_boxes';
97
+		// don't load these meta boxes if using the advanced editor
98
+		if (
99
+			! $this->admin_config->useAdvancedEditor()
100
+			|| ! $this->feature->allowed('use_default_ticket_manager')
101
+		) {
102
+			$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
103
+			$this->_page_config['edit']['qtips'][]       = 'EE_Event_Editor_Tips';
104
+
105
+			$legacy_editor_page_routes = [
106
+				'trash_ticket'    => [
107
+					'func'       => [$this, '_trash_or_restore_ticket'],
108
+					'capability' => 'ee_delete_default_ticket',
109
+					'obj_id'     => $TKT_ID,
110
+					'noheader'   => true,
111
+					'args'       => ['trash' => true],
112
+				],
113
+				'trash_tickets'   => [
114
+					'func'       => [$this, '_trash_or_restore_ticket'],
115
+					'capability' => 'ee_delete_default_tickets',
116
+					'noheader'   => true,
117
+					'args'       => ['trash' => true],
118
+				],
119
+				'restore_ticket'  => [
120
+					'func'       => [$this, '_trash_or_restore_ticket'],
121
+					'capability' => 'ee_delete_default_ticket',
122
+					'obj_id'     => $TKT_ID,
123
+					'noheader'   => true,
124
+				],
125
+				'restore_tickets' => [
126
+					'func'       => [$this, '_trash_or_restore_ticket'],
127
+					'capability' => 'ee_delete_default_tickets',
128
+					'noheader'   => true,
129
+				],
130
+				'delete_ticket'   => [
131
+					'func'       => [$this, '_delete_ticket'],
132
+					'capability' => 'ee_delete_default_ticket',
133
+					'obj_id'     => $TKT_ID,
134
+					'noheader'   => true,
135
+				],
136
+				'delete_tickets'  => [
137
+					'func'       => [$this, '_delete_ticket'],
138
+					'capability' => 'ee_delete_default_tickets',
139
+					'noheader'   => true,
140
+				],
141
+			];
142
+			$new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
143
+		}
144
+
145
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
146
+		// partial route/config override
147
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
148
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
149
+
150
+		// add default tickets tab and template settings nav tabs (note union at end)
151
+		$this->_page_config = [
152
+								  'ticket_list_table' => [
153
+									  'nav'           => [
154
+										  'label' => esc_html__('Default Tickets', 'event_espresso'),
155
+										  'icon'  => 'dashicons-tickets-alt',
156
+										  'order' => 60,
157
+									  ],
158
+									  'list_table'    => 'Tickets_List_Table',
159
+									  'require_nonce' => false,
160
+								  ],
161
+								  'template_settings' => [
162
+									  'nav'           => [
163
+										  'label' => esc_html__('Templates', 'event_espresso'),
164
+										  'icon'  => 'dashicons-layout',
165
+										  'order' => 30,
166
+									  ],
167
+									  'metaboxes'     => array_merge(
168
+										  ['_publish_post_box'],
169
+										  $this->_default_espresso_metaboxes
170
+									  ),
171
+									  'help_tabs'     => [
172
+										  'general_settings_templates_help_tab' => [
173
+											  'title'    => esc_html__('Templates', 'event_espresso'),
174
+											  'filename' => 'general_settings_templates',
175
+										  ],
176
+									  ],
177
+									  'require_nonce' => false,
178
+								  ],
179
+							  ] + $this->_page_config;
180
+
181
+		// add filters and actions
182
+		// modifying _views
183
+		add_filter(
184
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
185
+			[$this, 'add_additional_datetime_button'],
186
+			10,
187
+			2
188
+		);
189
+		add_filter(
190
+			'FHEE_event_datetime_metabox_clone_button_template',
191
+			[$this, 'add_datetime_clone_button'],
192
+			10,
193
+			2
194
+		);
195
+		add_filter(
196
+			'FHEE_event_datetime_metabox_timezones_template',
197
+			[$this, 'datetime_timezones_template'],
198
+			10,
199
+			2
200
+		);
201
+		// filters for event list table
202
+		add_filter(
203
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
204
+			[$this, 'extra_list_table_actions'],
205
+			10,
206
+			2
207
+		);
208
+		// legend item
209
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
210
+		add_action('admin_init', [$this, 'admin_init']);
211
+		// this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
212
+		// add_filter('get_sample_permalink_html', [DuplicateEventButton::class, 'addButton'], 8, 2);
213
+		DuplicateEventButton::addEventEditorPermalinkButton(8);
214
+	}
215
+
216
+
217
+	/**
218
+	 * admin_init
219
+	 */
220
+	public function admin_init()
221
+	{
222
+		EE_Registry::$i18n_js_strings['image_confirm']          = esc_html__(
223
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
224
+			'event_espresso'
225
+		);
226
+		EE_Registry::$i18n_js_strings['event_starts_on']        = esc_html__('Event Starts on', 'event_espresso');
227
+		EE_Registry::$i18n_js_strings['event_ends_on']          = esc_html__('Event Ends on', 'event_espresso');
228
+		EE_Registry::$i18n_js_strings['event_datetime_actions'] = esc_html__('Actions', 'event_espresso');
229
+		EE_Registry::$i18n_js_strings['event_clone_dt_msg']     = esc_html__(
230
+			'Clone this Event Date and Time',
231
+			'event_espresso'
232
+		);
233
+		EE_Registry::$i18n_js_strings['remove_event_dt_msg']    = esc_html__(
234
+			'Remove this Event Time',
235
+			'event_espresso'
236
+		);
237
+	}
238
+
239
+
240
+	/**
241
+	 * Add per page screen options to the default ticket list table view.
242
+	 *
243
+	 * @throws InvalidArgumentException
244
+	 * @throws InvalidDataTypeException
245
+	 * @throws InvalidInterfaceException
246
+	 */
247
+	protected function _add_screen_options_ticket_list_table()
248
+	{
249
+		$this->_per_page_screen_option();
250
+	}
251
+
252
+
253
+	/**
254
+	 * @param string      $return    the current html
255
+	 * @param int         $id        the post id for the page
256
+	 * @param string|null $new_title What the title is
257
+	 * @param string|null $new_slug  what the slug is
258
+	 * @return string
259
+	 * @deprecated 5.0.0.p
260
+	 */
261
+	public function extra_permalink_field_buttons(
262
+		string $return,
263
+		int $id,
264
+		?string $new_title,
265
+		?string $new_slug
266
+	): string {
267
+		$return = DuplicateEventButton::addButton($return, $id, $new_title, $new_slug);
268
+		return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug);
269
+	}
270
+
271
+
272
+	/**
273
+	 * Set the list table views for the default ticket list table view.
274
+	 */
275
+	public function _set_list_table_views_ticket_list_table()
276
+	{
277
+		$this->_views = [
278
+			'all'     => [
279
+				'slug'        => 'all',
280
+				'label'       => esc_html__('All', 'event_espresso'),
281
+				'count'       => 0,
282
+				'bulk_action' => [
283
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
284
+				],
285
+			],
286
+			'trashed' => [
287
+				'slug'        => 'trashed',
288
+				'label'       => esc_html__('Trash', 'event_espresso'),
289
+				'count'       => 0,
290
+				'bulk_action' => [
291
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
292
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
293
+				],
294
+			],
295
+		];
296
+	}
297
+
298
+
299
+	/**
300
+	 * Enqueue scripts and styles for the event editor.
301
+	 */
302
+	public function load_scripts_styles_edit()
303
+	{
304
+		parent::load_scripts_styles_edit();
305
+		if (! $this->admin_config->useAdvancedEditor()) {
306
+			wp_register_script(
307
+				'ee-event-editor-heartbeat',
308
+				EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
309
+				['ee_admin_js', 'heartbeat'],
310
+				EVENT_ESPRESSO_VERSION,
311
+				true
312
+			);
313
+			wp_enqueue_script('ee-accounting');
314
+			wp_enqueue_script('ee-event-editor-heartbeat');
315
+		}
316
+		wp_enqueue_script('event_editor_js');
317
+		wp_register_style(
318
+			'event-editor-css',
319
+			EVENTS_ASSETS_URL . 'event-editor.css',
320
+			['ee-admin-css'],
321
+			EVENT_ESPRESSO_VERSION
322
+		);
323
+		wp_enqueue_style('event-editor-css');
324
+		// styles
325
+		wp_enqueue_style('espresso-ui-theme');
326
+	}
327
+
328
+
329
+	/**
330
+	 * Sets the views for the default list table view.
331
+	 *
332
+	 * @throws EE_Error
333
+	 * @throws ReflectionException
334
+	 */
335
+	protected function _set_list_table_views_default()
336
+	{
337
+		parent::_set_list_table_views_default();
338
+		$new_views    = [
339
+			'today' => [
340
+				'slug'        => 'today',
341
+				'label'       => esc_html__('Today', 'event_espresso'),
342
+				'count'       => $this->total_events_today(),
343
+				'bulk_action' => [
344
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
345
+				],
346
+			],
347
+			'month' => [
348
+				'slug'        => 'month',
349
+				'label'       => esc_html__('This Month', 'event_espresso'),
350
+				'count'       => $this->total_events_this_month(),
351
+				'bulk_action' => [
352
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
353
+				],
354
+			],
355
+		];
356
+		$this->_views = array_merge($this->_views, $new_views);
357
+	}
358
+
359
+
360
+	/**
361
+	 * Returns the extra action links for the default list table view.
362
+	 *
363
+	 * @param array    $action_links
364
+	 * @param EE_Event $event
365
+	 * @return array
366
+	 * @throws EE_Error
367
+	 * @throws ReflectionException
368
+	 */
369
+	public function extra_list_table_actions(array $action_links, EE_Event $event): array
370
+	{
371
+		if (
372
+			EE_Registry::instance()->CAP->current_user_can(
373
+				'ee_read_registrations',
374
+				'espresso_registrations_reports',
375
+				$event->ID()
376
+			)
377
+		) {
378
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce(
379
+				[
380
+					'action' => 'reports',
381
+					'EVT_ID' => $event->ID(),
382
+				],
383
+				REG_ADMIN_URL
384
+			);
385
+
386
+			$action_links[] = '
387 387
                 <a href="' . $reports_link . '"
388 388
                     aria-label="' . esc_attr__('View Report', 'event_espresso') . '"
389 389
                     class="ee-aria-tooltip button button--icon-only"
390 390
                 >
391 391
                     <span class="dashicons dashicons-chart-bar"></span>
392 392
                 </a>';
393
-        }
394
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
395
-            EE_Registry::instance()->load_helper('MSG_Template');
396
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
397
-                'see_notifications_for',
398
-                null,
399
-                ['EVT_ID' => $event->ID()]
400
-            );
401
-        }
402
-        return $action_links;
403
-    }
404
-
405
-
406
-    /**
407
-     * @param $items
408
-     * @return mixed
409
-     */
410
-    public function additional_legend_items($items)
411
-    {
412
-        if (
413
-            EE_Registry::instance()->CAP->current_user_can(
414
-                'ee_read_registrations',
415
-                'espresso_registrations_reports'
416
-            )
417
-        ) {
418
-            $items['reports'] = [
419
-                'class' => 'dashicons dashicons-chart-bar',
420
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
421
-            ];
422
-        }
423
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
424
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
425
-            // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
426
-            // (can only use numeric offsets when treating strings as arrays)
427
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
428
-                $items['view_related_messages'] = [
429
-                    'class' => $related_for_icon['css_class'],
430
-                    'desc'  => $related_for_icon['label'],
431
-                ];
432
-            }
433
-        }
434
-        return $items;
435
-    }
436
-
437
-
438
-    /**
439
-     * This is the callback method for the duplicate event route
440
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
441
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
442
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
443
-     * After duplication the redirect is to the new event edit page.
444
-     *
445
-     * @return void
446
-     * @throws EE_Error If EE_Event is not available with given ID
447
-     * @throws ReflectionException
448
-     * @access protected
449
-     */
450
-    protected function _duplicate_event()
451
-    {
452
-        // first make sure the ID for the event is in the request.
453
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
454
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
455
-        if (! $EVT_ID) {
456
-            EE_Error::add_error(
457
-                esc_html__(
458
-                    'In order to duplicate an event an Event ID is required.  None was given.',
459
-                    'event_espresso'
460
-                ),
461
-                __FILE__,
462
-                __FUNCTION__,
463
-                __LINE__
464
-            );
465
-            $this->_redirect_after_action(false, '', '', [], true);
466
-            return;
467
-        }
468
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
469
-        $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
470
-        if (! $orig_event instanceof EE_Event) {
471
-            throw new EE_Error(
472
-                sprintf(
473
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
474
-                    $EVT_ID
475
-                )
476
-            );
477
-        }
478
-        // k now let's clone the $orig_event before getting relations
479
-        $new_event = clone $orig_event;
480
-        // original datetimes
481
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
482
-        // other original relations
483
-        $orig_ven = $orig_event->get_many_related('Venue');
484
-        // reset the ID and modify other details to make it clear this is a dupe
485
-        $new_event->set('EVT_ID', 0);
486
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
487
-        $new_event->set('EVT_name', $new_name);
488
-        $new_event->set(
489
-            'EVT_slug',
490
-            wp_unique_post_slug(
491
-                sanitize_title($orig_event->name()),
492
-                0,
493
-                'publish',
494
-                EspressoPostType::EVENTS,
495
-                0
496
-            )
497
-        );
498
-        $new_event->set('status', 'draft');
499
-        // duplicate discussion settings
500
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
501
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
502
-        // save the new event
503
-        $new_event->save();
504
-        // venues
505
-        foreach ($orig_ven as $ven) {
506
-            $new_event->_add_relation_to($ven, 'Venue');
507
-        }
508
-        $new_event->save();
509
-        // now we need to get the question group relations and handle that
510
-        // first primary question groups
511
-        $orig_primary_qgs = $orig_event->get_many_related(
512
-            'Question_Group',
513
-            [['Event_Question_Group.EQG_primary' => true]]
514
-        );
515
-        if (! empty($orig_primary_qgs)) {
516
-            foreach ($orig_primary_qgs as $obj) {
517
-                if ($obj instanceof EE_Question_Group) {
518
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
519
-                }
520
-            }
521
-        }
522
-        // next additional attendee question groups
523
-        $orig_additional_qgs = $orig_event->get_many_related(
524
-            'Question_Group',
525
-            [['Event_Question_Group.EQG_additional' => true]]
526
-        );
527
-        if (! empty($orig_additional_qgs)) {
528
-            foreach ($orig_additional_qgs as $obj) {
529
-                if ($obj instanceof EE_Question_Group) {
530
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
531
-                }
532
-            }
533
-        }
534
-
535
-        $new_event->save();
536
-
537
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
538
-        $cloned_tickets = [];
539
-        foreach ($orig_datetimes as $orig_dtt) {
540
-            if (! $orig_dtt instanceof EE_Datetime) {
541
-                continue;
542
-            }
543
-            $new_dtt      = clone $orig_dtt;
544
-            $orig_tickets = $orig_dtt->tickets();
545
-            // save new dtt then add to event
546
-            $new_dtt->set('DTT_ID', 0);
547
-            $new_dtt->set('DTT_sold', 0);
548
-            $new_dtt->set_reserved(0);
549
-            $new_dtt->save();
550
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
551
-            $new_event->save();
552
-            // now let's get the ticket relations setup.
553
-            foreach ((array) $orig_tickets as $orig_ticket) {
554
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
555
-                if (! $orig_ticket instanceof EE_Ticket) {
556
-                    continue;
557
-                }
558
-                // is this ticket archived?  If it is then let's skip
559
-                if ($orig_ticket->get('TKT_deleted')) {
560
-                    continue;
561
-                }
562
-                // does this original ticket already exist in the clone_tickets cache?
563
-                //  If so we'll just use the new ticket from it.
564
-                if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
565
-                    $new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
566
-                } else {
567
-                    $new_ticket = clone $orig_ticket;
568
-                    // get relations on the $orig_ticket that we need to set up.
569
-                    $orig_prices = $orig_ticket->prices();
570
-                    $new_ticket->set('TKT_ID', 0);
571
-                    $new_ticket->set('TKT_sold', 0);
572
-                    $new_ticket->set('TKT_reserved', 0);
573
-                    // make sure new ticket has ID.
574
-                    $new_ticket->save();
575
-                    // price relations on new ticket need to be setup.
576
-                    foreach ($orig_prices as $orig_price) {
577
-                        // don't clone default prices, just add a relation
578
-                        if ($orig_price->is_default()) {
579
-                            $new_ticket->_add_relation_to($orig_price, 'Price');
580
-                            $new_ticket->save();
581
-                            continue;
582
-                        }
583
-                        $new_price = clone $orig_price;
584
-                        $new_price->set('PRC_ID', 0);
585
-                        $new_price->save();
586
-                        $new_ticket->_add_relation_to($new_price, 'Price');
587
-                    }
588
-                    $new_ticket->save();
589
-
590
-                    do_action(
591
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
592
-                        $orig_ticket,
593
-                        $new_ticket,
594
-                        $orig_prices,
595
-                        $orig_event,
596
-                        $orig_dtt,
597
-                        $new_dtt
598
-                    );
599
-                    $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
600
-                }
601
-                // k now we can add the new ticket as a relation to the new datetime
602
-                // and make sure it's added to our cached $cloned_tickets array
603
-                // for use with later datetimes that have the same ticket.
604
-                $new_dtt->_add_relation_to($new_ticket, 'Ticket');
605
-            }
606
-            $new_dtt->save();
607
-        }
608
-        // clone taxonomy information
609
-        $taxonomies_to_clone_with = apply_filters(
610
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
611
-            ['espresso_event_categories', 'espresso_event_type', 'post_tag']
612
-        );
613
-        // get terms for original event (notice)
614
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
615
-        // loop through terms and add them to new event.
616
-        foreach ($orig_terms as $term) {
617
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
618
-        }
619
-
620
-        // duplicate other core WP_Post items for this event.
621
-        // post thumbnail (feature image).
622
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
623
-        if ($feature_image_id) {
624
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
625
-        }
626
-
627
-        // duplicate page_template setting
628
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
629
-        if ($page_template) {
630
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
631
-        }
632
-
633
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
634
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
635
-        if ($new_event->ID()) {
636
-            $redirect_args = [
637
-                'post'   => $new_event->ID(),
638
-                'action' => 'edit',
639
-            ];
640
-            EE_Error::add_success(
641
-                esc_html__(
642
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
643
-                    'event_espresso'
644
-                )
645
-            );
646
-        } else {
647
-            $redirect_args = [
648
-                'action' => 'default',
649
-            ];
650
-            EE_Error::add_error(
651
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
652
-                __FILE__,
653
-                __FUNCTION__,
654
-                __LINE__
655
-            );
656
-        }
657
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
658
-    }
659
-
660
-
661
-    /**
662
-     * Generates output for the import page.
663
-     *
664
-     * @throws EE_Error
665
-     */
666
-    protected function _import_page()
667
-    {
668
-        $title = esc_html__('Import', 'event_espresso');
669
-        $intro = esc_html__(
670
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
671
-            'event_espresso'
672
-        );
673
-
674
-        $form_url = EVENTS_ADMIN_URL;
675
-        $action   = 'import_events';
676
-        $type     = 'csv';
677
-
678
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
679
-            $title,
680
-            $intro,
681
-            $form_url,
682
-            $action,
683
-            $type
684
-        );
685
-
686
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
687
-            ['action' => 'sample_export_file'],
688
-            $this->_admin_base_url
689
-        );
690
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
691
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
692
-            $this->_template_args,
693
-            true
694
-        );
695
-        $this->display_admin_page_with_sidebar();
696
-    }
697
-
698
-
699
-    /**
700
-     * _import_events
701
-     * This handles displaying the screen and running imports for importing events.
702
-     *
703
-     * @return void
704
-     * @throws EE_Error
705
-     */
706
-    protected function _import_events()
707
-    {
708
-        require_once(EE_CLASSES . 'EE_Import.class.php');
709
-        $success = EE_Import::instance()->import();
710
-        $this->_redirect_after_action(
711
-            $success,
712
-            esc_html__('Import File', 'event_espresso'),
713
-            'ran',
714
-            ['action' => 'import_page'],
715
-            true
716
-        );
717
-    }
718
-
719
-
720
-    /**
721
-     * _events_export
722
-     * Will export all (or just the given event) to a Excel compatible file.
723
-     *
724
-     * @access protected
725
-     * @return void
726
-     */
727
-    protected function _events_export()
728
-    {
729
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
730
-        $EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
731
-        $this->request->mergeRequestParams(
732
-            [
733
-                'export' => 'report',
734
-                'action' => 'all_event_data',
735
-                'EVT_ID' => $EVT_ID,
736
-            ]
737
-        );
738
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
739
-            require_once(EE_CLASSES . 'EE_Export.class.php');
740
-            $EE_Export = EE_Export::instance($this->request->requestParams());
741
-            $EE_Export->export();
742
-        }
743
-    }
744
-
745
-
746
-    /**
747
-     * handle category exports()
748
-     *
749
-     * @return void
750
-     */
751
-    protected function _categories_export()
752
-    {
753
-        $EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
754
-        $this->request->mergeRequestParams(
755
-            [
756
-                'export' => 'report',
757
-                'action' => 'categories',
758
-                'EVT_ID' => $EVT_ID,
759
-            ]
760
-        );
761
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
762
-            require_once(EE_CLASSES . 'EE_Export.class.php');
763
-            $EE_Export = EE_Export::instance($this->request->requestParams());
764
-            $EE_Export->export();
765
-        }
766
-    }
767
-
768
-
769
-    /**
770
-     * Creates a sample CSV file for importing
771
-     */
772
-    protected function _sample_export_file()
773
-    {
774
-        $EE_Export = EE_Export::instance();
775
-        if ($EE_Export instanceof EE_Export) {
776
-            $EE_Export->export();
777
-        }
778
-    }
779
-
780
-
781
-    /*************        Template Settings        *************/
782
-    /**
783
-     * Generates template settings page output
784
-     *
785
-     * @throws DomainException
786
-     * @throws EE_Error
787
-     * @throws InvalidArgumentException
788
-     * @throws InvalidDataTypeException
789
-     * @throws InvalidInterfaceException
790
-     */
791
-    protected function _template_settings()
792
-    {
793
-        new TemplateCacheAdmin(EE_Registry::instance()->CFG->template_settings, $this->request);
794
-        $this->_template_args['values'] = $this->_yes_no_values;
795
-        /**
796
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
797
-         * from General_Settings_Admin_Page to here.
798
-         */
799
-        $this->_template_args = apply_filters(
800
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
801
-            $this->_template_args
802
-        );
803
-        $this->_set_add_edit_form_tags('update_template_settings');
804
-        $this->_set_publish_post_box_vars();
805
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
806
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
807
-            $this->_template_args,
808
-            true
809
-        );
810
-        $this->display_admin_page_with_sidebar();
811
-    }
812
-
813
-
814
-    /**
815
-     * Handler for updating template settings.
816
-     *
817
-     * @throws EE_Error
818
-     */
819
-    protected function _update_template_settings()
820
-    {
821
-        new TemplateCacheAdmin(EE_Registry::instance()->CFG->template_settings, $this->request);
822
-        /**
823
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
824
-         * from General_Settings_Admin_Page to here.
825
-         */
826
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
827
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
828
-            EE_Registry::instance()->CFG->template_settings,
829
-            $this->request->requestParams()
830
-        );
831
-        // update custom post type slugs and detect if we need to flush rewrite rules
832
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
833
-
834
-        $event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
835
-
836
-        EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
837
-            ? EEH_URL::slugify($event_cpt_slug, 'events')
838
-            : EE_Registry::instance()->CFG->core->event_cpt_slug;
839
-
840
-        $what    = esc_html__('Template Settings', 'event_espresso');
841
-        $success = $this->_update_espresso_configuration(
842
-            $what,
843
-            EE_Registry::instance()->CFG->template_settings,
844
-            __FILE__,
845
-            __FUNCTION__,
846
-            __LINE__
847
-        );
848
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
849
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
850
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
851
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
852
-            );
853
-            $rewrite_rules->flush();
854
-        }
855
-        do_action(
856
-            'AHEE__General_Settings_Admin_Page__update_template_settings__after_update',
857
-            EE_Registry::instance()->CFG->template_settings,
858
-            $this->request->requestParams(),
859
-            $success
860
-        );
861
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
862
-    }
863
-
864
-
865
-    /**
866
-     * _premium_event_editor_meta_boxes
867
-     * add all metaboxes related to the event_editor
868
-     *
869
-     * @access protected
870
-     * @return void
871
-     * @throws EE_Error
872
-     * @throws ReflectionException
873
-     */
874
-    protected function _premium_event_editor_meta_boxes()
875
-    {
876
-        $this->verify_cpt_object();
877
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
878
-        if (
879
-            ! $this->admin_config->useAdvancedEditor()
880
-            || ! $this->feature->allowed('use_reg_options_meta_box')
881
-        ) {
882
-            $this->addMetaBox(
883
-                'espresso_event_editor_event_options',
884
-                esc_html__('Event Registration Options', 'event_espresso'),
885
-                [$this, 'registration_options_meta_box'],
886
-                $this->page_slug,
887
-                'side',
888
-                'core'
889
-            );
890
-        }
891
-    }
892
-
893
-
894
-    /**
895
-     * override caf metabox
896
-     *
897
-     * @return void
898
-     * @throws EE_Error
899
-     * @throws ReflectionException
900
-     */
901
-    public function registration_options_meta_box()
902
-    {
903
-        $yes_no_values = [
904
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
905
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
906
-        ];
907
-
908
-        $default_reg_status_values = EEM_Registration::reg_status_array(
909
-            [
910
-                RegStatus::CANCELLED,
911
-                RegStatus::DECLINED,
912
-                RegStatus::INCOMPLETE,
913
-                RegStatus::WAIT_LIST,
914
-            ],
915
-            true
916
-        );
917
-
918
-        $template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
919
-        $template_args['_event']           = $this->_cpt_model_obj;
920
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
921
-
922
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
923
-            'default_reg_status',
924
-            $default_reg_status_values,
925
-            $this->_cpt_model_obj->default_registration_status(),
926
-            '',
927
-            'ee-input-width--reg',
928
-            false
929
-        );
930
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
931
-            'display_desc',
932
-            $yes_no_values,
933
-            $this->_cpt_model_obj->display_description()
934
-        );
935
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
936
-            'display_ticket_selector',
937
-            $yes_no_values,
938
-            $this->_cpt_model_obj->display_ticket_selector(),
939
-            '',
940
-            'ee-input-width--small',
941
-            false
942
-        );
943
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
944
-            'EVT_default_registration_status',
945
-            $default_reg_status_values,
946
-            $this->_cpt_model_obj->default_registration_status(),
947
-            '',
948
-            'ee-input-width--reg',
949
-            false
950
-        );
951
-        $template_args['additional_registration_options'] = apply_filters(
952
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
953
-            '',
954
-            $template_args,
955
-            $yes_no_values,
956
-            $default_reg_status_values
957
-        );
958
-        EEH_Template::display_template(
959
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
960
-            $template_args
961
-        );
962
-    }
963
-
964
-
965
-
966
-    /**
967
-     * wp_list_table_mods for caf
968
-     * ============================
969
-     */
970
-
971
-
972
-    /**
973
-     * espresso_event_months_dropdown
974
-     *
975
-     * @deprecatd 5.0.0.p
976
-     * @access public
977
-     * @return string                dropdown listing month/year selections for events.
978
-     * @throws EE_Error
979
-     */
980
-    public function espresso_event_months_dropdown(): string
981
-    {
982
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
983
-        // Note we need to include any other filters that are set!
984
-        return EEH_Form_Fields::generate_event_months_dropdown(
985
-            $this->request->getRequestParam('month_range', ''),
986
-            $this->request->getRequestParam('status', ''),
987
-            $this->request->getRequestParam('EVT_CAT', 0, 'int'),
988
-            $this->request->getRequestParam('active_status', '')
989
-        );
990
-    }
991
-
992
-
993
-    /**
994
-     * returns a list of "active" statuses on the event
995
-     *
996
-     * @deprecatd 5.0.0.p
997
-     * @param string $current_value whatever the current active status is
998
-     * @return string
999
-     */
1000
-    public function active_status_dropdown(string $current_value = ''): string
1001
-    {
1002
-        $select_name = 'active_status';
1003
-        $values      = [
1004
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1005
-            'active'   => esc_html__('Active', 'event_espresso'),
1006
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1007
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1008
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1009
-        ];
1010
-
1011
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value);
1012
-    }
1013
-
1014
-
1015
-    /**
1016
-     * returns a list of "venues"
1017
-     *
1018
-     * @deprecatd 5.0.0.p
1019
-     * @param string $current_value whatever the current active status is
1020
-     * @return string
1021
-     * @throws EE_Error
1022
-     * @throws ReflectionException
1023
-     */
1024
-    protected function venuesDropdown(string $current_value = ''): string
1025
-    {
1026
-        $values = ['' => esc_html__('All Venues', 'event_espresso')];
1027
-        // populate the list of venues.
1028
-        $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1029
-
1030
-        foreach ($venues as $venue) {
1031
-            $values[ $venue->ID() ] = $venue->name();
1032
-        }
1033
-
1034
-        return EEH_Form_Fields::select_input('venue', $values, $current_value);
1035
-    }
1036
-
1037
-
1038
-    /**
1039
-     * output a dropdown of the categories for the category filter on the event admin list table
1040
-     *
1041
-     * @deprecatd 5.0.0.p
1042
-     * @access  public
1043
-     * @return string html
1044
-     * @throws EE_Error
1045
-     * @throws ReflectionException
1046
-     */
1047
-    public function category_dropdown(): string
1048
-    {
1049
-        return EEH_Form_Fields::generate_event_category_dropdown(
1050
-            $this->request->getRequestParam('EVT_CAT', -1, 'int')
1051
-        );
1052
-    }
1053
-
1054
-
1055
-    /**
1056
-     * get total number of events today
1057
-     *
1058
-     * @access public
1059
-     * @return int
1060
-     * @throws EE_Error
1061
-     * @throws InvalidArgumentException
1062
-     * @throws InvalidDataTypeException
1063
-     * @throws InvalidInterfaceException
1064
-     * @throws ReflectionException
1065
-     */
1066
-    public function total_events_today(): int
1067
-    {
1068
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1069
-            'DTT_EVT_start',
1070
-            date('Y-m-d') . ' 00:00:00',
1071
-            'Y-m-d H:i:s',
1072
-            'UTC'
1073
-        );
1074
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1075
-            'DTT_EVT_start',
1076
-            date('Y-m-d') . ' 23:59:59',
1077
-            'Y-m-d H:i:s',
1078
-            'UTC'
1079
-        );
1080
-        $where = [
1081
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1082
-        ];
1083
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1084
-    }
1085
-
1086
-
1087
-    /**
1088
-     * get total number of events this month
1089
-     *
1090
-     * @access public
1091
-     * @return int
1092
-     * @throws EE_Error
1093
-     * @throws InvalidArgumentException
1094
-     * @throws InvalidDataTypeException
1095
-     * @throws InvalidInterfaceException
1096
-     * @throws ReflectionException
1097
-     */
1098
-    public function total_events_this_month(): int
1099
-    {
1100
-        // Dates
1101
-        $this_year_r     = date('Y');
1102
-        $this_month_r    = date('m');
1103
-        $days_this_month = date('t');
1104
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1105
-            'DTT_EVT_start',
1106
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1107
-            'Y-m-d H:i:s',
1108
-            'UTC'
1109
-        );
1110
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1111
-            'DTT_EVT_start',
1112
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1113
-            'Y-m-d H:i:s',
1114
-            'UTC'
1115
-        );
1116
-        $where           = [
1117
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1118
-        ];
1119
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1120
-    }
1121
-
1122
-
1123
-    /** DEFAULT TICKETS STUFF **/
1124
-
1125
-    /**
1126
-     * Output default tickets list table view.
1127
-     *
1128
-     * @throws EE_Error
1129
-     */
1130
-    public function _tickets_overview_list_table()
1131
-    {
1132
-        if (
1133
-            $this->admin_config->useAdvancedEditor()
1134
-            && $this->feature->allowed('use_default_ticket_manager')
1135
-        ) {
1136
-            // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1137
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1138
-                EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1139
-                [],
1140
-                true
1141
-            );
1142
-            $this->display_admin_page_with_no_sidebar();
1143
-        } else {
1144
-            $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1145
-            $this->display_admin_list_table_page_with_no_sidebar();
1146
-        }
1147
-    }
1148
-
1149
-
1150
-    /**
1151
-     * @param int  $per_page
1152
-     * @param bool $count
1153
-     * @param bool $trashed
1154
-     * @return EE_Soft_Delete_Base_Class[]|int
1155
-     * @throws EE_Error
1156
-     * @throws ReflectionException
1157
-     */
1158
-    public function get_default_tickets(int $per_page = 10, bool $count = false, bool $trashed = false)
1159
-    {
1160
-        $orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1161
-        $order   = $this->request->getRequestParam('order', 'ASC');
1162
-        switch ($orderby) {
1163
-            case 'TKT_name':
1164
-                $orderby = ['TKT_name' => $order];
1165
-                break;
1166
-            case 'TKT_price':
1167
-                $orderby = ['TKT_price' => $order];
1168
-                break;
1169
-            case 'TKT_uses':
1170
-                $orderby = ['TKT_uses' => $order];
1171
-                break;
1172
-            case 'TKT_min':
1173
-                $orderby = ['TKT_min' => $order];
1174
-                break;
1175
-            case 'TKT_max':
1176
-                $orderby = ['TKT_max' => $order];
1177
-                break;
1178
-            case 'TKT_qty':
1179
-                $orderby = ['TKT_qty' => $order];
1180
-                break;
1181
-        }
1182
-
1183
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1184
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1185
-        $offset       = ($current_page - 1) * $per_page;
1186
-
1187
-        $where = [
1188
-            'TKT_is_default' => 1,
1189
-            'TKT_deleted'    => $trashed,
1190
-        ];
1191
-
1192
-        $search_term = $this->request->getRequestParam('s');
1193
-        if ($search_term) {
1194
-            $search_term = '%' . $search_term . '%';
1195
-            $where['OR'] = [
1196
-                'TKT_name'        => ['LIKE', $search_term],
1197
-                'TKT_description' => ['LIKE', $search_term],
1198
-            ];
1199
-        }
1200
-
1201
-        return $count
1202
-            ? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1203
-            : EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1204
-                [
1205
-                    $where,
1206
-                    'order_by' => $orderby,
1207
-                    'limit'    => [$offset, $per_page],
1208
-                    'group_by' => 'TKT_ID',
1209
-                ]
1210
-            );
1211
-    }
1212
-
1213
-
1214
-    /**
1215
-     * @param bool $trash
1216
-     * @throws EE_Error
1217
-     * @throws InvalidArgumentException
1218
-     * @throws InvalidDataTypeException
1219
-     * @throws InvalidInterfaceException
1220
-     * @throws ReflectionException
1221
-     */
1222
-    protected function _trash_or_restore_ticket(bool $trash = false)
1223
-    {
1224
-        $success = 1;
1225
-        $TKT     = EEM_Ticket::instance();
1226
-        // checkboxes?
1227
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1228
-        if (! empty($checkboxes)) {
1229
-            // if array has more than one element then success message should be plural
1230
-            $success = count($checkboxes) > 1 ? 2 : 1;
1231
-            // cycle thru the boxes
1232
-            foreach ($checkboxes as $TKT_ID => $value) {
1233
-                if ($trash) {
1234
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1235
-                        $success = 0;
1236
-                    }
1237
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1238
-                    $success = 0;
1239
-                }
1240
-            }
1241
-        } else {
1242
-            // grab single id and trash
1243
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1244
-            if ($trash) {
1245
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1246
-                    $success = 0;
1247
-                }
1248
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1249
-                $success = 0;
1250
-            }
1251
-        }
1252
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1253
-        $query_args  = [
1254
-            'action' => 'ticket_list_table',
1255
-            'status' => $trash ? '' : 'trashed',
1256
-        ];
1257
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1258
-    }
1259
-
1260
-
1261
-    /**
1262
-     * Handles trashing default ticket.
1263
-     *
1264
-     * @throws EE_Error
1265
-     * @throws ReflectionException
1266
-     */
1267
-    protected function _delete_ticket()
1268
-    {
1269
-        $success = 1;
1270
-        // checkboxes?
1271
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1272
-        if (! empty($checkboxes)) {
1273
-            // if array has more than one element then success message should be plural
1274
-            $success = count($checkboxes) > 1 ? 2 : 1;
1275
-            // cycle thru the boxes
1276
-            foreach ($checkboxes as $TKT_ID => $value) {
1277
-                // delete
1278
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1279
-                    $success = 0;
1280
-                }
1281
-            }
1282
-        } else {
1283
-            // grab single id and trash
1284
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1285
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1286
-                $success = 0;
1287
-            }
1288
-        }
1289
-        $action_desc = 'deleted';
1290
-        $query_args  = [
1291
-            'action' => 'ticket_list_table',
1292
-            'status' => 'trashed',
1293
-        ];
1294
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1295
-        if (
1296
-            EEM_Ticket::instance()->count_deleted_and_undeleted(
1297
-                [['TKT_is_default' => 1]],
1298
-                'TKT_ID',
1299
-                true
1300
-            )
1301
-        ) {
1302
-            $query_args = [];
1303
-        }
1304
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1305
-    }
1306
-
1307
-
1308
-    /**
1309
-     * @param int $TKT_ID
1310
-     * @return bool|int
1311
-     * @throws EE_Error
1312
-     * @throws ReflectionException
1313
-     */
1314
-    protected function _delete_the_ticket(int $TKT_ID)
1315
-    {
1316
-        $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1317
-        if (! $ticket instanceof EE_Ticket) {
1318
-            return false;
1319
-        }
1320
-        $ticket->_remove_relations('Datetime');
1321
-        // delete all related prices first
1322
-        $ticket->delete_related_permanently('Price');
1323
-        return $ticket->delete_permanently();
1324
-    }
393
+		}
394
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
395
+			EE_Registry::instance()->load_helper('MSG_Template');
396
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
397
+				'see_notifications_for',
398
+				null,
399
+				['EVT_ID' => $event->ID()]
400
+			);
401
+		}
402
+		return $action_links;
403
+	}
404
+
405
+
406
+	/**
407
+	 * @param $items
408
+	 * @return mixed
409
+	 */
410
+	public function additional_legend_items($items)
411
+	{
412
+		if (
413
+			EE_Registry::instance()->CAP->current_user_can(
414
+				'ee_read_registrations',
415
+				'espresso_registrations_reports'
416
+			)
417
+		) {
418
+			$items['reports'] = [
419
+				'class' => 'dashicons dashicons-chart-bar',
420
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
421
+			];
422
+		}
423
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
424
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
425
+			// $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
426
+			// (can only use numeric offsets when treating strings as arrays)
427
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
428
+				$items['view_related_messages'] = [
429
+					'class' => $related_for_icon['css_class'],
430
+					'desc'  => $related_for_icon['label'],
431
+				];
432
+			}
433
+		}
434
+		return $items;
435
+	}
436
+
437
+
438
+	/**
439
+	 * This is the callback method for the duplicate event route
440
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
441
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
442
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
443
+	 * After duplication the redirect is to the new event edit page.
444
+	 *
445
+	 * @return void
446
+	 * @throws EE_Error If EE_Event is not available with given ID
447
+	 * @throws ReflectionException
448
+	 * @access protected
449
+	 */
450
+	protected function _duplicate_event()
451
+	{
452
+		// first make sure the ID for the event is in the request.
453
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
454
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
455
+		if (! $EVT_ID) {
456
+			EE_Error::add_error(
457
+				esc_html__(
458
+					'In order to duplicate an event an Event ID is required.  None was given.',
459
+					'event_espresso'
460
+				),
461
+				__FILE__,
462
+				__FUNCTION__,
463
+				__LINE__
464
+			);
465
+			$this->_redirect_after_action(false, '', '', [], true);
466
+			return;
467
+		}
468
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
469
+		$orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
470
+		if (! $orig_event instanceof EE_Event) {
471
+			throw new EE_Error(
472
+				sprintf(
473
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
474
+					$EVT_ID
475
+				)
476
+			);
477
+		}
478
+		// k now let's clone the $orig_event before getting relations
479
+		$new_event = clone $orig_event;
480
+		// original datetimes
481
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
482
+		// other original relations
483
+		$orig_ven = $orig_event->get_many_related('Venue');
484
+		// reset the ID and modify other details to make it clear this is a dupe
485
+		$new_event->set('EVT_ID', 0);
486
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
487
+		$new_event->set('EVT_name', $new_name);
488
+		$new_event->set(
489
+			'EVT_slug',
490
+			wp_unique_post_slug(
491
+				sanitize_title($orig_event->name()),
492
+				0,
493
+				'publish',
494
+				EspressoPostType::EVENTS,
495
+				0
496
+			)
497
+		);
498
+		$new_event->set('status', 'draft');
499
+		// duplicate discussion settings
500
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
501
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
502
+		// save the new event
503
+		$new_event->save();
504
+		// venues
505
+		foreach ($orig_ven as $ven) {
506
+			$new_event->_add_relation_to($ven, 'Venue');
507
+		}
508
+		$new_event->save();
509
+		// now we need to get the question group relations and handle that
510
+		// first primary question groups
511
+		$orig_primary_qgs = $orig_event->get_many_related(
512
+			'Question_Group',
513
+			[['Event_Question_Group.EQG_primary' => true]]
514
+		);
515
+		if (! empty($orig_primary_qgs)) {
516
+			foreach ($orig_primary_qgs as $obj) {
517
+				if ($obj instanceof EE_Question_Group) {
518
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
519
+				}
520
+			}
521
+		}
522
+		// next additional attendee question groups
523
+		$orig_additional_qgs = $orig_event->get_many_related(
524
+			'Question_Group',
525
+			[['Event_Question_Group.EQG_additional' => true]]
526
+		);
527
+		if (! empty($orig_additional_qgs)) {
528
+			foreach ($orig_additional_qgs as $obj) {
529
+				if ($obj instanceof EE_Question_Group) {
530
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
531
+				}
532
+			}
533
+		}
534
+
535
+		$new_event->save();
536
+
537
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
538
+		$cloned_tickets = [];
539
+		foreach ($orig_datetimes as $orig_dtt) {
540
+			if (! $orig_dtt instanceof EE_Datetime) {
541
+				continue;
542
+			}
543
+			$new_dtt      = clone $orig_dtt;
544
+			$orig_tickets = $orig_dtt->tickets();
545
+			// save new dtt then add to event
546
+			$new_dtt->set('DTT_ID', 0);
547
+			$new_dtt->set('DTT_sold', 0);
548
+			$new_dtt->set_reserved(0);
549
+			$new_dtt->save();
550
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
551
+			$new_event->save();
552
+			// now let's get the ticket relations setup.
553
+			foreach ((array) $orig_tickets as $orig_ticket) {
554
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
555
+				if (! $orig_ticket instanceof EE_Ticket) {
556
+					continue;
557
+				}
558
+				// is this ticket archived?  If it is then let's skip
559
+				if ($orig_ticket->get('TKT_deleted')) {
560
+					continue;
561
+				}
562
+				// does this original ticket already exist in the clone_tickets cache?
563
+				//  If so we'll just use the new ticket from it.
564
+				if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
565
+					$new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
566
+				} else {
567
+					$new_ticket = clone $orig_ticket;
568
+					// get relations on the $orig_ticket that we need to set up.
569
+					$orig_prices = $orig_ticket->prices();
570
+					$new_ticket->set('TKT_ID', 0);
571
+					$new_ticket->set('TKT_sold', 0);
572
+					$new_ticket->set('TKT_reserved', 0);
573
+					// make sure new ticket has ID.
574
+					$new_ticket->save();
575
+					// price relations on new ticket need to be setup.
576
+					foreach ($orig_prices as $orig_price) {
577
+						// don't clone default prices, just add a relation
578
+						if ($orig_price->is_default()) {
579
+							$new_ticket->_add_relation_to($orig_price, 'Price');
580
+							$new_ticket->save();
581
+							continue;
582
+						}
583
+						$new_price = clone $orig_price;
584
+						$new_price->set('PRC_ID', 0);
585
+						$new_price->save();
586
+						$new_ticket->_add_relation_to($new_price, 'Price');
587
+					}
588
+					$new_ticket->save();
589
+
590
+					do_action(
591
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
592
+						$orig_ticket,
593
+						$new_ticket,
594
+						$orig_prices,
595
+						$orig_event,
596
+						$orig_dtt,
597
+						$new_dtt
598
+					);
599
+					$cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
600
+				}
601
+				// k now we can add the new ticket as a relation to the new datetime
602
+				// and make sure it's added to our cached $cloned_tickets array
603
+				// for use with later datetimes that have the same ticket.
604
+				$new_dtt->_add_relation_to($new_ticket, 'Ticket');
605
+			}
606
+			$new_dtt->save();
607
+		}
608
+		// clone taxonomy information
609
+		$taxonomies_to_clone_with = apply_filters(
610
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
611
+			['espresso_event_categories', 'espresso_event_type', 'post_tag']
612
+		);
613
+		// get terms for original event (notice)
614
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
615
+		// loop through terms and add them to new event.
616
+		foreach ($orig_terms as $term) {
617
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
618
+		}
619
+
620
+		// duplicate other core WP_Post items for this event.
621
+		// post thumbnail (feature image).
622
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
623
+		if ($feature_image_id) {
624
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
625
+		}
626
+
627
+		// duplicate page_template setting
628
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
629
+		if ($page_template) {
630
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
631
+		}
632
+
633
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
634
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
635
+		if ($new_event->ID()) {
636
+			$redirect_args = [
637
+				'post'   => $new_event->ID(),
638
+				'action' => 'edit',
639
+			];
640
+			EE_Error::add_success(
641
+				esc_html__(
642
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
643
+					'event_espresso'
644
+				)
645
+			);
646
+		} else {
647
+			$redirect_args = [
648
+				'action' => 'default',
649
+			];
650
+			EE_Error::add_error(
651
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
652
+				__FILE__,
653
+				__FUNCTION__,
654
+				__LINE__
655
+			);
656
+		}
657
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
658
+	}
659
+
660
+
661
+	/**
662
+	 * Generates output for the import page.
663
+	 *
664
+	 * @throws EE_Error
665
+	 */
666
+	protected function _import_page()
667
+	{
668
+		$title = esc_html__('Import', 'event_espresso');
669
+		$intro = esc_html__(
670
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
671
+			'event_espresso'
672
+		);
673
+
674
+		$form_url = EVENTS_ADMIN_URL;
675
+		$action   = 'import_events';
676
+		$type     = 'csv';
677
+
678
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
679
+			$title,
680
+			$intro,
681
+			$form_url,
682
+			$action,
683
+			$type
684
+		);
685
+
686
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
687
+			['action' => 'sample_export_file'],
688
+			$this->_admin_base_url
689
+		);
690
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
691
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
692
+			$this->_template_args,
693
+			true
694
+		);
695
+		$this->display_admin_page_with_sidebar();
696
+	}
697
+
698
+
699
+	/**
700
+	 * _import_events
701
+	 * This handles displaying the screen and running imports for importing events.
702
+	 *
703
+	 * @return void
704
+	 * @throws EE_Error
705
+	 */
706
+	protected function _import_events()
707
+	{
708
+		require_once(EE_CLASSES . 'EE_Import.class.php');
709
+		$success = EE_Import::instance()->import();
710
+		$this->_redirect_after_action(
711
+			$success,
712
+			esc_html__('Import File', 'event_espresso'),
713
+			'ran',
714
+			['action' => 'import_page'],
715
+			true
716
+		);
717
+	}
718
+
719
+
720
+	/**
721
+	 * _events_export
722
+	 * Will export all (or just the given event) to a Excel compatible file.
723
+	 *
724
+	 * @access protected
725
+	 * @return void
726
+	 */
727
+	protected function _events_export()
728
+	{
729
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
730
+		$EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
731
+		$this->request->mergeRequestParams(
732
+			[
733
+				'export' => 'report',
734
+				'action' => 'all_event_data',
735
+				'EVT_ID' => $EVT_ID,
736
+			]
737
+		);
738
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
739
+			require_once(EE_CLASSES . 'EE_Export.class.php');
740
+			$EE_Export = EE_Export::instance($this->request->requestParams());
741
+			$EE_Export->export();
742
+		}
743
+	}
744
+
745
+
746
+	/**
747
+	 * handle category exports()
748
+	 *
749
+	 * @return void
750
+	 */
751
+	protected function _categories_export()
752
+	{
753
+		$EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
754
+		$this->request->mergeRequestParams(
755
+			[
756
+				'export' => 'report',
757
+				'action' => 'categories',
758
+				'EVT_ID' => $EVT_ID,
759
+			]
760
+		);
761
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
762
+			require_once(EE_CLASSES . 'EE_Export.class.php');
763
+			$EE_Export = EE_Export::instance($this->request->requestParams());
764
+			$EE_Export->export();
765
+		}
766
+	}
767
+
768
+
769
+	/**
770
+	 * Creates a sample CSV file for importing
771
+	 */
772
+	protected function _sample_export_file()
773
+	{
774
+		$EE_Export = EE_Export::instance();
775
+		if ($EE_Export instanceof EE_Export) {
776
+			$EE_Export->export();
777
+		}
778
+	}
779
+
780
+
781
+	/*************        Template Settings        *************/
782
+	/**
783
+	 * Generates template settings page output
784
+	 *
785
+	 * @throws DomainException
786
+	 * @throws EE_Error
787
+	 * @throws InvalidArgumentException
788
+	 * @throws InvalidDataTypeException
789
+	 * @throws InvalidInterfaceException
790
+	 */
791
+	protected function _template_settings()
792
+	{
793
+		new TemplateCacheAdmin(EE_Registry::instance()->CFG->template_settings, $this->request);
794
+		$this->_template_args['values'] = $this->_yes_no_values;
795
+		/**
796
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
797
+		 * from General_Settings_Admin_Page to here.
798
+		 */
799
+		$this->_template_args = apply_filters(
800
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
801
+			$this->_template_args
802
+		);
803
+		$this->_set_add_edit_form_tags('update_template_settings');
804
+		$this->_set_publish_post_box_vars();
805
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
806
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
807
+			$this->_template_args,
808
+			true
809
+		);
810
+		$this->display_admin_page_with_sidebar();
811
+	}
812
+
813
+
814
+	/**
815
+	 * Handler for updating template settings.
816
+	 *
817
+	 * @throws EE_Error
818
+	 */
819
+	protected function _update_template_settings()
820
+	{
821
+		new TemplateCacheAdmin(EE_Registry::instance()->CFG->template_settings, $this->request);
822
+		/**
823
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
824
+		 * from General_Settings_Admin_Page to here.
825
+		 */
826
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
827
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
828
+			EE_Registry::instance()->CFG->template_settings,
829
+			$this->request->requestParams()
830
+		);
831
+		// update custom post type slugs and detect if we need to flush rewrite rules
832
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
833
+
834
+		$event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
835
+
836
+		EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
837
+			? EEH_URL::slugify($event_cpt_slug, 'events')
838
+			: EE_Registry::instance()->CFG->core->event_cpt_slug;
839
+
840
+		$what    = esc_html__('Template Settings', 'event_espresso');
841
+		$success = $this->_update_espresso_configuration(
842
+			$what,
843
+			EE_Registry::instance()->CFG->template_settings,
844
+			__FILE__,
845
+			__FUNCTION__,
846
+			__LINE__
847
+		);
848
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
849
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
850
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
851
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
852
+			);
853
+			$rewrite_rules->flush();
854
+		}
855
+		do_action(
856
+			'AHEE__General_Settings_Admin_Page__update_template_settings__after_update',
857
+			EE_Registry::instance()->CFG->template_settings,
858
+			$this->request->requestParams(),
859
+			$success
860
+		);
861
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
862
+	}
863
+
864
+
865
+	/**
866
+	 * _premium_event_editor_meta_boxes
867
+	 * add all metaboxes related to the event_editor
868
+	 *
869
+	 * @access protected
870
+	 * @return void
871
+	 * @throws EE_Error
872
+	 * @throws ReflectionException
873
+	 */
874
+	protected function _premium_event_editor_meta_boxes()
875
+	{
876
+		$this->verify_cpt_object();
877
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
878
+		if (
879
+			! $this->admin_config->useAdvancedEditor()
880
+			|| ! $this->feature->allowed('use_reg_options_meta_box')
881
+		) {
882
+			$this->addMetaBox(
883
+				'espresso_event_editor_event_options',
884
+				esc_html__('Event Registration Options', 'event_espresso'),
885
+				[$this, 'registration_options_meta_box'],
886
+				$this->page_slug,
887
+				'side',
888
+				'core'
889
+			);
890
+		}
891
+	}
892
+
893
+
894
+	/**
895
+	 * override caf metabox
896
+	 *
897
+	 * @return void
898
+	 * @throws EE_Error
899
+	 * @throws ReflectionException
900
+	 */
901
+	public function registration_options_meta_box()
902
+	{
903
+		$yes_no_values = [
904
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
905
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
906
+		];
907
+
908
+		$default_reg_status_values = EEM_Registration::reg_status_array(
909
+			[
910
+				RegStatus::CANCELLED,
911
+				RegStatus::DECLINED,
912
+				RegStatus::INCOMPLETE,
913
+				RegStatus::WAIT_LIST,
914
+			],
915
+			true
916
+		);
917
+
918
+		$template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
919
+		$template_args['_event']           = $this->_cpt_model_obj;
920
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
921
+
922
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
923
+			'default_reg_status',
924
+			$default_reg_status_values,
925
+			$this->_cpt_model_obj->default_registration_status(),
926
+			'',
927
+			'ee-input-width--reg',
928
+			false
929
+		);
930
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
931
+			'display_desc',
932
+			$yes_no_values,
933
+			$this->_cpt_model_obj->display_description()
934
+		);
935
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
936
+			'display_ticket_selector',
937
+			$yes_no_values,
938
+			$this->_cpt_model_obj->display_ticket_selector(),
939
+			'',
940
+			'ee-input-width--small',
941
+			false
942
+		);
943
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
944
+			'EVT_default_registration_status',
945
+			$default_reg_status_values,
946
+			$this->_cpt_model_obj->default_registration_status(),
947
+			'',
948
+			'ee-input-width--reg',
949
+			false
950
+		);
951
+		$template_args['additional_registration_options'] = apply_filters(
952
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
953
+			'',
954
+			$template_args,
955
+			$yes_no_values,
956
+			$default_reg_status_values
957
+		);
958
+		EEH_Template::display_template(
959
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
960
+			$template_args
961
+		);
962
+	}
963
+
964
+
965
+
966
+	/**
967
+	 * wp_list_table_mods for caf
968
+	 * ============================
969
+	 */
970
+
971
+
972
+	/**
973
+	 * espresso_event_months_dropdown
974
+	 *
975
+	 * @deprecatd 5.0.0.p
976
+	 * @access public
977
+	 * @return string                dropdown listing month/year selections for events.
978
+	 * @throws EE_Error
979
+	 */
980
+	public function espresso_event_months_dropdown(): string
981
+	{
982
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
983
+		// Note we need to include any other filters that are set!
984
+		return EEH_Form_Fields::generate_event_months_dropdown(
985
+			$this->request->getRequestParam('month_range', ''),
986
+			$this->request->getRequestParam('status', ''),
987
+			$this->request->getRequestParam('EVT_CAT', 0, 'int'),
988
+			$this->request->getRequestParam('active_status', '')
989
+		);
990
+	}
991
+
992
+
993
+	/**
994
+	 * returns a list of "active" statuses on the event
995
+	 *
996
+	 * @deprecatd 5.0.0.p
997
+	 * @param string $current_value whatever the current active status is
998
+	 * @return string
999
+	 */
1000
+	public function active_status_dropdown(string $current_value = ''): string
1001
+	{
1002
+		$select_name = 'active_status';
1003
+		$values      = [
1004
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1005
+			'active'   => esc_html__('Active', 'event_espresso'),
1006
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1007
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1008
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1009
+		];
1010
+
1011
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value);
1012
+	}
1013
+
1014
+
1015
+	/**
1016
+	 * returns a list of "venues"
1017
+	 *
1018
+	 * @deprecatd 5.0.0.p
1019
+	 * @param string $current_value whatever the current active status is
1020
+	 * @return string
1021
+	 * @throws EE_Error
1022
+	 * @throws ReflectionException
1023
+	 */
1024
+	protected function venuesDropdown(string $current_value = ''): string
1025
+	{
1026
+		$values = ['' => esc_html__('All Venues', 'event_espresso')];
1027
+		// populate the list of venues.
1028
+		$venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1029
+
1030
+		foreach ($venues as $venue) {
1031
+			$values[ $venue->ID() ] = $venue->name();
1032
+		}
1033
+
1034
+		return EEH_Form_Fields::select_input('venue', $values, $current_value);
1035
+	}
1036
+
1037
+
1038
+	/**
1039
+	 * output a dropdown of the categories for the category filter on the event admin list table
1040
+	 *
1041
+	 * @deprecatd 5.0.0.p
1042
+	 * @access  public
1043
+	 * @return string html
1044
+	 * @throws EE_Error
1045
+	 * @throws ReflectionException
1046
+	 */
1047
+	public function category_dropdown(): string
1048
+	{
1049
+		return EEH_Form_Fields::generate_event_category_dropdown(
1050
+			$this->request->getRequestParam('EVT_CAT', -1, 'int')
1051
+		);
1052
+	}
1053
+
1054
+
1055
+	/**
1056
+	 * get total number of events today
1057
+	 *
1058
+	 * @access public
1059
+	 * @return int
1060
+	 * @throws EE_Error
1061
+	 * @throws InvalidArgumentException
1062
+	 * @throws InvalidDataTypeException
1063
+	 * @throws InvalidInterfaceException
1064
+	 * @throws ReflectionException
1065
+	 */
1066
+	public function total_events_today(): int
1067
+	{
1068
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1069
+			'DTT_EVT_start',
1070
+			date('Y-m-d') . ' 00:00:00',
1071
+			'Y-m-d H:i:s',
1072
+			'UTC'
1073
+		);
1074
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1075
+			'DTT_EVT_start',
1076
+			date('Y-m-d') . ' 23:59:59',
1077
+			'Y-m-d H:i:s',
1078
+			'UTC'
1079
+		);
1080
+		$where = [
1081
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1082
+		];
1083
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1084
+	}
1085
+
1086
+
1087
+	/**
1088
+	 * get total number of events this month
1089
+	 *
1090
+	 * @access public
1091
+	 * @return int
1092
+	 * @throws EE_Error
1093
+	 * @throws InvalidArgumentException
1094
+	 * @throws InvalidDataTypeException
1095
+	 * @throws InvalidInterfaceException
1096
+	 * @throws ReflectionException
1097
+	 */
1098
+	public function total_events_this_month(): int
1099
+	{
1100
+		// Dates
1101
+		$this_year_r     = date('Y');
1102
+		$this_month_r    = date('m');
1103
+		$days_this_month = date('t');
1104
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1105
+			'DTT_EVT_start',
1106
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1107
+			'Y-m-d H:i:s',
1108
+			'UTC'
1109
+		);
1110
+		$end             = EEM_Datetime::instance()->convert_datetime_for_query(
1111
+			'DTT_EVT_start',
1112
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1113
+			'Y-m-d H:i:s',
1114
+			'UTC'
1115
+		);
1116
+		$where           = [
1117
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1118
+		];
1119
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1120
+	}
1121
+
1122
+
1123
+	/** DEFAULT TICKETS STUFF **/
1124
+
1125
+	/**
1126
+	 * Output default tickets list table view.
1127
+	 *
1128
+	 * @throws EE_Error
1129
+	 */
1130
+	public function _tickets_overview_list_table()
1131
+	{
1132
+		if (
1133
+			$this->admin_config->useAdvancedEditor()
1134
+			&& $this->feature->allowed('use_default_ticket_manager')
1135
+		) {
1136
+			// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1137
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1138
+				EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1139
+				[],
1140
+				true
1141
+			);
1142
+			$this->display_admin_page_with_no_sidebar();
1143
+		} else {
1144
+			$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1145
+			$this->display_admin_list_table_page_with_no_sidebar();
1146
+		}
1147
+	}
1148
+
1149
+
1150
+	/**
1151
+	 * @param int  $per_page
1152
+	 * @param bool $count
1153
+	 * @param bool $trashed
1154
+	 * @return EE_Soft_Delete_Base_Class[]|int
1155
+	 * @throws EE_Error
1156
+	 * @throws ReflectionException
1157
+	 */
1158
+	public function get_default_tickets(int $per_page = 10, bool $count = false, bool $trashed = false)
1159
+	{
1160
+		$orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1161
+		$order   = $this->request->getRequestParam('order', 'ASC');
1162
+		switch ($orderby) {
1163
+			case 'TKT_name':
1164
+				$orderby = ['TKT_name' => $order];
1165
+				break;
1166
+			case 'TKT_price':
1167
+				$orderby = ['TKT_price' => $order];
1168
+				break;
1169
+			case 'TKT_uses':
1170
+				$orderby = ['TKT_uses' => $order];
1171
+				break;
1172
+			case 'TKT_min':
1173
+				$orderby = ['TKT_min' => $order];
1174
+				break;
1175
+			case 'TKT_max':
1176
+				$orderby = ['TKT_max' => $order];
1177
+				break;
1178
+			case 'TKT_qty':
1179
+				$orderby = ['TKT_qty' => $order];
1180
+				break;
1181
+		}
1182
+
1183
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1184
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1185
+		$offset       = ($current_page - 1) * $per_page;
1186
+
1187
+		$where = [
1188
+			'TKT_is_default' => 1,
1189
+			'TKT_deleted'    => $trashed,
1190
+		];
1191
+
1192
+		$search_term = $this->request->getRequestParam('s');
1193
+		if ($search_term) {
1194
+			$search_term = '%' . $search_term . '%';
1195
+			$where['OR'] = [
1196
+				'TKT_name'        => ['LIKE', $search_term],
1197
+				'TKT_description' => ['LIKE', $search_term],
1198
+			];
1199
+		}
1200
+
1201
+		return $count
1202
+			? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1203
+			: EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1204
+				[
1205
+					$where,
1206
+					'order_by' => $orderby,
1207
+					'limit'    => [$offset, $per_page],
1208
+					'group_by' => 'TKT_ID',
1209
+				]
1210
+			);
1211
+	}
1212
+
1213
+
1214
+	/**
1215
+	 * @param bool $trash
1216
+	 * @throws EE_Error
1217
+	 * @throws InvalidArgumentException
1218
+	 * @throws InvalidDataTypeException
1219
+	 * @throws InvalidInterfaceException
1220
+	 * @throws ReflectionException
1221
+	 */
1222
+	protected function _trash_or_restore_ticket(bool $trash = false)
1223
+	{
1224
+		$success = 1;
1225
+		$TKT     = EEM_Ticket::instance();
1226
+		// checkboxes?
1227
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1228
+		if (! empty($checkboxes)) {
1229
+			// if array has more than one element then success message should be plural
1230
+			$success = count($checkboxes) > 1 ? 2 : 1;
1231
+			// cycle thru the boxes
1232
+			foreach ($checkboxes as $TKT_ID => $value) {
1233
+				if ($trash) {
1234
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1235
+						$success = 0;
1236
+					}
1237
+				} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1238
+					$success = 0;
1239
+				}
1240
+			}
1241
+		} else {
1242
+			// grab single id and trash
1243
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1244
+			if ($trash) {
1245
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1246
+					$success = 0;
1247
+				}
1248
+			} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1249
+				$success = 0;
1250
+			}
1251
+		}
1252
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1253
+		$query_args  = [
1254
+			'action' => 'ticket_list_table',
1255
+			'status' => $trash ? '' : 'trashed',
1256
+		];
1257
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1258
+	}
1259
+
1260
+
1261
+	/**
1262
+	 * Handles trashing default ticket.
1263
+	 *
1264
+	 * @throws EE_Error
1265
+	 * @throws ReflectionException
1266
+	 */
1267
+	protected function _delete_ticket()
1268
+	{
1269
+		$success = 1;
1270
+		// checkboxes?
1271
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1272
+		if (! empty($checkboxes)) {
1273
+			// if array has more than one element then success message should be plural
1274
+			$success = count($checkboxes) > 1 ? 2 : 1;
1275
+			// cycle thru the boxes
1276
+			foreach ($checkboxes as $TKT_ID => $value) {
1277
+				// delete
1278
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1279
+					$success = 0;
1280
+				}
1281
+			}
1282
+		} else {
1283
+			// grab single id and trash
1284
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1285
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1286
+				$success = 0;
1287
+			}
1288
+		}
1289
+		$action_desc = 'deleted';
1290
+		$query_args  = [
1291
+			'action' => 'ticket_list_table',
1292
+			'status' => 'trashed',
1293
+		];
1294
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1295
+		if (
1296
+			EEM_Ticket::instance()->count_deleted_and_undeleted(
1297
+				[['TKT_is_default' => 1]],
1298
+				'TKT_ID',
1299
+				true
1300
+			)
1301
+		) {
1302
+			$query_args = [];
1303
+		}
1304
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1305
+	}
1306
+
1307
+
1308
+	/**
1309
+	 * @param int $TKT_ID
1310
+	 * @return bool|int
1311
+	 * @throws EE_Error
1312
+	 * @throws ReflectionException
1313
+	 */
1314
+	protected function _delete_the_ticket(int $TKT_ID)
1315
+	{
1316
+		$ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1317
+		if (! $ticket instanceof EE_Ticket) {
1318
+			return false;
1319
+		}
1320
+		$ticket->_remove_relations('Datetime');
1321
+		// delete all related prices first
1322
+		$ticket->delete_related_permanently('Price');
1323
+		return $ticket->delete_permanently();
1324
+	}
1325 1325
 }
Please login to merge, or discard this patch.
admin/extend/registration_form/Extend_Registration_Form_Admin_Page.core.php 2 patches
Indentation   +1491 added lines, -1491 removed lines patch added patch discarded remove patch
@@ -16,1495 +16,1495 @@
 block discarded – undo
16 16
  */
17 17
 class Extend_Registration_Form_Admin_Page extends Registration_Form_Admin_Page
18 18
 {
19
-    /**
20
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
21
-     * @throws EE_Error
22
-     * @throws ReflectionException
23
-     */
24
-    public function __construct($routing = true)
25
-    {
26
-        define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/');
27
-        define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/');
28
-        define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
29
-        define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/');
30
-        define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
31
-        parent::__construct($routing);
32
-    }
33
-
34
-
35
-    protected function _define_page_props()
36
-    {
37
-        parent::_define_page_props();
38
-        $this->_labels['publishbox'] = [
39
-            'add_question'        => esc_html__('Add New Question', 'event_espresso'),
40
-            'edit_question'       => esc_html__('Edit Question', 'event_espresso'),
41
-            'add_question_group'  => esc_html__('Add New Question Group', 'event_espresso'),
42
-            'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'),
43
-        ];
44
-    }
45
-
46
-
47
-    protected function _set_page_config()
48
-    {
49
-        parent::_set_page_config();
50
-
51
-        $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;
52
-        $qst_id                 = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID'])
53
-            ? $this->_req_data['QST_ID'] : 0;
54
-        $qsg_id                 = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID'])
55
-            ? $this->_req_data['QSG_ID'] : 0;
56
-
57
-        $new_page_routes    = [
58
-            'question_groups'    => [
59
-                'func'       => [$this, '_question_groups_overview_list_table'],
60
-                'capability' => 'ee_read_question_groups',
61
-            ],
62
-            'add_question'       => [
63
-                'func'       => [$this, '_edit_question'],
64
-                'capability' => 'ee_edit_questions',
65
-            ],
66
-            'insert_question'    => [
67
-                'func'       => [$this, '_insert_or_update_question'],
68
-                'args'       => ['new_question' => true],
69
-                'capability' => 'ee_edit_questions',
70
-                'noheader'   => true,
71
-            ],
72
-            'duplicate_question' => [
73
-                'func'       => [$this, '_duplicate_question'],
74
-                'capability' => 'ee_edit_questions',
75
-                'noheader'   => true,
76
-            ],
77
-            'trash_question'     => [
78
-                'func'       => [$this, '_trash_question'],
79
-                'capability' => 'ee_delete_question',
80
-                'obj_id'     => $qst_id,
81
-                'noheader'   => true,
82
-            ],
83
-
84
-            'restore_question' => [
85
-                'func'       => [$this, '_trash_or_restore_questions'],
86
-                'capability' => 'ee_delete_question',
87
-                'obj_id'     => $qst_id,
88
-                'args'       => ['trash' => false],
89
-                'noheader'   => true,
90
-            ],
91
-
92
-            'delete_question' => [
93
-                'func'       => [$this, '_delete_question'],
94
-                'capability' => 'ee_delete_question',
95
-                'obj_id'     => $qst_id,
96
-                'noheader'   => true,
97
-            ],
98
-
99
-            'trash_questions' => [
100
-                'func'       => [$this, '_trash_or_restore_questions'],
101
-                'capability' => 'ee_delete_questions',
102
-                'args'       => ['trash' => true],
103
-                'noheader'   => true,
104
-            ],
105
-
106
-            'restore_questions' => [
107
-                'func'       => [$this, '_trash_or_restore_questions'],
108
-                'capability' => 'ee_delete_questions',
109
-                'args'       => ['trash' => false],
110
-                'noheader'   => true,
111
-            ],
112
-
113
-            'delete_questions' => [
114
-                'func'       => [$this, '_delete_questions'],
115
-                'args'       => [],
116
-                'capability' => 'ee_delete_questions',
117
-                'noheader'   => true,
118
-            ],
119
-
120
-            'add_question_group' => [
121
-                'func'       => [$this, '_edit_question_group'],
122
-                'capability' => 'ee_edit_question_groups',
123
-            ],
124
-
125
-            'edit_question_group' => [
126
-                'func'       => [$this, '_edit_question_group'],
127
-                'capability' => 'ee_edit_question_group',
128
-                'obj_id'     => $qsg_id,
129
-                'args'       => ['edit'],
130
-            ],
131
-
132
-            'delete_question_groups' => [
133
-                'func'       => [$this, '_delete_question_groups'],
134
-                'capability' => 'ee_delete_question_groups',
135
-                'noheader'   => true,
136
-            ],
137
-
138
-            'delete_question_group' => [
139
-                'func'       => [$this, '_delete_question_groups'],
140
-                'capability' => 'ee_delete_question_group',
141
-                'obj_id'     => $qsg_id,
142
-                'noheader'   => true,
143
-            ],
144
-
145
-            'trash_question_group' => [
146
-                'func'       => [$this, '_trash_or_restore_question_groups'],
147
-                'args'       => ['trash' => true],
148
-                'capability' => 'ee_delete_question_group',
149
-                'obj_id'     => $qsg_id,
150
-                'noheader'   => true,
151
-            ],
152
-
153
-            'restore_question_group' => [
154
-                'func'       => [$this, '_trash_or_restore_question_groups'],
155
-                'args'       => ['trash' => false],
156
-                'capability' => 'ee_delete_question_group',
157
-                'obj_id'     => $qsg_id,
158
-                'noheader'   => true,
159
-            ],
160
-
161
-            'insert_question_group' => [
162
-                'func'       => [$this, '_insert_or_update_question_group'],
163
-                'args'       => ['new_question_group' => true],
164
-                'capability' => 'ee_edit_question_groups',
165
-                'noheader'   => true,
166
-            ],
167
-
168
-            'update_question_group' => [
169
-                'func'       => [$this, '_insert_or_update_question_group'],
170
-                'args'       => ['new_question_group' => false],
171
-                'capability' => 'ee_edit_question_group',
172
-                'obj_id'     => $qsg_id,
173
-                'noheader'   => true,
174
-            ],
175
-
176
-            'trash_question_groups' => [
177
-                'func'       => [$this, '_trash_or_restore_question_groups'],
178
-                'args'       => ['trash' => true],
179
-                'capability' => 'ee_delete_question_groups',
180
-                'noheader'   => ['trash' => false],
181
-            ],
182
-
183
-            'restore_question_groups' => [
184
-                'func'       => [$this, '_trash_or_restore_question_groups'],
185
-                'args'       => ['trash' => false],
186
-                'capability' => 'ee_delete_question_groups',
187
-                'noheader'   => true,
188
-            ],
189
-
190
-
191
-            'espresso_update_question_group_order' => [
192
-                'func'       => [$this, 'update_question_group_order'],
193
-                'capability' => 'ee_edit_question_groups',
194
-                'noheader'   => true,
195
-            ],
196
-
197
-            'view_reg_form_settings' => [
198
-                'func'       => [$this, '_reg_form_settings'],
199
-                'capability' => 'manage_options',
200
-            ],
201
-
202
-            'update_reg_form_settings' => [
203
-                'func'       => [$this, '_update_reg_form_settings'],
204
-                'capability' => 'manage_options',
205
-                'noheader'   => true,
206
-            ],
207
-        ];
208
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
209
-
210
-        $new_page_config    = [
211
-
212
-            'question_groups' => [
213
-                'nav'           => [
214
-                    'label' => esc_html__('Question Groups', 'event_espresso'),
215
-                    'icon'  => 'dashicons-forms',
216
-                    'order' => 20,
217
-                ],
218
-                'list_table'    => 'Registration_Form_Question_Groups_Admin_List_Table',
219
-                'help_tabs'     => [
220
-                    'registration_form_question_groups_help_tab'                           => [
221
-                        'title'    => esc_html__('Question Groups', 'event_espresso'),
222
-                        'filename' => 'registration_form_question_groups',
223
-                    ],
224
-                    'registration_form_question_groups_table_column_headings_help_tab'     => [
225
-                        'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'),
226
-                        'filename' => 'registration_form_question_groups_table_column_headings',
227
-                    ],
228
-                    'registration_form_question_groups_views_bulk_actions_search_help_tab' => [
229
-                        'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'),
230
-                        'filename' => 'registration_form_question_groups_views_bulk_actions_search',
231
-                    ],
232
-                ],
233
-                'metaboxes'     => $this->_default_espresso_metaboxes,
234
-                'require_nonce' => false,
235
-            ],
236
-
237
-            'add_question' => [
238
-                'nav'           => [
239
-                    'label'      => esc_html__('Add Question', 'event_espresso'),
240
-                    'icon'       => 'dashicons-plus-alt',
241
-                    'order'      => 15,
242
-                    'persistent' => false,
243
-                ],
244
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
245
-                'help_tabs'     => [
246
-                    'registration_form_add_question_help_tab' => [
247
-                        'title'    => esc_html__('Add Question', 'event_espresso'),
248
-                        'filename' => 'registration_form_add_question',
249
-                    ],
250
-                ],
251
-                'require_nonce' => false,
252
-            ],
253
-
254
-            'add_question_group' => [
255
-                'nav'           => [
256
-                    'label'      => esc_html__('Add Question Group', 'event_espresso'),
257
-                    'icon'       => 'dashicons-plus-alt',
258
-                    'order'      => 25,
259
-                    'persistent' => false,
260
-                ],
261
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
262
-                'help_tabs'     => [
263
-                    'registration_form_add_question_group_help_tab' => [
264
-                        'title'    => esc_html__('Add Question Group', 'event_espresso'),
265
-                        'filename' => 'registration_form_add_question_group',
266
-                    ],
267
-                ],
268
-                'require_nonce' => false,
269
-            ],
270
-
271
-            'edit_question_group' => [
272
-                'nav'           => [
273
-                    'label'      => esc_html__('Edit Question Group', 'event_espresso'),
274
-                    'icon'       => 'dashicons-edit-large',
275
-                    'order'      => 25,
276
-                    'persistent' => false,
277
-                    'url'        => isset($this->_req_data['question_group_id']) ? add_query_arg(
278
-                        ['question_group_id' => $this->_req_data['question_group_id']],
279
-                        $this->_current_page_view_url
280
-                    ) : $this->_admin_base_url,
281
-                ],
282
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
283
-                'help_tabs'     => [
284
-                    'registration_form_edit_question_group_help_tab' => [
285
-                        'title'    => esc_html__('Edit Question Group', 'event_espresso'),
286
-                        'filename' => 'registration_form_edit_question_group',
287
-                    ],
288
-                ],
289
-                'require_nonce' => false,
290
-            ],
291
-
292
-            'view_reg_form_settings' => [
293
-                'nav'           => [
294
-                    'label' => esc_html__('Reg Form Settings', 'event_espresso'),
295
-                    'icon'  => 'dashicons-admin-generic',
296
-                    'order' => 40,
297
-                ],
298
-                'labels'        => [
299
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
300
-                ],
301
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
302
-                'help_tabs'     => [
303
-                    'registration_form_reg_form_settings_help_tab' => [
304
-                        'title'    => esc_html__('Registration Form Settings', 'event_espresso'),
305
-                        'filename' => 'registration_form_reg_form_settings',
306
-                    ],
307
-                ],
308
-                'require_nonce' => false,
309
-            ],
310
-
311
-        ];
312
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
313
-
314
-        // change the list table we're going to use so it's the NEW list table!
315
-        $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';
316
-
317
-
318
-        // additional labels
319
-        $new_labels               = [
320
-            'add_question'          => esc_html__('Add New Question', 'event_espresso'),
321
-            'delete_question'       => esc_html__('Delete Question', 'event_espresso'),
322
-            'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'),
323
-            'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'),
324
-            'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'),
325
-        ];
326
-        $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);
327
-    }
328
-
329
-
330
-    /**
331
-     * @return void
332
-     */
333
-    protected function _ajax_hooks()
334
-    {
335
-        if (! $this->capabilities->current_user_can('ee_edit_question_groups', 'edit-questions')) {
336
-            return;
337
-        }
338
-        add_action('wp_ajax_espresso_update_question_group_order', [$this, 'update_question_group_order']);
339
-    }
340
-
341
-
342
-    /**
343
-     * @return void
344
-     */
345
-    public function load_scripts_styles_question_groups()
346
-    {
347
-        wp_enqueue_script('espresso_ajax_table_sorting');
348
-    }
349
-
350
-
351
-    /**
352
-     * @return void
353
-     */
354
-    public function load_scripts_styles_add_question_group()
355
-    {
356
-        $this->load_scripts_styles_forms();
357
-        $this->load_sortable_question_script();
358
-    }
359
-
360
-
361
-    /**
362
-     * @return void
363
-     */
364
-    public function load_scripts_styles_edit_question_group()
365
-    {
366
-        $this->load_scripts_styles_forms();
367
-        $this->load_sortable_question_script();
368
-    }
369
-
370
-
371
-    /**
372
-     * registers and enqueues script for questions
373
-     *
374
-     * @return void
375
-     */
376
-    public function load_sortable_question_script()
377
-    {
378
-        wp_register_script(
379
-            'ee-question-sortable',
380
-            REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
381
-            ['jquery-ui-sortable'],
382
-            EVENT_ESPRESSO_VERSION,
383
-            true
384
-        );
385
-        wp_enqueue_script('ee-question-sortable');
386
-    }
387
-
388
-
389
-    /**
390
-     * @return void
391
-     */
392
-    protected function _set_list_table_views_default()
393
-    {
394
-        $this->_views = [
395
-            'all' => [
396
-                'slug'        => 'all',
397
-                'label'       => esc_html__('View All Questions', 'event_espresso'),
398
-                'count'       => 0,
399
-                'bulk_action' => [
400
-                    'trash_questions' => esc_html__('Trash', 'event_espresso'),
401
-                ],
402
-            ],
403
-        ];
404
-
405
-        if (
406
-            EE_Registry::instance()->CAP->current_user_can(
407
-                'ee_delete_questions',
408
-                'espresso_registration_form_trash_questions'
409
-            )
410
-        ) {
411
-            $this->_views['trash'] = [
412
-                'slug'        => 'trash',
413
-                'label'       => esc_html__('Trash', 'event_espresso'),
414
-                'count'       => 0,
415
-                'bulk_action' => [
416
-                    'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'),
417
-                    'restore_questions' => esc_html__('Restore', 'event_espresso'),
418
-                ],
419
-            ];
420
-        }
421
-    }
422
-
423
-
424
-    /**
425
-     * @return void
426
-     */
427
-    protected function _set_list_table_views_question_groups()
428
-    {
429
-        $this->_views = [
430
-            'all' => [
431
-                'slug'        => 'all',
432
-                'label'       => esc_html__('All', 'event_espresso'),
433
-                'count'       => 0,
434
-                'bulk_action' => [
435
-                    'trash_question_groups' => esc_html__('Trash', 'event_espresso'),
436
-                ],
437
-            ],
438
-        ];
439
-
440
-        if (
441
-            EE_Registry::instance()->CAP->current_user_can(
442
-                'ee_delete_question_groups',
443
-                'espresso_registration_form_trash_question_groups'
444
-            )
445
-        ) {
446
-            $this->_views['trash'] = [
447
-                'slug'        => 'trash',
448
-                'label'       => esc_html__('Trash', 'event_espresso'),
449
-                'count'       => 0,
450
-                'bulk_action' => [
451
-                    'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'),
452
-                    'restore_question_groups' => esc_html__('Restore', 'event_espresso'),
453
-                ],
454
-            ];
455
-        }
456
-    }
457
-
458
-
459
-    /**
460
-     * @return void
461
-     * @throws EE_Error
462
-     * @throws InvalidArgumentException
463
-     * @throws InvalidDataTypeException
464
-     * @throws InvalidInterfaceException
465
-     */
466
-    protected function _questions_overview_list_table()
467
-    {
468
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
469
-            'add_question',
470
-            'add_question',
471
-            [],
472
-            'add-new-h2'
473
-        );
474
-        parent::_questions_overview_list_table();
475
-    }
476
-
477
-
478
-    /**
479
-     * @return void
480
-     * @throws DomainException
481
-     * @throws EE_Error
482
-     * @throws InvalidArgumentException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     */
486
-    protected function _question_groups_overview_list_table()
487
-    {
488
-        $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
489
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
490
-            'add_question_group',
491
-            'add_question_group',
492
-            [],
493
-            'add-new-h2'
494
-        );
495
-        $this->display_admin_list_table_page_with_sidebar();
496
-    }
497
-
498
-
499
-    /**
500
-     * @return void
501
-     * @throws EE_Error
502
-     * @throws InvalidArgumentException
503
-     * @throws InvalidDataTypeException
504
-     * @throws InvalidInterfaceException
505
-     * @throws ReflectionException
506
-     */
507
-    protected function _delete_question()
508
-    {
509
-        $success = $this->_delete_items($this->_question_model);
510
-        $this->_redirect_after_action(
511
-            $success,
512
-            $this->_question_model->item_name($success),
513
-            'deleted',
514
-            ['action' => 'default', 'status' => 'all']
515
-        );
516
-    }
517
-
518
-
519
-    /**
520
-     * @return void
521
-     * @throws EE_Error
522
-     * @throws InvalidArgumentException
523
-     * @throws InvalidDataTypeException
524
-     * @throws InvalidInterfaceException
525
-     * @throws ReflectionException
526
-     */
527
-    protected function _delete_questions()
528
-    {
529
-        $success = $this->_delete_items($this->_question_model);
530
-        $this->_redirect_after_action(
531
-            $success,
532
-            $this->_question_model->item_name($success),
533
-            'deleted permanently',
534
-            ['action' => 'default', 'status' => 'trash']
535
-        );
536
-    }
537
-
538
-
539
-    /**
540
-     * Performs the deletion of a single or multiple questions or question groups.
541
-     *
542
-     * @param EEM_Soft_Delete_Base $model
543
-     * @return int number of items deleted permanently
544
-     * @throws EE_Error
545
-     * @throws InvalidArgumentException
546
-     * @throws InvalidDataTypeException
547
-     * @throws InvalidInterfaceException
548
-     * @throws ReflectionException
549
-     */
550
-    private function _delete_items(EEM_Soft_Delete_Base $model)
551
-    {
552
-        $success = 0;
553
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
554
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
555
-            // if array has more than one element than success message should be plural
556
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
557
-            // cycle thru bulk action checkboxes
558
-            $checkboxes = $this->_req_data['checkbox'];
559
-            foreach (array_keys($checkboxes) as $ID) {
560
-                if (! $this->_delete_item($ID, $model)) {
561
-                    $success = 0;
562
-                }
563
-            }
564
-        } elseif (! empty($this->_req_data['QSG_ID'])) {
565
-            $success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
566
-        } elseif (! empty($this->_req_data['QST_ID'])) {
567
-            $success = $this->_delete_item($this->_req_data['QST_ID'], $model);
568
-        } else {
569
-            EE_Error::add_error(
570
-                sprintf(
571
-                    esc_html__(
572
-                        "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",
573
-                        "event_espresso"
574
-                    )
575
-                ),
576
-                __FILE__,
577
-                __FUNCTION__,
578
-                __LINE__
579
-            );
580
-        }
581
-        return $success;
582
-    }
583
-
584
-
585
-    /**
586
-     * Deletes the specified question (and its associated question options) or question group
587
-     *
588
-     * @param int                  $id
589
-     * @param EEM_Soft_Delete_Base $model
590
-     * @return boolean
591
-     * @throws EE_Error
592
-     * @throws InvalidArgumentException
593
-     * @throws InvalidDataTypeException
594
-     * @throws InvalidInterfaceException
595
-     * @throws ReflectionException
596
-     */
597
-    protected function _delete_item($id, $model)
598
-    {
599
-        if ($model instanceof EEM_Question) {
600
-            EEM_Question_Option::instance()->delete_permanently([['QST_ID' => absint($id)]]);
601
-        }
602
-        return $model->delete_permanently_by_ID(absint($id));
603
-    }
604
-
605
-
606
-    /******************************    QUESTION GROUPS    ******************************/
607
-
608
-
609
-    /**
610
-     * @param string $type
611
-     * @return void
612
-     * @throws DomainException
613
-     * @throws EE_Error
614
-     * @throws InvalidArgumentException
615
-     * @throws InvalidDataTypeException
616
-     * @throws InvalidInterfaceException
617
-     * @throws ReflectionException
618
-     */
619
-    protected function _edit_question_group($type = 'add')
620
-    {
621
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
622
-        $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID'])
623
-            ? absint($this->_req_data['QSG_ID'])
624
-            : false;
625
-
626
-        switch ($this->_req_action) {
627
-            case 'add_question_group':
628
-                $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso');
629
-                break;
630
-            case 'edit_question_group':
631
-                $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso');
632
-                break;
633
-            default:
634
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
635
-        }
636
-        // add ID to title if editing
637
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
638
-        if ($ID) {
639
-            /** @var EE_Question_Group $questionGroup */
640
-            $questionGroup            = $this->_question_group_model->get_one_by_ID($ID);
641
-            $additional_hidden_fields = ['QSG_ID' => ['type' => 'hidden', 'value' => $ID]];
642
-            $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields);
643
-        } else {
644
-            /** @var EE_Question_Group $questionGroup */
645
-            $questionGroup = EEM_Question_Group::instance()->create_default_object();
646
-            $questionGroup->set_order_to_latest();
647
-            $this->_set_add_edit_form_tags('insert_question_group');
648
-        }
649
-        $this->_template_args['values']         = $this->_yes_no_values;
650
-        $this->_template_args['all_questions']  = $questionGroup->questions_in_and_not_in_group();
651
-        $this->_template_args['QSG_ID']         = $ID ? $ID : true;
652
-        $this->_template_args['question_group'] = $questionGroup;
653
-
654
-        $redirect_URL = add_query_arg(['action' => 'question_groups'], $this->_admin_base_url);
655
-        $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL, true);
656
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
657
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
658
-            $this->_template_args,
659
-            true
660
-        );
661
-
662
-        // the details template wrapper
663
-        $this->display_admin_page_with_sidebar();
664
-    }
665
-
666
-
667
-    /**
668
-     * @return void
669
-     * @throws EE_Error
670
-     * @throws InvalidArgumentException
671
-     * @throws InvalidDataTypeException
672
-     * @throws InvalidInterfaceException
673
-     * @throws ReflectionException
674
-     */
675
-    protected function _delete_question_groups()
676
-    {
677
-        $success = $this->_delete_items($this->_question_group_model);
678
-        $this->_redirect_after_action(
679
-            $success,
680
-            $this->_question_group_model->item_name($success),
681
-            'deleted permanently',
682
-            ['action' => 'question_groups', 'status' => 'trash']
683
-        );
684
-    }
685
-
686
-
687
-    /**
688
-     * @param bool $new_question_group
689
-     * @throws EE_Error
690
-     * @throws InvalidArgumentException
691
-     * @throws InvalidDataTypeException
692
-     * @throws InvalidInterfaceException
693
-     * @throws ReflectionException
694
-     */
695
-    protected function _insert_or_update_question_group($new_question_group = true)
696
-    {
697
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
698
-        $set_column_values = $this->_set_column_values_for($this->_question_group_model);
699
-
700
-        // make sure identifier is unique
701
-        $identifier_value = $set_column_values['QSG_identifier'] ?? '';
702
-        $where_values     = ['QSG_identifier' => $identifier_value];
703
-        if (! $new_question_group && isset($set_column_values['QSG_ID'])) {
704
-            $where_values['QSG_ID'] = ['!=', $set_column_values['QSG_ID']];
705
-        }
706
-        $identifier_exists = ! empty($identifier_value) && $this->_question_group_model->count([$where_values]) > 0;
707
-        if ($identifier_exists) {
708
-            $set_column_values['QSG_identifier'] .= uniqid('id', true);
709
-        }
710
-
711
-        if ($new_question_group) {
712
-            $QSG_ID  = $this->_question_group_model->insert($set_column_values);
713
-            $success = $QSG_ID ? 1 : 0;
714
-            if ($success === 0) {
715
-                EE_Error::add_error(
716
-                    esc_html__('Something went wrong saving the question group.', 'event_espresso'),
717
-                    __FILE__,
718
-                    __FUNCTION__,
719
-                    __LINE__
720
-                );
721
-                $this->_redirect_after_action(
722
-                    false,
723
-                    '',
724
-                    '',
725
-                    ['action' => 'edit_question_group', 'QSG_ID' => $QSG_ID],
726
-                    true
727
-                );
728
-            }
729
-        } else {
730
-            $QSG_ID = absint($this->_req_data['QSG_ID']);
731
-            unset($set_column_values['QSG_ID']);
732
-            $success = $this->_question_group_model->update($set_column_values, [['QSG_ID' => $QSG_ID]]);
733
-        }
734
-
735
-        $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
736
-            EEM_Attendee::system_question_phone
737
-        );
738
-        // update the existing related questions
739
-        // BUT FIRST...  delete the phone question from the Question_Group_Question
740
-        // if it is being added to this question group (therefore removed from the existing group)
741
-        if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) {
742
-            // delete where QST ID = system phone question ID and Question Group ID is NOT this group
743
-            EEM_Question_Group_Question::instance()->delete(
744
-                [
745
-                    [
746
-                        'QST_ID' => $phone_question_id,
747
-                        'QSG_ID' => ['!=', $QSG_ID],
748
-                    ],
749
-                ]
750
-            );
751
-        }
752
-        /** @type EE_Question_Group $question_group */
753
-        $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
754
-        $questions      = $question_group->questions();
755
-        // make sure system phone question is added to list of questions for this group
756
-        if (! isset($questions[ $phone_question_id ])) {
757
-            $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
758
-        }
759
-
760
-        foreach ($questions as $question_ID => $question) {
761
-            // first we always check for order.
762
-            if (! empty($this->_req_data['question_orders'][ $question_ID ])) {
763
-                // update question order
764
-                $question_group->update_question_order(
765
-                    $question_ID,
766
-                    $this->_req_data['question_orders'][ $question_ID ]
767
-                );
768
-            }
769
-
770
-            // then we always check if adding or removing.
771
-            if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) {
772
-                $question_group->add_question($question_ID);
773
-            } else {
774
-                // not found, remove it (but only if not a system question for the personal group
775
-                // with the exception of lname system question - we allow removal of it)
776
-                if (
777
-                    in_array(
778
-                        $question->system_ID(),
779
-                        EEM_Question::instance()->required_system_questions_in_system_question_group(
780
-                            $question_group->system_group()
781
-                        )
782
-                    )
783
-                ) {
784
-                    continue;
785
-                } else {
786
-                    $question_group->remove_question($question_ID);
787
-                }
788
-            }
789
-        }
790
-        // save new related questions
791
-        if (isset($this->_req_data['questions'])) {
792
-            foreach ($this->_req_data['questions'] as $QST_ID) {
793
-                $question_group->add_question($QST_ID);
794
-                if (isset($this->_req_data['question_orders'][ $QST_ID ])) {
795
-                    $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);
796
-                }
797
-            }
798
-        }
799
-
800
-        if ($success !== false) {
801
-            $msg = $new_question_group
802
-                ? sprintf(
803
-                    esc_html__('The %s has been created', 'event_espresso'),
804
-                    $this->_question_group_model->item_name()
805
-                )
806
-                : sprintf(
807
-                    esc_html__(
808
-                        'The %s has been updated',
809
-                        'event_espresso'
810
-                    ),
811
-                    $this->_question_group_model->item_name()
812
-                );
813
-            EE_Error::add_success($msg);
814
-        }
815
-        $this->_redirect_after_action(
816
-            false,
817
-            '',
818
-            '',
819
-            ['action' => 'edit_question_group', 'QSG_ID' => $QSG_ID],
820
-            true
821
-        );
822
-    }
823
-
824
-
825
-    /**
826
-     * duplicates a question and all its question options and redirects to the new question.
827
-     *
828
-     * @return void
829
-     * @throws EE_Error
830
-     * @throws InvalidArgumentException
831
-     * @throws ReflectionException
832
-     * @throws InvalidDataTypeException
833
-     * @throws InvalidInterfaceException
834
-     */
835
-    public function _duplicate_question()
836
-    {
837
-        $question_ID = (int) $this->_req_data['QST_ID'];
838
-        $question    = EEM_Question::instance()->get_one_by_ID($question_ID);
839
-        if ($question instanceof EE_Question) {
840
-            $new_question = $question->duplicate();
841
-            if ($new_question instanceof EE_Question) {
842
-                $this->_redirect_after_action(
843
-                    true,
844
-                    esc_html__('Question', 'event_espresso'),
845
-                    esc_html__('Duplicated', 'event_espresso'),
846
-                    ['action' => 'edit_question', 'QST_ID' => $new_question->ID()],
847
-                    true
848
-                );
849
-            } else {
850
-                global $wpdb;
851
-                EE_Error::add_error(
852
-                    sprintf(
853
-                        esc_html__(
854
-                            'Could not duplicate question with ID %1$d because: %2$s',
855
-                            'event_espresso'
856
-                        ),
857
-                        $question_ID,
858
-                        $wpdb->last_error
859
-                    ),
860
-                    __FILE__,
861
-                    __FUNCTION__,
862
-                    __LINE__
863
-                );
864
-                $this->_redirect_after_action(false, '', '', ['action' => 'default'], false);
865
-            }
866
-        } else {
867
-            EE_Error::add_error(
868
-                sprintf(
869
-                    esc_html__(
870
-                        'Could not duplicate question with ID %d because it didn\'t exist!',
871
-                        'event_espresso'
872
-                    ),
873
-                    $question_ID
874
-                ),
875
-                __FILE__,
876
-                __FUNCTION__,
877
-                __LINE__
878
-            );
879
-            $this->_redirect_after_action(false, '', '', ['action' => 'default'], false);
880
-        }
881
-    }
882
-
883
-
884
-    /**
885
-     * @param bool $trash
886
-     * @throws EE_Error
887
-     */
888
-    protected function _trash_or_restore_question_groups($trash = true)
889
-    {
890
-        $this->_trash_or_restore_items($this->_question_group_model, $trash);
891
-    }
892
-
893
-
894
-    /**
895
-     *_trash_question
896
-     *
897
-     * @return void
898
-     * @throws EE_Error
899
-     */
900
-    protected function _trash_question()
901
-    {
902
-        $success    = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']);
903
-        $query_args = ['action' => 'default', 'status' => 'all'];
904
-        $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);
905
-    }
906
-
907
-
908
-    /**
909
-     * @param bool $trash
910
-     * @throws EE_Error
911
-     */
912
-    protected function _trash_or_restore_questions($trash = true)
913
-    {
914
-        $this->_trash_or_restore_items($this->_question_model, $trash);
915
-    }
916
-
917
-
918
-    /**
919
-     * Internally used to delete or restore items, using the request data. Meant to be
920
-     * flexible between question or question groups
921
-     *
922
-     * @param EEM_Soft_Delete_Base $model
923
-     * @param boolean              $trash whether to trash or restore
924
-     * @throws EE_Error
925
-     */
926
-    private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)
927
-    {
928
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
929
-
930
-        $success = 1;
931
-        // Checkboxes
932
-        // echo "trash $trash";
933
-        // var_dump($this->_req_data['checkbox']);die;
934
-        if (isset($this->_req_data['checkbox'])) {
935
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
936
-                // if array has more than one element than success message should be plural
937
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
938
-                // cycle thru bulk action checkboxes
939
-                $checkboxes = $this->_req_data['checkbox'];
940
-                foreach (array_keys($checkboxes) as $ID) {
941
-                    if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
942
-                        $success = 0;
943
-                    }
944
-                }
945
-            } else {
946
-                // grab single id and delete
947
-                $ID = absint($this->_req_data['checkbox']);
948
-                if (! $model->delete_or_restore_by_ID($trash, $ID)) {
949
-                    $success = 0;
950
-                }
951
-            }
952
-        } else {
953
-            // delete via trash link
954
-            // grab single id and delete
955
-            $ID = absint($this->_req_data[ $model->primary_key_name() ]);
956
-            if (! $model->delete_or_restore_by_ID($trash, $ID)) {
957
-                $success = 0;
958
-            }
959
-        }
960
-
961
-
962
-        $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );
963
-        // echo "action :$action";
964
-        // $action = 'questions' ? 'default' : $action;
965
-        if ($trash) {
966
-            $action_desc = 'trashed';
967
-            $status      = 'trash';
968
-        } else {
969
-            $action_desc = 'restored';
970
-            $status      = 'all';
971
-        }
972
-        $this->_redirect_after_action(
973
-            $success,
974
-            $model->item_name($success),
975
-            $action_desc,
976
-            ['action' => $action, 'status' => $status]
977
-        );
978
-    }
979
-
980
-
981
-    /**
982
-     * @param            $per_page
983
-     * @param int        $current_page
984
-     * @param bool|false $count
985
-     * @return EE_Soft_Delete_Base_Class[]|int
986
-     * @throws EE_Error
987
-     * @throws InvalidArgumentException
988
-     * @throws InvalidDataTypeException
989
-     * @throws InvalidInterfaceException
990
-     * @throws ReflectionException
991
-     */
992
-    public function get_trashed_questions($per_page, $current_page = 1, $count = false)
993
-    {
994
-        $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
995
-
996
-        if ($count) {
997
-            // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
998
-            $where   = isset($query_params[0]) ? [$query_params[0]] : [];
999
-            $results = $this->_question_model->count_deleted($where);
1000
-        } else {
1001
-            // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
1002
-            $results = $this->_question_model->get_all_deleted($query_params);
1003
-        }
1004
-        return $results;
1005
-    }
1006
-
1007
-
1008
-    /**
1009
-     * @param            $per_page
1010
-     * @param int        $current_page
1011
-     * @param bool|false $count
1012
-     * @return EE_Soft_Delete_Base_Class[]|int
1013
-     * @throws EE_Error
1014
-     * @throws InvalidArgumentException
1015
-     * @throws InvalidDataTypeException
1016
-     * @throws InvalidInterfaceException
1017
-     * @throws ReflectionException
1018
-     */
1019
-    public function get_question_groups($per_page, $current_page = 1, $count = false)
1020
-    {
1021
-        $questionGroupModel = EEM_Question_Group::instance();
1022
-        $query_params       = $this->get_query_params($questionGroupModel, $per_page, $current_page);
1023
-        if ($count) {
1024
-            $where   = isset($query_params[0]) ? [$query_params[0]] : [];
1025
-            $results = $questionGroupModel->count($where);
1026
-        } else {
1027
-            $results = $questionGroupModel->get_all($query_params);
1028
-        }
1029
-        return $results;
1030
-    }
1031
-
1032
-
1033
-    /**
1034
-     * @param      $per_page
1035
-     * @param int  $current_page
1036
-     * @param bool $count
1037
-     * @return EE_Soft_Delete_Base_Class[]|int
1038
-     * @throws EE_Error
1039
-     * @throws InvalidArgumentException
1040
-     * @throws InvalidDataTypeException
1041
-     * @throws InvalidInterfaceException
1042
-     * @throws ReflectionException
1043
-     */
1044
-    public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)
1045
-    {
1046
-        $questionGroupModel = EEM_Question_Group::instance();
1047
-        $query_params       = $this->get_query_params($questionGroupModel, $per_page, $current_page);
1048
-        if ($count) {
1049
-            $where                 = isset($query_params[0]) ? [$query_params[0]] : [];
1050
-            $query_params['limit'] = null;
1051
-            $results               = $questionGroupModel->count_deleted($where);
1052
-        } else {
1053
-            $results = $questionGroupModel->get_all_deleted($query_params);
1054
-        }
1055
-        return $results;
1056
-    }
1057
-
1058
-
1059
-    /**
1060
-     * method for performing updates to question order
1061
-     *
1062
-     * @return void results array
1063
-     * @throws EE_Error
1064
-     * @throws InvalidArgumentException
1065
-     * @throws InvalidDataTypeException
1066
-     * @throws InvalidInterfaceException
1067
-     * @throws ReflectionException
1068
-     */
1069
-    public function update_question_group_order()
1070
-    {
1071
-        if (! $this->capabilities->current_user_can('ee_edit_question_groups', __FUNCTION__)) {
1072
-            wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
1073
-        }
1074
-        $success = esc_html__('Question group order was updated successfully.', 'event_espresso');
1075
-
1076
-        // grab our row IDs
1077
-        $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])
1078
-            ? explode(',', rtrim($this->_req_data['row_ids'], ','))
1079
-            : [];
1080
-
1081
-        $perpage = ! empty($this->_req_data['perpage'])
1082
-            ? (int) $this->_req_data['perpage']
1083
-            : null;
1084
-        $curpage = ! empty($this->_req_data['curpage'])
1085
-            ? (int) $this->_req_data['curpage']
1086
-            : null;
1087
-
1088
-        if (! empty($row_ids)) {
1089
-            // figure out where we start the row_id count at for the current page.
1090
-            $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
1091
-
1092
-            $row_count = count($row_ids);
1093
-            for ($i = 0; $i < $row_count; $i++) {
1094
-                // Update the questions when re-ordering
1095
-                $updated = EEM_Question_Group::instance()->update(
1096
-                    ['QSG_order' => $qsgcount],
1097
-                    [['QSG_ID' => $row_ids[ $i ]]]
1098
-                );
1099
-                if ($updated === false) {
1100
-                    $success = false;
1101
-                }
1102
-                $qsgcount++;
1103
-            }
1104
-        } else {
1105
-            $success = false;
1106
-        }
1107
-
1108
-        $errors = ! $success
1109
-            ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso')
1110
-            : false;
1111
-
1112
-        echo wp_json_encode(['return_data' => false, 'success' => $success, 'errors' => $errors]);
1113
-        die();
1114
-    }
1115
-
1116
-
1117
-
1118
-    /***************************************       REGISTRATION SETTINGS       ***************************************/
1119
-
1120
-
1121
-    /**
1122
-     * @throws DomainException
1123
-     * @throws EE_Error
1124
-     * @throws InvalidArgumentException
1125
-     * @throws InvalidDataTypeException
1126
-     * @throws InvalidInterfaceException
1127
-     */
1128
-    protected function _reg_form_settings()
1129
-    {
1130
-        $this->_template_args['values'] = $this->_yes_no_values;
1131
-        add_action(
1132
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1133
-            [$this, 'email_validation_settings_form'],
1134
-            2
1135
-        );
1136
-        add_action(
1137
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1138
-            [$this, 'copy_attendee_info_settings_form'],
1139
-            4
1140
-        );
1141
-        add_action(
1142
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1143
-            [$this, 'setSessionLifespan'],
1144
-            5
1145
-        );
1146
-        $this->_template_args = (array) apply_filters(
1147
-            'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',
1148
-            $this->_template_args
1149
-        );
1150
-        $this->_set_add_edit_form_tags('update_reg_form_settings');
1151
-        $this->_set_publish_post_box_vars();
1152
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1153
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
1154
-            $this->_template_args,
1155
-            true
1156
-        );
1157
-        $this->display_admin_page_with_sidebar();
1158
-    }
1159
-
1160
-
1161
-    /**
1162
-     * @return void
1163
-     * @throws EE_Error
1164
-     * @throws InvalidArgumentException
1165
-     * @throws ReflectionException
1166
-     * @throws InvalidDataTypeException
1167
-     * @throws InvalidInterfaceException
1168
-     */
1169
-    protected function _update_reg_form_settings()
1170
-    {
1171
-        EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(
1172
-            EE_Registry::instance()->CFG->registration
1173
-        );
1174
-        EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form(
1175
-            EE_Registry::instance()->CFG->registration
1176
-        );
1177
-        $this->updateSessionLifespan();
1178
-        EE_Registry::instance()->CFG->registration = apply_filters(
1179
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
1180
-            EE_Registry::instance()->CFG->registration
1181
-        );
1182
-        $success                                   = $this->_update_espresso_configuration(
1183
-            esc_html__('Registration Form Options', 'event_espresso'),
1184
-            EE_Registry::instance()->CFG,
1185
-            __FILE__,
1186
-            __FUNCTION__,
1187
-            __LINE__
1188
-        );
1189
-        $this->_redirect_after_action(
1190
-            $success,
1191
-            esc_html__('Registration Form Options', 'event_espresso'),
1192
-            'updated',
1193
-            ['action' => 'view_reg_form_settings']
1194
-        );
1195
-    }
1196
-
1197
-
1198
-    /**
1199
-     * @return void
1200
-     * @throws EE_Error
1201
-     * @throws InvalidArgumentException
1202
-     * @throws InvalidDataTypeException
1203
-     * @throws InvalidInterfaceException
1204
-     */
1205
-    public function copy_attendee_info_settings_form()
1206
-    {
1207
-        echo wp_kses($this->_copy_attendee_info_settings_form()->get_html(), AllowedTags::getWithFormTags());
1208
-    }
1209
-
1210
-
1211
-    /**
1212
-     * _copy_attendee_info_settings_form
1213
-     *
1214
-     * @access protected
1215
-     * @return EE_Form_Section_Proper
1216
-     * @throws \EE_Error
1217
-     */
1218
-    protected function _copy_attendee_info_settings_form()
1219
-    {
1220
-        return new EE_Form_Section_Proper(
1221
-            [
1222
-                'name'            => 'copy_attendee_info_settings',
1223
-                'html_id'         => 'copy_attendee_info_settings',
1224
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1225
-                'subsections'     => apply_filters(
1226
-                    'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections',
1227
-                    [
1228
-                        'copy_attendee_info_hdr' => new EE_Form_Section_HTML(
1229
-                            EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso'))
1230
-                        ),
1231
-                        'copy_attendee_info'     => new EE_Yes_No_Input(
1232
-                            [
1233
-                                'html_label_text'         => esc_html__(
1234
-                                    'Allow copy #1 attendee info to extra attendees?',
1235
-                                    'event_espresso'
1236
-                                ),
1237
-                                'html_help_text'          => esc_html__(
1238
-                                    'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.',
1239
-                                    'event_espresso'
1240
-                                ),
1241
-                                'default'                 => EE_Registry::instance(
1242
-                                )->CFG->registration->copyAttendeeInfo(),
1243
-                                'required'                => false,
1244
-                                'display_html_label_text' => false,
1245
-                            ]
1246
-                        ),
1247
-                    ]
1248
-                ),
1249
-            ]
1250
-        );
1251
-    }
1252
-
1253
-
1254
-    /**
1255
-     * @param EE_Registration_Config $EE_Registration_Config
1256
-     * @return EE_Registration_Config
1257
-     * @throws EE_Error
1258
-     * @throws InvalidArgumentException
1259
-     * @throws ReflectionException
1260
-     * @throws InvalidDataTypeException
1261
-     * @throws InvalidInterfaceException
1262
-     */
1263
-    public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config)
1264
-    {
1265
-        $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo();
1266
-        try {
1267
-            $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form();
1268
-            // if not displaying a form, then check for form submission
1269
-            if ($copy_attendee_info_settings_form->was_submitted()) {
1270
-                // capture form data
1271
-                $copy_attendee_info_settings_form->receive_form_submission();
1272
-                // validate form data
1273
-                if ($copy_attendee_info_settings_form->is_valid()) {
1274
-                    // grab validated data from form
1275
-                    $valid_data = $copy_attendee_info_settings_form->valid_data();
1276
-                    if (isset($valid_data['copy_attendee_info'])) {
1277
-                        $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']);
1278
-                    } else {
1279
-                        EE_Error::add_error(
1280
-                            esc_html__(
1281
-                                'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.',
1282
-                                'event_espresso'
1283
-                            ),
1284
-                            __FILE__,
1285
-                            __FUNCTION__,
1286
-                            __LINE__
1287
-                        );
1288
-                    }
1289
-                } elseif ($copy_attendee_info_settings_form->submission_error_message() !== '') {
1290
-                    EE_Error::add_error(
1291
-                        $copy_attendee_info_settings_form->submission_error_message(),
1292
-                        __FILE__,
1293
-                        __FUNCTION__,
1294
-                        __LINE__
1295
-                    );
1296
-                }
1297
-            }
1298
-        } catch (EE_Error $e) {
1299
-            $e->get_error();
1300
-        }
1301
-        return $EE_Registration_Config;
1302
-    }
1303
-
1304
-
1305
-    /**
1306
-     * @return void
1307
-     * @throws EE_Error
1308
-     * @throws InvalidArgumentException
1309
-     * @throws InvalidDataTypeException
1310
-     * @throws InvalidInterfaceException
1311
-     */
1312
-    public function email_validation_settings_form()
1313
-    {
1314
-        echo wp_kses($this->_email_validation_settings_form()->get_html(), AllowedTags::getWithFormTags());
1315
-    }
1316
-
1317
-
1318
-    /**
1319
-     * _email_validation_settings_form
1320
-     *
1321
-     * @access protected
1322
-     * @return EE_Form_Section_Proper
1323
-     * @throws \EE_Error
1324
-     */
1325
-    protected function _email_validation_settings_form()
1326
-    {
1327
-        return new EE_Form_Section_Proper(
1328
-            [
1329
-                'name'            => 'email_validation_settings',
1330
-                'html_id'         => 'email_validation_settings',
1331
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1332
-                'subsections'     => apply_filters(
1333
-                    'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',
1334
-                    [
1335
-                        'email_validation_hdr'   => new EE_Form_Section_HTML(
1336
-                            EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso'))
1337
-                        ),
1338
-                        'email_validation_level' => new EE_Select_Input(
1339
-                            [
1340
-                                'basic'      => esc_html__('Basic', 'event_espresso'),
1341
-                                'wp_default' => esc_html__('WordPress Default', 'event_espresso'),
1342
-                                'i18n'       => esc_html__('International', 'event_espresso'),
1343
-                                'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'),
1344
-                            ],
1345
-                            [
1346
-                                'html_label_text' => esc_html__('Email Validation Level', 'event_espresso')
1347
-                                                     . EEH_Template::get_help_tab_link('email_validation_info'),
1348
-                                'html_help_text'  => esc_html__(
1349
-                                    'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',
1350
-                                    'event_espresso'
1351
-                                ),
1352
-                                'default'         => isset(
1353
-                                    EE_Registry::instance()->CFG->registration->email_validation_level
1354
-                                )
1355
-                                    ? EE_Registry::instance()->CFG->registration->email_validation_level
1356
-                                    : 'wp_default',
1357
-                                'required'        => false,
1358
-                            ]
1359
-                        ),
1360
-                    ]
1361
-                ),
1362
-            ]
1363
-        );
1364
-    }
1365
-
1366
-
1367
-    /**
1368
-     * @param EE_Registration_Config $EE_Registration_Config
1369
-     * @return EE_Registration_Config
1370
-     * @throws EE_Error
1371
-     * @throws InvalidArgumentException
1372
-     * @throws ReflectionException
1373
-     * @throws InvalidDataTypeException
1374
-     * @throws InvalidInterfaceException
1375
-     */
1376
-    public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)
1377
-    {
1378
-        $prev_email_validation_level = $EE_Registration_Config->email_validation_level;
1379
-        try {
1380
-            $email_validation_settings_form = $this->_email_validation_settings_form();
1381
-            // if not displaying a form, then check for form submission
1382
-            if ($email_validation_settings_form->was_submitted()) {
1383
-                // capture form data
1384
-                $email_validation_settings_form->receive_form_submission();
1385
-                // validate form data
1386
-                if ($email_validation_settings_form->is_valid()) {
1387
-                    // grab validated data from form
1388
-                    $valid_data = $email_validation_settings_form->valid_data();
1389
-                    if (isset($valid_data['email_validation_level'])) {
1390
-                        $email_validation_level = $valid_data['email_validation_level'];
1391
-                        // now if they want to use international email addresses
1392
-                        if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') {
1393
-                            // in case we need to reset their email validation level,
1394
-                            // make sure that the previous value wasn't already set to one of the i18n options.
1395
-                            if (
1396
-                                $prev_email_validation_level === 'i18n'
1397
-                                || $prev_email_validation_level
1398
-                                   === 'i18n_dns'
1399
-                            ) {
1400
-                                // if so, then reset it back to "basic" since that is the only other option that,
1401
-                                // despite offering poor validation, supports i18n email addresses
1402
-                                $prev_email_validation_level = 'basic';
1403
-                            }
1404
-                            // confirm our i18n email validation will work on the server
1405
-                            if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1406
-                                // or reset email validation level to previous value
1407
-                                $email_validation_level = $prev_email_validation_level;
1408
-                            }
1409
-                        }
1410
-                        $EE_Registration_Config->email_validation_level = $email_validation_level;
1411
-                    } else {
1412
-                        EE_Error::add_error(
1413
-                            esc_html__(
1414
-                                'Invalid or missing Email Validation settings. Please refresh the form and try again.',
1415
-                                'event_espresso'
1416
-                            ),
1417
-                            __FILE__,
1418
-                            __FUNCTION__,
1419
-                            __LINE__
1420
-                        );
1421
-                    }
1422
-                } elseif ($email_validation_settings_form->submission_error_message() !== '') {
1423
-                    EE_Error::add_error(
1424
-                        $email_validation_settings_form->submission_error_message(),
1425
-                        __FILE__,
1426
-                        __FUNCTION__,
1427
-                        __LINE__
1428
-                    );
1429
-                }
1430
-            }
1431
-        } catch (EE_Error $e) {
1432
-            $e->get_error();
1433
-        }
1434
-        return $EE_Registration_Config;
1435
-    }
1436
-
1437
-
1438
-    /**
1439
-     * confirms that the server's PHP version has the PCRE module enabled,
1440
-     * and that the PCRE version works with our i18n email validation
1441
-     *
1442
-     * @param EE_Registration_Config $EE_Registration_Config
1443
-     * @param string                 $email_validation_level
1444
-     * @return bool
1445
-     */
1446
-    private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1447
-    {
1448
-        // first check that PCRE is enabled
1449
-        if (! defined('PREG_BAD_UTF8_ERROR')) {
1450
-            EE_Error::add_error(
1451
-                sprintf(
1452
-                    esc_html__(
1453
-                        'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',
1454
-                        'event_espresso'
1455
-                    ),
1456
-                    '<br />'
1457
-                ),
1458
-                __FILE__,
1459
-                __FUNCTION__,
1460
-                __LINE__
1461
-            );
1462
-            return false;
1463
-        } else {
1464
-            // PCRE support is enabled, but let's still
1465
-            // perform a test to see if the server will support it.
1466
-            // but first, save the updated validation level to the config,
1467
-            // so that the validation strategy picks it up.
1468
-            // this will get bumped back down if it doesn't work
1469
-            $EE_Registration_Config->email_validation_level = $email_validation_level;
1470
-            try {
1471
-                $email_validator    = new EE_Email_Validation_Strategy();
1472
-                $i18n_email_address = apply_filters(
1473
-                    'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',
1474
-                    'jägerjü[email protected]'
1475
-                );
1476
-                $email_validator->validate($i18n_email_address);
1477
-            } catch (Exception $e) {
1478
-                EE_Error::add_error(
1479
-                    sprintf(
1480
-                        esc_html__(
1481
-                            'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',
1482
-                            'event_espresso'
1483
-                        ),
1484
-                        '<br />',
1485
-                        '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>'
1486
-                    ),
1487
-                    __FILE__,
1488
-                    __FUNCTION__,
1489
-                    __LINE__
1490
-                );
1491
-                return false;
1492
-            }
1493
-        }
1494
-        return true;
1495
-    }
1496
-
1497
-
1498
-    public function setSessionLifespan()
1499
-    {
1500
-        $session_lifespan_form = $this->loader->getNew(SessionLifespanForm::class);
1501
-        echo wp_kses($session_lifespan_form->get_html(), AllowedTags::getWithFormTags());
1502
-    }
1503
-
1504
-
1505
-    public function updateSessionLifespan()
1506
-    {
1507
-        $handler = $this->loader->getNew(SessionLifespanFormHandler::class);
1508
-        $handler->process($this->loader->getNew(SessionLifespanForm::class));
1509
-    }
19
+	/**
20
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
21
+	 * @throws EE_Error
22
+	 * @throws ReflectionException
23
+	 */
24
+	public function __construct($routing = true)
25
+	{
26
+		define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/');
27
+		define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/');
28
+		define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
29
+		define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/');
30
+		define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
31
+		parent::__construct($routing);
32
+	}
33
+
34
+
35
+	protected function _define_page_props()
36
+	{
37
+		parent::_define_page_props();
38
+		$this->_labels['publishbox'] = [
39
+			'add_question'        => esc_html__('Add New Question', 'event_espresso'),
40
+			'edit_question'       => esc_html__('Edit Question', 'event_espresso'),
41
+			'add_question_group'  => esc_html__('Add New Question Group', 'event_espresso'),
42
+			'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'),
43
+		];
44
+	}
45
+
46
+
47
+	protected function _set_page_config()
48
+	{
49
+		parent::_set_page_config();
50
+
51
+		$this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;
52
+		$qst_id                 = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID'])
53
+			? $this->_req_data['QST_ID'] : 0;
54
+		$qsg_id                 = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID'])
55
+			? $this->_req_data['QSG_ID'] : 0;
56
+
57
+		$new_page_routes    = [
58
+			'question_groups'    => [
59
+				'func'       => [$this, '_question_groups_overview_list_table'],
60
+				'capability' => 'ee_read_question_groups',
61
+			],
62
+			'add_question'       => [
63
+				'func'       => [$this, '_edit_question'],
64
+				'capability' => 'ee_edit_questions',
65
+			],
66
+			'insert_question'    => [
67
+				'func'       => [$this, '_insert_or_update_question'],
68
+				'args'       => ['new_question' => true],
69
+				'capability' => 'ee_edit_questions',
70
+				'noheader'   => true,
71
+			],
72
+			'duplicate_question' => [
73
+				'func'       => [$this, '_duplicate_question'],
74
+				'capability' => 'ee_edit_questions',
75
+				'noheader'   => true,
76
+			],
77
+			'trash_question'     => [
78
+				'func'       => [$this, '_trash_question'],
79
+				'capability' => 'ee_delete_question',
80
+				'obj_id'     => $qst_id,
81
+				'noheader'   => true,
82
+			],
83
+
84
+			'restore_question' => [
85
+				'func'       => [$this, '_trash_or_restore_questions'],
86
+				'capability' => 'ee_delete_question',
87
+				'obj_id'     => $qst_id,
88
+				'args'       => ['trash' => false],
89
+				'noheader'   => true,
90
+			],
91
+
92
+			'delete_question' => [
93
+				'func'       => [$this, '_delete_question'],
94
+				'capability' => 'ee_delete_question',
95
+				'obj_id'     => $qst_id,
96
+				'noheader'   => true,
97
+			],
98
+
99
+			'trash_questions' => [
100
+				'func'       => [$this, '_trash_or_restore_questions'],
101
+				'capability' => 'ee_delete_questions',
102
+				'args'       => ['trash' => true],
103
+				'noheader'   => true,
104
+			],
105
+
106
+			'restore_questions' => [
107
+				'func'       => [$this, '_trash_or_restore_questions'],
108
+				'capability' => 'ee_delete_questions',
109
+				'args'       => ['trash' => false],
110
+				'noheader'   => true,
111
+			],
112
+
113
+			'delete_questions' => [
114
+				'func'       => [$this, '_delete_questions'],
115
+				'args'       => [],
116
+				'capability' => 'ee_delete_questions',
117
+				'noheader'   => true,
118
+			],
119
+
120
+			'add_question_group' => [
121
+				'func'       => [$this, '_edit_question_group'],
122
+				'capability' => 'ee_edit_question_groups',
123
+			],
124
+
125
+			'edit_question_group' => [
126
+				'func'       => [$this, '_edit_question_group'],
127
+				'capability' => 'ee_edit_question_group',
128
+				'obj_id'     => $qsg_id,
129
+				'args'       => ['edit'],
130
+			],
131
+
132
+			'delete_question_groups' => [
133
+				'func'       => [$this, '_delete_question_groups'],
134
+				'capability' => 'ee_delete_question_groups',
135
+				'noheader'   => true,
136
+			],
137
+
138
+			'delete_question_group' => [
139
+				'func'       => [$this, '_delete_question_groups'],
140
+				'capability' => 'ee_delete_question_group',
141
+				'obj_id'     => $qsg_id,
142
+				'noheader'   => true,
143
+			],
144
+
145
+			'trash_question_group' => [
146
+				'func'       => [$this, '_trash_or_restore_question_groups'],
147
+				'args'       => ['trash' => true],
148
+				'capability' => 'ee_delete_question_group',
149
+				'obj_id'     => $qsg_id,
150
+				'noheader'   => true,
151
+			],
152
+
153
+			'restore_question_group' => [
154
+				'func'       => [$this, '_trash_or_restore_question_groups'],
155
+				'args'       => ['trash' => false],
156
+				'capability' => 'ee_delete_question_group',
157
+				'obj_id'     => $qsg_id,
158
+				'noheader'   => true,
159
+			],
160
+
161
+			'insert_question_group' => [
162
+				'func'       => [$this, '_insert_or_update_question_group'],
163
+				'args'       => ['new_question_group' => true],
164
+				'capability' => 'ee_edit_question_groups',
165
+				'noheader'   => true,
166
+			],
167
+
168
+			'update_question_group' => [
169
+				'func'       => [$this, '_insert_or_update_question_group'],
170
+				'args'       => ['new_question_group' => false],
171
+				'capability' => 'ee_edit_question_group',
172
+				'obj_id'     => $qsg_id,
173
+				'noheader'   => true,
174
+			],
175
+
176
+			'trash_question_groups' => [
177
+				'func'       => [$this, '_trash_or_restore_question_groups'],
178
+				'args'       => ['trash' => true],
179
+				'capability' => 'ee_delete_question_groups',
180
+				'noheader'   => ['trash' => false],
181
+			],
182
+
183
+			'restore_question_groups' => [
184
+				'func'       => [$this, '_trash_or_restore_question_groups'],
185
+				'args'       => ['trash' => false],
186
+				'capability' => 'ee_delete_question_groups',
187
+				'noheader'   => true,
188
+			],
189
+
190
+
191
+			'espresso_update_question_group_order' => [
192
+				'func'       => [$this, 'update_question_group_order'],
193
+				'capability' => 'ee_edit_question_groups',
194
+				'noheader'   => true,
195
+			],
196
+
197
+			'view_reg_form_settings' => [
198
+				'func'       => [$this, '_reg_form_settings'],
199
+				'capability' => 'manage_options',
200
+			],
201
+
202
+			'update_reg_form_settings' => [
203
+				'func'       => [$this, '_update_reg_form_settings'],
204
+				'capability' => 'manage_options',
205
+				'noheader'   => true,
206
+			],
207
+		];
208
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
209
+
210
+		$new_page_config    = [
211
+
212
+			'question_groups' => [
213
+				'nav'           => [
214
+					'label' => esc_html__('Question Groups', 'event_espresso'),
215
+					'icon'  => 'dashicons-forms',
216
+					'order' => 20,
217
+				],
218
+				'list_table'    => 'Registration_Form_Question_Groups_Admin_List_Table',
219
+				'help_tabs'     => [
220
+					'registration_form_question_groups_help_tab'                           => [
221
+						'title'    => esc_html__('Question Groups', 'event_espresso'),
222
+						'filename' => 'registration_form_question_groups',
223
+					],
224
+					'registration_form_question_groups_table_column_headings_help_tab'     => [
225
+						'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'),
226
+						'filename' => 'registration_form_question_groups_table_column_headings',
227
+					],
228
+					'registration_form_question_groups_views_bulk_actions_search_help_tab' => [
229
+						'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'),
230
+						'filename' => 'registration_form_question_groups_views_bulk_actions_search',
231
+					],
232
+				],
233
+				'metaboxes'     => $this->_default_espresso_metaboxes,
234
+				'require_nonce' => false,
235
+			],
236
+
237
+			'add_question' => [
238
+				'nav'           => [
239
+					'label'      => esc_html__('Add Question', 'event_espresso'),
240
+					'icon'       => 'dashicons-plus-alt',
241
+					'order'      => 15,
242
+					'persistent' => false,
243
+				],
244
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
245
+				'help_tabs'     => [
246
+					'registration_form_add_question_help_tab' => [
247
+						'title'    => esc_html__('Add Question', 'event_espresso'),
248
+						'filename' => 'registration_form_add_question',
249
+					],
250
+				],
251
+				'require_nonce' => false,
252
+			],
253
+
254
+			'add_question_group' => [
255
+				'nav'           => [
256
+					'label'      => esc_html__('Add Question Group', 'event_espresso'),
257
+					'icon'       => 'dashicons-plus-alt',
258
+					'order'      => 25,
259
+					'persistent' => false,
260
+				],
261
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
262
+				'help_tabs'     => [
263
+					'registration_form_add_question_group_help_tab' => [
264
+						'title'    => esc_html__('Add Question Group', 'event_espresso'),
265
+						'filename' => 'registration_form_add_question_group',
266
+					],
267
+				],
268
+				'require_nonce' => false,
269
+			],
270
+
271
+			'edit_question_group' => [
272
+				'nav'           => [
273
+					'label'      => esc_html__('Edit Question Group', 'event_espresso'),
274
+					'icon'       => 'dashicons-edit-large',
275
+					'order'      => 25,
276
+					'persistent' => false,
277
+					'url'        => isset($this->_req_data['question_group_id']) ? add_query_arg(
278
+						['question_group_id' => $this->_req_data['question_group_id']],
279
+						$this->_current_page_view_url
280
+					) : $this->_admin_base_url,
281
+				],
282
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
283
+				'help_tabs'     => [
284
+					'registration_form_edit_question_group_help_tab' => [
285
+						'title'    => esc_html__('Edit Question Group', 'event_espresso'),
286
+						'filename' => 'registration_form_edit_question_group',
287
+					],
288
+				],
289
+				'require_nonce' => false,
290
+			],
291
+
292
+			'view_reg_form_settings' => [
293
+				'nav'           => [
294
+					'label' => esc_html__('Reg Form Settings', 'event_espresso'),
295
+					'icon'  => 'dashicons-admin-generic',
296
+					'order' => 40,
297
+				],
298
+				'labels'        => [
299
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
300
+				],
301
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
302
+				'help_tabs'     => [
303
+					'registration_form_reg_form_settings_help_tab' => [
304
+						'title'    => esc_html__('Registration Form Settings', 'event_espresso'),
305
+						'filename' => 'registration_form_reg_form_settings',
306
+					],
307
+				],
308
+				'require_nonce' => false,
309
+			],
310
+
311
+		];
312
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
313
+
314
+		// change the list table we're going to use so it's the NEW list table!
315
+		$this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';
316
+
317
+
318
+		// additional labels
319
+		$new_labels               = [
320
+			'add_question'          => esc_html__('Add New Question', 'event_espresso'),
321
+			'delete_question'       => esc_html__('Delete Question', 'event_espresso'),
322
+			'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'),
323
+			'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'),
324
+			'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'),
325
+		];
326
+		$this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);
327
+	}
328
+
329
+
330
+	/**
331
+	 * @return void
332
+	 */
333
+	protected function _ajax_hooks()
334
+	{
335
+		if (! $this->capabilities->current_user_can('ee_edit_question_groups', 'edit-questions')) {
336
+			return;
337
+		}
338
+		add_action('wp_ajax_espresso_update_question_group_order', [$this, 'update_question_group_order']);
339
+	}
340
+
341
+
342
+	/**
343
+	 * @return void
344
+	 */
345
+	public function load_scripts_styles_question_groups()
346
+	{
347
+		wp_enqueue_script('espresso_ajax_table_sorting');
348
+	}
349
+
350
+
351
+	/**
352
+	 * @return void
353
+	 */
354
+	public function load_scripts_styles_add_question_group()
355
+	{
356
+		$this->load_scripts_styles_forms();
357
+		$this->load_sortable_question_script();
358
+	}
359
+
360
+
361
+	/**
362
+	 * @return void
363
+	 */
364
+	public function load_scripts_styles_edit_question_group()
365
+	{
366
+		$this->load_scripts_styles_forms();
367
+		$this->load_sortable_question_script();
368
+	}
369
+
370
+
371
+	/**
372
+	 * registers and enqueues script for questions
373
+	 *
374
+	 * @return void
375
+	 */
376
+	public function load_sortable_question_script()
377
+	{
378
+		wp_register_script(
379
+			'ee-question-sortable',
380
+			REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
381
+			['jquery-ui-sortable'],
382
+			EVENT_ESPRESSO_VERSION,
383
+			true
384
+		);
385
+		wp_enqueue_script('ee-question-sortable');
386
+	}
387
+
388
+
389
+	/**
390
+	 * @return void
391
+	 */
392
+	protected function _set_list_table_views_default()
393
+	{
394
+		$this->_views = [
395
+			'all' => [
396
+				'slug'        => 'all',
397
+				'label'       => esc_html__('View All Questions', 'event_espresso'),
398
+				'count'       => 0,
399
+				'bulk_action' => [
400
+					'trash_questions' => esc_html__('Trash', 'event_espresso'),
401
+				],
402
+			],
403
+		];
404
+
405
+		if (
406
+			EE_Registry::instance()->CAP->current_user_can(
407
+				'ee_delete_questions',
408
+				'espresso_registration_form_trash_questions'
409
+			)
410
+		) {
411
+			$this->_views['trash'] = [
412
+				'slug'        => 'trash',
413
+				'label'       => esc_html__('Trash', 'event_espresso'),
414
+				'count'       => 0,
415
+				'bulk_action' => [
416
+					'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'),
417
+					'restore_questions' => esc_html__('Restore', 'event_espresso'),
418
+				],
419
+			];
420
+		}
421
+	}
422
+
423
+
424
+	/**
425
+	 * @return void
426
+	 */
427
+	protected function _set_list_table_views_question_groups()
428
+	{
429
+		$this->_views = [
430
+			'all' => [
431
+				'slug'        => 'all',
432
+				'label'       => esc_html__('All', 'event_espresso'),
433
+				'count'       => 0,
434
+				'bulk_action' => [
435
+					'trash_question_groups' => esc_html__('Trash', 'event_espresso'),
436
+				],
437
+			],
438
+		];
439
+
440
+		if (
441
+			EE_Registry::instance()->CAP->current_user_can(
442
+				'ee_delete_question_groups',
443
+				'espresso_registration_form_trash_question_groups'
444
+			)
445
+		) {
446
+			$this->_views['trash'] = [
447
+				'slug'        => 'trash',
448
+				'label'       => esc_html__('Trash', 'event_espresso'),
449
+				'count'       => 0,
450
+				'bulk_action' => [
451
+					'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'),
452
+					'restore_question_groups' => esc_html__('Restore', 'event_espresso'),
453
+				],
454
+			];
455
+		}
456
+	}
457
+
458
+
459
+	/**
460
+	 * @return void
461
+	 * @throws EE_Error
462
+	 * @throws InvalidArgumentException
463
+	 * @throws InvalidDataTypeException
464
+	 * @throws InvalidInterfaceException
465
+	 */
466
+	protected function _questions_overview_list_table()
467
+	{
468
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
469
+			'add_question',
470
+			'add_question',
471
+			[],
472
+			'add-new-h2'
473
+		);
474
+		parent::_questions_overview_list_table();
475
+	}
476
+
477
+
478
+	/**
479
+	 * @return void
480
+	 * @throws DomainException
481
+	 * @throws EE_Error
482
+	 * @throws InvalidArgumentException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 */
486
+	protected function _question_groups_overview_list_table()
487
+	{
488
+		$this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
489
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
490
+			'add_question_group',
491
+			'add_question_group',
492
+			[],
493
+			'add-new-h2'
494
+		);
495
+		$this->display_admin_list_table_page_with_sidebar();
496
+	}
497
+
498
+
499
+	/**
500
+	 * @return void
501
+	 * @throws EE_Error
502
+	 * @throws InvalidArgumentException
503
+	 * @throws InvalidDataTypeException
504
+	 * @throws InvalidInterfaceException
505
+	 * @throws ReflectionException
506
+	 */
507
+	protected function _delete_question()
508
+	{
509
+		$success = $this->_delete_items($this->_question_model);
510
+		$this->_redirect_after_action(
511
+			$success,
512
+			$this->_question_model->item_name($success),
513
+			'deleted',
514
+			['action' => 'default', 'status' => 'all']
515
+		);
516
+	}
517
+
518
+
519
+	/**
520
+	 * @return void
521
+	 * @throws EE_Error
522
+	 * @throws InvalidArgumentException
523
+	 * @throws InvalidDataTypeException
524
+	 * @throws InvalidInterfaceException
525
+	 * @throws ReflectionException
526
+	 */
527
+	protected function _delete_questions()
528
+	{
529
+		$success = $this->_delete_items($this->_question_model);
530
+		$this->_redirect_after_action(
531
+			$success,
532
+			$this->_question_model->item_name($success),
533
+			'deleted permanently',
534
+			['action' => 'default', 'status' => 'trash']
535
+		);
536
+	}
537
+
538
+
539
+	/**
540
+	 * Performs the deletion of a single or multiple questions or question groups.
541
+	 *
542
+	 * @param EEM_Soft_Delete_Base $model
543
+	 * @return int number of items deleted permanently
544
+	 * @throws EE_Error
545
+	 * @throws InvalidArgumentException
546
+	 * @throws InvalidDataTypeException
547
+	 * @throws InvalidInterfaceException
548
+	 * @throws ReflectionException
549
+	 */
550
+	private function _delete_items(EEM_Soft_Delete_Base $model)
551
+	{
552
+		$success = 0;
553
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
554
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
555
+			// if array has more than one element than success message should be plural
556
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
557
+			// cycle thru bulk action checkboxes
558
+			$checkboxes = $this->_req_data['checkbox'];
559
+			foreach (array_keys($checkboxes) as $ID) {
560
+				if (! $this->_delete_item($ID, $model)) {
561
+					$success = 0;
562
+				}
563
+			}
564
+		} elseif (! empty($this->_req_data['QSG_ID'])) {
565
+			$success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
566
+		} elseif (! empty($this->_req_data['QST_ID'])) {
567
+			$success = $this->_delete_item($this->_req_data['QST_ID'], $model);
568
+		} else {
569
+			EE_Error::add_error(
570
+				sprintf(
571
+					esc_html__(
572
+						"No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",
573
+						"event_espresso"
574
+					)
575
+				),
576
+				__FILE__,
577
+				__FUNCTION__,
578
+				__LINE__
579
+			);
580
+		}
581
+		return $success;
582
+	}
583
+
584
+
585
+	/**
586
+	 * Deletes the specified question (and its associated question options) or question group
587
+	 *
588
+	 * @param int                  $id
589
+	 * @param EEM_Soft_Delete_Base $model
590
+	 * @return boolean
591
+	 * @throws EE_Error
592
+	 * @throws InvalidArgumentException
593
+	 * @throws InvalidDataTypeException
594
+	 * @throws InvalidInterfaceException
595
+	 * @throws ReflectionException
596
+	 */
597
+	protected function _delete_item($id, $model)
598
+	{
599
+		if ($model instanceof EEM_Question) {
600
+			EEM_Question_Option::instance()->delete_permanently([['QST_ID' => absint($id)]]);
601
+		}
602
+		return $model->delete_permanently_by_ID(absint($id));
603
+	}
604
+
605
+
606
+	/******************************    QUESTION GROUPS    ******************************/
607
+
608
+
609
+	/**
610
+	 * @param string $type
611
+	 * @return void
612
+	 * @throws DomainException
613
+	 * @throws EE_Error
614
+	 * @throws InvalidArgumentException
615
+	 * @throws InvalidDataTypeException
616
+	 * @throws InvalidInterfaceException
617
+	 * @throws ReflectionException
618
+	 */
619
+	protected function _edit_question_group($type = 'add')
620
+	{
621
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
622
+		$ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID'])
623
+			? absint($this->_req_data['QSG_ID'])
624
+			: false;
625
+
626
+		switch ($this->_req_action) {
627
+			case 'add_question_group':
628
+				$this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso');
629
+				break;
630
+			case 'edit_question_group':
631
+				$this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso');
632
+				break;
633
+			default:
634
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
635
+		}
636
+		// add ID to title if editing
637
+		$this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
638
+		if ($ID) {
639
+			/** @var EE_Question_Group $questionGroup */
640
+			$questionGroup            = $this->_question_group_model->get_one_by_ID($ID);
641
+			$additional_hidden_fields = ['QSG_ID' => ['type' => 'hidden', 'value' => $ID]];
642
+			$this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields);
643
+		} else {
644
+			/** @var EE_Question_Group $questionGroup */
645
+			$questionGroup = EEM_Question_Group::instance()->create_default_object();
646
+			$questionGroup->set_order_to_latest();
647
+			$this->_set_add_edit_form_tags('insert_question_group');
648
+		}
649
+		$this->_template_args['values']         = $this->_yes_no_values;
650
+		$this->_template_args['all_questions']  = $questionGroup->questions_in_and_not_in_group();
651
+		$this->_template_args['QSG_ID']         = $ID ? $ID : true;
652
+		$this->_template_args['question_group'] = $questionGroup;
653
+
654
+		$redirect_URL = add_query_arg(['action' => 'question_groups'], $this->_admin_base_url);
655
+		$this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL, true);
656
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
657
+			REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
658
+			$this->_template_args,
659
+			true
660
+		);
661
+
662
+		// the details template wrapper
663
+		$this->display_admin_page_with_sidebar();
664
+	}
665
+
666
+
667
+	/**
668
+	 * @return void
669
+	 * @throws EE_Error
670
+	 * @throws InvalidArgumentException
671
+	 * @throws InvalidDataTypeException
672
+	 * @throws InvalidInterfaceException
673
+	 * @throws ReflectionException
674
+	 */
675
+	protected function _delete_question_groups()
676
+	{
677
+		$success = $this->_delete_items($this->_question_group_model);
678
+		$this->_redirect_after_action(
679
+			$success,
680
+			$this->_question_group_model->item_name($success),
681
+			'deleted permanently',
682
+			['action' => 'question_groups', 'status' => 'trash']
683
+		);
684
+	}
685
+
686
+
687
+	/**
688
+	 * @param bool $new_question_group
689
+	 * @throws EE_Error
690
+	 * @throws InvalidArgumentException
691
+	 * @throws InvalidDataTypeException
692
+	 * @throws InvalidInterfaceException
693
+	 * @throws ReflectionException
694
+	 */
695
+	protected function _insert_or_update_question_group($new_question_group = true)
696
+	{
697
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
698
+		$set_column_values = $this->_set_column_values_for($this->_question_group_model);
699
+
700
+		// make sure identifier is unique
701
+		$identifier_value = $set_column_values['QSG_identifier'] ?? '';
702
+		$where_values     = ['QSG_identifier' => $identifier_value];
703
+		if (! $new_question_group && isset($set_column_values['QSG_ID'])) {
704
+			$where_values['QSG_ID'] = ['!=', $set_column_values['QSG_ID']];
705
+		}
706
+		$identifier_exists = ! empty($identifier_value) && $this->_question_group_model->count([$where_values]) > 0;
707
+		if ($identifier_exists) {
708
+			$set_column_values['QSG_identifier'] .= uniqid('id', true);
709
+		}
710
+
711
+		if ($new_question_group) {
712
+			$QSG_ID  = $this->_question_group_model->insert($set_column_values);
713
+			$success = $QSG_ID ? 1 : 0;
714
+			if ($success === 0) {
715
+				EE_Error::add_error(
716
+					esc_html__('Something went wrong saving the question group.', 'event_espresso'),
717
+					__FILE__,
718
+					__FUNCTION__,
719
+					__LINE__
720
+				);
721
+				$this->_redirect_after_action(
722
+					false,
723
+					'',
724
+					'',
725
+					['action' => 'edit_question_group', 'QSG_ID' => $QSG_ID],
726
+					true
727
+				);
728
+			}
729
+		} else {
730
+			$QSG_ID = absint($this->_req_data['QSG_ID']);
731
+			unset($set_column_values['QSG_ID']);
732
+			$success = $this->_question_group_model->update($set_column_values, [['QSG_ID' => $QSG_ID]]);
733
+		}
734
+
735
+		$phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
736
+			EEM_Attendee::system_question_phone
737
+		);
738
+		// update the existing related questions
739
+		// BUT FIRST...  delete the phone question from the Question_Group_Question
740
+		// if it is being added to this question group (therefore removed from the existing group)
741
+		if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) {
742
+			// delete where QST ID = system phone question ID and Question Group ID is NOT this group
743
+			EEM_Question_Group_Question::instance()->delete(
744
+				[
745
+					[
746
+						'QST_ID' => $phone_question_id,
747
+						'QSG_ID' => ['!=', $QSG_ID],
748
+					],
749
+				]
750
+			);
751
+		}
752
+		/** @type EE_Question_Group $question_group */
753
+		$question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
754
+		$questions      = $question_group->questions();
755
+		// make sure system phone question is added to list of questions for this group
756
+		if (! isset($questions[ $phone_question_id ])) {
757
+			$questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
758
+		}
759
+
760
+		foreach ($questions as $question_ID => $question) {
761
+			// first we always check for order.
762
+			if (! empty($this->_req_data['question_orders'][ $question_ID ])) {
763
+				// update question order
764
+				$question_group->update_question_order(
765
+					$question_ID,
766
+					$this->_req_data['question_orders'][ $question_ID ]
767
+				);
768
+			}
769
+
770
+			// then we always check if adding or removing.
771
+			if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) {
772
+				$question_group->add_question($question_ID);
773
+			} else {
774
+				// not found, remove it (but only if not a system question for the personal group
775
+				// with the exception of lname system question - we allow removal of it)
776
+				if (
777
+					in_array(
778
+						$question->system_ID(),
779
+						EEM_Question::instance()->required_system_questions_in_system_question_group(
780
+							$question_group->system_group()
781
+						)
782
+					)
783
+				) {
784
+					continue;
785
+				} else {
786
+					$question_group->remove_question($question_ID);
787
+				}
788
+			}
789
+		}
790
+		// save new related questions
791
+		if (isset($this->_req_data['questions'])) {
792
+			foreach ($this->_req_data['questions'] as $QST_ID) {
793
+				$question_group->add_question($QST_ID);
794
+				if (isset($this->_req_data['question_orders'][ $QST_ID ])) {
795
+					$question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);
796
+				}
797
+			}
798
+		}
799
+
800
+		if ($success !== false) {
801
+			$msg = $new_question_group
802
+				? sprintf(
803
+					esc_html__('The %s has been created', 'event_espresso'),
804
+					$this->_question_group_model->item_name()
805
+				)
806
+				: sprintf(
807
+					esc_html__(
808
+						'The %s has been updated',
809
+						'event_espresso'
810
+					),
811
+					$this->_question_group_model->item_name()
812
+				);
813
+			EE_Error::add_success($msg);
814
+		}
815
+		$this->_redirect_after_action(
816
+			false,
817
+			'',
818
+			'',
819
+			['action' => 'edit_question_group', 'QSG_ID' => $QSG_ID],
820
+			true
821
+		);
822
+	}
823
+
824
+
825
+	/**
826
+	 * duplicates a question and all its question options and redirects to the new question.
827
+	 *
828
+	 * @return void
829
+	 * @throws EE_Error
830
+	 * @throws InvalidArgumentException
831
+	 * @throws ReflectionException
832
+	 * @throws InvalidDataTypeException
833
+	 * @throws InvalidInterfaceException
834
+	 */
835
+	public function _duplicate_question()
836
+	{
837
+		$question_ID = (int) $this->_req_data['QST_ID'];
838
+		$question    = EEM_Question::instance()->get_one_by_ID($question_ID);
839
+		if ($question instanceof EE_Question) {
840
+			$new_question = $question->duplicate();
841
+			if ($new_question instanceof EE_Question) {
842
+				$this->_redirect_after_action(
843
+					true,
844
+					esc_html__('Question', 'event_espresso'),
845
+					esc_html__('Duplicated', 'event_espresso'),
846
+					['action' => 'edit_question', 'QST_ID' => $new_question->ID()],
847
+					true
848
+				);
849
+			} else {
850
+				global $wpdb;
851
+				EE_Error::add_error(
852
+					sprintf(
853
+						esc_html__(
854
+							'Could not duplicate question with ID %1$d because: %2$s',
855
+							'event_espresso'
856
+						),
857
+						$question_ID,
858
+						$wpdb->last_error
859
+					),
860
+					__FILE__,
861
+					__FUNCTION__,
862
+					__LINE__
863
+				);
864
+				$this->_redirect_after_action(false, '', '', ['action' => 'default'], false);
865
+			}
866
+		} else {
867
+			EE_Error::add_error(
868
+				sprintf(
869
+					esc_html__(
870
+						'Could not duplicate question with ID %d because it didn\'t exist!',
871
+						'event_espresso'
872
+					),
873
+					$question_ID
874
+				),
875
+				__FILE__,
876
+				__FUNCTION__,
877
+				__LINE__
878
+			);
879
+			$this->_redirect_after_action(false, '', '', ['action' => 'default'], false);
880
+		}
881
+	}
882
+
883
+
884
+	/**
885
+	 * @param bool $trash
886
+	 * @throws EE_Error
887
+	 */
888
+	protected function _trash_or_restore_question_groups($trash = true)
889
+	{
890
+		$this->_trash_or_restore_items($this->_question_group_model, $trash);
891
+	}
892
+
893
+
894
+	/**
895
+	 *_trash_question
896
+	 *
897
+	 * @return void
898
+	 * @throws EE_Error
899
+	 */
900
+	protected function _trash_question()
901
+	{
902
+		$success    = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']);
903
+		$query_args = ['action' => 'default', 'status' => 'all'];
904
+		$this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);
905
+	}
906
+
907
+
908
+	/**
909
+	 * @param bool $trash
910
+	 * @throws EE_Error
911
+	 */
912
+	protected function _trash_or_restore_questions($trash = true)
913
+	{
914
+		$this->_trash_or_restore_items($this->_question_model, $trash);
915
+	}
916
+
917
+
918
+	/**
919
+	 * Internally used to delete or restore items, using the request data. Meant to be
920
+	 * flexible between question or question groups
921
+	 *
922
+	 * @param EEM_Soft_Delete_Base $model
923
+	 * @param boolean              $trash whether to trash or restore
924
+	 * @throws EE_Error
925
+	 */
926
+	private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)
927
+	{
928
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
929
+
930
+		$success = 1;
931
+		// Checkboxes
932
+		// echo "trash $trash";
933
+		// var_dump($this->_req_data['checkbox']);die;
934
+		if (isset($this->_req_data['checkbox'])) {
935
+			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
936
+				// if array has more than one element than success message should be plural
937
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
938
+				// cycle thru bulk action checkboxes
939
+				$checkboxes = $this->_req_data['checkbox'];
940
+				foreach (array_keys($checkboxes) as $ID) {
941
+					if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
942
+						$success = 0;
943
+					}
944
+				}
945
+			} else {
946
+				// grab single id and delete
947
+				$ID = absint($this->_req_data['checkbox']);
948
+				if (! $model->delete_or_restore_by_ID($trash, $ID)) {
949
+					$success = 0;
950
+				}
951
+			}
952
+		} else {
953
+			// delete via trash link
954
+			// grab single id and delete
955
+			$ID = absint($this->_req_data[ $model->primary_key_name() ]);
956
+			if (! $model->delete_or_restore_by_ID($trash, $ID)) {
957
+				$success = 0;
958
+			}
959
+		}
960
+
961
+
962
+		$action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );
963
+		// echo "action :$action";
964
+		// $action = 'questions' ? 'default' : $action;
965
+		if ($trash) {
966
+			$action_desc = 'trashed';
967
+			$status      = 'trash';
968
+		} else {
969
+			$action_desc = 'restored';
970
+			$status      = 'all';
971
+		}
972
+		$this->_redirect_after_action(
973
+			$success,
974
+			$model->item_name($success),
975
+			$action_desc,
976
+			['action' => $action, 'status' => $status]
977
+		);
978
+	}
979
+
980
+
981
+	/**
982
+	 * @param            $per_page
983
+	 * @param int        $current_page
984
+	 * @param bool|false $count
985
+	 * @return EE_Soft_Delete_Base_Class[]|int
986
+	 * @throws EE_Error
987
+	 * @throws InvalidArgumentException
988
+	 * @throws InvalidDataTypeException
989
+	 * @throws InvalidInterfaceException
990
+	 * @throws ReflectionException
991
+	 */
992
+	public function get_trashed_questions($per_page, $current_page = 1, $count = false)
993
+	{
994
+		$query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
995
+
996
+		if ($count) {
997
+			// note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
998
+			$where   = isset($query_params[0]) ? [$query_params[0]] : [];
999
+			$results = $this->_question_model->count_deleted($where);
1000
+		} else {
1001
+			// note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
1002
+			$results = $this->_question_model->get_all_deleted($query_params);
1003
+		}
1004
+		return $results;
1005
+	}
1006
+
1007
+
1008
+	/**
1009
+	 * @param            $per_page
1010
+	 * @param int        $current_page
1011
+	 * @param bool|false $count
1012
+	 * @return EE_Soft_Delete_Base_Class[]|int
1013
+	 * @throws EE_Error
1014
+	 * @throws InvalidArgumentException
1015
+	 * @throws InvalidDataTypeException
1016
+	 * @throws InvalidInterfaceException
1017
+	 * @throws ReflectionException
1018
+	 */
1019
+	public function get_question_groups($per_page, $current_page = 1, $count = false)
1020
+	{
1021
+		$questionGroupModel = EEM_Question_Group::instance();
1022
+		$query_params       = $this->get_query_params($questionGroupModel, $per_page, $current_page);
1023
+		if ($count) {
1024
+			$where   = isset($query_params[0]) ? [$query_params[0]] : [];
1025
+			$results = $questionGroupModel->count($where);
1026
+		} else {
1027
+			$results = $questionGroupModel->get_all($query_params);
1028
+		}
1029
+		return $results;
1030
+	}
1031
+
1032
+
1033
+	/**
1034
+	 * @param      $per_page
1035
+	 * @param int  $current_page
1036
+	 * @param bool $count
1037
+	 * @return EE_Soft_Delete_Base_Class[]|int
1038
+	 * @throws EE_Error
1039
+	 * @throws InvalidArgumentException
1040
+	 * @throws InvalidDataTypeException
1041
+	 * @throws InvalidInterfaceException
1042
+	 * @throws ReflectionException
1043
+	 */
1044
+	public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)
1045
+	{
1046
+		$questionGroupModel = EEM_Question_Group::instance();
1047
+		$query_params       = $this->get_query_params($questionGroupModel, $per_page, $current_page);
1048
+		if ($count) {
1049
+			$where                 = isset($query_params[0]) ? [$query_params[0]] : [];
1050
+			$query_params['limit'] = null;
1051
+			$results               = $questionGroupModel->count_deleted($where);
1052
+		} else {
1053
+			$results = $questionGroupModel->get_all_deleted($query_params);
1054
+		}
1055
+		return $results;
1056
+	}
1057
+
1058
+
1059
+	/**
1060
+	 * method for performing updates to question order
1061
+	 *
1062
+	 * @return void results array
1063
+	 * @throws EE_Error
1064
+	 * @throws InvalidArgumentException
1065
+	 * @throws InvalidDataTypeException
1066
+	 * @throws InvalidInterfaceException
1067
+	 * @throws ReflectionException
1068
+	 */
1069
+	public function update_question_group_order()
1070
+	{
1071
+		if (! $this->capabilities->current_user_can('ee_edit_question_groups', __FUNCTION__)) {
1072
+			wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
1073
+		}
1074
+		$success = esc_html__('Question group order was updated successfully.', 'event_espresso');
1075
+
1076
+		// grab our row IDs
1077
+		$row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])
1078
+			? explode(',', rtrim($this->_req_data['row_ids'], ','))
1079
+			: [];
1080
+
1081
+		$perpage = ! empty($this->_req_data['perpage'])
1082
+			? (int) $this->_req_data['perpage']
1083
+			: null;
1084
+		$curpage = ! empty($this->_req_data['curpage'])
1085
+			? (int) $this->_req_data['curpage']
1086
+			: null;
1087
+
1088
+		if (! empty($row_ids)) {
1089
+			// figure out where we start the row_id count at for the current page.
1090
+			$qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
1091
+
1092
+			$row_count = count($row_ids);
1093
+			for ($i = 0; $i < $row_count; $i++) {
1094
+				// Update the questions when re-ordering
1095
+				$updated = EEM_Question_Group::instance()->update(
1096
+					['QSG_order' => $qsgcount],
1097
+					[['QSG_ID' => $row_ids[ $i ]]]
1098
+				);
1099
+				if ($updated === false) {
1100
+					$success = false;
1101
+				}
1102
+				$qsgcount++;
1103
+			}
1104
+		} else {
1105
+			$success = false;
1106
+		}
1107
+
1108
+		$errors = ! $success
1109
+			? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso')
1110
+			: false;
1111
+
1112
+		echo wp_json_encode(['return_data' => false, 'success' => $success, 'errors' => $errors]);
1113
+		die();
1114
+	}
1115
+
1116
+
1117
+
1118
+	/***************************************       REGISTRATION SETTINGS       ***************************************/
1119
+
1120
+
1121
+	/**
1122
+	 * @throws DomainException
1123
+	 * @throws EE_Error
1124
+	 * @throws InvalidArgumentException
1125
+	 * @throws InvalidDataTypeException
1126
+	 * @throws InvalidInterfaceException
1127
+	 */
1128
+	protected function _reg_form_settings()
1129
+	{
1130
+		$this->_template_args['values'] = $this->_yes_no_values;
1131
+		add_action(
1132
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1133
+			[$this, 'email_validation_settings_form'],
1134
+			2
1135
+		);
1136
+		add_action(
1137
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1138
+			[$this, 'copy_attendee_info_settings_form'],
1139
+			4
1140
+		);
1141
+		add_action(
1142
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1143
+			[$this, 'setSessionLifespan'],
1144
+			5
1145
+		);
1146
+		$this->_template_args = (array) apply_filters(
1147
+			'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',
1148
+			$this->_template_args
1149
+		);
1150
+		$this->_set_add_edit_form_tags('update_reg_form_settings');
1151
+		$this->_set_publish_post_box_vars();
1152
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1153
+			REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
1154
+			$this->_template_args,
1155
+			true
1156
+		);
1157
+		$this->display_admin_page_with_sidebar();
1158
+	}
1159
+
1160
+
1161
+	/**
1162
+	 * @return void
1163
+	 * @throws EE_Error
1164
+	 * @throws InvalidArgumentException
1165
+	 * @throws ReflectionException
1166
+	 * @throws InvalidDataTypeException
1167
+	 * @throws InvalidInterfaceException
1168
+	 */
1169
+	protected function _update_reg_form_settings()
1170
+	{
1171
+		EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(
1172
+			EE_Registry::instance()->CFG->registration
1173
+		);
1174
+		EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form(
1175
+			EE_Registry::instance()->CFG->registration
1176
+		);
1177
+		$this->updateSessionLifespan();
1178
+		EE_Registry::instance()->CFG->registration = apply_filters(
1179
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
1180
+			EE_Registry::instance()->CFG->registration
1181
+		);
1182
+		$success                                   = $this->_update_espresso_configuration(
1183
+			esc_html__('Registration Form Options', 'event_espresso'),
1184
+			EE_Registry::instance()->CFG,
1185
+			__FILE__,
1186
+			__FUNCTION__,
1187
+			__LINE__
1188
+		);
1189
+		$this->_redirect_after_action(
1190
+			$success,
1191
+			esc_html__('Registration Form Options', 'event_espresso'),
1192
+			'updated',
1193
+			['action' => 'view_reg_form_settings']
1194
+		);
1195
+	}
1196
+
1197
+
1198
+	/**
1199
+	 * @return void
1200
+	 * @throws EE_Error
1201
+	 * @throws InvalidArgumentException
1202
+	 * @throws InvalidDataTypeException
1203
+	 * @throws InvalidInterfaceException
1204
+	 */
1205
+	public function copy_attendee_info_settings_form()
1206
+	{
1207
+		echo wp_kses($this->_copy_attendee_info_settings_form()->get_html(), AllowedTags::getWithFormTags());
1208
+	}
1209
+
1210
+
1211
+	/**
1212
+	 * _copy_attendee_info_settings_form
1213
+	 *
1214
+	 * @access protected
1215
+	 * @return EE_Form_Section_Proper
1216
+	 * @throws \EE_Error
1217
+	 */
1218
+	protected function _copy_attendee_info_settings_form()
1219
+	{
1220
+		return new EE_Form_Section_Proper(
1221
+			[
1222
+				'name'            => 'copy_attendee_info_settings',
1223
+				'html_id'         => 'copy_attendee_info_settings',
1224
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1225
+				'subsections'     => apply_filters(
1226
+					'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections',
1227
+					[
1228
+						'copy_attendee_info_hdr' => new EE_Form_Section_HTML(
1229
+							EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso'))
1230
+						),
1231
+						'copy_attendee_info'     => new EE_Yes_No_Input(
1232
+							[
1233
+								'html_label_text'         => esc_html__(
1234
+									'Allow copy #1 attendee info to extra attendees?',
1235
+									'event_espresso'
1236
+								),
1237
+								'html_help_text'          => esc_html__(
1238
+									'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.',
1239
+									'event_espresso'
1240
+								),
1241
+								'default'                 => EE_Registry::instance(
1242
+								)->CFG->registration->copyAttendeeInfo(),
1243
+								'required'                => false,
1244
+								'display_html_label_text' => false,
1245
+							]
1246
+						),
1247
+					]
1248
+				),
1249
+			]
1250
+		);
1251
+	}
1252
+
1253
+
1254
+	/**
1255
+	 * @param EE_Registration_Config $EE_Registration_Config
1256
+	 * @return EE_Registration_Config
1257
+	 * @throws EE_Error
1258
+	 * @throws InvalidArgumentException
1259
+	 * @throws ReflectionException
1260
+	 * @throws InvalidDataTypeException
1261
+	 * @throws InvalidInterfaceException
1262
+	 */
1263
+	public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config)
1264
+	{
1265
+		$prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo();
1266
+		try {
1267
+			$copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form();
1268
+			// if not displaying a form, then check for form submission
1269
+			if ($copy_attendee_info_settings_form->was_submitted()) {
1270
+				// capture form data
1271
+				$copy_attendee_info_settings_form->receive_form_submission();
1272
+				// validate form data
1273
+				if ($copy_attendee_info_settings_form->is_valid()) {
1274
+					// grab validated data from form
1275
+					$valid_data = $copy_attendee_info_settings_form->valid_data();
1276
+					if (isset($valid_data['copy_attendee_info'])) {
1277
+						$EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']);
1278
+					} else {
1279
+						EE_Error::add_error(
1280
+							esc_html__(
1281
+								'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.',
1282
+								'event_espresso'
1283
+							),
1284
+							__FILE__,
1285
+							__FUNCTION__,
1286
+							__LINE__
1287
+						);
1288
+					}
1289
+				} elseif ($copy_attendee_info_settings_form->submission_error_message() !== '') {
1290
+					EE_Error::add_error(
1291
+						$copy_attendee_info_settings_form->submission_error_message(),
1292
+						__FILE__,
1293
+						__FUNCTION__,
1294
+						__LINE__
1295
+					);
1296
+				}
1297
+			}
1298
+		} catch (EE_Error $e) {
1299
+			$e->get_error();
1300
+		}
1301
+		return $EE_Registration_Config;
1302
+	}
1303
+
1304
+
1305
+	/**
1306
+	 * @return void
1307
+	 * @throws EE_Error
1308
+	 * @throws InvalidArgumentException
1309
+	 * @throws InvalidDataTypeException
1310
+	 * @throws InvalidInterfaceException
1311
+	 */
1312
+	public function email_validation_settings_form()
1313
+	{
1314
+		echo wp_kses($this->_email_validation_settings_form()->get_html(), AllowedTags::getWithFormTags());
1315
+	}
1316
+
1317
+
1318
+	/**
1319
+	 * _email_validation_settings_form
1320
+	 *
1321
+	 * @access protected
1322
+	 * @return EE_Form_Section_Proper
1323
+	 * @throws \EE_Error
1324
+	 */
1325
+	protected function _email_validation_settings_form()
1326
+	{
1327
+		return new EE_Form_Section_Proper(
1328
+			[
1329
+				'name'            => 'email_validation_settings',
1330
+				'html_id'         => 'email_validation_settings',
1331
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1332
+				'subsections'     => apply_filters(
1333
+					'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',
1334
+					[
1335
+						'email_validation_hdr'   => new EE_Form_Section_HTML(
1336
+							EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso'))
1337
+						),
1338
+						'email_validation_level' => new EE_Select_Input(
1339
+							[
1340
+								'basic'      => esc_html__('Basic', 'event_espresso'),
1341
+								'wp_default' => esc_html__('WordPress Default', 'event_espresso'),
1342
+								'i18n'       => esc_html__('International', 'event_espresso'),
1343
+								'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'),
1344
+							],
1345
+							[
1346
+								'html_label_text' => esc_html__('Email Validation Level', 'event_espresso')
1347
+													 . EEH_Template::get_help_tab_link('email_validation_info'),
1348
+								'html_help_text'  => esc_html__(
1349
+									'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',
1350
+									'event_espresso'
1351
+								),
1352
+								'default'         => isset(
1353
+									EE_Registry::instance()->CFG->registration->email_validation_level
1354
+								)
1355
+									? EE_Registry::instance()->CFG->registration->email_validation_level
1356
+									: 'wp_default',
1357
+								'required'        => false,
1358
+							]
1359
+						),
1360
+					]
1361
+				),
1362
+			]
1363
+		);
1364
+	}
1365
+
1366
+
1367
+	/**
1368
+	 * @param EE_Registration_Config $EE_Registration_Config
1369
+	 * @return EE_Registration_Config
1370
+	 * @throws EE_Error
1371
+	 * @throws InvalidArgumentException
1372
+	 * @throws ReflectionException
1373
+	 * @throws InvalidDataTypeException
1374
+	 * @throws InvalidInterfaceException
1375
+	 */
1376
+	public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)
1377
+	{
1378
+		$prev_email_validation_level = $EE_Registration_Config->email_validation_level;
1379
+		try {
1380
+			$email_validation_settings_form = $this->_email_validation_settings_form();
1381
+			// if not displaying a form, then check for form submission
1382
+			if ($email_validation_settings_form->was_submitted()) {
1383
+				// capture form data
1384
+				$email_validation_settings_form->receive_form_submission();
1385
+				// validate form data
1386
+				if ($email_validation_settings_form->is_valid()) {
1387
+					// grab validated data from form
1388
+					$valid_data = $email_validation_settings_form->valid_data();
1389
+					if (isset($valid_data['email_validation_level'])) {
1390
+						$email_validation_level = $valid_data['email_validation_level'];
1391
+						// now if they want to use international email addresses
1392
+						if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') {
1393
+							// in case we need to reset their email validation level,
1394
+							// make sure that the previous value wasn't already set to one of the i18n options.
1395
+							if (
1396
+								$prev_email_validation_level === 'i18n'
1397
+								|| $prev_email_validation_level
1398
+								   === 'i18n_dns'
1399
+							) {
1400
+								// if so, then reset it back to "basic" since that is the only other option that,
1401
+								// despite offering poor validation, supports i18n email addresses
1402
+								$prev_email_validation_level = 'basic';
1403
+							}
1404
+							// confirm our i18n email validation will work on the server
1405
+							if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1406
+								// or reset email validation level to previous value
1407
+								$email_validation_level = $prev_email_validation_level;
1408
+							}
1409
+						}
1410
+						$EE_Registration_Config->email_validation_level = $email_validation_level;
1411
+					} else {
1412
+						EE_Error::add_error(
1413
+							esc_html__(
1414
+								'Invalid or missing Email Validation settings. Please refresh the form and try again.',
1415
+								'event_espresso'
1416
+							),
1417
+							__FILE__,
1418
+							__FUNCTION__,
1419
+							__LINE__
1420
+						);
1421
+					}
1422
+				} elseif ($email_validation_settings_form->submission_error_message() !== '') {
1423
+					EE_Error::add_error(
1424
+						$email_validation_settings_form->submission_error_message(),
1425
+						__FILE__,
1426
+						__FUNCTION__,
1427
+						__LINE__
1428
+					);
1429
+				}
1430
+			}
1431
+		} catch (EE_Error $e) {
1432
+			$e->get_error();
1433
+		}
1434
+		return $EE_Registration_Config;
1435
+	}
1436
+
1437
+
1438
+	/**
1439
+	 * confirms that the server's PHP version has the PCRE module enabled,
1440
+	 * and that the PCRE version works with our i18n email validation
1441
+	 *
1442
+	 * @param EE_Registration_Config $EE_Registration_Config
1443
+	 * @param string                 $email_validation_level
1444
+	 * @return bool
1445
+	 */
1446
+	private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1447
+	{
1448
+		// first check that PCRE is enabled
1449
+		if (! defined('PREG_BAD_UTF8_ERROR')) {
1450
+			EE_Error::add_error(
1451
+				sprintf(
1452
+					esc_html__(
1453
+						'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',
1454
+						'event_espresso'
1455
+					),
1456
+					'<br />'
1457
+				),
1458
+				__FILE__,
1459
+				__FUNCTION__,
1460
+				__LINE__
1461
+			);
1462
+			return false;
1463
+		} else {
1464
+			// PCRE support is enabled, but let's still
1465
+			// perform a test to see if the server will support it.
1466
+			// but first, save the updated validation level to the config,
1467
+			// so that the validation strategy picks it up.
1468
+			// this will get bumped back down if it doesn't work
1469
+			$EE_Registration_Config->email_validation_level = $email_validation_level;
1470
+			try {
1471
+				$email_validator    = new EE_Email_Validation_Strategy();
1472
+				$i18n_email_address = apply_filters(
1473
+					'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',
1474
+					'jägerjü[email protected]'
1475
+				);
1476
+				$email_validator->validate($i18n_email_address);
1477
+			} catch (Exception $e) {
1478
+				EE_Error::add_error(
1479
+					sprintf(
1480
+						esc_html__(
1481
+							'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',
1482
+							'event_espresso'
1483
+						),
1484
+						'<br />',
1485
+						'<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>'
1486
+					),
1487
+					__FILE__,
1488
+					__FUNCTION__,
1489
+					__LINE__
1490
+				);
1491
+				return false;
1492
+			}
1493
+		}
1494
+		return true;
1495
+	}
1496
+
1497
+
1498
+	public function setSessionLifespan()
1499
+	{
1500
+		$session_lifespan_form = $this->loader->getNew(SessionLifespanForm::class);
1501
+		echo wp_kses($session_lifespan_form->get_html(), AllowedTags::getWithFormTags());
1502
+	}
1503
+
1504
+
1505
+	public function updateSessionLifespan()
1506
+	{
1507
+		$handler = $this->loader->getNew(SessionLifespanFormHandler::class);
1508
+		$handler->process($this->loader->getNew(SessionLifespanForm::class));
1509
+	}
1510 1510
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public function __construct($routing = true)
25 25
     {
26
-        define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/');
27
-        define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/');
28
-        define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
29
-        define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/');
30
-        define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
26
+        define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND.'registration_form/');
27
+        define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN.'assets/');
28
+        define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/assets/');
29
+        define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN.'templates/');
30
+        define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/templates/');
31 31
         parent::__construct($routing);
32 32
     }
33 33
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
         $qsg_id                 = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID'])
55 55
             ? $this->_req_data['QSG_ID'] : 0;
56 56
 
57
-        $new_page_routes    = [
57
+        $new_page_routes = [
58 58
             'question_groups'    => [
59 59
                 'func'       => [$this, '_question_groups_overview_list_table'],
60 60
                 'capability' => 'ee_read_question_groups',
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 
317 317
 
318 318
         // additional labels
319
-        $new_labels               = [
319
+        $new_labels = [
320 320
             'add_question'          => esc_html__('Add New Question', 'event_espresso'),
321 321
             'delete_question'       => esc_html__('Delete Question', 'event_espresso'),
322 322
             'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'),
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
      */
333 333
     protected function _ajax_hooks()
334 334
     {
335
-        if (! $this->capabilities->current_user_can('ee_edit_question_groups', 'edit-questions')) {
335
+        if ( ! $this->capabilities->current_user_can('ee_edit_question_groups', 'edit-questions')) {
336 336
             return;
337 337
         }
338 338
         add_action('wp_ajax_espresso_update_question_group_order', [$this, 'update_question_group_order']);
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
     {
378 378
         wp_register_script(
379 379
             'ee-question-sortable',
380
-            REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
380
+            REGISTRATION_FORM_CAF_ASSETS_URL.'ee_question_order.js',
381 381
             ['jquery-ui-sortable'],
382 382
             EVENT_ESPRESSO_VERSION,
383 383
             true
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
      */
466 466
     protected function _questions_overview_list_table()
467 467
     {
468
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
468
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
469 469
             'add_question',
470 470
             'add_question',
471 471
             [],
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
     protected function _question_groups_overview_list_table()
487 487
     {
488 488
         $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
489
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
489
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
490 490
             'add_question_group',
491 491
             'add_question_group',
492 492
             [],
@@ -551,19 +551,19 @@  discard block
 block discarded – undo
551 551
     {
552 552
         $success = 0;
553 553
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
554
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
554
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
555 555
             // if array has more than one element than success message should be plural
556 556
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
557 557
             // cycle thru bulk action checkboxes
558 558
             $checkboxes = $this->_req_data['checkbox'];
559 559
             foreach (array_keys($checkboxes) as $ID) {
560
-                if (! $this->_delete_item($ID, $model)) {
560
+                if ( ! $this->_delete_item($ID, $model)) {
561 561
                     $success = 0;
562 562
                 }
563 563
             }
564
-        } elseif (! empty($this->_req_data['QSG_ID'])) {
564
+        } elseif ( ! empty($this->_req_data['QSG_ID'])) {
565 565
             $success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
566
-        } elseif (! empty($this->_req_data['QST_ID'])) {
566
+        } elseif ( ! empty($this->_req_data['QST_ID'])) {
567 567
             $success = $this->_delete_item($this->_req_data['QST_ID'], $model);
568 568
         } else {
569 569
             EE_Error::add_error(
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
                 $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
635 635
         }
636 636
         // add ID to title if editing
637
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
637
+        $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title;
638 638
         if ($ID) {
639 639
             /** @var EE_Question_Group $questionGroup */
640 640
             $questionGroup            = $this->_question_group_model->get_one_by_ID($ID);
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
         $redirect_URL = add_query_arg(['action' => 'question_groups'], $this->_admin_base_url);
655 655
         $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL, true);
656 656
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
657
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
657
+            REGISTRATION_FORM_CAF_TEMPLATE_PATH.'question_groups_main_meta_box.template.php',
658 658
             $this->_template_args,
659 659
             true
660 660
         );
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
         // make sure identifier is unique
701 701
         $identifier_value = $set_column_values['QSG_identifier'] ?? '';
702 702
         $where_values     = ['QSG_identifier' => $identifier_value];
703
-        if (! $new_question_group && isset($set_column_values['QSG_ID'])) {
703
+        if ( ! $new_question_group && isset($set_column_values['QSG_ID'])) {
704 704
             $where_values['QSG_ID'] = ['!=', $set_column_values['QSG_ID']];
705 705
         }
706 706
         $identifier_exists = ! empty($identifier_value) && $this->_question_group_model->count([$where_values]) > 0;
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
         // update the existing related questions
739 739
         // BUT FIRST...  delete the phone question from the Question_Group_Question
740 740
         // if it is being added to this question group (therefore removed from the existing group)
741
-        if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) {
741
+        if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) {
742 742
             // delete where QST ID = system phone question ID and Question Group ID is NOT this group
743 743
             EEM_Question_Group_Question::instance()->delete(
744 744
                 [
@@ -753,22 +753,22 @@  discard block
 block discarded – undo
753 753
         $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
754 754
         $questions      = $question_group->questions();
755 755
         // make sure system phone question is added to list of questions for this group
756
-        if (! isset($questions[ $phone_question_id ])) {
757
-            $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
756
+        if ( ! isset($questions[$phone_question_id])) {
757
+            $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
758 758
         }
759 759
 
760 760
         foreach ($questions as $question_ID => $question) {
761 761
             // first we always check for order.
762
-            if (! empty($this->_req_data['question_orders'][ $question_ID ])) {
762
+            if ( ! empty($this->_req_data['question_orders'][$question_ID])) {
763 763
                 // update question order
764 764
                 $question_group->update_question_order(
765 765
                     $question_ID,
766
-                    $this->_req_data['question_orders'][ $question_ID ]
766
+                    $this->_req_data['question_orders'][$question_ID]
767 767
                 );
768 768
             }
769 769
 
770 770
             // then we always check if adding or removing.
771
-            if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) {
771
+            if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) {
772 772
                 $question_group->add_question($question_ID);
773 773
             } else {
774 774
                 // not found, remove it (but only if not a system question for the personal group
@@ -791,8 +791,8 @@  discard block
 block discarded – undo
791 791
         if (isset($this->_req_data['questions'])) {
792 792
             foreach ($this->_req_data['questions'] as $QST_ID) {
793 793
                 $question_group->add_question($QST_ID);
794
-                if (isset($this->_req_data['question_orders'][ $QST_ID ])) {
795
-                    $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);
794
+                if (isset($this->_req_data['question_orders'][$QST_ID])) {
795
+                    $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]);
796 796
                 }
797 797
             }
798 798
         }
@@ -932,34 +932,34 @@  discard block
 block discarded – undo
932 932
         // echo "trash $trash";
933 933
         // var_dump($this->_req_data['checkbox']);die;
934 934
         if (isset($this->_req_data['checkbox'])) {
935
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
935
+            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
936 936
                 // if array has more than one element than success message should be plural
937 937
                 $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
938 938
                 // cycle thru bulk action checkboxes
939 939
                 $checkboxes = $this->_req_data['checkbox'];
940 940
                 foreach (array_keys($checkboxes) as $ID) {
941
-                    if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
941
+                    if ( ! $model->delete_or_restore_by_ID($trash, absint($ID))) {
942 942
                         $success = 0;
943 943
                     }
944 944
                 }
945 945
             } else {
946 946
                 // grab single id and delete
947 947
                 $ID = absint($this->_req_data['checkbox']);
948
-                if (! $model->delete_or_restore_by_ID($trash, $ID)) {
948
+                if ( ! $model->delete_or_restore_by_ID($trash, $ID)) {
949 949
                     $success = 0;
950 950
                 }
951 951
             }
952 952
         } else {
953 953
             // delete via trash link
954 954
             // grab single id and delete
955
-            $ID = absint($this->_req_data[ $model->primary_key_name() ]);
956
-            if (! $model->delete_or_restore_by_ID($trash, $ID)) {
955
+            $ID = absint($this->_req_data[$model->primary_key_name()]);
956
+            if ( ! $model->delete_or_restore_by_ID($trash, $ID)) {
957 957
                 $success = 0;
958 958
             }
959 959
         }
960 960
 
961 961
 
962
-        $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );
962
+        $action = $model instanceof EEM_Question ? 'default' : 'question_groups'; // strtolower( $model->item_name(2) );
963 963
         // echo "action :$action";
964 964
         // $action = 'questions' ? 'default' : $action;
965 965
         if ($trash) {
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
      */
1069 1069
     public function update_question_group_order()
1070 1070
     {
1071
-        if (! $this->capabilities->current_user_can('ee_edit_question_groups', __FUNCTION__)) {
1071
+        if ( ! $this->capabilities->current_user_can('ee_edit_question_groups', __FUNCTION__)) {
1072 1072
             wp_die(esc_html__('You do not have the required privileges to perform this action', 'event_espresso'));
1073 1073
         }
1074 1074
         $success = esc_html__('Question group order was updated successfully.', 'event_espresso');
@@ -1085,7 +1085,7 @@  discard block
 block discarded – undo
1085 1085
             ? (int) $this->_req_data['curpage']
1086 1086
             : null;
1087 1087
 
1088
-        if (! empty($row_ids)) {
1088
+        if ( ! empty($row_ids)) {
1089 1089
             // figure out where we start the row_id count at for the current page.
1090 1090
             $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
1091 1091
 
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
                 // Update the questions when re-ordering
1095 1095
                 $updated = EEM_Question_Group::instance()->update(
1096 1096
                     ['QSG_order' => $qsgcount],
1097
-                    [['QSG_ID' => $row_ids[ $i ]]]
1097
+                    [['QSG_ID' => $row_ids[$i]]]
1098 1098
                 );
1099 1099
                 if ($updated === false) {
1100 1100
                     $success = false;
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
         $this->_set_add_edit_form_tags('update_reg_form_settings');
1151 1151
         $this->_set_publish_post_box_vars();
1152 1152
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1153
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
1153
+            REGISTRATION_FORM_CAF_TEMPLATE_PATH.'reg_form_settings.template.php',
1154 1154
             $this->_template_args,
1155 1155
             true
1156 1156
         );
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
             'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
1180 1180
             EE_Registry::instance()->CFG->registration
1181 1181
         );
1182
-        $success                                   = $this->_update_espresso_configuration(
1182
+        $success = $this->_update_espresso_configuration(
1183 1183
             esc_html__('Registration Form Options', 'event_espresso'),
1184 1184
             EE_Registry::instance()->CFG,
1185 1185
             __FILE__,
@@ -1402,7 +1402,7 @@  discard block
 block discarded – undo
1402 1402
                                 $prev_email_validation_level = 'basic';
1403 1403
                             }
1404 1404
                             // confirm our i18n email validation will work on the server
1405
-                            if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1405
+                            if ( ! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1406 1406
                                 // or reset email validation level to previous value
1407 1407
                                 $email_validation_level = $prev_email_validation_level;
1408 1408
                             }
@@ -1446,7 +1446,7 @@  discard block
 block discarded – undo
1446 1446
     private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1447 1447
     {
1448 1448
         // first check that PCRE is enabled
1449
-        if (! defined('PREG_BAD_UTF8_ERROR')) {
1449
+        if ( ! defined('PREG_BAD_UTF8_ERROR')) {
1450 1450
             EE_Error::add_error(
1451 1451
                 sprintf(
1452 1452
                     esc_html__(
Please login to merge, or discard this patch.
caffeinated/admin/extend/support/Extend_Support_Admin_Page.core.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -11,75 +11,75 @@
 block discarded – undo
11 11
  */
12 12
 class Extend_Support_Admin_Page extends Support_Admin_Page
13 13
 {
14
-    public function __construct($routing = true)
15
-    {
16
-        parent::__construct($routing);
17
-        define('EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'support/templates/');
18
-    }
14
+	public function __construct($routing = true)
15
+	{
16
+		parent::__construct($routing);
17
+		define('EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'support/templates/');
18
+	}
19 19
 
20 20
 
21
-    protected function _set_page_config()
22
-    {
23
-        parent::_set_page_config();
21
+	protected function _set_page_config()
22
+	{
23
+		parent::_set_page_config();
24 24
 
25
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'support';
26
-        // new routes and new configs (or overrides )
27
-        $new_page_routes                              = [
28
-            'faq' => [
29
-                'func'       => [$this, '_faq'],
30
-                'capability' => 'ee_read_ee',
31
-            ],
32
-        ];
33
-        $this->_page_routes                           = array_merge($this->_page_routes, $new_page_routes);
34
-        $new_page_config                              = [
35
-            'faq' => [
36
-                'nav'           => [
37
-                    'label' => esc_html__('FAQ', 'event_espresso'),
38
-                    'icon'  => 'dashicons-editor-help',
39
-                    'order' => 40,
40
-                ],
41
-                'metaboxes'     => ['_espresso_news_post_box', '_espresso_links_post_box'],
42
-                'require_nonce' => false,
43
-            ],
44
-        ];
45
-        $this->_page_config                           = array_merge($this->_page_config, $new_page_config);
46
-        $this->_page_config['default']['metaboxes'][] = '_installation_boxes';
47
-    }
25
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'support';
26
+		// new routes and new configs (or overrides )
27
+		$new_page_routes                              = [
28
+			'faq' => [
29
+				'func'       => [$this, '_faq'],
30
+				'capability' => 'ee_read_ee',
31
+			],
32
+		];
33
+		$this->_page_routes                           = array_merge($this->_page_routes, $new_page_routes);
34
+		$new_page_config                              = [
35
+			'faq' => [
36
+				'nav'           => [
37
+					'label' => esc_html__('FAQ', 'event_espresso'),
38
+					'icon'  => 'dashicons-editor-help',
39
+					'order' => 40,
40
+				],
41
+				'metaboxes'     => ['_espresso_news_post_box', '_espresso_links_post_box'],
42
+				'require_nonce' => false,
43
+			],
44
+		];
45
+		$this->_page_config                           = array_merge($this->_page_config, $new_page_config);
46
+		$this->_page_config['default']['metaboxes'][] = '_installation_boxes';
47
+	}
48 48
 
49 49
 
50
-    protected function _faq()
51
-    {
52
-        $template_path                              =
53
-            EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH . 'support_admin_details_faq.template.php';
54
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
55
-            $template_path,
56
-            '',
57
-            true
58
-        );
59
-        $this->display_admin_page_with_sidebar();
60
-    }
50
+	protected function _faq()
51
+	{
52
+		$template_path                              =
53
+			EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH . 'support_admin_details_faq.template.php';
54
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
55
+			$template_path,
56
+			'',
57
+			true
58
+		);
59
+		$this->display_admin_page_with_sidebar();
60
+	}
61 61
 
62 62
 
63
-    protected function _installation_boxes()
64
-    {
65
-        $callback_args = [
66
-            'template_path' => EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH
67
-                               . 'support_admin_details_additional_information.template.php',
68
-        ];
69
-        $this->addMetaBox(
70
-            'espresso_additional_information_support',
71
-            esc_html__('Additional Information', 'event_espresso'),
72
-            function ($post, $metabox) {
73
-                echo EEH_Template::display_template(
74
-                    $metabox['args']['template_path'],
75
-                    '',
76
-                    true
77
-                );
78
-            },
79
-            $this->_current_screen->id,
80
-            'normal',
81
-            'high',
82
-            $callback_args
83
-        );
84
-    }
63
+	protected function _installation_boxes()
64
+	{
65
+		$callback_args = [
66
+			'template_path' => EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH
67
+							   . 'support_admin_details_additional_information.template.php',
68
+		];
69
+		$this->addMetaBox(
70
+			'espresso_additional_information_support',
71
+			esc_html__('Additional Information', 'event_espresso'),
72
+			function ($post, $metabox) {
73
+				echo EEH_Template::display_template(
74
+					$metabox['args']['template_path'],
75
+					'',
76
+					true
77
+				);
78
+			},
79
+			$this->_current_screen->id,
80
+			'normal',
81
+			'high',
82
+			$callback_args
83
+		);
84
+	}
85 85
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     public function __construct($routing = true)
15 15
     {
16 16
         parent::__construct($routing);
17
-        define('EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'support/templates/');
17
+        define('EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'support/templates/');
18 18
     }
19 19
 
20 20
 
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
     {
23 23
         parent::_set_page_config();
24 24
 
25
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'support';
25
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'support';
26 26
         // new routes and new configs (or overrides )
27
-        $new_page_routes                              = [
27
+        $new_page_routes = [
28 28
             'faq' => [
29 29
                 'func'       => [$this, '_faq'],
30 30
                 'capability' => 'ee_read_ee',
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     protected function _faq()
51 51
     {
52 52
         $template_path                              =
53
-            EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH . 'support_admin_details_faq.template.php';
53
+            EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH.'support_admin_details_faq.template.php';
54 54
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
55 55
             $template_path,
56 56
             '',
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         $this->addMetaBox(
70 70
             'espresso_additional_information_support',
71 71
             esc_html__('Additional Information', 'event_espresso'),
72
-            function ($post, $metabox) {
72
+            function($post, $metabox) {
73 73
                 echo EEH_Template::display_template(
74 74
                     $metabox['args']['template_path'],
75 75
                     '',
Please login to merge, or discard this patch.
admin/extend/transactions/Extend_Transactions_Admin_Page.core.php 1 patch
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -14,254 +14,254 @@
 block discarded – undo
14 14
  */
15 15
 class Extend_Transactions_Admin_Page extends Transactions_Admin_Page
16 16
 {
17
-    /**
18
-     * This is used to hold the reports template data which is setup early in the request.
19
-     *
20
-     * @type array
21
-     */
22
-    protected $_reports_template_data = [];
23
-
24
-
25
-    /**
26
-     * @Constructor
27
-     * @access public
28
-     *
29
-     * @param bool $routing
30
-     *
31
-     * @throws ReflectionException
32
-     */
33
-    public function __construct($routing = true)
34
-    {
35
-        parent::__construct($routing);
36
-        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
37
-        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
38
-        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
39
-    }
40
-
41
-
42
-    protected function _set_page_config()
43
-    {
44
-        parent::_set_page_config();
45
-
46
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
47
-
48
-        $new_page_routes = [
49
-            'reports' => [
50
-                'func'       => [$this, '_transaction_reports'],
51
-                'capability' => 'ee_read_transactions',
52
-            ],
53
-        ];
54
-
55
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
56
-
57
-        $new_page_config    = [
58
-            'reports' => [
59
-                'nav'           => [
60
-                    'label' => esc_html__('Reports', 'event_espresso'),
61
-                    'icon'  => 'dashicons-chart-bar',
62
-                    'order' => 20,
63
-                ],
64
-                'help_tabs'     => [
65
-                    'transactions_reports_help_tab' => [
66
-                        'title'    => esc_html__('Transaction Reports', 'event_espresso'),
67
-                        'filename' => 'transactions_reports',
68
-                    ],
69
-                ],
70
-                'require_nonce' => false,
71
-            ],
72
-        ];
73
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
74
-    }
75
-
76
-
77
-    /**
78
-     *    load_scripts_styles_reports
79
-     *
80
-     * @access public
81
-     * @return void
82
-     * @throws EE_Error
83
-     * @throws ReflectionException
84
-     */
85
-    public function load_scripts_styles_reports()
86
-    {
87
-        wp_register_script(
88
-            'ee-txn-reports-js',
89
-            TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
90
-            ['google-charts'],
91
-            EVENT_ESPRESSO_VERSION,
92
-            true
93
-        );
94
-        wp_enqueue_script('ee-txn-reports-js');
95
-        $this->_transaction_reports_js_setup();
96
-        EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
97
-    }
98
-
99
-
100
-    /**
101
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
102
-     * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
103
-     *
104
-     * @throws EE_Error
105
-     * @throws ReflectionException
106
-     */
107
-    protected function _transaction_reports_js_setup()
108
-    {
109
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
110
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
111
-    }
112
-
113
-
114
-    /**
115
-     * _transaction_reports
116
-     *    generates Business Reports regarding Transactions
117
-     *
118
-     * @return void
119
-     * @throws EE_Error
120
-     */
121
-    protected function _transaction_reports()
122
-    {
123
-        $template_path                              = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
124
-        $this->_admin_page_title                    = esc_html__('Transactions', 'event_espresso');
125
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
126
-            $template_path,
127
-            $this->_reports_template_data,
128
-            true
129
-        );
130
-
131
-        // the final template wrapper
132
-        $this->display_admin_page_with_no_sidebar();
133
-    }
134
-
135
-
136
-    /**
137
-     * _revenue_per_day_report
138
-     * generates Business Report showing Total Revenue per Day.
139
-     *
140
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
141
-     *
142
-     * @return string
143
-     * @throws EE_Error
144
-     * @throws ReflectionException
145
-     * @throws Exception
146
-     */
147
-    private function _revenue_per_day_report($period = '-1 month')
148
-    {
149
-        $report_ID = 'txn-admin-revenue-per-day-report-dv';
150
-
151
-        $TXN = EEM_Transaction::instance();
152
-
153
-        $results  = $TXN->get_revenue_per_day_report($period);
154
-        $results  = (array) $results;
155
-        $revenue  = [];
156
-        $subtitle = '';
157
-
158
-        if ($results) {
159
-            $revenue[] = [
160
-                esc_html__('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
161
-                esc_html__('Total Revenue', 'event_espresso'),
162
-            ];
163
-            foreach ($results as $result) {
164
-                $revenue[] = [$result->txnDate, (float) $result->revenue];
165
-            }
166
-
167
-            // setup the date range.
168
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
169
-            $ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
170
-            $subtitle       = sprintf(
171
-                wp_strip_all_tags(
172
-                    _x('For the period: %s to %s', 'Used to give date range', 'event_espresso')
173
-                ),
174
-                $beginning_date->format('Y-m-d'),
175
-                $ending_date->format('Y-m-d')
176
-            );
177
-        }
178
-
179
-        $report_title = wp_strip_all_tags(__('Total Revenue per Day', 'event_espresso'));
180
-
181
-        $report_params = [
182
-            'title'     => $report_title,
183
-            'subtitle'  => $subtitle,
184
-            'id'        => $report_ID,
185
-            'revenue'   => $revenue,
186
-            'noResults' => empty($revenue) || count($revenue) === 1,
187
-            'noTxnMsg'  => sprintf(
188
-                wp_strip_all_tags(
189
-                    __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
190
-                ),
191
-                '<h2>' . $report_title . '</h2><p>',
192
-                '</p>'
193
-            ),
194
-        ];
195
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
196
-
197
-        return $report_ID;
198
-    }
199
-
200
-
201
-    /**
202
-     * _revenue_per_event_report
203
-     * generates Business Report showing total revenue per event.
204
-     *
205
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
206
-     *
207
-     * @return int
208
-     * @throws EE_Error
209
-     * @throws ReflectionException
210
-     * @throws Exception
211
-     */
212
-    private function _revenue_per_event_report($period = '-1 month')
213
-    {
214
-        $report_ID = 'txn-admin-revenue-per-event-report-dv';
215
-
216
-        $TXN      = EEM_Transaction::instance();
217
-        $results  = $TXN->get_revenue_per_event_report($period);
218
-        $results  = (array) $results;
219
-        $revenue  = [];
220
-        $subtitle = '';
221
-
222
-        if ($results) {
223
-            $revenue[] = [
224
-                esc_html__('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
225
-                esc_html__('Total Revenue', 'event_espresso'),
226
-            ];
227
-            foreach ($results as $result) {
228
-                if ($result->revenue > 1) {
229
-                    $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
230
-                    $event_name = wp_trim_words($event_name, 5, '...');
231
-                    $revenue[]  = [$event_name, (float) $result->revenue];
232
-                }
233
-            }
234
-
235
-            // setup the date range.
236
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
237
-            $ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
238
-            $subtitle       = sprintf(
239
-                wp_strip_all_tags(
240
-                    _x('For the period: %s to %s', 'Used to give date range', 'event_espresso')
241
-                ),
242
-                $beginning_date->format('Y-m-d'),
243
-                $ending_date->format('Y-m-d')
244
-            );
245
-        }
246
-
247
-        $report_title = wp_strip_all_tags(__('Total Revenue per Event', 'event_espresso'));
248
-
249
-        $report_params = [
250
-            'title'     => $report_title,
251
-            'subtitle'  => $subtitle,
252
-            'id'        => $report_ID,
253
-            'revenue'   => $revenue,
254
-            'noResults' => empty($revenue),
255
-            'noTxnMsg'  => sprintf(
256
-                wp_strip_all_tags(
257
-                    __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
258
-                ),
259
-                '<h2>' . $report_title . '</h2><p>',
260
-                '</p>'
261
-            ),
262
-        ];
263
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
264
-
265
-        return $report_ID;
266
-    }
17
+	/**
18
+	 * This is used to hold the reports template data which is setup early in the request.
19
+	 *
20
+	 * @type array
21
+	 */
22
+	protected $_reports_template_data = [];
23
+
24
+
25
+	/**
26
+	 * @Constructor
27
+	 * @access public
28
+	 *
29
+	 * @param bool $routing
30
+	 *
31
+	 * @throws ReflectionException
32
+	 */
33
+	public function __construct($routing = true)
34
+	{
35
+		parent::__construct($routing);
36
+		define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
37
+		define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
38
+		define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
39
+	}
40
+
41
+
42
+	protected function _set_page_config()
43
+	{
44
+		parent::_set_page_config();
45
+
46
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
47
+
48
+		$new_page_routes = [
49
+			'reports' => [
50
+				'func'       => [$this, '_transaction_reports'],
51
+				'capability' => 'ee_read_transactions',
52
+			],
53
+		];
54
+
55
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
56
+
57
+		$new_page_config    = [
58
+			'reports' => [
59
+				'nav'           => [
60
+					'label' => esc_html__('Reports', 'event_espresso'),
61
+					'icon'  => 'dashicons-chart-bar',
62
+					'order' => 20,
63
+				],
64
+				'help_tabs'     => [
65
+					'transactions_reports_help_tab' => [
66
+						'title'    => esc_html__('Transaction Reports', 'event_espresso'),
67
+						'filename' => 'transactions_reports',
68
+					],
69
+				],
70
+				'require_nonce' => false,
71
+			],
72
+		];
73
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
74
+	}
75
+
76
+
77
+	/**
78
+	 *    load_scripts_styles_reports
79
+	 *
80
+	 * @access public
81
+	 * @return void
82
+	 * @throws EE_Error
83
+	 * @throws ReflectionException
84
+	 */
85
+	public function load_scripts_styles_reports()
86
+	{
87
+		wp_register_script(
88
+			'ee-txn-reports-js',
89
+			TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
90
+			['google-charts'],
91
+			EVENT_ESPRESSO_VERSION,
92
+			true
93
+		);
94
+		wp_enqueue_script('ee-txn-reports-js');
95
+		$this->_transaction_reports_js_setup();
96
+		EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
97
+	}
98
+
99
+
100
+	/**
101
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
102
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
103
+	 *
104
+	 * @throws EE_Error
105
+	 * @throws ReflectionException
106
+	 */
107
+	protected function _transaction_reports_js_setup()
108
+	{
109
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
110
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
111
+	}
112
+
113
+
114
+	/**
115
+	 * _transaction_reports
116
+	 *    generates Business Reports regarding Transactions
117
+	 *
118
+	 * @return void
119
+	 * @throws EE_Error
120
+	 */
121
+	protected function _transaction_reports()
122
+	{
123
+		$template_path                              = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
124
+		$this->_admin_page_title                    = esc_html__('Transactions', 'event_espresso');
125
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
126
+			$template_path,
127
+			$this->_reports_template_data,
128
+			true
129
+		);
130
+
131
+		// the final template wrapper
132
+		$this->display_admin_page_with_no_sidebar();
133
+	}
134
+
135
+
136
+	/**
137
+	 * _revenue_per_day_report
138
+	 * generates Business Report showing Total Revenue per Day.
139
+	 *
140
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
141
+	 *
142
+	 * @return string
143
+	 * @throws EE_Error
144
+	 * @throws ReflectionException
145
+	 * @throws Exception
146
+	 */
147
+	private function _revenue_per_day_report($period = '-1 month')
148
+	{
149
+		$report_ID = 'txn-admin-revenue-per-day-report-dv';
150
+
151
+		$TXN = EEM_Transaction::instance();
152
+
153
+		$results  = $TXN->get_revenue_per_day_report($period);
154
+		$results  = (array) $results;
155
+		$revenue  = [];
156
+		$subtitle = '';
157
+
158
+		if ($results) {
159
+			$revenue[] = [
160
+				esc_html__('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
161
+				esc_html__('Total Revenue', 'event_espresso'),
162
+			];
163
+			foreach ($results as $result) {
164
+				$revenue[] = [$result->txnDate, (float) $result->revenue];
165
+			}
166
+
167
+			// setup the date range.
168
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
169
+			$ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
170
+			$subtitle       = sprintf(
171
+				wp_strip_all_tags(
172
+					_x('For the period: %s to %s', 'Used to give date range', 'event_espresso')
173
+				),
174
+				$beginning_date->format('Y-m-d'),
175
+				$ending_date->format('Y-m-d')
176
+			);
177
+		}
178
+
179
+		$report_title = wp_strip_all_tags(__('Total Revenue per Day', 'event_espresso'));
180
+
181
+		$report_params = [
182
+			'title'     => $report_title,
183
+			'subtitle'  => $subtitle,
184
+			'id'        => $report_ID,
185
+			'revenue'   => $revenue,
186
+			'noResults' => empty($revenue) || count($revenue) === 1,
187
+			'noTxnMsg'  => sprintf(
188
+				wp_strip_all_tags(
189
+					__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
190
+				),
191
+				'<h2>' . $report_title . '</h2><p>',
192
+				'</p>'
193
+			),
194
+		];
195
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
196
+
197
+		return $report_ID;
198
+	}
199
+
200
+
201
+	/**
202
+	 * _revenue_per_event_report
203
+	 * generates Business Report showing total revenue per event.
204
+	 *
205
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
206
+	 *
207
+	 * @return int
208
+	 * @throws EE_Error
209
+	 * @throws ReflectionException
210
+	 * @throws Exception
211
+	 */
212
+	private function _revenue_per_event_report($period = '-1 month')
213
+	{
214
+		$report_ID = 'txn-admin-revenue-per-event-report-dv';
215
+
216
+		$TXN      = EEM_Transaction::instance();
217
+		$results  = $TXN->get_revenue_per_event_report($period);
218
+		$results  = (array) $results;
219
+		$revenue  = [];
220
+		$subtitle = '';
221
+
222
+		if ($results) {
223
+			$revenue[] = [
224
+				esc_html__('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
225
+				esc_html__('Total Revenue', 'event_espresso'),
226
+			];
227
+			foreach ($results as $result) {
228
+				if ($result->revenue > 1) {
229
+					$event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
230
+					$event_name = wp_trim_words($event_name, 5, '...');
231
+					$revenue[]  = [$event_name, (float) $result->revenue];
232
+				}
233
+			}
234
+
235
+			// setup the date range.
236
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
237
+			$ending_date    = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
238
+			$subtitle       = sprintf(
239
+				wp_strip_all_tags(
240
+					_x('For the period: %s to %s', 'Used to give date range', 'event_espresso')
241
+				),
242
+				$beginning_date->format('Y-m-d'),
243
+				$ending_date->format('Y-m-d')
244
+			);
245
+		}
246
+
247
+		$report_title = wp_strip_all_tags(__('Total Revenue per Event', 'event_espresso'));
248
+
249
+		$report_params = [
250
+			'title'     => $report_title,
251
+			'subtitle'  => $subtitle,
252
+			'id'        => $report_ID,
253
+			'revenue'   => $revenue,
254
+			'noResults' => empty($revenue),
255
+			'noTxnMsg'  => sprintf(
256
+				wp_strip_all_tags(
257
+					__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
258
+				),
259
+				'<h2>' . $report_title . '</h2><p>',
260
+				'</p>'
261
+			),
262
+		];
263
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
264
+
265
+		return $report_ID;
266
+	}
267 267
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/messages/Extend_Messages_Admin_Page.core.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -13,201 +13,201 @@
 block discarded – undo
13 13
  */
14 14
 class Extend_Messages_Admin_Page extends Messages_Admin_Page
15 15
 {
16
-    public function __construct($routing = true)
17
-    {
18
-        parent::__construct($routing);
19
-        if (! defined('EE_MSG_CAF_ASSETS_PATH')) {
20
-            define('EE_MSG_CAF_ASSETS_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'messages/assets/');
21
-            define('EE_MSG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
22
-            define('EE_MSG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/');
23
-            define('EE_MSG_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/templates/');
24
-        }
25
-    }
26
-
27
-
28
-    protected function _set_page_config()
29
-    {
30
-        parent::_set_page_config();
31
-
32
-        $this->_admin_base_path            = EE_CORE_CAF_ADMIN_EXTEND . 'messages';
33
-        $this->_page_routes['custom_mtps'] = [
34
-            'func'       => [$this, '_ee_custom_messages_overview_list_table'],
35
-            'capability' => 'ee_read_messages',
36
-        ];
37
-        $this->_page_config['custom_mtps'] = [
38
-            'nav'           => [
39
-                'label' => esc_html__('Custom Message Templates', 'event_espresso'),
40
-                'icon'  => 'dashicons-art',
41
-                'order' => 30,
42
-            ],
43
-            'list_table'    => 'Custom_Messages_Template_List_Table',
44
-            'help_tabs'     => [
45
-                'message_overview_message_types_help_tab' => [
46
-                    'title'    => esc_html__('Message Types', 'event_espresso'),
47
-                    'filename' => 'messages_overview_types',
48
-                ],
49
-                'messages_overview_messengers_help_tab'   => [
50
-                    'title'    => esc_html__('Messengers', 'event_espresso'),
51
-                    'filename' => 'messages_overview_messengers',
52
-                ],
53
-                'messages_overview_other_help_tab'        => [
54
-                    'title'    => esc_html__('Messages Other', 'event_espresso'),
55
-                    'filename' => 'messages_overview_other',
56
-                ],
57
-            ],
58
-            'require_nonce' => false,
59
-        ];
60
-
61
-        add_action('current_screen', [$this, 'dynamic_screen_hooks']);
62
-    }
63
-
64
-
65
-    /**
66
-     * Callback for current_screen action
67
-     * This is used for any filters and/or actions that require the dynamic screen hook_prefix to be correct.
68
-     *
69
-     * @return void
70
-     * @since 4.5.0
71
-     *
72
-     */
73
-    public function dynamic_screen_hooks()
74
-    {
75
-        global $admin_page_hooks;
76
-
77
-        if (! empty($admin_page_hooks['espresso_events'])) {
78
-            // we're on a EE specific page... good stuff!
79
-            $hook_prefix = $admin_page_hooks['espresso_events'];
80
-            $filter_ref  = "{$hook_prefix}_page_$this->page_slug";
81
-            add_filter("FHEE_manage_{$filter_ref}_columns", [$this, 'add_custom_mtps_columns'], 10, 3);
82
-            add_action(
83
-                'AHEE__EE_Admin_List_Table__column_actions__' . $filter_ref,
84
-                [$this, 'custom_mtp_create_button_column'],
85
-                10,
86
-                2
87
-            );
88
-        }
89
-    }
90
-
91
-
92
-    /**
93
-     * This is the callback for the FHEE__manage_event-espresso_page_espresso_messages_columns to register the
94
-     * caffeinated columns for the global message templates list table.
95
-     *
96
-     * @param array  $columns   Original defined list of columns
97
-     * @param string $screen_id The unique screen id for the page.
98
-     * @return array
99
-     * @since 4.3.2
100
-     *
101
-     */
102
-    public function add_custom_mtps_columns($columns, $screen_id, EE_Admin_List_Table $list_table)
103
-    {
104
-        if ($screen_id !== 'espresso_messages_global_mtps') {
105
-            return $columns;
106
-        }
107
-        $columns['actions'] = $list_table->actionsColumnHeader();
108
-        return $columns;
109
-    }
110
-
111
-
112
-    /**
113
-     * Callback for FHEE__EE_Admin_List_Table__column_actions__event-espresso_page_espresso_messages action that allows
114
-     * for adding the content for the registered "action" column.
115
-     *
116
-     * @param EE_Base_Class
117
-     * @param string $screen_id Unique screen id for the page
118
-     *
119
-     * @return string html content for the page.
120
-     * @throws EE_Error
121
-     * @throws ReflectionException
122
-     * @since 4.3.2
123
-     */
124
-    public function custom_mtp_create_button_column(EE_Base_Class $item, string $screen_id)
125
-    {
126
-        if (
127
-            $screen_id !== 'espresso_messages_global_mtps'
128
-            || ! EE_Registry::instance()->CAP->current_user_can(
129
-                'ee_edit_messages',
130
-                'espresso_messages_add_new_message_template'
131
-            )
132
-        ) {
133
-            return '';
134
-        }
135
-
136
-        // first we consider whether this template has override set.  If it does then that means no custom templates can be created from this template as a base.  So let's just skip the button creation.
137
-        if ($item->get('MTP_is_override')) {
138
-            return '';
139
-        }
140
-
141
-        $create_link = EE_Admin_Page::add_query_args_and_nonce(
142
-            [
143
-                'GRP_ID'       => $item->ID(),
144
-                'messenger'    => $item->messenger(),
145
-                'message_type' => $item->message_type(),
146
-                'action'       => 'add_new_message_template',
147
-            ],
148
-            EE_MSG_ADMIN_URL
149
-        );
150
-        $aria_label  = esc_html__('Create Custom Message Template', 'event_espresso');
151
-        echo "
16
+	public function __construct($routing = true)
17
+	{
18
+		parent::__construct($routing);
19
+		if (! defined('EE_MSG_CAF_ASSETS_PATH')) {
20
+			define('EE_MSG_CAF_ASSETS_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'messages/assets/');
21
+			define('EE_MSG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
22
+			define('EE_MSG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/');
23
+			define('EE_MSG_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/templates/');
24
+		}
25
+	}
26
+
27
+
28
+	protected function _set_page_config()
29
+	{
30
+		parent::_set_page_config();
31
+
32
+		$this->_admin_base_path            = EE_CORE_CAF_ADMIN_EXTEND . 'messages';
33
+		$this->_page_routes['custom_mtps'] = [
34
+			'func'       => [$this, '_ee_custom_messages_overview_list_table'],
35
+			'capability' => 'ee_read_messages',
36
+		];
37
+		$this->_page_config['custom_mtps'] = [
38
+			'nav'           => [
39
+				'label' => esc_html__('Custom Message Templates', 'event_espresso'),
40
+				'icon'  => 'dashicons-art',
41
+				'order' => 30,
42
+			],
43
+			'list_table'    => 'Custom_Messages_Template_List_Table',
44
+			'help_tabs'     => [
45
+				'message_overview_message_types_help_tab' => [
46
+					'title'    => esc_html__('Message Types', 'event_espresso'),
47
+					'filename' => 'messages_overview_types',
48
+				],
49
+				'messages_overview_messengers_help_tab'   => [
50
+					'title'    => esc_html__('Messengers', 'event_espresso'),
51
+					'filename' => 'messages_overview_messengers',
52
+				],
53
+				'messages_overview_other_help_tab'        => [
54
+					'title'    => esc_html__('Messages Other', 'event_espresso'),
55
+					'filename' => 'messages_overview_other',
56
+				],
57
+			],
58
+			'require_nonce' => false,
59
+		];
60
+
61
+		add_action('current_screen', [$this, 'dynamic_screen_hooks']);
62
+	}
63
+
64
+
65
+	/**
66
+	 * Callback for current_screen action
67
+	 * This is used for any filters and/or actions that require the dynamic screen hook_prefix to be correct.
68
+	 *
69
+	 * @return void
70
+	 * @since 4.5.0
71
+	 *
72
+	 */
73
+	public function dynamic_screen_hooks()
74
+	{
75
+		global $admin_page_hooks;
76
+
77
+		if (! empty($admin_page_hooks['espresso_events'])) {
78
+			// we're on a EE specific page... good stuff!
79
+			$hook_prefix = $admin_page_hooks['espresso_events'];
80
+			$filter_ref  = "{$hook_prefix}_page_$this->page_slug";
81
+			add_filter("FHEE_manage_{$filter_ref}_columns", [$this, 'add_custom_mtps_columns'], 10, 3);
82
+			add_action(
83
+				'AHEE__EE_Admin_List_Table__column_actions__' . $filter_ref,
84
+				[$this, 'custom_mtp_create_button_column'],
85
+				10,
86
+				2
87
+			);
88
+		}
89
+	}
90
+
91
+
92
+	/**
93
+	 * This is the callback for the FHEE__manage_event-espresso_page_espresso_messages_columns to register the
94
+	 * caffeinated columns for the global message templates list table.
95
+	 *
96
+	 * @param array  $columns   Original defined list of columns
97
+	 * @param string $screen_id The unique screen id for the page.
98
+	 * @return array
99
+	 * @since 4.3.2
100
+	 *
101
+	 */
102
+	public function add_custom_mtps_columns($columns, $screen_id, EE_Admin_List_Table $list_table)
103
+	{
104
+		if ($screen_id !== 'espresso_messages_global_mtps') {
105
+			return $columns;
106
+		}
107
+		$columns['actions'] = $list_table->actionsColumnHeader();
108
+		return $columns;
109
+	}
110
+
111
+
112
+	/**
113
+	 * Callback for FHEE__EE_Admin_List_Table__column_actions__event-espresso_page_espresso_messages action that allows
114
+	 * for adding the content for the registered "action" column.
115
+	 *
116
+	 * @param EE_Base_Class
117
+	 * @param string $screen_id Unique screen id for the page
118
+	 *
119
+	 * @return string html content for the page.
120
+	 * @throws EE_Error
121
+	 * @throws ReflectionException
122
+	 * @since 4.3.2
123
+	 */
124
+	public function custom_mtp_create_button_column(EE_Base_Class $item, string $screen_id)
125
+	{
126
+		if (
127
+			$screen_id !== 'espresso_messages_global_mtps'
128
+			|| ! EE_Registry::instance()->CAP->current_user_can(
129
+				'ee_edit_messages',
130
+				'espresso_messages_add_new_message_template'
131
+			)
132
+		) {
133
+			return '';
134
+		}
135
+
136
+		// first we consider whether this template has override set.  If it does then that means no custom templates can be created from this template as a base.  So let's just skip the button creation.
137
+		if ($item->get('MTP_is_override')) {
138
+			return '';
139
+		}
140
+
141
+		$create_link = EE_Admin_Page::add_query_args_and_nonce(
142
+			[
143
+				'GRP_ID'       => $item->ID(),
144
+				'messenger'    => $item->messenger(),
145
+				'message_type' => $item->message_type(),
146
+				'action'       => 'add_new_message_template',
147
+			],
148
+			EE_MSG_ADMIN_URL
149
+		);
150
+		$aria_label  = esc_html__('Create Custom Message Template', 'event_espresso');
151
+		echo "
152 152
         <a href='$create_link' class='ee-aria-tooltip button button--icon-only' aria-label='$aria_label'>
153 153
             <span class='dashicons dashicons-admin-customizer'></span>
154 154
         </a>";
155
-        return '';
156
-    }
157
-
158
-
159
-    protected function _add_screen_options_custom_mtps()
160
-    {
161
-        $page_title              = $this->_admin_page_title;
162
-        $this->_admin_page_title = esc_html__('Custom Message Templates', 'event_espresso');
163
-        $this->_per_page_screen_option();
164
-        $this->_admin_page_title = $page_title;
165
-    }
166
-
167
-
168
-    /**
169
-     * set views array for Custom Templates list table
170
-     *
171
-     * @access public
172
-     * @return void
173
-     */
174
-    public function _set_list_table_views_custom_mtps()
175
-    {
176
-        $this->_views = [
177
-            'in_use' => [
178
-                'slug'        => 'in_use',
179
-                'label'       => esc_html__('In Use', 'event_espresso'),
180
-                'count'       => 0,
181
-                'bulk_action' => [
182
-                    'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
183
-                ],
184
-            ],
185
-        ];
186
-        if (
187
-            EE_Registry::instance()->CAP->current_user_can(
188
-                'ee_delete_messages',
189
-                'espresso_messages_trash_message_template'
190
-            )
191
-        ) {
192
-            $this->_views['trashed'] = [
193
-                'slug'        => 'trashed',
194
-                'label'       => esc_html__('Trash', 'event_espresso'),
195
-                'count'       => 0,
196
-                'bulk_action' => [
197
-                    'restore_message_template' => esc_html__('Restore From Trash', 'event_espresso'),
198
-                    'delete_message_template'  => esc_html__('Delete Permanently', 'event_espresso'),
199
-                ],
200
-            ];
201
-        }
202
-    }
203
-
204
-
205
-    /**
206
-     * @throws EE_Error
207
-     */
208
-    protected function _ee_custom_messages_overview_list_table()
209
-    {
210
-        $this->_admin_page_title = esc_html__('Custom Message Templates', 'event_espresso');
211
-        $this->display_admin_list_table_page_with_no_sidebar();
212
-    }
155
+		return '';
156
+	}
157
+
158
+
159
+	protected function _add_screen_options_custom_mtps()
160
+	{
161
+		$page_title              = $this->_admin_page_title;
162
+		$this->_admin_page_title = esc_html__('Custom Message Templates', 'event_espresso');
163
+		$this->_per_page_screen_option();
164
+		$this->_admin_page_title = $page_title;
165
+	}
166
+
167
+
168
+	/**
169
+	 * set views array for Custom Templates list table
170
+	 *
171
+	 * @access public
172
+	 * @return void
173
+	 */
174
+	public function _set_list_table_views_custom_mtps()
175
+	{
176
+		$this->_views = [
177
+			'in_use' => [
178
+				'slug'        => 'in_use',
179
+				'label'       => esc_html__('In Use', 'event_espresso'),
180
+				'count'       => 0,
181
+				'bulk_action' => [
182
+					'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
183
+				],
184
+			],
185
+		];
186
+		if (
187
+			EE_Registry::instance()->CAP->current_user_can(
188
+				'ee_delete_messages',
189
+				'espresso_messages_trash_message_template'
190
+			)
191
+		) {
192
+			$this->_views['trashed'] = [
193
+				'slug'        => 'trashed',
194
+				'label'       => esc_html__('Trash', 'event_espresso'),
195
+				'count'       => 0,
196
+				'bulk_action' => [
197
+					'restore_message_template' => esc_html__('Restore From Trash', 'event_espresso'),
198
+					'delete_message_template'  => esc_html__('Delete Permanently', 'event_espresso'),
199
+				],
200
+			];
201
+		}
202
+	}
203
+
204
+
205
+	/**
206
+	 * @throws EE_Error
207
+	 */
208
+	protected function _ee_custom_messages_overview_list_table()
209
+	{
210
+		$this->_admin_page_title = esc_html__('Custom Message Templates', 'event_espresso');
211
+		$this->display_admin_list_table_page_with_no_sidebar();
212
+	}
213 213
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,11 +16,11 @@  discard block
 block discarded – undo
16 16
     public function __construct($routing = true)
17 17
     {
18 18
         parent::__construct($routing);
19
-        if (! defined('EE_MSG_CAF_ASSETS_PATH')) {
20
-            define('EE_MSG_CAF_ASSETS_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'messages/assets/');
21
-            define('EE_MSG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
22
-            define('EE_MSG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/');
23
-            define('EE_MSG_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/templates/');
19
+        if ( ! defined('EE_MSG_CAF_ASSETS_PATH')) {
20
+            define('EE_MSG_CAF_ASSETS_PATH', EE_CORE_CAF_ADMIN_EXTEND.'messages/assets/');
21
+            define('EE_MSG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/');
22
+            define('EE_MSG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/');
23
+            define('EE_MSG_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/templates/');
24 24
         }
25 25
     }
26 26
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     {
30 30
         parent::_set_page_config();
31 31
 
32
-        $this->_admin_base_path            = EE_CORE_CAF_ADMIN_EXTEND . 'messages';
32
+        $this->_admin_base_path            = EE_CORE_CAF_ADMIN_EXTEND.'messages';
33 33
         $this->_page_routes['custom_mtps'] = [
34 34
             'func'       => [$this, '_ee_custom_messages_overview_list_table'],
35 35
             'capability' => 'ee_read_messages',
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
     {
75 75
         global $admin_page_hooks;
76 76
 
77
-        if (! empty($admin_page_hooks['espresso_events'])) {
77
+        if ( ! empty($admin_page_hooks['espresso_events'])) {
78 78
             // we're on a EE specific page... good stuff!
79 79
             $hook_prefix = $admin_page_hooks['espresso_events'];
80 80
             $filter_ref  = "{$hook_prefix}_page_$this->page_slug";
81 81
             add_filter("FHEE_manage_{$filter_ref}_columns", [$this, 'add_custom_mtps_columns'], 10, 3);
82 82
             add_action(
83
-                'AHEE__EE_Admin_List_Table__column_actions__' . $filter_ref,
83
+                'AHEE__EE_Admin_List_Table__column_actions__'.$filter_ref,
84 84
                 [$this, 'custom_mtp_create_button_column'],
85 85
                 10,
86 86
                 2
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
             ],
148 148
             EE_MSG_ADMIN_URL
149 149
         );
150
-        $aria_label  = esc_html__('Create Custom Message Template', 'event_espresso');
150
+        $aria_label = esc_html__('Create Custom Message Template', 'event_espresso');
151 151
         echo "
152 152
         <a href='$create_link' class='ee-aria-tooltip button button--icon-only' aria-label='$aria_label'>
153 153
             <span class='dashicons dashicons-admin-customizer'></span>
Please login to merge, or discard this patch.
caffeinated/admin/new/tickets/Tickets_Admin_Page.core.php 1 patch
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -11,314 +11,314 @@
 block discarded – undo
11 11
  */
12 12
 class Tickets_Admin_Page extends EE_Admin_Page
13 13
 {
14
-    protected function _init_page_props()
15
-    {
16
-        $this->page_slug = TICKETS_PG_SLUG;
17
-        $this->page_label = TICKETS_LABEL;
18
-        $this->_admin_base_url = TICKETS_ADMIN_URL;
19
-        $this->_admin_base_path = TICKETS_ADMIN;
20
-    }
21
-
22
-
23
-    protected function _ajax_hooks()
24
-    {
25
-    }
26
-
27
-
28
-    protected function _define_page_props()
29
-    {
30
-        $this->_admin_page_title = TICKETS_LABEL;
31
-        $this->_labels = array(
32
-            'buttons' => array(
33
-                'add'    => esc_html__('Add New Default Ticket', 'event_espresso'),
34
-                'edit'   => esc_html__('Edit Default Ticket', 'event_espresso'),
35
-                'delete' => esc_html__('Delete Default Ticket', 'event_espresso'),
36
-            ),
37
-        );
38
-    }
39
-
40
-
41
-    protected function _set_page_routes()
42
-    {
43
-
44
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
45
-            ? $this->_req_data['TKT_ID'] : 0;
46
-
47
-        $this->_page_routes = array(
48
-            'default'         => array(
49
-                'func'       => [$this, '_tickets_overview_list_table'],
50
-                'capability' => 'ee_read_default_tickets',
51
-            ),
52
-            'trash_ticket'    => array(
53
-                'func'       => [$this, '_trash_or_restore_ticket'],
54
-                'noheader'   => true,
55
-                'args'       => array('trash' => true),
56
-                'capability' => 'ee_delete_default_ticket',
57
-                'obj_id'     => $tkt_id,
58
-            ),
59
-            'trash_tickets'   => array(
60
-                'func'       => [$this, '_trash_or_restore_ticket'],
61
-                'noheader'   => true,
62
-                'args'       => array('trash' => true),
63
-                'capability' => 'ee_delete_default_tickets',
64
-            ),
65
-            'restore_ticket'  => array(
66
-                'func'       => [$this, '_trash_or_restore_ticket'],
67
-                'noheader'   => true,
68
-                'capability' => 'ee_delete_default_ticket',
69
-                'obj_id'     => $tkt_id,
70
-            ),
71
-            'restore_tickets' => array(
72
-                'func'       => [$this, '_trash_or_restore_ticket'],
73
-                'noheader'   => true,
74
-                'capability' => 'ee_delete_default_tickets',
75
-            ),
76
-            'delete_ticket'   => array(
77
-                'func'       => [$this, '_delete_ticket'],
78
-                'noheader'   => true,
79
-                'capability' => 'ee_delete_default_ticket',
80
-                'obj_id'     => $tkt_id,
81
-            ),
82
-            'delete_tickets'  => array(
83
-                'func'       => [$this, '_delete_ticket'],
84
-                'noheader'   => true,
85
-                'capability' => 'ee_delete_default_tickets',
86
-            ),
87
-        );
88
-    }
89
-
90
-
91
-    protected function _set_page_config()
92
-    {
93
-        $this->_page_config = array(
94
-            'default' => array(
95
-                'nav'           => array(
96
-                    'label' => esc_html__('Default Tickets', 'event_espresso'),
97
-                    'order' => 10,
98
-                ),
99
-                'list_table'    => 'Tickets_List_Table',
100
-                'require_nonce' => false,
101
-            ),
102
-        );
103
-    }
104
-
105
-
106
-    protected function _add_screen_options()
107
-    {
108
-    }
109
-
110
-    protected function _add_screen_options_default()
111
-    {
112
-        $this->_per_page_screen_option();
113
-    }
114
-
115
-
116
-    protected function _add_feature_pointers()
117
-    {
118
-    }
119
-
120
-    public function load_scripts_styles()
121
-    {
122
-    }
123
-
124
-    public function load_scripts_styles_default()
125
-    {
126
-    }
127
-
128
-    public function admin_footer_scripts()
129
-    {
130
-    }
131
-
132
-    public function admin_init()
133
-    {
134
-    }
135
-
136
-    public function admin_notices()
137
-    {
138
-    }
139
-
140
-
141
-    public function _set_list_table_views_default()
142
-    {
143
-        $this->_views = array(
144
-            'all'     => array(
145
-                'slug'        => 'all',
146
-                'label'       => esc_html__('All', 'event_espresso'),
147
-                'count'       => 0,
148
-                'bulk_action' => array(
149
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
150
-                ),
151
-            ),
152
-            'trashed' => array(
153
-                'slug'        => 'trashed',
154
-                'label'       => esc_html__('Trash', 'event_espresso'),
155
-                'count'       => 0,
156
-                'bulk_action' => array(
157
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
158
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
159
-                ),
160
-            ),
161
-        );
162
-    }
163
-
164
-
165
-    public function _tickets_overview_list_table()
166
-    {
167
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
168
-        $this->display_admin_list_table_page_with_no_sidebar();
169
-    }
170
-
171
-
172
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
173
-    {
174
-
175
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
176
-        $order = empty($this->_req_data['order']) ? 'ASC' : $order;
177
-
178
-        switch ($orderby) {
179
-            case 'TKT_name':
180
-                $orderby = array('TKT_name' => $order);
181
-                break;
182
-
183
-            case 'TKT_price':
184
-                $orderby = array('TKT_price' => $order);
185
-                break;
186
-
187
-            case 'TKT_uses':
188
-                $orderby = array('TKT_uses' => $order);
189
-                break;
190
-
191
-            case 'TKT_min':
192
-                $orderby = array('TKT_min' => $order);
193
-                break;
194
-
195
-            case 'TKT_max':
196
-                $orderby = array('TKT_max' => $order);
197
-                break;
198
-
199
-            case 'TKT_qty':
200
-                $orderby = array('TKT_qty' => $order);
201
-                break;
202
-        }
203
-
204
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
205
-            ? $this->_req_data['paged'] : 1;
206
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
207
-            ? $this->_req_data['perpage'] : $per_page;
208
-
209
-        $_where = array(
210
-            'TKT_is_default' => 1,
211
-            'TKT_deleted'    => $trashed,
212
-        );
213
-
214
-        $offset = ($current_page - 1) * $per_page;
215
-        $limit = array($offset, $per_page);
216
-
217
-        if (isset($this->_req_data['s'])) {
218
-            $sstr = '%' . $this->_req_data['s'] . '%';
219
-            $_where['OR'] = array(
220
-                'TKT_name'        => array('LIKE', $sstr),
221
-                'TKT_description' => array('LIKE', $sstr),
222
-            );
223
-        }
224
-
225
-        $query_params = array(
226
-            $_where,
227
-            'order_by' => $orderby,
228
-            'limit'    => $limit,
229
-            'group_by' => 'TKT_ID',
230
-        );
231
-
232
-        if ($count) {
233
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
234
-        } else {
235
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
236
-        }
237
-    }
238
-
239
-
240
-    protected function _trash_or_restore_ticket($trash = false)
241
-    {
242
-        $success = 1;
243
-
244
-        $TKT = EEM_Ticket::instance();
245
-
246
-        // checkboxes?
247
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
248
-            // if array has more than one element then success message should be plural
249
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
250
-
251
-            // cycle thru the boxes
252
-            $checkboxes = $this->_req_data['checkbox'];
253
-            foreach (array_keys($checkboxes) as $TKT_ID) {
254
-                if ($trash) {
255
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
256
-                        $success = 0;
257
-                    }
258
-                    continue;
259
-                }
260
-                if (! $TKT->restore_by_ID($TKT_ID)) {
261
-                    $success = 0;
262
-                }
263
-            }
264
-        } else {
265
-            // grab single id and trash
266
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
267
-
268
-            if ($trash) {
269
-                if (! $TKT->delete_by_ID($TKT_ID)) {
270
-                    $success = 0;
271
-                }
272
-            } else {
273
-                if (! $TKT->restore_by_ID($TKT_ID)) {
274
-                    $success = 0;
275
-                }
276
-            }
277
-        }
278
-
279
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
280
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, array());
281
-    }
282
-
283
-
284
-    protected function _delete_ticket()
285
-    {
286
-        $success = 1;
287
-
288
-        $TKT = EEM_Ticket::instance();
289
-
290
-        // checkboxes?
291
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
292
-            // if array has more than one element then success message should be plural
293
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
294
-
295
-            // cycle thru the boxes
296
-            $checkboxes = $this->_req_data['checkbox'];
297
-            foreach (array_keys($checkboxes) as $TKT_ID) {
298
-                // delete
299
-                if (! $this->_delete_the_ticket($TKT_ID)) {
300
-                    $success = 0;
301
-                }
302
-            }
303
-        } else {
304
-            // grab single id and trash
305
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
306
-            if (! $this->_delete_the_ticket($TKT_ID)) {
307
-                $success = 0;
308
-            }
309
-        }
310
-
311
-        $action_desc = 'deleted';
312
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, array());
313
-    }
314
-
315
-
316
-    protected function _delete_the_ticket($TKT_ID)
317
-    {
318
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
319
-
320
-        // delete all related prices first
321
-        $tkt->delete_related_permanently('Price');
322
-        return $tkt->delete_permanently();
323
-    }
14
+	protected function _init_page_props()
15
+	{
16
+		$this->page_slug = TICKETS_PG_SLUG;
17
+		$this->page_label = TICKETS_LABEL;
18
+		$this->_admin_base_url = TICKETS_ADMIN_URL;
19
+		$this->_admin_base_path = TICKETS_ADMIN;
20
+	}
21
+
22
+
23
+	protected function _ajax_hooks()
24
+	{
25
+	}
26
+
27
+
28
+	protected function _define_page_props()
29
+	{
30
+		$this->_admin_page_title = TICKETS_LABEL;
31
+		$this->_labels = array(
32
+			'buttons' => array(
33
+				'add'    => esc_html__('Add New Default Ticket', 'event_espresso'),
34
+				'edit'   => esc_html__('Edit Default Ticket', 'event_espresso'),
35
+				'delete' => esc_html__('Delete Default Ticket', 'event_espresso'),
36
+			),
37
+		);
38
+	}
39
+
40
+
41
+	protected function _set_page_routes()
42
+	{
43
+
44
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
45
+			? $this->_req_data['TKT_ID'] : 0;
46
+
47
+		$this->_page_routes = array(
48
+			'default'         => array(
49
+				'func'       => [$this, '_tickets_overview_list_table'],
50
+				'capability' => 'ee_read_default_tickets',
51
+			),
52
+			'trash_ticket'    => array(
53
+				'func'       => [$this, '_trash_or_restore_ticket'],
54
+				'noheader'   => true,
55
+				'args'       => array('trash' => true),
56
+				'capability' => 'ee_delete_default_ticket',
57
+				'obj_id'     => $tkt_id,
58
+			),
59
+			'trash_tickets'   => array(
60
+				'func'       => [$this, '_trash_or_restore_ticket'],
61
+				'noheader'   => true,
62
+				'args'       => array('trash' => true),
63
+				'capability' => 'ee_delete_default_tickets',
64
+			),
65
+			'restore_ticket'  => array(
66
+				'func'       => [$this, '_trash_or_restore_ticket'],
67
+				'noheader'   => true,
68
+				'capability' => 'ee_delete_default_ticket',
69
+				'obj_id'     => $tkt_id,
70
+			),
71
+			'restore_tickets' => array(
72
+				'func'       => [$this, '_trash_or_restore_ticket'],
73
+				'noheader'   => true,
74
+				'capability' => 'ee_delete_default_tickets',
75
+			),
76
+			'delete_ticket'   => array(
77
+				'func'       => [$this, '_delete_ticket'],
78
+				'noheader'   => true,
79
+				'capability' => 'ee_delete_default_ticket',
80
+				'obj_id'     => $tkt_id,
81
+			),
82
+			'delete_tickets'  => array(
83
+				'func'       => [$this, '_delete_ticket'],
84
+				'noheader'   => true,
85
+				'capability' => 'ee_delete_default_tickets',
86
+			),
87
+		);
88
+	}
89
+
90
+
91
+	protected function _set_page_config()
92
+	{
93
+		$this->_page_config = array(
94
+			'default' => array(
95
+				'nav'           => array(
96
+					'label' => esc_html__('Default Tickets', 'event_espresso'),
97
+					'order' => 10,
98
+				),
99
+				'list_table'    => 'Tickets_List_Table',
100
+				'require_nonce' => false,
101
+			),
102
+		);
103
+	}
104
+
105
+
106
+	protected function _add_screen_options()
107
+	{
108
+	}
109
+
110
+	protected function _add_screen_options_default()
111
+	{
112
+		$this->_per_page_screen_option();
113
+	}
114
+
115
+
116
+	protected function _add_feature_pointers()
117
+	{
118
+	}
119
+
120
+	public function load_scripts_styles()
121
+	{
122
+	}
123
+
124
+	public function load_scripts_styles_default()
125
+	{
126
+	}
127
+
128
+	public function admin_footer_scripts()
129
+	{
130
+	}
131
+
132
+	public function admin_init()
133
+	{
134
+	}
135
+
136
+	public function admin_notices()
137
+	{
138
+	}
139
+
140
+
141
+	public function _set_list_table_views_default()
142
+	{
143
+		$this->_views = array(
144
+			'all'     => array(
145
+				'slug'        => 'all',
146
+				'label'       => esc_html__('All', 'event_espresso'),
147
+				'count'       => 0,
148
+				'bulk_action' => array(
149
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
150
+				),
151
+			),
152
+			'trashed' => array(
153
+				'slug'        => 'trashed',
154
+				'label'       => esc_html__('Trash', 'event_espresso'),
155
+				'count'       => 0,
156
+				'bulk_action' => array(
157
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
158
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
159
+				),
160
+			),
161
+		);
162
+	}
163
+
164
+
165
+	public function _tickets_overview_list_table()
166
+	{
167
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
168
+		$this->display_admin_list_table_page_with_no_sidebar();
169
+	}
170
+
171
+
172
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
173
+	{
174
+
175
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
176
+		$order = empty($this->_req_data['order']) ? 'ASC' : $order;
177
+
178
+		switch ($orderby) {
179
+			case 'TKT_name':
180
+				$orderby = array('TKT_name' => $order);
181
+				break;
182
+
183
+			case 'TKT_price':
184
+				$orderby = array('TKT_price' => $order);
185
+				break;
186
+
187
+			case 'TKT_uses':
188
+				$orderby = array('TKT_uses' => $order);
189
+				break;
190
+
191
+			case 'TKT_min':
192
+				$orderby = array('TKT_min' => $order);
193
+				break;
194
+
195
+			case 'TKT_max':
196
+				$orderby = array('TKT_max' => $order);
197
+				break;
198
+
199
+			case 'TKT_qty':
200
+				$orderby = array('TKT_qty' => $order);
201
+				break;
202
+		}
203
+
204
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
205
+			? $this->_req_data['paged'] : 1;
206
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
207
+			? $this->_req_data['perpage'] : $per_page;
208
+
209
+		$_where = array(
210
+			'TKT_is_default' => 1,
211
+			'TKT_deleted'    => $trashed,
212
+		);
213
+
214
+		$offset = ($current_page - 1) * $per_page;
215
+		$limit = array($offset, $per_page);
216
+
217
+		if (isset($this->_req_data['s'])) {
218
+			$sstr = '%' . $this->_req_data['s'] . '%';
219
+			$_where['OR'] = array(
220
+				'TKT_name'        => array('LIKE', $sstr),
221
+				'TKT_description' => array('LIKE', $sstr),
222
+			);
223
+		}
224
+
225
+		$query_params = array(
226
+			$_where,
227
+			'order_by' => $orderby,
228
+			'limit'    => $limit,
229
+			'group_by' => 'TKT_ID',
230
+		);
231
+
232
+		if ($count) {
233
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
234
+		} else {
235
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
236
+		}
237
+	}
238
+
239
+
240
+	protected function _trash_or_restore_ticket($trash = false)
241
+	{
242
+		$success = 1;
243
+
244
+		$TKT = EEM_Ticket::instance();
245
+
246
+		// checkboxes?
247
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
248
+			// if array has more than one element then success message should be plural
249
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
250
+
251
+			// cycle thru the boxes
252
+			$checkboxes = $this->_req_data['checkbox'];
253
+			foreach (array_keys($checkboxes) as $TKT_ID) {
254
+				if ($trash) {
255
+					if (! $TKT->delete_by_ID($TKT_ID)) {
256
+						$success = 0;
257
+					}
258
+					continue;
259
+				}
260
+				if (! $TKT->restore_by_ID($TKT_ID)) {
261
+					$success = 0;
262
+				}
263
+			}
264
+		} else {
265
+			// grab single id and trash
266
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
267
+
268
+			if ($trash) {
269
+				if (! $TKT->delete_by_ID($TKT_ID)) {
270
+					$success = 0;
271
+				}
272
+			} else {
273
+				if (! $TKT->restore_by_ID($TKT_ID)) {
274
+					$success = 0;
275
+				}
276
+			}
277
+		}
278
+
279
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
280
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, array());
281
+	}
282
+
283
+
284
+	protected function _delete_ticket()
285
+	{
286
+		$success = 1;
287
+
288
+		$TKT = EEM_Ticket::instance();
289
+
290
+		// checkboxes?
291
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
292
+			// if array has more than one element then success message should be plural
293
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
294
+
295
+			// cycle thru the boxes
296
+			$checkboxes = $this->_req_data['checkbox'];
297
+			foreach (array_keys($checkboxes) as $TKT_ID) {
298
+				// delete
299
+				if (! $this->_delete_the_ticket($TKT_ID)) {
300
+					$success = 0;
301
+				}
302
+			}
303
+		} else {
304
+			// grab single id and trash
305
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
306
+			if (! $this->_delete_the_ticket($TKT_ID)) {
307
+				$success = 0;
308
+			}
309
+		}
310
+
311
+		$action_desc = 'deleted';
312
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, array());
313
+	}
314
+
315
+
316
+	protected function _delete_the_ticket($TKT_ID)
317
+	{
318
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
319
+
320
+		// delete all related prices first
321
+		$tkt->delete_related_permanently('Price');
322
+		return $tkt->delete_permanently();
323
+	}
324 324
 }
Please login to merge, or discard this patch.