Completed
Branch FET/update-venues-admin-reques... (232b22)
by
unknown
02:08 queued 16s
created
admin_pages/venues/Venues_Admin_Page.core.php 2 patches
Indentation   +1568 added lines, -1568 removed lines patch added patch discarded remove patch
@@ -14,1578 +14,1578 @@
 block discarded – undo
14 14
 class Venues_Admin_Page extends EE_Admin_Page_CPT
15 15
 {
16 16
 
17
-    /**
18
-     * _venue
19
-     * This will hold the venue object for venue_details screen.
20
-     *
21
-     * @access protected
22
-     * @var object
23
-     */
24
-    protected $_venue;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var object
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This property will hold the venue model instance
37
-     *
38
-     * @var object
39
-     */
40
-    protected $_venue_model;
41
-
42
-
43
-    /**
44
-     * @throws EE_Error
45
-     */
46
-    protected function _init_page_props()
47
-    {
48
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
49
-        $this->page_slug        = EE_VENUES_PG_SLUG;
50
-        $this->_admin_base_url  = EE_VENUES_ADMIN_URL;
51
-        $this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
-        $this->page_label       = esc_html__('Event Venues', 'event_espresso');
53
-        $this->_cpt_model_names = [
54
-            'create_new' => 'EEM_Venue',
55
-            'edit'       => 'EEM_Venue',
56
-        ];
57
-        $this->_cpt_edit_routes = [
58
-            'espresso_venues' => 'edit',
59
-        ];
60
-        $this->_venue_model     = EEM_Venue::instance();
61
-    }
62
-
63
-
64
-    protected function _ajax_hooks()
65
-    {
66
-        // todo: all hooks for ee_venues ajax goes in here.
67
-    }
68
-
69
-
70
-    protected function _define_page_props()
71
-    {
72
-        $this->_admin_page_title = $this->page_label;
73
-        $this->_labels           = [
74
-            'buttons'      => [
75
-                'add'             => esc_html__('Add New Venue', 'event_espresso'),
76
-                'edit'            => esc_html__('Edit Venue', 'event_espresso'),
77
-                'delete'          => esc_html__('Delete Venue', 'event_espresso'),
78
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
79
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
80
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
81
-            ],
82
-            'editor_title' => [
83
-                'espresso_venues' => esc_html__('Enter Venue name here', 'event_espresso'),
84
-            ],
85
-            'publishbox'   => [
86
-                'create_new'          => esc_html__('Save New Venue', 'event_espresso'),
87
-                'edit'                => esc_html__('Update Venue', 'event_espresso'),
88
-                'add_category'        => esc_html__('Save New Category', 'event_espresso'),
89
-                'edit_category'       => esc_html__('Update Category', 'event_espresso'),
90
-                'google_map_settings' => esc_html__('Update Settings', 'event_espresso'),
91
-            ],
92
-        ];
93
-    }
94
-
95
-
96
-    protected function _set_page_routes()
97
-    {
98
-
99
-        // load formatter helper
100
-        // load field generator helper
101
-
102
-        // is there a vnu_id in the request?
103
-        $VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
104
-        $VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
105
-
106
-        $this->_page_routes = [
107
-            'default'                    => [
108
-                'func'       => '_overview_list_table',
109
-                'capability' => 'ee_read_venues',
110
-            ],
111
-            'create_new'                 => [
112
-                'func'       => '_create_new_cpt_item',
113
-                'capability' => 'ee_edit_venues',
114
-            ],
115
-            'edit'                       => [
116
-                'func'       => '_edit_cpt_item',
117
-                'capability' => 'ee_edit_venue',
118
-                'obj_id'     => $VNU_ID,
119
-            ],
120
-            'trash_venue'                => [
121
-                'func'       => '_trash_or_restore_venue',
122
-                'args'       => ['venue_status' => 'trash'],
123
-                'noheader'   => true,
124
-                'capability' => 'ee_delete_venue',
125
-                'obj_id'     => $VNU_ID,
126
-            ],
127
-            'trash_venues'               => [
128
-                'func'       => '_trash_or_restore_venues',
129
-                'args'       => ['venue_status' => 'trash'],
130
-                'noheader'   => true,
131
-                'capability' => 'ee_delete_venues',
132
-            ],
133
-            'restore_venue'              => [
134
-                'func'       => '_trash_or_restore_venue',
135
-                'args'       => ['venue_status' => 'draft'],
136
-                'noheader'   => true,
137
-                'capability' => 'ee_delete_venue',
138
-                'obj_id'     => $VNU_ID,
139
-            ],
140
-            'restore_venues'             => [
141
-                'func'       => '_trash_or_restore_venues',
142
-                'args'       => ['venue_status' => 'draft'],
143
-                'noheader'   => true,
144
-                'capability' => 'ee_delete_venues',
145
-            ],
146
-            'delete_venues'              => [
147
-                'func'       => '_delete_venues',
148
-                'noheader'   => true,
149
-                'capability' => 'ee_delete_venues',
150
-            ],
151
-            'delete_venue'               => [
152
-                'func'       => '_delete_venue',
153
-                'noheader'   => true,
154
-                'capability' => 'ee_delete_venue',
155
-                'obj_id'     => $VNU_ID,
156
-            ],
157
-            // settings related
158
-            'google_map_settings'        => [
159
-                'func'       => '_google_map_settings',
160
-                'capability' => 'manage_options',
161
-            ],
162
-            'update_google_map_settings' => [
163
-                'func'       => '_update_google_map_settings',
164
-                'capability' => 'manage_options',
165
-                'noheader'   => true,
166
-            ],
167
-            // venue category tab related
168
-            'add_category'               => [
169
-                'func'       => '_category_details',
170
-                'args'       => ['add'],
171
-                'capability' => 'ee_edit_venue_category',
172
-            ],
173
-            'edit_category'              => [
174
-                'func'       => '_category_details',
175
-                'args'       => ['edit'],
176
-                'capability' => 'ee_edit_venue_category',
177
-            ],
178
-            'delete_categories'          => [
179
-                'func'       => '_delete_categories',
180
-                'noheader'   => true,
181
-                'capability' => 'ee_delete_venue_category',
182
-            ],
183
-
184
-            'delete_category' => [
185
-                'func'       => '_delete_categories',
186
-                'noheader'   => true,
187
-                'capability' => 'ee_delete_venue_category',
188
-            ],
189
-
190
-            'insert_category' => [
191
-                'func'       => '_insert_or_update_category',
192
-                'args'       => ['new_category' => true],
193
-                'noheader'   => true,
194
-                'capability' => 'ee_edit_venue_category',
195
-            ],
196
-
197
-            'update_category'   => [
198
-                'func'       => '_insert_or_update_category',
199
-                'args'       => ['new_category' => false],
200
-                'noheader'   => true,
201
-                'capability' => 'ee_edit_venue_category',
202
-            ],
203
-            'export_categories' => [
204
-                'func'       => '_categories_export',
205
-                'noheader'   => true,
206
-                'capability' => 'export',
207
-            ],
208
-            'import_categories' => [
209
-                'func'       => '_import_categories',
210
-                'capability' => 'import',
211
-            ],
212
-            'category_list'     => [
213
-                'func'       => '_category_list_table',
214
-                'capability' => 'ee_manage_venue_categories',
215
-            ],
216
-        ];
217
-    }
218
-
219
-
220
-    protected function _set_page_config()
221
-    {
222
-        $VNU_ID     = $this->request->getRequestParam('post', 0, 'int');
223
-        $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
224
-
225
-        $this->_page_config = [
226
-            'default'             => [
227
-                'nav'           => [
228
-                    'label' => esc_html__('Overview', 'event_espresso'),
229
-                    'order' => 10,
230
-                ],
231
-                'list_table'    => 'Venues_Admin_List_Table',
232
-                'help_tabs'     => [
233
-                    'venues_overview_help_tab'                           => [
234
-                        'title'    => esc_html__('Venues Overview', 'event_espresso'),
235
-                        'filename' => 'venues_overview',
236
-                    ],
237
-                    'venues_overview_table_column_headings_help_tab'     => [
238
-                        'title'    => esc_html__('Venues Overview Table Column Headings', 'event_espresso'),
239
-                        'filename' => 'venues_overview_table_column_headings',
240
-                    ],
241
-                    'venues_overview_views_bulk_actions_search_help_tab' => [
242
-                        'title'    => esc_html__('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
243
-                        'filename' => 'venues_overview_views_bulk_actions_search',
244
-                    ],
245
-                ],
246
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
247
-                // 'help_tour'     => array('Venues_Overview_Help_Tour'),
248
-                'metaboxes'     => ['_espresso_news_post_box', '_espresso_links_post_box'],
249
-                'require_nonce' => false,
250
-            ],
251
-            'create_new'          => [
252
-                'nav'           => [
253
-                    'label'      => esc_html__('Add Venue', 'event_espresso'),
254
-                    'order'      => 5,
255
-                    'persistent' => false,
256
-                ],
257
-                'help_tabs'     => [
258
-                    'venues_editor_help_tab'                                               => [
259
-                        'title'    => esc_html__('Venue Editor', 'event_espresso'),
260
-                        'filename' => 'venues_editor',
261
-                    ],
262
-                    'venues_editor_title_richtexteditor_help_tab'                          => [
263
-                        'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
264
-                        'filename' => 'venues_editor_title_richtexteditor',
265
-                    ],
266
-                    'venues_editor_tags_categories_help_tab'                               => [
267
-                        'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
268
-                        'filename' => 'venues_editor_tags_categories',
269
-                    ],
270
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
271
-                        'title'    => esc_html__(
272
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
273
-                            'event_espresso'
274
-                        ),
275
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
276
-                    ],
277
-                    'venues_editor_save_new_venue_help_tab'                                => [
278
-                        'title'    => esc_html__('Save New Venue', 'event_espresso'),
279
-                        'filename' => 'venues_editor_save_new_venue',
280
-                    ],
281
-                    'venues_editor_other_help_tab'                                         => [
282
-                        'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
283
-                        'filename' => 'venues_editor_other',
284
-                    ],
285
-                ],
286
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
287
-                // 'help_tour'     => array('Venues_Add_Venue_Help_Tour'),
288
-                'metaboxes'     => ['_venue_editor_metaboxes'],
289
-                'require_nonce' => false,
290
-            ],
291
-            'edit'                => [
292
-                'nav'           => [
293
-                    'label'      => esc_html__('Edit Venue', 'event_espresso'),
294
-                    'order'      => 5,
295
-                    'persistent' => false,
296
-                    'url'        => $VNU_ID
297
-                        ? add_query_arg(['post' => $VNU_ID], $this->_current_page_view_url)
298
-                        : $this->_admin_base_url,
299
-                ],
300
-                'help_tabs'     => [
301
-                    'venues_editor_help_tab'                                               => [
302
-                        'title'    => esc_html__('Venue Editor', 'event_espresso'),
303
-                        'filename' => 'venues_editor',
304
-                    ],
305
-                    'venues_editor_title_richtexteditor_help_tab'                          => [
306
-                        'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
307
-                        'filename' => 'venues_editor_title_richtexteditor',
308
-                    ],
309
-                    'venues_editor_tags_categories_help_tab'                               => [
310
-                        'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
311
-                        'filename' => 'venues_editor_tags_categories',
312
-                    ],
313
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
314
-                        'title'    => esc_html__(
315
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
316
-                            'event_espresso'
317
-                        ),
318
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
319
-                    ],
320
-                    'venues_editor_save_new_venue_help_tab'                                => [
321
-                        'title'    => esc_html__('Save New Venue', 'event_espresso'),
322
-                        'filename' => 'venues_editor_save_new_venue',
323
-                    ],
324
-                    'venues_editor_other_help_tab'                                         => [
325
-                        'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
326
-                        'filename' => 'venues_editor_other',
327
-                    ],
328
-                ],
329
-                /*'help_tour' => array( 'Venues_Edit_Venue_Help_Tour' ),*/
330
-                'metaboxes'     => ['_venue_editor_metaboxes'],
331
-                'require_nonce' => false,
332
-            ],
333
-            'google_map_settings' => [
334
-                'nav'           => [
335
-                    'label' => esc_html__('Google Maps', 'event_espresso'),
336
-                    'order' => 40,
337
-                ],
338
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
339
-                'help_tabs'     => [
340
-                    'general_settings_google_maps_help_tab' => [
341
-                        'title'    => esc_html__('Google Maps', 'event_espresso'),
342
-                        'filename' => 'general_settings_google_maps',
343
-                    ],
344
-                ],
345
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
346
-                // 'help_tour'     => array('Google_Maps_Help_Tour'),
347
-                'require_nonce' => false,
348
-            ],
349
-            // venue category stuff
350
-            'add_category'        => [
351
-                'nav'           => [
352
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
353
-                    'order'      => 15,
354
-                    'persistent' => false,
355
-                ],
356
-                'metaboxes'     => ['_publish_post_box'],
357
-                'help_tabs'     => [
358
-                    'venues_add_category_help_tab' => [
359
-                        'title'    => esc_html__('Add New Venue Category', 'event_espresso'),
360
-                        'filename' => 'venues_add_category',
361
-                    ],
362
-                ],
363
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
364
-                // 'help_tour'     => array('Venues_Add_Category_Help_Tour'),
365
-                'require_nonce' => false,
366
-            ],
367
-            'edit_category'       => [
368
-                'nav'           => [
369
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
370
-                    'order'      => 15,
371
-                    'persistent' => false,
372
-                    'url'        => $EVT_CAT_ID
373
-                        ? add_query_arg(['EVT_CAT_ID' => $EVT_CAT_ID], $this->_current_page_view_url)
374
-                        : $this->_admin_base_url,
375
-                ],
376
-                'metaboxes'     => ['_publish_post_box'],
377
-                'help_tabs'     => [
378
-                    'venues_edit_category_help_tab' => [
379
-                        'title'    => esc_html__('Edit Venue Category', 'event_espresso'),
380
-                        'filename' => 'venues_edit_category',
381
-                    ],
382
-                ],
383
-                /*'help_tour' => array( 'Venues_Edit_Category_Help_Tour' ),*/
384
-                'require_nonce' => false,
385
-            ],
386
-            'category_list'       => [
387
-                'nav'           => [
388
-                    'label' => esc_html__('Categories', 'event_espresso'),
389
-                    'order' => 20,
390
-                ],
391
-                'list_table'    => 'Venue_Categories_Admin_List_Table',
392
-                'help_tabs'     => [
393
-                    'venues_categories_help_tab'                       => [
394
-                        'title'    => esc_html__('Venue Categories', 'event_espresso'),
395
-                        'filename' => 'venues_categories',
396
-                    ],
397
-                    'venues_categories_table_column_headings_help_tab' => [
398
-                        'title'    => esc_html__('Venue Categories Table Column Headings', 'event_espresso'),
399
-                        'filename' => 'venues_categories_table_column_headings',
400
-                    ],
401
-                    'venues_categories_views_help_tab'                 => [
402
-                        'title'    => esc_html__('Venue Categories Views', 'event_espresso'),
403
-                        'filename' => 'venues_categories_views',
404
-                    ],
405
-                    'venues_categories_other_help_tab'                 => [
406
-                        'title'    => esc_html__('Venue Categories Other', 'event_espresso'),
407
-                        'filename' => 'venues_categories_other',
408
-                    ],
409
-                ],
410
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
411
-                // 'help_tour'     => array('Venues_Categories_Help_Tour'),
412
-                'metaboxes'     => $this->_default_espresso_metaboxes,
413
-                'require_nonce' => false,
414
-            ],
415
-        ];
416
-    }
417
-
418
-
419
-    protected function _add_screen_options()
420
-    {
421
-        // todo
422
-    }
423
-
424
-
425
-    protected function _add_screen_options_default()
426
-    {
427
-        $this->_per_page_screen_option();
428
-    }
429
-
430
-
431
-    protected function _add_screen_options_category_list()
432
-    {
433
-        $page_title              = $this->_admin_page_title;
434
-        $this->_admin_page_title = esc_html__('Venue Categories', 'event_espresso');
435
-        $this->_per_page_screen_option();
436
-        $this->_admin_page_title = $page_title;
437
-    }
438
-
439
-
440
-    // none of the below group are currently used for Event Venues
441
-    protected function _add_feature_pointers()
442
-    {
443
-    }
444
-
445
-
446
-    public function admin_init()
447
-    {
448
-    }
449
-
450
-
451
-    public function admin_notices()
452
-    {
453
-    }
454
-
455
-
456
-    public function admin_footer_scripts()
457
-    {
458
-    }
459
-
460
-
461
-    public function load_scripts_styles_create_new()
462
-    {
463
-        $this->load_scripts_styles_edit();
464
-    }
465
-
466
-
467
-    public function load_scripts_styles()
468
-    {
469
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
470
-        wp_enqueue_style('ee-cat-admin');
471
-    }
472
-
473
-
474
-    public function load_scripts_styles_add_category()
475
-    {
476
-        $this->load_scripts_styles_edit_category();
477
-    }
478
-
479
-
480
-    public function load_scripts_styles_edit_category()
481
-    {
482
-    }
483
-
484
-
485
-    public function load_scripts_styles_edit()
486
-    {
487
-        // styles
488
-        wp_enqueue_style('espresso-ui-theme');
489
-        wp_register_style(
490
-            'espresso_venues',
491
-            EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
492
-            [],
493
-            EVENT_ESPRESSO_VERSION
494
-        );
495
-        wp_enqueue_style('espresso_venues');
496
-    }
497
-
498
-
499
-    protected function _set_list_table_views_default()
500
-    {
501
-        $this->_views = [
502
-            'all' => [
503
-                'slug'        => 'all',
504
-                'label'       => esc_html__('View All Venues', 'event_espresso'),
505
-                'count'       => 0,
506
-                'bulk_action' => [],
507
-            ],
508
-        ];
509
-
510
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
511
-            $this->_views['all']['bulk_action'] = [
512
-                'trash_venues' => esc_html__('Move to Trash', 'event_espresso'),
513
-            ];
514
-            $this->_views['trash']              = [
515
-                'slug'        => 'trash',
516
-                'label'       => esc_html__('Trash', 'event_espresso'),
517
-                'count'       => 0,
518
-                'bulk_action' => [
519
-                    'restore_venues' => esc_html__('Restore from Trash', 'event_espresso'),
520
-                    'delete_venues'  => esc_html__('Delete', 'event_espresso'),
521
-                ],
522
-            ];
523
-        }
524
-    }
525
-
526
-
527
-    protected function _set_list_table_views_category_list()
528
-    {
529
-        $this->_views = [
530
-            'all' => [
531
-                'slug'        => 'all',
532
-                'label'       => esc_html__('All', 'event_espresso'),
533
-                'count'       => 0,
534
-                'bulk_action' => [
535
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
536
-                ],
537
-            ],
538
-        ];
539
-    }
540
-
541
-
542
-    /**
543
-     * @throws EE_Error
544
-     */
545
-    protected function _overview_list_table()
546
-    {
547
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
548
-        $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
549
-            get_post_type_archive_link('espresso_venues'),
550
-            esc_html__("View Venue Archive Page", "event_espresso"),
551
-            'button'
552
-        );
553
-
554
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
555
-            'create_new',
556
-            'add',
557
-            [],
558
-            'add-new-h2'
559
-        );
560
-
561
-        $this->_search_btn_label  = esc_html__('Venues', 'event_espresso');
562
-        $this->display_admin_list_table_page_with_sidebar();
563
-    }
564
-
565
-
566
-    /**
567
-     * @throws EE_Error
568
-     * @throws ReflectionException
569
-     */
570
-    public function extra_misc_actions_publish_box()
571
-    {
572
-        $extra_rows = [
573
-            'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
574
-            'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
575
-            'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
576
-        ];
577
-        $template   = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
578
-        EEH_Template::display_template($template, $extra_rows);
579
-    }
580
-
581
-
582
-    /*************        Google Maps        *************
17
+	/**
18
+	 * _venue
19
+	 * This will hold the venue object for venue_details screen.
20
+	 *
21
+	 * @access protected
22
+	 * @var object
23
+	 */
24
+	protected $_venue;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var object
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This property will hold the venue model instance
37
+	 *
38
+	 * @var object
39
+	 */
40
+	protected $_venue_model;
41
+
42
+
43
+	/**
44
+	 * @throws EE_Error
45
+	 */
46
+	protected function _init_page_props()
47
+	{
48
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
49
+		$this->page_slug        = EE_VENUES_PG_SLUG;
50
+		$this->_admin_base_url  = EE_VENUES_ADMIN_URL;
51
+		$this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
+		$this->page_label       = esc_html__('Event Venues', 'event_espresso');
53
+		$this->_cpt_model_names = [
54
+			'create_new' => 'EEM_Venue',
55
+			'edit'       => 'EEM_Venue',
56
+		];
57
+		$this->_cpt_edit_routes = [
58
+			'espresso_venues' => 'edit',
59
+		];
60
+		$this->_venue_model     = EEM_Venue::instance();
61
+	}
62
+
63
+
64
+	protected function _ajax_hooks()
65
+	{
66
+		// todo: all hooks for ee_venues ajax goes in here.
67
+	}
68
+
69
+
70
+	protected function _define_page_props()
71
+	{
72
+		$this->_admin_page_title = $this->page_label;
73
+		$this->_labels           = [
74
+			'buttons'      => [
75
+				'add'             => esc_html__('Add New Venue', 'event_espresso'),
76
+				'edit'            => esc_html__('Edit Venue', 'event_espresso'),
77
+				'delete'          => esc_html__('Delete Venue', 'event_espresso'),
78
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
79
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
80
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
81
+			],
82
+			'editor_title' => [
83
+				'espresso_venues' => esc_html__('Enter Venue name here', 'event_espresso'),
84
+			],
85
+			'publishbox'   => [
86
+				'create_new'          => esc_html__('Save New Venue', 'event_espresso'),
87
+				'edit'                => esc_html__('Update Venue', 'event_espresso'),
88
+				'add_category'        => esc_html__('Save New Category', 'event_espresso'),
89
+				'edit_category'       => esc_html__('Update Category', 'event_espresso'),
90
+				'google_map_settings' => esc_html__('Update Settings', 'event_espresso'),
91
+			],
92
+		];
93
+	}
94
+
95
+
96
+	protected function _set_page_routes()
97
+	{
98
+
99
+		// load formatter helper
100
+		// load field generator helper
101
+
102
+		// is there a vnu_id in the request?
103
+		$VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
104
+		$VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
105
+
106
+		$this->_page_routes = [
107
+			'default'                    => [
108
+				'func'       => '_overview_list_table',
109
+				'capability' => 'ee_read_venues',
110
+			],
111
+			'create_new'                 => [
112
+				'func'       => '_create_new_cpt_item',
113
+				'capability' => 'ee_edit_venues',
114
+			],
115
+			'edit'                       => [
116
+				'func'       => '_edit_cpt_item',
117
+				'capability' => 'ee_edit_venue',
118
+				'obj_id'     => $VNU_ID,
119
+			],
120
+			'trash_venue'                => [
121
+				'func'       => '_trash_or_restore_venue',
122
+				'args'       => ['venue_status' => 'trash'],
123
+				'noheader'   => true,
124
+				'capability' => 'ee_delete_venue',
125
+				'obj_id'     => $VNU_ID,
126
+			],
127
+			'trash_venues'               => [
128
+				'func'       => '_trash_or_restore_venues',
129
+				'args'       => ['venue_status' => 'trash'],
130
+				'noheader'   => true,
131
+				'capability' => 'ee_delete_venues',
132
+			],
133
+			'restore_venue'              => [
134
+				'func'       => '_trash_or_restore_venue',
135
+				'args'       => ['venue_status' => 'draft'],
136
+				'noheader'   => true,
137
+				'capability' => 'ee_delete_venue',
138
+				'obj_id'     => $VNU_ID,
139
+			],
140
+			'restore_venues'             => [
141
+				'func'       => '_trash_or_restore_venues',
142
+				'args'       => ['venue_status' => 'draft'],
143
+				'noheader'   => true,
144
+				'capability' => 'ee_delete_venues',
145
+			],
146
+			'delete_venues'              => [
147
+				'func'       => '_delete_venues',
148
+				'noheader'   => true,
149
+				'capability' => 'ee_delete_venues',
150
+			],
151
+			'delete_venue'               => [
152
+				'func'       => '_delete_venue',
153
+				'noheader'   => true,
154
+				'capability' => 'ee_delete_venue',
155
+				'obj_id'     => $VNU_ID,
156
+			],
157
+			// settings related
158
+			'google_map_settings'        => [
159
+				'func'       => '_google_map_settings',
160
+				'capability' => 'manage_options',
161
+			],
162
+			'update_google_map_settings' => [
163
+				'func'       => '_update_google_map_settings',
164
+				'capability' => 'manage_options',
165
+				'noheader'   => true,
166
+			],
167
+			// venue category tab related
168
+			'add_category'               => [
169
+				'func'       => '_category_details',
170
+				'args'       => ['add'],
171
+				'capability' => 'ee_edit_venue_category',
172
+			],
173
+			'edit_category'              => [
174
+				'func'       => '_category_details',
175
+				'args'       => ['edit'],
176
+				'capability' => 'ee_edit_venue_category',
177
+			],
178
+			'delete_categories'          => [
179
+				'func'       => '_delete_categories',
180
+				'noheader'   => true,
181
+				'capability' => 'ee_delete_venue_category',
182
+			],
183
+
184
+			'delete_category' => [
185
+				'func'       => '_delete_categories',
186
+				'noheader'   => true,
187
+				'capability' => 'ee_delete_venue_category',
188
+			],
189
+
190
+			'insert_category' => [
191
+				'func'       => '_insert_or_update_category',
192
+				'args'       => ['new_category' => true],
193
+				'noheader'   => true,
194
+				'capability' => 'ee_edit_venue_category',
195
+			],
196
+
197
+			'update_category'   => [
198
+				'func'       => '_insert_or_update_category',
199
+				'args'       => ['new_category' => false],
200
+				'noheader'   => true,
201
+				'capability' => 'ee_edit_venue_category',
202
+			],
203
+			'export_categories' => [
204
+				'func'       => '_categories_export',
205
+				'noheader'   => true,
206
+				'capability' => 'export',
207
+			],
208
+			'import_categories' => [
209
+				'func'       => '_import_categories',
210
+				'capability' => 'import',
211
+			],
212
+			'category_list'     => [
213
+				'func'       => '_category_list_table',
214
+				'capability' => 'ee_manage_venue_categories',
215
+			],
216
+		];
217
+	}
218
+
219
+
220
+	protected function _set_page_config()
221
+	{
222
+		$VNU_ID     = $this->request->getRequestParam('post', 0, 'int');
223
+		$EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
224
+
225
+		$this->_page_config = [
226
+			'default'             => [
227
+				'nav'           => [
228
+					'label' => esc_html__('Overview', 'event_espresso'),
229
+					'order' => 10,
230
+				],
231
+				'list_table'    => 'Venues_Admin_List_Table',
232
+				'help_tabs'     => [
233
+					'venues_overview_help_tab'                           => [
234
+						'title'    => esc_html__('Venues Overview', 'event_espresso'),
235
+						'filename' => 'venues_overview',
236
+					],
237
+					'venues_overview_table_column_headings_help_tab'     => [
238
+						'title'    => esc_html__('Venues Overview Table Column Headings', 'event_espresso'),
239
+						'filename' => 'venues_overview_table_column_headings',
240
+					],
241
+					'venues_overview_views_bulk_actions_search_help_tab' => [
242
+						'title'    => esc_html__('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
243
+						'filename' => 'venues_overview_views_bulk_actions_search',
244
+					],
245
+				],
246
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
247
+				// 'help_tour'     => array('Venues_Overview_Help_Tour'),
248
+				'metaboxes'     => ['_espresso_news_post_box', '_espresso_links_post_box'],
249
+				'require_nonce' => false,
250
+			],
251
+			'create_new'          => [
252
+				'nav'           => [
253
+					'label'      => esc_html__('Add Venue', 'event_espresso'),
254
+					'order'      => 5,
255
+					'persistent' => false,
256
+				],
257
+				'help_tabs'     => [
258
+					'venues_editor_help_tab'                                               => [
259
+						'title'    => esc_html__('Venue Editor', 'event_espresso'),
260
+						'filename' => 'venues_editor',
261
+					],
262
+					'venues_editor_title_richtexteditor_help_tab'                          => [
263
+						'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
264
+						'filename' => 'venues_editor_title_richtexteditor',
265
+					],
266
+					'venues_editor_tags_categories_help_tab'                               => [
267
+						'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
268
+						'filename' => 'venues_editor_tags_categories',
269
+					],
270
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
271
+						'title'    => esc_html__(
272
+							'Venue Editor Physical Location & Google Map & Virtual Location',
273
+							'event_espresso'
274
+						),
275
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
276
+					],
277
+					'venues_editor_save_new_venue_help_tab'                                => [
278
+						'title'    => esc_html__('Save New Venue', 'event_espresso'),
279
+						'filename' => 'venues_editor_save_new_venue',
280
+					],
281
+					'venues_editor_other_help_tab'                                         => [
282
+						'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
283
+						'filename' => 'venues_editor_other',
284
+					],
285
+				],
286
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
287
+				// 'help_tour'     => array('Venues_Add_Venue_Help_Tour'),
288
+				'metaboxes'     => ['_venue_editor_metaboxes'],
289
+				'require_nonce' => false,
290
+			],
291
+			'edit'                => [
292
+				'nav'           => [
293
+					'label'      => esc_html__('Edit Venue', 'event_espresso'),
294
+					'order'      => 5,
295
+					'persistent' => false,
296
+					'url'        => $VNU_ID
297
+						? add_query_arg(['post' => $VNU_ID], $this->_current_page_view_url)
298
+						: $this->_admin_base_url,
299
+				],
300
+				'help_tabs'     => [
301
+					'venues_editor_help_tab'                                               => [
302
+						'title'    => esc_html__('Venue Editor', 'event_espresso'),
303
+						'filename' => 'venues_editor',
304
+					],
305
+					'venues_editor_title_richtexteditor_help_tab'                          => [
306
+						'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
307
+						'filename' => 'venues_editor_title_richtexteditor',
308
+					],
309
+					'venues_editor_tags_categories_help_tab'                               => [
310
+						'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
311
+						'filename' => 'venues_editor_tags_categories',
312
+					],
313
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
314
+						'title'    => esc_html__(
315
+							'Venue Editor Physical Location & Google Map & Virtual Location',
316
+							'event_espresso'
317
+						),
318
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
319
+					],
320
+					'venues_editor_save_new_venue_help_tab'                                => [
321
+						'title'    => esc_html__('Save New Venue', 'event_espresso'),
322
+						'filename' => 'venues_editor_save_new_venue',
323
+					],
324
+					'venues_editor_other_help_tab'                                         => [
325
+						'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
326
+						'filename' => 'venues_editor_other',
327
+					],
328
+				],
329
+				/*'help_tour' => array( 'Venues_Edit_Venue_Help_Tour' ),*/
330
+				'metaboxes'     => ['_venue_editor_metaboxes'],
331
+				'require_nonce' => false,
332
+			],
333
+			'google_map_settings' => [
334
+				'nav'           => [
335
+					'label' => esc_html__('Google Maps', 'event_espresso'),
336
+					'order' => 40,
337
+				],
338
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
339
+				'help_tabs'     => [
340
+					'general_settings_google_maps_help_tab' => [
341
+						'title'    => esc_html__('Google Maps', 'event_espresso'),
342
+						'filename' => 'general_settings_google_maps',
343
+					],
344
+				],
345
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
346
+				// 'help_tour'     => array('Google_Maps_Help_Tour'),
347
+				'require_nonce' => false,
348
+			],
349
+			// venue category stuff
350
+			'add_category'        => [
351
+				'nav'           => [
352
+					'label'      => esc_html__('Add Category', 'event_espresso'),
353
+					'order'      => 15,
354
+					'persistent' => false,
355
+				],
356
+				'metaboxes'     => ['_publish_post_box'],
357
+				'help_tabs'     => [
358
+					'venues_add_category_help_tab' => [
359
+						'title'    => esc_html__('Add New Venue Category', 'event_espresso'),
360
+						'filename' => 'venues_add_category',
361
+					],
362
+				],
363
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
364
+				// 'help_tour'     => array('Venues_Add_Category_Help_Tour'),
365
+				'require_nonce' => false,
366
+			],
367
+			'edit_category'       => [
368
+				'nav'           => [
369
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
370
+					'order'      => 15,
371
+					'persistent' => false,
372
+					'url'        => $EVT_CAT_ID
373
+						? add_query_arg(['EVT_CAT_ID' => $EVT_CAT_ID], $this->_current_page_view_url)
374
+						: $this->_admin_base_url,
375
+				],
376
+				'metaboxes'     => ['_publish_post_box'],
377
+				'help_tabs'     => [
378
+					'venues_edit_category_help_tab' => [
379
+						'title'    => esc_html__('Edit Venue Category', 'event_espresso'),
380
+						'filename' => 'venues_edit_category',
381
+					],
382
+				],
383
+				/*'help_tour' => array( 'Venues_Edit_Category_Help_Tour' ),*/
384
+				'require_nonce' => false,
385
+			],
386
+			'category_list'       => [
387
+				'nav'           => [
388
+					'label' => esc_html__('Categories', 'event_espresso'),
389
+					'order' => 20,
390
+				],
391
+				'list_table'    => 'Venue_Categories_Admin_List_Table',
392
+				'help_tabs'     => [
393
+					'venues_categories_help_tab'                       => [
394
+						'title'    => esc_html__('Venue Categories', 'event_espresso'),
395
+						'filename' => 'venues_categories',
396
+					],
397
+					'venues_categories_table_column_headings_help_tab' => [
398
+						'title'    => esc_html__('Venue Categories Table Column Headings', 'event_espresso'),
399
+						'filename' => 'venues_categories_table_column_headings',
400
+					],
401
+					'venues_categories_views_help_tab'                 => [
402
+						'title'    => esc_html__('Venue Categories Views', 'event_espresso'),
403
+						'filename' => 'venues_categories_views',
404
+					],
405
+					'venues_categories_other_help_tab'                 => [
406
+						'title'    => esc_html__('Venue Categories Other', 'event_espresso'),
407
+						'filename' => 'venues_categories_other',
408
+					],
409
+				],
410
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
411
+				// 'help_tour'     => array('Venues_Categories_Help_Tour'),
412
+				'metaboxes'     => $this->_default_espresso_metaboxes,
413
+				'require_nonce' => false,
414
+			],
415
+		];
416
+	}
417
+
418
+
419
+	protected function _add_screen_options()
420
+	{
421
+		// todo
422
+	}
423
+
424
+
425
+	protected function _add_screen_options_default()
426
+	{
427
+		$this->_per_page_screen_option();
428
+	}
429
+
430
+
431
+	protected function _add_screen_options_category_list()
432
+	{
433
+		$page_title              = $this->_admin_page_title;
434
+		$this->_admin_page_title = esc_html__('Venue Categories', 'event_espresso');
435
+		$this->_per_page_screen_option();
436
+		$this->_admin_page_title = $page_title;
437
+	}
438
+
439
+
440
+	// none of the below group are currently used for Event Venues
441
+	protected function _add_feature_pointers()
442
+	{
443
+	}
444
+
445
+
446
+	public function admin_init()
447
+	{
448
+	}
449
+
450
+
451
+	public function admin_notices()
452
+	{
453
+	}
454
+
455
+
456
+	public function admin_footer_scripts()
457
+	{
458
+	}
459
+
460
+
461
+	public function load_scripts_styles_create_new()
462
+	{
463
+		$this->load_scripts_styles_edit();
464
+	}
465
+
466
+
467
+	public function load_scripts_styles()
468
+	{
469
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
470
+		wp_enqueue_style('ee-cat-admin');
471
+	}
472
+
473
+
474
+	public function load_scripts_styles_add_category()
475
+	{
476
+		$this->load_scripts_styles_edit_category();
477
+	}
478
+
479
+
480
+	public function load_scripts_styles_edit_category()
481
+	{
482
+	}
483
+
484
+
485
+	public function load_scripts_styles_edit()
486
+	{
487
+		// styles
488
+		wp_enqueue_style('espresso-ui-theme');
489
+		wp_register_style(
490
+			'espresso_venues',
491
+			EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
492
+			[],
493
+			EVENT_ESPRESSO_VERSION
494
+		);
495
+		wp_enqueue_style('espresso_venues');
496
+	}
497
+
498
+
499
+	protected function _set_list_table_views_default()
500
+	{
501
+		$this->_views = [
502
+			'all' => [
503
+				'slug'        => 'all',
504
+				'label'       => esc_html__('View All Venues', 'event_espresso'),
505
+				'count'       => 0,
506
+				'bulk_action' => [],
507
+			],
508
+		];
509
+
510
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
511
+			$this->_views['all']['bulk_action'] = [
512
+				'trash_venues' => esc_html__('Move to Trash', 'event_espresso'),
513
+			];
514
+			$this->_views['trash']              = [
515
+				'slug'        => 'trash',
516
+				'label'       => esc_html__('Trash', 'event_espresso'),
517
+				'count'       => 0,
518
+				'bulk_action' => [
519
+					'restore_venues' => esc_html__('Restore from Trash', 'event_espresso'),
520
+					'delete_venues'  => esc_html__('Delete', 'event_espresso'),
521
+				],
522
+			];
523
+		}
524
+	}
525
+
526
+
527
+	protected function _set_list_table_views_category_list()
528
+	{
529
+		$this->_views = [
530
+			'all' => [
531
+				'slug'        => 'all',
532
+				'label'       => esc_html__('All', 'event_espresso'),
533
+				'count'       => 0,
534
+				'bulk_action' => [
535
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
536
+				],
537
+			],
538
+		];
539
+	}
540
+
541
+
542
+	/**
543
+	 * @throws EE_Error
544
+	 */
545
+	protected function _overview_list_table()
546
+	{
547
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
548
+		$this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
549
+			get_post_type_archive_link('espresso_venues'),
550
+			esc_html__("View Venue Archive Page", "event_espresso"),
551
+			'button'
552
+		);
553
+
554
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
555
+			'create_new',
556
+			'add',
557
+			[],
558
+			'add-new-h2'
559
+		);
560
+
561
+		$this->_search_btn_label  = esc_html__('Venues', 'event_espresso');
562
+		$this->display_admin_list_table_page_with_sidebar();
563
+	}
564
+
565
+
566
+	/**
567
+	 * @throws EE_Error
568
+	 * @throws ReflectionException
569
+	 */
570
+	public function extra_misc_actions_publish_box()
571
+	{
572
+		$extra_rows = [
573
+			'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
574
+			'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
575
+			'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
576
+		];
577
+		$template   = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
578
+		EEH_Template::display_template($template, $extra_rows);
579
+	}
580
+
581
+
582
+	/*************        Google Maps        *************
583 583
      *
584 584
      * @throws EE_Error
585 585
      * @throws EE_Error
586 586
      */
587 587
 
588 588
 
589
-    protected function _google_map_settings()
590
-    {
591
-
592
-
593
-        $this->_template_args['values']           = $this->_yes_no_values;
594
-        $default_map_settings                     = new stdClass();
595
-        $default_map_settings->use_google_maps    = true;
596
-        $default_map_settings->google_map_api_key = '';
597
-        // for event details pages (reg page)
598
-        $default_map_settings->event_details_map_width    = 585;
599
-        // ee_map_width_single
600
-        $default_map_settings->event_details_map_height   = 362;
601
-        // ee_map_height_single
602
-        $default_map_settings->event_details_map_zoom     = 14;
603
-        // ee_map_zoom_single
604
-        $default_map_settings->event_details_display_nav  = true;
605
-        // ee_map_nav_display_single
606
-        $default_map_settings->event_details_nav_size     = false;
607
-        // ee_map_nav_size_single
608
-        $default_map_settings->event_details_control_type = 'default';
609
-        // ee_map_type_control_single
610
-        $default_map_settings->event_details_map_align    = 'center';
611
-        // ee_map_align_single
612
-
613
-        // for event list pages
614
-        $default_map_settings->event_list_map_width    = 300;
615
-        // ee_map_width
616
-        $default_map_settings->event_list_map_height   = 185;
617
-        // ee_map_height
618
-        $default_map_settings->event_list_map_zoom     = 12;
619
-        // ee_map_zoom
620
-        $default_map_settings->event_list_display_nav  = false;
621
-        // ee_map_nav_display
622
-        $default_map_settings->event_list_nav_size     = true;
623
-        // ee_map_nav_size
624
-        $default_map_settings->event_list_control_type = 'dropdown';
625
-        // ee_map_type_control
626
-        $default_map_settings->event_list_map_align    = 'center';
627
-        // ee_map_align
628
-
629
-        $this->_template_args['map_settings'] =
630
-            isset(EE_Registry::instance()->CFG->map_settings)
631
-            && ! empty(EE_Registry::instance()->CFG->map_settings)
632
-                ? (object) array_merge(
633
-                    (array) $default_map_settings,
634
-                    (array) EE_Registry::instance()->CFG->map_settings
635
-                )
636
-                : $default_map_settings;
637
-
638
-        $this->_set_add_edit_form_tags('update_google_map_settings');
639
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
640
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
641
-            EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
642
-            $this->_template_args,
643
-            true
644
-        );
645
-        $this->display_admin_page_with_sidebar();
646
-    }
647
-
648
-
649
-    /**
650
-     * @throws EE_Error
651
-     */
652
-    protected function _update_google_map_settings()
653
-    {
654
-        $map_settings = EE_Registry::instance()->CFG->map_settings;
655
-
656
-        $settings = [
657
-            'use_google_maps'            => 'int',
658
-            'google_map_api_key'         => 'string',
659
-            'event_details_map_width'    => 'int',
660
-            'event_details_map_zoom'     => 'int',
661
-            'event_details_display_nav'  => 'int',
662
-            'event_details_nav_size'     => 'int',
663
-            'event_details_control_type' => 'string',
664
-            'event_details_map_align'    => 'string',
665
-            'event_list_map_width'       => 'int',
666
-            'event_list_map_height'      => 'int',
667
-            'event_list_map_zoom'        => 'int',
668
-            'event_list_display_nav'     => 'int',
669
-            'event_list_nav_size'        => 'int',
670
-            'event_list_control_type'    => 'string',
671
-            'event_list_map_align'       => 'string',
672
-        ];
673
-
674
-        foreach ($settings as $setting => $type) {
675
-            $map_settings->{$setting} = $this->request->getRequestParam($setting, $map_settings->{$setting}, $type);
676
-        }
677
-
678
-        EE_Registry::instance()->CFG->map_settings = apply_filters(
679
-            'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
680
-            $map_settings
681
-        );
682
-
683
-        $what    = 'Google Map Settings';
684
-        $success = $this->_update_espresso_configuration(
685
-            $what,
686
-            EE_Registry::instance()->CFG->map_settings,
687
-            __FILE__,
688
-            __FUNCTION__,
689
-            __LINE__
690
-        );
691
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'google_map_settings']);
692
-    }
693
-
694
-
695
-    /**
696
-     * @throws EE_Error
697
-     * @throws ReflectionException
698
-     */
699
-    protected function _venue_editor_metaboxes()
700
-    {
701
-        $this->verify_cpt_object();
702
-
703
-        add_meta_box(
704
-            'espresso_venue_address_options',
705
-            esc_html__('Physical Location', 'event_espresso'),
706
-            [$this, 'venue_address_metabox'],
707
-            $this->page_slug,
708
-            'side'
709
-        );
710
-        add_meta_box(
711
-            'espresso_venue_gmap_options',
712
-            esc_html__('Google Map', 'event_espresso'),
713
-            [$this, 'venue_gmap_metabox'],
714
-            $this->page_slug,
715
-            'side'
716
-        );
717
-        add_meta_box(
718
-            'espresso_venue_virtual_loc_options',
719
-            esc_html__('Virtual Location', 'event_espresso'),
720
-            [$this, 'venue_virtual_loc_metabox'],
721
-            $this->page_slug,
722
-            'side'
723
-        );
724
-    }
725
-
726
-
727
-    public function venue_gmap_metabox()
728
-    {
729
-        $template_args = [
730
-            'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
731
-                'vnu_enable_for_gmap',
732
-                $this->get_yes_no_values(),
733
-                $this->_cpt_model_obj instanceof EE_Venue ? $this->_cpt_model_obj->enable_for_gmap() : false
734
-            ),
735
-            'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
736
-        ];
737
-        $template      = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
738
-        EEH_Template::display_template($template, $template_args);
739
-    }
740
-
741
-
742
-    /**
743
-     * @throws EE_Error
744
-     * @throws ReflectionException
745
-     */
746
-    public function venue_address_metabox()
747
-    {
748
-        $template_args['_venue'] = $this->_cpt_model_obj;
749
-
750
-        $template_args['states_dropdown']    = EEH_Form_Fields::generate_form_input(
751
-            new EE_Question_Form_Input(
752
-                EE_Question::new_instance(
753
-                    ['QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state']
754
-                ),
755
-                EE_Answer::new_instance(
756
-                    [
757
-                        'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
758
-                            ? $this->_cpt_model_obj->state_ID()
759
-                            : 0,
760
-                    ]
761
-                ),
762
-                [
763
-                    'input_name'     => 'sta_id',
764
-                    'input_id'       => 'sta_id',
765
-                    'input_class'    => '',
766
-                    'input_prefix'   => '',
767
-                    'append_qstn_id' => false,
768
-                ]
769
-            )
770
-        );
771
-        $template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
772
-            new EE_Question_Form_Input(
773
-                EE_Question::new_instance(
774
-                    ['QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country']
775
-                ),
776
-                EE_Answer::new_instance(
777
-                    [
778
-                        'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
779
-                            ? $this->_cpt_model_obj->country_ID()
780
-                            : 0,
781
-                    ]
782
-                ),
783
-                [
784
-                    'input_name'     => 'cnt_iso',
785
-                    'input_id'       => 'cnt_iso',
786
-                    'input_class'    => '',
787
-                    'input_prefix'   => '',
788
-                    'append_qstn_id' => false,
789
-                ]
790
-            )
791
-        );
792
-
793
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
794
-        EEH_Template::display_template($template, $template_args);
795
-    }
796
-
797
-
798
-    public function venue_virtual_loc_metabox()
799
-    {
800
-        $template_args = [
801
-            '_venue' => $this->_cpt_model_obj,
802
-        ];
803
-        $template      = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
804
-        EEH_Template::display_template($template, $template_args);
805
-    }
806
-
807
-
808
-    protected function _restore_cpt_item($post_id, $revision_id)
809
-    {
810
-        $venue_obj = $this->_venue_model->get_one_by_ID($post_id);
811
-
812
-        // meta revision restore
813
-        $venue_obj->restore_revision($revision_id);
814
-    }
815
-
816
-
817
-    /**
818
-     * Handles updates for venue cpts
819
-     *
820
-     * @param int    $post_id ID of Venue CPT
821
-     * @param object $post    Post object (with "blessed" WP properties)
822
-     * @return void
823
-     */
824
-    protected function _insert_update_cpt_item($post_id, $post)
825
-    {
826
-
827
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
828
-            return;// get out we're not processing the saving of venues.
829
-        }
830
-
831
-        $wheres = [$this->_venue_model->primary_key_name() => $post_id];
832
-
833
-        $venue_values = [
834
-            'VNU_address'         => $this->request->getRequestParam('vnu_address'),
835
-            'VNU_address2'        => $this->request->getRequestParam('vnu_address2'),
836
-            'VNU_city'            => $this->request->getRequestParam('vnu_city'),
837
-            'STA_ID'              => $this->request->getRequestParam('sta_id'),
838
-            'CNT_ISO'             => $this->request->getRequestParam('cnt_iso'),
839
-            'VNU_zip'             => $this->request->getRequestParam('vnu_zip'),
840
-            'VNU_phone'           => $this->request->getRequestParam('vnu_phone'),
841
-            'VNU_capacity'        => $this->request->requestParamIsSet('vnu_capacity')
842
-                ? str_replace(',', '', $this->request->getRequestParam('vnu_capacity'))
843
-                : EE_INF,
844
-            'VNU_url'             => $this->request->getRequestParam('vnu_url'),
845
-            'VNU_virtual_phone'   => $this->request->getRequestParam('vnu_virtual_phone'),
846
-            'VNU_virtual_url'     => $this->request->getRequestParam('vnu_virtual_url'),
847
-            'VNU_enable_for_gmap' => $this->request->getRequestParam('vnu_enable_for_gmap', false, 'bool'),
848
-            'VNU_google_map_link' => $this->request->getRequestParam('vnu_google_map_link'),
849
-        ];
850
-
851
-        // update venue
852
-        $success = $this->_venue_model->update($venue_values, [$wheres]);
853
-
854
-        // get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
855
-        $get_one_where = [$this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status];
856
-        $venue         = $this->_venue_model->get_one([$get_one_where]);
857
-
858
-        // notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
859
-        $venue_update_callbacks = apply_filters(
860
-            'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
861
-            []
862
-        );
863
-        $att_success            = true;
864
-        foreach ($venue_update_callbacks as $v_callback) {
865
-            // if ANY of these updates fail then we want the appropriate global error message
866
-            $att_success = call_user_func_array($v_callback, [$venue, $this->request->requestParams()])
867
-                ? $att_success
868
-                : false;
869
-        }
870
-
871
-        // any errors?
872
-        if ($success && ! $att_success) {
873
-            EE_Error::add_error(
874
-                esc_html__(
875
-                    'Venue Details saved successfully but something went wrong with saving attachments.',
876
-                    'event_espresso'
877
-                ),
878
-                __FILE__,
879
-                __FUNCTION__,
880
-                __LINE__
881
-            );
882
-        } elseif ($success === false) {
883
-            EE_Error::add_error(
884
-                esc_html__('Venue Details did not save successfully.', 'event_espresso'),
885
-                __FILE__,
886
-                __FUNCTION__,
887
-                __LINE__
888
-            );
889
-        }
890
-    }
891
-
892
-
893
-    /**
894
-     * @param int $post_id
895
-     * @throws EE_Error
896
-     * @throws ReflectionException
897
-     */
898
-    public function trash_cpt_item($post_id)
899
-    {
900
-        $this->request->setRequestParam('VNU_ID', $post_id);
901
-        $this->_trash_or_restore_venue('trash', false);
902
-    }
903
-
904
-
905
-    /**
906
-     * @param int $post_id
907
-     * @throws EE_Error
908
-     * @throws ReflectionException
909
-     */
910
-    public function restore_cpt_item($post_id)
911
-    {
912
-        $this->request->setRequestParam('VNU_ID', $post_id);
913
-        $this->_trash_or_restore_venue('draft', false);
914
-    }
915
-
916
-
917
-    /**
918
-     * @param int $post_id
919
-     * @throws EE_Error
920
-     * @throws ReflectionException
921
-     */
922
-    public function delete_cpt_item($post_id)
923
-    {
924
-        $this->request->setRequestParam('VNU_ID', $post_id);
925
-        $this->_delete_venue(false);
926
-    }
927
-
928
-
929
-    public function get_venue_object()
930
-    {
931
-        return $this->_cpt_model_obj;
932
-    }
933
-
934
-
935
-    /**
936
-     * @throws EE_Error
937
-     * @throws ReflectionException
938
-     */
939
-    protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
940
-    {
941
-        $VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
942
-
943
-        // loop thru venues
944
-        if ($VNU_ID) {
945
-            // clean status
946
-            $venue_status = sanitize_key($venue_status);
947
-            // grab status
948
-            if (! empty($venue_status)) {
949
-                $success = $this->_change_venue_status($VNU_ID, $venue_status);
950
-            } else {
951
-                $success = false;
952
-                $msg     = esc_html__(
953
-                    'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
954
-                    'event_espresso'
955
-                );
956
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
957
-            }
958
-        } else {
959
-            $success = false;
960
-            $msg     = esc_html__(
961
-                'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
962
-                'event_espresso'
963
-            );
964
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
965
-        }
966
-        $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
967
-
968
-        if ($redirect_after) {
969
-            $this->_redirect_after_action($success, 'Venue', $action, ['action' => 'default']);
970
-        }
971
-    }
972
-
973
-
974
-    /**
975
-     * @throws EE_Error
976
-     * @throws ReflectionException
977
-     */
978
-    protected function _trash_or_restore_venues($venue_status = 'trash')
979
-    {
980
-        // clean status
981
-        $venue_status = sanitize_key($venue_status);
982
-        // grab status
983
-        if (! empty($venue_status)) {
984
-            $success = true;
985
-            // determine the event id and set to array.
986
-            $VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
987
-            // loop thru events
988
-            foreach ($VNU_IDs as $VNU_ID) {
989
-                if ($VNU_ID = absint($VNU_ID)) {
990
-                    $results = $this->_change_venue_status($VNU_ID, $venue_status);
991
-                    $success = $results !== false ? $success : false;
992
-                } else {
993
-                    $msg = sprintf(
994
-                        esc_html__(
995
-                            'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
996
-                            'event_espresso'
997
-                        ),
998
-                        $VNU_ID
999
-                    );
1000
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1001
-                    $success = false;
1002
-                }
1003
-            }
1004
-        } else {
1005
-            $success = false;
1006
-            $msg     = esc_html__(
1007
-                'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
1008
-                'event_espresso'
1009
-            );
1010
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1011
-        }
1012
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1013
-        $success = $success ? 2 : false;
1014
-        $action  = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1015
-        $this->_redirect_after_action($success, 'Venues', $action, ['action' => 'default']);
1016
-    }
1017
-
1018
-
1019
-    /**
1020
-     * _trash_or_restore_venues
1021
-     *
1022
-     * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1023
-     * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1024
-     * accepting a certain number of params.
1025
-     *
1026
-     * @access  private
1027
-     * @param int    $VNU_ID
1028
-     * @param string $venue_status
1029
-     * @return bool
1030
-     * @throws EE_Error
1031
-     * @throws ReflectionException
1032
-     */
1033
-    private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1034
-    {
1035
-        // grab venue id
1036
-        if (! $VNU_ID) {
1037
-            $msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1038
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1039
-            return false;
1040
-        }
1041
-
1042
-        $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1043
-
1044
-        // clean status
1045
-        $venue_status = sanitize_key($venue_status);
1046
-        // grab status
1047
-        if (! $venue_status) {
1048
-            $msg = esc_html__(
1049
-                'An error occurred. No Venue Status or an invalid Venue Status was received.',
1050
-                'event_espresso'
1051
-            );
1052
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1053
-            return false;
1054
-        }
1055
-
1056
-        // was event trashed or restored ?
1057
-        switch ($venue_status) {
1058
-            case 'draft':
1059
-                $action = 'restored from the trash';
1060
-                $hook   = 'AHEE_venue_restored_from_trash';
1061
-                break;
1062
-            case 'trash':
1063
-                $action = 'moved to the trash';
1064
-                $hook   = 'AHEE_venue_moved_to_trash';
1065
-                break;
1066
-            default:
1067
-                $action = 'updated';
1068
-                $hook   = false;
1069
-        }
1070
-        // use class to change status
1071
-        $this->_cpt_model_obj->set_status($venue_status);
1072
-        $success = $this->_cpt_model_obj->save();
1073
-
1074
-        if ($success === false) {
1075
-            $msg = sprintf(esc_html__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1076
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1077
-            return false;
1078
-        }
1079
-        if ($hook) {
1080
-            do_action($hook);
1081
-        }
1082
-        return true;
1083
-    }
1084
-
1085
-
1086
-    /**
1087
-     * @param bool $redirect_after
1088
-     * @return void
1089
-     * @throws EE_Error
1090
-     * @throws ReflectionException
1091
-     */
1092
-    protected function _delete_venue($redirect_after = true)
1093
-    {
1094
-        // determine the venue id and set to array.
1095
-        $VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
1096
-        $VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
1097
-
1098
-        // loop thru venues
1099
-        if ($VNU_ID) {
1100
-            $success = $this->_delete_or_trash_venue($VNU_ID);
1101
-        } else {
1102
-            $success = false;
1103
-            $msg     = esc_html__(
1104
-                'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1105
-                'event_espresso'
1106
-            );
1107
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1108
-        }
1109
-        if ($redirect_after) {
1110
-            $this->_redirect_after_action($success, 'Venue', 'deleted', ['action' => 'default']);
1111
-        }
1112
-    }
1113
-
1114
-
1115
-    /**
1116
-     * @throws EE_Error
1117
-     * @throws ReflectionException
1118
-     */
1119
-    protected function _delete_venues()
1120
-    {
1121
-        $success = true;
1122
-        // determine the event id and set to array.
1123
-        $VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
1124
-        // loop thru events
1125
-        foreach ($VNU_IDs as $VNU_ID) {
1126
-            if ($VNU_ID = absint($VNU_ID)) {
1127
-                $results = $this->_delete_or_trash_venue($VNU_ID);
1128
-                $success = $results !== false ? $success : false;
1129
-            } else {
1130
-                $success = false;
1131
-                $msg     = esc_html__(
1132
-                    'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1133
-                    'event_espresso'
1134
-                );
1135
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1136
-            }
1137
-        }
1138
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1139
-        $success = $success ? 2 : false;
1140
-        $this->_redirect_after_action(
1141
-            $success,
1142
-            esc_html__('Venues', 'event_espresso'),
1143
-            esc_html__('deleted', 'event_espresso'),
1144
-            ['action' => 'default']
1145
-        );
1146
-    }
1147
-
1148
-
1149
-    // todo: put in parent
1150
-
1151
-
1152
-    /**
1153
-     * @throws EE_Error
1154
-     * @throws ReflectionException
1155
-     */
1156
-    private function _delete_or_trash_venue($VNU_ID = false)
1157
-    {
1158
-        // grab event id
1159
-        if (! $VNU_ID = absint($VNU_ID)) {
1160
-            $msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1161
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1162
-            return false;
1163
-        }
1164
-
1165
-
1166
-        $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1167
-        // first need to remove all term relationships
1168
-        $venue->_remove_relations('Term_Taxonomy');
1169
-        $success = $venue->delete_permanently();
1170
-        // did it all go as planned ?
1171
-        if ($success) {
1172
-            $msg = sprintf(esc_html__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1173
-            EE_Error::add_success($msg);
1174
-        } else {
1175
-            $msg =
1176
-                sprintf(
1177
-                    esc_html__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'),
1178
-                    $VNU_ID
1179
-                );
1180
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1181
-            return false;
1182
-        }
1183
-        do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1184
-        return true;
1185
-    }
1186
-
1187
-
1188
-
1189
-
1190
-    /***********/
1191
-    /* QUERIES */
1192
-
1193
-
1194
-    public function get_venues($per_page = 10, $count = false)
1195
-    {
1196
-
1197
-        $orderby = $this->request->getRequestParam('orderby', '');
1198
-
1199
-        switch ($orderby) {
1200
-            case 'id':
1201
-                $orderby = 'VNU_ID';
1202
-                break;
1203
-
1204
-            case 'capacity':
1205
-                $orderby = 'VNU_capacity';
1206
-                break;
1207
-
1208
-            case 'city':
1209
-                $orderby = 'VNU_city';
1210
-                break;
1211
-
1212
-            default:
1213
-                $orderby = 'VNU_name';
1214
-        }
1215
-
1216
-        $sort         = $this->request->getRequestParam('order', 'ASC');
1217
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1218
-        $per_page     = ! empty($per_page) ? $per_page : 10;
1219
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1220
-
1221
-        $offset = ($current_page - 1) * $per_page;
1222
-        $limit  = [$offset, $per_page];
1223
-
1224
-        $category = $this->request->getRequestParam('category');
1225
-        $category = $category > 0 ? $category : null;
1226
-
1227
-        $where = [];
1228
-
1229
-        // only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1230
-        $status = $this->request->getRequestParam('status');
1231
-        if ($status && $status !== 'all') {
1232
-            $where['status'] = $status;
1233
-        }
1234
-
1235
-        $venue_status = $this->request->getRequestParam('venue_status');
1236
-        if ($venue_status) {
1237
-            $where['status'] = $venue_status;
1238
-        }
1239
-
1240
-
1241
-        if ($category) {
1242
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1243
-            $where['Term_Taxonomy.term_id']  = $category;
1244
-        }
1245
-
1246
-
1247
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1248
-            $where['VNU_wp_user'] = get_current_user_id();
1249
-        } else {
1250
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1251
-                $where['OR'] = [
1252
-                    'status*restrict_private' => ['!=', 'private'],
1253
-                    'AND'                     => [
1254
-                        'status*inclusive' => ['=', 'private'],
1255
-                        'VNU_wp_user'      => get_current_user_id(),
1256
-                    ],
1257
-                ];
1258
-            }
1259
-        }
1260
-
1261
-        $search_term = $this->request->getRequestParam('s');
1262
-        if ($search_term) {
1263
-            $search_term = '%' . $search_term . '%';
1264
-            $where['OR'] = [
1265
-                'VNU_name'               => ['LIKE', $search_term],
1266
-                'VNU_desc'               => ['LIKE', $search_term],
1267
-                'VNU_short_desc'         => ['LIKE', $search_term],
1268
-                'VNU_address'            => ['LIKE', $search_term],
1269
-                'VNU_address2'           => ['LIKE', $search_term],
1270
-                'VNU_city'               => ['LIKE', $search_term],
1271
-                'VNU_zip'                => ['LIKE', $search_term],
1272
-                'VNU_phone'              => ['LIKE', $search_term],
1273
-                'VNU_url'                => ['LIKE', $search_term],
1274
-                'VNU_virtual_phone'      => ['LIKE', $search_term],
1275
-                'VNU_virtual_url'        => ['LIKE', $search_term],
1276
-                'VNU_google_map_link'    => ['LIKE', $search_term],
1277
-                'Event.EVT_name'         => ['LIKE', $search_term],
1278
-                'Event.EVT_desc'         => ['LIKE', $search_term],
1279
-                'Event.EVT_phone'        => ['LIKE', $search_term],
1280
-                'Event.EVT_external_URL' => ['LIKE', $search_term],
1281
-            ];
1282
-        }
1283
-
1284
-
1285
-        return $count
1286
-            ? $this->_venue_model->count([$where], 'VNU_ID')
1287
-            : $this->_venue_model->get_all(
1288
-                [$where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort]
1289
-            );
1290
-    }
1291
-
1292
-
1293
-
1294
-
1295
-    /** Venue Category Stuff **/
1296
-
1297
-    /**
1298
-     * set the _category property with the category object for the loaded page.
1299
-     *
1300
-     * @access private
1301
-     * @return void
1302
-     */
1303
-    private function _set_category_object()
1304
-    {
1305
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
1306
-            return;
1307
-        } // already have the category object so get out.
1308
-
1309
-        // set default category object
1310
-        $this->_set_empty_category_object();
1311
-
1312
-        // only set if we've got an id
1313
-        $category_ID = $this->request->getRequestParam('VEN_CAT_ID', 0, 'int');
1314
-        if (! $category_ID) {
1315
-            return;
1316
-        }
1317
-
1318
-        $term = get_term($category_ID, 'espresso_venue_categories');
1319
-
1320
-
1321
-        if (! empty($term)) {
1322
-            $this->_category->category_name       = $term->name;
1323
-            $this->_category->category_identifier = $term->slug;
1324
-            $this->_category->category_desc       = $term->description;
1325
-            $this->_category->id                  = $term->term_id;
1326
-            $this->_category->parent              = $term->parent;
1327
-        }
1328
-    }
1329
-
1330
-
1331
-    private function _set_empty_category_object()
1332
-    {
1333
-        $this->_category                = new stdClass();
1334
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1335
-        $this->_category->id            = $this->_category->parent = 0;
1336
-    }
1337
-
1338
-
1339
-    /**
1340
-     * @throws EE_Error
1341
-     */
1342
-    protected function _category_list_table()
1343
-    {
1344
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1345
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1346
-            'add_category',
1347
-            'add_category',
1348
-            [],
1349
-            'add-new-h2'
1350
-        );
1351
-        $this->_search_btn_label = esc_html__('Venue Categories', 'event_espresso');
1352
-        $this->display_admin_list_table_page_with_sidebar();
1353
-    }
1354
-
1355
-
1356
-    /**
1357
-     * @throws EE_Error
1358
-     */
1359
-    protected function _category_details($view)
1360
-    {
1361
-
1362
-        // load formatter helper
1363
-        // load field generator helper
1364
-
1365
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
1366
-        $this->_set_add_edit_form_tags($route);
1367
-
1368
-        $this->_set_category_object();
1369
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
1370
-
1371
-        $delete_action = 'delete_category';
1372
-
1373
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(['action' => 'category_list'], $this->_admin_base_url);
1374
-
1375
-        $this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1376
-
1377
-        // take care of contents
1378
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
1379
-        $this->display_admin_page_with_sidebar();
1380
-    }
1381
-
1382
-
1383
-    protected function _category_details_content()
1384
-    {
1385
-        $editor_args['category_desc'] = [
1386
-            'type'          => 'wp_editor',
1387
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1388
-            'class'         => 'my_editor_custom',
1389
-            'wpeditor_args' => ['media_buttons' => false],
1390
-        ];
1391
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
1392
-
1393
-        $all_terms = get_terms(
1394
-            ['espresso_venue_categories'],
1395
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
1396
-        );
1397
-
1398
-        // setup category select for term parents.
1399
-        $category_select_values[] = [
1400
-            'text' => esc_html__('No Parent', 'event_espresso'),
1401
-            'id'   => 0,
1402
-        ];
1403
-        foreach ($all_terms as $term) {
1404
-            $category_select_values[] = [
1405
-                'text' => $term->name,
1406
-                'id'   => $term->term_id,
1407
-            ];
1408
-        }
1409
-
1410
-        $category_select = EEH_Form_Fields::select_input(
1411
-            'category_parent',
1412
-            $category_select_values,
1413
-            $this->_category->parent
1414
-        );
1415
-        $template_args   = [
1416
-            'category'                 => $this->_category,
1417
-            'category_select'          => $category_select,
1418
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1419
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1420
-            'disable'                  => '',
1421
-            'disabled_message'         => false,
1422
-        ];
1423
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1424
-        return EEH_Template::display_template($template, $template_args, true);
1425
-    }
1426
-
1427
-
1428
-    /**
1429
-     * @throws EE_Error
1430
-     */
1431
-    protected function _delete_categories()
1432
-    {
1433
-        $category_ID  = $this->request->getRequestParam('category_id', 0, 'int');
1434
-        $category_IDs = $this->request->getRequestParam('VEN_CAT_ID', [$category_ID], 'int', true);
1435
-
1436
-        foreach ($category_IDs as $cat_id) {
1437
-            $this->_delete_category($cat_id);
1438
-        }
1439
-
1440
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
1441
-        $query_args = [
1442
-            'action' => 'category_list',
1443
-        ];
1444
-        $this->_redirect_after_action(0, '', '', $query_args);
1445
-    }
1446
-
1447
-
1448
-    protected function _delete_category($cat_id)
1449
-    {
1450
-        $cat_id = absint($cat_id);
1451
-        wp_delete_term($cat_id, 'espresso_venue_categories');
1452
-    }
1453
-
1454
-
1455
-    /**
1456
-     * @throws EE_Error
1457
-     */
1458
-    protected function _insert_or_update_category($new_category)
1459
-    {
1460
-
1461
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1462
-        $success = 0; // we already have a success message so lets not send another.
1463
-        if ($cat_id) {
1464
-            $query_args = [
1465
-                'action'     => 'edit_category',
1466
-                'VEN_CAT_ID' => $cat_id,
1467
-            ];
1468
-        } else {
1469
-            $query_args = ['action' => 'add_category'];
1470
-        }
1471
-        $this->_redirect_after_action($success, '', '', $query_args, true);
1472
-    }
1473
-
1474
-
1475
-    private function _insert_category($update = false)
1476
-    {
1477
-        $category_ID     = $update ? $this->request->getRequestParam('VEN_CAT_ID', '', 'int') : '';
1478
-        $category_name   = $this->request->getRequestParam('category_name', '');
1479
-        $category_desc   = $this->request->getRequestParam('category_desc', '', 'html');
1480
-        $category_parent = $this->request->getRequestParam('category_parent', 0, 'int');
1481
-
1482
-        if (empty($category_name)) {
1483
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
1484
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1485
-            return false;
1486
-        }
1487
-
1488
-
1489
-        $term_args = [
1490
-            'name'        => $category_name,
1491
-            'description' => $category_desc,
1492
-            'parent'      => $category_parent,
1493
-        ];
1494
-
1495
-        $insert_ids = $update
1496
-            ? wp_update_term($category_ID, 'espresso_venue_categories', $term_args)
1497
-            : wp_insert_term(
1498
-                $category_name,
1499
-                'espresso_venue_categories',
1500
-                $term_args
1501
-            );
1502
-
1503
-        if (! is_array($insert_ids)) {
1504
-            EE_Error::add_error(
1505
-                esc_html__('An error occurred and the category has not been saved to the database.', 'event_espresso'),
1506
-                __FILE__,
1507
-                __FUNCTION__,
1508
-                __LINE__
1509
-            );
1510
-        } else {
1511
-            $category_ID = $insert_ids['term_id'];
1512
-            EE_Error::add_success(
1513
-                sprintf(
1514
-                    esc_html__('The category %s was successfully created', 'event_espresso'),
1515
-                    $category_name
1516
-                )
1517
-            );
1518
-        }
1519
-
1520
-        return $category_ID;
1521
-    }
1522
-
1523
-
1524
-    /**
1525
-     * TODO handle category exports()
1526
-     *
1527
-     * @return void
1528
-     */
1529
-    protected function _categories_export()
1530
-    {
1531
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
1532
-        $this->request->mergeRequestParams(
1533
-            [
1534
-                'export'       => 'report',
1535
-                'action'       => 'categories',
1536
-                'category_ids' => $this->request->getRequestParam('VEN_CAT_ID', 0, 'int'),
1537
-            ]
1538
-        );
1539
-
1540
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1541
-            require_once(EE_CLASSES . 'EE_Export.class.php');
1542
-            $EE_Export = EE_Export::instance($this->request->requestParams());
1543
-            $EE_Export->export();
1544
-        }
1545
-    }
1546
-
1547
-
1548
-    protected function _import_categories()
1549
-    {
1550
-
1551
-        require_once(EE_CLASSES . 'EE_Import.class.php');
1552
-        EE_Import::instance()->import();
1553
-    }
1554
-
1555
-
1556
-    /**
1557
-     * @throws EE_Error
1558
-     */
1559
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
1560
-    {
1561
-
1562
-        // testing term stuff
1563
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
1564
-        $order       = $this->request->getRequestParam('order', 'DESC');
1565
-        $limit       = ($current_page - 1) * $per_page;
1566
-        $where       = ['taxonomy' => 'espresso_venue_categories'];
1567
-        $search_term = $this->request->getRequestParam('s');
1568
-        if ($search_term) {
1569
-            $search_term = '%' . $search_term . '%';
1570
-            $where['OR'] = [
1571
-                'Term.name'   => ['LIKE', $search_term],
1572
-                'description' => ['LIKE', $search_term],
1573
-            ];
1574
-        }
1575
-
1576
-        $query_params = [
1577
-            $where,
1578
-            'order_by'   => [$orderby => $order],
1579
-            'limit'      => $limit . ',' . $per_page,
1580
-            'force_join' => ['Term'],
1581
-        ];
1582
-
1583
-        return $count
1584
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1585
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
1586
-    }
1587
-
1588
-
1589
-    /* end category stuff */
1590
-    /**************/
589
+	protected function _google_map_settings()
590
+	{
591
+
592
+
593
+		$this->_template_args['values']           = $this->_yes_no_values;
594
+		$default_map_settings                     = new stdClass();
595
+		$default_map_settings->use_google_maps    = true;
596
+		$default_map_settings->google_map_api_key = '';
597
+		// for event details pages (reg page)
598
+		$default_map_settings->event_details_map_width    = 585;
599
+		// ee_map_width_single
600
+		$default_map_settings->event_details_map_height   = 362;
601
+		// ee_map_height_single
602
+		$default_map_settings->event_details_map_zoom     = 14;
603
+		// ee_map_zoom_single
604
+		$default_map_settings->event_details_display_nav  = true;
605
+		// ee_map_nav_display_single
606
+		$default_map_settings->event_details_nav_size     = false;
607
+		// ee_map_nav_size_single
608
+		$default_map_settings->event_details_control_type = 'default';
609
+		// ee_map_type_control_single
610
+		$default_map_settings->event_details_map_align    = 'center';
611
+		// ee_map_align_single
612
+
613
+		// for event list pages
614
+		$default_map_settings->event_list_map_width    = 300;
615
+		// ee_map_width
616
+		$default_map_settings->event_list_map_height   = 185;
617
+		// ee_map_height
618
+		$default_map_settings->event_list_map_zoom     = 12;
619
+		// ee_map_zoom
620
+		$default_map_settings->event_list_display_nav  = false;
621
+		// ee_map_nav_display
622
+		$default_map_settings->event_list_nav_size     = true;
623
+		// ee_map_nav_size
624
+		$default_map_settings->event_list_control_type = 'dropdown';
625
+		// ee_map_type_control
626
+		$default_map_settings->event_list_map_align    = 'center';
627
+		// ee_map_align
628
+
629
+		$this->_template_args['map_settings'] =
630
+			isset(EE_Registry::instance()->CFG->map_settings)
631
+			&& ! empty(EE_Registry::instance()->CFG->map_settings)
632
+				? (object) array_merge(
633
+					(array) $default_map_settings,
634
+					(array) EE_Registry::instance()->CFG->map_settings
635
+				)
636
+				: $default_map_settings;
637
+
638
+		$this->_set_add_edit_form_tags('update_google_map_settings');
639
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
640
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
641
+			EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
642
+			$this->_template_args,
643
+			true
644
+		);
645
+		$this->display_admin_page_with_sidebar();
646
+	}
647
+
648
+
649
+	/**
650
+	 * @throws EE_Error
651
+	 */
652
+	protected function _update_google_map_settings()
653
+	{
654
+		$map_settings = EE_Registry::instance()->CFG->map_settings;
655
+
656
+		$settings = [
657
+			'use_google_maps'            => 'int',
658
+			'google_map_api_key'         => 'string',
659
+			'event_details_map_width'    => 'int',
660
+			'event_details_map_zoom'     => 'int',
661
+			'event_details_display_nav'  => 'int',
662
+			'event_details_nav_size'     => 'int',
663
+			'event_details_control_type' => 'string',
664
+			'event_details_map_align'    => 'string',
665
+			'event_list_map_width'       => 'int',
666
+			'event_list_map_height'      => 'int',
667
+			'event_list_map_zoom'        => 'int',
668
+			'event_list_display_nav'     => 'int',
669
+			'event_list_nav_size'        => 'int',
670
+			'event_list_control_type'    => 'string',
671
+			'event_list_map_align'       => 'string',
672
+		];
673
+
674
+		foreach ($settings as $setting => $type) {
675
+			$map_settings->{$setting} = $this->request->getRequestParam($setting, $map_settings->{$setting}, $type);
676
+		}
677
+
678
+		EE_Registry::instance()->CFG->map_settings = apply_filters(
679
+			'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
680
+			$map_settings
681
+		);
682
+
683
+		$what    = 'Google Map Settings';
684
+		$success = $this->_update_espresso_configuration(
685
+			$what,
686
+			EE_Registry::instance()->CFG->map_settings,
687
+			__FILE__,
688
+			__FUNCTION__,
689
+			__LINE__
690
+		);
691
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'google_map_settings']);
692
+	}
693
+
694
+
695
+	/**
696
+	 * @throws EE_Error
697
+	 * @throws ReflectionException
698
+	 */
699
+	protected function _venue_editor_metaboxes()
700
+	{
701
+		$this->verify_cpt_object();
702
+
703
+		add_meta_box(
704
+			'espresso_venue_address_options',
705
+			esc_html__('Physical Location', 'event_espresso'),
706
+			[$this, 'venue_address_metabox'],
707
+			$this->page_slug,
708
+			'side'
709
+		);
710
+		add_meta_box(
711
+			'espresso_venue_gmap_options',
712
+			esc_html__('Google Map', 'event_espresso'),
713
+			[$this, 'venue_gmap_metabox'],
714
+			$this->page_slug,
715
+			'side'
716
+		);
717
+		add_meta_box(
718
+			'espresso_venue_virtual_loc_options',
719
+			esc_html__('Virtual Location', 'event_espresso'),
720
+			[$this, 'venue_virtual_loc_metabox'],
721
+			$this->page_slug,
722
+			'side'
723
+		);
724
+	}
725
+
726
+
727
+	public function venue_gmap_metabox()
728
+	{
729
+		$template_args = [
730
+			'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
731
+				'vnu_enable_for_gmap',
732
+				$this->get_yes_no_values(),
733
+				$this->_cpt_model_obj instanceof EE_Venue ? $this->_cpt_model_obj->enable_for_gmap() : false
734
+			),
735
+			'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
736
+		];
737
+		$template      = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
738
+		EEH_Template::display_template($template, $template_args);
739
+	}
740
+
741
+
742
+	/**
743
+	 * @throws EE_Error
744
+	 * @throws ReflectionException
745
+	 */
746
+	public function venue_address_metabox()
747
+	{
748
+		$template_args['_venue'] = $this->_cpt_model_obj;
749
+
750
+		$template_args['states_dropdown']    = EEH_Form_Fields::generate_form_input(
751
+			new EE_Question_Form_Input(
752
+				EE_Question::new_instance(
753
+					['QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state']
754
+				),
755
+				EE_Answer::new_instance(
756
+					[
757
+						'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
758
+							? $this->_cpt_model_obj->state_ID()
759
+							: 0,
760
+					]
761
+				),
762
+				[
763
+					'input_name'     => 'sta_id',
764
+					'input_id'       => 'sta_id',
765
+					'input_class'    => '',
766
+					'input_prefix'   => '',
767
+					'append_qstn_id' => false,
768
+				]
769
+			)
770
+		);
771
+		$template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
772
+			new EE_Question_Form_Input(
773
+				EE_Question::new_instance(
774
+					['QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country']
775
+				),
776
+				EE_Answer::new_instance(
777
+					[
778
+						'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
779
+							? $this->_cpt_model_obj->country_ID()
780
+							: 0,
781
+					]
782
+				),
783
+				[
784
+					'input_name'     => 'cnt_iso',
785
+					'input_id'       => 'cnt_iso',
786
+					'input_class'    => '',
787
+					'input_prefix'   => '',
788
+					'append_qstn_id' => false,
789
+				]
790
+			)
791
+		);
792
+
793
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
794
+		EEH_Template::display_template($template, $template_args);
795
+	}
796
+
797
+
798
+	public function venue_virtual_loc_metabox()
799
+	{
800
+		$template_args = [
801
+			'_venue' => $this->_cpt_model_obj,
802
+		];
803
+		$template      = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
804
+		EEH_Template::display_template($template, $template_args);
805
+	}
806
+
807
+
808
+	protected function _restore_cpt_item($post_id, $revision_id)
809
+	{
810
+		$venue_obj = $this->_venue_model->get_one_by_ID($post_id);
811
+
812
+		// meta revision restore
813
+		$venue_obj->restore_revision($revision_id);
814
+	}
815
+
816
+
817
+	/**
818
+	 * Handles updates for venue cpts
819
+	 *
820
+	 * @param int    $post_id ID of Venue CPT
821
+	 * @param object $post    Post object (with "blessed" WP properties)
822
+	 * @return void
823
+	 */
824
+	protected function _insert_update_cpt_item($post_id, $post)
825
+	{
826
+
827
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
828
+			return;// get out we're not processing the saving of venues.
829
+		}
830
+
831
+		$wheres = [$this->_venue_model->primary_key_name() => $post_id];
832
+
833
+		$venue_values = [
834
+			'VNU_address'         => $this->request->getRequestParam('vnu_address'),
835
+			'VNU_address2'        => $this->request->getRequestParam('vnu_address2'),
836
+			'VNU_city'            => $this->request->getRequestParam('vnu_city'),
837
+			'STA_ID'              => $this->request->getRequestParam('sta_id'),
838
+			'CNT_ISO'             => $this->request->getRequestParam('cnt_iso'),
839
+			'VNU_zip'             => $this->request->getRequestParam('vnu_zip'),
840
+			'VNU_phone'           => $this->request->getRequestParam('vnu_phone'),
841
+			'VNU_capacity'        => $this->request->requestParamIsSet('vnu_capacity')
842
+				? str_replace(',', '', $this->request->getRequestParam('vnu_capacity'))
843
+				: EE_INF,
844
+			'VNU_url'             => $this->request->getRequestParam('vnu_url'),
845
+			'VNU_virtual_phone'   => $this->request->getRequestParam('vnu_virtual_phone'),
846
+			'VNU_virtual_url'     => $this->request->getRequestParam('vnu_virtual_url'),
847
+			'VNU_enable_for_gmap' => $this->request->getRequestParam('vnu_enable_for_gmap', false, 'bool'),
848
+			'VNU_google_map_link' => $this->request->getRequestParam('vnu_google_map_link'),
849
+		];
850
+
851
+		// update venue
852
+		$success = $this->_venue_model->update($venue_values, [$wheres]);
853
+
854
+		// get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
855
+		$get_one_where = [$this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status];
856
+		$venue         = $this->_venue_model->get_one([$get_one_where]);
857
+
858
+		// notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
859
+		$venue_update_callbacks = apply_filters(
860
+			'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
861
+			[]
862
+		);
863
+		$att_success            = true;
864
+		foreach ($venue_update_callbacks as $v_callback) {
865
+			// if ANY of these updates fail then we want the appropriate global error message
866
+			$att_success = call_user_func_array($v_callback, [$venue, $this->request->requestParams()])
867
+				? $att_success
868
+				: false;
869
+		}
870
+
871
+		// any errors?
872
+		if ($success && ! $att_success) {
873
+			EE_Error::add_error(
874
+				esc_html__(
875
+					'Venue Details saved successfully but something went wrong with saving attachments.',
876
+					'event_espresso'
877
+				),
878
+				__FILE__,
879
+				__FUNCTION__,
880
+				__LINE__
881
+			);
882
+		} elseif ($success === false) {
883
+			EE_Error::add_error(
884
+				esc_html__('Venue Details did not save successfully.', 'event_espresso'),
885
+				__FILE__,
886
+				__FUNCTION__,
887
+				__LINE__
888
+			);
889
+		}
890
+	}
891
+
892
+
893
+	/**
894
+	 * @param int $post_id
895
+	 * @throws EE_Error
896
+	 * @throws ReflectionException
897
+	 */
898
+	public function trash_cpt_item($post_id)
899
+	{
900
+		$this->request->setRequestParam('VNU_ID', $post_id);
901
+		$this->_trash_or_restore_venue('trash', false);
902
+	}
903
+
904
+
905
+	/**
906
+	 * @param int $post_id
907
+	 * @throws EE_Error
908
+	 * @throws ReflectionException
909
+	 */
910
+	public function restore_cpt_item($post_id)
911
+	{
912
+		$this->request->setRequestParam('VNU_ID', $post_id);
913
+		$this->_trash_or_restore_venue('draft', false);
914
+	}
915
+
916
+
917
+	/**
918
+	 * @param int $post_id
919
+	 * @throws EE_Error
920
+	 * @throws ReflectionException
921
+	 */
922
+	public function delete_cpt_item($post_id)
923
+	{
924
+		$this->request->setRequestParam('VNU_ID', $post_id);
925
+		$this->_delete_venue(false);
926
+	}
927
+
928
+
929
+	public function get_venue_object()
930
+	{
931
+		return $this->_cpt_model_obj;
932
+	}
933
+
934
+
935
+	/**
936
+	 * @throws EE_Error
937
+	 * @throws ReflectionException
938
+	 */
939
+	protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
940
+	{
941
+		$VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
942
+
943
+		// loop thru venues
944
+		if ($VNU_ID) {
945
+			// clean status
946
+			$venue_status = sanitize_key($venue_status);
947
+			// grab status
948
+			if (! empty($venue_status)) {
949
+				$success = $this->_change_venue_status($VNU_ID, $venue_status);
950
+			} else {
951
+				$success = false;
952
+				$msg     = esc_html__(
953
+					'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
954
+					'event_espresso'
955
+				);
956
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
957
+			}
958
+		} else {
959
+			$success = false;
960
+			$msg     = esc_html__(
961
+				'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
962
+				'event_espresso'
963
+			);
964
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
965
+		}
966
+		$action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
967
+
968
+		if ($redirect_after) {
969
+			$this->_redirect_after_action($success, 'Venue', $action, ['action' => 'default']);
970
+		}
971
+	}
972
+
973
+
974
+	/**
975
+	 * @throws EE_Error
976
+	 * @throws ReflectionException
977
+	 */
978
+	protected function _trash_or_restore_venues($venue_status = 'trash')
979
+	{
980
+		// clean status
981
+		$venue_status = sanitize_key($venue_status);
982
+		// grab status
983
+		if (! empty($venue_status)) {
984
+			$success = true;
985
+			// determine the event id and set to array.
986
+			$VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
987
+			// loop thru events
988
+			foreach ($VNU_IDs as $VNU_ID) {
989
+				if ($VNU_ID = absint($VNU_ID)) {
990
+					$results = $this->_change_venue_status($VNU_ID, $venue_status);
991
+					$success = $results !== false ? $success : false;
992
+				} else {
993
+					$msg = sprintf(
994
+						esc_html__(
995
+							'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
996
+							'event_espresso'
997
+						),
998
+						$VNU_ID
999
+					);
1000
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1001
+					$success = false;
1002
+				}
1003
+			}
1004
+		} else {
1005
+			$success = false;
1006
+			$msg     = esc_html__(
1007
+				'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
1008
+				'event_espresso'
1009
+			);
1010
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1011
+		}
1012
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1013
+		$success = $success ? 2 : false;
1014
+		$action  = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1015
+		$this->_redirect_after_action($success, 'Venues', $action, ['action' => 'default']);
1016
+	}
1017
+
1018
+
1019
+	/**
1020
+	 * _trash_or_restore_venues
1021
+	 *
1022
+	 * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1023
+	 * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1024
+	 * accepting a certain number of params.
1025
+	 *
1026
+	 * @access  private
1027
+	 * @param int    $VNU_ID
1028
+	 * @param string $venue_status
1029
+	 * @return bool
1030
+	 * @throws EE_Error
1031
+	 * @throws ReflectionException
1032
+	 */
1033
+	private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1034
+	{
1035
+		// grab venue id
1036
+		if (! $VNU_ID) {
1037
+			$msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1038
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1039
+			return false;
1040
+		}
1041
+
1042
+		$this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1043
+
1044
+		// clean status
1045
+		$venue_status = sanitize_key($venue_status);
1046
+		// grab status
1047
+		if (! $venue_status) {
1048
+			$msg = esc_html__(
1049
+				'An error occurred. No Venue Status or an invalid Venue Status was received.',
1050
+				'event_espresso'
1051
+			);
1052
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1053
+			return false;
1054
+		}
1055
+
1056
+		// was event trashed or restored ?
1057
+		switch ($venue_status) {
1058
+			case 'draft':
1059
+				$action = 'restored from the trash';
1060
+				$hook   = 'AHEE_venue_restored_from_trash';
1061
+				break;
1062
+			case 'trash':
1063
+				$action = 'moved to the trash';
1064
+				$hook   = 'AHEE_venue_moved_to_trash';
1065
+				break;
1066
+			default:
1067
+				$action = 'updated';
1068
+				$hook   = false;
1069
+		}
1070
+		// use class to change status
1071
+		$this->_cpt_model_obj->set_status($venue_status);
1072
+		$success = $this->_cpt_model_obj->save();
1073
+
1074
+		if ($success === false) {
1075
+			$msg = sprintf(esc_html__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1076
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1077
+			return false;
1078
+		}
1079
+		if ($hook) {
1080
+			do_action($hook);
1081
+		}
1082
+		return true;
1083
+	}
1084
+
1085
+
1086
+	/**
1087
+	 * @param bool $redirect_after
1088
+	 * @return void
1089
+	 * @throws EE_Error
1090
+	 * @throws ReflectionException
1091
+	 */
1092
+	protected function _delete_venue($redirect_after = true)
1093
+	{
1094
+		// determine the venue id and set to array.
1095
+		$VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
1096
+		$VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
1097
+
1098
+		// loop thru venues
1099
+		if ($VNU_ID) {
1100
+			$success = $this->_delete_or_trash_venue($VNU_ID);
1101
+		} else {
1102
+			$success = false;
1103
+			$msg     = esc_html__(
1104
+				'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1105
+				'event_espresso'
1106
+			);
1107
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1108
+		}
1109
+		if ($redirect_after) {
1110
+			$this->_redirect_after_action($success, 'Venue', 'deleted', ['action' => 'default']);
1111
+		}
1112
+	}
1113
+
1114
+
1115
+	/**
1116
+	 * @throws EE_Error
1117
+	 * @throws ReflectionException
1118
+	 */
1119
+	protected function _delete_venues()
1120
+	{
1121
+		$success = true;
1122
+		// determine the event id and set to array.
1123
+		$VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
1124
+		// loop thru events
1125
+		foreach ($VNU_IDs as $VNU_ID) {
1126
+			if ($VNU_ID = absint($VNU_ID)) {
1127
+				$results = $this->_delete_or_trash_venue($VNU_ID);
1128
+				$success = $results !== false ? $success : false;
1129
+			} else {
1130
+				$success = false;
1131
+				$msg     = esc_html__(
1132
+					'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1133
+					'event_espresso'
1134
+				);
1135
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1136
+			}
1137
+		}
1138
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1139
+		$success = $success ? 2 : false;
1140
+		$this->_redirect_after_action(
1141
+			$success,
1142
+			esc_html__('Venues', 'event_espresso'),
1143
+			esc_html__('deleted', 'event_espresso'),
1144
+			['action' => 'default']
1145
+		);
1146
+	}
1147
+
1148
+
1149
+	// todo: put in parent
1150
+
1151
+
1152
+	/**
1153
+	 * @throws EE_Error
1154
+	 * @throws ReflectionException
1155
+	 */
1156
+	private function _delete_or_trash_venue($VNU_ID = false)
1157
+	{
1158
+		// grab event id
1159
+		if (! $VNU_ID = absint($VNU_ID)) {
1160
+			$msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1161
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1162
+			return false;
1163
+		}
1164
+
1165
+
1166
+		$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1167
+		// first need to remove all term relationships
1168
+		$venue->_remove_relations('Term_Taxonomy');
1169
+		$success = $venue->delete_permanently();
1170
+		// did it all go as planned ?
1171
+		if ($success) {
1172
+			$msg = sprintf(esc_html__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1173
+			EE_Error::add_success($msg);
1174
+		} else {
1175
+			$msg =
1176
+				sprintf(
1177
+					esc_html__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'),
1178
+					$VNU_ID
1179
+				);
1180
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1181
+			return false;
1182
+		}
1183
+		do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1184
+		return true;
1185
+	}
1186
+
1187
+
1188
+
1189
+
1190
+	/***********/
1191
+	/* QUERIES */
1192
+
1193
+
1194
+	public function get_venues($per_page = 10, $count = false)
1195
+	{
1196
+
1197
+		$orderby = $this->request->getRequestParam('orderby', '');
1198
+
1199
+		switch ($orderby) {
1200
+			case 'id':
1201
+				$orderby = 'VNU_ID';
1202
+				break;
1203
+
1204
+			case 'capacity':
1205
+				$orderby = 'VNU_capacity';
1206
+				break;
1207
+
1208
+			case 'city':
1209
+				$orderby = 'VNU_city';
1210
+				break;
1211
+
1212
+			default:
1213
+				$orderby = 'VNU_name';
1214
+		}
1215
+
1216
+		$sort         = $this->request->getRequestParam('order', 'ASC');
1217
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1218
+		$per_page     = ! empty($per_page) ? $per_page : 10;
1219
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1220
+
1221
+		$offset = ($current_page - 1) * $per_page;
1222
+		$limit  = [$offset, $per_page];
1223
+
1224
+		$category = $this->request->getRequestParam('category');
1225
+		$category = $category > 0 ? $category : null;
1226
+
1227
+		$where = [];
1228
+
1229
+		// only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1230
+		$status = $this->request->getRequestParam('status');
1231
+		if ($status && $status !== 'all') {
1232
+			$where['status'] = $status;
1233
+		}
1234
+
1235
+		$venue_status = $this->request->getRequestParam('venue_status');
1236
+		if ($venue_status) {
1237
+			$where['status'] = $venue_status;
1238
+		}
1239
+
1240
+
1241
+		if ($category) {
1242
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1243
+			$where['Term_Taxonomy.term_id']  = $category;
1244
+		}
1245
+
1246
+
1247
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1248
+			$where['VNU_wp_user'] = get_current_user_id();
1249
+		} else {
1250
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1251
+				$where['OR'] = [
1252
+					'status*restrict_private' => ['!=', 'private'],
1253
+					'AND'                     => [
1254
+						'status*inclusive' => ['=', 'private'],
1255
+						'VNU_wp_user'      => get_current_user_id(),
1256
+					],
1257
+				];
1258
+			}
1259
+		}
1260
+
1261
+		$search_term = $this->request->getRequestParam('s');
1262
+		if ($search_term) {
1263
+			$search_term = '%' . $search_term . '%';
1264
+			$where['OR'] = [
1265
+				'VNU_name'               => ['LIKE', $search_term],
1266
+				'VNU_desc'               => ['LIKE', $search_term],
1267
+				'VNU_short_desc'         => ['LIKE', $search_term],
1268
+				'VNU_address'            => ['LIKE', $search_term],
1269
+				'VNU_address2'           => ['LIKE', $search_term],
1270
+				'VNU_city'               => ['LIKE', $search_term],
1271
+				'VNU_zip'                => ['LIKE', $search_term],
1272
+				'VNU_phone'              => ['LIKE', $search_term],
1273
+				'VNU_url'                => ['LIKE', $search_term],
1274
+				'VNU_virtual_phone'      => ['LIKE', $search_term],
1275
+				'VNU_virtual_url'        => ['LIKE', $search_term],
1276
+				'VNU_google_map_link'    => ['LIKE', $search_term],
1277
+				'Event.EVT_name'         => ['LIKE', $search_term],
1278
+				'Event.EVT_desc'         => ['LIKE', $search_term],
1279
+				'Event.EVT_phone'        => ['LIKE', $search_term],
1280
+				'Event.EVT_external_URL' => ['LIKE', $search_term],
1281
+			];
1282
+		}
1283
+
1284
+
1285
+		return $count
1286
+			? $this->_venue_model->count([$where], 'VNU_ID')
1287
+			: $this->_venue_model->get_all(
1288
+				[$where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort]
1289
+			);
1290
+	}
1291
+
1292
+
1293
+
1294
+
1295
+	/** Venue Category Stuff **/
1296
+
1297
+	/**
1298
+	 * set the _category property with the category object for the loaded page.
1299
+	 *
1300
+	 * @access private
1301
+	 * @return void
1302
+	 */
1303
+	private function _set_category_object()
1304
+	{
1305
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
1306
+			return;
1307
+		} // already have the category object so get out.
1308
+
1309
+		// set default category object
1310
+		$this->_set_empty_category_object();
1311
+
1312
+		// only set if we've got an id
1313
+		$category_ID = $this->request->getRequestParam('VEN_CAT_ID', 0, 'int');
1314
+		if (! $category_ID) {
1315
+			return;
1316
+		}
1317
+
1318
+		$term = get_term($category_ID, 'espresso_venue_categories');
1319
+
1320
+
1321
+		if (! empty($term)) {
1322
+			$this->_category->category_name       = $term->name;
1323
+			$this->_category->category_identifier = $term->slug;
1324
+			$this->_category->category_desc       = $term->description;
1325
+			$this->_category->id                  = $term->term_id;
1326
+			$this->_category->parent              = $term->parent;
1327
+		}
1328
+	}
1329
+
1330
+
1331
+	private function _set_empty_category_object()
1332
+	{
1333
+		$this->_category                = new stdClass();
1334
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1335
+		$this->_category->id            = $this->_category->parent = 0;
1336
+	}
1337
+
1338
+
1339
+	/**
1340
+	 * @throws EE_Error
1341
+	 */
1342
+	protected function _category_list_table()
1343
+	{
1344
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1345
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1346
+			'add_category',
1347
+			'add_category',
1348
+			[],
1349
+			'add-new-h2'
1350
+		);
1351
+		$this->_search_btn_label = esc_html__('Venue Categories', 'event_espresso');
1352
+		$this->display_admin_list_table_page_with_sidebar();
1353
+	}
1354
+
1355
+
1356
+	/**
1357
+	 * @throws EE_Error
1358
+	 */
1359
+	protected function _category_details($view)
1360
+	{
1361
+
1362
+		// load formatter helper
1363
+		// load field generator helper
1364
+
1365
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
1366
+		$this->_set_add_edit_form_tags($route);
1367
+
1368
+		$this->_set_category_object();
1369
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
1370
+
1371
+		$delete_action = 'delete_category';
1372
+
1373
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(['action' => 'category_list'], $this->_admin_base_url);
1374
+
1375
+		$this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1376
+
1377
+		// take care of contents
1378
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
1379
+		$this->display_admin_page_with_sidebar();
1380
+	}
1381
+
1382
+
1383
+	protected function _category_details_content()
1384
+	{
1385
+		$editor_args['category_desc'] = [
1386
+			'type'          => 'wp_editor',
1387
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1388
+			'class'         => 'my_editor_custom',
1389
+			'wpeditor_args' => ['media_buttons' => false],
1390
+		];
1391
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
1392
+
1393
+		$all_terms = get_terms(
1394
+			['espresso_venue_categories'],
1395
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
1396
+		);
1397
+
1398
+		// setup category select for term parents.
1399
+		$category_select_values[] = [
1400
+			'text' => esc_html__('No Parent', 'event_espresso'),
1401
+			'id'   => 0,
1402
+		];
1403
+		foreach ($all_terms as $term) {
1404
+			$category_select_values[] = [
1405
+				'text' => $term->name,
1406
+				'id'   => $term->term_id,
1407
+			];
1408
+		}
1409
+
1410
+		$category_select = EEH_Form_Fields::select_input(
1411
+			'category_parent',
1412
+			$category_select_values,
1413
+			$this->_category->parent
1414
+		);
1415
+		$template_args   = [
1416
+			'category'                 => $this->_category,
1417
+			'category_select'          => $category_select,
1418
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1419
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1420
+			'disable'                  => '',
1421
+			'disabled_message'         => false,
1422
+		];
1423
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1424
+		return EEH_Template::display_template($template, $template_args, true);
1425
+	}
1426
+
1427
+
1428
+	/**
1429
+	 * @throws EE_Error
1430
+	 */
1431
+	protected function _delete_categories()
1432
+	{
1433
+		$category_ID  = $this->request->getRequestParam('category_id', 0, 'int');
1434
+		$category_IDs = $this->request->getRequestParam('VEN_CAT_ID', [$category_ID], 'int', true);
1435
+
1436
+		foreach ($category_IDs as $cat_id) {
1437
+			$this->_delete_category($cat_id);
1438
+		}
1439
+
1440
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
1441
+		$query_args = [
1442
+			'action' => 'category_list',
1443
+		];
1444
+		$this->_redirect_after_action(0, '', '', $query_args);
1445
+	}
1446
+
1447
+
1448
+	protected function _delete_category($cat_id)
1449
+	{
1450
+		$cat_id = absint($cat_id);
1451
+		wp_delete_term($cat_id, 'espresso_venue_categories');
1452
+	}
1453
+
1454
+
1455
+	/**
1456
+	 * @throws EE_Error
1457
+	 */
1458
+	protected function _insert_or_update_category($new_category)
1459
+	{
1460
+
1461
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1462
+		$success = 0; // we already have a success message so lets not send another.
1463
+		if ($cat_id) {
1464
+			$query_args = [
1465
+				'action'     => 'edit_category',
1466
+				'VEN_CAT_ID' => $cat_id,
1467
+			];
1468
+		} else {
1469
+			$query_args = ['action' => 'add_category'];
1470
+		}
1471
+		$this->_redirect_after_action($success, '', '', $query_args, true);
1472
+	}
1473
+
1474
+
1475
+	private function _insert_category($update = false)
1476
+	{
1477
+		$category_ID     = $update ? $this->request->getRequestParam('VEN_CAT_ID', '', 'int') : '';
1478
+		$category_name   = $this->request->getRequestParam('category_name', '');
1479
+		$category_desc   = $this->request->getRequestParam('category_desc', '', 'html');
1480
+		$category_parent = $this->request->getRequestParam('category_parent', 0, 'int');
1481
+
1482
+		if (empty($category_name)) {
1483
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
1484
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1485
+			return false;
1486
+		}
1487
+
1488
+
1489
+		$term_args = [
1490
+			'name'        => $category_name,
1491
+			'description' => $category_desc,
1492
+			'parent'      => $category_parent,
1493
+		];
1494
+
1495
+		$insert_ids = $update
1496
+			? wp_update_term($category_ID, 'espresso_venue_categories', $term_args)
1497
+			: wp_insert_term(
1498
+				$category_name,
1499
+				'espresso_venue_categories',
1500
+				$term_args
1501
+			);
1502
+
1503
+		if (! is_array($insert_ids)) {
1504
+			EE_Error::add_error(
1505
+				esc_html__('An error occurred and the category has not been saved to the database.', 'event_espresso'),
1506
+				__FILE__,
1507
+				__FUNCTION__,
1508
+				__LINE__
1509
+			);
1510
+		} else {
1511
+			$category_ID = $insert_ids['term_id'];
1512
+			EE_Error::add_success(
1513
+				sprintf(
1514
+					esc_html__('The category %s was successfully created', 'event_espresso'),
1515
+					$category_name
1516
+				)
1517
+			);
1518
+		}
1519
+
1520
+		return $category_ID;
1521
+	}
1522
+
1523
+
1524
+	/**
1525
+	 * TODO handle category exports()
1526
+	 *
1527
+	 * @return void
1528
+	 */
1529
+	protected function _categories_export()
1530
+	{
1531
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
1532
+		$this->request->mergeRequestParams(
1533
+			[
1534
+				'export'       => 'report',
1535
+				'action'       => 'categories',
1536
+				'category_ids' => $this->request->getRequestParam('VEN_CAT_ID', 0, 'int'),
1537
+			]
1538
+		);
1539
+
1540
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1541
+			require_once(EE_CLASSES . 'EE_Export.class.php');
1542
+			$EE_Export = EE_Export::instance($this->request->requestParams());
1543
+			$EE_Export->export();
1544
+		}
1545
+	}
1546
+
1547
+
1548
+	protected function _import_categories()
1549
+	{
1550
+
1551
+		require_once(EE_CLASSES . 'EE_Import.class.php');
1552
+		EE_Import::instance()->import();
1553
+	}
1554
+
1555
+
1556
+	/**
1557
+	 * @throws EE_Error
1558
+	 */
1559
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
1560
+	{
1561
+
1562
+		// testing term stuff
1563
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
1564
+		$order       = $this->request->getRequestParam('order', 'DESC');
1565
+		$limit       = ($current_page - 1) * $per_page;
1566
+		$where       = ['taxonomy' => 'espresso_venue_categories'];
1567
+		$search_term = $this->request->getRequestParam('s');
1568
+		if ($search_term) {
1569
+			$search_term = '%' . $search_term . '%';
1570
+			$where['OR'] = [
1571
+				'Term.name'   => ['LIKE', $search_term],
1572
+				'description' => ['LIKE', $search_term],
1573
+			];
1574
+		}
1575
+
1576
+		$query_params = [
1577
+			$where,
1578
+			'order_by'   => [$orderby => $order],
1579
+			'limit'      => $limit . ',' . $per_page,
1580
+			'force_join' => ['Term'],
1581
+		];
1582
+
1583
+		return $count
1584
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1585
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
1586
+	}
1587
+
1588
+
1589
+	/* end category stuff */
1590
+	/**************/
1591 1591
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
      */
46 46
     protected function _init_page_props()
47 47
     {
48
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
48
+        require_once(EE_MODELS.'EEM_Venue.model.php');
49 49
         $this->page_slug        = EE_VENUES_PG_SLUG;
50 50
         $this->_admin_base_url  = EE_VENUES_ADMIN_URL;
51
-        $this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
51
+        $this->_admin_base_path = EE_ADMIN_PAGES.'venues';
52 52
         $this->page_label       = esc_html__('Event Venues', 'event_espresso');
53 53
         $this->_cpt_model_names = [
54 54
             'create_new' => 'EEM_Venue',
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 
467 467
     public function load_scripts_styles()
468 468
     {
469
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
469
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
470 470
         wp_enqueue_style('ee-cat-admin');
471 471
     }
472 472
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
         wp_enqueue_style('espresso-ui-theme');
489 489
         wp_register_style(
490 490
             'espresso_venues',
491
-            EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
491
+            EE_VENUES_ASSETS_URL.'ee-venues-admin.css',
492 492
             [],
493 493
             EVENT_ESPRESSO_VERSION
494 494
         );
@@ -551,14 +551,14 @@  discard block
 block discarded – undo
551 551
             'button'
552 552
         );
553 553
 
554
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
554
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
555 555
             'create_new',
556 556
             'add',
557 557
             [],
558 558
             'add-new-h2'
559 559
         );
560 560
 
561
-        $this->_search_btn_label  = esc_html__('Venues', 'event_espresso');
561
+        $this->_search_btn_label = esc_html__('Venues', 'event_espresso');
562 562
         $this->display_admin_list_table_page_with_sidebar();
563 563
     }
564 564
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
             'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
575 575
             'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
576 576
         ];
577
-        $template   = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
577
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_publish_box_extras.template.php';
578 578
         EEH_Template::display_template($template, $extra_rows);
579 579
     }
580 580
 
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
         $this->_set_add_edit_form_tags('update_google_map_settings');
639 639
         $this->_set_publish_post_box_vars(null, false, false, null, false);
640 640
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
641
-            EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
641
+            EE_VENUES_TEMPLATE_PATH.'google_map.template.php',
642 642
             $this->_template_args,
643 643
             true
644 644
         );
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
             ),
735 735
             'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
736 736
         ];
737
-        $template      = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
737
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_gmap_metabox_content.template.php';
738 738
         EEH_Template::display_template($template, $template_args);
739 739
     }
740 740
 
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
     {
748 748
         $template_args['_venue'] = $this->_cpt_model_obj;
749 749
 
750
-        $template_args['states_dropdown']    = EEH_Form_Fields::generate_form_input(
750
+        $template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input(
751 751
             new EE_Question_Form_Input(
752 752
                 EE_Question::new_instance(
753 753
                     ['QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state']
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
             )
791 791
         );
792 792
 
793
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
793
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_address_metabox_content.template.php';
794 794
         EEH_Template::display_template($template, $template_args);
795 795
     }
796 796
 
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
         $template_args = [
801 801
             '_venue' => $this->_cpt_model_obj,
802 802
         ];
803
-        $template      = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
803
+        $template      = EE_VENUES_TEMPLATE_PATH.'venue_virtual_location_metabox_content.template.php';
804 804
         EEH_Template::display_template($template, $template_args);
805 805
     }
806 806
 
@@ -825,7 +825,7 @@  discard block
 block discarded – undo
825 825
     {
826 826
 
827 827
         if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
828
-            return;// get out we're not processing the saving of venues.
828
+            return; // get out we're not processing the saving of venues.
829 829
         }
830 830
 
831 831
         $wheres = [$this->_venue_model->primary_key_name() => $post_id];
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
             'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
861 861
             []
862 862
         );
863
-        $att_success            = true;
863
+        $att_success = true;
864 864
         foreach ($venue_update_callbacks as $v_callback) {
865 865
             // if ANY of these updates fail then we want the appropriate global error message
866 866
             $att_success = call_user_func_array($v_callback, [$venue, $this->request->requestParams()])
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
             // clean status
946 946
             $venue_status = sanitize_key($venue_status);
947 947
             // grab status
948
-            if (! empty($venue_status)) {
948
+            if ( ! empty($venue_status)) {
949 949
                 $success = $this->_change_venue_status($VNU_ID, $venue_status);
950 950
             } else {
951 951
                 $success = false;
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
         // clean status
981 981
         $venue_status = sanitize_key($venue_status);
982 982
         // grab status
983
-        if (! empty($venue_status)) {
983
+        if ( ! empty($venue_status)) {
984 984
             $success = true;
985 985
             // determine the event id and set to array.
986 986
             $VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
@@ -1033,7 +1033,7 @@  discard block
 block discarded – undo
1033 1033
     private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1034 1034
     {
1035 1035
         // grab venue id
1036
-        if (! $VNU_ID) {
1036
+        if ( ! $VNU_ID) {
1037 1037
             $msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1038 1038
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1039 1039
             return false;
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
         // clean status
1045 1045
         $venue_status = sanitize_key($venue_status);
1046 1046
         // grab status
1047
-        if (! $venue_status) {
1047
+        if ( ! $venue_status) {
1048 1048
             $msg = esc_html__(
1049 1049
                 'An error occurred. No Venue Status or an invalid Venue Status was received.',
1050 1050
                 'event_espresso'
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
     private function _delete_or_trash_venue($VNU_ID = false)
1157 1157
     {
1158 1158
         // grab event id
1159
-        if (! $VNU_ID = absint($VNU_ID)) {
1159
+        if ( ! $VNU_ID = absint($VNU_ID)) {
1160 1160
             $msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1161 1161
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1162 1162
             return false;
@@ -1244,10 +1244,10 @@  discard block
 block discarded – undo
1244 1244
         }
1245 1245
 
1246 1246
 
1247
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1247
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1248 1248
             $where['VNU_wp_user'] = get_current_user_id();
1249 1249
         } else {
1250
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1250
+            if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1251 1251
                 $where['OR'] = [
1252 1252
                     'status*restrict_private' => ['!=', 'private'],
1253 1253
                     'AND'                     => [
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 
1261 1261
         $search_term = $this->request->getRequestParam('s');
1262 1262
         if ($search_term) {
1263
-            $search_term = '%' . $search_term . '%';
1263
+            $search_term = '%'.$search_term.'%';
1264 1264
             $where['OR'] = [
1265 1265
                 'VNU_name'               => ['LIKE', $search_term],
1266 1266
                 'VNU_desc'               => ['LIKE', $search_term],
@@ -1311,14 +1311,14 @@  discard block
 block discarded – undo
1311 1311
 
1312 1312
         // only set if we've got an id
1313 1313
         $category_ID = $this->request->getRequestParam('VEN_CAT_ID', 0, 'int');
1314
-        if (! $category_ID) {
1314
+        if ( ! $category_ID) {
1315 1315
             return;
1316 1316
         }
1317 1317
 
1318 1318
         $term = get_term($category_ID, 'espresso_venue_categories');
1319 1319
 
1320 1320
 
1321
-        if (! empty($term)) {
1321
+        if ( ! empty($term)) {
1322 1322
             $this->_category->category_name       = $term->name;
1323 1323
             $this->_category->category_identifier = $term->slug;
1324 1324
             $this->_category->category_desc       = $term->description;
@@ -1342,7 +1342,7 @@  discard block
 block discarded – undo
1342 1342
     protected function _category_list_table()
1343 1343
     {
1344 1344
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1345
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1345
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1346 1346
             'add_category',
1347 1347
             'add_category',
1348 1348
             [],
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
             'class'         => 'my_editor_custom',
1389 1389
             'wpeditor_args' => ['media_buttons' => false],
1390 1390
         ];
1391
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
1391
+        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
1392 1392
 
1393 1393
         $all_terms = get_terms(
1394 1394
             ['espresso_venue_categories'],
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
             $category_select_values,
1413 1413
             $this->_category->parent
1414 1414
         );
1415
-        $template_args   = [
1415
+        $template_args = [
1416 1416
             'category'                 => $this->_category,
1417 1417
             'category_select'          => $category_select,
1418 1418
             'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
@@ -1420,7 +1420,7 @@  discard block
 block discarded – undo
1420 1420
             'disable'                  => '',
1421 1421
             'disabled_message'         => false,
1422 1422
         ];
1423
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1423
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
1424 1424
         return EEH_Template::display_template($template, $template_args, true);
1425 1425
     }
1426 1426
 
@@ -1500,7 +1500,7 @@  discard block
 block discarded – undo
1500 1500
                 $term_args
1501 1501
             );
1502 1502
 
1503
-        if (! is_array($insert_ids)) {
1503
+        if ( ! is_array($insert_ids)) {
1504 1504
             EE_Error::add_error(
1505 1505
                 esc_html__('An error occurred and the category has not been saved to the database.', 'event_espresso'),
1506 1506
                 __FILE__,
@@ -1537,8 +1537,8 @@  discard block
 block discarded – undo
1537 1537
             ]
1538 1538
         );
1539 1539
 
1540
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1541
-            require_once(EE_CLASSES . 'EE_Export.class.php');
1540
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
1541
+            require_once(EE_CLASSES.'EE_Export.class.php');
1542 1542
             $EE_Export = EE_Export::instance($this->request->requestParams());
1543 1543
             $EE_Export->export();
1544 1544
         }
@@ -1548,7 +1548,7 @@  discard block
 block discarded – undo
1548 1548
     protected function _import_categories()
1549 1549
     {
1550 1550
 
1551
-        require_once(EE_CLASSES . 'EE_Import.class.php');
1551
+        require_once(EE_CLASSES.'EE_Import.class.php');
1552 1552
         EE_Import::instance()->import();
1553 1553
     }
1554 1554
 
@@ -1566,7 +1566,7 @@  discard block
 block discarded – undo
1566 1566
         $where       = ['taxonomy' => 'espresso_venue_categories'];
1567 1567
         $search_term = $this->request->getRequestParam('s');
1568 1568
         if ($search_term) {
1569
-            $search_term = '%' . $search_term . '%';
1569
+            $search_term = '%'.$search_term.'%';
1570 1570
             $where['OR'] = [
1571 1571
                 'Term.name'   => ['LIKE', $search_term],
1572 1572
                 'description' => ['LIKE', $search_term],
@@ -1576,7 +1576,7 @@  discard block
 block discarded – undo
1576 1576
         $query_params = [
1577 1577
             $where,
1578 1578
             'order_by'   => [$orderby => $order],
1579
-            'limit'      => $limit . ',' . $per_page,
1579
+            'limit'      => $limit.','.$per_page,
1580 1580
             'force_join' => ['Term'],
1581 1581
         ];
1582 1582
 
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +4642 added lines, -4642 removed lines patch added patch discarded remove patch
@@ -16,2691 +16,2691 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19
-    /**
20
-     * @var EEM_Message
21
-     */
22
-    private $MSG_MODEL;
23
-
24
-    /**
25
-     * @var EEM_Message_Template
26
-     */
27
-    private $MTP_MODEL;
28
-
29
-    /**
30
-     * @var EEM_Message_Template_Group
31
-     */
32
-    private $MTG_MODEL;
33
-
34
-    /**
35
-     * @var EE_Message_Resource_Manager $_message_resource_manager
36
-     */
37
-    protected $_message_resource_manager;
38
-
39
-    /**
40
-     * @var string
41
-     */
42
-    protected $_active_message_type_name = '';
43
-
44
-    /**
45
-     * @var string
46
-     */
47
-    protected $_active_messenger_name = '';
48
-
49
-    /**
50
-     * @var EE_messenger $_active_messenger
51
-     */
52
-    protected $_active_messenger;
53
-
54
-    protected $_activate_meta_box_type;
55
-
56
-    protected $_current_message_meta_box;
57
-
58
-    protected $_current_message_meta_box_object;
59
-
60
-    protected $_context_switcher;
61
-
62
-    protected $_shortcodes           = [];
63
-
64
-    protected $_active_messengers    = [];
65
-
66
-    protected $_active_message_types = [];
67
-
68
-    /**
69
-     * @var EE_Message_Template_Group $_message_template_group
70
-     */
71
-    protected $_message_template_group;
72
-
73
-    protected $_m_mt_settings = [];
74
-
75
-
76
-    /**
77
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
78
-     * IF there is no group then it gets automatically set to the Default template pack.
79
-     *
80
-     * @since 4.5.0
81
-     *
82
-     * @var EE_Messages_Template_Pack
83
-     */
84
-    protected $_template_pack;
85
-
86
-
87
-    /**
88
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
89
-     * group is.  If there is no group then it automatically gets set to default.
90
-     *
91
-     * @since 4.5.0
92
-     *
93
-     * @var string
94
-     */
95
-    protected $_variation;
96
-
97
-
98
-    /**
99
-     * @param bool $routing
100
-     * @throws EE_Error
101
-     * @throws ReflectionException
102
-     */
103
-    public function __construct($routing = true)
104
-    {
105
-        // make sure messages autoloader is running
106
-        EED_Messages::set_autoloaders();
107
-        parent::__construct($routing);
108
-    }
109
-
110
-
111
-    /**
112
-     * @return EEM_Message
113
-     * @throws EE_Error
114
-     */
115
-    public function getMsgModel()
116
-    {
117
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
118
-            $this->MSG_MODEL = EEM_Message::instance();
119
-        }
120
-        return $this->MSG_MODEL;
121
-    }
122
-
123
-
124
-    /**
125
-     * @return EEM_Message_Template
126
-     * @throws EE_Error
127
-     */
128
-    public function getMtpModel()
129
-    {
130
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
-            $this->MTP_MODEL = EEM_Message_Template::instance();
132
-        }
133
-        return $this->MTP_MODEL;
134
-    }
135
-
136
-
137
-    /**
138
-     * @return EEM_Message_Template_Group
139
-     * @throws EE_Error
140
-     */
141
-    public function getMtgModel()
142
-    {
143
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
145
-        }
146
-        return $this->MTG_MODEL;
147
-    }
148
-
149
-
150
-    /**
151
-     * @throws EE_Error
152
-     * @throws ReflectionException
153
-     */
154
-    protected function _init_page_props()
155
-    {
156
-        $this->page_slug        = EE_MSG_PG_SLUG;
157
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
158
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
159
-        $this->_admin_base_path = EE_MSG_ADMIN;
160
-
161
-        $messenger    = $this->request->getRequestParam('messenger', '');
162
-        $message_type = $this->request->getRequestParam('message_type', '');
163
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
164
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
165
-
166
-        $this->_load_message_resource_manager();
167
-    }
168
-
169
-
170
-    /**
171
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
172
-     *
173
-     * @throws EE_Error
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     * @throws InvalidArgumentException
177
-     * @throws ReflectionException
178
-     */
179
-    protected function _load_message_resource_manager()
180
-    {
181
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
182
-    }
183
-
184
-
185
-    /**
186
-     * @return array
187
-     * @throws EE_Error
188
-     * @throws InvalidArgumentException
189
-     * @throws InvalidDataTypeException
190
-     * @throws InvalidInterfaceException
191
-     * @deprecated 4.9.9.rc.014
192
-     */
193
-    public function get_messengers_for_list_table()
194
-    {
195
-        EE_Error::doing_it_wrong(
196
-            __METHOD__,
197
-            sprintf(
198
-                esc_html__(
199
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
200
-                    'event_espresso'
201
-                ),
202
-                'Messages_Admin_Page::get_messengers_select_input()'
203
-            ),
204
-            '4.9.9.rc.014'
205
-        );
206
-
207
-        $m_values          = [];
208
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
209
-        // setup messengers for selects
210
-        $i = 1;
211
-        foreach ($active_messengers as $active_messenger) {
212
-            if ($active_messenger instanceof EE_Message) {
213
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
214
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
215
-                $i++;
216
-            }
217
-        }
218
-
219
-        return $m_values;
220
-    }
221
-
222
-
223
-    /**
224
-     * @return array
225
-     * @throws EE_Error
226
-     * @throws InvalidArgumentException
227
-     * @throws InvalidDataTypeException
228
-     * @throws InvalidInterfaceException
229
-     * @deprecated 4.9.9.rc.014
230
-     */
231
-    public function get_message_types_for_list_table()
232
-    {
233
-        EE_Error::doing_it_wrong(
234
-            __METHOD__,
235
-            sprintf(
236
-                esc_html__(
237
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
238
-                    'event_espresso'
239
-                ),
240
-                'Messages_Admin_Page::get_message_types_select_input()'
241
-            ),
242
-            '4.9.9.rc.014'
243
-        );
244
-
245
-        $mt_values       = [];
246
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
247
-        $i               = 1;
248
-        foreach ($active_messages as $active_message) {
249
-            if ($active_message instanceof EE_Message) {
250
-                $mt_values[ $i ]['id']   = $active_message->message_type();
251
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
252
-                $i++;
253
-            }
254
-        }
255
-
256
-        return $mt_values;
257
-    }
258
-
259
-
260
-    /**
261
-     * @return array
262
-     * @throws EE_Error
263
-     * @throws InvalidArgumentException
264
-     * @throws InvalidDataTypeException
265
-     * @throws InvalidInterfaceException
266
-     * @deprecated 4.9.9.rc.014
267
-     */
268
-    public function get_contexts_for_message_types_for_list_table()
269
-    {
270
-        EE_Error::doing_it_wrong(
271
-            __METHOD__,
272
-            sprintf(
273
-                esc_html__(
274
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
275
-                    'event_espresso'
276
-                ),
277
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
278
-            ),
279
-            '4.9.9.rc.014'
280
-        );
281
-
282
-        $contexts                = [];
283
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
284
-        foreach ($active_message_contexts as $active_message) {
285
-            if ($active_message instanceof EE_Message) {
286
-                $message_type = $active_message->message_type_object();
287
-                if ($message_type instanceof EE_message_type) {
288
-                    $message_type_contexts = $message_type->get_contexts();
289
-                    foreach ($message_type_contexts as $context => $context_details) {
290
-                        $contexts[ $context ] = $context_details['label'];
291
-                    }
292
-                }
293
-            }
294
-        }
295
-
296
-        return $contexts;
297
-    }
298
-
299
-
300
-    /**
301
-     * Generate select input with provided messenger options array.
302
-     *
303
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
304
-     *                                 labels.
305
-     * @return string
306
-     * @throws EE_Error
307
-     */
308
-    public function get_messengers_select_input($messenger_options)
309
-    {
310
-        // if empty or just one value then just return an empty string
311
-        if (
312
-            empty($messenger_options)
313
-            || ! is_array($messenger_options)
314
-            || count($messenger_options) === 1
315
-        ) {
316
-            return '';
317
-        }
318
-        // merge in default
319
-        $messenger_options = array_merge(
320
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
321
-            $messenger_options
322
-        );
323
-        $input             = new EE_Select_Input(
324
-            $messenger_options,
325
-            [
326
-                'html_name'  => 'ee_messenger_filter_by',
327
-                'html_id'    => 'ee_messenger_filter_by',
328
-                'html_class' => 'wide',
329
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
330
-            ]
331
-        );
332
-
333
-        return $input->get_html_for_input();
334
-    }
335
-
336
-
337
-    /**
338
-     * Generate select input with provided message type options array.
339
-     *
340
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
341
-     *                                    message type labels
342
-     * @return string
343
-     * @throws EE_Error
344
-     */
345
-    public function get_message_types_select_input($message_type_options)
346
-    {
347
-        // if empty or count of options is 1 then just return an empty string
348
-        if (
349
-            empty($message_type_options)
350
-            || ! is_array($message_type_options)
351
-            || count($message_type_options) === 1
352
-        ) {
353
-            return '';
354
-        }
355
-        // merge in default
356
-        $message_type_options = array_merge(
357
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
358
-            $message_type_options
359
-        );
360
-        $input                = new EE_Select_Input(
361
-            $message_type_options,
362
-            [
363
-                'html_name'  => 'ee_message_type_filter_by',
364
-                'html_id'    => 'ee_message_type_filter_by',
365
-                'html_class' => 'wide',
366
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
367
-            ]
368
-        );
369
-
370
-        return $input->get_html_for_input();
371
-    }
372
-
373
-
374
-    /**
375
-     * Generate select input with provide message type contexts array.
376
-     *
377
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
378
-     *                               context label.
379
-     * @return string
380
-     * @throws EE_Error
381
-     */
382
-    public function get_contexts_for_message_types_select_input($context_options)
383
-    {
384
-        // if empty or count of options is one then just return empty string
385
-        if (
386
-            empty($context_options)
387
-            || ! is_array($context_options)
388
-            || count($context_options) === 1
389
-        ) {
390
-            return '';
391
-        }
392
-        // merge in default
393
-        $context_options = array_merge(
394
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
395
-            $context_options
396
-        );
397
-        $input           = new EE_Select_Input(
398
-            $context_options,
399
-            [
400
-                'html_name'  => 'ee_context_filter_by',
401
-                'html_id'    => 'ee_context_filter_by',
402
-                'html_class' => 'wide',
403
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
404
-            ]
405
-        );
406
-
407
-        return $input->get_html_for_input();
408
-    }
409
-
410
-
411
-    protected function _ajax_hooks()
412
-    {
413
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
414
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
415
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
416
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
417
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
418
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
419
-    }
420
-
421
-
422
-    protected function _define_page_props()
423
-    {
424
-        $this->_admin_page_title = $this->page_label;
425
-        $this->_labels           = [
426
-            'buttons'    => [
427
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
428
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
429
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
430
-            ],
431
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
432
-        ];
433
-    }
434
-
435
-
436
-    /**
437
-     *        an array for storing key => value pairs of request actions and their corresponding methods
438
-     *
439
-     * @access protected
440
-     * @return void
441
-     */
442
-    protected function _set_page_routes()
443
-    {
444
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
445
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
446
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
447
-
448
-        $this->_page_routes = [
449
-            'default'                          => [
450
-                'func'       => '_message_queue_list_table',
451
-                'capability' => 'ee_read_global_messages',
452
-            ],
453
-            'global_mtps'                      => [
454
-                'func'       => '_ee_default_messages_overview_list_table',
455
-                'capability' => 'ee_read_global_messages',
456
-            ],
457
-            'custom_mtps'                      => [
458
-                'func'       => '_custom_mtps_preview',
459
-                'capability' => 'ee_read_messages',
460
-            ],
461
-            'add_new_message_template'         => [
462
-                'func'       => 'add_message_template',
463
-                'capability' => 'ee_edit_messages',
464
-                'noheader'   => true,
465
-            ],
466
-            'edit_message_template'            => [
467
-                'func'       => '_edit_message_template',
468
-                'capability' => 'ee_edit_message',
469
-                'obj_id'     => $GRP_ID,
470
-            ],
471
-            'preview_message'                  => [
472
-                'func'               => '_preview_message',
473
-                'capability'         => 'ee_read_message',
474
-                'obj_id'             => $GRP_ID,
475
-                'noheader'           => true,
476
-                'headers_sent_route' => 'display_preview_message',
477
-            ],
478
-            'display_preview_message'          => [
479
-                'func'       => '_display_preview_message',
480
-                'capability' => 'ee_read_message',
481
-                'obj_id'     => $GRP_ID,
482
-            ],
483
-            'insert_message_template'          => [
484
-                'func'       => '_insert_or_update_message_template',
485
-                'capability' => 'ee_edit_messages',
486
-                'args'       => ['new' => true],
487
-                'noheader'   => true,
488
-            ],
489
-            'update_message_template'          => [
490
-                'func'       => '_insert_or_update_message_template',
491
-                'capability' => 'ee_edit_message',
492
-                'obj_id'     => $GRP_ID,
493
-                'args'       => ['new' => false],
494
-                'noheader'   => true,
495
-            ],
496
-            'trash_message_template'           => [
497
-                'func'       => '_trash_or_restore_message_template',
498
-                'capability' => 'ee_delete_message',
499
-                'obj_id'     => $GRP_ID,
500
-                'args'       => ['trash' => true, 'all' => true],
501
-                'noheader'   => true,
502
-            ],
503
-            'trash_message_template_context'   => [
504
-                'func'       => '_trash_or_restore_message_template',
505
-                'capability' => 'ee_delete_message',
506
-                'obj_id'     => $GRP_ID,
507
-                'args'       => ['trash' => true],
508
-                'noheader'   => true,
509
-            ],
510
-            'restore_message_template'         => [
511
-                'func'       => '_trash_or_restore_message_template',
512
-                'capability' => 'ee_delete_message',
513
-                'obj_id'     => $GRP_ID,
514
-                'args'       => ['trash' => false, 'all' => true],
515
-                'noheader'   => true,
516
-            ],
517
-            'restore_message_template_context' => [
518
-                'func'       => '_trash_or_restore_message_template',
519
-                'capability' => 'ee_delete_message',
520
-                'obj_id'     => $GRP_ID,
521
-                'args'       => ['trash' => false],
522
-                'noheader'   => true,
523
-            ],
524
-            'delete_message_template'          => [
525
-                'func'       => '_delete_message_template',
526
-                'capability' => 'ee_delete_message',
527
-                'obj_id'     => $GRP_ID,
528
-                'noheader'   => true,
529
-            ],
530
-            'reset_to_default'                 => [
531
-                'func'       => '_reset_to_default_template',
532
-                'capability' => 'ee_edit_message',
533
-                'obj_id'     => $GRP_ID,
534
-                'noheader'   => true,
535
-            ],
536
-            'settings'                         => [
537
-                'func'       => '_settings',
538
-                'capability' => 'manage_options',
539
-            ],
540
-            'update_global_settings'           => [
541
-                'func'       => '_update_global_settings',
542
-                'capability' => 'manage_options',
543
-                'noheader'   => true,
544
-            ],
545
-            'generate_now'                     => [
546
-                'func'       => '_generate_now',
547
-                'capability' => 'ee_send_message',
548
-                'noheader'   => true,
549
-            ],
550
-            'generate_and_send_now'            => [
551
-                'func'       => '_generate_and_send_now',
552
-                'capability' => 'ee_send_message',
553
-                'noheader'   => true,
554
-            ],
555
-            'queue_for_resending'              => [
556
-                'func'       => '_queue_for_resending',
557
-                'capability' => 'ee_send_message',
558
-                'noheader'   => true,
559
-            ],
560
-            'send_now'                         => [
561
-                'func'       => '_send_now',
562
-                'capability' => 'ee_send_message',
563
-                'noheader'   => true,
564
-            ],
565
-            'delete_ee_message'                => [
566
-                'func'       => '_delete_ee_messages',
567
-                'capability' => 'ee_delete_messages',
568
-                'noheader'   => true,
569
-            ],
570
-            'delete_ee_messages'               => [
571
-                'func'       => '_delete_ee_messages',
572
-                'capability' => 'ee_delete_messages',
573
-                'noheader'   => true,
574
-                'obj_id'     => $MSG_ID,
575
-            ],
576
-        ];
577
-    }
578
-
579
-
580
-    protected function _set_page_config()
581
-    {
582
-        $this->_page_config = [
583
-            'default'                  => [
584
-                'nav'           => [
585
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
586
-                    'order' => 10,
587
-                ],
588
-                'list_table'    => 'EE_Message_List_Table',
589
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
590
-                'require_nonce' => false,
591
-            ],
592
-            'global_mtps'              => [
593
-                'nav'           => [
594
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
595
-                    'order' => 20,
596
-                ],
597
-                'list_table'    => 'Messages_Template_List_Table',
598
-                'help_tabs'     => [
599
-                    'messages_overview_help_tab'                                => [
600
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
601
-                        'filename' => 'messages_overview',
602
-                    ],
603
-                    'messages_overview_messages_table_column_headings_help_tab' => [
604
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
605
-                        'filename' => 'messages_overview_table_column_headings',
606
-                    ],
607
-                    'messages_overview_messages_filters_help_tab'               => [
608
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
609
-                        'filename' => 'messages_overview_filters',
610
-                    ],
611
-                    'messages_overview_messages_views_help_tab'                 => [
612
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
613
-                        'filename' => 'messages_overview_views',
614
-                    ],
615
-                    'message_overview_message_types_help_tab'                   => [
616
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
617
-                        'filename' => 'messages_overview_types',
618
-                    ],
619
-                    'messages_overview_messengers_help_tab'                     => [
620
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
621
-                        'filename' => 'messages_overview_messengers',
622
-                    ],
623
-                ],
624
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
625
-                // 'help_tour'     => array('Messages_Overview_Help_Tour'),
626
-                'require_nonce' => false,
627
-            ],
628
-            'custom_mtps'              => [
629
-                'nav'           => [
630
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
631
-                    'order' => 30,
632
-                ],
633
-                'help_tabs'     => [],
634
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
635
-                // 'help_tour'     => array(),
636
-                'require_nonce' => false,
637
-            ],
638
-            'add_new_message_template' => [
639
-                'nav'           => [
640
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
641
-                    'order'      => 5,
642
-                    'persistent' => false,
643
-                ],
644
-                'require_nonce' => false,
645
-            ],
646
-            'edit_message_template'    => [
647
-                'labels'        => [
648
-                    'buttons'    => [
649
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
650
-                    ],
651
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
652
-                ],
653
-                'nav'           => [
654
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
655
-                    'order'      => 5,
656
-                    'persistent' => false,
657
-                    'url'        => '',
658
-                ],
659
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
660
-                'has_metaboxes' => true,
661
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
662
-                // 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
663
-                'help_tabs'     => [
664
-                    'edit_message_template'            => [
665
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
666
-                        'callback' => 'edit_message_template_help_tab',
667
-                    ],
668
-                    'message_templates_help_tab'       => [
669
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
670
-                        'filename' => 'messages_templates',
671
-                    ],
672
-                    'message_template_shortcodes'      => [
673
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
674
-                        'callback' => 'message_template_shortcodes_help_tab',
675
-                    ],
676
-                    'message_preview_help_tab'         => [
677
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
678
-                        'filename' => 'messages_preview',
679
-                    ],
680
-                    'messages_overview_other_help_tab' => [
681
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
682
-                        'filename' => 'messages_overview_other',
683
-                    ],
684
-                ],
685
-                'require_nonce' => false,
686
-            ],
687
-            'display_preview_message'  => [
688
-                'nav'           => [
689
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
690
-                    'order'      => 5,
691
-                    'url'        => '',
692
-                    'persistent' => false,
693
-                ],
694
-                'help_tabs'     => [
695
-                    'preview_message' => [
696
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
697
-                        'callback' => 'preview_message_help_tab',
698
-                    ],
699
-                ],
700
-                'require_nonce' => false,
701
-            ],
702
-            'settings'                 => [
703
-                'nav'           => [
704
-                    'label' => esc_html__('Settings', 'event_espresso'),
705
-                    'order' => 40,
706
-                ],
707
-                'metaboxes'     => ['_messages_settings_metaboxes'],
708
-                'help_tabs'     => [
709
-                    'messages_settings_help_tab'               => [
710
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
711
-                        'filename' => 'messages_settings',
712
-                    ],
713
-                    'messages_settings_message_types_help_tab' => [
714
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
715
-                        'filename' => 'messages_settings_message_types',
716
-                    ],
717
-                    'messages_settings_messengers_help_tab'    => [
718
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
719
-                        'filename' => 'messages_settings_messengers',
720
-                    ],
721
-                ],
722
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
723
-                // 'help_tour'     => array('Messages_Settings_Help_Tour'),
724
-                'require_nonce' => false,
725
-            ],
726
-        ];
727
-    }
728
-
729
-
730
-    protected function _add_screen_options()
731
-    {
732
-        // todo
733
-    }
734
-
735
-
736
-    protected function _add_screen_options_global_mtps()
737
-    {
738
-        /**
739
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
740
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
741
-         */
742
-        $page_title              = $this->_admin_page_title;
743
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
744
-        $this->_per_page_screen_option();
745
-        $this->_admin_page_title = $page_title;
746
-    }
747
-
748
-
749
-    protected function _add_screen_options_default()
750
-    {
751
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
752
-        $this->_per_page_screen_option();
753
-    }
754
-
755
-
756
-    // none of the below group are currently used for Messages
757
-    protected function _add_feature_pointers()
758
-    {
759
-    }
760
-
761
-
762
-    public function admin_init()
763
-    {
764
-    }
765
-
766
-
767
-    public function admin_notices()
768
-    {
769
-    }
770
-
771
-
772
-    public function admin_footer_scripts()
773
-    {
774
-    }
775
-
776
-
777
-    public function messages_help_tab()
778
-    {
779
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
780
-    }
781
-
782
-
783
-    public function messengers_help_tab()
784
-    {
785
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
786
-    }
787
-
788
-
789
-    public function message_types_help_tab()
790
-    {
791
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
792
-    }
793
-
794
-
795
-    public function messages_overview_help_tab()
796
-    {
797
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
798
-    }
799
-
800
-
801
-    public function message_templates_help_tab()
802
-    {
803
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
804
-    }
805
-
806
-
807
-    public function edit_message_template_help_tab()
808
-    {
809
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
810
-                        . esc_attr__('Editor Title', 'event_espresso')
811
-                        . '" />';
812
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
813
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
814
-                        . '" />';
815
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
816
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
817
-                        . '" />';
818
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
819
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
820
-                        . '" />';
821
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
822
-                        . esc_attr__('Publish Metabox', 'event_espresso')
823
-                        . '" />';
824
-        EEH_Template::display_template(
825
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
826
-            $args
827
-        );
828
-    }
829
-
830
-
831
-    /**
832
-     * @throws ReflectionException
833
-     * @throws EE_Error
834
-     */
835
-    public function message_template_shortcodes_help_tab()
836
-    {
837
-        $this->_set_shortcodes();
838
-        $args['shortcodes'] = $this->_shortcodes;
839
-        EEH_Template::display_template(
840
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
841
-            $args
842
-        );
843
-    }
844
-
845
-
846
-    public function preview_message_help_tab()
847
-    {
848
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
849
-    }
850
-
851
-
852
-    public function settings_help_tab()
853
-    {
854
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
855
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
856
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
857
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
858
-        $args['img3'] = '<div class="switch">'
859
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
860
-                        . ' type="checkbox" checked="checked">'
861
-                        . '<label for="ee-on-off-toggle-on"></label>'
862
-                        . '</div>';
863
-        $args['img4'] = '<div class="switch">'
864
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
865
-                        . ' type="checkbox">'
866
-                        . '<label for="ee-on-off-toggle-on"></label>'
867
-                        . '</div>';
868
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
869
-    }
870
-
871
-
872
-    public function load_scripts_styles()
873
-    {
874
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
875
-        wp_enqueue_style('espresso_ee_msg');
876
-
877
-        wp_register_script(
878
-            'ee-messages-settings',
879
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
880
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
881
-            EVENT_ESPRESSO_VERSION,
882
-            true
883
-        );
884
-        wp_register_script(
885
-            'ee-msg-list-table-js',
886
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
887
-            ['ee-dialog'],
888
-            EVENT_ESPRESSO_VERSION
889
-        );
890
-    }
891
-
892
-
893
-    public function load_scripts_styles_default()
894
-    {
895
-        wp_enqueue_script('ee-msg-list-table-js');
896
-    }
897
-
898
-
899
-    public function wp_editor_css($mce_css)
900
-    {
901
-        // if we're on the edit_message_template route
902
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
903
-            $message_type_name = $this->_active_message_type_name;
904
-
905
-            // we're going to REPLACE the existing mce css
906
-            // we need to get the css file location from the active messenger
907
-            $mce_css = $this->_active_messenger->get_variation(
908
-                $this->_template_pack,
909
-                $message_type_name,
910
-                true,
911
-                'wpeditor',
912
-                $this->_variation
913
-            );
914
-        }
915
-
916
-        return $mce_css;
917
-    }
918
-
919
-
920
-    /**
921
-     * @throws EE_Error
922
-     * @throws ReflectionException
923
-     */
924
-    public function load_scripts_styles_edit_message_template()
925
-    {
926
-
927
-        $this->_set_shortcodes();
928
-
929
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
930
-            esc_html__(
931
-                '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.',
932
-                'event_espresso'
933
-            ),
934
-            $this->_message_template_group->messenger_obj()->label['singular'],
935
-            $this->_message_template_group->message_type_obj()->label['singular']
936
-        );
937
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
938
-            '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?',
939
-            'event_espresso'
940
-        );
941
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
942
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
943
-            'event_espresso'
944
-        );
945
-
946
-        wp_register_script(
947
-            'ee_msgs_edit_js',
948
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
949
-            ['jquery'],
950
-            EVENT_ESPRESSO_VERSION
951
-        );
952
-
953
-        wp_enqueue_script('ee_admin_js');
954
-        wp_enqueue_script('ee_msgs_edit_js');
955
-
956
-        // add in special css for tiny_mce
957
-        add_filter('mce_css', [$this, 'wp_editor_css']);
958
-    }
959
-
960
-
961
-    /**
962
-     * @throws EE_Error
963
-     * @throws ReflectionException
964
-     */
965
-    public function load_scripts_styles_display_preview_message()
966
-    {
967
-        $this->_set_message_template_group();
968
-        if ($this->_active_messenger_name) {
969
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
970
-                $this->_active_messenger_name
971
-            );
972
-        }
973
-
974
-        wp_enqueue_style(
975
-            'espresso_preview_css',
976
-            $this->_active_messenger->get_variation(
977
-                $this->_template_pack,
978
-                $this->_active_message_type_name,
979
-                true,
980
-                'preview',
981
-                $this->_variation
982
-            )
983
-        );
984
-    }
985
-
986
-
987
-    public function load_scripts_styles_settings()
988
-    {
989
-        wp_register_style(
990
-            'ee-message-settings',
991
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
992
-            [],
993
-            EVENT_ESPRESSO_VERSION
994
-        );
995
-        wp_enqueue_style('ee-text-links');
996
-        wp_enqueue_style('ee-message-settings');
997
-        wp_enqueue_script('ee-messages-settings');
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * set views array for List Table
1003
-     */
1004
-    public function _set_list_table_views_global_mtps()
1005
-    {
1006
-        $this->_views = [
1007
-            'in_use' => [
1008
-                'slug'  => 'in_use',
1009
-                'label' => esc_html__('In Use', 'event_espresso'),
1010
-                'count' => 0,
1011
-            ],
1012
-        ];
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * Set views array for the Custom Template List Table
1018
-     */
1019
-    public function _set_list_table_views_custom_mtps()
1020
-    {
1021
-        $this->_set_list_table_views_global_mtps();
1022
-        $this->_views['in_use']['bulk_action'] = [
1023
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1024
-        ];
1025
-    }
1026
-
1027
-
1028
-    /**
1029
-     * set views array for message queue list table
1030
-     *
1031
-     * @throws InvalidDataTypeException
1032
-     * @throws InvalidInterfaceException
1033
-     * @throws InvalidArgumentException
1034
-     * @throws EE_Error
1035
-     * @throws ReflectionException
1036
-     */
1037
-    public function _set_list_table_views_default()
1038
-    {
1039
-        EE_Registry::instance()->load_helper('Template');
1040
-
1041
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1042
-            'ee_send_message',
1043
-            'message_list_table_bulk_actions'
1044
-        )
1045
-            ? [
1046
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1047
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1048
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1049
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1050
-            ]
1051
-            : [];
1052
-
1053
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1054
-            'ee_delete_messages',
1055
-            'message_list_table_bulk_actions'
1056
-        )
1057
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1058
-            : [];
1059
-
1060
-
1061
-        $this->_views = [
1062
-            'all' => [
1063
-                'slug'        => 'all',
1064
-                'label'       => esc_html__('All', 'event_espresso'),
1065
-                'count'       => 0,
1066
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1067
-            ],
1068
-        ];
1069
-
1070
-
1071
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1072
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1073
-                continue;
1074
-            }
1075
-            $status_bulk_actions = $common_bulk_actions;
1076
-            // unset bulk actions not applying to status
1077
-            if (! empty($status_bulk_actions)) {
1078
-                switch ($status) {
1079
-                    case EEM_Message::status_idle:
1080
-                    case EEM_Message::status_resend:
1081
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1082
-                        break;
1083
-
1084
-                    case EEM_Message::status_failed:
1085
-                    case EEM_Message::status_debug_only:
1086
-                    case EEM_Message::status_messenger_executing:
1087
-                        $status_bulk_actions = [];
1088
-                        break;
1089
-
1090
-                    case EEM_Message::status_incomplete:
1091
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1092
-                        break;
1093
-
1094
-                    case EEM_Message::status_retry:
1095
-                    case EEM_Message::status_sent:
1096
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1097
-                        break;
1098
-                }
1099
-            }
1100
-
1101
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1102
-            if ($status === EEM_Message::status_messenger_executing) {
1103
-                continue;
1104
-            }
1105
-
1106
-            $this->_views[ strtolower($status) ] = [
1107
-                'slug'        => strtolower($status),
1108
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1109
-                'count'       => 0,
1110
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1111
-            ];
1112
-        }
1113
-    }
1114
-
1115
-
1116
-    /**
1117
-     * @throws EE_Error
1118
-     */
1119
-    protected function _ee_default_messages_overview_list_table()
1120
-    {
1121
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1122
-        $this->display_admin_list_table_page_with_no_sidebar();
1123
-    }
1124
-
1125
-
1126
-    /**
1127
-     * @throws EE_Error
1128
-     * @throws ReflectionException
1129
-     */
1130
-    protected function _message_queue_list_table()
1131
-    {
1132
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1133
-        $this->_template_args['per_column']        = 6;
1134
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1135
-        $this->_template_args['before_list_table'] = '<h3>'
1136
-                                                     . $this->getMsgModel()->get_pretty_label_for_results()
1137
-                                                     . '</h3>';
1138
-        $this->display_admin_list_table_page_with_no_sidebar();
1139
-    }
1140
-
1141
-
1142
-    /**
1143
-     * @throws EE_Error
1144
-     */
1145
-    protected function _message_legend_items()
1146
-    {
1147
-
1148
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1149
-        $action_items       = [];
1150
-
1151
-        foreach ($action_css_classes as $action_item => $action_details) {
1152
-            if ($action_item === 'see_notifications_for') {
1153
-                continue;
1154
-            }
1155
-            $action_items[ $action_item ] = [
1156
-                'class' => $action_details['css_class'],
1157
-                'desc'  => $action_details['label'],
1158
-            ];
1159
-        }
1160
-
1161
-        /** @var array $status_items status legend setup */
1162
-        $status_items = [
1163
-            'sent_status'                => [
1164
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1165
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1166
-            ],
1167
-            'idle_status'                => [
1168
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1169
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1170
-            ],
1171
-            'failed_status'              => [
1172
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1173
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1174
-            ],
1175
-            'messenger_executing_status' => [
1176
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1177
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1178
-            ],
1179
-            'resend_status'              => [
1180
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1181
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1182
-            ],
1183
-            'incomplete_status'          => [
1184
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1185
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1186
-            ],
1187
-            'retry_status'               => [
1188
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1189
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1190
-            ],
1191
-        ];
1192
-        if (EEM_Message::debug()) {
1193
-            $status_items['debug_only_status'] = [
1194
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1195
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1196
-            ];
1197
-        }
1198
-
1199
-        return array_merge($action_items, $status_items);
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * @throws EE_Error
1205
-     */
1206
-    protected function _custom_mtps_preview()
1207
-    {
1208
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1209
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1210
-                                                . ' alt="' . esc_attr__(
1211
-                                                    'Preview Custom Message Templates screenshot',
1212
-                                                    'event_espresso'
1213
-                                                ) . '" />';
1214
-        $this->_template_args['preview_text'] = '<strong>'
1215
-                                                . esc_html__(
1216
-                                                    '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.',
1217
-                                                    'event_espresso'
1218
-                                                )
1219
-                                                . '</strong>';
1220
-
1221
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * get_message_templates
1227
-     * This gets all the message templates for listing on the overview list.
1228
-     *
1229
-     * @access public
1230
-     * @param int    $per_page the amount of templates groups to show per page
1231
-     * @param string $type     the current _view we're getting templates for
1232
-     * @param bool   $count    return count?
1233
-     * @param bool   $all      disregard any paging info (get all data);
1234
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1235
-     * @return array
1236
-     * @throws EE_Error
1237
-     * @throws InvalidArgumentException
1238
-     * @throws InvalidDataTypeException
1239
-     * @throws InvalidInterfaceException
1240
-     */
1241
-    public function get_message_templates(
1242
-        $per_page = 10,
1243
-        $type = 'in_use',
1244
-        $count = false,
1245
-        $all = false,
1246
-        $global = true
1247
-    ) {
1248
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1249
-        $this->request->setRequestParam('orderby', $orderby);
1250
-
1251
-        $order        = $this->request->getRequestParam('order', 'ASC');
1252
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1253
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1254
-
1255
-        $offset = ($current_page - 1) * $per_page;
1256
-        $limit  = $all ? null : [$offset, $per_page];
1257
-
1258
-        // options will match what is in the _views array property
1259
-        return $type === 'in_use'
1260
-            ? $this->getMtgModel()->get_all_active_message_templates(
1261
-                $orderby,
1262
-                $order,
1263
-                $limit,
1264
-                $count,
1265
-                $global,
1266
-                true
1267
-            )
1268
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1269
-                $orderby,
1270
-                $order,
1271
-                $limit,
1272
-                $count,
1273
-                $global
1274
-            );
1275
-    }
1276
-
1277
-
1278
-    /**
1279
-     * filters etc might need a list of installed message_types
1280
-     *
1281
-     * @return array an array of message type objects
1282
-     */
1283
-    public function get_installed_message_types()
1284
-    {
1285
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1286
-        $installed               = [];
1287
-
1288
-        foreach ($installed_message_types as $message_type) {
1289
-            $installed[ $message_type->name ] = $message_type;
1290
-        }
1291
-
1292
-        return $installed;
1293
-    }
1294
-
1295
-
1296
-    /**
1297
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1298
-     *
1299
-     * @param string $message_type
1300
-     * @param string $messenger
1301
-     * @param string $GRP_ID
1302
-     *
1303
-     * @throws EE_error
1304
-     * @throws ReflectionException
1305
-     */
1306
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1307
-    {
1308
-        // set values override any request data
1309
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1310
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1311
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1312
-
1313
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1314
-        if (empty($message_type) || empty($messenger)) {
1315
-            throw new EE_Error(
1316
-                esc_html__(
1317
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1318
-                    'event_espresso'
1319
-                )
1320
-            );
1321
-        }
1322
-
1323
-        // we need the GRP_ID for the template being used as the base for the new template
1324
-        if (empty($GRP_ID)) {
1325
-            throw new EE_Error(
1326
-                esc_html__(
1327
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1328
-                    'event_espresso'
1329
-                )
1330
-            );
1331
-        }
1332
-
1333
-        // let's just make sure the template gets generated!
1334
-
1335
-        // we need to reassign some variables for what the insert is expecting
1336
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1337
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1338
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1339
-
1340
-        $this->_insert_or_update_message_template(true);
1341
-    }
1342
-
1343
-
1344
-    /**
1345
-     * @param string $message_type     message type slug
1346
-     * @param string $messenger        messenger slug
1347
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1348
-     *                                 off of.
1349
-     * @throws EE_error
1350
-     * @throws ReflectionException
1351
-     * @deprecated $VID:$
1352
-     */
1353
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1354
-    {
1355
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1356
-    }
1357
-
1358
-
1359
-    /**
1360
-     * _edit_message_template
1361
-     *
1362
-     * @access protected
1363
-     * @return void
1364
-     * @throws InvalidIdentifierException
1365
-     * @throws DomainException
1366
-     * @throws EE_Error
1367
-     * @throws InvalidArgumentException
1368
-     * @throws ReflectionException
1369
-     * @throws InvalidDataTypeException
1370
-     * @throws InvalidInterfaceException
1371
-     */
1372
-    protected function _edit_message_template()
1373
-    {
1374
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1375
-        $template_fields = '';
1376
-        $sidebar_fields  = '';
1377
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1378
-        // valid html in the templates.
1379
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1380
-
1381
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1382
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1383
-
1384
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1385
-        $message_template_group = $this->_message_template_group;
1386
-        $c_label                = $message_template_group->context_label();
1387
-        $c_config               = $message_template_group->contexts_config();
1388
-
1389
-        reset($c_config);
1390
-        $context = $this->request->getRequestParam('context', key($c_config));
1391
-        $context = strtolower($context);
1392
-
1393
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1394
-
1395
-        $edit_message_template_form_url = add_query_arg(
1396
-            ['action' => $action, 'noheader' => true],
1397
-            EE_MSG_ADMIN_URL
1398
-        );
1399
-
1400
-        // set active messenger for this view
1401
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1402
-            $message_template_group->messenger()
1403
-        );
1404
-        $this->_active_message_type_name = $message_template_group->message_type();
1405
-
1406
-
1407
-        // Do we have any validation errors?
1408
-        $validators = $this->_get_transient();
1409
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1410
-
1411
-
1412
-        // we need to assemble the title from Various details
1413
-        $context_label = sprintf(
1414
-            esc_html__('(%s %s)', 'event_espresso'),
1415
-            $c_config[ $context ]['label'],
1416
-            ucwords($c_label['label'])
1417
-        );
1418
-
1419
-        $title = sprintf(
1420
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1421
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1422
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1423
-            $context_label
1424
-        );
1425
-
1426
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1427
-        $this->_template_args['message_template'] = $message_template_group;
1428
-        $this->_template_args['is_extra_fields']  = false;
1429
-
1430
-
1431
-        // let's get EEH_MSG_Template so we can get template form fields
1432
-        $template_field_structure = EEH_MSG_Template::get_fields(
1433
-            $message_template_group->messenger(),
1434
-            $message_template_group->message_type()
1435
-        );
1436
-
1437
-        if (! $template_field_structure) {
1438
-            $template_field_structure = false;
1439
-            $template_fields          = esc_html__(
1440
-                'There was an error in assembling the fields for this display (you should see an error message)',
1441
-                'event_espresso'
1442
-            );
1443
-        }
1444
-
1445
-
1446
-        $message_templates = $message_template_group->context_templates();
1447
-
1448
-
1449
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1450
-        // will get handled in the "extra" array.
1451
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1452
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1453
-                unset($template_field_structure[ $context ][ $reference_field ]);
1454
-            }
1455
-        }
1456
-
1457
-        // let's loop through the template_field_structure and actually assemble the input fields!
1458
-        if (! empty($template_field_structure)) {
1459
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1460
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1461
-                // the extra array and reset them.
1462
-                if ($template_field === 'extra') {
1463
-                    $this->_template_args['is_extra_fields'] = true;
1464
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1465
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1466
-                        $content          = $message_template instanceof EE_Message_Template
1467
-                            ? $message_template->get('MTP_content')
1468
-                            : '';
1469
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1470
-                            // let's verify if we need this extra field via the shortcodes parameter.
1471
-                            $continue = false;
1472
-                            if (isset($extra_array['shortcodes_required'])) {
1473
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1474
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1475
-                                        $continue = true;
1476
-                                    }
1477
-                                }
1478
-                                if ($continue) {
1479
-                                    continue;
1480
-                                }
1481
-                            }
1482
-
1483
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1484
-
1485
-                            $template_form_fields[ $field_id ]         = $extra_array;
1486
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1487
-                                                                         . $reference_field
1488
-                                                                         . '][content]['
1489
-                                                                         . $extra_field . ']';
1490
-                            $css_class                                 = isset($extra_array['css_class'])
1491
-                                ? $extra_array['css_class']
1492
-                                : '';
1493
-
1494
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1495
-                                                                              && in_array($extra_field, $v_fields, true)
1496
-                                                                              && (
1497
-                                                                                  is_array($validators[ $extra_field ])
1498
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1499
-                                                                              )
1500
-                                ? 'validate-error ' . $css_class
1501
-                                : $css_class;
1502
-
1503
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1504
-                                                                          && isset($content[ $extra_field ])
1505
-                                ? $content[ $extra_field ]
1506
-                                : '';
1507
-
1508
-                            // do we have a validation error?  if we do then let's use that value instead
1509
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1510
-                                ? $validators[ $extra_field ]['value']
1511
-                                : $template_form_fields[ $field_id ]['value'];
1512
-
1513
-
1514
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1515
-
1516
-                            // shortcode selector
1517
-                            $field_name_to_use                                   = $extra_field === 'main'
1518
-                                ? 'content'
1519
-                                : $extra_field;
1520
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1521
-                                $field_name_to_use,
1522
-                                $field_id
1523
-                            );
1524
-                        }
1525
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1526
-                        $template_field_template_name_id = $reference_field . '-name';
1527
-
1528
-                        $template_form_fields[ $template_field_MTP_id ] = [
1529
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1530
-                            'label'      => null,
1531
-                            'input'      => 'hidden',
1532
-                            'type'       => 'int',
1533
-                            'required'   => false,
1534
-                            'validation' => false,
1535
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1536
-                            'css_class'  => '',
1537
-                            'format'     => '%d',
1538
-                            'db-col'     => 'MTP_ID',
1539
-                        ];
1540
-
1541
-                        $template_form_fields[ $template_field_template_name_id ] = [
1542
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1543
-                            'label'      => null,
1544
-                            'input'      => 'hidden',
1545
-                            'type'       => 'string',
1546
-                            'required'   => false,
1547
-                            'validation' => true,
1548
-                            'value'      => $reference_field,
1549
-                            'css_class'  => '',
1550
-                            'format'     => '%s',
1551
-                            'db-col'     => 'MTP_template_field',
1552
-                        ];
1553
-                    }
1554
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1555
-                } else {
1556
-                    $field_id                                   = $template_field . '-content';
1557
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1558
-                    $template_form_fields[ $field_id ]['name']  =
1559
-                        'MTP_template_fields[' . $template_field . '][content]';
1560
-                    $message_template                           =
1561
-                        isset($message_templates[ $context ][ $template_field ])
1562
-                            ? $message_templates[ $context ][ $template_field ]
1563
-                            : null;
1564
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1565
-                                                                  && is_array($message_templates[ $context ])
1566
-                                                                  && $message_template instanceof EE_Message_Template
1567
-                        ? $message_template->get('MTP_content')
1568
-                        : '';
1569
-
1570
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1571
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1572
-                        ? $validators[ $template_field ]['value']
1573
-                        : $template_form_fields[ $field_id ]['value'];
1574
-
1575
-
1576
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1577
-                    $css_class                                      = isset($field_setup_array['css_class'])
1578
-                        ? $field_setup_array['css_class']
1579
-                        : '';
1580
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1581
-                                                                      && in_array($template_field, $v_fields, true)
1582
-                                                                      && isset($validators[ $template_field ]['msg'])
1583
-                        ? 'validate-error ' . $css_class
1584
-                        : $css_class;
1585
-
1586
-                    // shortcode selector
1587
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1588
-                        $template_field,
1589
-                        $field_id
1590
-                    );
1591
-                }
1592
-
1593
-                // k took care of content field(s) now let's take care of others.
1594
-
1595
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1596
-                $template_field_field_template_name_id = $template_field . '-name';
1597
-
1598
-                // foreach template field there are actually two form fields created
1599
-                $template_form_fields[ $template_field_MTP_id ] = [
1600
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1601
-                    'label'      => null,
1602
-                    'input'      => 'hidden',
1603
-                    'type'       => 'int',
1604
-                    'required'   => false,
1605
-                    'validation' => true,
1606
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1607
-                    'css_class'  => '',
1608
-                    'format'     => '%d',
1609
-                    'db-col'     => 'MTP_ID',
1610
-                ];
1611
-
1612
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1613
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1614
-                    'label'      => null,
1615
-                    'input'      => 'hidden',
1616
-                    'type'       => 'string',
1617
-                    'required'   => false,
1618
-                    'validation' => true,
1619
-                    'value'      => $template_field,
1620
-                    'css_class'  => '',
1621
-                    'format'     => '%s',
1622
-                    'db-col'     => 'MTP_template_field',
1623
-                ];
1624
-            }
1625
-
1626
-            // add other fields
1627
-            $template_form_fields['ee-msg-current-context'] = [
1628
-                'name'       => 'MTP_context',
1629
-                'label'      => null,
1630
-                'input'      => 'hidden',
1631
-                'type'       => 'string',
1632
-                'required'   => false,
1633
-                'validation' => true,
1634
-                'value'      => $context,
1635
-                'css_class'  => '',
1636
-                'format'     => '%s',
1637
-                'db-col'     => 'MTP_context',
1638
-            ];
1639
-
1640
-            $template_form_fields['ee-msg-grp-id'] = [
1641
-                'name'       => 'GRP_ID',
1642
-                'label'      => null,
1643
-                'input'      => 'hidden',
1644
-                'type'       => 'int',
1645
-                'required'   => false,
1646
-                'validation' => true,
1647
-                'value'      => $GRP_ID,
1648
-                'css_class'  => '',
1649
-                'format'     => '%d',
1650
-                'db-col'     => 'GRP_ID',
1651
-            ];
1652
-
1653
-            $template_form_fields['ee-msg-messenger'] = [
1654
-                'name'       => 'MTP_messenger',
1655
-                'label'      => null,
1656
-                'input'      => 'hidden',
1657
-                'type'       => 'string',
1658
-                'required'   => false,
1659
-                'validation' => true,
1660
-                'value'      => $message_template_group->messenger(),
1661
-                'css_class'  => '',
1662
-                'format'     => '%s',
1663
-                'db-col'     => 'MTP_messenger',
1664
-            ];
1665
-
1666
-            $template_form_fields['ee-msg-message-type'] = [
1667
-                'name'       => 'MTP_message_type',
1668
-                'label'      => null,
1669
-                'input'      => 'hidden',
1670
-                'type'       => 'string',
1671
-                'required'   => false,
1672
-                'validation' => true,
1673
-                'value'      => $message_template_group->message_type(),
1674
-                'css_class'  => '',
1675
-                'format'     => '%s',
1676
-                'db-col'     => 'MTP_message_type',
1677
-            ];
1678
-
1679
-            $sidebar_form_fields['ee-msg-is-global'] = [
1680
-                'name'       => 'MTP_is_global',
1681
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1682
-                'input'      => 'hidden',
1683
-                'type'       => 'int',
1684
-                'required'   => false,
1685
-                'validation' => true,
1686
-                'value'      => $message_template_group->get('MTP_is_global'),
1687
-                'css_class'  => '',
1688
-                'format'     => '%d',
1689
-                'db-col'     => 'MTP_is_global',
1690
-            ];
1691
-
1692
-            $sidebar_form_fields['ee-msg-is-override'] = [
1693
-                'name'       => 'MTP_is_override',
1694
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1695
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1696
-                'type'       => 'int',
1697
-                'required'   => false,
1698
-                'validation' => true,
1699
-                'value'      => $message_template_group->get('MTP_is_override'),
1700
-                'css_class'  => '',
1701
-                'format'     => '%d',
1702
-                'db-col'     => 'MTP_is_override',
1703
-            ];
1704
-
1705
-            $sidebar_form_fields['ee-msg-is-active'] = [
1706
-                'name'       => 'MTP_is_active',
1707
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1708
-                'input'      => 'hidden',
1709
-                'type'       => 'int',
1710
-                'required'   => false,
1711
-                'validation' => true,
1712
-                'value'      => $message_template_group->is_active(),
1713
-                'css_class'  => '',
1714
-                'format'     => '%d',
1715
-                'db-col'     => 'MTP_is_active',
1716
-            ];
1717
-
1718
-            $sidebar_form_fields['ee-msg-deleted'] = [
1719
-                'name'       => 'MTP_deleted',
1720
-                'label'      => null,
1721
-                'input'      => 'hidden',
1722
-                'type'       => 'int',
1723
-                'required'   => false,
1724
-                'validation' => true,
1725
-                'value'      => $message_template_group->get('MTP_deleted'),
1726
-                'css_class'  => '',
1727
-                'format'     => '%d',
1728
-                'db-col'     => 'MTP_deleted',
1729
-            ];
1730
-            $sidebar_form_fields['ee-msg-author']  = [
1731
-                'name'       => 'MTP_user_id',
1732
-                'label'      => esc_html__('Author', 'event_espresso'),
1733
-                'input'      => 'hidden',
1734
-                'type'       => 'int',
1735
-                'required'   => false,
1736
-                'validation' => false,
1737
-                'value'      => $message_template_group->user(),
1738
-                'format'     => '%d',
1739
-                'db-col'     => 'MTP_user_id',
1740
-            ];
1741
-
1742
-            $sidebar_form_fields['ee-msg-route'] = [
1743
-                'name'  => 'action',
1744
-                'input' => 'hidden',
1745
-                'type'  => 'string',
1746
-                'value' => $action,
1747
-            ];
1748
-
1749
-            $sidebar_form_fields['ee-msg-id']        = [
1750
-                'name'  => 'id',
1751
-                'input' => 'hidden',
1752
-                'type'  => 'int',
1753
-                'value' => $GRP_ID,
1754
-            ];
1755
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1756
-                'name'  => $action . '_nonce',
1757
-                'input' => 'hidden',
1758
-                'type'  => 'string',
1759
-                'value' => wp_create_nonce($action . '_nonce'),
1760
-            ];
1761
-
1762
-            $template_switch = $this->request->getRequestParam('template_switch');
1763
-            if ($template_switch) {
1764
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1765
-                    'name'  => 'template_switch',
1766
-                    'input' => 'hidden',
1767
-                    'type'  => 'int',
1768
-                    'value' => 1,
1769
-                ];
1770
-            }
1771
-
1772
-
1773
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1774
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1775
-        } //end if ( !empty($template_field_structure) )
1776
-
1777
-        // set extra content for publish box
1778
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1779
-        $this->_set_publish_post_box_vars(
1780
-            'id',
1781
-            $GRP_ID,
1782
-            false,
1783
-            add_query_arg(
1784
-                ['action' => 'global_mtps'],
1785
-                $this->_admin_base_url
1786
-            )
1787
-        );
1788
-
1789
-        // add preview button
1790
-        $preview_url    = parent::add_query_args_and_nonce(
1791
-            [
1792
-                'message_type' => $message_template_group->message_type(),
1793
-                'messenger'    => $message_template_group->messenger(),
1794
-                'context'      => $context,
1795
-                'GRP_ID'       => $GRP_ID,
1796
-                'evt_id'       => $EVT_ID ?: false,
1797
-                'action'       => 'preview_message',
1798
-            ],
1799
-            $this->_admin_base_url
1800
-        );
1801
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1802
-                          . esc_html__('Preview', 'event_espresso')
1803
-                          . '</a>';
1804
-
1805
-
1806
-        // setup context switcher
1807
-        $this->_set_context_switcher(
1808
-            $message_template_group,
1809
-            [
1810
-                'page'    => 'espresso_messages',
1811
-                'action'  => 'edit_message_template',
1812
-                'id'      => $GRP_ID,
1813
-                'evt_id'  => $EVT_ID,
1814
-                'context' => $context,
1815
-                'extra'   => $preview_button,
1816
-            ]
1817
-        );
1818
-
1819
-
1820
-        // main box
1821
-        $this->_template_args['template_fields']                         = $template_fields;
1822
-        $this->_template_args['sidebar_box_id']                          = 'details';
1823
-        $this->_template_args['action']                                  = $action;
1824
-        $this->_template_args['context']                                 = $context;
1825
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1826
-        $this->_template_args['learn_more_about_message_templates_link'] =
1827
-            $this->_learn_more_about_message_templates_link();
1828
-
1829
-
1830
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1831
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1832
-            $message_template_group,
1833
-            $context,
1834
-            $context_label
1835
-        );
1836
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1837
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1838
-
1839
-        $this->_template_path = $this->_template_args['GRP_ID']
1840
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1841
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1842
-
1843
-        // send along EE_Message_Template_Group object for further template use.
1844
-        $this->_template_args['MTP'] = $message_template_group;
1845
-
1846
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1847
-            $this->_template_path,
1848
-            $this->_template_args,
1849
-            true
1850
-        );
1851
-
1852
-
1853
-        // finally, let's set the admin_page title
1854
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1855
-
1856
-
1857
-        // we need to take care of setting the shortcodes property for use elsewhere.
1858
-        $this->_set_shortcodes();
1859
-
1860
-
1861
-        // final template wrapper
1862
-        $this->display_admin_page_with_sidebar();
1863
-    }
1864
-
1865
-
1866
-    public function filter_tinymce_init($mceInit, $editor_id)
1867
-    {
1868
-        return $mceInit;
1869
-    }
1870
-
1871
-
1872
-    public function add_context_switcher()
1873
-    {
1874
-        return $this->_context_switcher;
1875
-    }
1876
-
1877
-
1878
-    /**
1879
-     * Adds the activation/deactivation toggle for the message template context.
1880
-     *
1881
-     * @param EE_Message_Template_Group $message_template_group
1882
-     * @param string                    $context
1883
-     * @param string                    $context_label
1884
-     * @return string
1885
-     * @throws DomainException
1886
-     * @throws EE_Error
1887
-     * @throws InvalidIdentifierException
1888
-     * @throws ReflectionException
1889
-     */
1890
-    protected function add_active_context_element(
1891
-        EE_Message_Template_Group $message_template_group,
1892
-        $context,
1893
-        $context_label
1894
-    ) {
1895
-        $template_args = [
1896
-            'context'                   => $context,
1897
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1898
-            'is_active'                 => $message_template_group->is_context_active($context),
1899
-            'on_off_action'             => $message_template_group->is_context_active($context)
1900
-                ? 'context-off'
1901
-                : 'context-on',
1902
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1903
-            'message_template_group_id' => $message_template_group->ID(),
1904
-        ];
1905
-        return EEH_Template::display_template(
1906
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1907
-            $template_args,
1908
-            true
1909
-        );
1910
-    }
1911
-
1912
-
1913
-    /**
1914
-     * Ajax callback for `toggle_context_template` ajax action.
1915
-     * Handles toggling the message context on or off.
1916
-     *
1917
-     * @throws EE_Error
1918
-     * @throws InvalidArgumentException
1919
-     * @throws InvalidDataTypeException
1920
-     * @throws InvalidIdentifierException
1921
-     * @throws InvalidInterfaceException
1922
-     */
1923
-    public function toggle_context_template()
1924
-    {
1925
-        $success = true;
1926
-        // check for required data
1927
-        if (
1928
-            ! (
1929
-                $this->request->requestParamIsSet('message_template_group_id')
1930
-                && $this->request->requestParamIsSet('context')
1931
-                && $this->request->requestParamIsSet('status')
1932
-            )
1933
-        ) {
1934
-            EE_Error::add_error(
1935
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1936
-                __FILE__,
1937
-                __FUNCTION__,
1938
-                __LINE__
1939
-            );
1940
-            $success = false;
1941
-        }
1942
-
1943
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1944
-        $context = $this->request->getRequestParam('context', '');
1945
-        $status  = $this->request->getRequestParam('status', '');
1946
-
1947
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1948
-
1949
-        if ($status !== 'off' && $status !== 'on') {
1950
-            EE_Error::add_error(
1951
-                sprintf(
1952
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1953
-                    $status
1954
-                ),
1955
-                __FILE__,
1956
-                __FUNCTION__,
1957
-                __LINE__
1958
-            );
1959
-            $success = false;
1960
-        }
1961
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1962
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1963
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1964
-            EE_Error::add_error(
1965
-                sprintf(
1966
-                    esc_html__(
1967
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1968
-                        'event_espresso'
1969
-                    ),
1970
-                    $message_template_group_id,
1971
-                    'EE_Message_Template_Group'
1972
-                ),
1973
-                __FILE__,
1974
-                __FUNCTION__,
1975
-                __LINE__
1976
-            );
1977
-            $success = false;
1978
-        }
1979
-        if ($success) {
1980
-            $success = $status === 'off'
1981
-                ? $message_template_group->deactivate_context($context)
1982
-                : $message_template_group->activate_context($context);
1983
-        }
1984
-        $this->_template_args['success'] = $success;
1985
-        $this->_return_json();
1986
-    }
1987
-
1988
-
1989
-    public function _add_form_element_before()
1990
-    {
1991
-        return '<form method="post" action="'
1992
-               . $this->_template_args['edit_message_template_form_url']
1993
-               . '" id="ee-msg-edit-frm">';
1994
-    }
1995
-
1996
-
1997
-    public function _add_form_element_after()
1998
-    {
1999
-        return '</form>';
2000
-    }
2001
-
2002
-
2003
-    /**
2004
-     * This executes switching the template pack for a message template.
2005
-     *
2006
-     * @throws EE_Error
2007
-     * @throws InvalidDataTypeException
2008
-     * @throws InvalidInterfaceException
2009
-     * @throws InvalidArgumentException
2010
-     * @throws ReflectionException
2011
-     * @since 4.5.0
2012
-     */
2013
-    public function switch_template_pack()
2014
-    {
2015
-
2016
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2017
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2018
-
2019
-        // verify we have needed values.
2020
-        if (empty($GRP_ID) || empty($template_pack)) {
2021
-            $this->_template_args['error'] = true;
2022
-            EE_Error::add_error(
2023
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2024
-                __FILE__,
2025
-                __FUNCTION__,
2026
-                __LINE__
2027
-            );
2028
-        } else {
2029
-            // get template, set the new template_pack and then reset to default
2030
-            /** @var EE_Message_Template_Group $message_template_group */
2031
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2032
-
2033
-            $message_template_group->set_template_pack_name($template_pack);
2034
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2035
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2036
-
2037
-            $query_args = $this->_reset_to_default_template();
2038
-
2039
-            if (empty($query_args['id'])) {
2040
-                EE_Error::add_error(
2041
-                    esc_html__(
2042
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2043
-                        'event_espresso'
2044
-                    ),
2045
-                    __FILE__,
2046
-                    __FUNCTION__,
2047
-                    __LINE__
2048
-                );
2049
-                $this->_template_args['error'] = true;
2050
-            } else {
2051
-                $template_label       = $message_template_group->get_template_pack()->label;
2052
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2053
-                EE_Error::add_success(
2054
-                    sprintf(
2055
-                        esc_html__(
2056
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2057
-                            'event_espresso'
2058
-                        ),
2059
-                        $template_label,
2060
-                        $template_pack_labels->template_pack
2061
-                    )
2062
-                );
2063
-                // generate the redirect url for js.
2064
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2065
-
2066
-                $this->_template_args['data']['redirect_url'] = $url;
2067
-                $this->_template_args['success']              = true;
2068
-            }
2069
-
2070
-            $this->_return_json();
2071
-        }
2072
-    }
2073
-
2074
-
2075
-    /**
2076
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2077
-     * they want.
2078
-     *
2079
-     * @access protected
2080
-     * @return array|void
2081
-     * @throws EE_Error
2082
-     * @throws InvalidArgumentException
2083
-     * @throws InvalidDataTypeException
2084
-     * @throws InvalidInterfaceException
2085
-     * @throws ReflectionException
2086
-     */
2087
-    protected function _reset_to_default_template()
2088
-    {
2089
-        $templates    = [];
2090
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2091
-        $messenger    = $this->request->getRequestParam('msgr');
2092
-        $message_type = $this->request->getRequestParam('mt');
2093
-        // we need to make sure we've got the info we need.
2094
-        if (! ($GRP_ID && $messenger && $message_type)) {
2095
-            EE_Error::add_error(
2096
-                esc_html__(
2097
-                    '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.',
2098
-                    'event_espresso'
2099
-                ),
2100
-                __FILE__,
2101
-                __FUNCTION__,
2102
-                __LINE__
2103
-            );
2104
-        }
2105
-
2106
-        // all templates will be reset to whatever the defaults are
2107
-        // for the global template matching the messenger and message type.
2108
-        $success = ! empty($GRP_ID);
2109
-
2110
-        if ($success) {
2111
-            // let's first determine if the incoming template is a global template,
2112
-            // if it isn't then we need to get the global template matching messenger and message type.
2113
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2114
-
2115
-
2116
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2117
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2118
-
2119
-            if ($success) {
2120
-                // if successfully deleted, lets generate the new ones.
2121
-                // Note. We set GLOBAL to true, because resets on ANY template
2122
-                // will use the related global template defaults for regeneration.
2123
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2124
-                // HOWEVER, we DO keep the template pack and template variation set
2125
-                // for the current custom template when resetting.
2126
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2127
-            }
2128
-        }
2129
-
2130
-        // any error messages?
2131
-        if (! $success) {
2132
-            EE_Error::add_error(
2133
-                esc_html__(
2134
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2135
-                    'event_espresso'
2136
-                ),
2137
-                __FILE__,
2138
-                __FUNCTION__,
2139
-                __LINE__
2140
-            );
2141
-        }
2142
-
2143
-        // all good, let's add a success message!
2144
-        if ($success && ! empty($templates)) {
2145
-            // the info for the template we generated is the first element in the returned array
2146
-            EE_Error::overwrite_success();
2147
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2148
-        }
2149
-
2150
-
2151
-        $query_args = [
2152
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2153
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2154
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2155
-        ];
2156
-
2157
-        // if called via ajax then we return query args otherwise redirect
2158
-        if ($this->request->isAjax()) {
2159
-            return $query_args;
2160
-        }
2161
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2162
-    }
2163
-
2164
-
2165
-    /**
2166
-     * Retrieve and set the message preview for display.
2167
-     *
2168
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2169
-     * @return string
2170
-     * @throws ReflectionException
2171
-     * @throws EE_Error
2172
-     * @throws InvalidArgumentException
2173
-     * @throws InvalidDataTypeException
2174
-     * @throws InvalidInterfaceException
2175
-     */
2176
-    public function _preview_message($send = false)
2177
-    {
2178
-        // first make sure we've got the necessary parameters
2179
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2180
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2181
-            EE_Error::add_error(
2182
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2183
-                __FILE__,
2184
-                __FUNCTION__,
2185
-                __LINE__
2186
-            );
2187
-        }
2188
-
2189
-        $context = $this->request->getRequestParam('context');
2190
-        // get the preview!
2191
-        $preview = EED_Messages::preview_message(
2192
-            $this->_active_message_type_name,
2193
-            $context,
2194
-            $this->_active_messenger_name,
2195
-            $send
2196
-        );
2197
-
2198
-        if ($send) {
2199
-            return $preview;
2200
-        }
2201
-
2202
-        // if we have an evt_id set on the request, use it.
2203
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2204
-
2205
-        // let's add a button to go back to the edit view
2206
-        $query_args             = [
2207
-            'id'      => $GRP_ID,
2208
-            'evt_id'  => $EVT_ID,
2209
-            'context' => $context,
2210
-            'action'  => 'edit_message_template',
2211
-        ];
2212
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2213
-        $preview_button         = '<a href="'
2214
-                                  . $go_back_url
2215
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2216
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2217
-                                  . '</a>';
2218
-        $message_types          = $this->get_installed_message_types();
2219
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2220
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2221
-            ? ucwords($active_messenger->label['singular'])
2222
-            : esc_html__('Unknown Messenger', 'event_espresso');
2223
-        // let's provide a helpful title for context
2224
-        $preview_title = sprintf(
2225
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2226
-            $active_messenger_label,
2227
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2228
-        );
2229
-        if (empty($preview)) {
2230
-            $this->noEventsErrorMessage();
2231
-        }
2232
-        // setup display of preview.
2233
-        $this->_admin_page_title                    = $preview_title;
2234
-        $this->_template_args['admin_page_title']   = $preview_title;
2235
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2236
-        $this->_template_args['data']['force_json'] = true;
2237
-
2238
-        return '';
2239
-    }
2240
-
2241
-
2242
-    /**
2243
-     * Used to set an error if there are no events available for generating a preview/test send.
2244
-     *
2245
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2246
-     */
2247
-    protected function noEventsErrorMessage($test_send = false)
2248
-    {
2249
-        $events_url = parent::add_query_args_and_nonce(
2250
-            [
2251
-                'action' => 'default',
2252
-                'page'   => 'espresso_events',
2253
-            ],
2254
-            admin_url('admin.php')
2255
-        );
2256
-        $message    = $test_send
2257
-            ? esc_html__(
2258
-                '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!',
2259
-                'event_espresso'
2260
-            )
2261
-            : esc_html__(
2262
-                '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!',
2263
-                'event_espresso'
2264
-            );
2265
-
2266
-        EE_Error::add_attention(
2267
-            sprintf(
2268
-                $message,
2269
-                "<a href='{$events_url}'>",
2270
-                '</a>'
2271
-            )
2272
-        );
2273
-    }
2274
-
2275
-
2276
-    /**
2277
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2278
-     * gets called automatically.
2279
-     *
2280
-     * @return void
2281
-     * @throws EE_Error
2282
-     * @since 4.5.0
2283
-     *
2284
-     */
2285
-    protected function _display_preview_message()
2286
-    {
2287
-        $this->display_admin_page_with_no_sidebar();
2288
-    }
2289
-
2290
-
2291
-    /**
2292
-     * registers metaboxes that should show up on the "edit_message_template" page
2293
-     *
2294
-     * @access protected
2295
-     * @return void
2296
-     */
2297
-    protected function _register_edit_meta_boxes()
2298
-    {
2299
-        add_meta_box(
2300
-            'mtp_valid_shortcodes',
2301
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2302
-            [$this, 'shortcode_meta_box'],
2303
-            $this->_current_screen->id,
2304
-            'side'
2305
-        );
2306
-        add_meta_box(
2307
-            'mtp_extra_actions',
2308
-            esc_html__('Extra Actions', 'event_espresso'),
2309
-            [$this, 'extra_actions_meta_box'],
2310
-            $this->_current_screen->id,
2311
-            'side',
2312
-            'high'
2313
-        );
2314
-        add_meta_box(
2315
-            'mtp_templates',
2316
-            esc_html__('Template Styles', 'event_espresso'),
2317
-            [$this, 'template_pack_meta_box'],
2318
-            $this->_current_screen->id,
2319
-            'side',
2320
-            'high'
2321
-        );
2322
-    }
2323
-
2324
-
2325
-    /**
2326
-     * metabox content for all template pack and variation selection.
2327
-     *
2328
-     * @return void
2329
-     * @throws DomainException
2330
-     * @throws EE_Error
2331
-     * @throws InvalidArgumentException
2332
-     * @throws ReflectionException
2333
-     * @throws InvalidDataTypeException
2334
-     * @throws InvalidInterfaceException
2335
-     * @since 4.5.0
2336
-     */
2337
-    public function template_pack_meta_box()
2338
-    {
2339
-        $this->_set_message_template_group();
2340
-
2341
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2342
-
2343
-        $tp_select_values = [];
2344
-
2345
-        foreach ($tp_collection as $tp) {
2346
-            // only include template packs that support this messenger and message type!
2347
-            $supports = $tp->get_supports();
2348
-            if (
2349
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2350
-                || ! in_array(
2351
-                    $this->_message_template_group->message_type(),
2352
-                    $supports[ $this->_message_template_group->messenger() ],
2353
-                    true
2354
-                )
2355
-            ) {
2356
-                // not supported
2357
-                continue;
2358
-            }
2359
-
2360
-            $tp_select_values[] = [
2361
-                'text' => $tp->label,
2362
-                'id'   => $tp->dbref,
2363
-            ];
2364
-        }
2365
-
2366
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2367
-        // the default template pack.  This still allows for the odd template pack to override.
2368
-        if (empty($tp_select_values)) {
2369
-            $tp_select_values[] = [
2370
-                'text' => esc_html__('Default', 'event_espresso'),
2371
-                'id'   => 'default',
2372
-            ];
2373
-        }
2374
-
2375
-        // setup variation select values for the currently selected template.
2376
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2377
-            $this->_message_template_group->messenger(),
2378
-            $this->_message_template_group->message_type()
2379
-        );
2380
-        $variations_select_values = [];
2381
-        foreach ($variations as $variation => $label) {
2382
-            $variations_select_values[] = [
2383
-                'text' => $label,
2384
-                'id'   => $variation,
2385
-            ];
2386
-        }
2387
-
2388
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2389
-
2390
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2391
-            'MTP_template_pack',
2392
-            $tp_select_values,
2393
-            $this->_message_template_group->get_template_pack_name()
2394
-        );
2395
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2396
-            'MTP_template_variation',
2397
-            $variations_select_values,
2398
-            $this->_message_template_group->get_template_pack_variation()
2399
-        );
2400
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2401
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2402
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2403
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2404
-
2405
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2406
-
2407
-        EEH_Template::display_template($template, $template_args);
2408
-    }
2409
-
2410
-
2411
-    /**
2412
-     * This meta box holds any extra actions related to Message Templates
2413
-     * For now, this includes Resetting templates to defaults and sending a test email.
2414
-     *
2415
-     * @access  public
2416
-     * @return void
2417
-     * @throws EE_Error
2418
-     */
2419
-    public function extra_actions_meta_box()
2420
-    {
2421
-        $template_form_fields = [];
2422
-
2423
-        $extra_args = [
2424
-            'msgr'   => $this->_message_template_group->messenger(),
2425
-            'mt'     => $this->_message_template_group->message_type(),
2426
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2427
-        ];
2428
-        // first we need to see if there are any fields
2429
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2430
-
2431
-        if (! empty($fields)) {
2432
-            // yup there be fields
2433
-            foreach ($fields as $field => $config) {
2434
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2435
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2436
-                $default  = isset($config['default']) ? $config['default'] : '';
2437
-                $default  = isset($config['value']) ? $config['value'] : $default;
2438
-
2439
-                // if type is hidden and the value is empty
2440
-                // something may have gone wrong so let's correct with the defaults
2441
-                $fix                = $config['input'] === 'hidden'
2442
-                                      && isset($existing[ $field ])
2443
-                                      && empty($existing[ $field ])
2444
-                    ? $default
2445
-                    : '';
2446
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2447
-                    ? $existing[ $field ]
2448
-                    : $fix;
2449
-
2450
-                $template_form_fields[ $field_id ] = [
2451
-                    'name'       => 'test_settings_fld[' . $field . ']',
2452
-                    'label'      => $config['label'],
2453
-                    'input'      => $config['input'],
2454
-                    'type'       => $config['type'],
2455
-                    'required'   => $config['required'],
2456
-                    'validation' => $config['validation'],
2457
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2458
-                    'css_class'  => $config['css_class'],
2459
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2460
-                    'default'    => $default,
2461
-                    'format'     => $config['format'],
2462
-                ];
2463
-            }
2464
-        }
2465
-
2466
-        $test_settings_html = ! empty($template_form_fields)
2467
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2468
-            : '';
2469
-
2470
-        // print out $test_settings_fields
2471
-        if (! empty($test_settings_html)) {
2472
-            $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2473
-            $test_settings_html .= 'name="test_button" value="';
2474
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2475
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2476
-        }
2477
-
2478
-        // and button
2479
-        $test_settings_html .= '<p>';
2480
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2481
-        $test_settings_html .= '</p>';
2482
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2483
-        $test_settings_html .= $this->get_action_link_or_button(
2484
-            'reset_to_default',
2485
-            'reset',
2486
-            $extra_args,
2487
-            'button-primary reset-default-button'
2488
-        );
2489
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2490
-        echo $test_settings_html; // already escaped
2491
-    }
2492
-
2493
-
2494
-    /**
2495
-     * This returns the shortcode selector skeleton for a given context and field.
2496
-     *
2497
-     * @param string $field           The name of the field retrieving shortcodes for.
2498
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2499
-     * @return string
2500
-     * @throws DomainException
2501
-     * @throws EE_Error
2502
-     * @throws InvalidArgumentException
2503
-     * @throws ReflectionException
2504
-     * @throws InvalidDataTypeException
2505
-     * @throws InvalidInterfaceException
2506
-     * @since 4.9.rc.000
2507
-     */
2508
-    protected function _get_shortcode_selector($field, $linked_input_id)
2509
-    {
2510
-        $template_args = [
2511
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2512
-            'fieldname'       => $field,
2513
-            'linked_input_id' => $linked_input_id,
2514
-        ];
2515
-
2516
-        return EEH_Template::display_template(
2517
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2518
-            $template_args,
2519
-            true
2520
-        );
2521
-    }
2522
-
2523
-
2524
-    /**
2525
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2526
-     * page)
2527
-     *
2528
-     * @access public
2529
-     * @return void
2530
-     * @throws EE_Error
2531
-     * @throws InvalidArgumentException
2532
-     * @throws ReflectionException
2533
-     * @throws InvalidDataTypeException
2534
-     * @throws InvalidInterfaceException
2535
-     */
2536
-    public function shortcode_meta_box()
2537
-    {
2538
-        $shortcodes = $this->_get_shortcodes([], false);
2539
-        // just make sure the shortcodes property is set
2540
-        // $messenger = $this->_message_template_group->messenger_obj();
2541
-        // now let's set the content depending on the status of the shortcodes array
2542
-        if (empty($shortcodes)) {
2543
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2544
-            return;
2545
-        }
2546
-        ?>
19
+	/**
20
+	 * @var EEM_Message
21
+	 */
22
+	private $MSG_MODEL;
23
+
24
+	/**
25
+	 * @var EEM_Message_Template
26
+	 */
27
+	private $MTP_MODEL;
28
+
29
+	/**
30
+	 * @var EEM_Message_Template_Group
31
+	 */
32
+	private $MTG_MODEL;
33
+
34
+	/**
35
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
36
+	 */
37
+	protected $_message_resource_manager;
38
+
39
+	/**
40
+	 * @var string
41
+	 */
42
+	protected $_active_message_type_name = '';
43
+
44
+	/**
45
+	 * @var string
46
+	 */
47
+	protected $_active_messenger_name = '';
48
+
49
+	/**
50
+	 * @var EE_messenger $_active_messenger
51
+	 */
52
+	protected $_active_messenger;
53
+
54
+	protected $_activate_meta_box_type;
55
+
56
+	protected $_current_message_meta_box;
57
+
58
+	protected $_current_message_meta_box_object;
59
+
60
+	protected $_context_switcher;
61
+
62
+	protected $_shortcodes           = [];
63
+
64
+	protected $_active_messengers    = [];
65
+
66
+	protected $_active_message_types = [];
67
+
68
+	/**
69
+	 * @var EE_Message_Template_Group $_message_template_group
70
+	 */
71
+	protected $_message_template_group;
72
+
73
+	protected $_m_mt_settings = [];
74
+
75
+
76
+	/**
77
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
78
+	 * IF there is no group then it gets automatically set to the Default template pack.
79
+	 *
80
+	 * @since 4.5.0
81
+	 *
82
+	 * @var EE_Messages_Template_Pack
83
+	 */
84
+	protected $_template_pack;
85
+
86
+
87
+	/**
88
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
89
+	 * group is.  If there is no group then it automatically gets set to default.
90
+	 *
91
+	 * @since 4.5.0
92
+	 *
93
+	 * @var string
94
+	 */
95
+	protected $_variation;
96
+
97
+
98
+	/**
99
+	 * @param bool $routing
100
+	 * @throws EE_Error
101
+	 * @throws ReflectionException
102
+	 */
103
+	public function __construct($routing = true)
104
+	{
105
+		// make sure messages autoloader is running
106
+		EED_Messages::set_autoloaders();
107
+		parent::__construct($routing);
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return EEM_Message
113
+	 * @throws EE_Error
114
+	 */
115
+	public function getMsgModel()
116
+	{
117
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
118
+			$this->MSG_MODEL = EEM_Message::instance();
119
+		}
120
+		return $this->MSG_MODEL;
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return EEM_Message_Template
126
+	 * @throws EE_Error
127
+	 */
128
+	public function getMtpModel()
129
+	{
130
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
+			$this->MTP_MODEL = EEM_Message_Template::instance();
132
+		}
133
+		return $this->MTP_MODEL;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @return EEM_Message_Template_Group
139
+	 * @throws EE_Error
140
+	 */
141
+	public function getMtgModel()
142
+	{
143
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
145
+		}
146
+		return $this->MTG_MODEL;
147
+	}
148
+
149
+
150
+	/**
151
+	 * @throws EE_Error
152
+	 * @throws ReflectionException
153
+	 */
154
+	protected function _init_page_props()
155
+	{
156
+		$this->page_slug        = EE_MSG_PG_SLUG;
157
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
158
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
159
+		$this->_admin_base_path = EE_MSG_ADMIN;
160
+
161
+		$messenger    = $this->request->getRequestParam('messenger', '');
162
+		$message_type = $this->request->getRequestParam('message_type', '');
163
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
164
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
165
+
166
+		$this->_load_message_resource_manager();
167
+	}
168
+
169
+
170
+	/**
171
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
172
+	 *
173
+	 * @throws EE_Error
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 * @throws InvalidArgumentException
177
+	 * @throws ReflectionException
178
+	 */
179
+	protected function _load_message_resource_manager()
180
+	{
181
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
182
+	}
183
+
184
+
185
+	/**
186
+	 * @return array
187
+	 * @throws EE_Error
188
+	 * @throws InvalidArgumentException
189
+	 * @throws InvalidDataTypeException
190
+	 * @throws InvalidInterfaceException
191
+	 * @deprecated 4.9.9.rc.014
192
+	 */
193
+	public function get_messengers_for_list_table()
194
+	{
195
+		EE_Error::doing_it_wrong(
196
+			__METHOD__,
197
+			sprintf(
198
+				esc_html__(
199
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
200
+					'event_espresso'
201
+				),
202
+				'Messages_Admin_Page::get_messengers_select_input()'
203
+			),
204
+			'4.9.9.rc.014'
205
+		);
206
+
207
+		$m_values          = [];
208
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
209
+		// setup messengers for selects
210
+		$i = 1;
211
+		foreach ($active_messengers as $active_messenger) {
212
+			if ($active_messenger instanceof EE_Message) {
213
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
214
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
215
+				$i++;
216
+			}
217
+		}
218
+
219
+		return $m_values;
220
+	}
221
+
222
+
223
+	/**
224
+	 * @return array
225
+	 * @throws EE_Error
226
+	 * @throws InvalidArgumentException
227
+	 * @throws InvalidDataTypeException
228
+	 * @throws InvalidInterfaceException
229
+	 * @deprecated 4.9.9.rc.014
230
+	 */
231
+	public function get_message_types_for_list_table()
232
+	{
233
+		EE_Error::doing_it_wrong(
234
+			__METHOD__,
235
+			sprintf(
236
+				esc_html__(
237
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
238
+					'event_espresso'
239
+				),
240
+				'Messages_Admin_Page::get_message_types_select_input()'
241
+			),
242
+			'4.9.9.rc.014'
243
+		);
244
+
245
+		$mt_values       = [];
246
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
247
+		$i               = 1;
248
+		foreach ($active_messages as $active_message) {
249
+			if ($active_message instanceof EE_Message) {
250
+				$mt_values[ $i ]['id']   = $active_message->message_type();
251
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
252
+				$i++;
253
+			}
254
+		}
255
+
256
+		return $mt_values;
257
+	}
258
+
259
+
260
+	/**
261
+	 * @return array
262
+	 * @throws EE_Error
263
+	 * @throws InvalidArgumentException
264
+	 * @throws InvalidDataTypeException
265
+	 * @throws InvalidInterfaceException
266
+	 * @deprecated 4.9.9.rc.014
267
+	 */
268
+	public function get_contexts_for_message_types_for_list_table()
269
+	{
270
+		EE_Error::doing_it_wrong(
271
+			__METHOD__,
272
+			sprintf(
273
+				esc_html__(
274
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
275
+					'event_espresso'
276
+				),
277
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
278
+			),
279
+			'4.9.9.rc.014'
280
+		);
281
+
282
+		$contexts                = [];
283
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
284
+		foreach ($active_message_contexts as $active_message) {
285
+			if ($active_message instanceof EE_Message) {
286
+				$message_type = $active_message->message_type_object();
287
+				if ($message_type instanceof EE_message_type) {
288
+					$message_type_contexts = $message_type->get_contexts();
289
+					foreach ($message_type_contexts as $context => $context_details) {
290
+						$contexts[ $context ] = $context_details['label'];
291
+					}
292
+				}
293
+			}
294
+		}
295
+
296
+		return $contexts;
297
+	}
298
+
299
+
300
+	/**
301
+	 * Generate select input with provided messenger options array.
302
+	 *
303
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
304
+	 *                                 labels.
305
+	 * @return string
306
+	 * @throws EE_Error
307
+	 */
308
+	public function get_messengers_select_input($messenger_options)
309
+	{
310
+		// if empty or just one value then just return an empty string
311
+		if (
312
+			empty($messenger_options)
313
+			|| ! is_array($messenger_options)
314
+			|| count($messenger_options) === 1
315
+		) {
316
+			return '';
317
+		}
318
+		// merge in default
319
+		$messenger_options = array_merge(
320
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
321
+			$messenger_options
322
+		);
323
+		$input             = new EE_Select_Input(
324
+			$messenger_options,
325
+			[
326
+				'html_name'  => 'ee_messenger_filter_by',
327
+				'html_id'    => 'ee_messenger_filter_by',
328
+				'html_class' => 'wide',
329
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
330
+			]
331
+		);
332
+
333
+		return $input->get_html_for_input();
334
+	}
335
+
336
+
337
+	/**
338
+	 * Generate select input with provided message type options array.
339
+	 *
340
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
341
+	 *                                    message type labels
342
+	 * @return string
343
+	 * @throws EE_Error
344
+	 */
345
+	public function get_message_types_select_input($message_type_options)
346
+	{
347
+		// if empty or count of options is 1 then just return an empty string
348
+		if (
349
+			empty($message_type_options)
350
+			|| ! is_array($message_type_options)
351
+			|| count($message_type_options) === 1
352
+		) {
353
+			return '';
354
+		}
355
+		// merge in default
356
+		$message_type_options = array_merge(
357
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
358
+			$message_type_options
359
+		);
360
+		$input                = new EE_Select_Input(
361
+			$message_type_options,
362
+			[
363
+				'html_name'  => 'ee_message_type_filter_by',
364
+				'html_id'    => 'ee_message_type_filter_by',
365
+				'html_class' => 'wide',
366
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
367
+			]
368
+		);
369
+
370
+		return $input->get_html_for_input();
371
+	}
372
+
373
+
374
+	/**
375
+	 * Generate select input with provide message type contexts array.
376
+	 *
377
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
378
+	 *                               context label.
379
+	 * @return string
380
+	 * @throws EE_Error
381
+	 */
382
+	public function get_contexts_for_message_types_select_input($context_options)
383
+	{
384
+		// if empty or count of options is one then just return empty string
385
+		if (
386
+			empty($context_options)
387
+			|| ! is_array($context_options)
388
+			|| count($context_options) === 1
389
+		) {
390
+			return '';
391
+		}
392
+		// merge in default
393
+		$context_options = array_merge(
394
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
395
+			$context_options
396
+		);
397
+		$input           = new EE_Select_Input(
398
+			$context_options,
399
+			[
400
+				'html_name'  => 'ee_context_filter_by',
401
+				'html_id'    => 'ee_context_filter_by',
402
+				'html_class' => 'wide',
403
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
404
+			]
405
+		);
406
+
407
+		return $input->get_html_for_input();
408
+	}
409
+
410
+
411
+	protected function _ajax_hooks()
412
+	{
413
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
414
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
415
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
416
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
417
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
418
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
419
+	}
420
+
421
+
422
+	protected function _define_page_props()
423
+	{
424
+		$this->_admin_page_title = $this->page_label;
425
+		$this->_labels           = [
426
+			'buttons'    => [
427
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
428
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
429
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
430
+			],
431
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
432
+		];
433
+	}
434
+
435
+
436
+	/**
437
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
438
+	 *
439
+	 * @access protected
440
+	 * @return void
441
+	 */
442
+	protected function _set_page_routes()
443
+	{
444
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
445
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
446
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
447
+
448
+		$this->_page_routes = [
449
+			'default'                          => [
450
+				'func'       => '_message_queue_list_table',
451
+				'capability' => 'ee_read_global_messages',
452
+			],
453
+			'global_mtps'                      => [
454
+				'func'       => '_ee_default_messages_overview_list_table',
455
+				'capability' => 'ee_read_global_messages',
456
+			],
457
+			'custom_mtps'                      => [
458
+				'func'       => '_custom_mtps_preview',
459
+				'capability' => 'ee_read_messages',
460
+			],
461
+			'add_new_message_template'         => [
462
+				'func'       => 'add_message_template',
463
+				'capability' => 'ee_edit_messages',
464
+				'noheader'   => true,
465
+			],
466
+			'edit_message_template'            => [
467
+				'func'       => '_edit_message_template',
468
+				'capability' => 'ee_edit_message',
469
+				'obj_id'     => $GRP_ID,
470
+			],
471
+			'preview_message'                  => [
472
+				'func'               => '_preview_message',
473
+				'capability'         => 'ee_read_message',
474
+				'obj_id'             => $GRP_ID,
475
+				'noheader'           => true,
476
+				'headers_sent_route' => 'display_preview_message',
477
+			],
478
+			'display_preview_message'          => [
479
+				'func'       => '_display_preview_message',
480
+				'capability' => 'ee_read_message',
481
+				'obj_id'     => $GRP_ID,
482
+			],
483
+			'insert_message_template'          => [
484
+				'func'       => '_insert_or_update_message_template',
485
+				'capability' => 'ee_edit_messages',
486
+				'args'       => ['new' => true],
487
+				'noheader'   => true,
488
+			],
489
+			'update_message_template'          => [
490
+				'func'       => '_insert_or_update_message_template',
491
+				'capability' => 'ee_edit_message',
492
+				'obj_id'     => $GRP_ID,
493
+				'args'       => ['new' => false],
494
+				'noheader'   => true,
495
+			],
496
+			'trash_message_template'           => [
497
+				'func'       => '_trash_or_restore_message_template',
498
+				'capability' => 'ee_delete_message',
499
+				'obj_id'     => $GRP_ID,
500
+				'args'       => ['trash' => true, 'all' => true],
501
+				'noheader'   => true,
502
+			],
503
+			'trash_message_template_context'   => [
504
+				'func'       => '_trash_or_restore_message_template',
505
+				'capability' => 'ee_delete_message',
506
+				'obj_id'     => $GRP_ID,
507
+				'args'       => ['trash' => true],
508
+				'noheader'   => true,
509
+			],
510
+			'restore_message_template'         => [
511
+				'func'       => '_trash_or_restore_message_template',
512
+				'capability' => 'ee_delete_message',
513
+				'obj_id'     => $GRP_ID,
514
+				'args'       => ['trash' => false, 'all' => true],
515
+				'noheader'   => true,
516
+			],
517
+			'restore_message_template_context' => [
518
+				'func'       => '_trash_or_restore_message_template',
519
+				'capability' => 'ee_delete_message',
520
+				'obj_id'     => $GRP_ID,
521
+				'args'       => ['trash' => false],
522
+				'noheader'   => true,
523
+			],
524
+			'delete_message_template'          => [
525
+				'func'       => '_delete_message_template',
526
+				'capability' => 'ee_delete_message',
527
+				'obj_id'     => $GRP_ID,
528
+				'noheader'   => true,
529
+			],
530
+			'reset_to_default'                 => [
531
+				'func'       => '_reset_to_default_template',
532
+				'capability' => 'ee_edit_message',
533
+				'obj_id'     => $GRP_ID,
534
+				'noheader'   => true,
535
+			],
536
+			'settings'                         => [
537
+				'func'       => '_settings',
538
+				'capability' => 'manage_options',
539
+			],
540
+			'update_global_settings'           => [
541
+				'func'       => '_update_global_settings',
542
+				'capability' => 'manage_options',
543
+				'noheader'   => true,
544
+			],
545
+			'generate_now'                     => [
546
+				'func'       => '_generate_now',
547
+				'capability' => 'ee_send_message',
548
+				'noheader'   => true,
549
+			],
550
+			'generate_and_send_now'            => [
551
+				'func'       => '_generate_and_send_now',
552
+				'capability' => 'ee_send_message',
553
+				'noheader'   => true,
554
+			],
555
+			'queue_for_resending'              => [
556
+				'func'       => '_queue_for_resending',
557
+				'capability' => 'ee_send_message',
558
+				'noheader'   => true,
559
+			],
560
+			'send_now'                         => [
561
+				'func'       => '_send_now',
562
+				'capability' => 'ee_send_message',
563
+				'noheader'   => true,
564
+			],
565
+			'delete_ee_message'                => [
566
+				'func'       => '_delete_ee_messages',
567
+				'capability' => 'ee_delete_messages',
568
+				'noheader'   => true,
569
+			],
570
+			'delete_ee_messages'               => [
571
+				'func'       => '_delete_ee_messages',
572
+				'capability' => 'ee_delete_messages',
573
+				'noheader'   => true,
574
+				'obj_id'     => $MSG_ID,
575
+			],
576
+		];
577
+	}
578
+
579
+
580
+	protected function _set_page_config()
581
+	{
582
+		$this->_page_config = [
583
+			'default'                  => [
584
+				'nav'           => [
585
+					'label' => esc_html__('Message Activity', 'event_espresso'),
586
+					'order' => 10,
587
+				],
588
+				'list_table'    => 'EE_Message_List_Table',
589
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
590
+				'require_nonce' => false,
591
+			],
592
+			'global_mtps'              => [
593
+				'nav'           => [
594
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
595
+					'order' => 20,
596
+				],
597
+				'list_table'    => 'Messages_Template_List_Table',
598
+				'help_tabs'     => [
599
+					'messages_overview_help_tab'                                => [
600
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
601
+						'filename' => 'messages_overview',
602
+					],
603
+					'messages_overview_messages_table_column_headings_help_tab' => [
604
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
605
+						'filename' => 'messages_overview_table_column_headings',
606
+					],
607
+					'messages_overview_messages_filters_help_tab'               => [
608
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
609
+						'filename' => 'messages_overview_filters',
610
+					],
611
+					'messages_overview_messages_views_help_tab'                 => [
612
+						'title'    => esc_html__('Message Views', 'event_espresso'),
613
+						'filename' => 'messages_overview_views',
614
+					],
615
+					'message_overview_message_types_help_tab'                   => [
616
+						'title'    => esc_html__('Message Types', 'event_espresso'),
617
+						'filename' => 'messages_overview_types',
618
+					],
619
+					'messages_overview_messengers_help_tab'                     => [
620
+						'title'    => esc_html__('Messengers', 'event_espresso'),
621
+						'filename' => 'messages_overview_messengers',
622
+					],
623
+				],
624
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
625
+				// 'help_tour'     => array('Messages_Overview_Help_Tour'),
626
+				'require_nonce' => false,
627
+			],
628
+			'custom_mtps'              => [
629
+				'nav'           => [
630
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
631
+					'order' => 30,
632
+				],
633
+				'help_tabs'     => [],
634
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
635
+				// 'help_tour'     => array(),
636
+				'require_nonce' => false,
637
+			],
638
+			'add_new_message_template' => [
639
+				'nav'           => [
640
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
641
+					'order'      => 5,
642
+					'persistent' => false,
643
+				],
644
+				'require_nonce' => false,
645
+			],
646
+			'edit_message_template'    => [
647
+				'labels'        => [
648
+					'buttons'    => [
649
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
650
+					],
651
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
652
+				],
653
+				'nav'           => [
654
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
655
+					'order'      => 5,
656
+					'persistent' => false,
657
+					'url'        => '',
658
+				],
659
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
660
+				'has_metaboxes' => true,
661
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
662
+				// 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
663
+				'help_tabs'     => [
664
+					'edit_message_template'            => [
665
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
666
+						'callback' => 'edit_message_template_help_tab',
667
+					],
668
+					'message_templates_help_tab'       => [
669
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
670
+						'filename' => 'messages_templates',
671
+					],
672
+					'message_template_shortcodes'      => [
673
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
674
+						'callback' => 'message_template_shortcodes_help_tab',
675
+					],
676
+					'message_preview_help_tab'         => [
677
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
678
+						'filename' => 'messages_preview',
679
+					],
680
+					'messages_overview_other_help_tab' => [
681
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
682
+						'filename' => 'messages_overview_other',
683
+					],
684
+				],
685
+				'require_nonce' => false,
686
+			],
687
+			'display_preview_message'  => [
688
+				'nav'           => [
689
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
690
+					'order'      => 5,
691
+					'url'        => '',
692
+					'persistent' => false,
693
+				],
694
+				'help_tabs'     => [
695
+					'preview_message' => [
696
+						'title'    => esc_html__('About Previews', 'event_espresso'),
697
+						'callback' => 'preview_message_help_tab',
698
+					],
699
+				],
700
+				'require_nonce' => false,
701
+			],
702
+			'settings'                 => [
703
+				'nav'           => [
704
+					'label' => esc_html__('Settings', 'event_espresso'),
705
+					'order' => 40,
706
+				],
707
+				'metaboxes'     => ['_messages_settings_metaboxes'],
708
+				'help_tabs'     => [
709
+					'messages_settings_help_tab'               => [
710
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
711
+						'filename' => 'messages_settings',
712
+					],
713
+					'messages_settings_message_types_help_tab' => [
714
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
715
+						'filename' => 'messages_settings_message_types',
716
+					],
717
+					'messages_settings_messengers_help_tab'    => [
718
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
719
+						'filename' => 'messages_settings_messengers',
720
+					],
721
+				],
722
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
723
+				// 'help_tour'     => array('Messages_Settings_Help_Tour'),
724
+				'require_nonce' => false,
725
+			],
726
+		];
727
+	}
728
+
729
+
730
+	protected function _add_screen_options()
731
+	{
732
+		// todo
733
+	}
734
+
735
+
736
+	protected function _add_screen_options_global_mtps()
737
+	{
738
+		/**
739
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
740
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
741
+		 */
742
+		$page_title              = $this->_admin_page_title;
743
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
744
+		$this->_per_page_screen_option();
745
+		$this->_admin_page_title = $page_title;
746
+	}
747
+
748
+
749
+	protected function _add_screen_options_default()
750
+	{
751
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
752
+		$this->_per_page_screen_option();
753
+	}
754
+
755
+
756
+	// none of the below group are currently used for Messages
757
+	protected function _add_feature_pointers()
758
+	{
759
+	}
760
+
761
+
762
+	public function admin_init()
763
+	{
764
+	}
765
+
766
+
767
+	public function admin_notices()
768
+	{
769
+	}
770
+
771
+
772
+	public function admin_footer_scripts()
773
+	{
774
+	}
775
+
776
+
777
+	public function messages_help_tab()
778
+	{
779
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
780
+	}
781
+
782
+
783
+	public function messengers_help_tab()
784
+	{
785
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
786
+	}
787
+
788
+
789
+	public function message_types_help_tab()
790
+	{
791
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
792
+	}
793
+
794
+
795
+	public function messages_overview_help_tab()
796
+	{
797
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
798
+	}
799
+
800
+
801
+	public function message_templates_help_tab()
802
+	{
803
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
804
+	}
805
+
806
+
807
+	public function edit_message_template_help_tab()
808
+	{
809
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
810
+						. esc_attr__('Editor Title', 'event_espresso')
811
+						. '" />';
812
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
813
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
814
+						. '" />';
815
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
816
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
817
+						. '" />';
818
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
819
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
820
+						. '" />';
821
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
822
+						. esc_attr__('Publish Metabox', 'event_espresso')
823
+						. '" />';
824
+		EEH_Template::display_template(
825
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
826
+			$args
827
+		);
828
+	}
829
+
830
+
831
+	/**
832
+	 * @throws ReflectionException
833
+	 * @throws EE_Error
834
+	 */
835
+	public function message_template_shortcodes_help_tab()
836
+	{
837
+		$this->_set_shortcodes();
838
+		$args['shortcodes'] = $this->_shortcodes;
839
+		EEH_Template::display_template(
840
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
841
+			$args
842
+		);
843
+	}
844
+
845
+
846
+	public function preview_message_help_tab()
847
+	{
848
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
849
+	}
850
+
851
+
852
+	public function settings_help_tab()
853
+	{
854
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
855
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
856
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
857
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
858
+		$args['img3'] = '<div class="switch">'
859
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
860
+						. ' type="checkbox" checked="checked">'
861
+						. '<label for="ee-on-off-toggle-on"></label>'
862
+						. '</div>';
863
+		$args['img4'] = '<div class="switch">'
864
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
865
+						. ' type="checkbox">'
866
+						. '<label for="ee-on-off-toggle-on"></label>'
867
+						. '</div>';
868
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
869
+	}
870
+
871
+
872
+	public function load_scripts_styles()
873
+	{
874
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
875
+		wp_enqueue_style('espresso_ee_msg');
876
+
877
+		wp_register_script(
878
+			'ee-messages-settings',
879
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
880
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
881
+			EVENT_ESPRESSO_VERSION,
882
+			true
883
+		);
884
+		wp_register_script(
885
+			'ee-msg-list-table-js',
886
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
887
+			['ee-dialog'],
888
+			EVENT_ESPRESSO_VERSION
889
+		);
890
+	}
891
+
892
+
893
+	public function load_scripts_styles_default()
894
+	{
895
+		wp_enqueue_script('ee-msg-list-table-js');
896
+	}
897
+
898
+
899
+	public function wp_editor_css($mce_css)
900
+	{
901
+		// if we're on the edit_message_template route
902
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
903
+			$message_type_name = $this->_active_message_type_name;
904
+
905
+			// we're going to REPLACE the existing mce css
906
+			// we need to get the css file location from the active messenger
907
+			$mce_css = $this->_active_messenger->get_variation(
908
+				$this->_template_pack,
909
+				$message_type_name,
910
+				true,
911
+				'wpeditor',
912
+				$this->_variation
913
+			);
914
+		}
915
+
916
+		return $mce_css;
917
+	}
918
+
919
+
920
+	/**
921
+	 * @throws EE_Error
922
+	 * @throws ReflectionException
923
+	 */
924
+	public function load_scripts_styles_edit_message_template()
925
+	{
926
+
927
+		$this->_set_shortcodes();
928
+
929
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
930
+			esc_html__(
931
+				'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.',
932
+				'event_espresso'
933
+			),
934
+			$this->_message_template_group->messenger_obj()->label['singular'],
935
+			$this->_message_template_group->message_type_obj()->label['singular']
936
+		);
937
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
938
+			'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?',
939
+			'event_espresso'
940
+		);
941
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
942
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
943
+			'event_espresso'
944
+		);
945
+
946
+		wp_register_script(
947
+			'ee_msgs_edit_js',
948
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
949
+			['jquery'],
950
+			EVENT_ESPRESSO_VERSION
951
+		);
952
+
953
+		wp_enqueue_script('ee_admin_js');
954
+		wp_enqueue_script('ee_msgs_edit_js');
955
+
956
+		// add in special css for tiny_mce
957
+		add_filter('mce_css', [$this, 'wp_editor_css']);
958
+	}
959
+
960
+
961
+	/**
962
+	 * @throws EE_Error
963
+	 * @throws ReflectionException
964
+	 */
965
+	public function load_scripts_styles_display_preview_message()
966
+	{
967
+		$this->_set_message_template_group();
968
+		if ($this->_active_messenger_name) {
969
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
970
+				$this->_active_messenger_name
971
+			);
972
+		}
973
+
974
+		wp_enqueue_style(
975
+			'espresso_preview_css',
976
+			$this->_active_messenger->get_variation(
977
+				$this->_template_pack,
978
+				$this->_active_message_type_name,
979
+				true,
980
+				'preview',
981
+				$this->_variation
982
+			)
983
+		);
984
+	}
985
+
986
+
987
+	public function load_scripts_styles_settings()
988
+	{
989
+		wp_register_style(
990
+			'ee-message-settings',
991
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
992
+			[],
993
+			EVENT_ESPRESSO_VERSION
994
+		);
995
+		wp_enqueue_style('ee-text-links');
996
+		wp_enqueue_style('ee-message-settings');
997
+		wp_enqueue_script('ee-messages-settings');
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * set views array for List Table
1003
+	 */
1004
+	public function _set_list_table_views_global_mtps()
1005
+	{
1006
+		$this->_views = [
1007
+			'in_use' => [
1008
+				'slug'  => 'in_use',
1009
+				'label' => esc_html__('In Use', 'event_espresso'),
1010
+				'count' => 0,
1011
+			],
1012
+		];
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * Set views array for the Custom Template List Table
1018
+	 */
1019
+	public function _set_list_table_views_custom_mtps()
1020
+	{
1021
+		$this->_set_list_table_views_global_mtps();
1022
+		$this->_views['in_use']['bulk_action'] = [
1023
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1024
+		];
1025
+	}
1026
+
1027
+
1028
+	/**
1029
+	 * set views array for message queue list table
1030
+	 *
1031
+	 * @throws InvalidDataTypeException
1032
+	 * @throws InvalidInterfaceException
1033
+	 * @throws InvalidArgumentException
1034
+	 * @throws EE_Error
1035
+	 * @throws ReflectionException
1036
+	 */
1037
+	public function _set_list_table_views_default()
1038
+	{
1039
+		EE_Registry::instance()->load_helper('Template');
1040
+
1041
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1042
+			'ee_send_message',
1043
+			'message_list_table_bulk_actions'
1044
+		)
1045
+			? [
1046
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1047
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1048
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1049
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1050
+			]
1051
+			: [];
1052
+
1053
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1054
+			'ee_delete_messages',
1055
+			'message_list_table_bulk_actions'
1056
+		)
1057
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1058
+			: [];
1059
+
1060
+
1061
+		$this->_views = [
1062
+			'all' => [
1063
+				'slug'        => 'all',
1064
+				'label'       => esc_html__('All', 'event_espresso'),
1065
+				'count'       => 0,
1066
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1067
+			],
1068
+		];
1069
+
1070
+
1071
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1072
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1073
+				continue;
1074
+			}
1075
+			$status_bulk_actions = $common_bulk_actions;
1076
+			// unset bulk actions not applying to status
1077
+			if (! empty($status_bulk_actions)) {
1078
+				switch ($status) {
1079
+					case EEM_Message::status_idle:
1080
+					case EEM_Message::status_resend:
1081
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1082
+						break;
1083
+
1084
+					case EEM_Message::status_failed:
1085
+					case EEM_Message::status_debug_only:
1086
+					case EEM_Message::status_messenger_executing:
1087
+						$status_bulk_actions = [];
1088
+						break;
1089
+
1090
+					case EEM_Message::status_incomplete:
1091
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1092
+						break;
1093
+
1094
+					case EEM_Message::status_retry:
1095
+					case EEM_Message::status_sent:
1096
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1097
+						break;
1098
+				}
1099
+			}
1100
+
1101
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1102
+			if ($status === EEM_Message::status_messenger_executing) {
1103
+				continue;
1104
+			}
1105
+
1106
+			$this->_views[ strtolower($status) ] = [
1107
+				'slug'        => strtolower($status),
1108
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1109
+				'count'       => 0,
1110
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1111
+			];
1112
+		}
1113
+	}
1114
+
1115
+
1116
+	/**
1117
+	 * @throws EE_Error
1118
+	 */
1119
+	protected function _ee_default_messages_overview_list_table()
1120
+	{
1121
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1122
+		$this->display_admin_list_table_page_with_no_sidebar();
1123
+	}
1124
+
1125
+
1126
+	/**
1127
+	 * @throws EE_Error
1128
+	 * @throws ReflectionException
1129
+	 */
1130
+	protected function _message_queue_list_table()
1131
+	{
1132
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1133
+		$this->_template_args['per_column']        = 6;
1134
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1135
+		$this->_template_args['before_list_table'] = '<h3>'
1136
+													 . $this->getMsgModel()->get_pretty_label_for_results()
1137
+													 . '</h3>';
1138
+		$this->display_admin_list_table_page_with_no_sidebar();
1139
+	}
1140
+
1141
+
1142
+	/**
1143
+	 * @throws EE_Error
1144
+	 */
1145
+	protected function _message_legend_items()
1146
+	{
1147
+
1148
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1149
+		$action_items       = [];
1150
+
1151
+		foreach ($action_css_classes as $action_item => $action_details) {
1152
+			if ($action_item === 'see_notifications_for') {
1153
+				continue;
1154
+			}
1155
+			$action_items[ $action_item ] = [
1156
+				'class' => $action_details['css_class'],
1157
+				'desc'  => $action_details['label'],
1158
+			];
1159
+		}
1160
+
1161
+		/** @var array $status_items status legend setup */
1162
+		$status_items = [
1163
+			'sent_status'                => [
1164
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1165
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1166
+			],
1167
+			'idle_status'                => [
1168
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1169
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1170
+			],
1171
+			'failed_status'              => [
1172
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1173
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1174
+			],
1175
+			'messenger_executing_status' => [
1176
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1177
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1178
+			],
1179
+			'resend_status'              => [
1180
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1181
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1182
+			],
1183
+			'incomplete_status'          => [
1184
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1185
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1186
+			],
1187
+			'retry_status'               => [
1188
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1189
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1190
+			],
1191
+		];
1192
+		if (EEM_Message::debug()) {
1193
+			$status_items['debug_only_status'] = [
1194
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1195
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1196
+			];
1197
+		}
1198
+
1199
+		return array_merge($action_items, $status_items);
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * @throws EE_Error
1205
+	 */
1206
+	protected function _custom_mtps_preview()
1207
+	{
1208
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1209
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1210
+												. ' alt="' . esc_attr__(
1211
+													'Preview Custom Message Templates screenshot',
1212
+													'event_espresso'
1213
+												) . '" />';
1214
+		$this->_template_args['preview_text'] = '<strong>'
1215
+												. esc_html__(
1216
+													'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.',
1217
+													'event_espresso'
1218
+												)
1219
+												. '</strong>';
1220
+
1221
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * get_message_templates
1227
+	 * This gets all the message templates for listing on the overview list.
1228
+	 *
1229
+	 * @access public
1230
+	 * @param int    $per_page the amount of templates groups to show per page
1231
+	 * @param string $type     the current _view we're getting templates for
1232
+	 * @param bool   $count    return count?
1233
+	 * @param bool   $all      disregard any paging info (get all data);
1234
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1235
+	 * @return array
1236
+	 * @throws EE_Error
1237
+	 * @throws InvalidArgumentException
1238
+	 * @throws InvalidDataTypeException
1239
+	 * @throws InvalidInterfaceException
1240
+	 */
1241
+	public function get_message_templates(
1242
+		$per_page = 10,
1243
+		$type = 'in_use',
1244
+		$count = false,
1245
+		$all = false,
1246
+		$global = true
1247
+	) {
1248
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1249
+		$this->request->setRequestParam('orderby', $orderby);
1250
+
1251
+		$order        = $this->request->getRequestParam('order', 'ASC');
1252
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1253
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1254
+
1255
+		$offset = ($current_page - 1) * $per_page;
1256
+		$limit  = $all ? null : [$offset, $per_page];
1257
+
1258
+		// options will match what is in the _views array property
1259
+		return $type === 'in_use'
1260
+			? $this->getMtgModel()->get_all_active_message_templates(
1261
+				$orderby,
1262
+				$order,
1263
+				$limit,
1264
+				$count,
1265
+				$global,
1266
+				true
1267
+			)
1268
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1269
+				$orderby,
1270
+				$order,
1271
+				$limit,
1272
+				$count,
1273
+				$global
1274
+			);
1275
+	}
1276
+
1277
+
1278
+	/**
1279
+	 * filters etc might need a list of installed message_types
1280
+	 *
1281
+	 * @return array an array of message type objects
1282
+	 */
1283
+	public function get_installed_message_types()
1284
+	{
1285
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1286
+		$installed               = [];
1287
+
1288
+		foreach ($installed_message_types as $message_type) {
1289
+			$installed[ $message_type->name ] = $message_type;
1290
+		}
1291
+
1292
+		return $installed;
1293
+	}
1294
+
1295
+
1296
+	/**
1297
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1298
+	 *
1299
+	 * @param string $message_type
1300
+	 * @param string $messenger
1301
+	 * @param string $GRP_ID
1302
+	 *
1303
+	 * @throws EE_error
1304
+	 * @throws ReflectionException
1305
+	 */
1306
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1307
+	{
1308
+		// set values override any request data
1309
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1310
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1311
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1312
+
1313
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1314
+		if (empty($message_type) || empty($messenger)) {
1315
+			throw new EE_Error(
1316
+				esc_html__(
1317
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1318
+					'event_espresso'
1319
+				)
1320
+			);
1321
+		}
1322
+
1323
+		// we need the GRP_ID for the template being used as the base for the new template
1324
+		if (empty($GRP_ID)) {
1325
+			throw new EE_Error(
1326
+				esc_html__(
1327
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1328
+					'event_espresso'
1329
+				)
1330
+			);
1331
+		}
1332
+
1333
+		// let's just make sure the template gets generated!
1334
+
1335
+		// we need to reassign some variables for what the insert is expecting
1336
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1337
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1338
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1339
+
1340
+		$this->_insert_or_update_message_template(true);
1341
+	}
1342
+
1343
+
1344
+	/**
1345
+	 * @param string $message_type     message type slug
1346
+	 * @param string $messenger        messenger slug
1347
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1348
+	 *                                 off of.
1349
+	 * @throws EE_error
1350
+	 * @throws ReflectionException
1351
+	 * @deprecated $VID:$
1352
+	 */
1353
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1354
+	{
1355
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1356
+	}
1357
+
1358
+
1359
+	/**
1360
+	 * _edit_message_template
1361
+	 *
1362
+	 * @access protected
1363
+	 * @return void
1364
+	 * @throws InvalidIdentifierException
1365
+	 * @throws DomainException
1366
+	 * @throws EE_Error
1367
+	 * @throws InvalidArgumentException
1368
+	 * @throws ReflectionException
1369
+	 * @throws InvalidDataTypeException
1370
+	 * @throws InvalidInterfaceException
1371
+	 */
1372
+	protected function _edit_message_template()
1373
+	{
1374
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1375
+		$template_fields = '';
1376
+		$sidebar_fields  = '';
1377
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1378
+		// valid html in the templates.
1379
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1380
+
1381
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1382
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1383
+
1384
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1385
+		$message_template_group = $this->_message_template_group;
1386
+		$c_label                = $message_template_group->context_label();
1387
+		$c_config               = $message_template_group->contexts_config();
1388
+
1389
+		reset($c_config);
1390
+		$context = $this->request->getRequestParam('context', key($c_config));
1391
+		$context = strtolower($context);
1392
+
1393
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1394
+
1395
+		$edit_message_template_form_url = add_query_arg(
1396
+			['action' => $action, 'noheader' => true],
1397
+			EE_MSG_ADMIN_URL
1398
+		);
1399
+
1400
+		// set active messenger for this view
1401
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1402
+			$message_template_group->messenger()
1403
+		);
1404
+		$this->_active_message_type_name = $message_template_group->message_type();
1405
+
1406
+
1407
+		// Do we have any validation errors?
1408
+		$validators = $this->_get_transient();
1409
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1410
+
1411
+
1412
+		// we need to assemble the title from Various details
1413
+		$context_label = sprintf(
1414
+			esc_html__('(%s %s)', 'event_espresso'),
1415
+			$c_config[ $context ]['label'],
1416
+			ucwords($c_label['label'])
1417
+		);
1418
+
1419
+		$title = sprintf(
1420
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1421
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1422
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1423
+			$context_label
1424
+		);
1425
+
1426
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1427
+		$this->_template_args['message_template'] = $message_template_group;
1428
+		$this->_template_args['is_extra_fields']  = false;
1429
+
1430
+
1431
+		// let's get EEH_MSG_Template so we can get template form fields
1432
+		$template_field_structure = EEH_MSG_Template::get_fields(
1433
+			$message_template_group->messenger(),
1434
+			$message_template_group->message_type()
1435
+		);
1436
+
1437
+		if (! $template_field_structure) {
1438
+			$template_field_structure = false;
1439
+			$template_fields          = esc_html__(
1440
+				'There was an error in assembling the fields for this display (you should see an error message)',
1441
+				'event_espresso'
1442
+			);
1443
+		}
1444
+
1445
+
1446
+		$message_templates = $message_template_group->context_templates();
1447
+
1448
+
1449
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1450
+		// will get handled in the "extra" array.
1451
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1452
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1453
+				unset($template_field_structure[ $context ][ $reference_field ]);
1454
+			}
1455
+		}
1456
+
1457
+		// let's loop through the template_field_structure and actually assemble the input fields!
1458
+		if (! empty($template_field_structure)) {
1459
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1460
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1461
+				// the extra array and reset them.
1462
+				if ($template_field === 'extra') {
1463
+					$this->_template_args['is_extra_fields'] = true;
1464
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1465
+						$message_template = $message_templates[ $context ][ $reference_field ];
1466
+						$content          = $message_template instanceof EE_Message_Template
1467
+							? $message_template->get('MTP_content')
1468
+							: '';
1469
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1470
+							// let's verify if we need this extra field via the shortcodes parameter.
1471
+							$continue = false;
1472
+							if (isset($extra_array['shortcodes_required'])) {
1473
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1474
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1475
+										$continue = true;
1476
+									}
1477
+								}
1478
+								if ($continue) {
1479
+									continue;
1480
+								}
1481
+							}
1482
+
1483
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1484
+
1485
+							$template_form_fields[ $field_id ]         = $extra_array;
1486
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1487
+																		 . $reference_field
1488
+																		 . '][content]['
1489
+																		 . $extra_field . ']';
1490
+							$css_class                                 = isset($extra_array['css_class'])
1491
+								? $extra_array['css_class']
1492
+								: '';
1493
+
1494
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1495
+																			  && in_array($extra_field, $v_fields, true)
1496
+																			  && (
1497
+																				  is_array($validators[ $extra_field ])
1498
+																				  && isset($validators[ $extra_field ]['msg'])
1499
+																			  )
1500
+								? 'validate-error ' . $css_class
1501
+								: $css_class;
1502
+
1503
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1504
+																		  && isset($content[ $extra_field ])
1505
+								? $content[ $extra_field ]
1506
+								: '';
1507
+
1508
+							// do we have a validation error?  if we do then let's use that value instead
1509
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1510
+								? $validators[ $extra_field ]['value']
1511
+								: $template_form_fields[ $field_id ]['value'];
1512
+
1513
+
1514
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1515
+
1516
+							// shortcode selector
1517
+							$field_name_to_use                                   = $extra_field === 'main'
1518
+								? 'content'
1519
+								: $extra_field;
1520
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1521
+								$field_name_to_use,
1522
+								$field_id
1523
+							);
1524
+						}
1525
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1526
+						$template_field_template_name_id = $reference_field . '-name';
1527
+
1528
+						$template_form_fields[ $template_field_MTP_id ] = [
1529
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1530
+							'label'      => null,
1531
+							'input'      => 'hidden',
1532
+							'type'       => 'int',
1533
+							'required'   => false,
1534
+							'validation' => false,
1535
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1536
+							'css_class'  => '',
1537
+							'format'     => '%d',
1538
+							'db-col'     => 'MTP_ID',
1539
+						];
1540
+
1541
+						$template_form_fields[ $template_field_template_name_id ] = [
1542
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1543
+							'label'      => null,
1544
+							'input'      => 'hidden',
1545
+							'type'       => 'string',
1546
+							'required'   => false,
1547
+							'validation' => true,
1548
+							'value'      => $reference_field,
1549
+							'css_class'  => '',
1550
+							'format'     => '%s',
1551
+							'db-col'     => 'MTP_template_field',
1552
+						];
1553
+					}
1554
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1555
+				} else {
1556
+					$field_id                                   = $template_field . '-content';
1557
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1558
+					$template_form_fields[ $field_id ]['name']  =
1559
+						'MTP_template_fields[' . $template_field . '][content]';
1560
+					$message_template                           =
1561
+						isset($message_templates[ $context ][ $template_field ])
1562
+							? $message_templates[ $context ][ $template_field ]
1563
+							: null;
1564
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1565
+																  && is_array($message_templates[ $context ])
1566
+																  && $message_template instanceof EE_Message_Template
1567
+						? $message_template->get('MTP_content')
1568
+						: '';
1569
+
1570
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1571
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1572
+						? $validators[ $template_field ]['value']
1573
+						: $template_form_fields[ $field_id ]['value'];
1574
+
1575
+
1576
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1577
+					$css_class                                      = isset($field_setup_array['css_class'])
1578
+						? $field_setup_array['css_class']
1579
+						: '';
1580
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1581
+																	  && in_array($template_field, $v_fields, true)
1582
+																	  && isset($validators[ $template_field ]['msg'])
1583
+						? 'validate-error ' . $css_class
1584
+						: $css_class;
1585
+
1586
+					// shortcode selector
1587
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1588
+						$template_field,
1589
+						$field_id
1590
+					);
1591
+				}
1592
+
1593
+				// k took care of content field(s) now let's take care of others.
1594
+
1595
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1596
+				$template_field_field_template_name_id = $template_field . '-name';
1597
+
1598
+				// foreach template field there are actually two form fields created
1599
+				$template_form_fields[ $template_field_MTP_id ] = [
1600
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1601
+					'label'      => null,
1602
+					'input'      => 'hidden',
1603
+					'type'       => 'int',
1604
+					'required'   => false,
1605
+					'validation' => true,
1606
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1607
+					'css_class'  => '',
1608
+					'format'     => '%d',
1609
+					'db-col'     => 'MTP_ID',
1610
+				];
1611
+
1612
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1613
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1614
+					'label'      => null,
1615
+					'input'      => 'hidden',
1616
+					'type'       => 'string',
1617
+					'required'   => false,
1618
+					'validation' => true,
1619
+					'value'      => $template_field,
1620
+					'css_class'  => '',
1621
+					'format'     => '%s',
1622
+					'db-col'     => 'MTP_template_field',
1623
+				];
1624
+			}
1625
+
1626
+			// add other fields
1627
+			$template_form_fields['ee-msg-current-context'] = [
1628
+				'name'       => 'MTP_context',
1629
+				'label'      => null,
1630
+				'input'      => 'hidden',
1631
+				'type'       => 'string',
1632
+				'required'   => false,
1633
+				'validation' => true,
1634
+				'value'      => $context,
1635
+				'css_class'  => '',
1636
+				'format'     => '%s',
1637
+				'db-col'     => 'MTP_context',
1638
+			];
1639
+
1640
+			$template_form_fields['ee-msg-grp-id'] = [
1641
+				'name'       => 'GRP_ID',
1642
+				'label'      => null,
1643
+				'input'      => 'hidden',
1644
+				'type'       => 'int',
1645
+				'required'   => false,
1646
+				'validation' => true,
1647
+				'value'      => $GRP_ID,
1648
+				'css_class'  => '',
1649
+				'format'     => '%d',
1650
+				'db-col'     => 'GRP_ID',
1651
+			];
1652
+
1653
+			$template_form_fields['ee-msg-messenger'] = [
1654
+				'name'       => 'MTP_messenger',
1655
+				'label'      => null,
1656
+				'input'      => 'hidden',
1657
+				'type'       => 'string',
1658
+				'required'   => false,
1659
+				'validation' => true,
1660
+				'value'      => $message_template_group->messenger(),
1661
+				'css_class'  => '',
1662
+				'format'     => '%s',
1663
+				'db-col'     => 'MTP_messenger',
1664
+			];
1665
+
1666
+			$template_form_fields['ee-msg-message-type'] = [
1667
+				'name'       => 'MTP_message_type',
1668
+				'label'      => null,
1669
+				'input'      => 'hidden',
1670
+				'type'       => 'string',
1671
+				'required'   => false,
1672
+				'validation' => true,
1673
+				'value'      => $message_template_group->message_type(),
1674
+				'css_class'  => '',
1675
+				'format'     => '%s',
1676
+				'db-col'     => 'MTP_message_type',
1677
+			];
1678
+
1679
+			$sidebar_form_fields['ee-msg-is-global'] = [
1680
+				'name'       => 'MTP_is_global',
1681
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1682
+				'input'      => 'hidden',
1683
+				'type'       => 'int',
1684
+				'required'   => false,
1685
+				'validation' => true,
1686
+				'value'      => $message_template_group->get('MTP_is_global'),
1687
+				'css_class'  => '',
1688
+				'format'     => '%d',
1689
+				'db-col'     => 'MTP_is_global',
1690
+			];
1691
+
1692
+			$sidebar_form_fields['ee-msg-is-override'] = [
1693
+				'name'       => 'MTP_is_override',
1694
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1695
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1696
+				'type'       => 'int',
1697
+				'required'   => false,
1698
+				'validation' => true,
1699
+				'value'      => $message_template_group->get('MTP_is_override'),
1700
+				'css_class'  => '',
1701
+				'format'     => '%d',
1702
+				'db-col'     => 'MTP_is_override',
1703
+			];
1704
+
1705
+			$sidebar_form_fields['ee-msg-is-active'] = [
1706
+				'name'       => 'MTP_is_active',
1707
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1708
+				'input'      => 'hidden',
1709
+				'type'       => 'int',
1710
+				'required'   => false,
1711
+				'validation' => true,
1712
+				'value'      => $message_template_group->is_active(),
1713
+				'css_class'  => '',
1714
+				'format'     => '%d',
1715
+				'db-col'     => 'MTP_is_active',
1716
+			];
1717
+
1718
+			$sidebar_form_fields['ee-msg-deleted'] = [
1719
+				'name'       => 'MTP_deleted',
1720
+				'label'      => null,
1721
+				'input'      => 'hidden',
1722
+				'type'       => 'int',
1723
+				'required'   => false,
1724
+				'validation' => true,
1725
+				'value'      => $message_template_group->get('MTP_deleted'),
1726
+				'css_class'  => '',
1727
+				'format'     => '%d',
1728
+				'db-col'     => 'MTP_deleted',
1729
+			];
1730
+			$sidebar_form_fields['ee-msg-author']  = [
1731
+				'name'       => 'MTP_user_id',
1732
+				'label'      => esc_html__('Author', 'event_espresso'),
1733
+				'input'      => 'hidden',
1734
+				'type'       => 'int',
1735
+				'required'   => false,
1736
+				'validation' => false,
1737
+				'value'      => $message_template_group->user(),
1738
+				'format'     => '%d',
1739
+				'db-col'     => 'MTP_user_id',
1740
+			];
1741
+
1742
+			$sidebar_form_fields['ee-msg-route'] = [
1743
+				'name'  => 'action',
1744
+				'input' => 'hidden',
1745
+				'type'  => 'string',
1746
+				'value' => $action,
1747
+			];
1748
+
1749
+			$sidebar_form_fields['ee-msg-id']        = [
1750
+				'name'  => 'id',
1751
+				'input' => 'hidden',
1752
+				'type'  => 'int',
1753
+				'value' => $GRP_ID,
1754
+			];
1755
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1756
+				'name'  => $action . '_nonce',
1757
+				'input' => 'hidden',
1758
+				'type'  => 'string',
1759
+				'value' => wp_create_nonce($action . '_nonce'),
1760
+			];
1761
+
1762
+			$template_switch = $this->request->getRequestParam('template_switch');
1763
+			if ($template_switch) {
1764
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1765
+					'name'  => 'template_switch',
1766
+					'input' => 'hidden',
1767
+					'type'  => 'int',
1768
+					'value' => 1,
1769
+				];
1770
+			}
1771
+
1772
+
1773
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1774
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1775
+		} //end if ( !empty($template_field_structure) )
1776
+
1777
+		// set extra content for publish box
1778
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1779
+		$this->_set_publish_post_box_vars(
1780
+			'id',
1781
+			$GRP_ID,
1782
+			false,
1783
+			add_query_arg(
1784
+				['action' => 'global_mtps'],
1785
+				$this->_admin_base_url
1786
+			)
1787
+		);
1788
+
1789
+		// add preview button
1790
+		$preview_url    = parent::add_query_args_and_nonce(
1791
+			[
1792
+				'message_type' => $message_template_group->message_type(),
1793
+				'messenger'    => $message_template_group->messenger(),
1794
+				'context'      => $context,
1795
+				'GRP_ID'       => $GRP_ID,
1796
+				'evt_id'       => $EVT_ID ?: false,
1797
+				'action'       => 'preview_message',
1798
+			],
1799
+			$this->_admin_base_url
1800
+		);
1801
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1802
+						  . esc_html__('Preview', 'event_espresso')
1803
+						  . '</a>';
1804
+
1805
+
1806
+		// setup context switcher
1807
+		$this->_set_context_switcher(
1808
+			$message_template_group,
1809
+			[
1810
+				'page'    => 'espresso_messages',
1811
+				'action'  => 'edit_message_template',
1812
+				'id'      => $GRP_ID,
1813
+				'evt_id'  => $EVT_ID,
1814
+				'context' => $context,
1815
+				'extra'   => $preview_button,
1816
+			]
1817
+		);
1818
+
1819
+
1820
+		// main box
1821
+		$this->_template_args['template_fields']                         = $template_fields;
1822
+		$this->_template_args['sidebar_box_id']                          = 'details';
1823
+		$this->_template_args['action']                                  = $action;
1824
+		$this->_template_args['context']                                 = $context;
1825
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1826
+		$this->_template_args['learn_more_about_message_templates_link'] =
1827
+			$this->_learn_more_about_message_templates_link();
1828
+
1829
+
1830
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1831
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1832
+			$message_template_group,
1833
+			$context,
1834
+			$context_label
1835
+		);
1836
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1837
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1838
+
1839
+		$this->_template_path = $this->_template_args['GRP_ID']
1840
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1841
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1842
+
1843
+		// send along EE_Message_Template_Group object for further template use.
1844
+		$this->_template_args['MTP'] = $message_template_group;
1845
+
1846
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1847
+			$this->_template_path,
1848
+			$this->_template_args,
1849
+			true
1850
+		);
1851
+
1852
+
1853
+		// finally, let's set the admin_page title
1854
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1855
+
1856
+
1857
+		// we need to take care of setting the shortcodes property for use elsewhere.
1858
+		$this->_set_shortcodes();
1859
+
1860
+
1861
+		// final template wrapper
1862
+		$this->display_admin_page_with_sidebar();
1863
+	}
1864
+
1865
+
1866
+	public function filter_tinymce_init($mceInit, $editor_id)
1867
+	{
1868
+		return $mceInit;
1869
+	}
1870
+
1871
+
1872
+	public function add_context_switcher()
1873
+	{
1874
+		return $this->_context_switcher;
1875
+	}
1876
+
1877
+
1878
+	/**
1879
+	 * Adds the activation/deactivation toggle for the message template context.
1880
+	 *
1881
+	 * @param EE_Message_Template_Group $message_template_group
1882
+	 * @param string                    $context
1883
+	 * @param string                    $context_label
1884
+	 * @return string
1885
+	 * @throws DomainException
1886
+	 * @throws EE_Error
1887
+	 * @throws InvalidIdentifierException
1888
+	 * @throws ReflectionException
1889
+	 */
1890
+	protected function add_active_context_element(
1891
+		EE_Message_Template_Group $message_template_group,
1892
+		$context,
1893
+		$context_label
1894
+	) {
1895
+		$template_args = [
1896
+			'context'                   => $context,
1897
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1898
+			'is_active'                 => $message_template_group->is_context_active($context),
1899
+			'on_off_action'             => $message_template_group->is_context_active($context)
1900
+				? 'context-off'
1901
+				: 'context-on',
1902
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1903
+			'message_template_group_id' => $message_template_group->ID(),
1904
+		];
1905
+		return EEH_Template::display_template(
1906
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1907
+			$template_args,
1908
+			true
1909
+		);
1910
+	}
1911
+
1912
+
1913
+	/**
1914
+	 * Ajax callback for `toggle_context_template` ajax action.
1915
+	 * Handles toggling the message context on or off.
1916
+	 *
1917
+	 * @throws EE_Error
1918
+	 * @throws InvalidArgumentException
1919
+	 * @throws InvalidDataTypeException
1920
+	 * @throws InvalidIdentifierException
1921
+	 * @throws InvalidInterfaceException
1922
+	 */
1923
+	public function toggle_context_template()
1924
+	{
1925
+		$success = true;
1926
+		// check for required data
1927
+		if (
1928
+			! (
1929
+				$this->request->requestParamIsSet('message_template_group_id')
1930
+				&& $this->request->requestParamIsSet('context')
1931
+				&& $this->request->requestParamIsSet('status')
1932
+			)
1933
+		) {
1934
+			EE_Error::add_error(
1935
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1936
+				__FILE__,
1937
+				__FUNCTION__,
1938
+				__LINE__
1939
+			);
1940
+			$success = false;
1941
+		}
1942
+
1943
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1944
+		$context = $this->request->getRequestParam('context', '');
1945
+		$status  = $this->request->getRequestParam('status', '');
1946
+
1947
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1948
+
1949
+		if ($status !== 'off' && $status !== 'on') {
1950
+			EE_Error::add_error(
1951
+				sprintf(
1952
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1953
+					$status
1954
+				),
1955
+				__FILE__,
1956
+				__FUNCTION__,
1957
+				__LINE__
1958
+			);
1959
+			$success = false;
1960
+		}
1961
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1962
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1963
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1964
+			EE_Error::add_error(
1965
+				sprintf(
1966
+					esc_html__(
1967
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1968
+						'event_espresso'
1969
+					),
1970
+					$message_template_group_id,
1971
+					'EE_Message_Template_Group'
1972
+				),
1973
+				__FILE__,
1974
+				__FUNCTION__,
1975
+				__LINE__
1976
+			);
1977
+			$success = false;
1978
+		}
1979
+		if ($success) {
1980
+			$success = $status === 'off'
1981
+				? $message_template_group->deactivate_context($context)
1982
+				: $message_template_group->activate_context($context);
1983
+		}
1984
+		$this->_template_args['success'] = $success;
1985
+		$this->_return_json();
1986
+	}
1987
+
1988
+
1989
+	public function _add_form_element_before()
1990
+	{
1991
+		return '<form method="post" action="'
1992
+			   . $this->_template_args['edit_message_template_form_url']
1993
+			   . '" id="ee-msg-edit-frm">';
1994
+	}
1995
+
1996
+
1997
+	public function _add_form_element_after()
1998
+	{
1999
+		return '</form>';
2000
+	}
2001
+
2002
+
2003
+	/**
2004
+	 * This executes switching the template pack for a message template.
2005
+	 *
2006
+	 * @throws EE_Error
2007
+	 * @throws InvalidDataTypeException
2008
+	 * @throws InvalidInterfaceException
2009
+	 * @throws InvalidArgumentException
2010
+	 * @throws ReflectionException
2011
+	 * @since 4.5.0
2012
+	 */
2013
+	public function switch_template_pack()
2014
+	{
2015
+
2016
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2017
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2018
+
2019
+		// verify we have needed values.
2020
+		if (empty($GRP_ID) || empty($template_pack)) {
2021
+			$this->_template_args['error'] = true;
2022
+			EE_Error::add_error(
2023
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2024
+				__FILE__,
2025
+				__FUNCTION__,
2026
+				__LINE__
2027
+			);
2028
+		} else {
2029
+			// get template, set the new template_pack and then reset to default
2030
+			/** @var EE_Message_Template_Group $message_template_group */
2031
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2032
+
2033
+			$message_template_group->set_template_pack_name($template_pack);
2034
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2035
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2036
+
2037
+			$query_args = $this->_reset_to_default_template();
2038
+
2039
+			if (empty($query_args['id'])) {
2040
+				EE_Error::add_error(
2041
+					esc_html__(
2042
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2043
+						'event_espresso'
2044
+					),
2045
+					__FILE__,
2046
+					__FUNCTION__,
2047
+					__LINE__
2048
+				);
2049
+				$this->_template_args['error'] = true;
2050
+			} else {
2051
+				$template_label       = $message_template_group->get_template_pack()->label;
2052
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2053
+				EE_Error::add_success(
2054
+					sprintf(
2055
+						esc_html__(
2056
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2057
+							'event_espresso'
2058
+						),
2059
+						$template_label,
2060
+						$template_pack_labels->template_pack
2061
+					)
2062
+				);
2063
+				// generate the redirect url for js.
2064
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2065
+
2066
+				$this->_template_args['data']['redirect_url'] = $url;
2067
+				$this->_template_args['success']              = true;
2068
+			}
2069
+
2070
+			$this->_return_json();
2071
+		}
2072
+	}
2073
+
2074
+
2075
+	/**
2076
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2077
+	 * they want.
2078
+	 *
2079
+	 * @access protected
2080
+	 * @return array|void
2081
+	 * @throws EE_Error
2082
+	 * @throws InvalidArgumentException
2083
+	 * @throws InvalidDataTypeException
2084
+	 * @throws InvalidInterfaceException
2085
+	 * @throws ReflectionException
2086
+	 */
2087
+	protected function _reset_to_default_template()
2088
+	{
2089
+		$templates    = [];
2090
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2091
+		$messenger    = $this->request->getRequestParam('msgr');
2092
+		$message_type = $this->request->getRequestParam('mt');
2093
+		// we need to make sure we've got the info we need.
2094
+		if (! ($GRP_ID && $messenger && $message_type)) {
2095
+			EE_Error::add_error(
2096
+				esc_html__(
2097
+					'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.',
2098
+					'event_espresso'
2099
+				),
2100
+				__FILE__,
2101
+				__FUNCTION__,
2102
+				__LINE__
2103
+			);
2104
+		}
2105
+
2106
+		// all templates will be reset to whatever the defaults are
2107
+		// for the global template matching the messenger and message type.
2108
+		$success = ! empty($GRP_ID);
2109
+
2110
+		if ($success) {
2111
+			// let's first determine if the incoming template is a global template,
2112
+			// if it isn't then we need to get the global template matching messenger and message type.
2113
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2114
+
2115
+
2116
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2117
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2118
+
2119
+			if ($success) {
2120
+				// if successfully deleted, lets generate the new ones.
2121
+				// Note. We set GLOBAL to true, because resets on ANY template
2122
+				// will use the related global template defaults for regeneration.
2123
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2124
+				// HOWEVER, we DO keep the template pack and template variation set
2125
+				// for the current custom template when resetting.
2126
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2127
+			}
2128
+		}
2129
+
2130
+		// any error messages?
2131
+		if (! $success) {
2132
+			EE_Error::add_error(
2133
+				esc_html__(
2134
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2135
+					'event_espresso'
2136
+				),
2137
+				__FILE__,
2138
+				__FUNCTION__,
2139
+				__LINE__
2140
+			);
2141
+		}
2142
+
2143
+		// all good, let's add a success message!
2144
+		if ($success && ! empty($templates)) {
2145
+			// the info for the template we generated is the first element in the returned array
2146
+			EE_Error::overwrite_success();
2147
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2148
+		}
2149
+
2150
+
2151
+		$query_args = [
2152
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2153
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2154
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2155
+		];
2156
+
2157
+		// if called via ajax then we return query args otherwise redirect
2158
+		if ($this->request->isAjax()) {
2159
+			return $query_args;
2160
+		}
2161
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2162
+	}
2163
+
2164
+
2165
+	/**
2166
+	 * Retrieve and set the message preview for display.
2167
+	 *
2168
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2169
+	 * @return string
2170
+	 * @throws ReflectionException
2171
+	 * @throws EE_Error
2172
+	 * @throws InvalidArgumentException
2173
+	 * @throws InvalidDataTypeException
2174
+	 * @throws InvalidInterfaceException
2175
+	 */
2176
+	public function _preview_message($send = false)
2177
+	{
2178
+		// first make sure we've got the necessary parameters
2179
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2180
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2181
+			EE_Error::add_error(
2182
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2183
+				__FILE__,
2184
+				__FUNCTION__,
2185
+				__LINE__
2186
+			);
2187
+		}
2188
+
2189
+		$context = $this->request->getRequestParam('context');
2190
+		// get the preview!
2191
+		$preview = EED_Messages::preview_message(
2192
+			$this->_active_message_type_name,
2193
+			$context,
2194
+			$this->_active_messenger_name,
2195
+			$send
2196
+		);
2197
+
2198
+		if ($send) {
2199
+			return $preview;
2200
+		}
2201
+
2202
+		// if we have an evt_id set on the request, use it.
2203
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2204
+
2205
+		// let's add a button to go back to the edit view
2206
+		$query_args             = [
2207
+			'id'      => $GRP_ID,
2208
+			'evt_id'  => $EVT_ID,
2209
+			'context' => $context,
2210
+			'action'  => 'edit_message_template',
2211
+		];
2212
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2213
+		$preview_button         = '<a href="'
2214
+								  . $go_back_url
2215
+								  . '" class="button-secondary messages-preview-go-back-button">'
2216
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2217
+								  . '</a>';
2218
+		$message_types          = $this->get_installed_message_types();
2219
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2220
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2221
+			? ucwords($active_messenger->label['singular'])
2222
+			: esc_html__('Unknown Messenger', 'event_espresso');
2223
+		// let's provide a helpful title for context
2224
+		$preview_title = sprintf(
2225
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2226
+			$active_messenger_label,
2227
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2228
+		);
2229
+		if (empty($preview)) {
2230
+			$this->noEventsErrorMessage();
2231
+		}
2232
+		// setup display of preview.
2233
+		$this->_admin_page_title                    = $preview_title;
2234
+		$this->_template_args['admin_page_title']   = $preview_title;
2235
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2236
+		$this->_template_args['data']['force_json'] = true;
2237
+
2238
+		return '';
2239
+	}
2240
+
2241
+
2242
+	/**
2243
+	 * Used to set an error if there are no events available for generating a preview/test send.
2244
+	 *
2245
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2246
+	 */
2247
+	protected function noEventsErrorMessage($test_send = false)
2248
+	{
2249
+		$events_url = parent::add_query_args_and_nonce(
2250
+			[
2251
+				'action' => 'default',
2252
+				'page'   => 'espresso_events',
2253
+			],
2254
+			admin_url('admin.php')
2255
+		);
2256
+		$message    = $test_send
2257
+			? esc_html__(
2258
+				'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!',
2259
+				'event_espresso'
2260
+			)
2261
+			: esc_html__(
2262
+				'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!',
2263
+				'event_espresso'
2264
+			);
2265
+
2266
+		EE_Error::add_attention(
2267
+			sprintf(
2268
+				$message,
2269
+				"<a href='{$events_url}'>",
2270
+				'</a>'
2271
+			)
2272
+		);
2273
+	}
2274
+
2275
+
2276
+	/**
2277
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2278
+	 * gets called automatically.
2279
+	 *
2280
+	 * @return void
2281
+	 * @throws EE_Error
2282
+	 * @since 4.5.0
2283
+	 *
2284
+	 */
2285
+	protected function _display_preview_message()
2286
+	{
2287
+		$this->display_admin_page_with_no_sidebar();
2288
+	}
2289
+
2290
+
2291
+	/**
2292
+	 * registers metaboxes that should show up on the "edit_message_template" page
2293
+	 *
2294
+	 * @access protected
2295
+	 * @return void
2296
+	 */
2297
+	protected function _register_edit_meta_boxes()
2298
+	{
2299
+		add_meta_box(
2300
+			'mtp_valid_shortcodes',
2301
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2302
+			[$this, 'shortcode_meta_box'],
2303
+			$this->_current_screen->id,
2304
+			'side'
2305
+		);
2306
+		add_meta_box(
2307
+			'mtp_extra_actions',
2308
+			esc_html__('Extra Actions', 'event_espresso'),
2309
+			[$this, 'extra_actions_meta_box'],
2310
+			$this->_current_screen->id,
2311
+			'side',
2312
+			'high'
2313
+		);
2314
+		add_meta_box(
2315
+			'mtp_templates',
2316
+			esc_html__('Template Styles', 'event_espresso'),
2317
+			[$this, 'template_pack_meta_box'],
2318
+			$this->_current_screen->id,
2319
+			'side',
2320
+			'high'
2321
+		);
2322
+	}
2323
+
2324
+
2325
+	/**
2326
+	 * metabox content for all template pack and variation selection.
2327
+	 *
2328
+	 * @return void
2329
+	 * @throws DomainException
2330
+	 * @throws EE_Error
2331
+	 * @throws InvalidArgumentException
2332
+	 * @throws ReflectionException
2333
+	 * @throws InvalidDataTypeException
2334
+	 * @throws InvalidInterfaceException
2335
+	 * @since 4.5.0
2336
+	 */
2337
+	public function template_pack_meta_box()
2338
+	{
2339
+		$this->_set_message_template_group();
2340
+
2341
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2342
+
2343
+		$tp_select_values = [];
2344
+
2345
+		foreach ($tp_collection as $tp) {
2346
+			// only include template packs that support this messenger and message type!
2347
+			$supports = $tp->get_supports();
2348
+			if (
2349
+				! isset($supports[ $this->_message_template_group->messenger() ])
2350
+				|| ! in_array(
2351
+					$this->_message_template_group->message_type(),
2352
+					$supports[ $this->_message_template_group->messenger() ],
2353
+					true
2354
+				)
2355
+			) {
2356
+				// not supported
2357
+				continue;
2358
+			}
2359
+
2360
+			$tp_select_values[] = [
2361
+				'text' => $tp->label,
2362
+				'id'   => $tp->dbref,
2363
+			];
2364
+		}
2365
+
2366
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2367
+		// the default template pack.  This still allows for the odd template pack to override.
2368
+		if (empty($tp_select_values)) {
2369
+			$tp_select_values[] = [
2370
+				'text' => esc_html__('Default', 'event_espresso'),
2371
+				'id'   => 'default',
2372
+			];
2373
+		}
2374
+
2375
+		// setup variation select values for the currently selected template.
2376
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2377
+			$this->_message_template_group->messenger(),
2378
+			$this->_message_template_group->message_type()
2379
+		);
2380
+		$variations_select_values = [];
2381
+		foreach ($variations as $variation => $label) {
2382
+			$variations_select_values[] = [
2383
+				'text' => $label,
2384
+				'id'   => $variation,
2385
+			];
2386
+		}
2387
+
2388
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2389
+
2390
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2391
+			'MTP_template_pack',
2392
+			$tp_select_values,
2393
+			$this->_message_template_group->get_template_pack_name()
2394
+		);
2395
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2396
+			'MTP_template_variation',
2397
+			$variations_select_values,
2398
+			$this->_message_template_group->get_template_pack_variation()
2399
+		);
2400
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2401
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2402
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2403
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2404
+
2405
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2406
+
2407
+		EEH_Template::display_template($template, $template_args);
2408
+	}
2409
+
2410
+
2411
+	/**
2412
+	 * This meta box holds any extra actions related to Message Templates
2413
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2414
+	 *
2415
+	 * @access  public
2416
+	 * @return void
2417
+	 * @throws EE_Error
2418
+	 */
2419
+	public function extra_actions_meta_box()
2420
+	{
2421
+		$template_form_fields = [];
2422
+
2423
+		$extra_args = [
2424
+			'msgr'   => $this->_message_template_group->messenger(),
2425
+			'mt'     => $this->_message_template_group->message_type(),
2426
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2427
+		];
2428
+		// first we need to see if there are any fields
2429
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2430
+
2431
+		if (! empty($fields)) {
2432
+			// yup there be fields
2433
+			foreach ($fields as $field => $config) {
2434
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2435
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2436
+				$default  = isset($config['default']) ? $config['default'] : '';
2437
+				$default  = isset($config['value']) ? $config['value'] : $default;
2438
+
2439
+				// if type is hidden and the value is empty
2440
+				// something may have gone wrong so let's correct with the defaults
2441
+				$fix                = $config['input'] === 'hidden'
2442
+									  && isset($existing[ $field ])
2443
+									  && empty($existing[ $field ])
2444
+					? $default
2445
+					: '';
2446
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2447
+					? $existing[ $field ]
2448
+					: $fix;
2449
+
2450
+				$template_form_fields[ $field_id ] = [
2451
+					'name'       => 'test_settings_fld[' . $field . ']',
2452
+					'label'      => $config['label'],
2453
+					'input'      => $config['input'],
2454
+					'type'       => $config['type'],
2455
+					'required'   => $config['required'],
2456
+					'validation' => $config['validation'],
2457
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2458
+					'css_class'  => $config['css_class'],
2459
+					'options'    => isset($config['options']) ? $config['options'] : [],
2460
+					'default'    => $default,
2461
+					'format'     => $config['format'],
2462
+				];
2463
+			}
2464
+		}
2465
+
2466
+		$test_settings_html = ! empty($template_form_fields)
2467
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2468
+			: '';
2469
+
2470
+		// print out $test_settings_fields
2471
+		if (! empty($test_settings_html)) {
2472
+			$test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2473
+			$test_settings_html .= 'name="test_button" value="';
2474
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2475
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2476
+		}
2477
+
2478
+		// and button
2479
+		$test_settings_html .= '<p>';
2480
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2481
+		$test_settings_html .= '</p>';
2482
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2483
+		$test_settings_html .= $this->get_action_link_or_button(
2484
+			'reset_to_default',
2485
+			'reset',
2486
+			$extra_args,
2487
+			'button-primary reset-default-button'
2488
+		);
2489
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2490
+		echo $test_settings_html; // already escaped
2491
+	}
2492
+
2493
+
2494
+	/**
2495
+	 * This returns the shortcode selector skeleton for a given context and field.
2496
+	 *
2497
+	 * @param string $field           The name of the field retrieving shortcodes for.
2498
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2499
+	 * @return string
2500
+	 * @throws DomainException
2501
+	 * @throws EE_Error
2502
+	 * @throws InvalidArgumentException
2503
+	 * @throws ReflectionException
2504
+	 * @throws InvalidDataTypeException
2505
+	 * @throws InvalidInterfaceException
2506
+	 * @since 4.9.rc.000
2507
+	 */
2508
+	protected function _get_shortcode_selector($field, $linked_input_id)
2509
+	{
2510
+		$template_args = [
2511
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2512
+			'fieldname'       => $field,
2513
+			'linked_input_id' => $linked_input_id,
2514
+		];
2515
+
2516
+		return EEH_Template::display_template(
2517
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2518
+			$template_args,
2519
+			true
2520
+		);
2521
+	}
2522
+
2523
+
2524
+	/**
2525
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2526
+	 * page)
2527
+	 *
2528
+	 * @access public
2529
+	 * @return void
2530
+	 * @throws EE_Error
2531
+	 * @throws InvalidArgumentException
2532
+	 * @throws ReflectionException
2533
+	 * @throws InvalidDataTypeException
2534
+	 * @throws InvalidInterfaceException
2535
+	 */
2536
+	public function shortcode_meta_box()
2537
+	{
2538
+		$shortcodes = $this->_get_shortcodes([], false);
2539
+		// just make sure the shortcodes property is set
2540
+		// $messenger = $this->_message_template_group->messenger_obj();
2541
+		// now let's set the content depending on the status of the shortcodes array
2542
+		if (empty($shortcodes)) {
2543
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2544
+			return;
2545
+		}
2546
+		?>
2547 2547
         <div style="float:right; margin-top:10px">
2548 2548
             <?php echo $this->_get_help_tab_link('message_template_shortcodes'); // already escaped
2549
-            ?>
2549
+			?>
2550 2550
         </div>
2551 2551
         <p class="small-text">
2552 2552
             <?php printf(
2553
-                esc_html__(
2554
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2555
-                    'event_espresso'
2556
-                ),
2557
-                '<span class="dashicons dashicons-menu"></span>'
2558
-            ); ?>
2553
+				esc_html__(
2554
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2555
+					'event_espresso'
2556
+				),
2557
+				'<span class="dashicons dashicons-menu"></span>'
2558
+			); ?>
2559 2559
         </p>
2560 2560
         <?php
2561
-    }
2562
-
2563
-
2564
-    /**
2565
-     * used to set the $_shortcodes property for when its needed elsewhere.
2566
-     *
2567
-     * @access protected
2568
-     * @return void
2569
-     * @throws EE_Error
2570
-     * @throws InvalidArgumentException
2571
-     * @throws ReflectionException
2572
-     * @throws InvalidDataTypeException
2573
-     * @throws InvalidInterfaceException
2574
-     */
2575
-    protected function _set_shortcodes()
2576
-    {
2577
-
2578
-        // no need to run this if the property is already set
2579
-        if (! empty($this->_shortcodes)) {
2580
-            return;
2581
-        }
2582
-
2583
-        $this->_shortcodes = $this->_get_shortcodes();
2584
-    }
2585
-
2586
-
2587
-    /**
2588
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2589
-     * property)
2590
-     *
2591
-     * @access  protected
2592
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2593
-     *                         for. Defaults to all (for the given context)
2594
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2595
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2596
-     *                         true just an array of shortcode/label pairs.
2597
-     * @throws EE_Error
2598
-     * @throws InvalidArgumentException
2599
-     * @throws ReflectionException
2600
-     * @throws InvalidDataTypeException
2601
-     * @throws InvalidInterfaceException
2602
-     */
2603
-    protected function _get_shortcodes($fields = [], $merged = true)
2604
-    {
2605
-        $this->_set_message_template_group();
2606
-
2607
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2608
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2609
-        if (empty($GRP_ID)) {
2610
-            return [];
2611
-        }
2612
-        $context = $this->request->getRequestParam(
2613
-            'messenger',
2614
-            key($this->_message_template_group->contexts_config())
2615
-        );
2616
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2617
-    }
2618
-
2619
-
2620
-    /**
2621
-     * This sets the _message_template property (containing the called message_template object)
2622
-     *
2623
-     * @access protected
2624
-     * @return void
2625
-     * @throws EE_Error
2626
-     * @throws InvalidArgumentException
2627
-     * @throws ReflectionException
2628
-     * @throws InvalidDataTypeException
2629
-     * @throws InvalidInterfaceException
2630
-     */
2631
-    protected function _set_message_template_group()
2632
-    {
2633
-        // get out if this is already set.
2634
-        if (! empty($this->_message_template_group)) {
2635
-            return;
2636
-        }
2637
-
2638
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2639
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2640
-
2641
-        // let's get the message templates
2642
-        $this->_message_template_group = ! empty($GRP_ID)
2643
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2644
-            : $this->getMtgModel()->create_default_object();
2645
-
2646
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2647
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2648
-    }
2649
-
2650
-
2651
-    /**
2652
-     * sets up a context switcher for edit forms
2653
-     *
2654
-     * @access  protected
2655
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2656
-     * @param array                     $args                  various things the context switcher needs.
2657
-     * @throws EE_Error
2658
-     */
2659
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2660
-    {
2661
-        $context_details = $template_group_object->contexts_config();
2662
-        $context_label   = $template_group_object->context_label();
2663
-        ob_start();
2664
-        ?>
2561
+	}
2562
+
2563
+
2564
+	/**
2565
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2566
+	 *
2567
+	 * @access protected
2568
+	 * @return void
2569
+	 * @throws EE_Error
2570
+	 * @throws InvalidArgumentException
2571
+	 * @throws ReflectionException
2572
+	 * @throws InvalidDataTypeException
2573
+	 * @throws InvalidInterfaceException
2574
+	 */
2575
+	protected function _set_shortcodes()
2576
+	{
2577
+
2578
+		// no need to run this if the property is already set
2579
+		if (! empty($this->_shortcodes)) {
2580
+			return;
2581
+		}
2582
+
2583
+		$this->_shortcodes = $this->_get_shortcodes();
2584
+	}
2585
+
2586
+
2587
+	/**
2588
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2589
+	 * property)
2590
+	 *
2591
+	 * @access  protected
2592
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2593
+	 *                         for. Defaults to all (for the given context)
2594
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2595
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2596
+	 *                         true just an array of shortcode/label pairs.
2597
+	 * @throws EE_Error
2598
+	 * @throws InvalidArgumentException
2599
+	 * @throws ReflectionException
2600
+	 * @throws InvalidDataTypeException
2601
+	 * @throws InvalidInterfaceException
2602
+	 */
2603
+	protected function _get_shortcodes($fields = [], $merged = true)
2604
+	{
2605
+		$this->_set_message_template_group();
2606
+
2607
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2608
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2609
+		if (empty($GRP_ID)) {
2610
+			return [];
2611
+		}
2612
+		$context = $this->request->getRequestParam(
2613
+			'messenger',
2614
+			key($this->_message_template_group->contexts_config())
2615
+		);
2616
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2617
+	}
2618
+
2619
+
2620
+	/**
2621
+	 * This sets the _message_template property (containing the called message_template object)
2622
+	 *
2623
+	 * @access protected
2624
+	 * @return void
2625
+	 * @throws EE_Error
2626
+	 * @throws InvalidArgumentException
2627
+	 * @throws ReflectionException
2628
+	 * @throws InvalidDataTypeException
2629
+	 * @throws InvalidInterfaceException
2630
+	 */
2631
+	protected function _set_message_template_group()
2632
+	{
2633
+		// get out if this is already set.
2634
+		if (! empty($this->_message_template_group)) {
2635
+			return;
2636
+		}
2637
+
2638
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2639
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2640
+
2641
+		// let's get the message templates
2642
+		$this->_message_template_group = ! empty($GRP_ID)
2643
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2644
+			: $this->getMtgModel()->create_default_object();
2645
+
2646
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2647
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2648
+	}
2649
+
2650
+
2651
+	/**
2652
+	 * sets up a context switcher for edit forms
2653
+	 *
2654
+	 * @access  protected
2655
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2656
+	 * @param array                     $args                  various things the context switcher needs.
2657
+	 * @throws EE_Error
2658
+	 */
2659
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2660
+	{
2661
+		$context_details = $template_group_object->contexts_config();
2662
+		$context_label   = $template_group_object->context_label();
2663
+		ob_start();
2664
+		?>
2665 2665
         <div class="ee-msg-switcher-container">
2666 2666
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2667 2667
                 <?php
2668
-                foreach ($args as $name => $value) {
2669
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2670
-                        continue;
2671
-                    }
2672
-                    ?>
2668
+				foreach ($args as $name => $value) {
2669
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2670
+						continue;
2671
+					}
2672
+					?>
2673 2673
                     <input type="hidden"
2674 2674
                            name="<?php echo esc_attr($name); ?>"
2675 2675
                            value="<?php echo esc_attr($value); ?>"
2676 2676
                     />
2677 2677
                     <?php
2678
-                }
2679
-                // setup nonce_url
2680
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2681
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2682
-                ?>
2678
+				}
2679
+				// setup nonce_url
2680
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2681
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2682
+				?>
2683 2683
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2684 2684
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2685 2685
                 </label>
2686 2686
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2687 2687
                     <?php
2688
-                    $context_templates = $template_group_object->context_templates();
2689
-                    if (is_array($context_templates)) :
2690
-                        foreach ($context_templates as $context => $template_fields) :
2691
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2692
-                            ?>
2688
+					$context_templates = $template_group_object->context_templates();
2689
+					if (is_array($context_templates)) :
2690
+						foreach ($context_templates as $context => $template_fields) :
2691
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2692
+							?>
2693 2693
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2694 2694
                                 <?php echo $context_details[ $context ]['label']; // already escaped
2695
-                                ?>
2695
+								?>
2696 2696
                             </option>
2697 2697
                         <?php endforeach;
2698
-                    endif; ?>
2698
+					endif; ?>
2699 2699
                 </select>
2700 2700
                 <?php $button_text = sprintf(
2701
-                    esc_html__('Switch %s', 'event_espresso'),
2702
-                    ucwords($context_label['label'])
2703
-                ); ?>
2701
+					esc_html__('Switch %s', 'event_espresso'),
2702
+					ucwords($context_label['label'])
2703
+				); ?>
2704 2704
                 <input class='button-secondary'
2705 2705
                        id="submit-msg-context-switcher-sbmt"
2706 2706
                        type="submit"
@@ -2708,1989 +2708,1989 @@  discard block
 block discarded – undo
2708 2708
                 />
2709 2709
             </form>
2710 2710
             <?php echo $args['extra']; // already escaped
2711
-            ?>
2711
+			?>
2712 2712
         </div> <!-- end .ee-msg-switcher-container -->
2713 2713
         <?php
2714
-        $this->_context_switcher = ob_get_clean();
2715
-    }
2716
-
2717
-
2718
-    /**
2719
-     * @param bool $new
2720
-     * @throws EE_Error
2721
-     * @throws ReflectionException
2722
-     */
2723
-    protected function _insert_or_update_message_template($new = false)
2724
-    {
2725
-        $form_data    = $this->getMessageTemplateFormData();
2726
-        $GRP_ID       = $form_data['GRP_ID'];
2727
-        $messenger    = $form_data['MTP_messenger'];
2728
-        $message_type = $form_data['MTP_message_type'];
2729
-        $context      = $form_data['MTP_context'];
2730
-
2731
-        // if this is "new" then we need to generate the default contexts
2732
-        // for the selected messenger/message_type for user to edit.
2733
-        list($success, $query_args) = $new
2734
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2735
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2736
-
2737
-        $success     = $success ? 1 : 0;
2738
-        $action_desc = $new ? 'created' : 'updated';
2739
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2740
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2741
-
2742
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2743
-    }
2744
-
2745
-
2746
-    /**
2747
-     * retrieve and sanitize form data
2748
-     *
2749
-     * @return array
2750
-     * @since $VID:$
2751
-     */
2752
-    protected function getMessageTemplateFormData()
2753
-    {
2754
-        return [
2755
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2756
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2757
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2758
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2759
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2760
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2761
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2762
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2763
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2764
-        ];
2765
-    }
2766
-
2767
-
2768
-    /**
2769
-     * @param int    $GRP_ID
2770
-     * @param string $messenger
2771
-     * @param string $message_type
2772
-     * @return array no return on AJAX requests
2773
-     * @throws EE_Error
2774
-     * @throws ReflectionException
2775
-     * @since $VID:$
2776
-     */
2777
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2778
-    {
2779
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2780
-        $success       = ! empty($new_templates);
2781
-
2782
-        // we return things differently if doing ajax
2783
-        if ($this->request->isAjax()) {
2784
-            $this->_template_args['success'] = $success;
2785
-            $this->_template_args['error']   = ! $success;
2786
-            $this->_template_args['content'] = '';
2787
-            $this->_template_args['data']    = [
2788
-                'grpID'        => $new_templates['GRP_ID'],
2789
-                'templateName' => $new_templates['template_name'],
2790
-            ];
2791
-            if ($success) {
2792
-                EE_Error::overwrite_success();
2793
-                EE_Error::add_success(
2794
-                    esc_html__(
2795
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2796
-                        'event_espresso'
2797
-                    )
2798
-                );
2799
-            }
2800
-            $this->_return_json();
2801
-        }
2802
-        return [
2803
-            $success,
2804
-            // 'query_args'
2805
-            [
2806
-                'id'      => $new_templates['GRP_ID'],
2807
-                'context' => $new_templates['MTP_context'],
2808
-                'action'  => 'edit_message_template',
2809
-            ],
2810
-        ];
2811
-    }
2812
-
2813
-
2814
-    /**
2815
-     * @param int    $GRP_ID
2816
-     * @param string $messenger
2817
-     * @param string $message_type
2818
-     * @param string $context
2819
-     * @param array  $form_data
2820
-     * @return array
2821
-     * @throws EE_Error
2822
-     * @since $VID:$
2823
-     */
2824
-    private function updateExistingTemplates(
2825
-        $GRP_ID,
2826
-        $messenger,
2827
-        $message_type,
2828
-        $context,
2829
-        array $form_data
2830
-    ) {
2831
-        $success         = false;
2832
-        $template_fields = $this->getTemplateFields();
2833
-        if ($template_fields) {
2834
-            // if field data is valid, then success will be true
2835
-            $success = $this->validateTemplateFields(
2836
-                $messenger,
2837
-                $message_type,
2838
-                $context,
2839
-                $template_fields
2840
-            );
2841
-            if ($success) {
2842
-                $field_data = [];
2843
-                foreach ($template_fields as $template_field => $content) {
2844
-                    // combine top-level form data with content for this field
2845
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2846
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2847
-                }
2848
-                // we can use the last set_column_values for the MTPG update
2849
-                // (because its the same for all of these specific MTPs)
2850
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2851
-            }
2852
-        }
2853
-
2854
-        return [
2855
-            $success,
2856
-            // 'query_args'
2857
-            [
2858
-                'id'      => $GRP_ID,
2859
-                'context' => $context,
2860
-                'action'  => 'edit_message_template',
2861
-            ],
2862
-        ];
2863
-    }
2864
-
2865
-
2866
-    /**
2867
-     * @return array
2868
-     * @since $VID:$
2869
-     */
2870
-    private function getTemplateFields()
2871
-    {
2872
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2873
-        if (empty($template_fields)) {
2874
-            EE_Error::add_error(
2875
-                esc_html__(
2876
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2877
-                    'event_espresso'
2878
-                ),
2879
-                __FILE__,
2880
-                __FUNCTION__,
2881
-                __LINE__
2882
-            );
2883
-            return null;
2884
-        }
2885
-        // messages content is expected to be escaped
2886
-        return EEH_Array::addSlashesRecursively($template_fields);
2887
-    }
2888
-
2889
-
2890
-    /**
2891
-     * @param string $messenger
2892
-     * @param string $message_type
2893
-     * @param string $context
2894
-     * @param array  $template_fields
2895
-     * @return bool
2896
-     * @throws EE_Error
2897
-     * @since   $VID:$
2898
-     */
2899
-    private function validateTemplateFields(
2900
-        $messenger,
2901
-        $message_type,
2902
-        $context,
2903
-        array $template_fields
2904
-    ) {
2905
-        // first validate all fields!
2906
-        // this filter allows client code to add its own validation to the template fields as well.
2907
-        // returning an empty array means everything passed validation.
2908
-        // errors in validation should be represented in an array with the following shape:
2909
-        // array(
2910
-        //   'fieldname' => array(
2911
-        //          'msg' => 'error message'
2912
-        //          'value' => 'value for field producing error'
2913
-        // )
2914
-        $custom_validation = (array) apply_filters(
2915
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2916
-            [],
2917
-            $template_fields,
2918
-            $context,
2919
-            $messenger,
2920
-            $message_type
2921
-        );
2922
-
2923
-        $system_validation = $this->getMtgModel()->validate(
2924
-            $template_fields,
2925
-            $context,
2926
-            $messenger,
2927
-            $message_type
2928
-        );
2929
-
2930
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2931
-        $validates         = array_merge($custom_validation, $system_validation);
2932
-
2933
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2934
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2935
-        //  WE need to make sure there is no actual error messages in validates.
2936
-        if (empty($validates)) {
2937
-            return true;
2938
-        }
2939
-
2940
-        // add the transient so when the form loads we know which fields to highlight
2941
-        $this->_add_transient('edit_message_template', $validates);
2942
-        // setup notices
2943
-        foreach ($validates as $error) {
2944
-            if (isset($error['msg'])) {
2945
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2946
-            }
2947
-        }
2948
-        return false;
2949
-    }
2950
-
2951
-
2952
-    /**
2953
-     * @param array $field_data
2954
-     * @param array $form_data
2955
-     * @return array
2956
-     * @since   $VID:$
2957
-     */
2958
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2959
-    {
2960
-        return $form_data + [
2961
-                'MTP_ID'             => $field_data['MTP_ID'],
2962
-                'MTP_template_field' => $field_data['name'],
2963
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2964
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2965
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2966
-                    : $field_data['content'],
2967
-            ];
2968
-    }
2969
-
2970
-
2971
-    /**
2972
-     * @param string $template_field
2973
-     * @param array  $form_data
2974
-     * @return bool
2975
-     * @throws EE_Error
2976
-     * @since $VID:$
2977
-     */
2978
-    private function updateMessageTemplates($template_field, array $form_data)
2979
-    {
2980
-        $MTP_ID                  = $form_data['MTP_ID'];
2981
-        $message_template_fields = [
2982
-            'GRP_ID'             => $form_data['GRP_ID'],
2983
-            'MTP_template_field' => $form_data['MTP_template_field'],
2984
-            'MTP_context'        => $form_data['MTP_context'],
2985
-            'MTP_content'        => $form_data['MTP_content'],
2986
-        ];
2987
-
2988
-        $hasMtpID = ! empty($MTP_ID);
2989
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2990
-        // this has already been through the template field validator and sanitized, so it will be
2991
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2992
-        // message template field in a messenger/message type and existing users don't have the
2993
-        // default setup for it.
2994
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2995
-        $updated = $hasMtpID
2996
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2997
-            : $this->getMtpModel()->insert($message_template_fields);
2998
-
2999
-        $insert_failed = ! $hasMtpID && ! $updated;
3000
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
3001
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
3002
-        $update_failed = $hasMtpID && $updated === false;
3003
-
3004
-        if ($insert_failed || $update_failed) {
3005
-            EE_Error::add_error(
3006
-                sprintf(
3007
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
3008
-                    $template_field
3009
-                ),
3010
-                __FILE__,
3011
-                __FUNCTION__,
3012
-                __LINE__
3013
-            );
3014
-            return false;
3015
-        }
3016
-        return true;
3017
-    }
3018
-
3019
-
3020
-    /**
3021
-     * @param array $form_data
3022
-     * @return bool
3023
-     * @throws EE_Error
3024
-     * @since $VID:$
3025
-     */
3026
-    private function updateMessageTemplateGroup(array $form_data)
3027
-    {
3028
-        $GRP_ID  = $form_data['GRP_ID'];
3029
-        $updated = $this->getMtgModel()->update(
3030
-        // fields and values
3031
-            [
3032
-                'MTP_user_id'      => $form_data['MTP_user_id'],
3033
-                'MTP_messenger'    => $form_data['MTP_messenger'],
3034
-                'MTP_message_type' => $form_data['MTP_message_type'],
3035
-                'MTP_is_global'    => $form_data['MTP_is_global'],
3036
-                'MTP_is_override'  => $form_data['MTP_is_override'],
3037
-                'MTP_deleted'      => $form_data['MTP_deleted'],
3038
-                'MTP_is_active'    => $form_data['MTP_is_active'],
3039
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3040
-                'MTP_description'  => $this->request->getRequestParam(
3041
-                    'ee_msg_non_global_fields[MTP_description]',
3042
-                    ''
3043
-                ),
3044
-            ],
3045
-            // where
3046
-            [['GRP_ID' => $GRP_ID]]
3047
-        );
3048
-
3049
-        if ($updated === false) {
3050
-            EE_Error::add_error(
3051
-                sprintf(
3052
-                    esc_html__(
3053
-                        'The Message Template Group (%d) was NOT updated for some reason',
3054
-                        'event_espresso'
3055
-                    ),
3056
-                    $form_data['GRP_ID']
3057
-                ),
3058
-                __FILE__,
3059
-                __FUNCTION__,
3060
-                __LINE__
3061
-            );
3062
-            return false;
3063
-        }
3064
-        // k now we need to ensure the template_pack and template_variation fields are set.
3065
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3066
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3067
-
3068
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3069
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3070
-            $message_template_group->set_template_pack_name($template_pack);
3071
-            $message_template_group->set_template_pack_variation($template_variation);
3072
-        }
3073
-        return true;
3074
-    }
3075
-
3076
-
3077
-    /**
3078
-     * recursively runs wp_kses() on message template content in a model safe manner
3079
-     *
3080
-     * @param array|string $content
3081
-     * @return array|string
3082
-     * @since   $VID:$
3083
-     */
3084
-    private function sanitizeMessageTemplateContent($content)
3085
-    {
3086
-        if (is_array($content)) {
3087
-            foreach ($content as $key => $value) {
3088
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3089
-            }
3090
-            return $content;
3091
-        }
3092
-        // remove slashes so wp_kses() works properly
3093
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3094
-        // so attributes using single quotes always appear invalid.
3095
-        $content = stripslashes($content);
3096
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3097
-        // But currently the models expect slashed data, so after wp_kses()
3098
-        // runs we need to re-slash the data. Sheesh.
3099
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3100
-        return addslashes($content);
3101
-    }
3102
-
3103
-
3104
-    /**
3105
-     * @param string $messenger
3106
-     * @param string $message_type
3107
-     * @param string $context
3108
-     * @return string
3109
-     * @since $VID:$
3110
-     */
3111
-    private function generateUpdateDescription($messenger, $message_type, $context)
3112
-    {
3113
-        // need the message type and messenger objects to be able to use the labels for the notices
3114
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3115
-        $messenger_label  = $messenger_object instanceof EE_messenger
3116
-            ? ucwords($messenger_object->label['singular'])
3117
-            : '';
3118
-
3119
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3120
-        $message_type_label  = $message_type_object instanceof EE_message_type
3121
-            ? ucwords($message_type_object->label['singular'])
3122
-            : '';
3123
-
3124
-        $context   = ucwords(str_replace('_', ' ', $context));
3125
-        $item_desc = $messenger_label && $message_type_label
3126
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3127
-            : '';
3128
-        $item_desc .= 'Message Template';
3129
-        return $item_desc;
3130
-    }
3131
-
3132
-
3133
-    /**
3134
-     * @param string $messenger
3135
-     * @param string $message_type
3136
-     * @param string $context
3137
-     * @return bool
3138
-     * @throws EE_Error
3139
-     * @throws ReflectionException
3140
-     * @since $VID:$
3141
-     */
3142
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3143
-    {
3144
-        // was a test send triggered?
3145
-        if ($this->request->requestParamIsSet('test_button')) {
3146
-            EE_Error::overwrite_success();
3147
-            $this->_do_test_send($context, $messenger, $message_type);
3148
-            return true;
3149
-        }
3150
-        return false;
3151
-    }
3152
-
3153
-
3154
-    /**
3155
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3156
-     *
3157
-     * @param string $context      what context being tested
3158
-     * @param string $messenger    messenger being tested
3159
-     * @param string $message_type message type being tested
3160
-     * @throws EE_Error
3161
-     * @throws InvalidArgumentException
3162
-     * @throws InvalidDataTypeException
3163
-     * @throws InvalidInterfaceException
3164
-     * @throws ReflectionException
3165
-     */
3166
-    protected function _do_test_send($context, $messenger, $message_type)
3167
-    {
3168
-        // set things up for preview
3169
-        $this->request->setRequestParam('messenger', $messenger);
3170
-        $this->request->setRequestParam('message_type', $message_type);
3171
-        $this->request->setRequestParam('context', $context);
3172
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3173
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3174
-
3175
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3176
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3177
-
3178
-        // let's save any existing fields that might be required by the messenger
3179
-        if (
3180
-            ! empty($test_settings_fld)
3181
-            && $active_messenger instanceof EE_messenger
3182
-            && apply_filters(
3183
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3184
-                true,
3185
-                $test_settings_fld,
3186
-                $active_messenger
3187
-            )
3188
-        ) {
3189
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3190
-        }
3191
-
3192
-        /**
3193
-         * Use filter to add additional controls on whether message can send or not
3194
-         */
3195
-        if (
3196
-            apply_filters(
3197
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3198
-                true,
3199
-                $context,
3200
-                $this->request->requestParams(),
3201
-                $messenger,
3202
-                $message_type
3203
-            )
3204
-        ) {
3205
-            if (EEM_Event::instance()->count() > 0) {
3206
-                $success = $this->_preview_message(true);
3207
-                if ($success) {
3208
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3209
-                } else {
3210
-                    EE_Error::add_error(
3211
-                        esc_html__('The test message was not sent', 'event_espresso'),
3212
-                        __FILE__,
3213
-                        __FUNCTION__,
3214
-                        __LINE__
3215
-                    );
3216
-                }
3217
-            } else {
3218
-                $this->noEventsErrorMessage(true);
3219
-            }
3220
-        }
3221
-    }
3222
-
3223
-
3224
-    /**
3225
-     * _generate_new_templates
3226
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3227
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3228
-     * for the event.
3229
-     *
3230
-     *
3231
-     * @param string $messenger      the messenger we are generating templates for
3232
-     * @param array  $message_types  array of message types that the templates are generated for.
3233
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3234
-     *                               indicate the message_template_group being used as the base.
3235
-     *
3236
-     * @param bool   $global
3237
-     *
3238
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3239
-     *                               encountering problems.
3240
-     * @throws EE_Error
3241
-     * @throws ReflectionException
3242
-     */
3243
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3244
-    {
3245
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3246
-        // just don't generate any templates.
3247
-        if (empty($message_types)) {
3248
-            return [];
3249
-        }
3250
-
3251
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3252
-        return $templates[0];
3253
-    }
3254
-
3255
-
3256
-    /**
3257
-     * [_trash_or_restore_message_template]
3258
-     *
3259
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3260
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3261
-     *                        an individual context (FALSE).
3262
-     * @return void
3263
-     * @throws EE_Error
3264
-     * @throws InvalidArgumentException
3265
-     * @throws InvalidDataTypeException
3266
-     * @throws InvalidInterfaceException
3267
-     */
3268
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3269
-    {
3270
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3271
-
3272
-        $success = 1;
3273
-
3274
-        // incoming GRP_IDs
3275
-        if ($all) {
3276
-            // Checkboxes
3277
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3278
-            if (! empty($checkboxes)) {
3279
-                // if array has more than one element then success message should be plural.
3280
-                // todo: what about nonce?
3281
-                $success = count($checkboxes) > 1 ? 2 : 1;
3282
-
3283
-                // cycle through checkboxes
3284
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3285
-                    $trashed_or_restored = $trash
3286
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3287
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3288
-                    if (! $trashed_or_restored) {
3289
-                        $success = 0;
3290
-                    }
3291
-                }
3292
-            } else {
3293
-                // grab single GRP_ID and handle
3294
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3295
-                if (! empty($GRP_ID)) {
3296
-                    $trashed_or_restored = $trash
3297
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3298
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3299
-                    if (! $trashed_or_restored) {
3300
-                        $success = 0;
3301
-                    }
3302
-                } else {
3303
-                    $success = 0;
3304
-                }
3305
-            }
3306
-        }
3307
-
3308
-        $action_desc = $trash
3309
-            ? esc_html__('moved to the trash', 'event_espresso')
3310
-            : esc_html__('restored', 'event_espresso');
3311
-
3312
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3313
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3314
-
3315
-        $item_desc = $all ? _n(
3316
-            'Message Template Group',
3317
-            'Message Template Groups',
3318
-            $success,
3319
-            'event_espresso'
3320
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3321
-
3322
-        $item_desc = $template_switch
3323
-            ? _n('template', 'templates', $success, 'event_espresso')
3324
-            : $item_desc;
3325
-
3326
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3327
-    }
3328
-
3329
-
3330
-    /**
3331
-     * [_delete_message_template]
3332
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3333
-     *
3334
-     * @return void
3335
-     * @throws EE_Error
3336
-     * @throws InvalidArgumentException
3337
-     * @throws InvalidDataTypeException
3338
-     * @throws InvalidInterfaceException
3339
-     * @throws ReflectionException
3340
-     */
3341
-    protected function _delete_message_template()
3342
-    {
3343
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3344
-
3345
-        // checkboxes
3346
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3347
-        if (! empty($checkboxes)) {
3348
-            // if array has more than one element then success message should be plural
3349
-            $success = count($checkboxes) > 1 ? 2 : 1;
3350
-
3351
-            // cycle through bulk action checkboxes
3352
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3353
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3354
-            }
3355
-        } else {
3356
-            // grab single grp_id and delete
3357
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3358
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3359
-        }
3360
-
3361
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3362
-    }
3363
-
3364
-
3365
-    /**
3366
-     * helper for permanently deleting a mtP group and all related message_templates
3367
-     *
3368
-     * @param int  $GRP_ID        The group being deleted
3369
-     * @param bool $include_group whether to delete the Message Template Group as well.
3370
-     * @return bool boolean to indicate the success of the deletes or not.
3371
-     * @throws EE_Error
3372
-     * @throws InvalidArgumentException
3373
-     * @throws InvalidDataTypeException
3374
-     * @throws InvalidInterfaceException
3375
-     * @throws ReflectionException
3376
-     * @throws ReflectionException
3377
-     */
3378
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3379
-    {
3380
-        $success = true;
3381
-        // first let's GET this group
3382
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3383
-        // then delete permanently all the related Message Templates
3384
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3385
-
3386
-        if ($deleted === 0) {
3387
-            $success = false;
3388
-        }
3389
-
3390
-        // now delete permanently this particular group
3391
-
3392
-        if ($include_group && ! $MTG->delete_permanently()) {
3393
-            $success = false;
3394
-        }
3395
-
3396
-        return $success;
3397
-    }
3398
-
3399
-
3400
-    /**
3401
-     *    _learn_more_about_message_templates_link
3402
-     *
3403
-     * @access protected
3404
-     * @return string
3405
-     */
3406
-    protected function _learn_more_about_message_templates_link()
3407
-    {
3408
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3409
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3410
-               . '</a>';
3411
-    }
3412
-
3413
-
3414
-    /**
3415
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3416
-     * ajax and other routes.
3417
-     *
3418
-     * @return void
3419
-     * @throws DomainException
3420
-     * @throws EE_Error
3421
-     */
3422
-    protected function _settings()
3423
-    {
3424
-        $this->_set_m_mt_settings();
3425
-
3426
-        // let's setup the messenger tabs
3427
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3428
-            $this->_m_mt_settings['messenger_tabs'],
3429
-            'messenger_links',
3430
-            '|',
3431
-            $this->request->getRequestParam('selected_messenger', 'email')
3432
-        );
3433
-
3434
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3435
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3436
-
3437
-        $this->display_admin_page_with_sidebar();
3438
-    }
3439
-
3440
-
3441
-    /**
3442
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3443
-     *
3444
-     * @access protected
3445
-     * @return void
3446
-     * @throws DomainException
3447
-     */
3448
-    protected function _set_m_mt_settings()
3449
-    {
3450
-        // first if this is already set then lets get out no need to regenerate data.
3451
-        if (! empty($this->_m_mt_settings)) {
3452
-            return;
3453
-        }
3454
-
3455
-        // get all installed messengers and message_types
3456
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3457
-        $message_types = $this->_message_resource_manager->installed_message_types();
3458
-
3459
-
3460
-        // assemble the array for the _tab_text_links helper
3461
-
3462
-        foreach ($messengers as $messenger) {
3463
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3464
-                'label' => ucwords($messenger->label['singular']),
3465
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3466
-                    ? 'messenger-active'
3467
-                    : '',
3468
-                'href'  => $messenger->name,
3469
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3470
-                'slug'  => $messenger->name,
3471
-                'obj'   => $messenger,
3472
-            ];
3473
-
3474
-
3475
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3476
-
3477
-            foreach ($message_types as $message_type) {
3478
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3479
-                // it shouldn't show in either the inactive OR active metabox.
3480
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3481
-                    continue;
3482
-                }
3483
-
3484
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3485
-                    $messenger->name,
3486
-                    $message_type->name
3487
-                )
3488
-                    ? 'active'
3489
-                    : 'inactive';
3490
-
3491
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3492
-                    'label'    => ucwords($message_type->label['singular']),
3493
-                    'class'    => 'message-type-' . $a_or_i,
3494
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3495
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3496
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3497
-                    'title'    => $a_or_i === 'active'
3498
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3499
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3500
-                    'content'  => $a_or_i === 'active'
3501
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3502
-                        : $this->_message_type_settings_content($message_type, $messenger),
3503
-                    'slug'     => $message_type->name,
3504
-                    'active'   => $a_or_i === 'active',
3505
-                    'obj'      => $message_type,
3506
-                ];
3507
-            }
3508
-        }
3509
-    }
3510
-
3511
-
3512
-    /**
3513
-     * This just prepares the content for the message type settings
3514
-     *
3515
-     * @param EE_message_type $message_type The message type object
3516
-     * @param EE_messenger    $messenger    The messenger object
3517
-     * @param boolean         $active       Whether the message type is active or not
3518
-     * @return string html output for the content
3519
-     * @throws DomainException
3520
-     */
3521
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3522
-    {
3523
-        // get message type fields
3524
-        $fields                                         = $message_type->get_admin_settings_fields();
3525
-        $settings_template_args['template_form_fields'] = '';
3526
-
3527
-        if (! empty($fields) && $active) {
3528
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3529
-            foreach ($fields as $fldname => $fldprops) {
3530
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3531
-                $template_form_field[ $field_id ] = [
3532
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3533
-                    'label'      => $fldprops['label'],
3534
-                    'input'      => $fldprops['field_type'],
3535
-                    'type'       => $fldprops['value_type'],
3536
-                    'required'   => $fldprops['required'],
3537
-                    'validation' => $fldprops['validation'],
3538
-                    'value'      => isset($existing_settings[ $fldname ])
3539
-                        ? $existing_settings[ $fldname ]
3540
-                        : $fldprops['default'],
3541
-                    'options'    => isset($fldprops['options'])
3542
-                        ? $fldprops['options']
3543
-                        : [],
3544
-                    'default'    => isset($existing_settings[ $fldname ])
3545
-                        ? $existing_settings[ $fldname ]
3546
-                        : $fldprops['default'],
3547
-                    'css_class'  => 'no-drag',
3548
-                    'format'     => $fldprops['format'],
3549
-                ];
3550
-            }
3551
-
3552
-
3553
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3554
-                ? $this->_generate_admin_form_fields(
3555
-                    $template_form_field,
3556
-                    'string',
3557
-                    'ee_mt_activate_form'
3558
-                )
3559
-                : '';
3560
-        }
3561
-
3562
-        $settings_template_args['description'] = $message_type->description;
3563
-        // we also need some hidden fields
3564
-        $hidden_fields = [
3565
-            'message_type_settings[messenger]' . $message_type->name    => [
3566
-                'type'  => 'hidden',
3567
-                'value' => $messenger->name,
3568
-            ],
3569
-            'message_type_settings[message_type]' . $message_type->name => [
3570
-                'type'  => 'hidden',
3571
-                'value' => $message_type->name,
3572
-            ],
3573
-            'type' . $message_type->name                                => [
3574
-                'type'  => 'hidden',
3575
-                'value' => 'message_type',
3576
-            ],
3577
-        ];
3578
-
3579
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3580
-            $hidden_fields,
3581
-            'array'
3582
-        );
3583
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3584
-            ? ' hidden'
3585
-            : '';
3586
-
3587
-
3588
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3589
-        return EEH_Template::display_template($template, $settings_template_args, true);
3590
-    }
3591
-
3592
-
3593
-    /**
3594
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3595
-     *
3596
-     * @access protected
3597
-     * @return void
3598
-     * @throws DomainException
3599
-     */
3600
-    protected function _messages_settings_metaboxes()
3601
-    {
3602
-        $this->_set_m_mt_settings();
3603
-        $m_boxes         = $mt_boxes = [];
3604
-        $m_template_args = $mt_template_args = [];
3605
-
3606
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3607
-
3608
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3609
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3610
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3611
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3612
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3613
-
3614
-                // messenger meta boxes
3615
-                $active         = $selected_messenger === $messenger;
3616
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3617
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3618
-                    : '';
3619
-
3620
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3621
-                    esc_html__('%s Settings', 'event_espresso'),
3622
-                    $tab_array['label']
3623
-                );
3624
-
3625
-                $m_template_args[ $messenger . '_a_box' ] = [
3626
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3627
-                    'inactive_message_types' => isset(
3628
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3629
-                    )
3630
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3631
-                        : '',
3632
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3633
-                    'hidden'                 => $active ? '' : ' hidden',
3634
-                    'hide_on_message'        => $hide_on_message,
3635
-                    'messenger'              => $messenger,
3636
-                    'active'                 => $active,
3637
-                ];
3638
-
3639
-                // message type meta boxes
3640
-                // (which is really just the inactive container for each messenger
3641
-                // showing inactive message types for that messenger)
3642
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3643
-                $mt_template_args[ $messenger . '_i_box' ] = [
3644
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3645
-                    'inactive_message_types' => isset(
3646
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3647
-                    )
3648
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3649
-                        : '',
3650
-                    'hidden'                 => $active ? '' : ' hidden',
3651
-                    'hide_on_message'        => $hide_on_message,
3652
-                    'hide_off_message'       => $hide_off_message,
3653
-                    'messenger'              => $messenger,
3654
-                    'active'                 => $active,
3655
-                ];
3656
-            }
3657
-        }
3658
-
3659
-
3660
-        // register messenger metaboxes
3661
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3662
-        foreach ($m_boxes as $box => $label) {
3663
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3664
-            $msgr          = str_replace('_a_box', '', $box);
3665
-            add_meta_box(
3666
-                'espresso_' . $msgr . '_settings',
3667
-                $label,
3668
-                function ($post, $metabox) {
3669
-                    EEH_Template::display_template(
3670
-                        $metabox['args']['template_path'],
3671
-                        $metabox['args']['template_args']
3672
-                    );
3673
-                },
3674
-                $this->_current_screen->id,
3675
-                'normal',
3676
-                'high',
3677
-                $callback_args
3678
-            );
3679
-        }
3680
-
3681
-        // register message type metaboxes
3682
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3683
-        foreach ($mt_boxes as $box => $label) {
3684
-            $callback_args = [
3685
-                'template_path' => $mt_template_path,
3686
-                'template_args' => $mt_template_args[ $box ],
3687
-            ];
3688
-            $mt            = str_replace('_i_box', '', $box);
3689
-            add_meta_box(
3690
-                'espresso_' . $mt . '_inactive_mts',
3691
-                $label,
3692
-                function ($post, $metabox) {
3693
-                    EEH_Template::display_template(
3694
-                        $metabox['args']['template_path'],
3695
-                        $metabox['args']['template_args']
3696
-                    );
3697
-                },
3698
-                $this->_current_screen->id,
3699
-                'side',
3700
-                'high',
3701
-                $callback_args
3702
-            );
3703
-        }
3704
-
3705
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3706
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3707
-        if (is_main_site()) {
3708
-            add_meta_box(
3709
-                'espresso_global_message_settings',
3710
-                esc_html__('Global Message Settings', 'event_espresso'),
3711
-                [$this, 'global_messages_settings_metabox_content'],
3712
-                $this->_current_screen->id,
3713
-                'normal',
3714
-                'low',
3715
-                []
3716
-            );
3717
-        }
3718
-    }
3719
-
3720
-
3721
-    /**
3722
-     *  This generates the content for the global messages settings metabox.
3723
-     *
3724
-     * @return void
3725
-     * @throws EE_Error
3726
-     * @throws InvalidArgumentException
3727
-     * @throws ReflectionException
3728
-     * @throws InvalidDataTypeException
3729
-     * @throws InvalidInterfaceException
3730
-     */
3731
-    public function global_messages_settings_metabox_content()
3732
-    {
3733
-        $form = $this->_generate_global_settings_form();
3734
-        // already escaped
3735
-        echo $form->form_open(
3736
-            $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3737
-            'POST'
3738
-        );
3739
-        echo $form->get_html();
3740
-        echo $form->form_close();
3741
-    }
3742
-
3743
-
3744
-    /**
3745
-     * This generates and returns the form object for the global messages settings.
3746
-     *
3747
-     * @return EE_Form_Section_Proper
3748
-     * @throws EE_Error
3749
-     * @throws InvalidArgumentException
3750
-     * @throws ReflectionException
3751
-     * @throws InvalidDataTypeException
3752
-     * @throws InvalidInterfaceException
3753
-     */
3754
-    protected function _generate_global_settings_form()
3755
-    {
3756
-        /** @var EE_Network_Core_Config $network_config */
3757
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3758
-
3759
-        return new EE_Form_Section_Proper(
3760
-            [
3761
-                'name'            => 'global_messages_settings',
3762
-                'html_id'         => 'global_messages_settings',
3763
-                'html_class'      => 'form-table',
3764
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3765
-                'subsections'     => apply_filters(
3766
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3767
-                    [
3768
-                        'do_messages_on_same_request' => new EE_Select_Input(
3769
-                            [
3770
-                                true  => esc_html__('On the same request', 'event_espresso'),
3771
-                                false => esc_html__('On a separate request', 'event_espresso'),
3772
-                            ],
3773
-                            [
3774
-                                'default'         => $network_config->do_messages_on_same_request,
3775
-                                'html_label_text' => esc_html__(
3776
-                                    'Generate and send all messages:',
3777
-                                    'event_espresso'
3778
-                                ),
3779
-                                'html_help_text'  => esc_html__(
3780
-                                    '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.',
3781
-                                    'event_espresso'
3782
-                                ),
3783
-                            ]
3784
-                        ),
3785
-                        'delete_threshold'            => new EE_Select_Input(
3786
-                            [
3787
-                                0  => esc_html__('Forever', 'event_espresso'),
3788
-                                3  => esc_html__('3 Months', 'event_espresso'),
3789
-                                6  => esc_html__('6 Months', 'event_espresso'),
3790
-                                9  => esc_html__('9 Months', 'event_espresso'),
3791
-                                12 => esc_html__('12 Months', 'event_espresso'),
3792
-                                24 => esc_html__('24 Months', 'event_espresso'),
3793
-                                36 => esc_html__('36 Months', 'event_espresso'),
3794
-                            ],
3795
-                            [
3796
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3797
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3798
-                                'html_help_text'  => esc_html__(
3799
-                                    'You can control how long a record of processed messages is kept via this option.',
3800
-                                    'event_espresso'
3801
-                                ),
3802
-                            ]
3803
-                        ),
3804
-                        'update_settings'             => new EE_Submit_Input(
3805
-                            [
3806
-                                'default'         => esc_html__('Update', 'event_espresso'),
3807
-                                'html_label_text' => '&nbsp',
3808
-                            ]
3809
-                        ),
3810
-                    ]
3811
-                ),
3812
-            ]
3813
-        );
3814
-    }
3815
-
3816
-
3817
-    /**
3818
-     * This handles updating the global settings set on the admin page.
3819
-     *
3820
-     * @throws EE_Error
3821
-     * @throws InvalidDataTypeException
3822
-     * @throws InvalidInterfaceException
3823
-     * @throws InvalidArgumentException
3824
-     * @throws ReflectionException
3825
-     */
3826
-    protected function _update_global_settings()
3827
-    {
3828
-        /** @var EE_Network_Core_Config $network_config */
3829
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3830
-        $messages_config = EE_Registry::instance()->CFG->messages;
3831
-        $form            = $this->_generate_global_settings_form();
3832
-        if ($form->was_submitted()) {
3833
-            $form->receive_form_submission();
3834
-            if ($form->is_valid()) {
3835
-                $valid_data = $form->valid_data();
3836
-                foreach ($valid_data as $property => $value) {
3837
-                    $setter = 'set_' . $property;
3838
-                    if (method_exists($network_config, $setter)) {
3839
-                        $network_config->{$setter}($value);
3840
-                    } elseif (
3841
-                        property_exists($network_config, $property)
3842
-                        && $network_config->{$property} !== $value
3843
-                    ) {
3844
-                        $network_config->{$property} = $value;
3845
-                    } elseif (
3846
-                        property_exists($messages_config, $property)
3847
-                        && $messages_config->{$property} !== $value
3848
-                    ) {
3849
-                        $messages_config->{$property} = $value;
3850
-                    }
3851
-                }
3852
-                // only update if the form submission was valid!
3853
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3854
-                EE_Registry::instance()->CFG->update_espresso_config();
3855
-                EE_Error::overwrite_success();
3856
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3857
-            }
3858
-        }
3859
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3860
-    }
3861
-
3862
-
3863
-    /**
3864
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3865
-     *
3866
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3867
-     * @return string html formatted tabs
3868
-     * @throws DomainException
3869
-     */
3870
-    protected function _get_mt_tabs($tab_array)
3871
-    {
3872
-        $tab_array = (array) $tab_array;
3873
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3874
-        $tabs      = '';
3875
-
3876
-        foreach ($tab_array as $tab) {
3877
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3878
-        }
3879
-
3880
-        return $tabs;
3881
-    }
3882
-
3883
-
3884
-    /**
3885
-     * This prepares the content of the messenger meta box admin settings
3886
-     *
3887
-     * @param EE_messenger $messenger The messenger we're setting up content for
3888
-     * @return string html formatted content
3889
-     * @throws DomainException
3890
-     */
3891
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3892
-    {
3893
-
3894
-        $fields                                         = $messenger->get_admin_settings_fields();
3895
-        $settings_template_args['template_form_fields'] = '';
3896
-
3897
-        // is $messenger active?
3898
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3899
-
3900
-
3901
-        if (! empty($fields)) {
3902
-            $existing_settings = $messenger->get_existing_admin_settings();
3903
-
3904
-            foreach ($fields as $fldname => $fldprops) {
3905
-                $field_id                         = $messenger->name . '-' . $fldname;
3906
-                $template_form_field[ $field_id ] = [
3907
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3908
-                    'label'      => $fldprops['label'],
3909
-                    'input'      => $fldprops['field_type'],
3910
-                    'type'       => $fldprops['value_type'],
3911
-                    'required'   => $fldprops['required'],
3912
-                    'validation' => $fldprops['validation'],
3913
-                    'value'      => isset($existing_settings[ $field_id ])
3914
-                        ? $existing_settings[ $field_id ]
3915
-                        : $fldprops['default'],
3916
-                    'css_class'  => '',
3917
-                    'format'     => $fldprops['format'],
3918
-                ];
3919
-            }
3920
-
3921
-
3922
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3923
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3924
-                : '';
3925
-        }
3926
-
3927
-        // we also need some hidden fields
3928
-        $settings_template_args['hidden_fields'] = [
3929
-            'messenger_settings[messenger]' . $messenger->name => [
3930
-                'type'  => 'hidden',
3931
-                'value' => $messenger->name,
3932
-            ],
3933
-            'type' . $messenger->name                          => [
3934
-                'type'  => 'hidden',
3935
-                'value' => 'messenger',
3936
-            ],
3937
-        ];
3938
-
3939
-        // make sure any active message types that are existing are included in the hidden fields
3940
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3941
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3942
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3943
-                    'type'  => 'hidden',
3944
-                    'value' => $mt,
3945
-                ];
3946
-            }
3947
-        }
3948
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3949
-            $settings_template_args['hidden_fields'],
3950
-            'array'
3951
-        );
3952
-        $active                                  =
3953
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3954
-
3955
-        $settings_template_args['messenger']           = $messenger->name;
3956
-        $settings_template_args['description']         = $messenger->description;
3957
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3958
-
3959
-
3960
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3961
-            $messenger->name
3962
-        )
3963
-            ? $settings_template_args['show_hide_edit_form']
3964
-            : ' hidden';
3965
-
3966
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3967
-            ? ' hidden'
3968
-            : $settings_template_args['show_hide_edit_form'];
3969
-
3970
-
3971
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3972
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3973
-        $settings_template_args['on_off_status'] = $active;
3974
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3975
-        return EEH_Template::display_template(
3976
-            $template,
3977
-            $settings_template_args,
3978
-            true
3979
-        );
3980
-    }
3981
-
3982
-
3983
-    /**
3984
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3985
-     *
3986
-     * @throws DomainException
3987
-     * @throws EE_Error
3988
-     * @throws InvalidDataTypeException
3989
-     * @throws InvalidInterfaceException
3990
-     * @throws InvalidArgumentException
3991
-     * @throws ReflectionException
3992
-     */
3993
-    public function activate_messenger_toggle()
3994
-    {
3995
-        $success = true;
3996
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3997
-        // let's check that we have required data
3998
-
3999
-        if (! $this->_active_messenger_name) {
4000
-            EE_Error::add_error(
4001
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4002
-                __FILE__,
4003
-                __FUNCTION__,
4004
-                __LINE__
4005
-            );
4006
-            $success = false;
4007
-        }
4008
-
4009
-        // do a nonce check here since we're not arriving via a normal route
4010
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4011
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4012
-
4013
-        $this->_verify_nonce($nonce, $nonce_ref);
4014
-
4015
-
4016
-        $status = $this->request->getRequestParam('status');
4017
-        if (! $status) {
4018
-            EE_Error::add_error(
4019
-                esc_html__(
4020
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4021
-                    'event_espresso'
4022
-                ),
4023
-                __FILE__,
4024
-                __FUNCTION__,
4025
-                __LINE__
4026
-            );
4027
-            $success = false;
4028
-        }
4029
-
4030
-        // do check to verify we have a valid status.
4031
-        if ($status !== 'off' && $status !== 'on') {
4032
-            EE_Error::add_error(
4033
-                sprintf(
4034
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4035
-                    $status
4036
-                ),
4037
-                __FILE__,
4038
-                __FUNCTION__,
4039
-                __LINE__
4040
-            );
4041
-            $success = false;
4042
-        }
4043
-
4044
-        if ($success) {
4045
-            // made it here?  Stop dawdling then!!
4046
-            $success = $status === 'off'
4047
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4048
-                : $this->_activate_messenger($this->_active_messenger_name);
4049
-        }
4050
-
4051
-        $this->_template_args['success'] = $success;
4052
-
4053
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4054
-        $this->_return_json();
4055
-    }
4056
-
4057
-
4058
-    /**
4059
-     * used by ajax from the messages settings page to activate|deactivate a message type
4060
-     *
4061
-     * @throws DomainException
4062
-     * @throws EE_Error
4063
-     * @throws ReflectionException
4064
-     * @throws InvalidDataTypeException
4065
-     * @throws InvalidInterfaceException
4066
-     * @throws InvalidArgumentException
4067
-     */
4068
-    public function activate_mt_toggle()
4069
-    {
4070
-        $success = true;
4071
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4072
-
4073
-        // let's make sure we have the necessary data
4074
-        if (! $this->_active_message_type_name) {
4075
-            EE_Error::add_error(
4076
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4077
-                __FILE__,
4078
-                __FUNCTION__,
4079
-                __LINE__
4080
-            );
4081
-            $success = false;
4082
-        }
4083
-
4084
-        if (! $this->_active_messenger_name) {
4085
-            EE_Error::add_error(
4086
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4087
-                __FILE__,
4088
-                __FUNCTION__,
4089
-                __LINE__
4090
-            );
4091
-            $success = false;
4092
-        }
4093
-
4094
-        $status = $this->request->getRequestParam('status');
4095
-        if (! $status) {
4096
-            EE_Error::add_error(
4097
-                esc_html__(
4098
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4099
-                    'event_espresso'
4100
-                ),
4101
-                __FILE__,
4102
-                __FUNCTION__,
4103
-                __LINE__
4104
-            );
4105
-            $success = false;
4106
-        }
4107
-
4108
-
4109
-        // do check to verify we have a valid status.
4110
-        if ($status !== 'activate' && $status !== 'deactivate') {
4111
-            EE_Error::add_error(
4112
-                sprintf(
4113
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4114
-                    $status
4115
-                ),
4116
-                __FILE__,
4117
-                __FUNCTION__,
4118
-                __LINE__
4119
-            );
4120
-            $success = false;
4121
-        }
4122
-
4123
-
4124
-        // do a nonce check here since we're not arriving via a normal route
4125
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4126
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4127
-
4128
-        if ($success) {
4129
-            // made it here? um, what are you waiting for then?
4130
-            $success = $status === 'deactivate'
4131
-                ? $this->_deactivate_message_type_for_messenger(
4132
-                    $this->_active_messenger_name,
4133
-                    $this->_active_message_type_name
4134
-                )
4135
-                : $this->_activate_message_type_for_messenger(
4136
-                    $this->_active_messenger_name,
4137
-                    $this->_active_message_type_name
4138
-                );
4139
-        }
4140
-
4141
-        $this->_template_args['success'] = $success;
4142
-        $this->_return_json();
4143
-    }
4144
-
4145
-
4146
-    /**
4147
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4148
-     *
4149
-     * @param string $messenger_name The name of the messenger being activated
4150
-     * @return bool
4151
-     * @throws DomainException
4152
-     * @throws EE_Error
4153
-     * @throws InvalidArgumentException
4154
-     * @throws ReflectionException
4155
-     * @throws InvalidDataTypeException
4156
-     * @throws InvalidInterfaceException
4157
-     */
4158
-    protected function _activate_messenger($messenger_name)
4159
-    {
4160
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4161
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4162
-            ? $active_messenger->get_default_message_types()
4163
-            : [];
4164
-
4165
-        // ensure is active
4166
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4167
-
4168
-        // set response_data for reload
4169
-        foreach ($message_types_to_activate as $message_type_name) {
4170
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4171
-            if (
4172
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4173
-                    $messenger_name,
4174
-                    $message_type_name
4175
-                )
4176
-                && $message_type instanceof EE_message_type
4177
-            ) {
4178
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4179
-                if ($message_type->get_admin_settings_fields()) {
4180
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4181
-                }
4182
-            }
4183
-        }
4184
-
4185
-        // add success message for activating messenger
4186
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4187
-    }
4188
-
4189
-
4190
-    /**
4191
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4192
-     *
4193
-     * @param string $messenger_name The name of the messenger being activated
4194
-     * @return bool
4195
-     * @throws DomainException
4196
-     * @throws EE_Error
4197
-     * @throws InvalidArgumentException
4198
-     * @throws ReflectionException
4199
-     * @throws InvalidDataTypeException
4200
-     * @throws InvalidInterfaceException
4201
-     */
4202
-    protected function _deactivate_messenger($messenger_name)
4203
-    {
4204
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4205
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4206
-
4207
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4208
-    }
4209
-
4210
-
4211
-    /**
4212
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4213
-     *
4214
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4215
-     * @param string $message_type_name The name of the message type being activated for the messenger
4216
-     * @return bool
4217
-     * @throws DomainException
4218
-     * @throws EE_Error
4219
-     * @throws InvalidArgumentException
4220
-     * @throws ReflectionException
4221
-     * @throws InvalidDataTypeException
4222
-     * @throws InvalidInterfaceException
4223
-     */
4224
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4225
-    {
4226
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4227
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4228
-
4229
-        // ensure is active
4230
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4231
-
4232
-        // set response for load
4233
-        if (
4234
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4235
-                $messenger_name,
4236
-                $message_type_name
4237
-            )
4238
-        ) {
4239
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4240
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4241
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4242
-            }
4243
-        }
4244
-
4245
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4246
-            $active_messenger,
4247
-            $message_type_to_activate
4248
-        );
4249
-    }
4250
-
4251
-
4252
-    /**
4253
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4254
-     *
4255
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4256
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4257
-     * @return bool
4258
-     * @throws DomainException
4259
-     * @throws EE_Error
4260
-     * @throws InvalidArgumentException
4261
-     * @throws ReflectionException
4262
-     * @throws InvalidDataTypeException
4263
-     * @throws InvalidInterfaceException
4264
-     */
4265
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4266
-    {
4267
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4268
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4269
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4270
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4271
-
4272
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4273
-            $active_messenger,
4274
-            $message_type_to_deactivate
4275
-        );
4276
-    }
4277
-
4278
-
4279
-    /**
4280
-     * This just initializes the defaults for activating messenger and message type responses.
4281
-     */
4282
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4283
-    {
4284
-        $this->_template_args['data']['active_mts'] = [];
4285
-        $this->_template_args['data']['mt_reload']  = [];
4286
-    }
4287
-
4288
-
4289
-    /**
4290
-     * Setup appropriate response for activating a messenger and/or message types
4291
-     *
4292
-     * @param EE_messenger         $messenger
4293
-     * @param EE_message_type|null $message_type
4294
-     * @return bool
4295
-     * @throws DomainException
4296
-     * @throws EE_Error
4297
-     * @throws InvalidArgumentException
4298
-     * @throws ReflectionException
4299
-     * @throws InvalidDataTypeException
4300
-     * @throws InvalidInterfaceException
4301
-     */
4302
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4303
-        $messenger,
4304
-        EE_Message_Type $message_type = null
4305
-    ) {
4306
-        // if $messenger isn't a valid messenger object then get out.
4307
-        if (! $messenger instanceof EE_Messenger) {
4308
-            EE_Error::add_error(
4309
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4310
-                __FILE__,
4311
-                __FUNCTION__,
4312
-                __LINE__
4313
-            );
4314
-            return false;
4315
-        }
4316
-        // activated
4317
-        if ($this->_template_args['data']['active_mts']) {
4318
-            EE_Error::overwrite_success();
4319
-            // activated a message type with the messenger
4320
-            if ($message_type instanceof EE_message_type) {
4321
-                EE_Error::add_success(
4322
-                    sprintf(
4323
-                        esc_html__(
4324
-                            '%s message type has been successfully activated with the %s messenger',
4325
-                            'event_espresso'
4326
-                        ),
4327
-                        ucwords($message_type->label['singular']),
4328
-                        ucwords($messenger->label['singular'])
4329
-                    )
4330
-                );
4331
-
4332
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4333
-                if ($message_type->name === 'invoice') {
4334
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4335
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4336
-                    if ($pm instanceof EE_Payment_Method) {
4337
-                        EE_Error::add_attention(
4338
-                            esc_html__(
4339
-                                '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.',
4340
-                                'event_espresso'
4341
-                            )
4342
-                        );
4343
-                    }
4344
-                }
4345
-                // just toggles the entire messenger
4346
-            } else {
4347
-                EE_Error::add_success(
4348
-                    sprintf(
4349
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4350
-                        ucwords($messenger->label['singular'])
4351
-                    )
4352
-                );
4353
-            }
4354
-
4355
-            return true;
4356
-
4357
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4358
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4359
-            // in which case we just give a success message for the messenger being successfully activated.
4360
-        } else {
4361
-            if (! $messenger->get_default_message_types()) {
4362
-                // messenger doesn't have any default message types so still a success.
4363
-                EE_Error::add_success(
4364
-                    sprintf(
4365
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4366
-                        ucwords($messenger->label['singular'])
4367
-                    )
4368
-                );
4369
-
4370
-                return true;
4371
-            } else {
4372
-                EE_Error::add_error(
4373
-                    $message_type instanceof EE_message_type
4374
-                    ? sprintf(
4375
-                        esc_html__(
4376
-                            '%s message type was not successfully activated with the %s messenger',
4377
-                            'event_espresso'
4378
-                        ),
4379
-                        ucwords($message_type->label['singular']),
4380
-                        ucwords($messenger->label['singular'])
4381
-                    )
4382
-                    : sprintf(
4383
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4384
-                        ucwords($messenger->label['singular'])
4385
-                    ),
4386
-                    __FILE__,
4387
-                    __FUNCTION__,
4388
-                    __LINE__
4389
-                );
4390
-
4391
-                return false;
4392
-            }
4393
-        }
4394
-    }
4395
-
4396
-
4397
-    /**
4398
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4399
-     *
4400
-     * @param EE_messenger         $messenger
4401
-     * @param EE_message_type|null $message_type
4402
-     * @return bool
4403
-     * @throws DomainException
4404
-     * @throws EE_Error
4405
-     * @throws InvalidArgumentException
4406
-     * @throws ReflectionException
4407
-     * @throws InvalidDataTypeException
4408
-     * @throws InvalidInterfaceException
4409
-     */
4410
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4411
-        $messenger,
4412
-        EE_message_type $message_type = null
4413
-    ) {
4414
-        EE_Error::overwrite_success();
4415
-
4416
-        // if $messenger isn't a valid messenger object then get out.
4417
-        if (! $messenger instanceof EE_Messenger) {
4418
-            EE_Error::add_error(
4419
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4420
-                __FILE__,
4421
-                __FUNCTION__,
4422
-                __LINE__
4423
-            );
4424
-
4425
-            return false;
4426
-        }
4427
-
4428
-        if ($message_type instanceof EE_message_type) {
4429
-            $message_type_name = $message_type->name;
4430
-            EE_Error::add_success(
4431
-                sprintf(
4432
-                    esc_html__(
4433
-                        '%s message type has been successfully deactivated for the %s messenger.',
4434
-                        'event_espresso'
4435
-                    ),
4436
-                    ucwords($message_type->label['singular']),
4437
-                    ucwords($messenger->label['singular'])
4438
-                )
4439
-            );
4440
-        } else {
4441
-            $message_type_name = '';
4442
-            EE_Error::add_success(
4443
-                sprintf(
4444
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4445
-                    ucwords($messenger->label['singular'])
4446
-                )
4447
-            );
4448
-        }
4449
-
4450
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4451
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4452
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4453
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4454
-            if ($count_updated > 0) {
4455
-                $msg = $message_type_name === 'invoice'
4456
-                    ? esc_html__(
4457
-                        '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.',
4458
-                        'event_espresso'
4459
-                    )
4460
-                    : esc_html__(
4461
-                        '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.',
4462
-                        'event_espresso'
4463
-                    );
4464
-                EE_Error::add_attention($msg);
4465
-            }
4466
-        }
4467
-
4468
-        return true;
4469
-    }
4470
-
4471
-
4472
-    /**
4473
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4474
-     *
4475
-     * @throws DomainException
4476
-     * @throws EE_Error
4477
-     * @throws EE_Error
4478
-     */
4479
-    public function update_mt_form()
4480
-    {
4481
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4482
-            EE_Error::add_error(
4483
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4484
-                __FILE__,
4485
-                __FUNCTION__,
4486
-                __LINE__
4487
-            );
4488
-            $this->_return_json();
4489
-        }
4490
-
4491
-        $message_types = $this->get_installed_message_types();
4492
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4493
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4494
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4495
-
4496
-        $this->_template_args['success'] = true;
4497
-        $this->_template_args['content'] = $content;
4498
-        $this->_return_json();
4499
-    }
4500
-
4501
-
4502
-    /**
4503
-     * this handles saving the settings for a messenger or message type
4504
-     *
4505
-     * @throws EE_Error
4506
-     * @throws EE_Error
4507
-     */
4508
-    public function save_settings()
4509
-    {
4510
-        $type = $this->request->getRequestParam('type');
4511
-        if (! $type) {
4512
-            EE_Error::add_error(
4513
-                esc_html__(
4514
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4515
-                    'event_espresso'
4516
-                ),
4517
-                __FILE__,
4518
-                __FUNCTION__,
4519
-                __LINE__
4520
-            );
4521
-            $this->_template_args['error'] = true;
4522
-            $this->_return_json();
4523
-        }
4524
-
4525
-
4526
-        if ($type === 'messenger') {
4527
-            // this should be an array.
4528
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4529
-            $messenger = $settings['messenger'];
4530
-            // remove messenger and message_types from settings array
4531
-            unset($settings['messenger'], $settings['message_types']);
4532
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4533
-        } elseif ($type === 'message_type') {
4534
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4535
-            $messenger    = $settings['messenger'];
4536
-            $message_type = $settings['message_type'];
4537
-            // remove messenger and message_types from settings array
4538
-            unset($settings['messenger'], $settings['message_types']);
4539
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4540
-        }
4541
-
4542
-        // okay we should have the data all setup.  Now we just update!
4543
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4544
-
4545
-        if ($success) {
4546
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4547
-        } else {
4548
-            EE_Error::add_error(
4549
-                esc_html__('Settings did not get updated', 'event_espresso'),
4550
-                __FILE__,
4551
-                __FUNCTION__,
4552
-                __LINE__
4553
-            );
4554
-        }
4555
-
4556
-        $this->_template_args['success'] = $success;
4557
-        $this->_return_json();
4558
-    }
4559
-
4560
-
4561
-
4562
-
4563
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4564
-
4565
-
4566
-    /**
4567
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4568
-     * However, this does not send immediately, it just queues for sending.
4569
-     *
4570
-     * @throws EE_Error
4571
-     * @throws InvalidDataTypeException
4572
-     * @throws InvalidInterfaceException
4573
-     * @throws InvalidArgumentException
4574
-     * @throws ReflectionException
4575
-     * @since 4.9.0
4576
-     */
4577
-    protected function _generate_now()
4578
-    {
4579
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4580
-        $this->_redirect_after_action(false, '', '', [], true);
4581
-    }
4582
-
4583
-
4584
-    /**
4585
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4586
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4587
-     *
4588
-     * @throws EE_Error
4589
-     * @throws InvalidDataTypeException
4590
-     * @throws InvalidInterfaceException
4591
-     * @throws InvalidArgumentException
4592
-     * @throws ReflectionException
4593
-     * @since 4.9.0
4594
-     */
4595
-    protected function _generate_and_send_now()
4596
-    {
4597
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4598
-        $this->_redirect_after_action(false, '', '', [], true);
4599
-    }
4600
-
4601
-
4602
-    /**
4603
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4604
-     *
4605
-     * @throws EE_Error
4606
-     * @throws InvalidDataTypeException
4607
-     * @throws InvalidInterfaceException
4608
-     * @throws InvalidArgumentException
4609
-     * @throws ReflectionException
4610
-     * @since 4.9.0
4611
-     */
4612
-    protected function _queue_for_resending()
4613
-    {
4614
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4615
-        $this->_redirect_after_action(false, '', '', [], true);
4616
-    }
4617
-
4618
-
4619
-    /**
4620
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4621
-     *
4622
-     * @throws EE_Error
4623
-     * @throws InvalidDataTypeException
4624
-     * @throws InvalidInterfaceException
4625
-     * @throws InvalidArgumentException
4626
-     * @throws ReflectionException
4627
-     * @since 4.9.0
4628
-     */
4629
-    protected function _send_now()
4630
-    {
4631
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4632
-        $this->_redirect_after_action(false, '', '', [], true);
4633
-    }
4634
-
4635
-
4636
-    /**
4637
-     * Deletes EE_messages for IDs in the request.
4638
-     *
4639
-     * @throws EE_Error
4640
-     * @throws InvalidDataTypeException
4641
-     * @throws InvalidInterfaceException
4642
-     * @throws InvalidArgumentException
4643
-     * @since 4.9.0
4644
-     */
4645
-    protected function _delete_ee_messages()
4646
-    {
4647
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4648
-        $deleted_count = 0;
4649
-        foreach ($MSG_IDs as $MSG_ID) {
4650
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4651
-                $deleted_count++;
4652
-            }
4653
-        }
4654
-        if ($deleted_count) {
4655
-            EE_Error::add_success(
4656
-                esc_html(
4657
-                    _n(
4658
-                        'Message successfully deleted',
4659
-                        'Messages successfully deleted',
4660
-                        $deleted_count,
4661
-                        'event_espresso'
4662
-                    )
4663
-                )
4664
-            );
4665
-        } else {
4666
-            EE_Error::add_error(
4667
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4668
-                __FILE__,
4669
-                __FUNCTION__,
4670
-                __LINE__
4671
-            );
4672
-        }
4673
-        $this->_redirect_after_action(false, '', '', [], true);
4674
-    }
4675
-
4676
-
4677
-    /**
4678
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4679
-     *
4680
-     * @return array
4681
-     * @since 4.9.0
4682
-     */
4683
-    protected function _get_msg_ids_from_request()
4684
-    {
4685
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4686
-        if (empty($MSG_IDs)) {
4687
-            return [];
4688
-        }
4689
-        // if 'MSG_ID' was just a single ID (not an array)
4690
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4691
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4692
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4693
-            ? $MSG_IDs
4694
-            : array_keys($MSG_IDs);
4695
-    }
2714
+		$this->_context_switcher = ob_get_clean();
2715
+	}
2716
+
2717
+
2718
+	/**
2719
+	 * @param bool $new
2720
+	 * @throws EE_Error
2721
+	 * @throws ReflectionException
2722
+	 */
2723
+	protected function _insert_or_update_message_template($new = false)
2724
+	{
2725
+		$form_data    = $this->getMessageTemplateFormData();
2726
+		$GRP_ID       = $form_data['GRP_ID'];
2727
+		$messenger    = $form_data['MTP_messenger'];
2728
+		$message_type = $form_data['MTP_message_type'];
2729
+		$context      = $form_data['MTP_context'];
2730
+
2731
+		// if this is "new" then we need to generate the default contexts
2732
+		// for the selected messenger/message_type for user to edit.
2733
+		list($success, $query_args) = $new
2734
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2735
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2736
+
2737
+		$success     = $success ? 1 : 0;
2738
+		$action_desc = $new ? 'created' : 'updated';
2739
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2740
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2741
+
2742
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2743
+	}
2744
+
2745
+
2746
+	/**
2747
+	 * retrieve and sanitize form data
2748
+	 *
2749
+	 * @return array
2750
+	 * @since $VID:$
2751
+	 */
2752
+	protected function getMessageTemplateFormData()
2753
+	{
2754
+		return [
2755
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2756
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2757
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2758
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2759
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2760
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2761
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2762
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2763
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2764
+		];
2765
+	}
2766
+
2767
+
2768
+	/**
2769
+	 * @param int    $GRP_ID
2770
+	 * @param string $messenger
2771
+	 * @param string $message_type
2772
+	 * @return array no return on AJAX requests
2773
+	 * @throws EE_Error
2774
+	 * @throws ReflectionException
2775
+	 * @since $VID:$
2776
+	 */
2777
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2778
+	{
2779
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2780
+		$success       = ! empty($new_templates);
2781
+
2782
+		// we return things differently if doing ajax
2783
+		if ($this->request->isAjax()) {
2784
+			$this->_template_args['success'] = $success;
2785
+			$this->_template_args['error']   = ! $success;
2786
+			$this->_template_args['content'] = '';
2787
+			$this->_template_args['data']    = [
2788
+				'grpID'        => $new_templates['GRP_ID'],
2789
+				'templateName' => $new_templates['template_name'],
2790
+			];
2791
+			if ($success) {
2792
+				EE_Error::overwrite_success();
2793
+				EE_Error::add_success(
2794
+					esc_html__(
2795
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2796
+						'event_espresso'
2797
+					)
2798
+				);
2799
+			}
2800
+			$this->_return_json();
2801
+		}
2802
+		return [
2803
+			$success,
2804
+			// 'query_args'
2805
+			[
2806
+				'id'      => $new_templates['GRP_ID'],
2807
+				'context' => $new_templates['MTP_context'],
2808
+				'action'  => 'edit_message_template',
2809
+			],
2810
+		];
2811
+	}
2812
+
2813
+
2814
+	/**
2815
+	 * @param int    $GRP_ID
2816
+	 * @param string $messenger
2817
+	 * @param string $message_type
2818
+	 * @param string $context
2819
+	 * @param array  $form_data
2820
+	 * @return array
2821
+	 * @throws EE_Error
2822
+	 * @since $VID:$
2823
+	 */
2824
+	private function updateExistingTemplates(
2825
+		$GRP_ID,
2826
+		$messenger,
2827
+		$message_type,
2828
+		$context,
2829
+		array $form_data
2830
+	) {
2831
+		$success         = false;
2832
+		$template_fields = $this->getTemplateFields();
2833
+		if ($template_fields) {
2834
+			// if field data is valid, then success will be true
2835
+			$success = $this->validateTemplateFields(
2836
+				$messenger,
2837
+				$message_type,
2838
+				$context,
2839
+				$template_fields
2840
+			);
2841
+			if ($success) {
2842
+				$field_data = [];
2843
+				foreach ($template_fields as $template_field => $content) {
2844
+					// combine top-level form data with content for this field
2845
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2846
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2847
+				}
2848
+				// we can use the last set_column_values for the MTPG update
2849
+				// (because its the same for all of these specific MTPs)
2850
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2851
+			}
2852
+		}
2853
+
2854
+		return [
2855
+			$success,
2856
+			// 'query_args'
2857
+			[
2858
+				'id'      => $GRP_ID,
2859
+				'context' => $context,
2860
+				'action'  => 'edit_message_template',
2861
+			],
2862
+		];
2863
+	}
2864
+
2865
+
2866
+	/**
2867
+	 * @return array
2868
+	 * @since $VID:$
2869
+	 */
2870
+	private function getTemplateFields()
2871
+	{
2872
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2873
+		if (empty($template_fields)) {
2874
+			EE_Error::add_error(
2875
+				esc_html__(
2876
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2877
+					'event_espresso'
2878
+				),
2879
+				__FILE__,
2880
+				__FUNCTION__,
2881
+				__LINE__
2882
+			);
2883
+			return null;
2884
+		}
2885
+		// messages content is expected to be escaped
2886
+		return EEH_Array::addSlashesRecursively($template_fields);
2887
+	}
2888
+
2889
+
2890
+	/**
2891
+	 * @param string $messenger
2892
+	 * @param string $message_type
2893
+	 * @param string $context
2894
+	 * @param array  $template_fields
2895
+	 * @return bool
2896
+	 * @throws EE_Error
2897
+	 * @since   $VID:$
2898
+	 */
2899
+	private function validateTemplateFields(
2900
+		$messenger,
2901
+		$message_type,
2902
+		$context,
2903
+		array $template_fields
2904
+	) {
2905
+		// first validate all fields!
2906
+		// this filter allows client code to add its own validation to the template fields as well.
2907
+		// returning an empty array means everything passed validation.
2908
+		// errors in validation should be represented in an array with the following shape:
2909
+		// array(
2910
+		//   'fieldname' => array(
2911
+		//          'msg' => 'error message'
2912
+		//          'value' => 'value for field producing error'
2913
+		// )
2914
+		$custom_validation = (array) apply_filters(
2915
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2916
+			[],
2917
+			$template_fields,
2918
+			$context,
2919
+			$messenger,
2920
+			$message_type
2921
+		);
2922
+
2923
+		$system_validation = $this->getMtgModel()->validate(
2924
+			$template_fields,
2925
+			$context,
2926
+			$messenger,
2927
+			$message_type
2928
+		);
2929
+
2930
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2931
+		$validates         = array_merge($custom_validation, $system_validation);
2932
+
2933
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2934
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2935
+		//  WE need to make sure there is no actual error messages in validates.
2936
+		if (empty($validates)) {
2937
+			return true;
2938
+		}
2939
+
2940
+		// add the transient so when the form loads we know which fields to highlight
2941
+		$this->_add_transient('edit_message_template', $validates);
2942
+		// setup notices
2943
+		foreach ($validates as $error) {
2944
+			if (isset($error['msg'])) {
2945
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2946
+			}
2947
+		}
2948
+		return false;
2949
+	}
2950
+
2951
+
2952
+	/**
2953
+	 * @param array $field_data
2954
+	 * @param array $form_data
2955
+	 * @return array
2956
+	 * @since   $VID:$
2957
+	 */
2958
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2959
+	{
2960
+		return $form_data + [
2961
+				'MTP_ID'             => $field_data['MTP_ID'],
2962
+				'MTP_template_field' => $field_data['name'],
2963
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2964
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2965
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2966
+					: $field_data['content'],
2967
+			];
2968
+	}
2969
+
2970
+
2971
+	/**
2972
+	 * @param string $template_field
2973
+	 * @param array  $form_data
2974
+	 * @return bool
2975
+	 * @throws EE_Error
2976
+	 * @since $VID:$
2977
+	 */
2978
+	private function updateMessageTemplates($template_field, array $form_data)
2979
+	{
2980
+		$MTP_ID                  = $form_data['MTP_ID'];
2981
+		$message_template_fields = [
2982
+			'GRP_ID'             => $form_data['GRP_ID'],
2983
+			'MTP_template_field' => $form_data['MTP_template_field'],
2984
+			'MTP_context'        => $form_data['MTP_context'],
2985
+			'MTP_content'        => $form_data['MTP_content'],
2986
+		];
2987
+
2988
+		$hasMtpID = ! empty($MTP_ID);
2989
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2990
+		// this has already been through the template field validator and sanitized, so it will be
2991
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2992
+		// message template field in a messenger/message type and existing users don't have the
2993
+		// default setup for it.
2994
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2995
+		$updated = $hasMtpID
2996
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2997
+			: $this->getMtpModel()->insert($message_template_fields);
2998
+
2999
+		$insert_failed = ! $hasMtpID && ! $updated;
3000
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
3001
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
3002
+		$update_failed = $hasMtpID && $updated === false;
3003
+
3004
+		if ($insert_failed || $update_failed) {
3005
+			EE_Error::add_error(
3006
+				sprintf(
3007
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
3008
+					$template_field
3009
+				),
3010
+				__FILE__,
3011
+				__FUNCTION__,
3012
+				__LINE__
3013
+			);
3014
+			return false;
3015
+		}
3016
+		return true;
3017
+	}
3018
+
3019
+
3020
+	/**
3021
+	 * @param array $form_data
3022
+	 * @return bool
3023
+	 * @throws EE_Error
3024
+	 * @since $VID:$
3025
+	 */
3026
+	private function updateMessageTemplateGroup(array $form_data)
3027
+	{
3028
+		$GRP_ID  = $form_data['GRP_ID'];
3029
+		$updated = $this->getMtgModel()->update(
3030
+		// fields and values
3031
+			[
3032
+				'MTP_user_id'      => $form_data['MTP_user_id'],
3033
+				'MTP_messenger'    => $form_data['MTP_messenger'],
3034
+				'MTP_message_type' => $form_data['MTP_message_type'],
3035
+				'MTP_is_global'    => $form_data['MTP_is_global'],
3036
+				'MTP_is_override'  => $form_data['MTP_is_override'],
3037
+				'MTP_deleted'      => $form_data['MTP_deleted'],
3038
+				'MTP_is_active'    => $form_data['MTP_is_active'],
3039
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3040
+				'MTP_description'  => $this->request->getRequestParam(
3041
+					'ee_msg_non_global_fields[MTP_description]',
3042
+					''
3043
+				),
3044
+			],
3045
+			// where
3046
+			[['GRP_ID' => $GRP_ID]]
3047
+		);
3048
+
3049
+		if ($updated === false) {
3050
+			EE_Error::add_error(
3051
+				sprintf(
3052
+					esc_html__(
3053
+						'The Message Template Group (%d) was NOT updated for some reason',
3054
+						'event_espresso'
3055
+					),
3056
+					$form_data['GRP_ID']
3057
+				),
3058
+				__FILE__,
3059
+				__FUNCTION__,
3060
+				__LINE__
3061
+			);
3062
+			return false;
3063
+		}
3064
+		// k now we need to ensure the template_pack and template_variation fields are set.
3065
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3066
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3067
+
3068
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3069
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3070
+			$message_template_group->set_template_pack_name($template_pack);
3071
+			$message_template_group->set_template_pack_variation($template_variation);
3072
+		}
3073
+		return true;
3074
+	}
3075
+
3076
+
3077
+	/**
3078
+	 * recursively runs wp_kses() on message template content in a model safe manner
3079
+	 *
3080
+	 * @param array|string $content
3081
+	 * @return array|string
3082
+	 * @since   $VID:$
3083
+	 */
3084
+	private function sanitizeMessageTemplateContent($content)
3085
+	{
3086
+		if (is_array($content)) {
3087
+			foreach ($content as $key => $value) {
3088
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3089
+			}
3090
+			return $content;
3091
+		}
3092
+		// remove slashes so wp_kses() works properly
3093
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3094
+		// so attributes using single quotes always appear invalid.
3095
+		$content = stripslashes($content);
3096
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3097
+		// But currently the models expect slashed data, so after wp_kses()
3098
+		// runs we need to re-slash the data. Sheesh.
3099
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3100
+		return addslashes($content);
3101
+	}
3102
+
3103
+
3104
+	/**
3105
+	 * @param string $messenger
3106
+	 * @param string $message_type
3107
+	 * @param string $context
3108
+	 * @return string
3109
+	 * @since $VID:$
3110
+	 */
3111
+	private function generateUpdateDescription($messenger, $message_type, $context)
3112
+	{
3113
+		// need the message type and messenger objects to be able to use the labels for the notices
3114
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3115
+		$messenger_label  = $messenger_object instanceof EE_messenger
3116
+			? ucwords($messenger_object->label['singular'])
3117
+			: '';
3118
+
3119
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3120
+		$message_type_label  = $message_type_object instanceof EE_message_type
3121
+			? ucwords($message_type_object->label['singular'])
3122
+			: '';
3123
+
3124
+		$context   = ucwords(str_replace('_', ' ', $context));
3125
+		$item_desc = $messenger_label && $message_type_label
3126
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3127
+			: '';
3128
+		$item_desc .= 'Message Template';
3129
+		return $item_desc;
3130
+	}
3131
+
3132
+
3133
+	/**
3134
+	 * @param string $messenger
3135
+	 * @param string $message_type
3136
+	 * @param string $context
3137
+	 * @return bool
3138
+	 * @throws EE_Error
3139
+	 * @throws ReflectionException
3140
+	 * @since $VID:$
3141
+	 */
3142
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3143
+	{
3144
+		// was a test send triggered?
3145
+		if ($this->request->requestParamIsSet('test_button')) {
3146
+			EE_Error::overwrite_success();
3147
+			$this->_do_test_send($context, $messenger, $message_type);
3148
+			return true;
3149
+		}
3150
+		return false;
3151
+	}
3152
+
3153
+
3154
+	/**
3155
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3156
+	 *
3157
+	 * @param string $context      what context being tested
3158
+	 * @param string $messenger    messenger being tested
3159
+	 * @param string $message_type message type being tested
3160
+	 * @throws EE_Error
3161
+	 * @throws InvalidArgumentException
3162
+	 * @throws InvalidDataTypeException
3163
+	 * @throws InvalidInterfaceException
3164
+	 * @throws ReflectionException
3165
+	 */
3166
+	protected function _do_test_send($context, $messenger, $message_type)
3167
+	{
3168
+		// set things up for preview
3169
+		$this->request->setRequestParam('messenger', $messenger);
3170
+		$this->request->setRequestParam('message_type', $message_type);
3171
+		$this->request->setRequestParam('context', $context);
3172
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3173
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3174
+
3175
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3176
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3177
+
3178
+		// let's save any existing fields that might be required by the messenger
3179
+		if (
3180
+			! empty($test_settings_fld)
3181
+			&& $active_messenger instanceof EE_messenger
3182
+			&& apply_filters(
3183
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3184
+				true,
3185
+				$test_settings_fld,
3186
+				$active_messenger
3187
+			)
3188
+		) {
3189
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3190
+		}
3191
+
3192
+		/**
3193
+		 * Use filter to add additional controls on whether message can send or not
3194
+		 */
3195
+		if (
3196
+			apply_filters(
3197
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3198
+				true,
3199
+				$context,
3200
+				$this->request->requestParams(),
3201
+				$messenger,
3202
+				$message_type
3203
+			)
3204
+		) {
3205
+			if (EEM_Event::instance()->count() > 0) {
3206
+				$success = $this->_preview_message(true);
3207
+				if ($success) {
3208
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3209
+				} else {
3210
+					EE_Error::add_error(
3211
+						esc_html__('The test message was not sent', 'event_espresso'),
3212
+						__FILE__,
3213
+						__FUNCTION__,
3214
+						__LINE__
3215
+					);
3216
+				}
3217
+			} else {
3218
+				$this->noEventsErrorMessage(true);
3219
+			}
3220
+		}
3221
+	}
3222
+
3223
+
3224
+	/**
3225
+	 * _generate_new_templates
3226
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3227
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3228
+	 * for the event.
3229
+	 *
3230
+	 *
3231
+	 * @param string $messenger      the messenger we are generating templates for
3232
+	 * @param array  $message_types  array of message types that the templates are generated for.
3233
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3234
+	 *                               indicate the message_template_group being used as the base.
3235
+	 *
3236
+	 * @param bool   $global
3237
+	 *
3238
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3239
+	 *                               encountering problems.
3240
+	 * @throws EE_Error
3241
+	 * @throws ReflectionException
3242
+	 */
3243
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3244
+	{
3245
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3246
+		// just don't generate any templates.
3247
+		if (empty($message_types)) {
3248
+			return [];
3249
+		}
3250
+
3251
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3252
+		return $templates[0];
3253
+	}
3254
+
3255
+
3256
+	/**
3257
+	 * [_trash_or_restore_message_template]
3258
+	 *
3259
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3260
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3261
+	 *                        an individual context (FALSE).
3262
+	 * @return void
3263
+	 * @throws EE_Error
3264
+	 * @throws InvalidArgumentException
3265
+	 * @throws InvalidDataTypeException
3266
+	 * @throws InvalidInterfaceException
3267
+	 */
3268
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3269
+	{
3270
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3271
+
3272
+		$success = 1;
3273
+
3274
+		// incoming GRP_IDs
3275
+		if ($all) {
3276
+			// Checkboxes
3277
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3278
+			if (! empty($checkboxes)) {
3279
+				// if array has more than one element then success message should be plural.
3280
+				// todo: what about nonce?
3281
+				$success = count($checkboxes) > 1 ? 2 : 1;
3282
+
3283
+				// cycle through checkboxes
3284
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3285
+					$trashed_or_restored = $trash
3286
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3287
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3288
+					if (! $trashed_or_restored) {
3289
+						$success = 0;
3290
+					}
3291
+				}
3292
+			} else {
3293
+				// grab single GRP_ID and handle
3294
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3295
+				if (! empty($GRP_ID)) {
3296
+					$trashed_or_restored = $trash
3297
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3298
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3299
+					if (! $trashed_or_restored) {
3300
+						$success = 0;
3301
+					}
3302
+				} else {
3303
+					$success = 0;
3304
+				}
3305
+			}
3306
+		}
3307
+
3308
+		$action_desc = $trash
3309
+			? esc_html__('moved to the trash', 'event_espresso')
3310
+			: esc_html__('restored', 'event_espresso');
3311
+
3312
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3313
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3314
+
3315
+		$item_desc = $all ? _n(
3316
+			'Message Template Group',
3317
+			'Message Template Groups',
3318
+			$success,
3319
+			'event_espresso'
3320
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3321
+
3322
+		$item_desc = $template_switch
3323
+			? _n('template', 'templates', $success, 'event_espresso')
3324
+			: $item_desc;
3325
+
3326
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3327
+	}
3328
+
3329
+
3330
+	/**
3331
+	 * [_delete_message_template]
3332
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3333
+	 *
3334
+	 * @return void
3335
+	 * @throws EE_Error
3336
+	 * @throws InvalidArgumentException
3337
+	 * @throws InvalidDataTypeException
3338
+	 * @throws InvalidInterfaceException
3339
+	 * @throws ReflectionException
3340
+	 */
3341
+	protected function _delete_message_template()
3342
+	{
3343
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3344
+
3345
+		// checkboxes
3346
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3347
+		if (! empty($checkboxes)) {
3348
+			// if array has more than one element then success message should be plural
3349
+			$success = count($checkboxes) > 1 ? 2 : 1;
3350
+
3351
+			// cycle through bulk action checkboxes
3352
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3353
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3354
+			}
3355
+		} else {
3356
+			// grab single grp_id and delete
3357
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3358
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3359
+		}
3360
+
3361
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3362
+	}
3363
+
3364
+
3365
+	/**
3366
+	 * helper for permanently deleting a mtP group and all related message_templates
3367
+	 *
3368
+	 * @param int  $GRP_ID        The group being deleted
3369
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3370
+	 * @return bool boolean to indicate the success of the deletes or not.
3371
+	 * @throws EE_Error
3372
+	 * @throws InvalidArgumentException
3373
+	 * @throws InvalidDataTypeException
3374
+	 * @throws InvalidInterfaceException
3375
+	 * @throws ReflectionException
3376
+	 * @throws ReflectionException
3377
+	 */
3378
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3379
+	{
3380
+		$success = true;
3381
+		// first let's GET this group
3382
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3383
+		// then delete permanently all the related Message Templates
3384
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3385
+
3386
+		if ($deleted === 0) {
3387
+			$success = false;
3388
+		}
3389
+
3390
+		// now delete permanently this particular group
3391
+
3392
+		if ($include_group && ! $MTG->delete_permanently()) {
3393
+			$success = false;
3394
+		}
3395
+
3396
+		return $success;
3397
+	}
3398
+
3399
+
3400
+	/**
3401
+	 *    _learn_more_about_message_templates_link
3402
+	 *
3403
+	 * @access protected
3404
+	 * @return string
3405
+	 */
3406
+	protected function _learn_more_about_message_templates_link()
3407
+	{
3408
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3409
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3410
+			   . '</a>';
3411
+	}
3412
+
3413
+
3414
+	/**
3415
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3416
+	 * ajax and other routes.
3417
+	 *
3418
+	 * @return void
3419
+	 * @throws DomainException
3420
+	 * @throws EE_Error
3421
+	 */
3422
+	protected function _settings()
3423
+	{
3424
+		$this->_set_m_mt_settings();
3425
+
3426
+		// let's setup the messenger tabs
3427
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3428
+			$this->_m_mt_settings['messenger_tabs'],
3429
+			'messenger_links',
3430
+			'|',
3431
+			$this->request->getRequestParam('selected_messenger', 'email')
3432
+		);
3433
+
3434
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3435
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3436
+
3437
+		$this->display_admin_page_with_sidebar();
3438
+	}
3439
+
3440
+
3441
+	/**
3442
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3443
+	 *
3444
+	 * @access protected
3445
+	 * @return void
3446
+	 * @throws DomainException
3447
+	 */
3448
+	protected function _set_m_mt_settings()
3449
+	{
3450
+		// first if this is already set then lets get out no need to regenerate data.
3451
+		if (! empty($this->_m_mt_settings)) {
3452
+			return;
3453
+		}
3454
+
3455
+		// get all installed messengers and message_types
3456
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3457
+		$message_types = $this->_message_resource_manager->installed_message_types();
3458
+
3459
+
3460
+		// assemble the array for the _tab_text_links helper
3461
+
3462
+		foreach ($messengers as $messenger) {
3463
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3464
+				'label' => ucwords($messenger->label['singular']),
3465
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3466
+					? 'messenger-active'
3467
+					: '',
3468
+				'href'  => $messenger->name,
3469
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3470
+				'slug'  => $messenger->name,
3471
+				'obj'   => $messenger,
3472
+			];
3473
+
3474
+
3475
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3476
+
3477
+			foreach ($message_types as $message_type) {
3478
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3479
+				// it shouldn't show in either the inactive OR active metabox.
3480
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3481
+					continue;
3482
+				}
3483
+
3484
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3485
+					$messenger->name,
3486
+					$message_type->name
3487
+				)
3488
+					? 'active'
3489
+					: 'inactive';
3490
+
3491
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3492
+					'label'    => ucwords($message_type->label['singular']),
3493
+					'class'    => 'message-type-' . $a_or_i,
3494
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3495
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3496
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3497
+					'title'    => $a_or_i === 'active'
3498
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3499
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3500
+					'content'  => $a_or_i === 'active'
3501
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3502
+						: $this->_message_type_settings_content($message_type, $messenger),
3503
+					'slug'     => $message_type->name,
3504
+					'active'   => $a_or_i === 'active',
3505
+					'obj'      => $message_type,
3506
+				];
3507
+			}
3508
+		}
3509
+	}
3510
+
3511
+
3512
+	/**
3513
+	 * This just prepares the content for the message type settings
3514
+	 *
3515
+	 * @param EE_message_type $message_type The message type object
3516
+	 * @param EE_messenger    $messenger    The messenger object
3517
+	 * @param boolean         $active       Whether the message type is active or not
3518
+	 * @return string html output for the content
3519
+	 * @throws DomainException
3520
+	 */
3521
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3522
+	{
3523
+		// get message type fields
3524
+		$fields                                         = $message_type->get_admin_settings_fields();
3525
+		$settings_template_args['template_form_fields'] = '';
3526
+
3527
+		if (! empty($fields) && $active) {
3528
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3529
+			foreach ($fields as $fldname => $fldprops) {
3530
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3531
+				$template_form_field[ $field_id ] = [
3532
+					'name'       => 'message_type_settings[' . $fldname . ']',
3533
+					'label'      => $fldprops['label'],
3534
+					'input'      => $fldprops['field_type'],
3535
+					'type'       => $fldprops['value_type'],
3536
+					'required'   => $fldprops['required'],
3537
+					'validation' => $fldprops['validation'],
3538
+					'value'      => isset($existing_settings[ $fldname ])
3539
+						? $existing_settings[ $fldname ]
3540
+						: $fldprops['default'],
3541
+					'options'    => isset($fldprops['options'])
3542
+						? $fldprops['options']
3543
+						: [],
3544
+					'default'    => isset($existing_settings[ $fldname ])
3545
+						? $existing_settings[ $fldname ]
3546
+						: $fldprops['default'],
3547
+					'css_class'  => 'no-drag',
3548
+					'format'     => $fldprops['format'],
3549
+				];
3550
+			}
3551
+
3552
+
3553
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3554
+				? $this->_generate_admin_form_fields(
3555
+					$template_form_field,
3556
+					'string',
3557
+					'ee_mt_activate_form'
3558
+				)
3559
+				: '';
3560
+		}
3561
+
3562
+		$settings_template_args['description'] = $message_type->description;
3563
+		// we also need some hidden fields
3564
+		$hidden_fields = [
3565
+			'message_type_settings[messenger]' . $message_type->name    => [
3566
+				'type'  => 'hidden',
3567
+				'value' => $messenger->name,
3568
+			],
3569
+			'message_type_settings[message_type]' . $message_type->name => [
3570
+				'type'  => 'hidden',
3571
+				'value' => $message_type->name,
3572
+			],
3573
+			'type' . $message_type->name                                => [
3574
+				'type'  => 'hidden',
3575
+				'value' => 'message_type',
3576
+			],
3577
+		];
3578
+
3579
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3580
+			$hidden_fields,
3581
+			'array'
3582
+		);
3583
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3584
+			? ' hidden'
3585
+			: '';
3586
+
3587
+
3588
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3589
+		return EEH_Template::display_template($template, $settings_template_args, true);
3590
+	}
3591
+
3592
+
3593
+	/**
3594
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3595
+	 *
3596
+	 * @access protected
3597
+	 * @return void
3598
+	 * @throws DomainException
3599
+	 */
3600
+	protected function _messages_settings_metaboxes()
3601
+	{
3602
+		$this->_set_m_mt_settings();
3603
+		$m_boxes         = $mt_boxes = [];
3604
+		$m_template_args = $mt_template_args = [];
3605
+
3606
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3607
+
3608
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3609
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3610
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3611
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3612
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3613
+
3614
+				// messenger meta boxes
3615
+				$active         = $selected_messenger === $messenger;
3616
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3617
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3618
+					: '';
3619
+
3620
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3621
+					esc_html__('%s Settings', 'event_espresso'),
3622
+					$tab_array['label']
3623
+				);
3624
+
3625
+				$m_template_args[ $messenger . '_a_box' ] = [
3626
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3627
+					'inactive_message_types' => isset(
3628
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3629
+					)
3630
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3631
+						: '',
3632
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3633
+					'hidden'                 => $active ? '' : ' hidden',
3634
+					'hide_on_message'        => $hide_on_message,
3635
+					'messenger'              => $messenger,
3636
+					'active'                 => $active,
3637
+				];
3638
+
3639
+				// message type meta boxes
3640
+				// (which is really just the inactive container for each messenger
3641
+				// showing inactive message types for that messenger)
3642
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3643
+				$mt_template_args[ $messenger . '_i_box' ] = [
3644
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3645
+					'inactive_message_types' => isset(
3646
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3647
+					)
3648
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3649
+						: '',
3650
+					'hidden'                 => $active ? '' : ' hidden',
3651
+					'hide_on_message'        => $hide_on_message,
3652
+					'hide_off_message'       => $hide_off_message,
3653
+					'messenger'              => $messenger,
3654
+					'active'                 => $active,
3655
+				];
3656
+			}
3657
+		}
3658
+
3659
+
3660
+		// register messenger metaboxes
3661
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3662
+		foreach ($m_boxes as $box => $label) {
3663
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3664
+			$msgr          = str_replace('_a_box', '', $box);
3665
+			add_meta_box(
3666
+				'espresso_' . $msgr . '_settings',
3667
+				$label,
3668
+				function ($post, $metabox) {
3669
+					EEH_Template::display_template(
3670
+						$metabox['args']['template_path'],
3671
+						$metabox['args']['template_args']
3672
+					);
3673
+				},
3674
+				$this->_current_screen->id,
3675
+				'normal',
3676
+				'high',
3677
+				$callback_args
3678
+			);
3679
+		}
3680
+
3681
+		// register message type metaboxes
3682
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3683
+		foreach ($mt_boxes as $box => $label) {
3684
+			$callback_args = [
3685
+				'template_path' => $mt_template_path,
3686
+				'template_args' => $mt_template_args[ $box ],
3687
+			];
3688
+			$mt            = str_replace('_i_box', '', $box);
3689
+			add_meta_box(
3690
+				'espresso_' . $mt . '_inactive_mts',
3691
+				$label,
3692
+				function ($post, $metabox) {
3693
+					EEH_Template::display_template(
3694
+						$metabox['args']['template_path'],
3695
+						$metabox['args']['template_args']
3696
+					);
3697
+				},
3698
+				$this->_current_screen->id,
3699
+				'side',
3700
+				'high',
3701
+				$callback_args
3702
+			);
3703
+		}
3704
+
3705
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3706
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3707
+		if (is_main_site()) {
3708
+			add_meta_box(
3709
+				'espresso_global_message_settings',
3710
+				esc_html__('Global Message Settings', 'event_espresso'),
3711
+				[$this, 'global_messages_settings_metabox_content'],
3712
+				$this->_current_screen->id,
3713
+				'normal',
3714
+				'low',
3715
+				[]
3716
+			);
3717
+		}
3718
+	}
3719
+
3720
+
3721
+	/**
3722
+	 *  This generates the content for the global messages settings metabox.
3723
+	 *
3724
+	 * @return void
3725
+	 * @throws EE_Error
3726
+	 * @throws InvalidArgumentException
3727
+	 * @throws ReflectionException
3728
+	 * @throws InvalidDataTypeException
3729
+	 * @throws InvalidInterfaceException
3730
+	 */
3731
+	public function global_messages_settings_metabox_content()
3732
+	{
3733
+		$form = $this->_generate_global_settings_form();
3734
+		// already escaped
3735
+		echo $form->form_open(
3736
+			$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3737
+			'POST'
3738
+		);
3739
+		echo $form->get_html();
3740
+		echo $form->form_close();
3741
+	}
3742
+
3743
+
3744
+	/**
3745
+	 * This generates and returns the form object for the global messages settings.
3746
+	 *
3747
+	 * @return EE_Form_Section_Proper
3748
+	 * @throws EE_Error
3749
+	 * @throws InvalidArgumentException
3750
+	 * @throws ReflectionException
3751
+	 * @throws InvalidDataTypeException
3752
+	 * @throws InvalidInterfaceException
3753
+	 */
3754
+	protected function _generate_global_settings_form()
3755
+	{
3756
+		/** @var EE_Network_Core_Config $network_config */
3757
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3758
+
3759
+		return new EE_Form_Section_Proper(
3760
+			[
3761
+				'name'            => 'global_messages_settings',
3762
+				'html_id'         => 'global_messages_settings',
3763
+				'html_class'      => 'form-table',
3764
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3765
+				'subsections'     => apply_filters(
3766
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3767
+					[
3768
+						'do_messages_on_same_request' => new EE_Select_Input(
3769
+							[
3770
+								true  => esc_html__('On the same request', 'event_espresso'),
3771
+								false => esc_html__('On a separate request', 'event_espresso'),
3772
+							],
3773
+							[
3774
+								'default'         => $network_config->do_messages_on_same_request,
3775
+								'html_label_text' => esc_html__(
3776
+									'Generate and send all messages:',
3777
+									'event_espresso'
3778
+								),
3779
+								'html_help_text'  => esc_html__(
3780
+									'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.',
3781
+									'event_espresso'
3782
+								),
3783
+							]
3784
+						),
3785
+						'delete_threshold'            => new EE_Select_Input(
3786
+							[
3787
+								0  => esc_html__('Forever', 'event_espresso'),
3788
+								3  => esc_html__('3 Months', 'event_espresso'),
3789
+								6  => esc_html__('6 Months', 'event_espresso'),
3790
+								9  => esc_html__('9 Months', 'event_espresso'),
3791
+								12 => esc_html__('12 Months', 'event_espresso'),
3792
+								24 => esc_html__('24 Months', 'event_espresso'),
3793
+								36 => esc_html__('36 Months', 'event_espresso'),
3794
+							],
3795
+							[
3796
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3797
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3798
+								'html_help_text'  => esc_html__(
3799
+									'You can control how long a record of processed messages is kept via this option.',
3800
+									'event_espresso'
3801
+								),
3802
+							]
3803
+						),
3804
+						'update_settings'             => new EE_Submit_Input(
3805
+							[
3806
+								'default'         => esc_html__('Update', 'event_espresso'),
3807
+								'html_label_text' => '&nbsp',
3808
+							]
3809
+						),
3810
+					]
3811
+				),
3812
+			]
3813
+		);
3814
+	}
3815
+
3816
+
3817
+	/**
3818
+	 * This handles updating the global settings set on the admin page.
3819
+	 *
3820
+	 * @throws EE_Error
3821
+	 * @throws InvalidDataTypeException
3822
+	 * @throws InvalidInterfaceException
3823
+	 * @throws InvalidArgumentException
3824
+	 * @throws ReflectionException
3825
+	 */
3826
+	protected function _update_global_settings()
3827
+	{
3828
+		/** @var EE_Network_Core_Config $network_config */
3829
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3830
+		$messages_config = EE_Registry::instance()->CFG->messages;
3831
+		$form            = $this->_generate_global_settings_form();
3832
+		if ($form->was_submitted()) {
3833
+			$form->receive_form_submission();
3834
+			if ($form->is_valid()) {
3835
+				$valid_data = $form->valid_data();
3836
+				foreach ($valid_data as $property => $value) {
3837
+					$setter = 'set_' . $property;
3838
+					if (method_exists($network_config, $setter)) {
3839
+						$network_config->{$setter}($value);
3840
+					} elseif (
3841
+						property_exists($network_config, $property)
3842
+						&& $network_config->{$property} !== $value
3843
+					) {
3844
+						$network_config->{$property} = $value;
3845
+					} elseif (
3846
+						property_exists($messages_config, $property)
3847
+						&& $messages_config->{$property} !== $value
3848
+					) {
3849
+						$messages_config->{$property} = $value;
3850
+					}
3851
+				}
3852
+				// only update if the form submission was valid!
3853
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3854
+				EE_Registry::instance()->CFG->update_espresso_config();
3855
+				EE_Error::overwrite_success();
3856
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3857
+			}
3858
+		}
3859
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3860
+	}
3861
+
3862
+
3863
+	/**
3864
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3865
+	 *
3866
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3867
+	 * @return string html formatted tabs
3868
+	 * @throws DomainException
3869
+	 */
3870
+	protected function _get_mt_tabs($tab_array)
3871
+	{
3872
+		$tab_array = (array) $tab_array;
3873
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3874
+		$tabs      = '';
3875
+
3876
+		foreach ($tab_array as $tab) {
3877
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3878
+		}
3879
+
3880
+		return $tabs;
3881
+	}
3882
+
3883
+
3884
+	/**
3885
+	 * This prepares the content of the messenger meta box admin settings
3886
+	 *
3887
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3888
+	 * @return string html formatted content
3889
+	 * @throws DomainException
3890
+	 */
3891
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3892
+	{
3893
+
3894
+		$fields                                         = $messenger->get_admin_settings_fields();
3895
+		$settings_template_args['template_form_fields'] = '';
3896
+
3897
+		// is $messenger active?
3898
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3899
+
3900
+
3901
+		if (! empty($fields)) {
3902
+			$existing_settings = $messenger->get_existing_admin_settings();
3903
+
3904
+			foreach ($fields as $fldname => $fldprops) {
3905
+				$field_id                         = $messenger->name . '-' . $fldname;
3906
+				$template_form_field[ $field_id ] = [
3907
+					'name'       => 'messenger_settings[' . $field_id . ']',
3908
+					'label'      => $fldprops['label'],
3909
+					'input'      => $fldprops['field_type'],
3910
+					'type'       => $fldprops['value_type'],
3911
+					'required'   => $fldprops['required'],
3912
+					'validation' => $fldprops['validation'],
3913
+					'value'      => isset($existing_settings[ $field_id ])
3914
+						? $existing_settings[ $field_id ]
3915
+						: $fldprops['default'],
3916
+					'css_class'  => '',
3917
+					'format'     => $fldprops['format'],
3918
+				];
3919
+			}
3920
+
3921
+
3922
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3923
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3924
+				: '';
3925
+		}
3926
+
3927
+		// we also need some hidden fields
3928
+		$settings_template_args['hidden_fields'] = [
3929
+			'messenger_settings[messenger]' . $messenger->name => [
3930
+				'type'  => 'hidden',
3931
+				'value' => $messenger->name,
3932
+			],
3933
+			'type' . $messenger->name                          => [
3934
+				'type'  => 'hidden',
3935
+				'value' => 'messenger',
3936
+			],
3937
+		];
3938
+
3939
+		// make sure any active message types that are existing are included in the hidden fields
3940
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3941
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3942
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3943
+					'type'  => 'hidden',
3944
+					'value' => $mt,
3945
+				];
3946
+			}
3947
+		}
3948
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3949
+			$settings_template_args['hidden_fields'],
3950
+			'array'
3951
+		);
3952
+		$active                                  =
3953
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3954
+
3955
+		$settings_template_args['messenger']           = $messenger->name;
3956
+		$settings_template_args['description']         = $messenger->description;
3957
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3958
+
3959
+
3960
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3961
+			$messenger->name
3962
+		)
3963
+			? $settings_template_args['show_hide_edit_form']
3964
+			: ' hidden';
3965
+
3966
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3967
+			? ' hidden'
3968
+			: $settings_template_args['show_hide_edit_form'];
3969
+
3970
+
3971
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3972
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3973
+		$settings_template_args['on_off_status'] = $active;
3974
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3975
+		return EEH_Template::display_template(
3976
+			$template,
3977
+			$settings_template_args,
3978
+			true
3979
+		);
3980
+	}
3981
+
3982
+
3983
+	/**
3984
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3985
+	 *
3986
+	 * @throws DomainException
3987
+	 * @throws EE_Error
3988
+	 * @throws InvalidDataTypeException
3989
+	 * @throws InvalidInterfaceException
3990
+	 * @throws InvalidArgumentException
3991
+	 * @throws ReflectionException
3992
+	 */
3993
+	public function activate_messenger_toggle()
3994
+	{
3995
+		$success = true;
3996
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3997
+		// let's check that we have required data
3998
+
3999
+		if (! $this->_active_messenger_name) {
4000
+			EE_Error::add_error(
4001
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4002
+				__FILE__,
4003
+				__FUNCTION__,
4004
+				__LINE__
4005
+			);
4006
+			$success = false;
4007
+		}
4008
+
4009
+		// do a nonce check here since we're not arriving via a normal route
4010
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4011
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4012
+
4013
+		$this->_verify_nonce($nonce, $nonce_ref);
4014
+
4015
+
4016
+		$status = $this->request->getRequestParam('status');
4017
+		if (! $status) {
4018
+			EE_Error::add_error(
4019
+				esc_html__(
4020
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4021
+					'event_espresso'
4022
+				),
4023
+				__FILE__,
4024
+				__FUNCTION__,
4025
+				__LINE__
4026
+			);
4027
+			$success = false;
4028
+		}
4029
+
4030
+		// do check to verify we have a valid status.
4031
+		if ($status !== 'off' && $status !== 'on') {
4032
+			EE_Error::add_error(
4033
+				sprintf(
4034
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4035
+					$status
4036
+				),
4037
+				__FILE__,
4038
+				__FUNCTION__,
4039
+				__LINE__
4040
+			);
4041
+			$success = false;
4042
+		}
4043
+
4044
+		if ($success) {
4045
+			// made it here?  Stop dawdling then!!
4046
+			$success = $status === 'off'
4047
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4048
+				: $this->_activate_messenger($this->_active_messenger_name);
4049
+		}
4050
+
4051
+		$this->_template_args['success'] = $success;
4052
+
4053
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4054
+		$this->_return_json();
4055
+	}
4056
+
4057
+
4058
+	/**
4059
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4060
+	 *
4061
+	 * @throws DomainException
4062
+	 * @throws EE_Error
4063
+	 * @throws ReflectionException
4064
+	 * @throws InvalidDataTypeException
4065
+	 * @throws InvalidInterfaceException
4066
+	 * @throws InvalidArgumentException
4067
+	 */
4068
+	public function activate_mt_toggle()
4069
+	{
4070
+		$success = true;
4071
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4072
+
4073
+		// let's make sure we have the necessary data
4074
+		if (! $this->_active_message_type_name) {
4075
+			EE_Error::add_error(
4076
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4077
+				__FILE__,
4078
+				__FUNCTION__,
4079
+				__LINE__
4080
+			);
4081
+			$success = false;
4082
+		}
4083
+
4084
+		if (! $this->_active_messenger_name) {
4085
+			EE_Error::add_error(
4086
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4087
+				__FILE__,
4088
+				__FUNCTION__,
4089
+				__LINE__
4090
+			);
4091
+			$success = false;
4092
+		}
4093
+
4094
+		$status = $this->request->getRequestParam('status');
4095
+		if (! $status) {
4096
+			EE_Error::add_error(
4097
+				esc_html__(
4098
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4099
+					'event_espresso'
4100
+				),
4101
+				__FILE__,
4102
+				__FUNCTION__,
4103
+				__LINE__
4104
+			);
4105
+			$success = false;
4106
+		}
4107
+
4108
+
4109
+		// do check to verify we have a valid status.
4110
+		if ($status !== 'activate' && $status !== 'deactivate') {
4111
+			EE_Error::add_error(
4112
+				sprintf(
4113
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4114
+					$status
4115
+				),
4116
+				__FILE__,
4117
+				__FUNCTION__,
4118
+				__LINE__
4119
+			);
4120
+			$success = false;
4121
+		}
4122
+
4123
+
4124
+		// do a nonce check here since we're not arriving via a normal route
4125
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4126
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4127
+
4128
+		if ($success) {
4129
+			// made it here? um, what are you waiting for then?
4130
+			$success = $status === 'deactivate'
4131
+				? $this->_deactivate_message_type_for_messenger(
4132
+					$this->_active_messenger_name,
4133
+					$this->_active_message_type_name
4134
+				)
4135
+				: $this->_activate_message_type_for_messenger(
4136
+					$this->_active_messenger_name,
4137
+					$this->_active_message_type_name
4138
+				);
4139
+		}
4140
+
4141
+		$this->_template_args['success'] = $success;
4142
+		$this->_return_json();
4143
+	}
4144
+
4145
+
4146
+	/**
4147
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4148
+	 *
4149
+	 * @param string $messenger_name The name of the messenger being activated
4150
+	 * @return bool
4151
+	 * @throws DomainException
4152
+	 * @throws EE_Error
4153
+	 * @throws InvalidArgumentException
4154
+	 * @throws ReflectionException
4155
+	 * @throws InvalidDataTypeException
4156
+	 * @throws InvalidInterfaceException
4157
+	 */
4158
+	protected function _activate_messenger($messenger_name)
4159
+	{
4160
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4161
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4162
+			? $active_messenger->get_default_message_types()
4163
+			: [];
4164
+
4165
+		// ensure is active
4166
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4167
+
4168
+		// set response_data for reload
4169
+		foreach ($message_types_to_activate as $message_type_name) {
4170
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4171
+			if (
4172
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4173
+					$messenger_name,
4174
+					$message_type_name
4175
+				)
4176
+				&& $message_type instanceof EE_message_type
4177
+			) {
4178
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4179
+				if ($message_type->get_admin_settings_fields()) {
4180
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4181
+				}
4182
+			}
4183
+		}
4184
+
4185
+		// add success message for activating messenger
4186
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4187
+	}
4188
+
4189
+
4190
+	/**
4191
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4192
+	 *
4193
+	 * @param string $messenger_name The name of the messenger being activated
4194
+	 * @return bool
4195
+	 * @throws DomainException
4196
+	 * @throws EE_Error
4197
+	 * @throws InvalidArgumentException
4198
+	 * @throws ReflectionException
4199
+	 * @throws InvalidDataTypeException
4200
+	 * @throws InvalidInterfaceException
4201
+	 */
4202
+	protected function _deactivate_messenger($messenger_name)
4203
+	{
4204
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4205
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4206
+
4207
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4208
+	}
4209
+
4210
+
4211
+	/**
4212
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4213
+	 *
4214
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4215
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4216
+	 * @return bool
4217
+	 * @throws DomainException
4218
+	 * @throws EE_Error
4219
+	 * @throws InvalidArgumentException
4220
+	 * @throws ReflectionException
4221
+	 * @throws InvalidDataTypeException
4222
+	 * @throws InvalidInterfaceException
4223
+	 */
4224
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4225
+	{
4226
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4227
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4228
+
4229
+		// ensure is active
4230
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4231
+
4232
+		// set response for load
4233
+		if (
4234
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4235
+				$messenger_name,
4236
+				$message_type_name
4237
+			)
4238
+		) {
4239
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4240
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4241
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4242
+			}
4243
+		}
4244
+
4245
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4246
+			$active_messenger,
4247
+			$message_type_to_activate
4248
+		);
4249
+	}
4250
+
4251
+
4252
+	/**
4253
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4254
+	 *
4255
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4256
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4257
+	 * @return bool
4258
+	 * @throws DomainException
4259
+	 * @throws EE_Error
4260
+	 * @throws InvalidArgumentException
4261
+	 * @throws ReflectionException
4262
+	 * @throws InvalidDataTypeException
4263
+	 * @throws InvalidInterfaceException
4264
+	 */
4265
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4266
+	{
4267
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4268
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4269
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4270
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4271
+
4272
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4273
+			$active_messenger,
4274
+			$message_type_to_deactivate
4275
+		);
4276
+	}
4277
+
4278
+
4279
+	/**
4280
+	 * This just initializes the defaults for activating messenger and message type responses.
4281
+	 */
4282
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4283
+	{
4284
+		$this->_template_args['data']['active_mts'] = [];
4285
+		$this->_template_args['data']['mt_reload']  = [];
4286
+	}
4287
+
4288
+
4289
+	/**
4290
+	 * Setup appropriate response for activating a messenger and/or message types
4291
+	 *
4292
+	 * @param EE_messenger         $messenger
4293
+	 * @param EE_message_type|null $message_type
4294
+	 * @return bool
4295
+	 * @throws DomainException
4296
+	 * @throws EE_Error
4297
+	 * @throws InvalidArgumentException
4298
+	 * @throws ReflectionException
4299
+	 * @throws InvalidDataTypeException
4300
+	 * @throws InvalidInterfaceException
4301
+	 */
4302
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4303
+		$messenger,
4304
+		EE_Message_Type $message_type = null
4305
+	) {
4306
+		// if $messenger isn't a valid messenger object then get out.
4307
+		if (! $messenger instanceof EE_Messenger) {
4308
+			EE_Error::add_error(
4309
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4310
+				__FILE__,
4311
+				__FUNCTION__,
4312
+				__LINE__
4313
+			);
4314
+			return false;
4315
+		}
4316
+		// activated
4317
+		if ($this->_template_args['data']['active_mts']) {
4318
+			EE_Error::overwrite_success();
4319
+			// activated a message type with the messenger
4320
+			if ($message_type instanceof EE_message_type) {
4321
+				EE_Error::add_success(
4322
+					sprintf(
4323
+						esc_html__(
4324
+							'%s message type has been successfully activated with the %s messenger',
4325
+							'event_espresso'
4326
+						),
4327
+						ucwords($message_type->label['singular']),
4328
+						ucwords($messenger->label['singular'])
4329
+					)
4330
+				);
4331
+
4332
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4333
+				if ($message_type->name === 'invoice') {
4334
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4335
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4336
+					if ($pm instanceof EE_Payment_Method) {
4337
+						EE_Error::add_attention(
4338
+							esc_html__(
4339
+								'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.',
4340
+								'event_espresso'
4341
+							)
4342
+						);
4343
+					}
4344
+				}
4345
+				// just toggles the entire messenger
4346
+			} else {
4347
+				EE_Error::add_success(
4348
+					sprintf(
4349
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4350
+						ucwords($messenger->label['singular'])
4351
+					)
4352
+				);
4353
+			}
4354
+
4355
+			return true;
4356
+
4357
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4358
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4359
+			// in which case we just give a success message for the messenger being successfully activated.
4360
+		} else {
4361
+			if (! $messenger->get_default_message_types()) {
4362
+				// messenger doesn't have any default message types so still a success.
4363
+				EE_Error::add_success(
4364
+					sprintf(
4365
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4366
+						ucwords($messenger->label['singular'])
4367
+					)
4368
+				);
4369
+
4370
+				return true;
4371
+			} else {
4372
+				EE_Error::add_error(
4373
+					$message_type instanceof EE_message_type
4374
+					? sprintf(
4375
+						esc_html__(
4376
+							'%s message type was not successfully activated with the %s messenger',
4377
+							'event_espresso'
4378
+						),
4379
+						ucwords($message_type->label['singular']),
4380
+						ucwords($messenger->label['singular'])
4381
+					)
4382
+					: sprintf(
4383
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4384
+						ucwords($messenger->label['singular'])
4385
+					),
4386
+					__FILE__,
4387
+					__FUNCTION__,
4388
+					__LINE__
4389
+				);
4390
+
4391
+				return false;
4392
+			}
4393
+		}
4394
+	}
4395
+
4396
+
4397
+	/**
4398
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4399
+	 *
4400
+	 * @param EE_messenger         $messenger
4401
+	 * @param EE_message_type|null $message_type
4402
+	 * @return bool
4403
+	 * @throws DomainException
4404
+	 * @throws EE_Error
4405
+	 * @throws InvalidArgumentException
4406
+	 * @throws ReflectionException
4407
+	 * @throws InvalidDataTypeException
4408
+	 * @throws InvalidInterfaceException
4409
+	 */
4410
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4411
+		$messenger,
4412
+		EE_message_type $message_type = null
4413
+	) {
4414
+		EE_Error::overwrite_success();
4415
+
4416
+		// if $messenger isn't a valid messenger object then get out.
4417
+		if (! $messenger instanceof EE_Messenger) {
4418
+			EE_Error::add_error(
4419
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4420
+				__FILE__,
4421
+				__FUNCTION__,
4422
+				__LINE__
4423
+			);
4424
+
4425
+			return false;
4426
+		}
4427
+
4428
+		if ($message_type instanceof EE_message_type) {
4429
+			$message_type_name = $message_type->name;
4430
+			EE_Error::add_success(
4431
+				sprintf(
4432
+					esc_html__(
4433
+						'%s message type has been successfully deactivated for the %s messenger.',
4434
+						'event_espresso'
4435
+					),
4436
+					ucwords($message_type->label['singular']),
4437
+					ucwords($messenger->label['singular'])
4438
+				)
4439
+			);
4440
+		} else {
4441
+			$message_type_name = '';
4442
+			EE_Error::add_success(
4443
+				sprintf(
4444
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4445
+					ucwords($messenger->label['singular'])
4446
+				)
4447
+			);
4448
+		}
4449
+
4450
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4451
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4452
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4453
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4454
+			if ($count_updated > 0) {
4455
+				$msg = $message_type_name === 'invoice'
4456
+					? esc_html__(
4457
+						'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.',
4458
+						'event_espresso'
4459
+					)
4460
+					: esc_html__(
4461
+						'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.',
4462
+						'event_espresso'
4463
+					);
4464
+				EE_Error::add_attention($msg);
4465
+			}
4466
+		}
4467
+
4468
+		return true;
4469
+	}
4470
+
4471
+
4472
+	/**
4473
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4474
+	 *
4475
+	 * @throws DomainException
4476
+	 * @throws EE_Error
4477
+	 * @throws EE_Error
4478
+	 */
4479
+	public function update_mt_form()
4480
+	{
4481
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4482
+			EE_Error::add_error(
4483
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4484
+				__FILE__,
4485
+				__FUNCTION__,
4486
+				__LINE__
4487
+			);
4488
+			$this->_return_json();
4489
+		}
4490
+
4491
+		$message_types = $this->get_installed_message_types();
4492
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4493
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4494
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4495
+
4496
+		$this->_template_args['success'] = true;
4497
+		$this->_template_args['content'] = $content;
4498
+		$this->_return_json();
4499
+	}
4500
+
4501
+
4502
+	/**
4503
+	 * this handles saving the settings for a messenger or message type
4504
+	 *
4505
+	 * @throws EE_Error
4506
+	 * @throws EE_Error
4507
+	 */
4508
+	public function save_settings()
4509
+	{
4510
+		$type = $this->request->getRequestParam('type');
4511
+		if (! $type) {
4512
+			EE_Error::add_error(
4513
+				esc_html__(
4514
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4515
+					'event_espresso'
4516
+				),
4517
+				__FILE__,
4518
+				__FUNCTION__,
4519
+				__LINE__
4520
+			);
4521
+			$this->_template_args['error'] = true;
4522
+			$this->_return_json();
4523
+		}
4524
+
4525
+
4526
+		if ($type === 'messenger') {
4527
+			// this should be an array.
4528
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4529
+			$messenger = $settings['messenger'];
4530
+			// remove messenger and message_types from settings array
4531
+			unset($settings['messenger'], $settings['message_types']);
4532
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4533
+		} elseif ($type === 'message_type') {
4534
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4535
+			$messenger    = $settings['messenger'];
4536
+			$message_type = $settings['message_type'];
4537
+			// remove messenger and message_types from settings array
4538
+			unset($settings['messenger'], $settings['message_types']);
4539
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4540
+		}
4541
+
4542
+		// okay we should have the data all setup.  Now we just update!
4543
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4544
+
4545
+		if ($success) {
4546
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4547
+		} else {
4548
+			EE_Error::add_error(
4549
+				esc_html__('Settings did not get updated', 'event_espresso'),
4550
+				__FILE__,
4551
+				__FUNCTION__,
4552
+				__LINE__
4553
+			);
4554
+		}
4555
+
4556
+		$this->_template_args['success'] = $success;
4557
+		$this->_return_json();
4558
+	}
4559
+
4560
+
4561
+
4562
+
4563
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4564
+
4565
+
4566
+	/**
4567
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4568
+	 * However, this does not send immediately, it just queues for sending.
4569
+	 *
4570
+	 * @throws EE_Error
4571
+	 * @throws InvalidDataTypeException
4572
+	 * @throws InvalidInterfaceException
4573
+	 * @throws InvalidArgumentException
4574
+	 * @throws ReflectionException
4575
+	 * @since 4.9.0
4576
+	 */
4577
+	protected function _generate_now()
4578
+	{
4579
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4580
+		$this->_redirect_after_action(false, '', '', [], true);
4581
+	}
4582
+
4583
+
4584
+	/**
4585
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4586
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4587
+	 *
4588
+	 * @throws EE_Error
4589
+	 * @throws InvalidDataTypeException
4590
+	 * @throws InvalidInterfaceException
4591
+	 * @throws InvalidArgumentException
4592
+	 * @throws ReflectionException
4593
+	 * @since 4.9.0
4594
+	 */
4595
+	protected function _generate_and_send_now()
4596
+	{
4597
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4598
+		$this->_redirect_after_action(false, '', '', [], true);
4599
+	}
4600
+
4601
+
4602
+	/**
4603
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4604
+	 *
4605
+	 * @throws EE_Error
4606
+	 * @throws InvalidDataTypeException
4607
+	 * @throws InvalidInterfaceException
4608
+	 * @throws InvalidArgumentException
4609
+	 * @throws ReflectionException
4610
+	 * @since 4.9.0
4611
+	 */
4612
+	protected function _queue_for_resending()
4613
+	{
4614
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4615
+		$this->_redirect_after_action(false, '', '', [], true);
4616
+	}
4617
+
4618
+
4619
+	/**
4620
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4621
+	 *
4622
+	 * @throws EE_Error
4623
+	 * @throws InvalidDataTypeException
4624
+	 * @throws InvalidInterfaceException
4625
+	 * @throws InvalidArgumentException
4626
+	 * @throws ReflectionException
4627
+	 * @since 4.9.0
4628
+	 */
4629
+	protected function _send_now()
4630
+	{
4631
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4632
+		$this->_redirect_after_action(false, '', '', [], true);
4633
+	}
4634
+
4635
+
4636
+	/**
4637
+	 * Deletes EE_messages for IDs in the request.
4638
+	 *
4639
+	 * @throws EE_Error
4640
+	 * @throws InvalidDataTypeException
4641
+	 * @throws InvalidInterfaceException
4642
+	 * @throws InvalidArgumentException
4643
+	 * @since 4.9.0
4644
+	 */
4645
+	protected function _delete_ee_messages()
4646
+	{
4647
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4648
+		$deleted_count = 0;
4649
+		foreach ($MSG_IDs as $MSG_ID) {
4650
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4651
+				$deleted_count++;
4652
+			}
4653
+		}
4654
+		if ($deleted_count) {
4655
+			EE_Error::add_success(
4656
+				esc_html(
4657
+					_n(
4658
+						'Message successfully deleted',
4659
+						'Messages successfully deleted',
4660
+						$deleted_count,
4661
+						'event_espresso'
4662
+					)
4663
+				)
4664
+			);
4665
+		} else {
4666
+			EE_Error::add_error(
4667
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4668
+				__FILE__,
4669
+				__FUNCTION__,
4670
+				__LINE__
4671
+			);
4672
+		}
4673
+		$this->_redirect_after_action(false, '', '', [], true);
4674
+	}
4675
+
4676
+
4677
+	/**
4678
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4679
+	 *
4680
+	 * @return array
4681
+	 * @since 4.9.0
4682
+	 */
4683
+	protected function _get_msg_ids_from_request()
4684
+	{
4685
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4686
+		if (empty($MSG_IDs)) {
4687
+			return [];
4688
+		}
4689
+		// if 'MSG_ID' was just a single ID (not an array)
4690
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4691
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4692
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4693
+			? $MSG_IDs
4694
+			: array_keys($MSG_IDs);
4695
+	}
4696 4696
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4104 added lines, -4104 removed lines patch added patch discarded remove patch
@@ -18,4179 +18,4179 @@
 block discarded – undo
18 18
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var LoaderInterface
23
-     */
24
-    protected $loader;
21
+	/**
22
+	 * @var LoaderInterface
23
+	 */
24
+	protected $loader;
25 25
 
26
-    /**
27
-     * @var RequestInterface
28
-     */
29
-    protected $request;
26
+	/**
27
+	 * @var RequestInterface
28
+	 */
29
+	protected $request;
30 30
 
31
-    // set in _init_page_props()
32
-    public $page_slug;
31
+	// set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    // set in define_page_props()
39
-    protected $_admin_base_url;
38
+	// set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    // set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	// set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    // navtabs
52
-    protected $_nav_tabs;
51
+	// navtabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56
-    /**
57
-     * @var array $_help_tour
58
-     */
59
-    protected $_help_tour = [];
56
+	/**
57
+	 * @var array $_help_tour
58
+	 */
59
+	protected $_help_tour = [];
60 60
 
61 61
 
62
-    // template variables (used by templates)
63
-    protected $_template_path;
62
+	// template variables (used by templates)
63
+	protected $_template_path;
64 64
 
65
-    protected $_column_template_path;
65
+	protected $_column_template_path;
66 66
 
67
-    /**
68
-     * @var array $_template_args
69
-     */
70
-    protected $_template_args = [];
67
+	/**
68
+	 * @var array $_template_args
69
+	 */
70
+	protected $_template_args = [];
71 71
 
72
-    /**
73
-     * this will hold the list table object for a given view.
74
-     *
75
-     * @var EE_Admin_List_Table $_list_table_object
76
-     */
77
-    protected $_list_table_object;
72
+	/**
73
+	 * this will hold the list table object for a given view.
74
+	 *
75
+	 * @var EE_Admin_List_Table $_list_table_object
76
+	 */
77
+	protected $_list_table_object;
78 78
 
79
-    // bools
80
-    protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
79
+	// bools
80
+	protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
81 81
 
82
-    protected $_routing;
82
+	protected $_routing;
83 83
 
84
-    // list table args
85
-    protected $_view;
84
+	// list table args
85
+	protected $_view;
86 86
 
87
-    protected $_views;
87
+	protected $_views;
88 88
 
89 89
 
90
-    // action => method pairs used for routing incoming requests
91
-    protected $_page_routes;
90
+	// action => method pairs used for routing incoming requests
91
+	protected $_page_routes;
92 92
 
93
-    /**
94
-     * @var array $_page_config
95
-     */
96
-    protected $_page_config;
93
+	/**
94
+	 * @var array $_page_config
95
+	 */
96
+	protected $_page_config;
97 97
 
98
-    /**
99
-     * the current page route and route config
100
-     *
101
-     * @var string $_route
102
-     */
103
-    protected $_route;
98
+	/**
99
+	 * the current page route and route config
100
+	 *
101
+	 * @var string $_route
102
+	 */
103
+	protected $_route;
104 104
 
105
-    /**
106
-     * @var string $_cpt_route
107
-     */
108
-    protected $_cpt_route;
105
+	/**
106
+	 * @var string $_cpt_route
107
+	 */
108
+	protected $_cpt_route;
109 109
 
110
-    /**
111
-     * @var array $_route_config
112
-     */
113
-    protected $_route_config;
110
+	/**
111
+	 * @var array $_route_config
112
+	 */
113
+	protected $_route_config;
114 114
 
115
-    /**
116
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
117
-     * actions.
118
-     *
119
-     * @since 4.6.x
120
-     * @var array.
121
-     */
122
-    protected $_default_route_query_args;
123
-
124
-    // set via request page and action args.
125
-    protected $_current_page;
126
-
127
-    protected $_current_view;
128
-
129
-    protected $_current_page_view_url;
130
-
131
-    /**
132
-     * unprocessed value for the 'action' request param (default '')
133
-     *
134
-     * @var string
135
-     */
136
-    protected $raw_req_action = '';
137
-
138
-    /**
139
-     * unprocessed value for the 'page' request param (default '')
140
-     *
141
-     * @var string
142
-     */
143
-    protected $raw_req_page = '';
144
-
145
-    /**
146
-     * sanitized request action (and nonce)
147
-     *
148
-     * @var string
149
-     */
150
-    protected $_req_action = '';
151
-
152
-    /**
153
-     * sanitized request action nonce
154
-     *
155
-     * @var string
156
-     */
157
-    protected $_req_nonce = '';
158
-
159
-    /**
160
-     * @var string
161
-     */
162
-    protected $_search_btn_label = '';
163
-
164
-    /**
165
-     * @var string
166
-     */
167
-    protected $_search_box_callback = '';
168
-
169
-    /**
170
-     * @var WP_Screen
171
-     */
172
-    protected $_current_screen;
173
-
174
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
175
-    protected $_hook_obj;
176
-
177
-    // for holding incoming request data
178
-    protected $_req_data = [];
179
-
180
-    // yes / no array for admin form fields
181
-    protected $_yes_no_values = [];
182
-
183
-    // some default things shared by all child classes
184
-    protected $_default_espresso_metaboxes;
185
-
186
-    /**
187
-     * @var EE_Registry
188
-     */
189
-    protected $EE = null;
190
-
191
-
192
-    /**
193
-     * This is just a property that flags whether the given route is a caffeinated route or not.
194
-     *
195
-     * @var boolean
196
-     */
197
-    protected $_is_caf = false;
198
-
199
-
200
-    /**
201
-     * @Constructor
202
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
203
-     * @throws EE_Error
204
-     * @throws InvalidArgumentException
205
-     * @throws ReflectionException
206
-     * @throws InvalidDataTypeException
207
-     * @throws InvalidInterfaceException
208
-     */
209
-    public function __construct($routing = true)
210
-    {
211
-        $this->loader  = LoaderFactory::getLoader();
212
-        $this->request = $this->loader->getShared(RequestInterface::class);
213
-        $this->_routing = $routing;
214
-
215
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
216
-            $this->_is_caf = true;
217
-        }
218
-        $this->_yes_no_values = [
219
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
220
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
221
-        ];
222
-        // set the _req_data property.
223
-        $this->_req_data = $this->request->requestParams();
224
-        // set initial page props (child method)
225
-        $this->_init_page_props();
226
-        // set global defaults
227
-        $this->_set_defaults();
228
-        // set early because incoming requests could be ajax related and we need to register those hooks.
229
-        $this->_global_ajax_hooks();
230
-        $this->_ajax_hooks();
231
-        // other_page_hooks have to be early too.
232
-        $this->_do_other_page_hooks();
233
-        // set up page dependencies
234
-        $this->_before_page_setup();
235
-        $this->_page_setup();
236
-        // die();
237
-    }
238
-
239
-
240
-    /**
241
-     * _init_page_props
242
-     * Child classes use to set at least the following properties:
243
-     * $page_slug.
244
-     * $page_label.
245
-     *
246
-     * @abstract
247
-     * @return void
248
-     */
249
-    abstract protected function _init_page_props();
250
-
251
-
252
-    /**
253
-     * _ajax_hooks
254
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
255
-     * Note: within the ajax callback methods.
256
-     *
257
-     * @abstract
258
-     * @return void
259
-     */
260
-    abstract protected function _ajax_hooks();
261
-
262
-
263
-    /**
264
-     * _define_page_props
265
-     * child classes define page properties in here.  Must include at least:
266
-     * $_admin_base_url = base_url for all admin pages
267
-     * $_admin_page_title = default admin_page_title for admin pages
268
-     * $_labels = array of default labels for various automatically generated elements:
269
-     *    array(
270
-     *        'buttons' => array(
271
-     *            'add' => esc_html__('label for add new button'),
272
-     *            'edit' => esc_html__('label for edit button'),
273
-     *            'delete' => esc_html__('label for delete button')
274
-     *            )
275
-     *        )
276
-     *
277
-     * @abstract
278
-     * @return void
279
-     */
280
-    abstract protected function _define_page_props();
281
-
282
-
283
-    /**
284
-     * _set_page_routes
285
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
286
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
287
-     * have a 'default' route. Here's the format
288
-     * $this->_page_routes = array(
289
-     *        'default' => array(
290
-     *            'func' => '_default_method_handling_route',
291
-     *            'args' => array('array','of','args'),
292
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
293
-     *            ajax request, backend processing)
294
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
295
-     *            headers route after.  The string you enter here should match the defined route reference for a
296
-     *            headers sent route.
297
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
298
-     *            this route.
299
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
300
-     *            checks).
301
-     *        ),
302
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
303
-     *        handling method.
304
-     *        )
305
-     * )
306
-     *
307
-     * @abstract
308
-     * @return void
309
-     */
310
-    abstract protected function _set_page_routes();
311
-
312
-
313
-    /**
314
-     * _set_page_config
315
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
316
-     * array corresponds to the page_route for the loaded page. Format:
317
-     * $this->_page_config = array(
318
-     *        'default' => array(
319
-     *            'labels' => array(
320
-     *                'buttons' => array(
321
-     *                    'add' => esc_html__('label for adding item'),
322
-     *                    'edit' => esc_html__('label for editing item'),
323
-     *                    'delete' => esc_html__('label for deleting item')
324
-     *                ),
325
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
326
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
327
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
328
-     *            _define_page_props() method
329
-     *            'nav' => array(
330
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
331
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
332
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
333
-     *                'order' => 10, //required to indicate tab position.
334
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
335
-     *                displayed then add this parameter.
336
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
337
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
338
-     *            metaboxes set for eventespresso admin pages.
339
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
340
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
341
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
342
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
343
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
344
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
345
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
346
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
347
-     *            want to display.
348
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
349
-     *                'tab_id' => array(
350
-     *                    'title' => 'tab_title',
351
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
352
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
353
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
354
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
355
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
356
-     *                    attempt to use the callback which should match the name of a method in the class
357
-     *                    ),
358
-     *                'tab2_id' => array(
359
-     *                    'title' => 'tab2 title',
360
-     *                    'filename' => 'file_name_2'
361
-     *                    'callback' => 'callback_method_for_content',
362
-     *                 ),
363
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
364
-     *            help tab area on an admin page. @return void
365
-     *
366
-     * @link
367
-     *                http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
368
-     *                'help_tour' => array(
369
-     *                'name_of_help_tour_class', //all help tours should be a child class of EE_Help_Tour and located
370
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
371
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
372
-     *                ),
373
-     *                'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default
374
-     *                is true if it isn't present).  To remove the requirement for a nonce check when this route is
375
-     *                visited just set
376
-     *                'require_nonce' to FALSE
377
-     *                )
378
-     *                )
379
-     *
380
-     * @abstract
381
-     */
382
-    abstract protected function _set_page_config();
383
-
384
-
385
-
386
-
387
-
388
-    /** end sample help_tour methods **/
389
-    /**
390
-     * _add_screen_options
391
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
392
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
393
-     * to a particular view.
394
-     *
395
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
396
-     *         see also WP_Screen object documents...
397
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
398
-     * @abstract
399
-     * @return void
400
-     */
401
-    abstract protected function _add_screen_options();
402
-
403
-
404
-    /**
405
-     * _add_feature_pointers
406
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
407
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
408
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
409
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
410
-     * extended) also see:
411
-     *
412
-     * @link   http://eamann.com/tech/wordpress-portland/
413
-     * @abstract
414
-     * @return void
415
-     */
416
-    abstract protected function _add_feature_pointers();
417
-
418
-
419
-    /**
420
-     * load_scripts_styles
421
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
422
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
423
-     * scripts/styles per view by putting them in a dynamic function in this format
424
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
425
-     *
426
-     * @abstract
427
-     * @return void
428
-     */
429
-    abstract public function load_scripts_styles();
430
-
431
-
432
-    /**
433
-     * admin_init
434
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
435
-     * all pages/views loaded by child class.
436
-     *
437
-     * @abstract
438
-     * @return void
439
-     */
440
-    abstract public function admin_init();
441
-
442
-
443
-    /**
444
-     * admin_notices
445
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
446
-     * all pages/views loaded by child class.
447
-     *
448
-     * @abstract
449
-     * @return void
450
-     */
451
-    abstract public function admin_notices();
452
-
453
-
454
-    /**
455
-     * admin_footer_scripts
456
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
457
-     * will apply to all pages/views loaded by child class.
458
-     *
459
-     * @return void
460
-     */
461
-    abstract public function admin_footer_scripts();
462
-
463
-
464
-    /**
465
-     * admin_footer
466
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
467
-     * apply to all pages/views loaded by child class.
468
-     *
469
-     * @return void
470
-     */
471
-    public function admin_footer()
472
-    {
473
-    }
474
-
475
-
476
-    /**
477
-     * _global_ajax_hooks
478
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
479
-     * Note: within the ajax callback methods.
480
-     *
481
-     * @abstract
482
-     * @return void
483
-     */
484
-    protected function _global_ajax_hooks()
485
-    {
486
-        // for lazy loading of metabox content
487
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
488
-    }
489
-
490
-
491
-    public function ajax_metabox_content()
492
-    {
493
-        $content_id  = $this->request->getRequestParam('contentid', '');
494
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
495
-        self::cached_rss_display($content_id, $content_url);
496
-        wp_die();
497
-    }
498
-
499
-
500
-    /**
501
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
502
-     *
503
-     * @return void
504
-     */
505
-    protected function _before_page_setup()
506
-    {
507
-        // default is to do nothing
508
-    }
509
-
510
-
511
-    /**
512
-     * Makes sure any things that need to be loaded early get handled.
513
-     * We also escape early here if the page requested doesn't match the object.
514
-     *
515
-     * @final
516
-     * @return void
517
-     * @throws EE_Error
518
-     * @throws InvalidArgumentException
519
-     * @throws ReflectionException
520
-     * @throws InvalidDataTypeException
521
-     * @throws InvalidInterfaceException
522
-     */
523
-    final protected function _page_setup()
524
-    {
525
-        // requires?
526
-        // admin_init stuff - global - we're setting this REALLY early
527
-        // so if EE_Admin pages have to hook into other WP pages they can.
528
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
529
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
530
-        // next verify if we need to load anything...
531
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
532
-        $this->page_folder   = strtolower(
533
-            str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
534
-        );
535
-        global $ee_menu_slugs;
536
-        $ee_menu_slugs = (array) $ee_menu_slugs;
537
-        if (
538
-            ! $this->request->isAjax()
539
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
540
-        ) {
541
-            return;
542
-        }
543
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
544
-        // we need to copy the action from the second to the first
545
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
546
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
547
-        $action     = $action !== '-1' ? $action : $action2;
548
-        $req_action = $action !== '-1' ? $action : 'default';
549
-
550
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
551
-        // then let's use the route as the action.
552
-        // This covers cases where we're coming in from a list table that isn't on the default route.
553
-        $route = $this->request->getRequestParam('route');
554
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
555
-            ? $route
556
-            : $req_action;
557
-
558
-        $this->_current_view = $this->_req_action;
559
-        $this->_req_nonce    = $this->_req_action . '_nonce';
560
-        $this->_define_page_props();
561
-        $this->_current_page_view_url = add_query_arg(
562
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
563
-            $this->_admin_base_url
564
-        );
565
-        // default things
566
-        $this->_default_espresso_metaboxes = [
567
-            '_espresso_news_post_box',
568
-            '_espresso_links_post_box',
569
-            '_espresso_ratings_request',
570
-            '_espresso_sponsors_post_box',
571
-        ];
572
-        // set page configs
573
-        $this->_set_page_routes();
574
-        $this->_set_page_config();
575
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
576
-        if ($this->request->requestParamIsSet('wp_referer')) {
577
-            $wp_referer = $this->request->getRequestParam('wp_referer');
578
-            if ($wp_referer) {
579
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
580
-            }
581
-        }
582
-        // for caffeinated and other extended functionality.
583
-        //  If there is a _extend_page_config method
584
-        // then let's run that to modify the all the various page configuration arrays
585
-        if (method_exists($this, '_extend_page_config')) {
586
-            $this->_extend_page_config();
587
-        }
588
-        // for CPT and other extended functionality.
589
-        // If there is an _extend_page_config_for_cpt
590
-        // then let's run that to modify all the various page configuration arrays.
591
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
592
-            $this->_extend_page_config_for_cpt();
593
-        }
594
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
595
-        $this->_page_routes = apply_filters(
596
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
597
-            $this->_page_routes,
598
-            $this
599
-        );
600
-        $this->_page_config = apply_filters(
601
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
602
-            $this->_page_config,
603
-            $this
604
-        );
605
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
606
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
607
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
608
-            add_action(
609
-                'AHEE__EE_Admin_Page__route_admin_request',
610
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
611
-                10,
612
-                2
613
-            );
614
-        }
615
-        // next route only if routing enabled
616
-        if ($this->_routing && ! $this->request->isAjax()) {
617
-            $this->_verify_routes();
618
-            // next let's just check user_access and kill if no access
619
-            $this->check_user_access();
620
-            if ($this->_is_UI_request) {
621
-                // admin_init stuff - global, all views for this page class, specific view
622
-                add_action('admin_init', [$this, 'admin_init'], 10);
623
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
624
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
625
-                }
626
-            } else {
627
-                // hijack regular WP loading and route admin request immediately
628
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
629
-                $this->route_admin_request();
630
-            }
631
-        }
632
-    }
633
-
634
-
635
-    /**
636
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
637
-     *
638
-     * @return void
639
-     * @throws EE_Error
640
-     */
641
-    private function _do_other_page_hooks()
642
-    {
643
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
644
-        foreach ($registered_pages as $page) {
645
-            // now let's setup the file name and class that should be present
646
-            $classname = str_replace('.class.php', '', $page);
647
-            // autoloaders should take care of loading file
648
-            if (! class_exists($classname)) {
649
-                $error_msg[] = sprintf(
650
-                    esc_html__(
651
-                        'Something went wrong with loading the %s admin hooks page.',
652
-                        'event_espresso'
653
-                    ),
654
-                    $page
655
-                );
656
-                $error_msg[] = $error_msg[0]
657
-                               . "\r\n"
658
-                               . sprintf(
659
-                                   esc_html__(
660
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
661
-                                       'event_espresso'
662
-                                   ),
663
-                                   $page,
664
-                                   '<br />',
665
-                                   '<strong>' . $classname . '</strong>'
666
-                               );
667
-                throw new EE_Error(implode('||', $error_msg));
668
-            }
669
-            // notice we are passing the instance of this class to the hook object.
670
-            $this->loader->getShared($classname, [$this]);
671
-        }
672
-    }
673
-
674
-
675
-    /**
676
-     * @throws ReflectionException
677
-     * @throws EE_Error
678
-     */
679
-    public function load_page_dependencies()
680
-    {
681
-        try {
682
-            $this->_load_page_dependencies();
683
-        } catch (EE_Error $e) {
684
-            $e->get_error();
685
-        }
686
-    }
687
-
688
-
689
-    /**
690
-     * load_page_dependencies
691
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
692
-     *
693
-     * @return void
694
-     * @throws DomainException
695
-     * @throws EE_Error
696
-     * @throws InvalidArgumentException
697
-     * @throws InvalidDataTypeException
698
-     * @throws InvalidInterfaceException
699
-     */
700
-    protected function _load_page_dependencies()
701
-    {
702
-        // let's set the current_screen and screen options to override what WP set
703
-        $this->_current_screen = get_current_screen();
704
-        // load admin_notices - global, page class, and view specific
705
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
706
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
707
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
708
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
709
-        }
710
-        // load network admin_notices - global, page class, and view specific
711
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
712
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
713
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
714
-        }
715
-        // this will save any per_page screen options if they are present
716
-        $this->_set_per_page_screen_options();
717
-        // setup list table properties
718
-        $this->_set_list_table();
719
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
720
-        // However in some cases the metaboxes will need to be added within a route handling callback.
721
-        $this->_add_registered_meta_boxes();
722
-        $this->_add_screen_columns();
723
-        // add screen options - global, page child class, and view specific
724
-        $this->_add_global_screen_options();
725
-        $this->_add_screen_options();
726
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
727
-        if (method_exists($this, $add_screen_options)) {
728
-            $this->{$add_screen_options}();
729
-        }
730
-        // add help tab(s) and tours- set via page_config and qtips.
731
-        // $this->_add_help_tour();
732
-        $this->_add_help_tabs();
733
-        $this->_add_qtips();
734
-        // add feature_pointers - global, page child class, and view specific
735
-        $this->_add_feature_pointers();
736
-        $this->_add_global_feature_pointers();
737
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
738
-        if (method_exists($this, $add_feature_pointer)) {
739
-            $this->{$add_feature_pointer}();
740
-        }
741
-        // enqueue scripts/styles - global, page class, and view specific
742
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
743
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
744
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
745
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
746
-        }
747
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
748
-        // admin_print_footer_scripts - global, page child class, and view specific.
749
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
750
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
751
-        // is a good use case. Notice the late priority we're giving these
752
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
753
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
754
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
755
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
756
-        }
757
-        // admin footer scripts
758
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
759
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
760
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
761
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
762
-        }
763
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
764
-        // targeted hook
765
-        do_action(
766
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
767
-        );
768
-    }
769
-
770
-
771
-    /**
772
-     * _set_defaults
773
-     * This sets some global defaults for class properties.
774
-     */
775
-    private function _set_defaults()
776
-    {
777
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
778
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
779
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
780
-        $this->_page_config          = $this->_default_route_query_args = [];
781
-        $this->_default_nav_tab_name = 'overview';
782
-        // init template args
783
-        $this->_template_args = [
784
-            'admin_page_header'  => '',
785
-            'admin_page_content' => '',
786
-            'post_body_content'  => '',
787
-            'before_list_table'  => '',
788
-            'after_list_table'   => '',
789
-        ];
790
-    }
791
-
792
-
793
-    /**
794
-     * route_admin_request
795
-     *
796
-     * @return void
797
-     * @throws InvalidArgumentException
798
-     * @throws InvalidInterfaceException
799
-     * @throws InvalidDataTypeException
800
-     * @throws EE_Error
801
-     * @throws ReflectionException
802
-     * @see    _route_admin_request()
803
-     */
804
-    public function route_admin_request()
805
-    {
806
-        try {
807
-            $this->_route_admin_request();
808
-        } catch (EE_Error $e) {
809
-            $e->get_error();
810
-        }
811
-    }
812
-
813
-
814
-    public function set_wp_page_slug($wp_page_slug)
815
-    {
816
-        $this->_wp_page_slug = $wp_page_slug;
817
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
818
-        if (is_network_admin()) {
819
-            $this->_wp_page_slug .= '-network';
820
-        }
821
-    }
822
-
823
-
824
-    /**
825
-     * _verify_routes
826
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
827
-     * we know if we need to drop out.
828
-     *
829
-     * @return bool
830
-     * @throws EE_Error
831
-     */
832
-    protected function _verify_routes()
833
-    {
834
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
835
-        if (! $this->_current_page && ! $this->request->isAjax()) {
836
-            return false;
837
-        }
838
-        $this->_route = false;
839
-        // check that the page_routes array is not empty
840
-        if (empty($this->_page_routes)) {
841
-            // user error msg
842
-            $error_msg = sprintf(
843
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
844
-                $this->_admin_page_title
845
-            );
846
-            // developer error msg
847
-            $error_msg .= '||' . $error_msg
848
-                          . esc_html__(
849
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
850
-                              'event_espresso'
851
-                          );
852
-            throw new EE_Error($error_msg);
853
-        }
854
-        // and that the requested page route exists
855
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
856
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
857
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
858
-                ? $this->_page_config[ $this->_req_action ]
859
-                : [];
860
-        } else {
861
-            // user error msg
862
-            $error_msg = sprintf(
863
-                esc_html__(
864
-                    'The requested page route does not exist for the %s admin page.',
865
-                    'event_espresso'
866
-                ),
867
-                $this->_admin_page_title
868
-            );
869
-            // developer error msg
870
-            $error_msg .= '||' . $error_msg
871
-                          . sprintf(
872
-                              esc_html__(
873
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
874
-                                  'event_espresso'
875
-                              ),
876
-                              $this->_req_action
877
-                          );
878
-            throw new EE_Error($error_msg);
879
-        }
880
-        // and that a default route exists
881
-        if (! array_key_exists('default', $this->_page_routes)) {
882
-            // user error msg
883
-            $error_msg = sprintf(
884
-                esc_html__(
885
-                    'A default page route has not been set for the % admin page.',
886
-                    'event_espresso'
887
-                ),
888
-                $this->_admin_page_title
889
-            );
890
-            // developer error msg
891
-            $error_msg .= '||' . $error_msg
892
-                          . esc_html__(
893
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
894
-                              'event_espresso'
895
-                          );
896
-            throw new EE_Error($error_msg);
897
-        }
898
-        // first lets' catch if the UI request has EVER been set.
899
-        if ($this->_is_UI_request === null) {
900
-            // lets set if this is a UI request or not.
901
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
902
-            // wait a minute... we might have a noheader in the route array
903
-            $this->_is_UI_request = ! (
904
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
905
-            )
906
-                ? $this->_is_UI_request
907
-                : false;
908
-        }
909
-        $this->_set_current_labels();
910
-        return true;
911
-    }
912
-
913
-
914
-    /**
915
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
916
-     *
917
-     * @param string $route the route name we're verifying
918
-     * @return bool we'll throw an exception if this isn't a valid route.
919
-     * @throws EE_Error
920
-     */
921
-    protected function _verify_route($route)
922
-    {
923
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
924
-            return true;
925
-        }
926
-        // user error msg
927
-        $error_msg = sprintf(
928
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
929
-            $this->_admin_page_title
930
-        );
931
-        // developer error msg
932
-        $error_msg .= '||' . $error_msg
933
-                      . sprintf(
934
-                          esc_html__(
935
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
936
-                              'event_espresso'
937
-                          ),
938
-                          $route
939
-                      );
940
-        throw new EE_Error($error_msg);
941
-    }
942
-
943
-
944
-    /**
945
-     * perform nonce verification
946
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
947
-     * using this method (and save retyping!)
948
-     *
949
-     * @param string $nonce     The nonce sent
950
-     * @param string $nonce_ref The nonce reference string (name0)
951
-     * @return void
952
-     * @throws EE_Error
953
-     */
954
-    protected function _verify_nonce($nonce, $nonce_ref)
955
-    {
956
-        // verify nonce against expected value
957
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
958
-            // these are not the droids you are looking for !!!
959
-            $msg = sprintf(
960
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
961
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
962
-                '</a>'
963
-            );
964
-            if (WP_DEBUG) {
965
-                $msg .= "\n  ";
966
-                $msg .= sprintf(
967
-                    esc_html__(
968
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
969
-                        'event_espresso'
970
-                    ),
971
-                    __CLASS__
972
-                );
973
-            }
974
-            if (! $this->request->isAjax()) {
975
-                wp_die($msg);
976
-            }
977
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
978
-            $this->_return_json();
979
-        }
980
-    }
981
-
982
-
983
-    /**
984
-     * _route_admin_request()
985
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
986
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
987
-     * in the page routes and then will try to load the corresponding method.
988
-     *
989
-     * @return void
990
-     * @throws EE_Error
991
-     * @throws InvalidArgumentException
992
-     * @throws InvalidDataTypeException
993
-     * @throws InvalidInterfaceException
994
-     * @throws ReflectionException
995
-     */
996
-    protected function _route_admin_request()
997
-    {
998
-        if (! $this->_is_UI_request) {
999
-            $this->_verify_routes();
1000
-        }
1001
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1002
-        if ($this->_req_action !== 'default' && $nonce_check) {
1003
-            // set nonce from post data
1004
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
1005
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1006
-        }
1007
-        // set the nav_tabs array but ONLY if this is  UI_request
1008
-        if ($this->_is_UI_request) {
1009
-            $this->_set_nav_tabs();
1010
-        }
1011
-        // grab callback function
1012
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
1013
-        // check if callback has args
1014
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1015
-        $error_msg = '';
1016
-        // action right before calling route
1017
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1018
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1019
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1020
-        }
1021
-        // right before calling the route, let's clean the _wp_http_referer
1022
-        $this->request->setServerParam(
1023
-            'REQUEST_URI',
1024
-            remove_query_arg(
1025
-                '_wp_http_referer',
1026
-                wp_unslash($this->request->getServerParam('REQUEST_URI'))
1027
-            )
1028
-        );
1029
-        if (! empty($func)) {
1030
-            if (is_array($func)) {
1031
-                list($class, $method) = $func;
1032
-            } elseif (strpos($func, '::') !== false) {
1033
-                list($class, $method) = explode('::', $func);
1034
-            } else {
1035
-                $class  = $this;
1036
-                $method = $func;
1037
-            }
1038
-            if (! (is_object($class) && $class === $this)) {
1039
-                // send along this admin page object for access by addons.
1040
-                $args['admin_page_object'] = $this;
1041
-            }
1042
-            if (
1043
-                // is it a method on a class that doesn't work?
1044
-                (
1045
-                    (
1046
-                        method_exists($class, $method)
1047
-                        && call_user_func_array([$class, $method], $args) === false
1048
-                    )
1049
-                    && (
1050
-                        // is it a standalone function that doesn't work?
1051
-                        function_exists($method)
1052
-                        && call_user_func_array(
1053
-                            $func,
1054
-                            array_merge(['admin_page_object' => $this], $args)
1055
-                        ) === false
1056
-                    )
1057
-                )
1058
-                || (
1059
-                    // is it neither a class method NOR a standalone function?
1060
-                    ! method_exists($class, $method)
1061
-                    && ! function_exists($method)
1062
-                )
1063
-            ) {
1064
-                // user error msg
1065
-                $error_msg = esc_html__(
1066
-                    'An error occurred. The  requested page route could not be found.',
1067
-                    'event_espresso'
1068
-                );
1069
-                // developer error msg
1070
-                $error_msg .= '||';
1071
-                $error_msg .= sprintf(
1072
-                    esc_html__(
1073
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1074
-                        'event_espresso'
1075
-                    ),
1076
-                    $method
1077
-                );
1078
-            }
1079
-            if (! empty($error_msg)) {
1080
-                throw new EE_Error($error_msg);
1081
-            }
1082
-        }
1083
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1084
-        // then we need to reset the routing properties to the new route.
1085
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1086
-        if (
1087
-            $this->_is_UI_request === false
1088
-            && is_array($this->_route)
1089
-            && ! empty($this->_route['headers_sent_route'])
1090
-        ) {
1091
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1092
-        }
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * This method just allows the resetting of page properties in the case where a no headers
1098
-     * route redirects to a headers route in its route config.
1099
-     *
1100
-     * @param string $new_route New (non header) route to redirect to.
1101
-     * @return   void
1102
-     * @throws ReflectionException
1103
-     * @throws InvalidArgumentException
1104
-     * @throws InvalidInterfaceException
1105
-     * @throws InvalidDataTypeException
1106
-     * @throws EE_Error
1107
-     * @since   4.3.0
1108
-     */
1109
-    protected function _reset_routing_properties($new_route)
1110
-    {
1111
-        $this->_is_UI_request = true;
1112
-        // now we set the current route to whatever the headers_sent_route is set at
1113
-        $this->request->setRequestParam('action', $new_route);
1114
-        // rerun page setup
1115
-        $this->_page_setup();
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * _add_query_arg
1121
-     * adds nonce to array of arguments then calls WP add_query_arg function
1122
-     *(internally just uses EEH_URL's function with the same name)
1123
-     *
1124
-     * @param array  $args
1125
-     * @param string $url
1126
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1127
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1128
-     *                                        Example usage: If the current page is:
1129
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1130
-     *                                        &action=default&event_id=20&month_range=March%202015
1131
-     *                                        &_wpnonce=5467821
1132
-     *                                        and you call:
1133
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1134
-     *                                        array(
1135
-     *                                        'action' => 'resend_something',
1136
-     *                                        'page=>espresso_registrations'
1137
-     *                                        ),
1138
-     *                                        $some_url,
1139
-     *                                        true
1140
-     *                                        );
1141
-     *                                        It will produce a url in this structure:
1142
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1143
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1144
-     *                                        month_range]=March%202015
1145
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1146
-     * @return string
1147
-     */
1148
-    public static function add_query_args_and_nonce(
1149
-        $args = [],
1150
-        $url = false,
1151
-        $sticky = false,
1152
-        $exclude_nonce = false
1153
-    ) {
1154
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1155
-        if ($sticky) {
1156
-            /** @var RequestInterface $request */
1157
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1158
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1159
-            foreach ($request->requestParams() as $key => $value) {
1160
-                // do not add nonces
1161
-                if (strpos($key, 'nonce') !== false) {
1162
-                    continue;
1163
-                }
1164
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1165
-            }
1166
-        }
1167
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * This returns a generated link that will load the related help tab.
1173
-     *
1174
-     * @param string $help_tab_id the id for the connected help tab
1175
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1176
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1177
-     * @return string              generated link
1178
-     * @uses EEH_Template::get_help_tab_link()
1179
-     */
1180
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1181
-    {
1182
-        return EEH_Template::get_help_tab_link(
1183
-            $help_tab_id,
1184
-            $this->page_slug,
1185
-            $this->_req_action,
1186
-            $icon_style,
1187
-            $help_text
1188
-        );
1189
-    }
1190
-
1191
-
1192
-    /**
1193
-     * _add_help_tabs
1194
-     * Note child classes define their help tabs within the page_config array.
1195
-     *
1196
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1197
-     * @return void
1198
-     * @throws DomainException
1199
-     * @throws EE_Error
1200
-     */
1201
-    protected function _add_help_tabs()
1202
-    {
1203
-        $tour_buttons = '';
1204
-        if (isset($this->_page_config[ $this->_req_action ])) {
1205
-            $config = $this->_page_config[ $this->_req_action ];
1206
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1207
-            // is there a help tour for the current route?  if there is let's setup the tour buttons
1208
-            // if (isset($this->_help_tour[ $this->_req_action ])) {
1209
-            //     $tb = array();
1210
-            //     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1211
-            //     foreach ($this->_help_tour['tours'] as $tour) {
1212
-            //         // if this is the end tour then we don't need to setup a button
1213
-            //         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1214
-            //             continue;
1215
-            //         }
1216
-            //         $tb[] = '<button id="trigger-tour-'
1217
-            //                 . $tour->get_slug()
1218
-            //                 . '" class="button-primary trigger-ee-help-tour">'
1219
-            //                 . $tour->get_label()
1220
-            //                 . '</button>';
1221
-            //     }
1222
-            //     $tour_buttons .= implode('<br />', $tb);
1223
-            //     $tour_buttons .= '</div></div>';
1224
-            // }
1225
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1226
-            if (is_array($config) && isset($config['help_sidebar'])) {
1227
-                // check that the callback given is valid
1228
-                if (! method_exists($this, $config['help_sidebar'])) {
1229
-                    throw new EE_Error(
1230
-                        sprintf(
1231
-                            esc_html__(
1232
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1233
-                                'event_espresso'
1234
-                            ),
1235
-                            $config['help_sidebar'],
1236
-                            get_class($this)
1237
-                        )
1238
-                    );
1239
-                }
1240
-                $content = apply_filters(
1241
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1242
-                    $this->{$config['help_sidebar']}()
1243
-                );
1244
-                $content .= $tour_buttons; // add help tour buttons.
1245
-                // do we have any help tours setup?  Cause if we do we want to add the buttons
1246
-                $this->_current_screen->set_help_sidebar($content);
1247
-            }
1248
-            // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1249
-            if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1250
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1251
-            }
1252
-            // handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1253
-            if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1254
-                $_ht['id']      = $this->page_slug;
1255
-                $_ht['title']   = esc_html__('Help Tours', 'event_espresso');
1256
-                $_ht['content'] = '<p>'
1257
-                                  . esc_html__(
1258
-                                      'The buttons to the right allow you to start/restart any help tours available for this page',
1259
-                                      'event_espresso'
1260
-                                  ) . '</p>';
1261
-                $this->_current_screen->add_help_tab($_ht);
1262
-            }
1263
-            if (! isset($config['help_tabs'])) {
1264
-                return;
1265
-            } //no help tabs for this route
1266
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1267
-                // we're here so there ARE help tabs!
1268
-                // make sure we've got what we need
1269
-                if (! isset($cfg['title'])) {
1270
-                    throw new EE_Error(
1271
-                        esc_html__(
1272
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1273
-                            'event_espresso'
1274
-                        )
1275
-                    );
1276
-                }
1277
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1278
-                    throw new EE_Error(
1279
-                        esc_html__(
1280
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1281
-                            'event_espresso'
1282
-                        )
1283
-                    );
1284
-                }
1285
-                // first priority goes to content.
1286
-                if (! empty($cfg['content'])) {
1287
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1288
-                    // second priority goes to filename
1289
-                } elseif (! empty($cfg['filename'])) {
1290
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1291
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1292
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1293
-                                                             . basename($this->_get_dir())
1294
-                                                             . '/help_tabs/'
1295
-                                                             . $cfg['filename']
1296
-                                                             . '.help_tab.php' : $file_path;
1297
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1298
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1299
-                        EE_Error::add_error(
1300
-                            sprintf(
1301
-                                esc_html__(
1302
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1303
-                                    'event_espresso'
1304
-                                ),
1305
-                                $tab_id,
1306
-                                key($config),
1307
-                                $file_path
1308
-                            ),
1309
-                            __FILE__,
1310
-                            __FUNCTION__,
1311
-                            __LINE__
1312
-                        );
1313
-                        return;
1314
-                    }
1315
-                    $template_args['admin_page_obj'] = $this;
1316
-                    $content                         = EEH_Template::display_template(
1317
-                        $file_path,
1318
-                        $template_args,
1319
-                        true
1320
-                    );
1321
-                } else {
1322
-                    $content = '';
1323
-                }
1324
-                // check if callback is valid
1325
-                if (
1326
-                    empty($content)
1327
-                    && (
1328
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1329
-                    )
1330
-                ) {
1331
-                    EE_Error::add_error(
1332
-                        sprintf(
1333
-                            esc_html__(
1334
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1335
-                                'event_espresso'
1336
-                            ),
1337
-                            $cfg['title']
1338
-                        ),
1339
-                        __FILE__,
1340
-                        __FUNCTION__,
1341
-                        __LINE__
1342
-                    );
1343
-                    return;
1344
-                }
1345
-                // setup config array for help tab method
1346
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1347
-                $_ht = [
1348
-                    'id'       => $id,
1349
-                    'title'    => $cfg['title'],
1350
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1351
-                    'content'  => $content,
1352
-                ];
1353
-                $this->_current_screen->add_help_tab($_ht);
1354
-            }
1355
-        }
1356
-    }
1357
-
1358
-
1359
-    /**
1360
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1361
-     * an array with properties for setting up usage of the joyride plugin
1362
-     *
1363
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1364
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1365
-     *         _set_page_config() comments
1366
-     * @return void
1367
-     * @throws InvalidArgumentException
1368
-     * @throws InvalidDataTypeException
1369
-     * @throws InvalidInterfaceException
1370
-     */
1371
-    protected function _add_help_tour()
1372
-    {
1373
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1374
-        // $tours = array();
1375
-        // $this->_help_tour = array();
1376
-        // // exit early if help tours are turned off globally
1377
-        // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1378
-        //     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1379
-        // ) {
1380
-        //     return;
1381
-        // }
1382
-        // // loop through _page_config to find any help_tour defined
1383
-        // foreach ($this->_page_config as $route => $config) {
1384
-        //     // we're only going to set things up for this route
1385
-        //     if ($route !== $this->_req_action) {
1386
-        //         continue;
1387
-        //     }
1388
-        //     if (isset($config['help_tour'])) {
1389
-        //         foreach ($config['help_tour'] as $tour) {
1390
-        //             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1391
-        //             // let's see if we can get that file...
1392
-        //             // if not its possible this is a decaf route not set in caffeinated
1393
-        //             // so lets try and get the caffeinated equivalent
1394
-        //             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1395
-        //                                                      . basename($this->_get_dir())
1396
-        //                                                      . '/help_tours/'
1397
-        //                                                      . $tour
1398
-        //                                                      . '.class.php' : $file_path;
1399
-        //             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1400
-        //             if (! is_readable($file_path)) {
1401
-        //                 EE_Error::add_error(
1402
-        //                     sprintf(
1403
-        //                         esc_html__(
1404
-        //                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1405
-        //                             'event_espresso'
1406
-        //                         ),
1407
-        //                         $file_path,
1408
-        //                         $tour
1409
-        //                     ),
1410
-        //                     __FILE__,
1411
-        //                     __FUNCTION__,
1412
-        //                     __LINE__
1413
-        //                 );
1414
-        //                 return;
1415
-        //             }
1416
-        //             require_once $file_path;
1417
-        //             if (! class_exists($tour)) {
1418
-        //                 $error_msg[] = sprintf(
1419
-        //                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1420
-        //                     $tour
1421
-        //                 );
1422
-        //                 $error_msg[] = $error_msg[0] . "\r\n"
1423
-        //                                . sprintf(
1424
-        //                                    esc_html__(
1425
-        //                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1426
-        //                                        'event_espresso'
1427
-        //                                    ),
1428
-        //                                    $tour,
1429
-        //                                    '<br />',
1430
-        //                                    $tour,
1431
-        //                                    $this->_req_action,
1432
-        //                                    get_class($this)
1433
-        //                                );
1434
-        //                 throw new EE_Error(implode('||', $error_msg));
1435
-        //             }
1436
-        //             $tour_obj = new $tour($this->_is_caf);
1437
-        //             $tours[] = $tour_obj;
1438
-        //             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1439
-        //         }
1440
-        //         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1441
-        //         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1442
-        //         $tours[] = $end_stop_tour;
1443
-        //         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1444
-        //     }
1445
-        // }
1446
-        //
1447
-        // if (! empty($tours)) {
1448
-        //     $this->_help_tour['tours'] = $tours;
1449
-        // }
1450
-        // // that's it!  Now that the $_help_tours property is set (or not)
1451
-        // // the scripts and html should be taken care of automatically.
1452
-        //
1453
-        // /**
1454
-        //  * Allow extending the help tours variable.
1455
-        //  *
1456
-        //  * @param Array $_help_tour The array containing all help tour information to be displayed.
1457
-        //  */
1458
-        // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1459
-    }
1460
-
1461
-
1462
-    /**
1463
-     * This simply sets up any qtips that have been defined in the page config
1464
-     *
1465
-     * @return void
1466
-     */
1467
-    protected function _add_qtips()
1468
-    {
1469
-        if (isset($this->_route_config['qtips'])) {
1470
-            $qtips = (array) $this->_route_config['qtips'];
1471
-            // load qtip loader
1472
-            $path = [
1473
-                $this->_get_dir() . '/qtips/',
1474
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1475
-            ];
1476
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1477
-        }
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * _set_nav_tabs
1483
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1484
-     * wish to add additional tabs or modify accordingly.
1485
-     *
1486
-     * @return void
1487
-     * @throws InvalidArgumentException
1488
-     * @throws InvalidInterfaceException
1489
-     * @throws InvalidDataTypeException
1490
-     */
1491
-    protected function _set_nav_tabs()
1492
-    {
1493
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1494
-        $i = 0;
1495
-        foreach ($this->_page_config as $slug => $config) {
1496
-            if (! is_array($config) || empty($config['nav'])) {
1497
-                continue;
1498
-            }
1499
-            // no nav tab for this config
1500
-            // check for persistent flag
1501
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1502
-                // nav tab is only to appear when route requested.
1503
-                continue;
1504
-            }
1505
-            if (! $this->check_user_access($slug, true)) {
1506
-                // no nav tab because current user does not have access.
1507
-                continue;
1508
-            }
1509
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1510
-            $this->_nav_tabs[ $slug ] = [
1511
-                'url'       => isset($config['nav']['url'])
1512
-                    ? $config['nav']['url']
1513
-                    : self::add_query_args_and_nonce(
1514
-                        ['action' => $slug],
1515
-                        $this->_admin_base_url
1516
-                    ),
1517
-                'link_text' => isset($config['nav']['label'])
1518
-                    ? $config['nav']['label']
1519
-                    : ucwords(
1520
-                        str_replace('_', ' ', $slug)
1521
-                    ),
1522
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1523
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1524
-            ];
1525
-            $i++;
1526
-        }
1527
-        // if $this->_nav_tabs is empty then lets set the default
1528
-        if (empty($this->_nav_tabs)) {
1529
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1530
-                'url'       => $this->_admin_base_url,
1531
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1532
-                'css_class' => 'nav-tab-active',
1533
-                'order'     => 10,
1534
-            ];
1535
-        }
1536
-        // now let's sort the tabs according to order
1537
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1538
-    }
1539
-
1540
-
1541
-    /**
1542
-     * _set_current_labels
1543
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1544
-     * property array
1545
-     *
1546
-     * @return void
1547
-     */
1548
-    private function _set_current_labels()
1549
-    {
1550
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1551
-            foreach ($this->_route_config['labels'] as $label => $text) {
1552
-                if (is_array($text)) {
1553
-                    foreach ($text as $sublabel => $subtext) {
1554
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1555
-                    }
1556
-                } else {
1557
-                    $this->_labels[ $label ] = $text;
1558
-                }
1559
-            }
1560
-        }
1561
-    }
1562
-
1563
-
1564
-    /**
1565
-     *        verifies user access for this admin page
1566
-     *
1567
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1568
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1569
-     *                               return false if verify fail.
1570
-     * @return bool
1571
-     * @throws InvalidArgumentException
1572
-     * @throws InvalidDataTypeException
1573
-     * @throws InvalidInterfaceException
1574
-     */
1575
-    public function check_user_access($route_to_check = '', $verify_only = false)
1576
-    {
1577
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1578
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1579
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1580
-                          && is_array(
1581
-                              $this->_page_routes[ $route_to_check ]
1582
-                          )
1583
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1584
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1585
-        if (empty($capability) && empty($route_to_check)) {
1586
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1587
-                : $this->_route['capability'];
1588
-        } else {
1589
-            $capability = empty($capability) ? 'manage_options' : $capability;
1590
-        }
1591
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1592
-        if (
1593
-            ! $this->request->isAjax()
1594
-            && (
1595
-                ! function_exists('is_admin')
1596
-                || ! EE_Registry::instance()->CAP->current_user_can(
1597
-                    $capability,
1598
-                    $this->page_slug
1599
-                    . '_'
1600
-                    . $route_to_check,
1601
-                    $id
1602
-                )
1603
-            )
1604
-        ) {
1605
-            if ($verify_only) {
1606
-                return false;
1607
-            }
1608
-            if (is_user_logged_in()) {
1609
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1610
-            } else {
1611
-                return false;
1612
-            }
1613
-        }
1614
-        return true;
1615
-    }
1616
-
1617
-
1618
-    /**
1619
-     * admin_init_global
1620
-     * This runs all the code that we want executed within the WP admin_init hook.
1621
-     * This method executes for ALL EE Admin pages.
1622
-     *
1623
-     * @return void
1624
-     */
1625
-    public function admin_init_global()
1626
-    {
1627
-    }
1628
-
1629
-
1630
-    /**
1631
-     * wp_loaded_global
1632
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1633
-     * EE_Admin page and will execute on every EE Admin Page load
1634
-     *
1635
-     * @return void
1636
-     */
1637
-    public function wp_loaded()
1638
-    {
1639
-    }
1640
-
1641
-
1642
-    /**
1643
-     * admin_notices
1644
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1645
-     * ALL EE_Admin pages.
1646
-     *
1647
-     * @return void
1648
-     */
1649
-    public function admin_notices_global()
1650
-    {
1651
-        $this->_display_no_javascript_warning();
1652
-        $this->_display_espresso_notices();
1653
-    }
1654
-
1655
-
1656
-    public function network_admin_notices_global()
1657
-    {
1658
-        $this->_display_no_javascript_warning();
1659
-        $this->_display_espresso_notices();
1660
-    }
1661
-
1662
-
1663
-    /**
1664
-     * admin_footer_scripts_global
1665
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1666
-     * will apply on ALL EE_Admin pages.
1667
-     *
1668
-     * @return void
1669
-     */
1670
-    public function admin_footer_scripts_global()
1671
-    {
1672
-        $this->_add_admin_page_ajax_loading_img();
1673
-        $this->_add_admin_page_overlay();
1674
-        // if metaboxes are present we need to add the nonce field
1675
-        if (
1676
-            isset($this->_route_config['metaboxes'])
1677
-            || isset($this->_route_config['list_table'])
1678
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1679
-        ) {
1680
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1681
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1682
-        }
1683
-    }
1684
-
1685
-
1686
-    /**
1687
-     * admin_footer_global
1688
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1689
-     * ALL EE_Admin Pages.
1690
-     *
1691
-     * @return void
1692
-     */
1693
-    public function admin_footer_global()
1694
-    {
1695
-        // dialog container for dialog helper
1696
-        echo '
115
+	/**
116
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
117
+	 * actions.
118
+	 *
119
+	 * @since 4.6.x
120
+	 * @var array.
121
+	 */
122
+	protected $_default_route_query_args;
123
+
124
+	// set via request page and action args.
125
+	protected $_current_page;
126
+
127
+	protected $_current_view;
128
+
129
+	protected $_current_page_view_url;
130
+
131
+	/**
132
+	 * unprocessed value for the 'action' request param (default '')
133
+	 *
134
+	 * @var string
135
+	 */
136
+	protected $raw_req_action = '';
137
+
138
+	/**
139
+	 * unprocessed value for the 'page' request param (default '')
140
+	 *
141
+	 * @var string
142
+	 */
143
+	protected $raw_req_page = '';
144
+
145
+	/**
146
+	 * sanitized request action (and nonce)
147
+	 *
148
+	 * @var string
149
+	 */
150
+	protected $_req_action = '';
151
+
152
+	/**
153
+	 * sanitized request action nonce
154
+	 *
155
+	 * @var string
156
+	 */
157
+	protected $_req_nonce = '';
158
+
159
+	/**
160
+	 * @var string
161
+	 */
162
+	protected $_search_btn_label = '';
163
+
164
+	/**
165
+	 * @var string
166
+	 */
167
+	protected $_search_box_callback = '';
168
+
169
+	/**
170
+	 * @var WP_Screen
171
+	 */
172
+	protected $_current_screen;
173
+
174
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
175
+	protected $_hook_obj;
176
+
177
+	// for holding incoming request data
178
+	protected $_req_data = [];
179
+
180
+	// yes / no array for admin form fields
181
+	protected $_yes_no_values = [];
182
+
183
+	// some default things shared by all child classes
184
+	protected $_default_espresso_metaboxes;
185
+
186
+	/**
187
+	 * @var EE_Registry
188
+	 */
189
+	protected $EE = null;
190
+
191
+
192
+	/**
193
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
194
+	 *
195
+	 * @var boolean
196
+	 */
197
+	protected $_is_caf = false;
198
+
199
+
200
+	/**
201
+	 * @Constructor
202
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
203
+	 * @throws EE_Error
204
+	 * @throws InvalidArgumentException
205
+	 * @throws ReflectionException
206
+	 * @throws InvalidDataTypeException
207
+	 * @throws InvalidInterfaceException
208
+	 */
209
+	public function __construct($routing = true)
210
+	{
211
+		$this->loader  = LoaderFactory::getLoader();
212
+		$this->request = $this->loader->getShared(RequestInterface::class);
213
+		$this->_routing = $routing;
214
+
215
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
216
+			$this->_is_caf = true;
217
+		}
218
+		$this->_yes_no_values = [
219
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
220
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
221
+		];
222
+		// set the _req_data property.
223
+		$this->_req_data = $this->request->requestParams();
224
+		// set initial page props (child method)
225
+		$this->_init_page_props();
226
+		// set global defaults
227
+		$this->_set_defaults();
228
+		// set early because incoming requests could be ajax related and we need to register those hooks.
229
+		$this->_global_ajax_hooks();
230
+		$this->_ajax_hooks();
231
+		// other_page_hooks have to be early too.
232
+		$this->_do_other_page_hooks();
233
+		// set up page dependencies
234
+		$this->_before_page_setup();
235
+		$this->_page_setup();
236
+		// die();
237
+	}
238
+
239
+
240
+	/**
241
+	 * _init_page_props
242
+	 * Child classes use to set at least the following properties:
243
+	 * $page_slug.
244
+	 * $page_label.
245
+	 *
246
+	 * @abstract
247
+	 * @return void
248
+	 */
249
+	abstract protected function _init_page_props();
250
+
251
+
252
+	/**
253
+	 * _ajax_hooks
254
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
255
+	 * Note: within the ajax callback methods.
256
+	 *
257
+	 * @abstract
258
+	 * @return void
259
+	 */
260
+	abstract protected function _ajax_hooks();
261
+
262
+
263
+	/**
264
+	 * _define_page_props
265
+	 * child classes define page properties in here.  Must include at least:
266
+	 * $_admin_base_url = base_url for all admin pages
267
+	 * $_admin_page_title = default admin_page_title for admin pages
268
+	 * $_labels = array of default labels for various automatically generated elements:
269
+	 *    array(
270
+	 *        'buttons' => array(
271
+	 *            'add' => esc_html__('label for add new button'),
272
+	 *            'edit' => esc_html__('label for edit button'),
273
+	 *            'delete' => esc_html__('label for delete button')
274
+	 *            )
275
+	 *        )
276
+	 *
277
+	 * @abstract
278
+	 * @return void
279
+	 */
280
+	abstract protected function _define_page_props();
281
+
282
+
283
+	/**
284
+	 * _set_page_routes
285
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
286
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
287
+	 * have a 'default' route. Here's the format
288
+	 * $this->_page_routes = array(
289
+	 *        'default' => array(
290
+	 *            'func' => '_default_method_handling_route',
291
+	 *            'args' => array('array','of','args'),
292
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
293
+	 *            ajax request, backend processing)
294
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
295
+	 *            headers route after.  The string you enter here should match the defined route reference for a
296
+	 *            headers sent route.
297
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
298
+	 *            this route.
299
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
300
+	 *            checks).
301
+	 *        ),
302
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
303
+	 *        handling method.
304
+	 *        )
305
+	 * )
306
+	 *
307
+	 * @abstract
308
+	 * @return void
309
+	 */
310
+	abstract protected function _set_page_routes();
311
+
312
+
313
+	/**
314
+	 * _set_page_config
315
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
316
+	 * array corresponds to the page_route for the loaded page. Format:
317
+	 * $this->_page_config = array(
318
+	 *        'default' => array(
319
+	 *            'labels' => array(
320
+	 *                'buttons' => array(
321
+	 *                    'add' => esc_html__('label for adding item'),
322
+	 *                    'edit' => esc_html__('label for editing item'),
323
+	 *                    'delete' => esc_html__('label for deleting item')
324
+	 *                ),
325
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
326
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
327
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
328
+	 *            _define_page_props() method
329
+	 *            'nav' => array(
330
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
331
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
332
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
333
+	 *                'order' => 10, //required to indicate tab position.
334
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
335
+	 *                displayed then add this parameter.
336
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
337
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
338
+	 *            metaboxes set for eventespresso admin pages.
339
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
340
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
341
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
342
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
343
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
344
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
345
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
346
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
347
+	 *            want to display.
348
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
349
+	 *                'tab_id' => array(
350
+	 *                    'title' => 'tab_title',
351
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
352
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
353
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
354
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
355
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
356
+	 *                    attempt to use the callback which should match the name of a method in the class
357
+	 *                    ),
358
+	 *                'tab2_id' => array(
359
+	 *                    'title' => 'tab2 title',
360
+	 *                    'filename' => 'file_name_2'
361
+	 *                    'callback' => 'callback_method_for_content',
362
+	 *                 ),
363
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
364
+	 *            help tab area on an admin page. @return void
365
+	 *
366
+	 * @link
367
+	 *                http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
368
+	 *                'help_tour' => array(
369
+	 *                'name_of_help_tour_class', //all help tours should be a child class of EE_Help_Tour and located
370
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
371
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
372
+	 *                ),
373
+	 *                'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default
374
+	 *                is true if it isn't present).  To remove the requirement for a nonce check when this route is
375
+	 *                visited just set
376
+	 *                'require_nonce' to FALSE
377
+	 *                )
378
+	 *                )
379
+	 *
380
+	 * @abstract
381
+	 */
382
+	abstract protected function _set_page_config();
383
+
384
+
385
+
386
+
387
+
388
+	/** end sample help_tour methods **/
389
+	/**
390
+	 * _add_screen_options
391
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
392
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
393
+	 * to a particular view.
394
+	 *
395
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
396
+	 *         see also WP_Screen object documents...
397
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
398
+	 * @abstract
399
+	 * @return void
400
+	 */
401
+	abstract protected function _add_screen_options();
402
+
403
+
404
+	/**
405
+	 * _add_feature_pointers
406
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
407
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
408
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
409
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
410
+	 * extended) also see:
411
+	 *
412
+	 * @link   http://eamann.com/tech/wordpress-portland/
413
+	 * @abstract
414
+	 * @return void
415
+	 */
416
+	abstract protected function _add_feature_pointers();
417
+
418
+
419
+	/**
420
+	 * load_scripts_styles
421
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
422
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
423
+	 * scripts/styles per view by putting them in a dynamic function in this format
424
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
425
+	 *
426
+	 * @abstract
427
+	 * @return void
428
+	 */
429
+	abstract public function load_scripts_styles();
430
+
431
+
432
+	/**
433
+	 * admin_init
434
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
435
+	 * all pages/views loaded by child class.
436
+	 *
437
+	 * @abstract
438
+	 * @return void
439
+	 */
440
+	abstract public function admin_init();
441
+
442
+
443
+	/**
444
+	 * admin_notices
445
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
446
+	 * all pages/views loaded by child class.
447
+	 *
448
+	 * @abstract
449
+	 * @return void
450
+	 */
451
+	abstract public function admin_notices();
452
+
453
+
454
+	/**
455
+	 * admin_footer_scripts
456
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
457
+	 * will apply to all pages/views loaded by child class.
458
+	 *
459
+	 * @return void
460
+	 */
461
+	abstract public function admin_footer_scripts();
462
+
463
+
464
+	/**
465
+	 * admin_footer
466
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
467
+	 * apply to all pages/views loaded by child class.
468
+	 *
469
+	 * @return void
470
+	 */
471
+	public function admin_footer()
472
+	{
473
+	}
474
+
475
+
476
+	/**
477
+	 * _global_ajax_hooks
478
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
479
+	 * Note: within the ajax callback methods.
480
+	 *
481
+	 * @abstract
482
+	 * @return void
483
+	 */
484
+	protected function _global_ajax_hooks()
485
+	{
486
+		// for lazy loading of metabox content
487
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
488
+	}
489
+
490
+
491
+	public function ajax_metabox_content()
492
+	{
493
+		$content_id  = $this->request->getRequestParam('contentid', '');
494
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
495
+		self::cached_rss_display($content_id, $content_url);
496
+		wp_die();
497
+	}
498
+
499
+
500
+	/**
501
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
502
+	 *
503
+	 * @return void
504
+	 */
505
+	protected function _before_page_setup()
506
+	{
507
+		// default is to do nothing
508
+	}
509
+
510
+
511
+	/**
512
+	 * Makes sure any things that need to be loaded early get handled.
513
+	 * We also escape early here if the page requested doesn't match the object.
514
+	 *
515
+	 * @final
516
+	 * @return void
517
+	 * @throws EE_Error
518
+	 * @throws InvalidArgumentException
519
+	 * @throws ReflectionException
520
+	 * @throws InvalidDataTypeException
521
+	 * @throws InvalidInterfaceException
522
+	 */
523
+	final protected function _page_setup()
524
+	{
525
+		// requires?
526
+		// admin_init stuff - global - we're setting this REALLY early
527
+		// so if EE_Admin pages have to hook into other WP pages they can.
528
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
529
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
530
+		// next verify if we need to load anything...
531
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
532
+		$this->page_folder   = strtolower(
533
+			str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
534
+		);
535
+		global $ee_menu_slugs;
536
+		$ee_menu_slugs = (array) $ee_menu_slugs;
537
+		if (
538
+			! $this->request->isAjax()
539
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
540
+		) {
541
+			return;
542
+		}
543
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
544
+		// we need to copy the action from the second to the first
545
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
546
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
547
+		$action     = $action !== '-1' ? $action : $action2;
548
+		$req_action = $action !== '-1' ? $action : 'default';
549
+
550
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
551
+		// then let's use the route as the action.
552
+		// This covers cases where we're coming in from a list table that isn't on the default route.
553
+		$route = $this->request->getRequestParam('route');
554
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
555
+			? $route
556
+			: $req_action;
557
+
558
+		$this->_current_view = $this->_req_action;
559
+		$this->_req_nonce    = $this->_req_action . '_nonce';
560
+		$this->_define_page_props();
561
+		$this->_current_page_view_url = add_query_arg(
562
+			['page' => $this->_current_page, 'action' => $this->_current_view],
563
+			$this->_admin_base_url
564
+		);
565
+		// default things
566
+		$this->_default_espresso_metaboxes = [
567
+			'_espresso_news_post_box',
568
+			'_espresso_links_post_box',
569
+			'_espresso_ratings_request',
570
+			'_espresso_sponsors_post_box',
571
+		];
572
+		// set page configs
573
+		$this->_set_page_routes();
574
+		$this->_set_page_config();
575
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
576
+		if ($this->request->requestParamIsSet('wp_referer')) {
577
+			$wp_referer = $this->request->getRequestParam('wp_referer');
578
+			if ($wp_referer) {
579
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
580
+			}
581
+		}
582
+		// for caffeinated and other extended functionality.
583
+		//  If there is a _extend_page_config method
584
+		// then let's run that to modify the all the various page configuration arrays
585
+		if (method_exists($this, '_extend_page_config')) {
586
+			$this->_extend_page_config();
587
+		}
588
+		// for CPT and other extended functionality.
589
+		// If there is an _extend_page_config_for_cpt
590
+		// then let's run that to modify all the various page configuration arrays.
591
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
592
+			$this->_extend_page_config_for_cpt();
593
+		}
594
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
595
+		$this->_page_routes = apply_filters(
596
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
597
+			$this->_page_routes,
598
+			$this
599
+		);
600
+		$this->_page_config = apply_filters(
601
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
602
+			$this->_page_config,
603
+			$this
604
+		);
605
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
606
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
607
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
608
+			add_action(
609
+				'AHEE__EE_Admin_Page__route_admin_request',
610
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
611
+				10,
612
+				2
613
+			);
614
+		}
615
+		// next route only if routing enabled
616
+		if ($this->_routing && ! $this->request->isAjax()) {
617
+			$this->_verify_routes();
618
+			// next let's just check user_access and kill if no access
619
+			$this->check_user_access();
620
+			if ($this->_is_UI_request) {
621
+				// admin_init stuff - global, all views for this page class, specific view
622
+				add_action('admin_init', [$this, 'admin_init'], 10);
623
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
624
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
625
+				}
626
+			} else {
627
+				// hijack regular WP loading and route admin request immediately
628
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
629
+				$this->route_admin_request();
630
+			}
631
+		}
632
+	}
633
+
634
+
635
+	/**
636
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
637
+	 *
638
+	 * @return void
639
+	 * @throws EE_Error
640
+	 */
641
+	private function _do_other_page_hooks()
642
+	{
643
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
644
+		foreach ($registered_pages as $page) {
645
+			// now let's setup the file name and class that should be present
646
+			$classname = str_replace('.class.php', '', $page);
647
+			// autoloaders should take care of loading file
648
+			if (! class_exists($classname)) {
649
+				$error_msg[] = sprintf(
650
+					esc_html__(
651
+						'Something went wrong with loading the %s admin hooks page.',
652
+						'event_espresso'
653
+					),
654
+					$page
655
+				);
656
+				$error_msg[] = $error_msg[0]
657
+							   . "\r\n"
658
+							   . sprintf(
659
+								   esc_html__(
660
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
661
+									   'event_espresso'
662
+								   ),
663
+								   $page,
664
+								   '<br />',
665
+								   '<strong>' . $classname . '</strong>'
666
+							   );
667
+				throw new EE_Error(implode('||', $error_msg));
668
+			}
669
+			// notice we are passing the instance of this class to the hook object.
670
+			$this->loader->getShared($classname, [$this]);
671
+		}
672
+	}
673
+
674
+
675
+	/**
676
+	 * @throws ReflectionException
677
+	 * @throws EE_Error
678
+	 */
679
+	public function load_page_dependencies()
680
+	{
681
+		try {
682
+			$this->_load_page_dependencies();
683
+		} catch (EE_Error $e) {
684
+			$e->get_error();
685
+		}
686
+	}
687
+
688
+
689
+	/**
690
+	 * load_page_dependencies
691
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
692
+	 *
693
+	 * @return void
694
+	 * @throws DomainException
695
+	 * @throws EE_Error
696
+	 * @throws InvalidArgumentException
697
+	 * @throws InvalidDataTypeException
698
+	 * @throws InvalidInterfaceException
699
+	 */
700
+	protected function _load_page_dependencies()
701
+	{
702
+		// let's set the current_screen and screen options to override what WP set
703
+		$this->_current_screen = get_current_screen();
704
+		// load admin_notices - global, page class, and view specific
705
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
706
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
707
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
708
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
709
+		}
710
+		// load network admin_notices - global, page class, and view specific
711
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
712
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
713
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
714
+		}
715
+		// this will save any per_page screen options if they are present
716
+		$this->_set_per_page_screen_options();
717
+		// setup list table properties
718
+		$this->_set_list_table();
719
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
720
+		// However in some cases the metaboxes will need to be added within a route handling callback.
721
+		$this->_add_registered_meta_boxes();
722
+		$this->_add_screen_columns();
723
+		// add screen options - global, page child class, and view specific
724
+		$this->_add_global_screen_options();
725
+		$this->_add_screen_options();
726
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
727
+		if (method_exists($this, $add_screen_options)) {
728
+			$this->{$add_screen_options}();
729
+		}
730
+		// add help tab(s) and tours- set via page_config and qtips.
731
+		// $this->_add_help_tour();
732
+		$this->_add_help_tabs();
733
+		$this->_add_qtips();
734
+		// add feature_pointers - global, page child class, and view specific
735
+		$this->_add_feature_pointers();
736
+		$this->_add_global_feature_pointers();
737
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
738
+		if (method_exists($this, $add_feature_pointer)) {
739
+			$this->{$add_feature_pointer}();
740
+		}
741
+		// enqueue scripts/styles - global, page class, and view specific
742
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
743
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
744
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
745
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
746
+		}
747
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
748
+		// admin_print_footer_scripts - global, page child class, and view specific.
749
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
750
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
751
+		// is a good use case. Notice the late priority we're giving these
752
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
753
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
754
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
755
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
756
+		}
757
+		// admin footer scripts
758
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
759
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
760
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
761
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
762
+		}
763
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
764
+		// targeted hook
765
+		do_action(
766
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
767
+		);
768
+	}
769
+
770
+
771
+	/**
772
+	 * _set_defaults
773
+	 * This sets some global defaults for class properties.
774
+	 */
775
+	private function _set_defaults()
776
+	{
777
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
778
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
779
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
780
+		$this->_page_config          = $this->_default_route_query_args = [];
781
+		$this->_default_nav_tab_name = 'overview';
782
+		// init template args
783
+		$this->_template_args = [
784
+			'admin_page_header'  => '',
785
+			'admin_page_content' => '',
786
+			'post_body_content'  => '',
787
+			'before_list_table'  => '',
788
+			'after_list_table'   => '',
789
+		];
790
+	}
791
+
792
+
793
+	/**
794
+	 * route_admin_request
795
+	 *
796
+	 * @return void
797
+	 * @throws InvalidArgumentException
798
+	 * @throws InvalidInterfaceException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws EE_Error
801
+	 * @throws ReflectionException
802
+	 * @see    _route_admin_request()
803
+	 */
804
+	public function route_admin_request()
805
+	{
806
+		try {
807
+			$this->_route_admin_request();
808
+		} catch (EE_Error $e) {
809
+			$e->get_error();
810
+		}
811
+	}
812
+
813
+
814
+	public function set_wp_page_slug($wp_page_slug)
815
+	{
816
+		$this->_wp_page_slug = $wp_page_slug;
817
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
818
+		if (is_network_admin()) {
819
+			$this->_wp_page_slug .= '-network';
820
+		}
821
+	}
822
+
823
+
824
+	/**
825
+	 * _verify_routes
826
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
827
+	 * we know if we need to drop out.
828
+	 *
829
+	 * @return bool
830
+	 * @throws EE_Error
831
+	 */
832
+	protected function _verify_routes()
833
+	{
834
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
835
+		if (! $this->_current_page && ! $this->request->isAjax()) {
836
+			return false;
837
+		}
838
+		$this->_route = false;
839
+		// check that the page_routes array is not empty
840
+		if (empty($this->_page_routes)) {
841
+			// user error msg
842
+			$error_msg = sprintf(
843
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
844
+				$this->_admin_page_title
845
+			);
846
+			// developer error msg
847
+			$error_msg .= '||' . $error_msg
848
+						  . esc_html__(
849
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
850
+							  'event_espresso'
851
+						  );
852
+			throw new EE_Error($error_msg);
853
+		}
854
+		// and that the requested page route exists
855
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
856
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
857
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
858
+				? $this->_page_config[ $this->_req_action ]
859
+				: [];
860
+		} else {
861
+			// user error msg
862
+			$error_msg = sprintf(
863
+				esc_html__(
864
+					'The requested page route does not exist for the %s admin page.',
865
+					'event_espresso'
866
+				),
867
+				$this->_admin_page_title
868
+			);
869
+			// developer error msg
870
+			$error_msg .= '||' . $error_msg
871
+						  . sprintf(
872
+							  esc_html__(
873
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
874
+								  'event_espresso'
875
+							  ),
876
+							  $this->_req_action
877
+						  );
878
+			throw new EE_Error($error_msg);
879
+		}
880
+		// and that a default route exists
881
+		if (! array_key_exists('default', $this->_page_routes)) {
882
+			// user error msg
883
+			$error_msg = sprintf(
884
+				esc_html__(
885
+					'A default page route has not been set for the % admin page.',
886
+					'event_espresso'
887
+				),
888
+				$this->_admin_page_title
889
+			);
890
+			// developer error msg
891
+			$error_msg .= '||' . $error_msg
892
+						  . esc_html__(
893
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
894
+							  'event_espresso'
895
+						  );
896
+			throw new EE_Error($error_msg);
897
+		}
898
+		// first lets' catch if the UI request has EVER been set.
899
+		if ($this->_is_UI_request === null) {
900
+			// lets set if this is a UI request or not.
901
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
902
+			// wait a minute... we might have a noheader in the route array
903
+			$this->_is_UI_request = ! (
904
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
905
+			)
906
+				? $this->_is_UI_request
907
+				: false;
908
+		}
909
+		$this->_set_current_labels();
910
+		return true;
911
+	}
912
+
913
+
914
+	/**
915
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
916
+	 *
917
+	 * @param string $route the route name we're verifying
918
+	 * @return bool we'll throw an exception if this isn't a valid route.
919
+	 * @throws EE_Error
920
+	 */
921
+	protected function _verify_route($route)
922
+	{
923
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
924
+			return true;
925
+		}
926
+		// user error msg
927
+		$error_msg = sprintf(
928
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
929
+			$this->_admin_page_title
930
+		);
931
+		// developer error msg
932
+		$error_msg .= '||' . $error_msg
933
+					  . sprintf(
934
+						  esc_html__(
935
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
936
+							  'event_espresso'
937
+						  ),
938
+						  $route
939
+					  );
940
+		throw new EE_Error($error_msg);
941
+	}
942
+
943
+
944
+	/**
945
+	 * perform nonce verification
946
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
947
+	 * using this method (and save retyping!)
948
+	 *
949
+	 * @param string $nonce     The nonce sent
950
+	 * @param string $nonce_ref The nonce reference string (name0)
951
+	 * @return void
952
+	 * @throws EE_Error
953
+	 */
954
+	protected function _verify_nonce($nonce, $nonce_ref)
955
+	{
956
+		// verify nonce against expected value
957
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
958
+			// these are not the droids you are looking for !!!
959
+			$msg = sprintf(
960
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
961
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
962
+				'</a>'
963
+			);
964
+			if (WP_DEBUG) {
965
+				$msg .= "\n  ";
966
+				$msg .= sprintf(
967
+					esc_html__(
968
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
969
+						'event_espresso'
970
+					),
971
+					__CLASS__
972
+				);
973
+			}
974
+			if (! $this->request->isAjax()) {
975
+				wp_die($msg);
976
+			}
977
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
978
+			$this->_return_json();
979
+		}
980
+	}
981
+
982
+
983
+	/**
984
+	 * _route_admin_request()
985
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
986
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
987
+	 * in the page routes and then will try to load the corresponding method.
988
+	 *
989
+	 * @return void
990
+	 * @throws EE_Error
991
+	 * @throws InvalidArgumentException
992
+	 * @throws InvalidDataTypeException
993
+	 * @throws InvalidInterfaceException
994
+	 * @throws ReflectionException
995
+	 */
996
+	protected function _route_admin_request()
997
+	{
998
+		if (! $this->_is_UI_request) {
999
+			$this->_verify_routes();
1000
+		}
1001
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1002
+		if ($this->_req_action !== 'default' && $nonce_check) {
1003
+			// set nonce from post data
1004
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
1005
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1006
+		}
1007
+		// set the nav_tabs array but ONLY if this is  UI_request
1008
+		if ($this->_is_UI_request) {
1009
+			$this->_set_nav_tabs();
1010
+		}
1011
+		// grab callback function
1012
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
1013
+		// check if callback has args
1014
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1015
+		$error_msg = '';
1016
+		// action right before calling route
1017
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1018
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1019
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1020
+		}
1021
+		// right before calling the route, let's clean the _wp_http_referer
1022
+		$this->request->setServerParam(
1023
+			'REQUEST_URI',
1024
+			remove_query_arg(
1025
+				'_wp_http_referer',
1026
+				wp_unslash($this->request->getServerParam('REQUEST_URI'))
1027
+			)
1028
+		);
1029
+		if (! empty($func)) {
1030
+			if (is_array($func)) {
1031
+				list($class, $method) = $func;
1032
+			} elseif (strpos($func, '::') !== false) {
1033
+				list($class, $method) = explode('::', $func);
1034
+			} else {
1035
+				$class  = $this;
1036
+				$method = $func;
1037
+			}
1038
+			if (! (is_object($class) && $class === $this)) {
1039
+				// send along this admin page object for access by addons.
1040
+				$args['admin_page_object'] = $this;
1041
+			}
1042
+			if (
1043
+				// is it a method on a class that doesn't work?
1044
+				(
1045
+					(
1046
+						method_exists($class, $method)
1047
+						&& call_user_func_array([$class, $method], $args) === false
1048
+					)
1049
+					&& (
1050
+						// is it a standalone function that doesn't work?
1051
+						function_exists($method)
1052
+						&& call_user_func_array(
1053
+							$func,
1054
+							array_merge(['admin_page_object' => $this], $args)
1055
+						) === false
1056
+					)
1057
+				)
1058
+				|| (
1059
+					// is it neither a class method NOR a standalone function?
1060
+					! method_exists($class, $method)
1061
+					&& ! function_exists($method)
1062
+				)
1063
+			) {
1064
+				// user error msg
1065
+				$error_msg = esc_html__(
1066
+					'An error occurred. The  requested page route could not be found.',
1067
+					'event_espresso'
1068
+				);
1069
+				// developer error msg
1070
+				$error_msg .= '||';
1071
+				$error_msg .= sprintf(
1072
+					esc_html__(
1073
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1074
+						'event_espresso'
1075
+					),
1076
+					$method
1077
+				);
1078
+			}
1079
+			if (! empty($error_msg)) {
1080
+				throw new EE_Error($error_msg);
1081
+			}
1082
+		}
1083
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1084
+		// then we need to reset the routing properties to the new route.
1085
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1086
+		if (
1087
+			$this->_is_UI_request === false
1088
+			&& is_array($this->_route)
1089
+			&& ! empty($this->_route['headers_sent_route'])
1090
+		) {
1091
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1092
+		}
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * This method just allows the resetting of page properties in the case where a no headers
1098
+	 * route redirects to a headers route in its route config.
1099
+	 *
1100
+	 * @param string $new_route New (non header) route to redirect to.
1101
+	 * @return   void
1102
+	 * @throws ReflectionException
1103
+	 * @throws InvalidArgumentException
1104
+	 * @throws InvalidInterfaceException
1105
+	 * @throws InvalidDataTypeException
1106
+	 * @throws EE_Error
1107
+	 * @since   4.3.0
1108
+	 */
1109
+	protected function _reset_routing_properties($new_route)
1110
+	{
1111
+		$this->_is_UI_request = true;
1112
+		// now we set the current route to whatever the headers_sent_route is set at
1113
+		$this->request->setRequestParam('action', $new_route);
1114
+		// rerun page setup
1115
+		$this->_page_setup();
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * _add_query_arg
1121
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1122
+	 *(internally just uses EEH_URL's function with the same name)
1123
+	 *
1124
+	 * @param array  $args
1125
+	 * @param string $url
1126
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1127
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1128
+	 *                                        Example usage: If the current page is:
1129
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1130
+	 *                                        &action=default&event_id=20&month_range=March%202015
1131
+	 *                                        &_wpnonce=5467821
1132
+	 *                                        and you call:
1133
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1134
+	 *                                        array(
1135
+	 *                                        'action' => 'resend_something',
1136
+	 *                                        'page=>espresso_registrations'
1137
+	 *                                        ),
1138
+	 *                                        $some_url,
1139
+	 *                                        true
1140
+	 *                                        );
1141
+	 *                                        It will produce a url in this structure:
1142
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1143
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1144
+	 *                                        month_range]=March%202015
1145
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1146
+	 * @return string
1147
+	 */
1148
+	public static function add_query_args_and_nonce(
1149
+		$args = [],
1150
+		$url = false,
1151
+		$sticky = false,
1152
+		$exclude_nonce = false
1153
+	) {
1154
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1155
+		if ($sticky) {
1156
+			/** @var RequestInterface $request */
1157
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1158
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1159
+			foreach ($request->requestParams() as $key => $value) {
1160
+				// do not add nonces
1161
+				if (strpos($key, 'nonce') !== false) {
1162
+					continue;
1163
+				}
1164
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1165
+			}
1166
+		}
1167
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * This returns a generated link that will load the related help tab.
1173
+	 *
1174
+	 * @param string $help_tab_id the id for the connected help tab
1175
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1176
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1177
+	 * @return string              generated link
1178
+	 * @uses EEH_Template::get_help_tab_link()
1179
+	 */
1180
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1181
+	{
1182
+		return EEH_Template::get_help_tab_link(
1183
+			$help_tab_id,
1184
+			$this->page_slug,
1185
+			$this->_req_action,
1186
+			$icon_style,
1187
+			$help_text
1188
+		);
1189
+	}
1190
+
1191
+
1192
+	/**
1193
+	 * _add_help_tabs
1194
+	 * Note child classes define their help tabs within the page_config array.
1195
+	 *
1196
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1197
+	 * @return void
1198
+	 * @throws DomainException
1199
+	 * @throws EE_Error
1200
+	 */
1201
+	protected function _add_help_tabs()
1202
+	{
1203
+		$tour_buttons = '';
1204
+		if (isset($this->_page_config[ $this->_req_action ])) {
1205
+			$config = $this->_page_config[ $this->_req_action ];
1206
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1207
+			// is there a help tour for the current route?  if there is let's setup the tour buttons
1208
+			// if (isset($this->_help_tour[ $this->_req_action ])) {
1209
+			//     $tb = array();
1210
+			//     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1211
+			//     foreach ($this->_help_tour['tours'] as $tour) {
1212
+			//         // if this is the end tour then we don't need to setup a button
1213
+			//         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1214
+			//             continue;
1215
+			//         }
1216
+			//         $tb[] = '<button id="trigger-tour-'
1217
+			//                 . $tour->get_slug()
1218
+			//                 . '" class="button-primary trigger-ee-help-tour">'
1219
+			//                 . $tour->get_label()
1220
+			//                 . '</button>';
1221
+			//     }
1222
+			//     $tour_buttons .= implode('<br />', $tb);
1223
+			//     $tour_buttons .= '</div></div>';
1224
+			// }
1225
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1226
+			if (is_array($config) && isset($config['help_sidebar'])) {
1227
+				// check that the callback given is valid
1228
+				if (! method_exists($this, $config['help_sidebar'])) {
1229
+					throw new EE_Error(
1230
+						sprintf(
1231
+							esc_html__(
1232
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1233
+								'event_espresso'
1234
+							),
1235
+							$config['help_sidebar'],
1236
+							get_class($this)
1237
+						)
1238
+					);
1239
+				}
1240
+				$content = apply_filters(
1241
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1242
+					$this->{$config['help_sidebar']}()
1243
+				);
1244
+				$content .= $tour_buttons; // add help tour buttons.
1245
+				// do we have any help tours setup?  Cause if we do we want to add the buttons
1246
+				$this->_current_screen->set_help_sidebar($content);
1247
+			}
1248
+			// if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1249
+			if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1250
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1251
+			}
1252
+			// handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1253
+			if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1254
+				$_ht['id']      = $this->page_slug;
1255
+				$_ht['title']   = esc_html__('Help Tours', 'event_espresso');
1256
+				$_ht['content'] = '<p>'
1257
+								  . esc_html__(
1258
+									  'The buttons to the right allow you to start/restart any help tours available for this page',
1259
+									  'event_espresso'
1260
+								  ) . '</p>';
1261
+				$this->_current_screen->add_help_tab($_ht);
1262
+			}
1263
+			if (! isset($config['help_tabs'])) {
1264
+				return;
1265
+			} //no help tabs for this route
1266
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1267
+				// we're here so there ARE help tabs!
1268
+				// make sure we've got what we need
1269
+				if (! isset($cfg['title'])) {
1270
+					throw new EE_Error(
1271
+						esc_html__(
1272
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1273
+							'event_espresso'
1274
+						)
1275
+					);
1276
+				}
1277
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1278
+					throw new EE_Error(
1279
+						esc_html__(
1280
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1281
+							'event_espresso'
1282
+						)
1283
+					);
1284
+				}
1285
+				// first priority goes to content.
1286
+				if (! empty($cfg['content'])) {
1287
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1288
+					// second priority goes to filename
1289
+				} elseif (! empty($cfg['filename'])) {
1290
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1291
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1292
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1293
+															 . basename($this->_get_dir())
1294
+															 . '/help_tabs/'
1295
+															 . $cfg['filename']
1296
+															 . '.help_tab.php' : $file_path;
1297
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1298
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1299
+						EE_Error::add_error(
1300
+							sprintf(
1301
+								esc_html__(
1302
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1303
+									'event_espresso'
1304
+								),
1305
+								$tab_id,
1306
+								key($config),
1307
+								$file_path
1308
+							),
1309
+							__FILE__,
1310
+							__FUNCTION__,
1311
+							__LINE__
1312
+						);
1313
+						return;
1314
+					}
1315
+					$template_args['admin_page_obj'] = $this;
1316
+					$content                         = EEH_Template::display_template(
1317
+						$file_path,
1318
+						$template_args,
1319
+						true
1320
+					);
1321
+				} else {
1322
+					$content = '';
1323
+				}
1324
+				// check if callback is valid
1325
+				if (
1326
+					empty($content)
1327
+					&& (
1328
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1329
+					)
1330
+				) {
1331
+					EE_Error::add_error(
1332
+						sprintf(
1333
+							esc_html__(
1334
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1335
+								'event_espresso'
1336
+							),
1337
+							$cfg['title']
1338
+						),
1339
+						__FILE__,
1340
+						__FUNCTION__,
1341
+						__LINE__
1342
+					);
1343
+					return;
1344
+				}
1345
+				// setup config array for help tab method
1346
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1347
+				$_ht = [
1348
+					'id'       => $id,
1349
+					'title'    => $cfg['title'],
1350
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1351
+					'content'  => $content,
1352
+				];
1353
+				$this->_current_screen->add_help_tab($_ht);
1354
+			}
1355
+		}
1356
+	}
1357
+
1358
+
1359
+	/**
1360
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1361
+	 * an array with properties for setting up usage of the joyride plugin
1362
+	 *
1363
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1364
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1365
+	 *         _set_page_config() comments
1366
+	 * @return void
1367
+	 * @throws InvalidArgumentException
1368
+	 * @throws InvalidDataTypeException
1369
+	 * @throws InvalidInterfaceException
1370
+	 */
1371
+	protected function _add_help_tour()
1372
+	{
1373
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1374
+		// $tours = array();
1375
+		// $this->_help_tour = array();
1376
+		// // exit early if help tours are turned off globally
1377
+		// if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1378
+		//     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1379
+		// ) {
1380
+		//     return;
1381
+		// }
1382
+		// // loop through _page_config to find any help_tour defined
1383
+		// foreach ($this->_page_config as $route => $config) {
1384
+		//     // we're only going to set things up for this route
1385
+		//     if ($route !== $this->_req_action) {
1386
+		//         continue;
1387
+		//     }
1388
+		//     if (isset($config['help_tour'])) {
1389
+		//         foreach ($config['help_tour'] as $tour) {
1390
+		//             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1391
+		//             // let's see if we can get that file...
1392
+		//             // if not its possible this is a decaf route not set in caffeinated
1393
+		//             // so lets try and get the caffeinated equivalent
1394
+		//             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1395
+		//                                                      . basename($this->_get_dir())
1396
+		//                                                      . '/help_tours/'
1397
+		//                                                      . $tour
1398
+		//                                                      . '.class.php' : $file_path;
1399
+		//             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1400
+		//             if (! is_readable($file_path)) {
1401
+		//                 EE_Error::add_error(
1402
+		//                     sprintf(
1403
+		//                         esc_html__(
1404
+		//                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1405
+		//                             'event_espresso'
1406
+		//                         ),
1407
+		//                         $file_path,
1408
+		//                         $tour
1409
+		//                     ),
1410
+		//                     __FILE__,
1411
+		//                     __FUNCTION__,
1412
+		//                     __LINE__
1413
+		//                 );
1414
+		//                 return;
1415
+		//             }
1416
+		//             require_once $file_path;
1417
+		//             if (! class_exists($tour)) {
1418
+		//                 $error_msg[] = sprintf(
1419
+		//                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1420
+		//                     $tour
1421
+		//                 );
1422
+		//                 $error_msg[] = $error_msg[0] . "\r\n"
1423
+		//                                . sprintf(
1424
+		//                                    esc_html__(
1425
+		//                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1426
+		//                                        'event_espresso'
1427
+		//                                    ),
1428
+		//                                    $tour,
1429
+		//                                    '<br />',
1430
+		//                                    $tour,
1431
+		//                                    $this->_req_action,
1432
+		//                                    get_class($this)
1433
+		//                                );
1434
+		//                 throw new EE_Error(implode('||', $error_msg));
1435
+		//             }
1436
+		//             $tour_obj = new $tour($this->_is_caf);
1437
+		//             $tours[] = $tour_obj;
1438
+		//             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1439
+		//         }
1440
+		//         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1441
+		//         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1442
+		//         $tours[] = $end_stop_tour;
1443
+		//         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1444
+		//     }
1445
+		// }
1446
+		//
1447
+		// if (! empty($tours)) {
1448
+		//     $this->_help_tour['tours'] = $tours;
1449
+		// }
1450
+		// // that's it!  Now that the $_help_tours property is set (or not)
1451
+		// // the scripts and html should be taken care of automatically.
1452
+		//
1453
+		// /**
1454
+		//  * Allow extending the help tours variable.
1455
+		//  *
1456
+		//  * @param Array $_help_tour The array containing all help tour information to be displayed.
1457
+		//  */
1458
+		// $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1459
+	}
1460
+
1461
+
1462
+	/**
1463
+	 * This simply sets up any qtips that have been defined in the page config
1464
+	 *
1465
+	 * @return void
1466
+	 */
1467
+	protected function _add_qtips()
1468
+	{
1469
+		if (isset($this->_route_config['qtips'])) {
1470
+			$qtips = (array) $this->_route_config['qtips'];
1471
+			// load qtip loader
1472
+			$path = [
1473
+				$this->_get_dir() . '/qtips/',
1474
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1475
+			];
1476
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1477
+		}
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * _set_nav_tabs
1483
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1484
+	 * wish to add additional tabs or modify accordingly.
1485
+	 *
1486
+	 * @return void
1487
+	 * @throws InvalidArgumentException
1488
+	 * @throws InvalidInterfaceException
1489
+	 * @throws InvalidDataTypeException
1490
+	 */
1491
+	protected function _set_nav_tabs()
1492
+	{
1493
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1494
+		$i = 0;
1495
+		foreach ($this->_page_config as $slug => $config) {
1496
+			if (! is_array($config) || empty($config['nav'])) {
1497
+				continue;
1498
+			}
1499
+			// no nav tab for this config
1500
+			// check for persistent flag
1501
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1502
+				// nav tab is only to appear when route requested.
1503
+				continue;
1504
+			}
1505
+			if (! $this->check_user_access($slug, true)) {
1506
+				// no nav tab because current user does not have access.
1507
+				continue;
1508
+			}
1509
+			$css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1510
+			$this->_nav_tabs[ $slug ] = [
1511
+				'url'       => isset($config['nav']['url'])
1512
+					? $config['nav']['url']
1513
+					: self::add_query_args_and_nonce(
1514
+						['action' => $slug],
1515
+						$this->_admin_base_url
1516
+					),
1517
+				'link_text' => isset($config['nav']['label'])
1518
+					? $config['nav']['label']
1519
+					: ucwords(
1520
+						str_replace('_', ' ', $slug)
1521
+					),
1522
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1523
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1524
+			];
1525
+			$i++;
1526
+		}
1527
+		// if $this->_nav_tabs is empty then lets set the default
1528
+		if (empty($this->_nav_tabs)) {
1529
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1530
+				'url'       => $this->_admin_base_url,
1531
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1532
+				'css_class' => 'nav-tab-active',
1533
+				'order'     => 10,
1534
+			];
1535
+		}
1536
+		// now let's sort the tabs according to order
1537
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1538
+	}
1539
+
1540
+
1541
+	/**
1542
+	 * _set_current_labels
1543
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1544
+	 * property array
1545
+	 *
1546
+	 * @return void
1547
+	 */
1548
+	private function _set_current_labels()
1549
+	{
1550
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1551
+			foreach ($this->_route_config['labels'] as $label => $text) {
1552
+				if (is_array($text)) {
1553
+					foreach ($text as $sublabel => $subtext) {
1554
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1555
+					}
1556
+				} else {
1557
+					$this->_labels[ $label ] = $text;
1558
+				}
1559
+			}
1560
+		}
1561
+	}
1562
+
1563
+
1564
+	/**
1565
+	 *        verifies user access for this admin page
1566
+	 *
1567
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1568
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1569
+	 *                               return false if verify fail.
1570
+	 * @return bool
1571
+	 * @throws InvalidArgumentException
1572
+	 * @throws InvalidDataTypeException
1573
+	 * @throws InvalidInterfaceException
1574
+	 */
1575
+	public function check_user_access($route_to_check = '', $verify_only = false)
1576
+	{
1577
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1578
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1579
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1580
+						  && is_array(
1581
+							  $this->_page_routes[ $route_to_check ]
1582
+						  )
1583
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1584
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1585
+		if (empty($capability) && empty($route_to_check)) {
1586
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1587
+				: $this->_route['capability'];
1588
+		} else {
1589
+			$capability = empty($capability) ? 'manage_options' : $capability;
1590
+		}
1591
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1592
+		if (
1593
+			! $this->request->isAjax()
1594
+			&& (
1595
+				! function_exists('is_admin')
1596
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1597
+					$capability,
1598
+					$this->page_slug
1599
+					. '_'
1600
+					. $route_to_check,
1601
+					$id
1602
+				)
1603
+			)
1604
+		) {
1605
+			if ($verify_only) {
1606
+				return false;
1607
+			}
1608
+			if (is_user_logged_in()) {
1609
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1610
+			} else {
1611
+				return false;
1612
+			}
1613
+		}
1614
+		return true;
1615
+	}
1616
+
1617
+
1618
+	/**
1619
+	 * admin_init_global
1620
+	 * This runs all the code that we want executed within the WP admin_init hook.
1621
+	 * This method executes for ALL EE Admin pages.
1622
+	 *
1623
+	 * @return void
1624
+	 */
1625
+	public function admin_init_global()
1626
+	{
1627
+	}
1628
+
1629
+
1630
+	/**
1631
+	 * wp_loaded_global
1632
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1633
+	 * EE_Admin page and will execute on every EE Admin Page load
1634
+	 *
1635
+	 * @return void
1636
+	 */
1637
+	public function wp_loaded()
1638
+	{
1639
+	}
1640
+
1641
+
1642
+	/**
1643
+	 * admin_notices
1644
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1645
+	 * ALL EE_Admin pages.
1646
+	 *
1647
+	 * @return void
1648
+	 */
1649
+	public function admin_notices_global()
1650
+	{
1651
+		$this->_display_no_javascript_warning();
1652
+		$this->_display_espresso_notices();
1653
+	}
1654
+
1655
+
1656
+	public function network_admin_notices_global()
1657
+	{
1658
+		$this->_display_no_javascript_warning();
1659
+		$this->_display_espresso_notices();
1660
+	}
1661
+
1662
+
1663
+	/**
1664
+	 * admin_footer_scripts_global
1665
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1666
+	 * will apply on ALL EE_Admin pages.
1667
+	 *
1668
+	 * @return void
1669
+	 */
1670
+	public function admin_footer_scripts_global()
1671
+	{
1672
+		$this->_add_admin_page_ajax_loading_img();
1673
+		$this->_add_admin_page_overlay();
1674
+		// if metaboxes are present we need to add the nonce field
1675
+		if (
1676
+			isset($this->_route_config['metaboxes'])
1677
+			|| isset($this->_route_config['list_table'])
1678
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1679
+		) {
1680
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1681
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1682
+		}
1683
+	}
1684
+
1685
+
1686
+	/**
1687
+	 * admin_footer_global
1688
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1689
+	 * ALL EE_Admin Pages.
1690
+	 *
1691
+	 * @return void
1692
+	 */
1693
+	public function admin_footer_global()
1694
+	{
1695
+		// dialog container for dialog helper
1696
+		echo '
1697 1697
         <div class="ee-admin-dialog-container auto-hide hidden">
1698 1698
             <div class="ee-notices"></div>
1699 1699
             <div class="ee-admin-dialog-container-inner-content"></div>
1700 1700
         </div>
1701 1701
         ';
1702 1702
 
1703
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1704
-        // help tour stuff?
1705
-        // if (isset($this->_help_tour[ $this->_req_action ])) {
1706
-        //     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1707
-        // }
1708
-        // current set timezone for timezone js
1709
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1710
-    }
1711
-
1712
-
1713
-    /**
1714
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1715
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1716
-     * help popups then in your templates or your content you set "triggers" for the content using the
1717
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1718
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1719
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1720
-     * for the
1721
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1722
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1723
-     *    'help_trigger_id' => array(
1724
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1725
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1726
-     *    )
1727
-     * );
1728
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1729
-     *
1730
-     * @param array $help_array
1731
-     * @param bool  $display
1732
-     * @return string content
1733
-     * @throws DomainException
1734
-     * @throws EE_Error
1735
-     */
1736
-    protected function _set_help_popup_content($help_array = [], $display = false)
1737
-    {
1738
-        $content    = '';
1739
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1740
-        // loop through the array and setup content
1741
-        foreach ($help_array as $trigger => $help) {
1742
-            // make sure the array is setup properly
1743
-            if (! isset($help['title']) || ! isset($help['content'])) {
1744
-                throw new EE_Error(
1745
-                    esc_html__(
1746
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1747
-                        'event_espresso'
1748
-                    )
1749
-                );
1750
-            }
1751
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1752
-            $template_args = [
1753
-                'help_popup_id'      => $trigger,
1754
-                'help_popup_title'   => $help['title'],
1755
-                'help_popup_content' => $help['content'],
1756
-            ];
1757
-            $content       .= EEH_Template::display_template(
1758
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1759
-                $template_args,
1760
-                true
1761
-            );
1762
-        }
1763
-        if ($display) {
1764
-            echo $content; // already escaped
1765
-            return '';
1766
-        }
1767
-        return $content;
1768
-    }
1769
-
1770
-
1771
-    /**
1772
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1773
-     *
1774
-     * @return array properly formatted array for help popup content
1775
-     * @throws EE_Error
1776
-     */
1777
-    private function _get_help_content()
1778
-    {
1779
-        // what is the method we're looking for?
1780
-        $method_name = '_help_popup_content_' . $this->_req_action;
1781
-        // if method doesn't exist let's get out.
1782
-        if (! method_exists($this, $method_name)) {
1783
-            return [];
1784
-        }
1785
-        // k we're good to go let's retrieve the help array
1786
-        $help_array = call_user_func([$this, $method_name]);
1787
-        // make sure we've got an array!
1788
-        if (! is_array($help_array)) {
1789
-            throw new EE_Error(
1790
-                esc_html__(
1791
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1792
-                    'event_espresso'
1793
-                )
1794
-            );
1795
-        }
1796
-        return $help_array;
1797
-    }
1798
-
1799
-
1800
-    /**
1801
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1802
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1803
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1804
-     *
1805
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1806
-     * @param boolean $display    if false then we return the trigger string
1807
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1808
-     * @return string
1809
-     * @throws DomainException
1810
-     * @throws EE_Error
1811
-     */
1812
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1813
-    {
1814
-        if ($this->request->isAjax()) {
1815
-            return '';
1816
-        }
1817
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1818
-        $help_array   = $this->_get_help_content();
1819
-        $help_content = '';
1820
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1821
-            $help_array[ $trigger_id ] = [
1822
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1823
-                'content' => esc_html__(
1824
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1825
-                    'event_espresso'
1826
-                ),
1827
-            ];
1828
-            $help_content              = $this->_set_help_popup_content($help_array);
1829
-        }
1830
-        // let's setup the trigger
1831
-        $content = '<a class="ee-dialog" href="?height='
1832
-                   . esc_attr($dimensions[0])
1833
-                   . '&width='
1834
-                   . esc_attr($dimensions[1])
1835
-                   . '&inlineId='
1836
-                   . esc_attr($trigger_id)
1837
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1838
-        $content .= $help_content;
1839
-        if ($display) {
1840
-            echo $content; // already escaped
1841
-            return '';
1842
-        }
1843
-        return $content;
1844
-    }
1845
-
1846
-
1847
-    /**
1848
-     * _add_global_screen_options
1849
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1850
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1851
-     *
1852
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1853
-     *         see also WP_Screen object documents...
1854
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1855
-     * @abstract
1856
-     * @return void
1857
-     */
1858
-    private function _add_global_screen_options()
1859
-    {
1860
-    }
1861
-
1862
-
1863
-    /**
1864
-     * _add_global_feature_pointers
1865
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1866
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1867
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1868
-     *
1869
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1870
-     *         extended) also see:
1871
-     * @link   http://eamann.com/tech/wordpress-portland/
1872
-     * @abstract
1873
-     * @return void
1874
-     */
1875
-    private function _add_global_feature_pointers()
1876
-    {
1877
-    }
1878
-
1879
-
1880
-    /**
1881
-     * load_global_scripts_styles
1882
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1883
-     *
1884
-     * @return void
1885
-     */
1886
-    public function load_global_scripts_styles()
1887
-    {
1888
-        /** STYLES **/
1889
-        // add debugging styles
1890
-        if (WP_DEBUG) {
1891
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1892
-        }
1893
-        // register all styles
1894
-        wp_register_style(
1895
-            'espresso-ui-theme',
1896
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1897
-            [],
1898
-            EVENT_ESPRESSO_VERSION
1899
-        );
1900
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1901
-        // helpers styles
1902
-        wp_register_style(
1903
-            'ee-text-links',
1904
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1905
-            [],
1906
-            EVENT_ESPRESSO_VERSION
1907
-        );
1908
-        /** SCRIPTS **/
1909
-        // register all scripts
1910
-        wp_register_script(
1911
-            'ee-dialog',
1912
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1913
-            ['jquery', 'jquery-ui-draggable'],
1914
-            EVENT_ESPRESSO_VERSION,
1915
-            true
1916
-        );
1917
-        wp_register_script(
1918
-            'ee_admin_js',
1919
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1920
-            ['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1921
-            EVENT_ESPRESSO_VERSION,
1922
-            true
1923
-        );
1924
-        wp_register_script(
1925
-            'jquery-ui-timepicker-addon',
1926
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1927
-            ['jquery-ui-datepicker', 'jquery-ui-slider'],
1928
-            EVENT_ESPRESSO_VERSION,
1929
-            true
1930
-        );
1931
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1932
-        // if (EE_Registry::instance()->CFG->admin->help_tour_activation) {
1933
-        //     add_filter('FHEE_load_joyride', '__return_true');
1934
-        // }
1935
-        // script for sorting tables
1936
-        wp_register_script(
1937
-            'espresso_ajax_table_sorting',
1938
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1939
-            ['ee_admin_js', 'jquery-ui-sortable'],
1940
-            EVENT_ESPRESSO_VERSION,
1941
-            true
1942
-        );
1943
-        // script for parsing uri's
1944
-        wp_register_script(
1945
-            'ee-parse-uri',
1946
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1947
-            [],
1948
-            EVENT_ESPRESSO_VERSION,
1949
-            true
1950
-        );
1951
-        // and parsing associative serialized form elements
1952
-        wp_register_script(
1953
-            'ee-serialize-full-array',
1954
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1955
-            ['jquery'],
1956
-            EVENT_ESPRESSO_VERSION,
1957
-            true
1958
-        );
1959
-        // helpers scripts
1960
-        wp_register_script(
1961
-            'ee-text-links',
1962
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1963
-            ['jquery'],
1964
-            EVENT_ESPRESSO_VERSION,
1965
-            true
1966
-        );
1967
-        wp_register_script(
1968
-            'ee-moment-core',
1969
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1970
-            [],
1971
-            EVENT_ESPRESSO_VERSION,
1972
-            true
1973
-        );
1974
-        wp_register_script(
1975
-            'ee-moment',
1976
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1977
-            ['ee-moment-core'],
1978
-            EVENT_ESPRESSO_VERSION,
1979
-            true
1980
-        );
1981
-        wp_register_script(
1982
-            'ee-datepicker',
1983
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1984
-            ['jquery-ui-timepicker-addon', 'ee-moment'],
1985
-            EVENT_ESPRESSO_VERSION,
1986
-            true
1987
-        );
1988
-        // google charts
1989
-        wp_register_script(
1990
-            'google-charts',
1991
-            'https://www.gstatic.com/charts/loader.js',
1992
-            [],
1993
-            EVENT_ESPRESSO_VERSION
1994
-        );
1995
-        // ENQUEUE ALL BASICS BY DEFAULT
1996
-        wp_enqueue_style('ee-admin-css');
1997
-        wp_enqueue_script('ee_admin_js');
1998
-        wp_enqueue_script('ee-accounting');
1999
-        wp_enqueue_script('jquery-validate');
2000
-        // taking care of metaboxes
2001
-        if (
2002
-            empty($this->_cpt_route)
2003
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
2004
-        ) {
2005
-            wp_enqueue_script('dashboard');
2006
-        }
2007
-        // LOCALIZED DATA
2008
-        // localize script for ajax lazy loading
2009
-        $lazy_loader_container_ids = apply_filters(
2010
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
2011
-            ['espresso_news_post_box_content']
2012
-        );
2013
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
2014
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
2015
-        // /**
2016
-        //  * help tour stuff
2017
-        //  */
2018
-        // if (! empty($this->_help_tour)) {
2019
-        //     // register the js for kicking things off
2020
-        //     wp_enqueue_script(
2021
-        //         'ee-help-tour',
2022
-        //         EE_ADMIN_URL . 'assets/ee-help-tour.js',
2023
-        //         array('jquery-joyride'),
2024
-        //         EVENT_ESPRESSO_VERSION,
2025
-        //         true
2026
-        //     );
2027
-        //     $tours = array();
2028
-        //     // setup tours for the js tour object
2029
-        //     foreach ($this->_help_tour['tours'] as $tour) {
2030
-        //         if ($tour instanceof EE_Help_Tour) {
2031
-        //             $tours[] = array(
2032
-        //                 'id'      => $tour->get_slug(),
2033
-        //                 'options' => $tour->get_options(),
2034
-        //             );
2035
-        //         }
2036
-        //     }
2037
-        //     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2038
-        //     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2039
-        // }
2040
-
2041
-        add_filter(
2042
-            'admin_body_class',
2043
-            function ($classes) {
2044
-                if (strpos($classes, 'espresso-admin') === false) {
2045
-                    $classes .= ' espresso-admin';
2046
-                }
2047
-                return $classes;
2048
-            }
2049
-        );
2050
-    }
2051
-
2052
-
2053
-    /**
2054
-     *        admin_footer_scripts_eei18n_js_strings
2055
-     *
2056
-     * @return        void
2057
-     */
2058
-    public function admin_footer_scripts_eei18n_js_strings()
2059
-    {
2060
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
2061
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
2062
-            __(
2063
-                'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2064
-                'event_espresso'
2065
-            )
2066
-        );
2067
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
2068
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
2069
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
2070
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
2071
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
2072
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
2073
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
2074
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
2075
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
2076
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
2077
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
2078
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
2079
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
2080
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
2081
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
2082
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
2083
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
2084
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
2085
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
2086
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
2087
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
2088
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
2089
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
2090
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
2091
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
2092
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
2093
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
2094
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
2095
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
2096
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
2097
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
2098
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
2099
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
2100
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
2101
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
2102
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
2103
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
2104
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
2105
-    }
2106
-
2107
-
2108
-    /**
2109
-     *        load enhanced xdebug styles for ppl with failing eyesight
2110
-     *
2111
-     * @return        void
2112
-     */
2113
-    public function add_xdebug_style()
2114
-    {
2115
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2116
-    }
2117
-
2118
-
2119
-    /************************/
2120
-    /** LIST TABLE METHODS **/
2121
-    /************************/
2122
-    /**
2123
-     * this sets up the list table if the current view requires it.
2124
-     *
2125
-     * @return void
2126
-     * @throws EE_Error
2127
-     */
2128
-    protected function _set_list_table()
2129
-    {
2130
-        // first is this a list_table view?
2131
-        if (! isset($this->_route_config['list_table'])) {
2132
-            return;
2133
-        } //not a list_table view so get out.
2134
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2135
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2136
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2137
-            // user error msg
2138
-            $error_msg = esc_html__(
2139
-                'An error occurred. The requested list table views could not be found.',
2140
-                'event_espresso'
2141
-            );
2142
-            // developer error msg
2143
-            $error_msg .= '||'
2144
-                          . sprintf(
2145
-                              esc_html__(
2146
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2147
-                                  'event_espresso'
2148
-                              ),
2149
-                              $this->_req_action,
2150
-                              $list_table_view
2151
-                          );
2152
-            throw new EE_Error($error_msg);
2153
-        }
2154
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2155
-        $this->_views = apply_filters(
2156
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2157
-            $this->_views
2158
-        );
2159
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2160
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2161
-        $this->_set_list_table_view();
2162
-        $this->_set_list_table_object();
2163
-    }
2164
-
2165
-
2166
-    /**
2167
-     * set current view for List Table
2168
-     *
2169
-     * @return void
2170
-     */
2171
-    protected function _set_list_table_view()
2172
-    {
2173
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2174
-        $status = $this->request->getRequestParam('status', null, 'key');
2175
-        $this->_view = $status && array_key_exists($status, $this->_views)
2176
-            ? $status
2177
-            : $this->_view;
2178
-    }
2179
-
2180
-
2181
-    /**
2182
-     * _set_list_table_object
2183
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2184
-     *
2185
-     * @throws InvalidInterfaceException
2186
-     * @throws InvalidArgumentException
2187
-     * @throws InvalidDataTypeException
2188
-     * @throws EE_Error
2189
-     * @throws InvalidInterfaceException
2190
-     */
2191
-    protected function _set_list_table_object()
2192
-    {
2193
-        if (isset($this->_route_config['list_table'])) {
2194
-            if (! class_exists($this->_route_config['list_table'])) {
2195
-                throw new EE_Error(
2196
-                    sprintf(
2197
-                        esc_html__(
2198
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2199
-                            'event_espresso'
2200
-                        ),
2201
-                        $this->_route_config['list_table'],
2202
-                        get_class($this)
2203
-                    )
2204
-                );
2205
-            }
2206
-            $this->_list_table_object = $this->loader->getShared(
2207
-                $this->_route_config['list_table'],
2208
-                [$this]
2209
-            );
2210
-        }
2211
-    }
2212
-
2213
-
2214
-    /**
2215
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2216
-     *
2217
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2218
-     *                                                    urls.  The array should be indexed by the view it is being
2219
-     *                                                    added to.
2220
-     * @return array
2221
-     */
2222
-    public function get_list_table_view_RLs($extra_query_args = [])
2223
-    {
2224
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2225
-        if (empty($this->_views)) {
2226
-            $this->_views = [];
2227
-        }
2228
-        // cycle thru views
2229
-        foreach ($this->_views as $key => $view) {
2230
-            $query_args = [];
2231
-            // check for current view
2232
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2233
-            $query_args['action']                        = $this->_req_action;
2234
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2235
-            $query_args['status']                        = $view['slug'];
2236
-            // merge any other arguments sent in.
2237
-            if (isset($extra_query_args[ $view['slug'] ])) {
2238
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2239
-            }
2240
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2241
-        }
2242
-        return $this->_views;
2243
-    }
2244
-
2245
-
2246
-    /**
2247
-     * _entries_per_page_dropdown
2248
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2249
-     *
2250
-     * @param int $max_entries total number of rows in the table
2251
-     * @return string
2252
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2253
-     *         WP does it.
2254
-     */
2255
-    protected function _entries_per_page_dropdown($max_entries = 0)
2256
-    {
2257
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2258
-        $values   = [10, 25, 50, 100];
2259
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2260
-        if ($max_entries) {
2261
-            $values[] = $max_entries;
2262
-            sort($values);
2263
-        }
2264
-        $entries_per_page_dropdown = '
1703
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1704
+		// help tour stuff?
1705
+		// if (isset($this->_help_tour[ $this->_req_action ])) {
1706
+		//     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1707
+		// }
1708
+		// current set timezone for timezone js
1709
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1710
+	}
1711
+
1712
+
1713
+	/**
1714
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1715
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1716
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1717
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1718
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1719
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1720
+	 * for the
1721
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1722
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1723
+	 *    'help_trigger_id' => array(
1724
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1725
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1726
+	 *    )
1727
+	 * );
1728
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1729
+	 *
1730
+	 * @param array $help_array
1731
+	 * @param bool  $display
1732
+	 * @return string content
1733
+	 * @throws DomainException
1734
+	 * @throws EE_Error
1735
+	 */
1736
+	protected function _set_help_popup_content($help_array = [], $display = false)
1737
+	{
1738
+		$content    = '';
1739
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1740
+		// loop through the array and setup content
1741
+		foreach ($help_array as $trigger => $help) {
1742
+			// make sure the array is setup properly
1743
+			if (! isset($help['title']) || ! isset($help['content'])) {
1744
+				throw new EE_Error(
1745
+					esc_html__(
1746
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1747
+						'event_espresso'
1748
+					)
1749
+				);
1750
+			}
1751
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1752
+			$template_args = [
1753
+				'help_popup_id'      => $trigger,
1754
+				'help_popup_title'   => $help['title'],
1755
+				'help_popup_content' => $help['content'],
1756
+			];
1757
+			$content       .= EEH_Template::display_template(
1758
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1759
+				$template_args,
1760
+				true
1761
+			);
1762
+		}
1763
+		if ($display) {
1764
+			echo $content; // already escaped
1765
+			return '';
1766
+		}
1767
+		return $content;
1768
+	}
1769
+
1770
+
1771
+	/**
1772
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1773
+	 *
1774
+	 * @return array properly formatted array for help popup content
1775
+	 * @throws EE_Error
1776
+	 */
1777
+	private function _get_help_content()
1778
+	{
1779
+		// what is the method we're looking for?
1780
+		$method_name = '_help_popup_content_' . $this->_req_action;
1781
+		// if method doesn't exist let's get out.
1782
+		if (! method_exists($this, $method_name)) {
1783
+			return [];
1784
+		}
1785
+		// k we're good to go let's retrieve the help array
1786
+		$help_array = call_user_func([$this, $method_name]);
1787
+		// make sure we've got an array!
1788
+		if (! is_array($help_array)) {
1789
+			throw new EE_Error(
1790
+				esc_html__(
1791
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1792
+					'event_espresso'
1793
+				)
1794
+			);
1795
+		}
1796
+		return $help_array;
1797
+	}
1798
+
1799
+
1800
+	/**
1801
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1802
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1803
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1804
+	 *
1805
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1806
+	 * @param boolean $display    if false then we return the trigger string
1807
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1808
+	 * @return string
1809
+	 * @throws DomainException
1810
+	 * @throws EE_Error
1811
+	 */
1812
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1813
+	{
1814
+		if ($this->request->isAjax()) {
1815
+			return '';
1816
+		}
1817
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1818
+		$help_array   = $this->_get_help_content();
1819
+		$help_content = '';
1820
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1821
+			$help_array[ $trigger_id ] = [
1822
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1823
+				'content' => esc_html__(
1824
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1825
+					'event_espresso'
1826
+				),
1827
+			];
1828
+			$help_content              = $this->_set_help_popup_content($help_array);
1829
+		}
1830
+		// let's setup the trigger
1831
+		$content = '<a class="ee-dialog" href="?height='
1832
+				   . esc_attr($dimensions[0])
1833
+				   . '&width='
1834
+				   . esc_attr($dimensions[1])
1835
+				   . '&inlineId='
1836
+				   . esc_attr($trigger_id)
1837
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1838
+		$content .= $help_content;
1839
+		if ($display) {
1840
+			echo $content; // already escaped
1841
+			return '';
1842
+		}
1843
+		return $content;
1844
+	}
1845
+
1846
+
1847
+	/**
1848
+	 * _add_global_screen_options
1849
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1850
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1851
+	 *
1852
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1853
+	 *         see also WP_Screen object documents...
1854
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1855
+	 * @abstract
1856
+	 * @return void
1857
+	 */
1858
+	private function _add_global_screen_options()
1859
+	{
1860
+	}
1861
+
1862
+
1863
+	/**
1864
+	 * _add_global_feature_pointers
1865
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1866
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1867
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1868
+	 *
1869
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1870
+	 *         extended) also see:
1871
+	 * @link   http://eamann.com/tech/wordpress-portland/
1872
+	 * @abstract
1873
+	 * @return void
1874
+	 */
1875
+	private function _add_global_feature_pointers()
1876
+	{
1877
+	}
1878
+
1879
+
1880
+	/**
1881
+	 * load_global_scripts_styles
1882
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1883
+	 *
1884
+	 * @return void
1885
+	 */
1886
+	public function load_global_scripts_styles()
1887
+	{
1888
+		/** STYLES **/
1889
+		// add debugging styles
1890
+		if (WP_DEBUG) {
1891
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1892
+		}
1893
+		// register all styles
1894
+		wp_register_style(
1895
+			'espresso-ui-theme',
1896
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1897
+			[],
1898
+			EVENT_ESPRESSO_VERSION
1899
+		);
1900
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1901
+		// helpers styles
1902
+		wp_register_style(
1903
+			'ee-text-links',
1904
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1905
+			[],
1906
+			EVENT_ESPRESSO_VERSION
1907
+		);
1908
+		/** SCRIPTS **/
1909
+		// register all scripts
1910
+		wp_register_script(
1911
+			'ee-dialog',
1912
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1913
+			['jquery', 'jquery-ui-draggable'],
1914
+			EVENT_ESPRESSO_VERSION,
1915
+			true
1916
+		);
1917
+		wp_register_script(
1918
+			'ee_admin_js',
1919
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1920
+			['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1921
+			EVENT_ESPRESSO_VERSION,
1922
+			true
1923
+		);
1924
+		wp_register_script(
1925
+			'jquery-ui-timepicker-addon',
1926
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1927
+			['jquery-ui-datepicker', 'jquery-ui-slider'],
1928
+			EVENT_ESPRESSO_VERSION,
1929
+			true
1930
+		);
1931
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1932
+		// if (EE_Registry::instance()->CFG->admin->help_tour_activation) {
1933
+		//     add_filter('FHEE_load_joyride', '__return_true');
1934
+		// }
1935
+		// script for sorting tables
1936
+		wp_register_script(
1937
+			'espresso_ajax_table_sorting',
1938
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1939
+			['ee_admin_js', 'jquery-ui-sortable'],
1940
+			EVENT_ESPRESSO_VERSION,
1941
+			true
1942
+		);
1943
+		// script for parsing uri's
1944
+		wp_register_script(
1945
+			'ee-parse-uri',
1946
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1947
+			[],
1948
+			EVENT_ESPRESSO_VERSION,
1949
+			true
1950
+		);
1951
+		// and parsing associative serialized form elements
1952
+		wp_register_script(
1953
+			'ee-serialize-full-array',
1954
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1955
+			['jquery'],
1956
+			EVENT_ESPRESSO_VERSION,
1957
+			true
1958
+		);
1959
+		// helpers scripts
1960
+		wp_register_script(
1961
+			'ee-text-links',
1962
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1963
+			['jquery'],
1964
+			EVENT_ESPRESSO_VERSION,
1965
+			true
1966
+		);
1967
+		wp_register_script(
1968
+			'ee-moment-core',
1969
+			EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1970
+			[],
1971
+			EVENT_ESPRESSO_VERSION,
1972
+			true
1973
+		);
1974
+		wp_register_script(
1975
+			'ee-moment',
1976
+			EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1977
+			['ee-moment-core'],
1978
+			EVENT_ESPRESSO_VERSION,
1979
+			true
1980
+		);
1981
+		wp_register_script(
1982
+			'ee-datepicker',
1983
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1984
+			['jquery-ui-timepicker-addon', 'ee-moment'],
1985
+			EVENT_ESPRESSO_VERSION,
1986
+			true
1987
+		);
1988
+		// google charts
1989
+		wp_register_script(
1990
+			'google-charts',
1991
+			'https://www.gstatic.com/charts/loader.js',
1992
+			[],
1993
+			EVENT_ESPRESSO_VERSION
1994
+		);
1995
+		// ENQUEUE ALL BASICS BY DEFAULT
1996
+		wp_enqueue_style('ee-admin-css');
1997
+		wp_enqueue_script('ee_admin_js');
1998
+		wp_enqueue_script('ee-accounting');
1999
+		wp_enqueue_script('jquery-validate');
2000
+		// taking care of metaboxes
2001
+		if (
2002
+			empty($this->_cpt_route)
2003
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
2004
+		) {
2005
+			wp_enqueue_script('dashboard');
2006
+		}
2007
+		// LOCALIZED DATA
2008
+		// localize script for ajax lazy loading
2009
+		$lazy_loader_container_ids = apply_filters(
2010
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
2011
+			['espresso_news_post_box_content']
2012
+		);
2013
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
2014
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
2015
+		// /**
2016
+		//  * help tour stuff
2017
+		//  */
2018
+		// if (! empty($this->_help_tour)) {
2019
+		//     // register the js for kicking things off
2020
+		//     wp_enqueue_script(
2021
+		//         'ee-help-tour',
2022
+		//         EE_ADMIN_URL . 'assets/ee-help-tour.js',
2023
+		//         array('jquery-joyride'),
2024
+		//         EVENT_ESPRESSO_VERSION,
2025
+		//         true
2026
+		//     );
2027
+		//     $tours = array();
2028
+		//     // setup tours for the js tour object
2029
+		//     foreach ($this->_help_tour['tours'] as $tour) {
2030
+		//         if ($tour instanceof EE_Help_Tour) {
2031
+		//             $tours[] = array(
2032
+		//                 'id'      => $tour->get_slug(),
2033
+		//                 'options' => $tour->get_options(),
2034
+		//             );
2035
+		//         }
2036
+		//     }
2037
+		//     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2038
+		//     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2039
+		// }
2040
+
2041
+		add_filter(
2042
+			'admin_body_class',
2043
+			function ($classes) {
2044
+				if (strpos($classes, 'espresso-admin') === false) {
2045
+					$classes .= ' espresso-admin';
2046
+				}
2047
+				return $classes;
2048
+			}
2049
+		);
2050
+	}
2051
+
2052
+
2053
+	/**
2054
+	 *        admin_footer_scripts_eei18n_js_strings
2055
+	 *
2056
+	 * @return        void
2057
+	 */
2058
+	public function admin_footer_scripts_eei18n_js_strings()
2059
+	{
2060
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
2061
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
2062
+			__(
2063
+				'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2064
+				'event_espresso'
2065
+			)
2066
+		);
2067
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
2068
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
2069
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
2070
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
2071
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
2072
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
2073
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
2074
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
2075
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
2076
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
2077
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
2078
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
2079
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
2080
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
2081
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
2082
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
2083
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
2084
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
2085
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
2086
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
2087
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
2088
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
2089
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
2090
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
2091
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
2092
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
2093
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
2094
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
2095
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
2096
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
2097
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
2098
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
2099
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
2100
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
2101
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
2102
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
2103
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
2104
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
2105
+	}
2106
+
2107
+
2108
+	/**
2109
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2110
+	 *
2111
+	 * @return        void
2112
+	 */
2113
+	public function add_xdebug_style()
2114
+	{
2115
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2116
+	}
2117
+
2118
+
2119
+	/************************/
2120
+	/** LIST TABLE METHODS **/
2121
+	/************************/
2122
+	/**
2123
+	 * this sets up the list table if the current view requires it.
2124
+	 *
2125
+	 * @return void
2126
+	 * @throws EE_Error
2127
+	 */
2128
+	protected function _set_list_table()
2129
+	{
2130
+		// first is this a list_table view?
2131
+		if (! isset($this->_route_config['list_table'])) {
2132
+			return;
2133
+		} //not a list_table view so get out.
2134
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2135
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2136
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2137
+			// user error msg
2138
+			$error_msg = esc_html__(
2139
+				'An error occurred. The requested list table views could not be found.',
2140
+				'event_espresso'
2141
+			);
2142
+			// developer error msg
2143
+			$error_msg .= '||'
2144
+						  . sprintf(
2145
+							  esc_html__(
2146
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2147
+								  'event_espresso'
2148
+							  ),
2149
+							  $this->_req_action,
2150
+							  $list_table_view
2151
+						  );
2152
+			throw new EE_Error($error_msg);
2153
+		}
2154
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2155
+		$this->_views = apply_filters(
2156
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2157
+			$this->_views
2158
+		);
2159
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2160
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2161
+		$this->_set_list_table_view();
2162
+		$this->_set_list_table_object();
2163
+	}
2164
+
2165
+
2166
+	/**
2167
+	 * set current view for List Table
2168
+	 *
2169
+	 * @return void
2170
+	 */
2171
+	protected function _set_list_table_view()
2172
+	{
2173
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2174
+		$status = $this->request->getRequestParam('status', null, 'key');
2175
+		$this->_view = $status && array_key_exists($status, $this->_views)
2176
+			? $status
2177
+			: $this->_view;
2178
+	}
2179
+
2180
+
2181
+	/**
2182
+	 * _set_list_table_object
2183
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2184
+	 *
2185
+	 * @throws InvalidInterfaceException
2186
+	 * @throws InvalidArgumentException
2187
+	 * @throws InvalidDataTypeException
2188
+	 * @throws EE_Error
2189
+	 * @throws InvalidInterfaceException
2190
+	 */
2191
+	protected function _set_list_table_object()
2192
+	{
2193
+		if (isset($this->_route_config['list_table'])) {
2194
+			if (! class_exists($this->_route_config['list_table'])) {
2195
+				throw new EE_Error(
2196
+					sprintf(
2197
+						esc_html__(
2198
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2199
+							'event_espresso'
2200
+						),
2201
+						$this->_route_config['list_table'],
2202
+						get_class($this)
2203
+					)
2204
+				);
2205
+			}
2206
+			$this->_list_table_object = $this->loader->getShared(
2207
+				$this->_route_config['list_table'],
2208
+				[$this]
2209
+			);
2210
+		}
2211
+	}
2212
+
2213
+
2214
+	/**
2215
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2216
+	 *
2217
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2218
+	 *                                                    urls.  The array should be indexed by the view it is being
2219
+	 *                                                    added to.
2220
+	 * @return array
2221
+	 */
2222
+	public function get_list_table_view_RLs($extra_query_args = [])
2223
+	{
2224
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2225
+		if (empty($this->_views)) {
2226
+			$this->_views = [];
2227
+		}
2228
+		// cycle thru views
2229
+		foreach ($this->_views as $key => $view) {
2230
+			$query_args = [];
2231
+			// check for current view
2232
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2233
+			$query_args['action']                        = $this->_req_action;
2234
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2235
+			$query_args['status']                        = $view['slug'];
2236
+			// merge any other arguments sent in.
2237
+			if (isset($extra_query_args[ $view['slug'] ])) {
2238
+				$query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2239
+			}
2240
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2241
+		}
2242
+		return $this->_views;
2243
+	}
2244
+
2245
+
2246
+	/**
2247
+	 * _entries_per_page_dropdown
2248
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2249
+	 *
2250
+	 * @param int $max_entries total number of rows in the table
2251
+	 * @return string
2252
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2253
+	 *         WP does it.
2254
+	 */
2255
+	protected function _entries_per_page_dropdown($max_entries = 0)
2256
+	{
2257
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2258
+		$values   = [10, 25, 50, 100];
2259
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2260
+		if ($max_entries) {
2261
+			$values[] = $max_entries;
2262
+			sort($values);
2263
+		}
2264
+		$entries_per_page_dropdown = '
2265 2265
 			<div id="entries-per-page-dv" class="alignleft actions">
2266 2266
 				<label class="hide-if-no-js">
2267 2267
 					Show
2268 2268
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2269
-        foreach ($values as $value) {
2270
-            if ($value < $max_entries) {
2271
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2272
-                $entries_per_page_dropdown .= '
2269
+		foreach ($values as $value) {
2270
+			if ($value < $max_entries) {
2271
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2272
+				$entries_per_page_dropdown .= '
2273 2273
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2274
-            }
2275
-        }
2276
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2277
-        $entries_per_page_dropdown .= '
2274
+			}
2275
+		}
2276
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2277
+		$entries_per_page_dropdown .= '
2278 2278
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2279
-        $entries_per_page_dropdown .= '
2279
+		$entries_per_page_dropdown .= '
2280 2280
 					</select>
2281 2281
 					entries
2282 2282
 				</label>
2283 2283
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2284 2284
 			</div>
2285 2285
 		';
2286
-        return $entries_per_page_dropdown;
2287
-    }
2288
-
2289
-
2290
-    /**
2291
-     *        _set_search_attributes
2292
-     *
2293
-     * @return        void
2294
-     */
2295
-    public function _set_search_attributes()
2296
-    {
2297
-        $this->_template_args['search']['btn_label'] = sprintf(
2298
-            esc_html__('Search %s', 'event_espresso'),
2299
-            empty($this->_search_btn_label) ? $this->page_label
2300
-                : $this->_search_btn_label
2301
-        );
2302
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2303
-    }
2304
-
2305
-
2306
-
2307
-    /*** END LIST TABLE METHODS **/
2308
-
2309
-
2310
-    /**
2311
-     * _add_registered_metaboxes
2312
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2313
-     *
2314
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2315
-     * @return void
2316
-     * @throws EE_Error
2317
-     */
2318
-    private function _add_registered_meta_boxes()
2319
-    {
2320
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2321
-        // we only add meta boxes if the page_route calls for it
2322
-        if (
2323
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2324
-            && is_array(
2325
-                $this->_route_config['metaboxes']
2326
-            )
2327
-        ) {
2328
-            // this simply loops through the callbacks provided
2329
-            // and checks if there is a corresponding callback registered by the child
2330
-            // if there is then we go ahead and process the metabox loader.
2331
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2332
-                // first check for Closures
2333
-                if ($metabox_callback instanceof Closure) {
2334
-                    $result = $metabox_callback();
2335
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2336
-                    $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2337
-                } else {
2338
-                    $result = call_user_func([$this, &$metabox_callback]);
2339
-                }
2340
-                if ($result === false) {
2341
-                    // user error msg
2342
-                    $error_msg = esc_html__(
2343
-                        'An error occurred. The  requested metabox could not be found.',
2344
-                        'event_espresso'
2345
-                    );
2346
-                    // developer error msg
2347
-                    $error_msg .= '||'
2348
-                                  . sprintf(
2349
-                                      esc_html__(
2350
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2351
-                                          'event_espresso'
2352
-                                      ),
2353
-                                      $metabox_callback
2354
-                                  );
2355
-                    throw new EE_Error($error_msg);
2356
-                }
2357
-            }
2358
-        }
2359
-    }
2360
-
2361
-
2362
-    /**
2363
-     * _add_screen_columns
2364
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2365
-     * the dynamic column template and we'll setup the column options for the page.
2366
-     *
2367
-     * @return void
2368
-     */
2369
-    private function _add_screen_columns()
2370
-    {
2371
-        if (
2372
-            is_array($this->_route_config)
2373
-            && isset($this->_route_config['columns'])
2374
-            && is_array($this->_route_config['columns'])
2375
-            && count($this->_route_config['columns']) === 2
2376
-        ) {
2377
-            add_screen_option(
2378
-                'layout_columns',
2379
-                [
2380
-                    'max'     => (int) $this->_route_config['columns'][0],
2381
-                    'default' => (int) $this->_route_config['columns'][1],
2382
-                ]
2383
-            );
2384
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2385
-            $screen_id                                           = $this->_current_screen->id;
2386
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2387
-            $total_columns                                       = ! empty($screen_columns)
2388
-                ? $screen_columns
2389
-                : $this->_route_config['columns'][1];
2390
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2391
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2392
-            $this->_template_args['screen']                      = $this->_current_screen;
2393
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2394
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2395
-            // finally if we don't have has_metaboxes set in the route config
2396
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2397
-            $this->_route_config['has_metaboxes'] = true;
2398
-        }
2399
-    }
2400
-
2401
-
2402
-
2403
-    /** GLOBALLY AVAILABLE METABOXES **/
2404
-
2405
-
2406
-    /**
2407
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2408
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2409
-     * these get loaded on.
2410
-     */
2411
-    private function _espresso_news_post_box()
2412
-    {
2413
-        $news_box_title = apply_filters(
2414
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2415
-            esc_html__('New @ Event Espresso', 'event_espresso')
2416
-        );
2417
-        add_meta_box(
2418
-            'espresso_news_post_box',
2419
-            $news_box_title,
2420
-            [
2421
-                $this,
2422
-                'espresso_news_post_box',
2423
-            ],
2424
-            $this->_wp_page_slug,
2425
-            'side'
2426
-        );
2427
-    }
2428
-
2429
-
2430
-    /**
2431
-     * Code for setting up espresso ratings request metabox.
2432
-     */
2433
-    protected function _espresso_ratings_request()
2434
-    {
2435
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2436
-            return;
2437
-        }
2438
-        $ratings_box_title = apply_filters(
2439
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2440
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2441
-        );
2442
-        add_meta_box(
2443
-            'espresso_ratings_request',
2444
-            $ratings_box_title,
2445
-            [
2446
-                $this,
2447
-                'espresso_ratings_request',
2448
-            ],
2449
-            $this->_wp_page_slug,
2450
-            'side'
2451
-        );
2452
-    }
2453
-
2454
-
2455
-    /**
2456
-     * Code for setting up espresso ratings request metabox content.
2457
-     *
2458
-     * @throws DomainException
2459
-     */
2460
-    public function espresso_ratings_request()
2461
-    {
2462
-        EEH_Template::display_template(
2463
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2464
-            []
2465
-        );
2466
-    }
2467
-
2468
-
2469
-    public static function cached_rss_display($rss_id, $url)
2470
-    {
2471
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2472
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2473
-                     . '</p><p class="hide-if-js">'
2474
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2475
-                     . '</p>';
2476
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2477
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2478
-        $post      = '</div>' . "\n";
2479
-        $cache_key = 'ee_rss_' . md5($rss_id);
2480
-        $output    = get_transient($cache_key);
2481
-        if ($output !== false) {
2482
-            echo $pre . $output . $post; // already escaped
2483
-            return true;
2484
-        }
2485
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2486
-            echo $pre . $loading . $post; // already escaped
2487
-            return false;
2488
-        }
2489
-        ob_start();
2490
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2491
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2492
-        return true;
2493
-    }
2494
-
2495
-
2496
-    public function espresso_news_post_box()
2497
-    {
2498
-        ?>
2286
+		return $entries_per_page_dropdown;
2287
+	}
2288
+
2289
+
2290
+	/**
2291
+	 *        _set_search_attributes
2292
+	 *
2293
+	 * @return        void
2294
+	 */
2295
+	public function _set_search_attributes()
2296
+	{
2297
+		$this->_template_args['search']['btn_label'] = sprintf(
2298
+			esc_html__('Search %s', 'event_espresso'),
2299
+			empty($this->_search_btn_label) ? $this->page_label
2300
+				: $this->_search_btn_label
2301
+		);
2302
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2303
+	}
2304
+
2305
+
2306
+
2307
+	/*** END LIST TABLE METHODS **/
2308
+
2309
+
2310
+	/**
2311
+	 * _add_registered_metaboxes
2312
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2313
+	 *
2314
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2315
+	 * @return void
2316
+	 * @throws EE_Error
2317
+	 */
2318
+	private function _add_registered_meta_boxes()
2319
+	{
2320
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2321
+		// we only add meta boxes if the page_route calls for it
2322
+		if (
2323
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2324
+			&& is_array(
2325
+				$this->_route_config['metaboxes']
2326
+			)
2327
+		) {
2328
+			// this simply loops through the callbacks provided
2329
+			// and checks if there is a corresponding callback registered by the child
2330
+			// if there is then we go ahead and process the metabox loader.
2331
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2332
+				// first check for Closures
2333
+				if ($metabox_callback instanceof Closure) {
2334
+					$result = $metabox_callback();
2335
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2336
+					$result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2337
+				} else {
2338
+					$result = call_user_func([$this, &$metabox_callback]);
2339
+				}
2340
+				if ($result === false) {
2341
+					// user error msg
2342
+					$error_msg = esc_html__(
2343
+						'An error occurred. The  requested metabox could not be found.',
2344
+						'event_espresso'
2345
+					);
2346
+					// developer error msg
2347
+					$error_msg .= '||'
2348
+								  . sprintf(
2349
+									  esc_html__(
2350
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2351
+										  'event_espresso'
2352
+									  ),
2353
+									  $metabox_callback
2354
+								  );
2355
+					throw new EE_Error($error_msg);
2356
+				}
2357
+			}
2358
+		}
2359
+	}
2360
+
2361
+
2362
+	/**
2363
+	 * _add_screen_columns
2364
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2365
+	 * the dynamic column template and we'll setup the column options for the page.
2366
+	 *
2367
+	 * @return void
2368
+	 */
2369
+	private function _add_screen_columns()
2370
+	{
2371
+		if (
2372
+			is_array($this->_route_config)
2373
+			&& isset($this->_route_config['columns'])
2374
+			&& is_array($this->_route_config['columns'])
2375
+			&& count($this->_route_config['columns']) === 2
2376
+		) {
2377
+			add_screen_option(
2378
+				'layout_columns',
2379
+				[
2380
+					'max'     => (int) $this->_route_config['columns'][0],
2381
+					'default' => (int) $this->_route_config['columns'][1],
2382
+				]
2383
+			);
2384
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2385
+			$screen_id                                           = $this->_current_screen->id;
2386
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2387
+			$total_columns                                       = ! empty($screen_columns)
2388
+				? $screen_columns
2389
+				: $this->_route_config['columns'][1];
2390
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2391
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2392
+			$this->_template_args['screen']                      = $this->_current_screen;
2393
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2394
+																   . 'admin_details_metabox_column_wrapper.template.php';
2395
+			// finally if we don't have has_metaboxes set in the route config
2396
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2397
+			$this->_route_config['has_metaboxes'] = true;
2398
+		}
2399
+	}
2400
+
2401
+
2402
+
2403
+	/** GLOBALLY AVAILABLE METABOXES **/
2404
+
2405
+
2406
+	/**
2407
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2408
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2409
+	 * these get loaded on.
2410
+	 */
2411
+	private function _espresso_news_post_box()
2412
+	{
2413
+		$news_box_title = apply_filters(
2414
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2415
+			esc_html__('New @ Event Espresso', 'event_espresso')
2416
+		);
2417
+		add_meta_box(
2418
+			'espresso_news_post_box',
2419
+			$news_box_title,
2420
+			[
2421
+				$this,
2422
+				'espresso_news_post_box',
2423
+			],
2424
+			$this->_wp_page_slug,
2425
+			'side'
2426
+		);
2427
+	}
2428
+
2429
+
2430
+	/**
2431
+	 * Code for setting up espresso ratings request metabox.
2432
+	 */
2433
+	protected function _espresso_ratings_request()
2434
+	{
2435
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2436
+			return;
2437
+		}
2438
+		$ratings_box_title = apply_filters(
2439
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2440
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2441
+		);
2442
+		add_meta_box(
2443
+			'espresso_ratings_request',
2444
+			$ratings_box_title,
2445
+			[
2446
+				$this,
2447
+				'espresso_ratings_request',
2448
+			],
2449
+			$this->_wp_page_slug,
2450
+			'side'
2451
+		);
2452
+	}
2453
+
2454
+
2455
+	/**
2456
+	 * Code for setting up espresso ratings request metabox content.
2457
+	 *
2458
+	 * @throws DomainException
2459
+	 */
2460
+	public function espresso_ratings_request()
2461
+	{
2462
+		EEH_Template::display_template(
2463
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2464
+			[]
2465
+		);
2466
+	}
2467
+
2468
+
2469
+	public static function cached_rss_display($rss_id, $url)
2470
+	{
2471
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2472
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2473
+					 . '</p><p class="hide-if-js">'
2474
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2475
+					 . '</p>';
2476
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2477
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2478
+		$post      = '</div>' . "\n";
2479
+		$cache_key = 'ee_rss_' . md5($rss_id);
2480
+		$output    = get_transient($cache_key);
2481
+		if ($output !== false) {
2482
+			echo $pre . $output . $post; // already escaped
2483
+			return true;
2484
+		}
2485
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2486
+			echo $pre . $loading . $post; // already escaped
2487
+			return false;
2488
+		}
2489
+		ob_start();
2490
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2491
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2492
+		return true;
2493
+	}
2494
+
2495
+
2496
+	public function espresso_news_post_box()
2497
+	{
2498
+		?>
2499 2499
         <div class="padding">
2500 2500
             <div id="espresso_news_post_box_content" class="infolinks">
2501 2501
                 <?php
2502
-                // Get RSS Feed(s)
2503
-                self::cached_rss_display(
2504
-                    'espresso_news_post_box_content',
2505
-                    esc_url_raw(
2506
-                        apply_filters(
2507
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2508
-                            'https://eventespresso.com/feed/'
2509
-                        )
2510
-                    )
2511
-                );
2512
-                ?>
2502
+				// Get RSS Feed(s)
2503
+				self::cached_rss_display(
2504
+					'espresso_news_post_box_content',
2505
+					esc_url_raw(
2506
+						apply_filters(
2507
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2508
+							'https://eventespresso.com/feed/'
2509
+						)
2510
+					)
2511
+				);
2512
+				?>
2513 2513
             </div>
2514 2514
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2515 2515
         </div>
2516 2516
         <?php
2517
-    }
2518
-
2519
-
2520
-    private function _espresso_links_post_box()
2521
-    {
2522
-        // Hiding until we actually have content to put in here...
2523
-        // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2524
-    }
2525
-
2526
-
2527
-    public function espresso_links_post_box()
2528
-    {
2529
-        // Hiding until we actually have content to put in here...
2530
-        // EEH_Template::display_template(
2531
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2532
-        // );
2533
-    }
2534
-
2535
-
2536
-    protected function _espresso_sponsors_post_box()
2537
-    {
2538
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2539
-            add_meta_box(
2540
-                'espresso_sponsors_post_box',
2541
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2542
-                [$this, 'espresso_sponsors_post_box'],
2543
-                $this->_wp_page_slug,
2544
-                'side'
2545
-            );
2546
-        }
2547
-    }
2548
-
2549
-
2550
-    public function espresso_sponsors_post_box()
2551
-    {
2552
-        EEH_Template::display_template(
2553
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2554
-        );
2555
-    }
2556
-
2557
-
2558
-    private function _publish_post_box()
2559
-    {
2560
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2561
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2562
-        // then we'll use that for the metabox label.
2563
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2564
-        if (! empty($this->_labels['publishbox'])) {
2565
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2566
-                : $this->_labels['publishbox'];
2567
-        } else {
2568
-            $box_label = esc_html__('Publish', 'event_espresso');
2569
-        }
2570
-        $box_label = apply_filters(
2571
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2572
-            $box_label,
2573
-            $this->_req_action,
2574
-            $this
2575
-        );
2576
-        add_meta_box(
2577
-            $meta_box_ref,
2578
-            $box_label,
2579
-            [$this, 'editor_overview'],
2580
-            $this->_current_screen->id,
2581
-            'side',
2582
-            'high'
2583
-        );
2584
-    }
2585
-
2586
-
2587
-    public function editor_overview()
2588
-    {
2589
-        // if we have extra content set let's add it in if not make sure its empty
2590
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2591
-            ? $this->_template_args['publish_box_extra_content']
2592
-            : '';
2593
-        echo EEH_Template::display_template(
2594
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2595
-            $this->_template_args,
2596
-            true
2597
-        );
2598
-    }
2599
-
2600
-
2601
-    /** end of globally available metaboxes section **/
2602
-
2603
-
2604
-    /**
2605
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2606
-     * protected method.
2607
-     *
2608
-     * @param string $name
2609
-     * @param int    $id
2610
-     * @param bool   $delete
2611
-     * @param string $save_close_redirect_URL
2612
-     * @param bool   $both_btns
2613
-     * @throws EE_Error
2614
-     * @throws InvalidArgumentException
2615
-     * @throws InvalidDataTypeException
2616
-     * @throws InvalidInterfaceException
2617
-     * @see   $this->_set_publish_post_box_vars for param details
2618
-     * @since 4.6.0
2619
-     */
2620
-    public function set_publish_post_box_vars(
2621
-        $name = '',
2622
-        $id = 0,
2623
-        $delete = false,
2624
-        $save_close_redirect_URL = '',
2625
-        $both_btns = true
2626
-    ) {
2627
-        $this->_set_publish_post_box_vars(
2628
-            $name,
2629
-            $id,
2630
-            $delete,
2631
-            $save_close_redirect_URL,
2632
-            $both_btns
2633
-        );
2634
-    }
2635
-
2636
-
2637
-    /**
2638
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2639
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2640
-     * save, and save and close buttons to work properly, then you will want to include a
2641
-     * values for the name and id arguments.
2642
-     *
2643
-     * @param string  $name                       key used for the action ID (i.e. event_id)
2644
-     * @param int     $id                         id attached to the item published
2645
-     * @param string  $delete                     page route callback for the delete action
2646
-     * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2647
-     * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2648
-     *                                            the Save button
2649
-     * @throws EE_Error
2650
-     * @throws InvalidArgumentException
2651
-     * @throws InvalidDataTypeException
2652
-     * @throws InvalidInterfaceException
2653
-     * @todo  Add in validation for name/id arguments.
2654
-     */
2655
-    protected function _set_publish_post_box_vars(
2656
-        $name = '',
2657
-        $id = 0,
2658
-        $delete = '',
2659
-        $save_close_redirect_URL = '',
2660
-        $both_btns = true
2661
-    ) {
2662
-        // if Save & Close, use a custom redirect URL or default to the main page?
2663
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2664
-            ? $save_close_redirect_URL
2665
-            : $this->_admin_base_url;
2666
-        // create the Save & Close and Save buttons
2667
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2668
-        // if we have extra content set let's add it in if not make sure its empty
2669
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2670
-            ? $this->_template_args['publish_box_extra_content']
2671
-            : '';
2672
-        if ($delete && ! empty($id)) {
2673
-            // make sure we have a default if just true is sent.
2674
-            $delete           = ! empty($delete) ? $delete : 'delete';
2675
-            $delete_link_args = [$name => $id];
2676
-            $delete           = $this->get_action_link_or_button(
2677
-                $delete,
2678
-                $delete,
2679
-                $delete_link_args,
2680
-                'submitdelete deletion',
2681
-                '',
2682
-                false
2683
-            );
2684
-        }
2685
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2686
-        if (! empty($name) && ! empty($id)) {
2687
-            $hidden_field_arr[ $name ] = [
2688
-                'type'  => 'hidden',
2689
-                'value' => $id,
2690
-            ];
2691
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2692
-        } else {
2693
-            $hf = '';
2694
-        }
2695
-        // add hidden field
2696
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2697
-            ? $hf[ $name ]['field']
2698
-            : $hf;
2699
-    }
2700
-
2701
-
2702
-    /**
2703
-     * displays an error message to ppl who have javascript disabled
2704
-     *
2705
-     * @return void
2706
-     */
2707
-    private function _display_no_javascript_warning()
2708
-    {
2709
-        ?>
2517
+	}
2518
+
2519
+
2520
+	private function _espresso_links_post_box()
2521
+	{
2522
+		// Hiding until we actually have content to put in here...
2523
+		// add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2524
+	}
2525
+
2526
+
2527
+	public function espresso_links_post_box()
2528
+	{
2529
+		// Hiding until we actually have content to put in here...
2530
+		// EEH_Template::display_template(
2531
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2532
+		// );
2533
+	}
2534
+
2535
+
2536
+	protected function _espresso_sponsors_post_box()
2537
+	{
2538
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2539
+			add_meta_box(
2540
+				'espresso_sponsors_post_box',
2541
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2542
+				[$this, 'espresso_sponsors_post_box'],
2543
+				$this->_wp_page_slug,
2544
+				'side'
2545
+			);
2546
+		}
2547
+	}
2548
+
2549
+
2550
+	public function espresso_sponsors_post_box()
2551
+	{
2552
+		EEH_Template::display_template(
2553
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2554
+		);
2555
+	}
2556
+
2557
+
2558
+	private function _publish_post_box()
2559
+	{
2560
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2561
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2562
+		// then we'll use that for the metabox label.
2563
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2564
+		if (! empty($this->_labels['publishbox'])) {
2565
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2566
+				: $this->_labels['publishbox'];
2567
+		} else {
2568
+			$box_label = esc_html__('Publish', 'event_espresso');
2569
+		}
2570
+		$box_label = apply_filters(
2571
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2572
+			$box_label,
2573
+			$this->_req_action,
2574
+			$this
2575
+		);
2576
+		add_meta_box(
2577
+			$meta_box_ref,
2578
+			$box_label,
2579
+			[$this, 'editor_overview'],
2580
+			$this->_current_screen->id,
2581
+			'side',
2582
+			'high'
2583
+		);
2584
+	}
2585
+
2586
+
2587
+	public function editor_overview()
2588
+	{
2589
+		// if we have extra content set let's add it in if not make sure its empty
2590
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2591
+			? $this->_template_args['publish_box_extra_content']
2592
+			: '';
2593
+		echo EEH_Template::display_template(
2594
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2595
+			$this->_template_args,
2596
+			true
2597
+		);
2598
+	}
2599
+
2600
+
2601
+	/** end of globally available metaboxes section **/
2602
+
2603
+
2604
+	/**
2605
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2606
+	 * protected method.
2607
+	 *
2608
+	 * @param string $name
2609
+	 * @param int    $id
2610
+	 * @param bool   $delete
2611
+	 * @param string $save_close_redirect_URL
2612
+	 * @param bool   $both_btns
2613
+	 * @throws EE_Error
2614
+	 * @throws InvalidArgumentException
2615
+	 * @throws InvalidDataTypeException
2616
+	 * @throws InvalidInterfaceException
2617
+	 * @see   $this->_set_publish_post_box_vars for param details
2618
+	 * @since 4.6.0
2619
+	 */
2620
+	public function set_publish_post_box_vars(
2621
+		$name = '',
2622
+		$id = 0,
2623
+		$delete = false,
2624
+		$save_close_redirect_URL = '',
2625
+		$both_btns = true
2626
+	) {
2627
+		$this->_set_publish_post_box_vars(
2628
+			$name,
2629
+			$id,
2630
+			$delete,
2631
+			$save_close_redirect_URL,
2632
+			$both_btns
2633
+		);
2634
+	}
2635
+
2636
+
2637
+	/**
2638
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2639
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2640
+	 * save, and save and close buttons to work properly, then you will want to include a
2641
+	 * values for the name and id arguments.
2642
+	 *
2643
+	 * @param string  $name                       key used for the action ID (i.e. event_id)
2644
+	 * @param int     $id                         id attached to the item published
2645
+	 * @param string  $delete                     page route callback for the delete action
2646
+	 * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2647
+	 * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2648
+	 *                                            the Save button
2649
+	 * @throws EE_Error
2650
+	 * @throws InvalidArgumentException
2651
+	 * @throws InvalidDataTypeException
2652
+	 * @throws InvalidInterfaceException
2653
+	 * @todo  Add in validation for name/id arguments.
2654
+	 */
2655
+	protected function _set_publish_post_box_vars(
2656
+		$name = '',
2657
+		$id = 0,
2658
+		$delete = '',
2659
+		$save_close_redirect_URL = '',
2660
+		$both_btns = true
2661
+	) {
2662
+		// if Save & Close, use a custom redirect URL or default to the main page?
2663
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2664
+			? $save_close_redirect_URL
2665
+			: $this->_admin_base_url;
2666
+		// create the Save & Close and Save buttons
2667
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2668
+		// if we have extra content set let's add it in if not make sure its empty
2669
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2670
+			? $this->_template_args['publish_box_extra_content']
2671
+			: '';
2672
+		if ($delete && ! empty($id)) {
2673
+			// make sure we have a default if just true is sent.
2674
+			$delete           = ! empty($delete) ? $delete : 'delete';
2675
+			$delete_link_args = [$name => $id];
2676
+			$delete           = $this->get_action_link_or_button(
2677
+				$delete,
2678
+				$delete,
2679
+				$delete_link_args,
2680
+				'submitdelete deletion',
2681
+				'',
2682
+				false
2683
+			);
2684
+		}
2685
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2686
+		if (! empty($name) && ! empty($id)) {
2687
+			$hidden_field_arr[ $name ] = [
2688
+				'type'  => 'hidden',
2689
+				'value' => $id,
2690
+			];
2691
+			$hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2692
+		} else {
2693
+			$hf = '';
2694
+		}
2695
+		// add hidden field
2696
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2697
+			? $hf[ $name ]['field']
2698
+			: $hf;
2699
+	}
2700
+
2701
+
2702
+	/**
2703
+	 * displays an error message to ppl who have javascript disabled
2704
+	 *
2705
+	 * @return void
2706
+	 */
2707
+	private function _display_no_javascript_warning()
2708
+	{
2709
+		?>
2710 2710
         <noscript>
2711 2711
             <div id="no-js-message" class="error">
2712 2712
                 <p style="font-size:1.3em;">
2713 2713
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2714 2714
                     <?php esc_html_e(
2715
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2716
-                        'event_espresso'
2717
-                    ); ?>
2715
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2716
+						'event_espresso'
2717
+					); ?>
2718 2718
                 </p>
2719 2719
             </div>
2720 2720
         </noscript>
2721 2721
         <?php
2722
-    }
2723
-
2724
-
2725
-    /**
2726
-     * displays espresso success and/or error notices
2727
-     *
2728
-     * @return void
2729
-     */
2730
-    protected function _display_espresso_notices()
2731
-    {
2732
-        $notices = $this->_get_transient(true);
2733
-        echo stripslashes($notices);
2734
-    }
2735
-
2736
-
2737
-    /**
2738
-     * spinny things pacify the masses
2739
-     *
2740
-     * @return void
2741
-     */
2742
-    protected function _add_admin_page_ajax_loading_img()
2743
-    {
2744
-        ?>
2722
+	}
2723
+
2724
+
2725
+	/**
2726
+	 * displays espresso success and/or error notices
2727
+	 *
2728
+	 * @return void
2729
+	 */
2730
+	protected function _display_espresso_notices()
2731
+	{
2732
+		$notices = $this->_get_transient(true);
2733
+		echo stripslashes($notices);
2734
+	}
2735
+
2736
+
2737
+	/**
2738
+	 * spinny things pacify the masses
2739
+	 *
2740
+	 * @return void
2741
+	 */
2742
+	protected function _add_admin_page_ajax_loading_img()
2743
+	{
2744
+		?>
2745 2745
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2746 2746
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2747
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2747
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2748 2748
         </div>
2749 2749
         <?php
2750
-    }
2750
+	}
2751 2751
 
2752 2752
 
2753
-    /**
2754
-     * add admin page overlay for modal boxes
2755
-     *
2756
-     * @return void
2757
-     */
2758
-    protected function _add_admin_page_overlay()
2759
-    {
2760
-        ?>
2753
+	/**
2754
+	 * add admin page overlay for modal boxes
2755
+	 *
2756
+	 * @return void
2757
+	 */
2758
+	protected function _add_admin_page_overlay()
2759
+	{
2760
+		?>
2761 2761
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2762 2762
         <?php
2763
-    }
2764
-
2765
-
2766
-    /**
2767
-     * facade for add_meta_box
2768
-     *
2769
-     * @param string  $action        where the metabox gets displayed
2770
-     * @param string  $title         Title of Metabox (output in metabox header)
2771
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2772
-     *                               instead of the one created in here.
2773
-     * @param array   $callback_args an array of args supplied for the metabox
2774
-     * @param string  $column        what metabox column
2775
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2776
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2777
-     *                               created but just set our own callback for wp's add_meta_box.
2778
-     * @throws DomainException
2779
-     */
2780
-    public function _add_admin_page_meta_box(
2781
-        $action,
2782
-        $title,
2783
-        $callback,
2784
-        $callback_args,
2785
-        $column = 'normal',
2786
-        $priority = 'high',
2787
-        $create_func = true
2788
-    ) {
2789
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2790
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2791
-        if (empty($callback_args) && $create_func) {
2792
-            $callback_args = [
2793
-                'template_path' => $this->_template_path,
2794
-                'template_args' => $this->_template_args,
2795
-            ];
2796
-        }
2797
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2798
-        $call_back_func = $create_func
2799
-            ? function ($post, $metabox) {
2800
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2801
-                echo EEH_Template::display_template(
2802
-                    $metabox['args']['template_path'],
2803
-                    $metabox['args']['template_args'],
2804
-                    true
2805
-                );
2806
-            }
2807
-            : $callback;
2808
-        add_meta_box(
2809
-            str_replace('_', '-', $action) . '-mbox',
2810
-            $title,
2811
-            $call_back_func,
2812
-            $this->_wp_page_slug,
2813
-            $column,
2814
-            $priority,
2815
-            $callback_args
2816
-        );
2817
-    }
2818
-
2819
-
2820
-    /**
2821
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2822
-     *
2823
-     * @throws DomainException
2824
-     * @throws EE_Error
2825
-     */
2826
-    public function display_admin_page_with_metabox_columns()
2827
-    {
2828
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2829
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2830
-            $this->_column_template_path,
2831
-            $this->_template_args,
2832
-            true
2833
-        );
2834
-        // the final wrapper
2835
-        $this->admin_page_wrapper();
2836
-    }
2837
-
2838
-
2839
-    /**
2840
-     * generates  HTML wrapper for an admin details page
2841
-     *
2842
-     * @return void
2843
-     * @throws EE_Error
2844
-     * @throws DomainException
2845
-     */
2846
-    public function display_admin_page_with_sidebar()
2847
-    {
2848
-        $this->_display_admin_page(true);
2849
-    }
2850
-
2851
-
2852
-    /**
2853
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2854
-     *
2855
-     * @return void
2856
-     * @throws EE_Error
2857
-     * @throws DomainException
2858
-     */
2859
-    public function display_admin_page_with_no_sidebar()
2860
-    {
2861
-        $this->_display_admin_page();
2862
-    }
2863
-
2864
-
2865
-    /**
2866
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2867
-     *
2868
-     * @return void
2869
-     * @throws EE_Error
2870
-     * @throws DomainException
2871
-     */
2872
-    public function display_about_admin_page()
2873
-    {
2874
-        $this->_display_admin_page(false, true);
2875
-    }
2876
-
2877
-
2878
-    /**
2879
-     * display_admin_page
2880
-     * contains the code for actually displaying an admin page
2881
-     *
2882
-     * @param boolean $sidebar true with sidebar, false without
2883
-     * @param boolean $about   use the about_admin_wrapper instead of the default.
2884
-     * @return void
2885
-     * @throws DomainException
2886
-     * @throws EE_Error
2887
-     */
2888
-    private function _display_admin_page($sidebar = false, $about = false)
2889
-    {
2890
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2891
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2892
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2893
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2894
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2895
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2896
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2897
-            ? 'poststuff'
2898
-            : 'espresso-default-admin';
2899
-        $template_path                                     = $sidebar
2900
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2901
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2902
-        if ($this->request->isAjax()) {
2903
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2904
-        }
2905
-        $template_path                                     = ! empty($this->_column_template_path)
2906
-            ? $this->_column_template_path : $template_path;
2907
-        $this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2908
-            ? $this->_template_args['admin_page_content']
2909
-            : '';
2910
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2911
-            ? $this->_template_args['before_admin_page_content']
2912
-            : '';
2913
-        $this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2914
-            ? $this->_template_args['after_admin_page_content']
2915
-            : '';
2916
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2917
-            $template_path,
2918
-            $this->_template_args,
2919
-            true
2920
-        );
2921
-        // the final template wrapper
2922
-        $this->admin_page_wrapper($about);
2923
-    }
2924
-
2925
-
2926
-    /**
2927
-     * This is used to display caf preview pages.
2928
-     *
2929
-     * @param string $utm_campaign_source what is the key used for google analytics link
2930
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2931
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2932
-     * @return void
2933
-     * @throws DomainException
2934
-     * @throws EE_Error
2935
-     * @throws InvalidArgumentException
2936
-     * @throws InvalidDataTypeException
2937
-     * @throws InvalidInterfaceException
2938
-     * @since 4.3.2
2939
-     */
2940
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2941
-    {
2942
-        // let's generate a default preview action button if there isn't one already present.
2943
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2944
-            'Upgrade to Event Espresso 4 Right Now',
2945
-            'event_espresso'
2946
-        );
2947
-        $buy_now_url                                   = add_query_arg(
2948
-            [
2949
-                'ee_ver'       => 'ee4',
2950
-                'utm_source'   => 'ee4_plugin_admin',
2951
-                'utm_medium'   => 'link',
2952
-                'utm_campaign' => $utm_campaign_source,
2953
-                'utm_content'  => 'buy_now_button',
2954
-            ],
2955
-            'https://eventespresso.com/pricing/'
2956
-        );
2957
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2958
-            ? $this->get_action_link_or_button(
2959
-                '',
2960
-                'buy_now',
2961
-                [],
2962
-                'button-primary button-large',
2963
-                esc_url_raw($buy_now_url),
2964
-                true
2965
-            )
2966
-            : $this->_template_args['preview_action_button'];
2967
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2968
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2969
-            $this->_template_args,
2970
-            true
2971
-        );
2972
-        $this->_display_admin_page($display_sidebar);
2973
-    }
2974
-
2975
-
2976
-    /**
2977
-     * display_admin_list_table_page_with_sidebar
2978
-     * generates HTML wrapper for an admin_page with list_table
2979
-     *
2980
-     * @return void
2981
-     * @throws EE_Error
2982
-     * @throws DomainException
2983
-     */
2984
-    public function display_admin_list_table_page_with_sidebar()
2985
-    {
2986
-        $this->_display_admin_list_table_page(true);
2987
-    }
2988
-
2989
-
2990
-    /**
2991
-     * display_admin_list_table_page_with_no_sidebar
2992
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2993
-     *
2994
-     * @return void
2995
-     * @throws EE_Error
2996
-     * @throws DomainException
2997
-     */
2998
-    public function display_admin_list_table_page_with_no_sidebar()
2999
-    {
3000
-        $this->_display_admin_list_table_page();
3001
-    }
3002
-
3003
-
3004
-    /**
3005
-     * generates html wrapper for an admin_list_table page
3006
-     *
3007
-     * @param boolean $sidebar whether to display with sidebar or not.
3008
-     * @return void
3009
-     * @throws DomainException
3010
-     * @throws EE_Error
3011
-     */
3012
-    private function _display_admin_list_table_page($sidebar = false)
3013
-    {
3014
-        // setup search attributes
3015
-        $this->_set_search_attributes();
3016
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
3017
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3018
-        $this->_template_args['table_url']        = $this->request->isAjax()
3019
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
3020
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
3021
-        $this->_template_args['list_table']       = $this->_list_table_object;
3022
-        $this->_template_args['current_route']    = $this->_req_action;
3023
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3024
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
3025
-        if (! empty($ajax_sorting_callback)) {
3026
-            $sortable_list_table_form_fields = wp_nonce_field(
3027
-                $ajax_sorting_callback . '_nonce',
3028
-                $ajax_sorting_callback . '_nonce',
3029
-                false,
3030
-                false
3031
-            );
3032
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3033
-                                                . $this->page_slug
3034
-                                                . '" />';
3035
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3036
-                                                . $ajax_sorting_callback
3037
-                                                . '" />';
3038
-        } else {
3039
-            $sortable_list_table_form_fields = '';
3040
-        }
3041
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3042
-        $hidden_form_fields                                      =
3043
-            isset($this->_template_args['list_table_hidden_fields'])
3044
-                ? $this->_template_args['list_table_hidden_fields']
3045
-                : '';
3046
-        $nonce_ref                                               = $this->_req_action . '_nonce';
3047
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
3048
-                                                                    . $nonce_ref
3049
-                                                                    . '" value="'
3050
-                                                                    . wp_create_nonce($nonce_ref)
3051
-                                                                    . '">';
3052
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
3053
-        // display message about search results?
3054
-        $search = $this->request->getRequestParam('s');
3055
-        $this->_template_args['before_list_table'] .= ! empty($search)
3056
-            ? '<p class="ee-search-results">' . sprintf(
3057
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3058
-                trim($search, '%')
3059
-            ) . '</p>'
3060
-            : '';
3061
-        // filter before_list_table template arg
3062
-        $this->_template_args['before_list_table'] = apply_filters(
3063
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3064
-            $this->_template_args['before_list_table'],
3065
-            $this->page_slug,
3066
-            $this->request->requestParams(),
3067
-            $this->_req_action
3068
-        );
3069
-        // convert to array and filter again
3070
-        // arrays are easier to inject new items in a specific location,
3071
-        // but would not be backwards compatible, so we have to add a new filter
3072
-        $this->_template_args['before_list_table'] = implode(
3073
-            " \n",
3074
-            (array) apply_filters(
3075
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3076
-                (array) $this->_template_args['before_list_table'],
3077
-                $this->page_slug,
3078
-                $this->request->requestParams(),
3079
-                $this->_req_action
3080
-            )
3081
-        );
3082
-        // filter after_list_table template arg
3083
-        $this->_template_args['after_list_table'] = apply_filters(
3084
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3085
-            $this->_template_args['after_list_table'],
3086
-            $this->page_slug,
3087
-            $this->request->requestParams(),
3088
-            $this->_req_action
3089
-        );
3090
-        // convert to array and filter again
3091
-        // arrays are easier to inject new items in a specific location,
3092
-        // but would not be backwards compatible, so we have to add a new filter
3093
-        $this->_template_args['after_list_table']   = implode(
3094
-            " \n",
3095
-            (array) apply_filters(
3096
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3097
-                (array) $this->_template_args['after_list_table'],
3098
-                $this->page_slug,
3099
-                $this->request->requestParams(),
3100
-                $this->_req_action
3101
-            )
3102
-        );
3103
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3104
-            $template_path,
3105
-            $this->_template_args,
3106
-            true
3107
-        );
3108
-        // the final template wrapper
3109
-        if ($sidebar) {
3110
-            $this->display_admin_page_with_sidebar();
3111
-        } else {
3112
-            $this->display_admin_page_with_no_sidebar();
3113
-        }
3114
-    }
3115
-
3116
-
3117
-    /**
3118
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3119
-     * html string for the legend.
3120
-     * $items are expected in an array in the following format:
3121
-     * $legend_items = array(
3122
-     *        'item_id' => array(
3123
-     *            'icon' => 'http://url_to_icon_being_described.png',
3124
-     *            'desc' => esc_html__('localized description of item');
3125
-     *        )
3126
-     * );
3127
-     *
3128
-     * @param array $items see above for format of array
3129
-     * @return string html string of legend
3130
-     * @throws DomainException
3131
-     */
3132
-    protected function _display_legend($items)
3133
-    {
3134
-        $this->_template_args['items'] = apply_filters(
3135
-            'FHEE__EE_Admin_Page___display_legend__items',
3136
-            (array) $items,
3137
-            $this
3138
-        );
3139
-        return EEH_Template::display_template(
3140
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3141
-            $this->_template_args,
3142
-            true
3143
-        );
3144
-    }
3145
-
3146
-
3147
-    /**
3148
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3149
-     * The returned json object is created from an array in the following format:
3150
-     * array(
3151
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3152
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3153
-     *  'notices' => '', // - contains any EE_Error formatted notices
3154
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3155
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3156
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3157
-     *  that might be included in here)
3158
-     * )
3159
-     * The json object is populated by whatever is set in the $_template_args property.
3160
-     *
3161
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3162
-     *                                 instead of displayed.
3163
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3164
-     * @return void
3165
-     * @throws EE_Error
3166
-     */
3167
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
3168
-    {
3169
-        // make sure any EE_Error notices have been handled.
3170
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3171
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3172
-        unset($this->_template_args['data']);
3173
-        $json = [
3174
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3175
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3176
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3177
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3178
-            'notices'   => EE_Error::get_notices(),
3179
-            'content'   => isset($this->_template_args['admin_page_content'])
3180
-                ? $this->_template_args['admin_page_content'] : '',
3181
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3182
-            'isEEajax'  => true
3183
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3184
-        ];
3185
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3186
-        if (null === error_get_last() || ! headers_sent()) {
3187
-            header('Content-Type: application/json; charset=UTF-8');
3188
-        }
3189
-        echo wp_json_encode($json);
3190
-        exit();
3191
-    }
3192
-
3193
-
3194
-    /**
3195
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3196
-     *
3197
-     * @return void
3198
-     * @throws EE_Error
3199
-     */
3200
-    public function return_json()
3201
-    {
3202
-        if ($this->request->isAjax()) {
3203
-            $this->_return_json();
3204
-        } else {
3205
-            throw new EE_Error(
3206
-                sprintf(
3207
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3208
-                    __FUNCTION__
3209
-                )
3210
-            );
3211
-        }
3212
-    }
3213
-
3214
-
3215
-    /**
3216
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3217
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3218
-     *
3219
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3220
-     */
3221
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3222
-    {
3223
-        $this->_hook_obj = $hook_obj;
3224
-    }
3225
-
3226
-
3227
-    /**
3228
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3229
-     *
3230
-     * @param boolean $about whether to use the special about page wrapper or default.
3231
-     * @return void
3232
-     * @throws DomainException
3233
-     * @throws EE_Error
3234
-     */
3235
-    public function admin_page_wrapper($about = false)
3236
-    {
3237
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3238
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3239
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3240
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3241
-
3242
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3243
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3244
-            isset($this->_template_args['before_admin_page_content'])
3245
-                ? $this->_template_args['before_admin_page_content']
3246
-                : ''
3247
-        );
3248
-
3249
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3250
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3251
-            isset($this->_template_args['after_admin_page_content'])
3252
-                ? $this->_template_args['after_admin_page_content']
3253
-                : ''
3254
-        );
3255
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3256
-
3257
-        if ($this->request->isAjax()) {
3258
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3259
-                // $template_path,
3260
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3261
-                $this->_template_args,
3262
-                true
3263
-            );
3264
-            $this->_return_json();
3265
-        }
3266
-        // load settings page wrapper template
3267
-        $template_path = $about
3268
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3269
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3270
-
3271
-        EEH_Template::display_template($template_path, $this->_template_args);
3272
-    }
3273
-
3274
-
3275
-    /**
3276
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3277
-     *
3278
-     * @return string html
3279
-     * @throws EE_Error
3280
-     */
3281
-    protected function _get_main_nav_tabs()
3282
-    {
3283
-        // let's generate the html using the EEH_Tabbed_Content helper.
3284
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3285
-        // (rather than setting in the page_routes array)
3286
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3287
-    }
3288
-
3289
-
3290
-    /**
3291
-     *        sort nav tabs
3292
-     *
3293
-     * @param $a
3294
-     * @param $b
3295
-     * @return int
3296
-     */
3297
-    private function _sort_nav_tabs($a, $b)
3298
-    {
3299
-        if ($a['order'] === $b['order']) {
3300
-            return 0;
3301
-        }
3302
-        return ($a['order'] < $b['order']) ? -1 : 1;
3303
-    }
3304
-
3305
-
3306
-    /**
3307
-     *    generates HTML for the forms used on admin pages
3308
-     *
3309
-     * @param array  $input_vars   - array of input field details
3310
-     * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3311
-     *                             use)
3312
-     * @param bool   $id
3313
-     * @return array|string
3314
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3315
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3316
-     */
3317
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3318
-    {
3319
-        return $generator === 'string'
3320
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3321
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3322
-    }
3323
-
3324
-
3325
-    /**
3326
-     * generates the "Save" and "Save & Close" buttons for edit forms
3327
-     *
3328
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3329
-     *                                   Close" button.
3330
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3331
-     *                                   'Save', [1] => 'save & close')
3332
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3333
-     *                                   via the "name" value in the button).  We can also use this to just dump
3334
-     *                                   default actions by submitting some other value.
3335
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3336
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3337
-     *                                   close (normal form handling).
3338
-     */
3339
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3340
-    {
3341
-        // make sure $text and $actions are in an array
3342
-        $text          = (array) $text;
3343
-        $actions       = (array) $actions;
3344
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3345
-        $button_text   = ! empty($text)
3346
-            ? $text
3347
-            : [
3348
-                esc_html__('Save', 'event_espresso'),
3349
-                esc_html__('Save and Close', 'event_espresso'),
3350
-            ];
3351
-        $default_names = ['save', 'save_and_close'];
3352
-        $buttons = '';
3353
-        foreach ($button_text as $key => $button) {
3354
-            $ref     = $default_names[ $key ];
3355
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3356
-            $buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3357
-                        . 'value="' . $button . '" name="' . $name . '" '
3358
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3359
-            if (! $both) {
3360
-                break;
3361
-            }
3362
-        }
3363
-        // add in a hidden index for the current page (so save and close redirects properly)
3364
-        $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3365
-                   . $referrer_url
3366
-                   . '" />';
3367
-        $this->_template_args['save_buttons'] = $buttons;
3368
-    }
3369
-
3370
-
3371
-    /**
3372
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3373
-     *
3374
-     * @param string $route
3375
-     * @param array  $additional_hidden_fields
3376
-     * @see   $this->_set_add_edit_form_tags() for details on params
3377
-     * @since 4.6.0
3378
-     */
3379
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3380
-    {
3381
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3382
-    }
3383
-
3384
-
3385
-    /**
3386
-     * set form open and close tags on add/edit pages.
3387
-     *
3388
-     * @param string $route                    the route you want the form to direct to
3389
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3390
-     * @return void
3391
-     */
3392
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3393
-    {
3394
-        if (empty($route)) {
3395
-            $user_msg = esc_html__(
3396
-                'An error occurred. No action was set for this page\'s form.',
3397
-                'event_espresso'
3398
-            );
3399
-            $dev_msg  = $user_msg . "\n"
3400
-                        . sprintf(
3401
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3402
-                            __FUNCTION__,
3403
-                            __CLASS__
3404
-                        );
3405
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3406
-        }
3407
-        // open form
3408
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3409
-                                                             . $this->_admin_base_url
3410
-                                                             . '" id="'
3411
-                                                             . $route
3412
-                                                             . '_event_form" >';
3413
-        // add nonce
3414
-        $nonce                                             =
3415
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3416
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3417
-        // add REQUIRED form action
3418
-        $hidden_fields = [
3419
-            'action' => ['type' => 'hidden', 'value' => $route],
3420
-        ];
3421
-        // merge arrays
3422
-        $hidden_fields = is_array($additional_hidden_fields)
3423
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3424
-            : $hidden_fields;
3425
-        // generate form fields
3426
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3427
-        // add fields to form
3428
-        foreach ((array) $form_fields as $form_field) {
3429
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3430
-        }
3431
-        // close form
3432
-        $this->_template_args['after_admin_page_content'] = '</form>';
3433
-    }
3434
-
3435
-
3436
-    /**
3437
-     * Public Wrapper for _redirect_after_action() method since its
3438
-     * discovered it would be useful for external code to have access.
3439
-     *
3440
-     * @param bool   $success
3441
-     * @param string $what
3442
-     * @param string $action_desc
3443
-     * @param array  $query_args
3444
-     * @param bool   $override_overwrite
3445
-     * @throws EE_Error
3446
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3447
-     * @since 4.5.0
3448
-     */
3449
-    public function redirect_after_action(
3450
-        $success = false,
3451
-        $what = 'item',
3452
-        $action_desc = 'processed',
3453
-        $query_args = [],
3454
-        $override_overwrite = false
3455
-    ) {
3456
-        $this->_redirect_after_action(
3457
-            $success,
3458
-            $what,
3459
-            $action_desc,
3460
-            $query_args,
3461
-            $override_overwrite
3462
-        );
3463
-    }
3464
-
3465
-
3466
-    /**
3467
-     * Helper method for merging existing request data with the returned redirect url.
3468
-     *
3469
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3470
-     * filters are still applied.
3471
-     *
3472
-     * @param array $new_route_data
3473
-     * @return array
3474
-     */
3475
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3476
-    {
3477
-        foreach ($this->request->requestParams() as $ref => $value) {
3478
-            // unset nonces
3479
-            if (strpos($ref, 'nonce') !== false) {
3480
-                $this->request->unSetRequestParam($ref);
3481
-                continue;
3482
-            }
3483
-            // urlencode values.
3484
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3485
-            $this->request->setRequestParam($ref, $value);
3486
-        }
3487
-        return array_merge($this->request->requestParams(), $new_route_data);
3488
-    }
3489
-
3490
-
3491
-    /**
3492
-     *    _redirect_after_action
3493
-     *
3494
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3495
-     * @param string $what               - what the action was performed on
3496
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3497
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3498
-     *                                   action is completed
3499
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3500
-     *                                   override this so that they show.
3501
-     * @return void
3502
-     * @throws EE_Error
3503
-     */
3504
-    protected function _redirect_after_action(
3505
-        $success = 0,
3506
-        $what = 'item',
3507
-        $action_desc = 'processed',
3508
-        $query_args = [],
3509
-        $override_overwrite = false
3510
-    ) {
3511
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3512
-        // class name for actions/filters.
3513
-        $classname = get_class($this);
3514
-        // set redirect url.
3515
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3516
-        // otherwise we go with whatever is set as the _admin_base_url
3517
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3518
-        $notices      = EE_Error::get_notices(false);
3519
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3520
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3521
-            EE_Error::overwrite_success();
3522
-        }
3523
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3524
-            // how many records affected ? more than one record ? or just one ?
3525
-            if ($success > 1) {
3526
-                // set plural msg
3527
-                EE_Error::add_success(
3528
-                    sprintf(
3529
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3530
-                        $what,
3531
-                        $action_desc
3532
-                    ),
3533
-                    __FILE__,
3534
-                    __FUNCTION__,
3535
-                    __LINE__
3536
-                );
3537
-            } elseif ($success === 1) {
3538
-                // set singular msg
3539
-                EE_Error::add_success(
3540
-                    sprintf(
3541
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3542
-                        $what,
3543
-                        $action_desc
3544
-                    ),
3545
-                    __FILE__,
3546
-                    __FUNCTION__,
3547
-                    __LINE__
3548
-                );
3549
-            }
3550
-        }
3551
-        // check that $query_args isn't something crazy
3552
-        if (! is_array($query_args)) {
3553
-            $query_args = [];
3554
-        }
3555
-        /**
3556
-         * Allow injecting actions before the query_args are modified for possible different
3557
-         * redirections on save and close actions
3558
-         *
3559
-         * @param array $query_args       The original query_args array coming into the
3560
-         *                                method.
3561
-         * @since 4.2.0
3562
-         */
3563
-        do_action(
3564
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3565
-            $query_args
3566
-        );
3567
-        // calculate where we're going (if we have a "save and close" button pushed)
3568
-
3569
-        if (
3570
-            $this->request->requestParamIsSet('save_and_close')
3571
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3572
-        ) {
3573
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3574
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3575
-            // regenerate query args array from referrer URL
3576
-            parse_str($parsed_url['query'], $query_args);
3577
-            // correct page and action will be in the query args now
3578
-            $redirect_url = admin_url('admin.php');
3579
-        }
3580
-        // merge any default query_args set in _default_route_query_args property
3581
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3582
-            $args_to_merge = [];
3583
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3584
-                // is there a wp_referer array in our _default_route_query_args property?
3585
-                if ($query_param === 'wp_referer') {
3586
-                    $query_value = (array) $query_value;
3587
-                    foreach ($query_value as $reference => $value) {
3588
-                        if (strpos($reference, 'nonce') !== false) {
3589
-                            continue;
3590
-                        }
3591
-                        // finally we will override any arguments in the referer with
3592
-                        // what might be set on the _default_route_query_args array.
3593
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3594
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3595
-                        } else {
3596
-                            $args_to_merge[ $reference ] = urlencode($value);
3597
-                        }
3598
-                    }
3599
-                    continue;
3600
-                }
3601
-                $args_to_merge[ $query_param ] = $query_value;
3602
-            }
3603
-            // now let's merge these arguments but override with what was specifically sent in to the
3604
-            // redirect.
3605
-            $query_args = array_merge($args_to_merge, $query_args);
3606
-        }
3607
-        $this->_process_notices($query_args);
3608
-        // generate redirect url
3609
-        // if redirecting to anything other than the main page, add a nonce
3610
-        if (isset($query_args['action'])) {
3611
-            // manually generate wp_nonce and merge that with the query vars
3612
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3613
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3614
-        }
3615
-        // we're adding some hooks and filters in here for processing any things just before redirects
3616
-        // (example: an admin page has done an insert or update and we want to run something after that).
3617
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3618
-        $redirect_url = apply_filters(
3619
-            'FHEE_redirect_' . $classname . $this->_req_action,
3620
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3621
-            $query_args
3622
-        );
3623
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3624
-        if ($this->request->isAjax()) {
3625
-            $default_data                    = [
3626
-                'close'        => true,
3627
-                'redirect_url' => $redirect_url,
3628
-                'where'        => 'main',
3629
-                'what'         => 'append',
3630
-            ];
3631
-            $this->_template_args['success'] = $success;
3632
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3633
-                $default_data,
3634
-                $this->_template_args['data']
3635
-            ) : $default_data;
3636
-            $this->_return_json();
3637
-        }
3638
-        wp_safe_redirect($redirect_url);
3639
-        exit();
3640
-    }
3641
-
3642
-
3643
-    /**
3644
-     * process any notices before redirecting (or returning ajax request)
3645
-     * This method sets the $this->_template_args['notices'] attribute;
3646
-     *
3647
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3648
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3649
-     *                                  page_routes haven't been defined yet.
3650
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3651
-     *                                  still save a transient for the notice.
3652
-     * @return void
3653
-     * @throws EE_Error
3654
-     */
3655
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3656
-    {
3657
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3658
-        if ($this->request->isAjax()) {
3659
-            $notices = EE_Error::get_notices(false);
3660
-            if (empty($this->_template_args['success'])) {
3661
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3662
-            }
3663
-            if (empty($this->_template_args['errors'])) {
3664
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3665
-            }
3666
-            if (empty($this->_template_args['attention'])) {
3667
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3668
-            }
3669
-        }
3670
-        $this->_template_args['notices'] = EE_Error::get_notices();
3671
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3672
-        if (! $this->request->isAjax() || $sticky_notices) {
3673
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3674
-            $this->_add_transient(
3675
-                $route,
3676
-                $this->_template_args['notices'],
3677
-                true,
3678
-                $skip_route_verify
3679
-            );
3680
-        }
3681
-    }
3682
-
3683
-
3684
-    /**
3685
-     * get_action_link_or_button
3686
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3687
-     *
3688
-     * @param string $action        use this to indicate which action the url is generated with.
3689
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3690
-     *                              property.
3691
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3692
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3693
-     * @param string $base_url      If this is not provided
3694
-     *                              the _admin_base_url will be used as the default for the button base_url.
3695
-     *                              Otherwise this value will be used.
3696
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3697
-     * @return string
3698
-     * @throws InvalidArgumentException
3699
-     * @throws InvalidInterfaceException
3700
-     * @throws InvalidDataTypeException
3701
-     * @throws EE_Error
3702
-     */
3703
-    public function get_action_link_or_button(
3704
-        $action,
3705
-        $type = 'add',
3706
-        $extra_request = [],
3707
-        $class = 'button-primary',
3708
-        $base_url = '',
3709
-        $exclude_nonce = false
3710
-    ) {
3711
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3712
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3713
-            throw new EE_Error(
3714
-                sprintf(
3715
-                    esc_html__(
3716
-                        'There is no page route for given action for the button.  This action was given: %s',
3717
-                        'event_espresso'
3718
-                    ),
3719
-                    $action
3720
-                )
3721
-            );
3722
-        }
3723
-        if (! isset($this->_labels['buttons'][ $type ])) {
3724
-            throw new EE_Error(
3725
-                sprintf(
3726
-                    esc_html__(
3727
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3728
-                        'event_espresso'
3729
-                    ),
3730
-                    $type
3731
-                )
3732
-            );
3733
-        }
3734
-        // finally check user access for this button.
3735
-        $has_access = $this->check_user_access($action, true);
3736
-        if (! $has_access) {
3737
-            return '';
3738
-        }
3739
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3740
-        $query_args = [
3741
-            'action' => $action,
3742
-        ];
3743
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3744
-        if (! empty($extra_request)) {
3745
-            $query_args = array_merge($extra_request, $query_args);
3746
-        }
3747
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3748
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3749
-    }
3750
-
3751
-
3752
-    /**
3753
-     * _per_page_screen_option
3754
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3755
-     *
3756
-     * @return void
3757
-     * @throws InvalidArgumentException
3758
-     * @throws InvalidInterfaceException
3759
-     * @throws InvalidDataTypeException
3760
-     */
3761
-    protected function _per_page_screen_option()
3762
-    {
3763
-        $option = 'per_page';
3764
-        $args   = [
3765
-            'label'   => apply_filters(
3766
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3767
-                $this->_admin_page_title,
3768
-                $this
3769
-            ),
3770
-            'default' => (int) apply_filters(
3771
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3772
-                20
3773
-            ),
3774
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3775
-        ];
3776
-        // ONLY add the screen option if the user has access to it.
3777
-        if ($this->check_user_access($this->_current_view, true)) {
3778
-            add_screen_option($option, $args);
3779
-        }
3780
-    }
3781
-
3782
-
3783
-    /**
3784
-     * set_per_page_screen_option
3785
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3786
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3787
-     * admin_menu.
3788
-     *
3789
-     * @return void
3790
-     */
3791
-    private function _set_per_page_screen_options()
3792
-    {
3793
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3794
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3795
-            if (! $user = wp_get_current_user()) {
3796
-                return;
3797
-            }
3798
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3799
-            if (! $option) {
3800
-                return;
3801
-            }
3802
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3803
-            $map_option = $option;
3804
-            $option     = str_replace('-', '_', $option);
3805
-            switch ($map_option) {
3806
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3807
-                    $max_value = apply_filters(
3808
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3809
-                        999,
3810
-                        $this->_current_page,
3811
-                        $this->_current_view
3812
-                    );
3813
-                    if ($value < 1) {
3814
-                        return;
3815
-                    }
3816
-                    $value = min($value, $max_value);
3817
-                    break;
3818
-                default:
3819
-                    $value = apply_filters(
3820
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3821
-                        false,
3822
-                        $option,
3823
-                        $value
3824
-                    );
3825
-                    if (false === $value) {
3826
-                        return;
3827
-                    }
3828
-                    break;
3829
-            }
3830
-            update_user_meta($user->ID, $option, $value);
3831
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3832
-            exit;
3833
-        }
3834
-    }
3835
-
3836
-
3837
-    /**
3838
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3839
-     *
3840
-     * @param array $data array that will be assigned to template args.
3841
-     */
3842
-    public function set_template_args($data)
3843
-    {
3844
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3845
-    }
3846
-
3847
-
3848
-    /**
3849
-     * This makes available the WP transient system for temporarily moving data between routes
3850
-     *
3851
-     * @param string $route             the route that should receive the transient
3852
-     * @param array  $data              the data that gets sent
3853
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3854
-     *                                  normal route transient.
3855
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3856
-     *                                  when we are adding a transient before page_routes have been defined.
3857
-     * @return void
3858
-     * @throws EE_Error
3859
-     */
3860
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3861
-    {
3862
-        $user_id = get_current_user_id();
3863
-        if (! $skip_route_verify) {
3864
-            $this->_verify_route($route);
3865
-        }
3866
-        // now let's set the string for what kind of transient we're setting
3867
-        $transient = $notices
3868
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3869
-            : 'rte_tx_' . $route . '_' . $user_id;
3870
-        $data      = $notices ? ['notices' => $data] : $data;
3871
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3872
-        $existing = is_multisite() && is_network_admin()
3873
-            ? get_site_transient($transient)
3874
-            : get_transient($transient);
3875
-        if ($existing) {
3876
-            $data = array_merge((array) $data, (array) $existing);
3877
-        }
3878
-        if (is_multisite() && is_network_admin()) {
3879
-            set_site_transient($transient, $data, 8);
3880
-        } else {
3881
-            set_transient($transient, $data, 8);
3882
-        }
3883
-    }
3884
-
3885
-
3886
-    /**
3887
-     * this retrieves the temporary transient that has been set for moving data between routes.
3888
-     *
3889
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3890
-     * @param string $route
3891
-     * @return mixed data
3892
-     */
3893
-    protected function _get_transient($notices = false, $route = '')
3894
-    {
3895
-        $user_id   = get_current_user_id();
3896
-        $route     = ! $route ? $this->_req_action : $route;
3897
-        $transient = $notices
3898
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3899
-            : 'rte_tx_' . $route . '_' . $user_id;
3900
-        $data      = is_multisite() && is_network_admin()
3901
-            ? get_site_transient($transient)
3902
-            : get_transient($transient);
3903
-        // delete transient after retrieval (just in case it hasn't expired);
3904
-        if (is_multisite() && is_network_admin()) {
3905
-            delete_site_transient($transient);
3906
-        } else {
3907
-            delete_transient($transient);
3908
-        }
3909
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3910
-    }
3911
-
3912
-
3913
-    /**
3914
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3915
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3916
-     * default route callback on the EE_Admin page you want it run.)
3917
-     *
3918
-     * @return void
3919
-     */
3920
-    protected function _transient_garbage_collection()
3921
-    {
3922
-        global $wpdb;
3923
-        // retrieve all existing transients
3924
-        $query =
3925
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3926
-        if ($results = $wpdb->get_results($query)) {
3927
-            foreach ($results as $result) {
3928
-                $transient = str_replace('_transient_', '', $result->option_name);
3929
-                get_transient($transient);
3930
-                if (is_multisite() && is_network_admin()) {
3931
-                    get_site_transient($transient);
3932
-                }
3933
-            }
3934
-        }
3935
-    }
3936
-
3937
-
3938
-    /**
3939
-     * get_view
3940
-     *
3941
-     * @return string content of _view property
3942
-     */
3943
-    public function get_view()
3944
-    {
3945
-        return $this->_view;
3946
-    }
3947
-
3948
-
3949
-    /**
3950
-     * getter for the protected $_views property
3951
-     *
3952
-     * @return array
3953
-     */
3954
-    public function get_views()
3955
-    {
3956
-        return $this->_views;
3957
-    }
3958
-
3959
-
3960
-    /**
3961
-     * get_current_page
3962
-     *
3963
-     * @return string _current_page property value
3964
-     */
3965
-    public function get_current_page()
3966
-    {
3967
-        return $this->_current_page;
3968
-    }
3969
-
3970
-
3971
-    /**
3972
-     * get_current_view
3973
-     *
3974
-     * @return string _current_view property value
3975
-     */
3976
-    public function get_current_view()
3977
-    {
3978
-        return $this->_current_view;
3979
-    }
3980
-
3981
-
3982
-    /**
3983
-     * get_current_screen
3984
-     *
3985
-     * @return object The current WP_Screen object
3986
-     */
3987
-    public function get_current_screen()
3988
-    {
3989
-        return $this->_current_screen;
3990
-    }
3991
-
3992
-
3993
-    /**
3994
-     * get_current_page_view_url
3995
-     *
3996
-     * @return string This returns the url for the current_page_view.
3997
-     */
3998
-    public function get_current_page_view_url()
3999
-    {
4000
-        return $this->_current_page_view_url;
4001
-    }
4002
-
4003
-
4004
-    /**
4005
-     * just returns the Request
4006
-     *
4007
-     * @return RequestInterface
4008
-     */
4009
-    public function get_request()
4010
-    {
4011
-        return $this->request;
4012
-    }
4013
-
4014
-
4015
-    /**
4016
-     * just returns the _req_data property
4017
-     *
4018
-     * @return array
4019
-     */
4020
-    public function get_request_data()
4021
-    {
4022
-        return $this->request->requestParams();
4023
-    }
4024
-
4025
-
4026
-    /**
4027
-     * returns the _req_data protected property
4028
-     *
4029
-     * @return string
4030
-     */
4031
-    public function get_req_action()
4032
-    {
4033
-        return $this->_req_action;
4034
-    }
4035
-
4036
-
4037
-    /**
4038
-     * @return bool  value of $_is_caf property
4039
-     */
4040
-    public function is_caf()
4041
-    {
4042
-        return $this->_is_caf;
4043
-    }
4044
-
4045
-
4046
-    /**
4047
-     * @return mixed
4048
-     */
4049
-    public function default_espresso_metaboxes()
4050
-    {
4051
-        return $this->_default_espresso_metaboxes;
4052
-    }
4053
-
4054
-
4055
-    /**
4056
-     * @return mixed
4057
-     */
4058
-    public function admin_base_url()
4059
-    {
4060
-        return $this->_admin_base_url;
4061
-    }
4062
-
4063
-
4064
-    /**
4065
-     * @return mixed
4066
-     */
4067
-    public function wp_page_slug()
4068
-    {
4069
-        return $this->_wp_page_slug;
4070
-    }
4071
-
4072
-
4073
-    /**
4074
-     * updates  espresso configuration settings
4075
-     *
4076
-     * @param string                   $tab
4077
-     * @param EE_Config_Base|EE_Config $config
4078
-     * @param string                   $file file where error occurred
4079
-     * @param string                   $func function  where error occurred
4080
-     * @param string                   $line line no where error occurred
4081
-     * @return boolean
4082
-     */
4083
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4084
-    {
4085
-        // remove any options that are NOT going to be saved with the config settings.
4086
-        if (isset($config->core->ee_ueip_optin)) {
4087
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4088
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4089
-            update_option('ee_ueip_has_notified', true);
4090
-        }
4091
-        // and save it (note we're also doing the network save here)
4092
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
4093
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4094
-        if ($config_saved && $net_saved) {
4095
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4096
-            return true;
4097
-        }
4098
-        EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4099
-        return false;
4100
-    }
4101
-
4102
-
4103
-    /**
4104
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4105
-     *
4106
-     * @return array
4107
-     */
4108
-    public function get_yes_no_values()
4109
-    {
4110
-        return $this->_yes_no_values;
4111
-    }
4112
-
4113
-
4114
-    protected function _get_dir()
4115
-    {
4116
-        $reflector = new ReflectionClass(get_class($this));
4117
-        return dirname($reflector->getFileName());
4118
-    }
4119
-
4120
-
4121
-    /**
4122
-     * A helper for getting a "next link".
4123
-     *
4124
-     * @param string $url   The url to link to
4125
-     * @param string $class The class to use.
4126
-     * @return string
4127
-     */
4128
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4129
-    {
4130
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4131
-    }
4132
-
4133
-
4134
-    /**
4135
-     * A helper for getting a "previous link".
4136
-     *
4137
-     * @param string $url   The url to link to
4138
-     * @param string $class The class to use.
4139
-     * @return string
4140
-     */
4141
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4142
-    {
4143
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4144
-    }
4145
-
4146
-
4147
-
4148
-
4149
-
4150
-
4151
-
4152
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4153
-
4154
-
4155
-    /**
4156
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4157
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4158
-     * _req_data array.
4159
-     *
4160
-     * @return bool success/fail
4161
-     * @throws EE_Error
4162
-     * @throws InvalidArgumentException
4163
-     * @throws ReflectionException
4164
-     * @throws InvalidDataTypeException
4165
-     * @throws InvalidInterfaceException
4166
-     */
4167
-    protected function _process_resend_registration()
4168
-    {
4169
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4170
-        do_action(
4171
-            'AHEE__EE_Admin_Page___process_resend_registration',
4172
-            $this->_template_args['success'],
4173
-            $this->request->requestParams()
4174
-        );
4175
-        return $this->_template_args['success'];
4176
-    }
4177
-
4178
-
4179
-    /**
4180
-     * This automatically processes any payment message notifications when manual payment has been applied.
4181
-     *
4182
-     * @param EE_Payment $payment
4183
-     * @return bool success/fail
4184
-     */
4185
-    protected function _process_payment_notification(EE_Payment $payment)
4186
-    {
4187
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4188
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4189
-        $this->_template_args['success'] = apply_filters(
4190
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4191
-            false,
4192
-            $payment
4193
-        );
4194
-        return $this->_template_args['success'];
4195
-    }
2763
+	}
2764
+
2765
+
2766
+	/**
2767
+	 * facade for add_meta_box
2768
+	 *
2769
+	 * @param string  $action        where the metabox gets displayed
2770
+	 * @param string  $title         Title of Metabox (output in metabox header)
2771
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2772
+	 *                               instead of the one created in here.
2773
+	 * @param array   $callback_args an array of args supplied for the metabox
2774
+	 * @param string  $column        what metabox column
2775
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2776
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2777
+	 *                               created but just set our own callback for wp's add_meta_box.
2778
+	 * @throws DomainException
2779
+	 */
2780
+	public function _add_admin_page_meta_box(
2781
+		$action,
2782
+		$title,
2783
+		$callback,
2784
+		$callback_args,
2785
+		$column = 'normal',
2786
+		$priority = 'high',
2787
+		$create_func = true
2788
+	) {
2789
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2790
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2791
+		if (empty($callback_args) && $create_func) {
2792
+			$callback_args = [
2793
+				'template_path' => $this->_template_path,
2794
+				'template_args' => $this->_template_args,
2795
+			];
2796
+		}
2797
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2798
+		$call_back_func = $create_func
2799
+			? function ($post, $metabox) {
2800
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2801
+				echo EEH_Template::display_template(
2802
+					$metabox['args']['template_path'],
2803
+					$metabox['args']['template_args'],
2804
+					true
2805
+				);
2806
+			}
2807
+			: $callback;
2808
+		add_meta_box(
2809
+			str_replace('_', '-', $action) . '-mbox',
2810
+			$title,
2811
+			$call_back_func,
2812
+			$this->_wp_page_slug,
2813
+			$column,
2814
+			$priority,
2815
+			$callback_args
2816
+		);
2817
+	}
2818
+
2819
+
2820
+	/**
2821
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2822
+	 *
2823
+	 * @throws DomainException
2824
+	 * @throws EE_Error
2825
+	 */
2826
+	public function display_admin_page_with_metabox_columns()
2827
+	{
2828
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2829
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2830
+			$this->_column_template_path,
2831
+			$this->_template_args,
2832
+			true
2833
+		);
2834
+		// the final wrapper
2835
+		$this->admin_page_wrapper();
2836
+	}
2837
+
2838
+
2839
+	/**
2840
+	 * generates  HTML wrapper for an admin details page
2841
+	 *
2842
+	 * @return void
2843
+	 * @throws EE_Error
2844
+	 * @throws DomainException
2845
+	 */
2846
+	public function display_admin_page_with_sidebar()
2847
+	{
2848
+		$this->_display_admin_page(true);
2849
+	}
2850
+
2851
+
2852
+	/**
2853
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2854
+	 *
2855
+	 * @return void
2856
+	 * @throws EE_Error
2857
+	 * @throws DomainException
2858
+	 */
2859
+	public function display_admin_page_with_no_sidebar()
2860
+	{
2861
+		$this->_display_admin_page();
2862
+	}
2863
+
2864
+
2865
+	/**
2866
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2867
+	 *
2868
+	 * @return void
2869
+	 * @throws EE_Error
2870
+	 * @throws DomainException
2871
+	 */
2872
+	public function display_about_admin_page()
2873
+	{
2874
+		$this->_display_admin_page(false, true);
2875
+	}
2876
+
2877
+
2878
+	/**
2879
+	 * display_admin_page
2880
+	 * contains the code for actually displaying an admin page
2881
+	 *
2882
+	 * @param boolean $sidebar true with sidebar, false without
2883
+	 * @param boolean $about   use the about_admin_wrapper instead of the default.
2884
+	 * @return void
2885
+	 * @throws DomainException
2886
+	 * @throws EE_Error
2887
+	 */
2888
+	private function _display_admin_page($sidebar = false, $about = false)
2889
+	{
2890
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2891
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2892
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2893
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2894
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2895
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2896
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2897
+			? 'poststuff'
2898
+			: 'espresso-default-admin';
2899
+		$template_path                                     = $sidebar
2900
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2901
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2902
+		if ($this->request->isAjax()) {
2903
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2904
+		}
2905
+		$template_path                                     = ! empty($this->_column_template_path)
2906
+			? $this->_column_template_path : $template_path;
2907
+		$this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2908
+			? $this->_template_args['admin_page_content']
2909
+			: '';
2910
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2911
+			? $this->_template_args['before_admin_page_content']
2912
+			: '';
2913
+		$this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2914
+			? $this->_template_args['after_admin_page_content']
2915
+			: '';
2916
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2917
+			$template_path,
2918
+			$this->_template_args,
2919
+			true
2920
+		);
2921
+		// the final template wrapper
2922
+		$this->admin_page_wrapper($about);
2923
+	}
2924
+
2925
+
2926
+	/**
2927
+	 * This is used to display caf preview pages.
2928
+	 *
2929
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2930
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2931
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2932
+	 * @return void
2933
+	 * @throws DomainException
2934
+	 * @throws EE_Error
2935
+	 * @throws InvalidArgumentException
2936
+	 * @throws InvalidDataTypeException
2937
+	 * @throws InvalidInterfaceException
2938
+	 * @since 4.3.2
2939
+	 */
2940
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2941
+	{
2942
+		// let's generate a default preview action button if there isn't one already present.
2943
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2944
+			'Upgrade to Event Espresso 4 Right Now',
2945
+			'event_espresso'
2946
+		);
2947
+		$buy_now_url                                   = add_query_arg(
2948
+			[
2949
+				'ee_ver'       => 'ee4',
2950
+				'utm_source'   => 'ee4_plugin_admin',
2951
+				'utm_medium'   => 'link',
2952
+				'utm_campaign' => $utm_campaign_source,
2953
+				'utm_content'  => 'buy_now_button',
2954
+			],
2955
+			'https://eventespresso.com/pricing/'
2956
+		);
2957
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2958
+			? $this->get_action_link_or_button(
2959
+				'',
2960
+				'buy_now',
2961
+				[],
2962
+				'button-primary button-large',
2963
+				esc_url_raw($buy_now_url),
2964
+				true
2965
+			)
2966
+			: $this->_template_args['preview_action_button'];
2967
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2968
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2969
+			$this->_template_args,
2970
+			true
2971
+		);
2972
+		$this->_display_admin_page($display_sidebar);
2973
+	}
2974
+
2975
+
2976
+	/**
2977
+	 * display_admin_list_table_page_with_sidebar
2978
+	 * generates HTML wrapper for an admin_page with list_table
2979
+	 *
2980
+	 * @return void
2981
+	 * @throws EE_Error
2982
+	 * @throws DomainException
2983
+	 */
2984
+	public function display_admin_list_table_page_with_sidebar()
2985
+	{
2986
+		$this->_display_admin_list_table_page(true);
2987
+	}
2988
+
2989
+
2990
+	/**
2991
+	 * display_admin_list_table_page_with_no_sidebar
2992
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2993
+	 *
2994
+	 * @return void
2995
+	 * @throws EE_Error
2996
+	 * @throws DomainException
2997
+	 */
2998
+	public function display_admin_list_table_page_with_no_sidebar()
2999
+	{
3000
+		$this->_display_admin_list_table_page();
3001
+	}
3002
+
3003
+
3004
+	/**
3005
+	 * generates html wrapper for an admin_list_table page
3006
+	 *
3007
+	 * @param boolean $sidebar whether to display with sidebar or not.
3008
+	 * @return void
3009
+	 * @throws DomainException
3010
+	 * @throws EE_Error
3011
+	 */
3012
+	private function _display_admin_list_table_page($sidebar = false)
3013
+	{
3014
+		// setup search attributes
3015
+		$this->_set_search_attributes();
3016
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
3017
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3018
+		$this->_template_args['table_url']        = $this->request->isAjax()
3019
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
3020
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
3021
+		$this->_template_args['list_table']       = $this->_list_table_object;
3022
+		$this->_template_args['current_route']    = $this->_req_action;
3023
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3024
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
3025
+		if (! empty($ajax_sorting_callback)) {
3026
+			$sortable_list_table_form_fields = wp_nonce_field(
3027
+				$ajax_sorting_callback . '_nonce',
3028
+				$ajax_sorting_callback . '_nonce',
3029
+				false,
3030
+				false
3031
+			);
3032
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3033
+												. $this->page_slug
3034
+												. '" />';
3035
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3036
+												. $ajax_sorting_callback
3037
+												. '" />';
3038
+		} else {
3039
+			$sortable_list_table_form_fields = '';
3040
+		}
3041
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3042
+		$hidden_form_fields                                      =
3043
+			isset($this->_template_args['list_table_hidden_fields'])
3044
+				? $this->_template_args['list_table_hidden_fields']
3045
+				: '';
3046
+		$nonce_ref                                               = $this->_req_action . '_nonce';
3047
+		$hidden_form_fields                                      .= '<input type="hidden" name="'
3048
+																	. $nonce_ref
3049
+																	. '" value="'
3050
+																	. wp_create_nonce($nonce_ref)
3051
+																	. '">';
3052
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
3053
+		// display message about search results?
3054
+		$search = $this->request->getRequestParam('s');
3055
+		$this->_template_args['before_list_table'] .= ! empty($search)
3056
+			? '<p class="ee-search-results">' . sprintf(
3057
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3058
+				trim($search, '%')
3059
+			) . '</p>'
3060
+			: '';
3061
+		// filter before_list_table template arg
3062
+		$this->_template_args['before_list_table'] = apply_filters(
3063
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3064
+			$this->_template_args['before_list_table'],
3065
+			$this->page_slug,
3066
+			$this->request->requestParams(),
3067
+			$this->_req_action
3068
+		);
3069
+		// convert to array and filter again
3070
+		// arrays are easier to inject new items in a specific location,
3071
+		// but would not be backwards compatible, so we have to add a new filter
3072
+		$this->_template_args['before_list_table'] = implode(
3073
+			" \n",
3074
+			(array) apply_filters(
3075
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3076
+				(array) $this->_template_args['before_list_table'],
3077
+				$this->page_slug,
3078
+				$this->request->requestParams(),
3079
+				$this->_req_action
3080
+			)
3081
+		);
3082
+		// filter after_list_table template arg
3083
+		$this->_template_args['after_list_table'] = apply_filters(
3084
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3085
+			$this->_template_args['after_list_table'],
3086
+			$this->page_slug,
3087
+			$this->request->requestParams(),
3088
+			$this->_req_action
3089
+		);
3090
+		// convert to array and filter again
3091
+		// arrays are easier to inject new items in a specific location,
3092
+		// but would not be backwards compatible, so we have to add a new filter
3093
+		$this->_template_args['after_list_table']   = implode(
3094
+			" \n",
3095
+			(array) apply_filters(
3096
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3097
+				(array) $this->_template_args['after_list_table'],
3098
+				$this->page_slug,
3099
+				$this->request->requestParams(),
3100
+				$this->_req_action
3101
+			)
3102
+		);
3103
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3104
+			$template_path,
3105
+			$this->_template_args,
3106
+			true
3107
+		);
3108
+		// the final template wrapper
3109
+		if ($sidebar) {
3110
+			$this->display_admin_page_with_sidebar();
3111
+		} else {
3112
+			$this->display_admin_page_with_no_sidebar();
3113
+		}
3114
+	}
3115
+
3116
+
3117
+	/**
3118
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3119
+	 * html string for the legend.
3120
+	 * $items are expected in an array in the following format:
3121
+	 * $legend_items = array(
3122
+	 *        'item_id' => array(
3123
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3124
+	 *            'desc' => esc_html__('localized description of item');
3125
+	 *        )
3126
+	 * );
3127
+	 *
3128
+	 * @param array $items see above for format of array
3129
+	 * @return string html string of legend
3130
+	 * @throws DomainException
3131
+	 */
3132
+	protected function _display_legend($items)
3133
+	{
3134
+		$this->_template_args['items'] = apply_filters(
3135
+			'FHEE__EE_Admin_Page___display_legend__items',
3136
+			(array) $items,
3137
+			$this
3138
+		);
3139
+		return EEH_Template::display_template(
3140
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3141
+			$this->_template_args,
3142
+			true
3143
+		);
3144
+	}
3145
+
3146
+
3147
+	/**
3148
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3149
+	 * The returned json object is created from an array in the following format:
3150
+	 * array(
3151
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3152
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3153
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3154
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3155
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3156
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3157
+	 *  that might be included in here)
3158
+	 * )
3159
+	 * The json object is populated by whatever is set in the $_template_args property.
3160
+	 *
3161
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3162
+	 *                                 instead of displayed.
3163
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3164
+	 * @return void
3165
+	 * @throws EE_Error
3166
+	 */
3167
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
3168
+	{
3169
+		// make sure any EE_Error notices have been handled.
3170
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3171
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3172
+		unset($this->_template_args['data']);
3173
+		$json = [
3174
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3175
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3176
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3177
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3178
+			'notices'   => EE_Error::get_notices(),
3179
+			'content'   => isset($this->_template_args['admin_page_content'])
3180
+				? $this->_template_args['admin_page_content'] : '',
3181
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3182
+			'isEEajax'  => true
3183
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3184
+		];
3185
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3186
+		if (null === error_get_last() || ! headers_sent()) {
3187
+			header('Content-Type: application/json; charset=UTF-8');
3188
+		}
3189
+		echo wp_json_encode($json);
3190
+		exit();
3191
+	}
3192
+
3193
+
3194
+	/**
3195
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3196
+	 *
3197
+	 * @return void
3198
+	 * @throws EE_Error
3199
+	 */
3200
+	public function return_json()
3201
+	{
3202
+		if ($this->request->isAjax()) {
3203
+			$this->_return_json();
3204
+		} else {
3205
+			throw new EE_Error(
3206
+				sprintf(
3207
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3208
+					__FUNCTION__
3209
+				)
3210
+			);
3211
+		}
3212
+	}
3213
+
3214
+
3215
+	/**
3216
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3217
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3218
+	 *
3219
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3220
+	 */
3221
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3222
+	{
3223
+		$this->_hook_obj = $hook_obj;
3224
+	}
3225
+
3226
+
3227
+	/**
3228
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3229
+	 *
3230
+	 * @param boolean $about whether to use the special about page wrapper or default.
3231
+	 * @return void
3232
+	 * @throws DomainException
3233
+	 * @throws EE_Error
3234
+	 */
3235
+	public function admin_page_wrapper($about = false)
3236
+	{
3237
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3238
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3239
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3240
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3241
+
3242
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3243
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3244
+			isset($this->_template_args['before_admin_page_content'])
3245
+				? $this->_template_args['before_admin_page_content']
3246
+				: ''
3247
+		);
3248
+
3249
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3250
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3251
+			isset($this->_template_args['after_admin_page_content'])
3252
+				? $this->_template_args['after_admin_page_content']
3253
+				: ''
3254
+		);
3255
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3256
+
3257
+		if ($this->request->isAjax()) {
3258
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3259
+				// $template_path,
3260
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3261
+				$this->_template_args,
3262
+				true
3263
+			);
3264
+			$this->_return_json();
3265
+		}
3266
+		// load settings page wrapper template
3267
+		$template_path = $about
3268
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3269
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3270
+
3271
+		EEH_Template::display_template($template_path, $this->_template_args);
3272
+	}
3273
+
3274
+
3275
+	/**
3276
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3277
+	 *
3278
+	 * @return string html
3279
+	 * @throws EE_Error
3280
+	 */
3281
+	protected function _get_main_nav_tabs()
3282
+	{
3283
+		// let's generate the html using the EEH_Tabbed_Content helper.
3284
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3285
+		// (rather than setting in the page_routes array)
3286
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3287
+	}
3288
+
3289
+
3290
+	/**
3291
+	 *        sort nav tabs
3292
+	 *
3293
+	 * @param $a
3294
+	 * @param $b
3295
+	 * @return int
3296
+	 */
3297
+	private function _sort_nav_tabs($a, $b)
3298
+	{
3299
+		if ($a['order'] === $b['order']) {
3300
+			return 0;
3301
+		}
3302
+		return ($a['order'] < $b['order']) ? -1 : 1;
3303
+	}
3304
+
3305
+
3306
+	/**
3307
+	 *    generates HTML for the forms used on admin pages
3308
+	 *
3309
+	 * @param array  $input_vars   - array of input field details
3310
+	 * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3311
+	 *                             use)
3312
+	 * @param bool   $id
3313
+	 * @return array|string
3314
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3315
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3316
+	 */
3317
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3318
+	{
3319
+		return $generator === 'string'
3320
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3321
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3322
+	}
3323
+
3324
+
3325
+	/**
3326
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3327
+	 *
3328
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3329
+	 *                                   Close" button.
3330
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3331
+	 *                                   'Save', [1] => 'save & close')
3332
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3333
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3334
+	 *                                   default actions by submitting some other value.
3335
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3336
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3337
+	 *                                   close (normal form handling).
3338
+	 */
3339
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3340
+	{
3341
+		// make sure $text and $actions are in an array
3342
+		$text          = (array) $text;
3343
+		$actions       = (array) $actions;
3344
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3345
+		$button_text   = ! empty($text)
3346
+			? $text
3347
+			: [
3348
+				esc_html__('Save', 'event_espresso'),
3349
+				esc_html__('Save and Close', 'event_espresso'),
3350
+			];
3351
+		$default_names = ['save', 'save_and_close'];
3352
+		$buttons = '';
3353
+		foreach ($button_text as $key => $button) {
3354
+			$ref     = $default_names[ $key ];
3355
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3356
+			$buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3357
+						. 'value="' . $button . '" name="' . $name . '" '
3358
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3359
+			if (! $both) {
3360
+				break;
3361
+			}
3362
+		}
3363
+		// add in a hidden index for the current page (so save and close redirects properly)
3364
+		$buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3365
+				   . $referrer_url
3366
+				   . '" />';
3367
+		$this->_template_args['save_buttons'] = $buttons;
3368
+	}
3369
+
3370
+
3371
+	/**
3372
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3373
+	 *
3374
+	 * @param string $route
3375
+	 * @param array  $additional_hidden_fields
3376
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3377
+	 * @since 4.6.0
3378
+	 */
3379
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3380
+	{
3381
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3382
+	}
3383
+
3384
+
3385
+	/**
3386
+	 * set form open and close tags on add/edit pages.
3387
+	 *
3388
+	 * @param string $route                    the route you want the form to direct to
3389
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3390
+	 * @return void
3391
+	 */
3392
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3393
+	{
3394
+		if (empty($route)) {
3395
+			$user_msg = esc_html__(
3396
+				'An error occurred. No action was set for this page\'s form.',
3397
+				'event_espresso'
3398
+			);
3399
+			$dev_msg  = $user_msg . "\n"
3400
+						. sprintf(
3401
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3402
+							__FUNCTION__,
3403
+							__CLASS__
3404
+						);
3405
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3406
+		}
3407
+		// open form
3408
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3409
+															 . $this->_admin_base_url
3410
+															 . '" id="'
3411
+															 . $route
3412
+															 . '_event_form" >';
3413
+		// add nonce
3414
+		$nonce                                             =
3415
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3416
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3417
+		// add REQUIRED form action
3418
+		$hidden_fields = [
3419
+			'action' => ['type' => 'hidden', 'value' => $route],
3420
+		];
3421
+		// merge arrays
3422
+		$hidden_fields = is_array($additional_hidden_fields)
3423
+			? array_merge($hidden_fields, $additional_hidden_fields)
3424
+			: $hidden_fields;
3425
+		// generate form fields
3426
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3427
+		// add fields to form
3428
+		foreach ((array) $form_fields as $form_field) {
3429
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3430
+		}
3431
+		// close form
3432
+		$this->_template_args['after_admin_page_content'] = '</form>';
3433
+	}
3434
+
3435
+
3436
+	/**
3437
+	 * Public Wrapper for _redirect_after_action() method since its
3438
+	 * discovered it would be useful for external code to have access.
3439
+	 *
3440
+	 * @param bool   $success
3441
+	 * @param string $what
3442
+	 * @param string $action_desc
3443
+	 * @param array  $query_args
3444
+	 * @param bool   $override_overwrite
3445
+	 * @throws EE_Error
3446
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3447
+	 * @since 4.5.0
3448
+	 */
3449
+	public function redirect_after_action(
3450
+		$success = false,
3451
+		$what = 'item',
3452
+		$action_desc = 'processed',
3453
+		$query_args = [],
3454
+		$override_overwrite = false
3455
+	) {
3456
+		$this->_redirect_after_action(
3457
+			$success,
3458
+			$what,
3459
+			$action_desc,
3460
+			$query_args,
3461
+			$override_overwrite
3462
+		);
3463
+	}
3464
+
3465
+
3466
+	/**
3467
+	 * Helper method for merging existing request data with the returned redirect url.
3468
+	 *
3469
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3470
+	 * filters are still applied.
3471
+	 *
3472
+	 * @param array $new_route_data
3473
+	 * @return array
3474
+	 */
3475
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3476
+	{
3477
+		foreach ($this->request->requestParams() as $ref => $value) {
3478
+			// unset nonces
3479
+			if (strpos($ref, 'nonce') !== false) {
3480
+				$this->request->unSetRequestParam($ref);
3481
+				continue;
3482
+			}
3483
+			// urlencode values.
3484
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3485
+			$this->request->setRequestParam($ref, $value);
3486
+		}
3487
+		return array_merge($this->request->requestParams(), $new_route_data);
3488
+	}
3489
+
3490
+
3491
+	/**
3492
+	 *    _redirect_after_action
3493
+	 *
3494
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3495
+	 * @param string $what               - what the action was performed on
3496
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3497
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3498
+	 *                                   action is completed
3499
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3500
+	 *                                   override this so that they show.
3501
+	 * @return void
3502
+	 * @throws EE_Error
3503
+	 */
3504
+	protected function _redirect_after_action(
3505
+		$success = 0,
3506
+		$what = 'item',
3507
+		$action_desc = 'processed',
3508
+		$query_args = [],
3509
+		$override_overwrite = false
3510
+	) {
3511
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3512
+		// class name for actions/filters.
3513
+		$classname = get_class($this);
3514
+		// set redirect url.
3515
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3516
+		// otherwise we go with whatever is set as the _admin_base_url
3517
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3518
+		$notices      = EE_Error::get_notices(false);
3519
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3520
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3521
+			EE_Error::overwrite_success();
3522
+		}
3523
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3524
+			// how many records affected ? more than one record ? or just one ?
3525
+			if ($success > 1) {
3526
+				// set plural msg
3527
+				EE_Error::add_success(
3528
+					sprintf(
3529
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3530
+						$what,
3531
+						$action_desc
3532
+					),
3533
+					__FILE__,
3534
+					__FUNCTION__,
3535
+					__LINE__
3536
+				);
3537
+			} elseif ($success === 1) {
3538
+				// set singular msg
3539
+				EE_Error::add_success(
3540
+					sprintf(
3541
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3542
+						$what,
3543
+						$action_desc
3544
+					),
3545
+					__FILE__,
3546
+					__FUNCTION__,
3547
+					__LINE__
3548
+				);
3549
+			}
3550
+		}
3551
+		// check that $query_args isn't something crazy
3552
+		if (! is_array($query_args)) {
3553
+			$query_args = [];
3554
+		}
3555
+		/**
3556
+		 * Allow injecting actions before the query_args are modified for possible different
3557
+		 * redirections on save and close actions
3558
+		 *
3559
+		 * @param array $query_args       The original query_args array coming into the
3560
+		 *                                method.
3561
+		 * @since 4.2.0
3562
+		 */
3563
+		do_action(
3564
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3565
+			$query_args
3566
+		);
3567
+		// calculate where we're going (if we have a "save and close" button pushed)
3568
+
3569
+		if (
3570
+			$this->request->requestParamIsSet('save_and_close')
3571
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3572
+		) {
3573
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3574
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3575
+			// regenerate query args array from referrer URL
3576
+			parse_str($parsed_url['query'], $query_args);
3577
+			// correct page and action will be in the query args now
3578
+			$redirect_url = admin_url('admin.php');
3579
+		}
3580
+		// merge any default query_args set in _default_route_query_args property
3581
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3582
+			$args_to_merge = [];
3583
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3584
+				// is there a wp_referer array in our _default_route_query_args property?
3585
+				if ($query_param === 'wp_referer') {
3586
+					$query_value = (array) $query_value;
3587
+					foreach ($query_value as $reference => $value) {
3588
+						if (strpos($reference, 'nonce') !== false) {
3589
+							continue;
3590
+						}
3591
+						// finally we will override any arguments in the referer with
3592
+						// what might be set on the _default_route_query_args array.
3593
+						if (isset($this->_default_route_query_args[ $reference ])) {
3594
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3595
+						} else {
3596
+							$args_to_merge[ $reference ] = urlencode($value);
3597
+						}
3598
+					}
3599
+					continue;
3600
+				}
3601
+				$args_to_merge[ $query_param ] = $query_value;
3602
+			}
3603
+			// now let's merge these arguments but override with what was specifically sent in to the
3604
+			// redirect.
3605
+			$query_args = array_merge($args_to_merge, $query_args);
3606
+		}
3607
+		$this->_process_notices($query_args);
3608
+		// generate redirect url
3609
+		// if redirecting to anything other than the main page, add a nonce
3610
+		if (isset($query_args['action'])) {
3611
+			// manually generate wp_nonce and merge that with the query vars
3612
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3613
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3614
+		}
3615
+		// we're adding some hooks and filters in here for processing any things just before redirects
3616
+		// (example: an admin page has done an insert or update and we want to run something after that).
3617
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3618
+		$redirect_url = apply_filters(
3619
+			'FHEE_redirect_' . $classname . $this->_req_action,
3620
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3621
+			$query_args
3622
+		);
3623
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3624
+		if ($this->request->isAjax()) {
3625
+			$default_data                    = [
3626
+				'close'        => true,
3627
+				'redirect_url' => $redirect_url,
3628
+				'where'        => 'main',
3629
+				'what'         => 'append',
3630
+			];
3631
+			$this->_template_args['success'] = $success;
3632
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3633
+				$default_data,
3634
+				$this->_template_args['data']
3635
+			) : $default_data;
3636
+			$this->_return_json();
3637
+		}
3638
+		wp_safe_redirect($redirect_url);
3639
+		exit();
3640
+	}
3641
+
3642
+
3643
+	/**
3644
+	 * process any notices before redirecting (or returning ajax request)
3645
+	 * This method sets the $this->_template_args['notices'] attribute;
3646
+	 *
3647
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3648
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3649
+	 *                                  page_routes haven't been defined yet.
3650
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3651
+	 *                                  still save a transient for the notice.
3652
+	 * @return void
3653
+	 * @throws EE_Error
3654
+	 */
3655
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3656
+	{
3657
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3658
+		if ($this->request->isAjax()) {
3659
+			$notices = EE_Error::get_notices(false);
3660
+			if (empty($this->_template_args['success'])) {
3661
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3662
+			}
3663
+			if (empty($this->_template_args['errors'])) {
3664
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3665
+			}
3666
+			if (empty($this->_template_args['attention'])) {
3667
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3668
+			}
3669
+		}
3670
+		$this->_template_args['notices'] = EE_Error::get_notices();
3671
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3672
+		if (! $this->request->isAjax() || $sticky_notices) {
3673
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3674
+			$this->_add_transient(
3675
+				$route,
3676
+				$this->_template_args['notices'],
3677
+				true,
3678
+				$skip_route_verify
3679
+			);
3680
+		}
3681
+	}
3682
+
3683
+
3684
+	/**
3685
+	 * get_action_link_or_button
3686
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3687
+	 *
3688
+	 * @param string $action        use this to indicate which action the url is generated with.
3689
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3690
+	 *                              property.
3691
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3692
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3693
+	 * @param string $base_url      If this is not provided
3694
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3695
+	 *                              Otherwise this value will be used.
3696
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3697
+	 * @return string
3698
+	 * @throws InvalidArgumentException
3699
+	 * @throws InvalidInterfaceException
3700
+	 * @throws InvalidDataTypeException
3701
+	 * @throws EE_Error
3702
+	 */
3703
+	public function get_action_link_or_button(
3704
+		$action,
3705
+		$type = 'add',
3706
+		$extra_request = [],
3707
+		$class = 'button-primary',
3708
+		$base_url = '',
3709
+		$exclude_nonce = false
3710
+	) {
3711
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3712
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3713
+			throw new EE_Error(
3714
+				sprintf(
3715
+					esc_html__(
3716
+						'There is no page route for given action for the button.  This action was given: %s',
3717
+						'event_espresso'
3718
+					),
3719
+					$action
3720
+				)
3721
+			);
3722
+		}
3723
+		if (! isset($this->_labels['buttons'][ $type ])) {
3724
+			throw new EE_Error(
3725
+				sprintf(
3726
+					esc_html__(
3727
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3728
+						'event_espresso'
3729
+					),
3730
+					$type
3731
+				)
3732
+			);
3733
+		}
3734
+		// finally check user access for this button.
3735
+		$has_access = $this->check_user_access($action, true);
3736
+		if (! $has_access) {
3737
+			return '';
3738
+		}
3739
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3740
+		$query_args = [
3741
+			'action' => $action,
3742
+		];
3743
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3744
+		if (! empty($extra_request)) {
3745
+			$query_args = array_merge($extra_request, $query_args);
3746
+		}
3747
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3748
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3749
+	}
3750
+
3751
+
3752
+	/**
3753
+	 * _per_page_screen_option
3754
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3755
+	 *
3756
+	 * @return void
3757
+	 * @throws InvalidArgumentException
3758
+	 * @throws InvalidInterfaceException
3759
+	 * @throws InvalidDataTypeException
3760
+	 */
3761
+	protected function _per_page_screen_option()
3762
+	{
3763
+		$option = 'per_page';
3764
+		$args   = [
3765
+			'label'   => apply_filters(
3766
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3767
+				$this->_admin_page_title,
3768
+				$this
3769
+			),
3770
+			'default' => (int) apply_filters(
3771
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3772
+				20
3773
+			),
3774
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3775
+		];
3776
+		// ONLY add the screen option if the user has access to it.
3777
+		if ($this->check_user_access($this->_current_view, true)) {
3778
+			add_screen_option($option, $args);
3779
+		}
3780
+	}
3781
+
3782
+
3783
+	/**
3784
+	 * set_per_page_screen_option
3785
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3786
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3787
+	 * admin_menu.
3788
+	 *
3789
+	 * @return void
3790
+	 */
3791
+	private function _set_per_page_screen_options()
3792
+	{
3793
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3794
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3795
+			if (! $user = wp_get_current_user()) {
3796
+				return;
3797
+			}
3798
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3799
+			if (! $option) {
3800
+				return;
3801
+			}
3802
+			$value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3803
+			$map_option = $option;
3804
+			$option     = str_replace('-', '_', $option);
3805
+			switch ($map_option) {
3806
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3807
+					$max_value = apply_filters(
3808
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3809
+						999,
3810
+						$this->_current_page,
3811
+						$this->_current_view
3812
+					);
3813
+					if ($value < 1) {
3814
+						return;
3815
+					}
3816
+					$value = min($value, $max_value);
3817
+					break;
3818
+				default:
3819
+					$value = apply_filters(
3820
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3821
+						false,
3822
+						$option,
3823
+						$value
3824
+					);
3825
+					if (false === $value) {
3826
+						return;
3827
+					}
3828
+					break;
3829
+			}
3830
+			update_user_meta($user->ID, $option, $value);
3831
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3832
+			exit;
3833
+		}
3834
+	}
3835
+
3836
+
3837
+	/**
3838
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3839
+	 *
3840
+	 * @param array $data array that will be assigned to template args.
3841
+	 */
3842
+	public function set_template_args($data)
3843
+	{
3844
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3845
+	}
3846
+
3847
+
3848
+	/**
3849
+	 * This makes available the WP transient system for temporarily moving data between routes
3850
+	 *
3851
+	 * @param string $route             the route that should receive the transient
3852
+	 * @param array  $data              the data that gets sent
3853
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3854
+	 *                                  normal route transient.
3855
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3856
+	 *                                  when we are adding a transient before page_routes have been defined.
3857
+	 * @return void
3858
+	 * @throws EE_Error
3859
+	 */
3860
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3861
+	{
3862
+		$user_id = get_current_user_id();
3863
+		if (! $skip_route_verify) {
3864
+			$this->_verify_route($route);
3865
+		}
3866
+		// now let's set the string for what kind of transient we're setting
3867
+		$transient = $notices
3868
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3869
+			: 'rte_tx_' . $route . '_' . $user_id;
3870
+		$data      = $notices ? ['notices' => $data] : $data;
3871
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3872
+		$existing = is_multisite() && is_network_admin()
3873
+			? get_site_transient($transient)
3874
+			: get_transient($transient);
3875
+		if ($existing) {
3876
+			$data = array_merge((array) $data, (array) $existing);
3877
+		}
3878
+		if (is_multisite() && is_network_admin()) {
3879
+			set_site_transient($transient, $data, 8);
3880
+		} else {
3881
+			set_transient($transient, $data, 8);
3882
+		}
3883
+	}
3884
+
3885
+
3886
+	/**
3887
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3888
+	 *
3889
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3890
+	 * @param string $route
3891
+	 * @return mixed data
3892
+	 */
3893
+	protected function _get_transient($notices = false, $route = '')
3894
+	{
3895
+		$user_id   = get_current_user_id();
3896
+		$route     = ! $route ? $this->_req_action : $route;
3897
+		$transient = $notices
3898
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3899
+			: 'rte_tx_' . $route . '_' . $user_id;
3900
+		$data      = is_multisite() && is_network_admin()
3901
+			? get_site_transient($transient)
3902
+			: get_transient($transient);
3903
+		// delete transient after retrieval (just in case it hasn't expired);
3904
+		if (is_multisite() && is_network_admin()) {
3905
+			delete_site_transient($transient);
3906
+		} else {
3907
+			delete_transient($transient);
3908
+		}
3909
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3910
+	}
3911
+
3912
+
3913
+	/**
3914
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3915
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3916
+	 * default route callback on the EE_Admin page you want it run.)
3917
+	 *
3918
+	 * @return void
3919
+	 */
3920
+	protected function _transient_garbage_collection()
3921
+	{
3922
+		global $wpdb;
3923
+		// retrieve all existing transients
3924
+		$query =
3925
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3926
+		if ($results = $wpdb->get_results($query)) {
3927
+			foreach ($results as $result) {
3928
+				$transient = str_replace('_transient_', '', $result->option_name);
3929
+				get_transient($transient);
3930
+				if (is_multisite() && is_network_admin()) {
3931
+					get_site_transient($transient);
3932
+				}
3933
+			}
3934
+		}
3935
+	}
3936
+
3937
+
3938
+	/**
3939
+	 * get_view
3940
+	 *
3941
+	 * @return string content of _view property
3942
+	 */
3943
+	public function get_view()
3944
+	{
3945
+		return $this->_view;
3946
+	}
3947
+
3948
+
3949
+	/**
3950
+	 * getter for the protected $_views property
3951
+	 *
3952
+	 * @return array
3953
+	 */
3954
+	public function get_views()
3955
+	{
3956
+		return $this->_views;
3957
+	}
3958
+
3959
+
3960
+	/**
3961
+	 * get_current_page
3962
+	 *
3963
+	 * @return string _current_page property value
3964
+	 */
3965
+	public function get_current_page()
3966
+	{
3967
+		return $this->_current_page;
3968
+	}
3969
+
3970
+
3971
+	/**
3972
+	 * get_current_view
3973
+	 *
3974
+	 * @return string _current_view property value
3975
+	 */
3976
+	public function get_current_view()
3977
+	{
3978
+		return $this->_current_view;
3979
+	}
3980
+
3981
+
3982
+	/**
3983
+	 * get_current_screen
3984
+	 *
3985
+	 * @return object The current WP_Screen object
3986
+	 */
3987
+	public function get_current_screen()
3988
+	{
3989
+		return $this->_current_screen;
3990
+	}
3991
+
3992
+
3993
+	/**
3994
+	 * get_current_page_view_url
3995
+	 *
3996
+	 * @return string This returns the url for the current_page_view.
3997
+	 */
3998
+	public function get_current_page_view_url()
3999
+	{
4000
+		return $this->_current_page_view_url;
4001
+	}
4002
+
4003
+
4004
+	/**
4005
+	 * just returns the Request
4006
+	 *
4007
+	 * @return RequestInterface
4008
+	 */
4009
+	public function get_request()
4010
+	{
4011
+		return $this->request;
4012
+	}
4013
+
4014
+
4015
+	/**
4016
+	 * just returns the _req_data property
4017
+	 *
4018
+	 * @return array
4019
+	 */
4020
+	public function get_request_data()
4021
+	{
4022
+		return $this->request->requestParams();
4023
+	}
4024
+
4025
+
4026
+	/**
4027
+	 * returns the _req_data protected property
4028
+	 *
4029
+	 * @return string
4030
+	 */
4031
+	public function get_req_action()
4032
+	{
4033
+		return $this->_req_action;
4034
+	}
4035
+
4036
+
4037
+	/**
4038
+	 * @return bool  value of $_is_caf property
4039
+	 */
4040
+	public function is_caf()
4041
+	{
4042
+		return $this->_is_caf;
4043
+	}
4044
+
4045
+
4046
+	/**
4047
+	 * @return mixed
4048
+	 */
4049
+	public function default_espresso_metaboxes()
4050
+	{
4051
+		return $this->_default_espresso_metaboxes;
4052
+	}
4053
+
4054
+
4055
+	/**
4056
+	 * @return mixed
4057
+	 */
4058
+	public function admin_base_url()
4059
+	{
4060
+		return $this->_admin_base_url;
4061
+	}
4062
+
4063
+
4064
+	/**
4065
+	 * @return mixed
4066
+	 */
4067
+	public function wp_page_slug()
4068
+	{
4069
+		return $this->_wp_page_slug;
4070
+	}
4071
+
4072
+
4073
+	/**
4074
+	 * updates  espresso configuration settings
4075
+	 *
4076
+	 * @param string                   $tab
4077
+	 * @param EE_Config_Base|EE_Config $config
4078
+	 * @param string                   $file file where error occurred
4079
+	 * @param string                   $func function  where error occurred
4080
+	 * @param string                   $line line no where error occurred
4081
+	 * @return boolean
4082
+	 */
4083
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4084
+	{
4085
+		// remove any options that are NOT going to be saved with the config settings.
4086
+		if (isset($config->core->ee_ueip_optin)) {
4087
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4088
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4089
+			update_option('ee_ueip_has_notified', true);
4090
+		}
4091
+		// and save it (note we're also doing the network save here)
4092
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
4093
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4094
+		if ($config_saved && $net_saved) {
4095
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4096
+			return true;
4097
+		}
4098
+		EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4099
+		return false;
4100
+	}
4101
+
4102
+
4103
+	/**
4104
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4105
+	 *
4106
+	 * @return array
4107
+	 */
4108
+	public function get_yes_no_values()
4109
+	{
4110
+		return $this->_yes_no_values;
4111
+	}
4112
+
4113
+
4114
+	protected function _get_dir()
4115
+	{
4116
+		$reflector = new ReflectionClass(get_class($this));
4117
+		return dirname($reflector->getFileName());
4118
+	}
4119
+
4120
+
4121
+	/**
4122
+	 * A helper for getting a "next link".
4123
+	 *
4124
+	 * @param string $url   The url to link to
4125
+	 * @param string $class The class to use.
4126
+	 * @return string
4127
+	 */
4128
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4129
+	{
4130
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4131
+	}
4132
+
4133
+
4134
+	/**
4135
+	 * A helper for getting a "previous link".
4136
+	 *
4137
+	 * @param string $url   The url to link to
4138
+	 * @param string $class The class to use.
4139
+	 * @return string
4140
+	 */
4141
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4142
+	{
4143
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4144
+	}
4145
+
4146
+
4147
+
4148
+
4149
+
4150
+
4151
+
4152
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4153
+
4154
+
4155
+	/**
4156
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4157
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4158
+	 * _req_data array.
4159
+	 *
4160
+	 * @return bool success/fail
4161
+	 * @throws EE_Error
4162
+	 * @throws InvalidArgumentException
4163
+	 * @throws ReflectionException
4164
+	 * @throws InvalidDataTypeException
4165
+	 * @throws InvalidInterfaceException
4166
+	 */
4167
+	protected function _process_resend_registration()
4168
+	{
4169
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4170
+		do_action(
4171
+			'AHEE__EE_Admin_Page___process_resend_registration',
4172
+			$this->_template_args['success'],
4173
+			$this->request->requestParams()
4174
+		);
4175
+		return $this->_template_args['success'];
4176
+	}
4177
+
4178
+
4179
+	/**
4180
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4181
+	 *
4182
+	 * @param EE_Payment $payment
4183
+	 * @return bool success/fail
4184
+	 */
4185
+	protected function _process_payment_notification(EE_Payment $payment)
4186
+	{
4187
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4188
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4189
+		$this->_template_args['success'] = apply_filters(
4190
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4191
+			false,
4192
+			$payment
4193
+		);
4194
+		return $this->_template_args['success'];
4195
+	}
4196 4196
 }
Please login to merge, or discard this patch.