Completed
Branch FET/update-messages-admin-requ... (bf978d)
by
unknown
06:24 queued 04:19
created
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +4103 added lines, -4103 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 (
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 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 . ']' ] = htmlspecialchars($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 '
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 . ']' ] = htmlspecialchars($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.
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
         $ee_menu_slugs = (array) $ee_menu_slugs;
537 537
         if (
538 538
             ! $this->request->isAjax()
539
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
539
+            && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))
540 540
         ) {
541 541
             return;
542 542
         }
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
             : $req_action;
557 557
 
558 558
         $this->_current_view = $this->_req_action;
559
-        $this->_req_nonce    = $this->_req_action . '_nonce';
559
+        $this->_req_nonce    = $this->_req_action.'_nonce';
560 560
         $this->_define_page_props();
561 561
         $this->_current_page_view_url = add_query_arg(
562 562
             ['page' => $this->_current_page, 'action' => $this->_current_view],
@@ -593,21 +593,21 @@  discard block
 block discarded – undo
593 593
         }
594 594
         // filter routes and page_config so addons can add their stuff. Filtering done per class
595 595
         $this->_page_routes = apply_filters(
596
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
596
+            'FHEE__'.get_class($this).'__page_setup__page_routes',
597 597
             $this->_page_routes,
598 598
             $this
599 599
         );
600 600
         $this->_page_config = apply_filters(
601
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
601
+            'FHEE__'.get_class($this).'__page_setup__page_config',
602 602
             $this->_page_config,
603 603
             $this
604 604
         );
605 605
         // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
606 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)) {
607
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
608 608
             add_action(
609 609
                 'AHEE__EE_Admin_Page__route_admin_request',
610
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
610
+                [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view],
611 611
                 10,
612 612
                 2
613 613
             );
@@ -620,8 +620,8 @@  discard block
 block discarded – undo
620 620
             if ($this->_is_UI_request) {
621 621
                 // admin_init stuff - global, all views for this page class, specific view
622 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);
623
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
624
+                    add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15);
625 625
                 }
626 626
             } else {
627 627
                 // hijack regular WP loading and route admin request immediately
@@ -640,12 +640,12 @@  discard block
 block discarded – undo
640 640
      */
641 641
     private function _do_other_page_hooks()
642 642
     {
643
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
643
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []);
644 644
         foreach ($registered_pages as $page) {
645 645
             // now let's setup the file name and class that should be present
646 646
             $classname = str_replace('.class.php', '', $page);
647 647
             // autoloaders should take care of loading file
648
-            if (! class_exists($classname)) {
648
+            if ( ! class_exists($classname)) {
649 649
                 $error_msg[] = sprintf(
650 650
                     esc_html__(
651 651
                         'Something went wrong with loading the %s admin hooks page.',
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
                                    ),
663 663
                                    $page,
664 664
                                    '<br />',
665
-                                   '<strong>' . $classname . '</strong>'
665
+                                   '<strong>'.$classname.'</strong>'
666 666
                                );
667 667
                 throw new EE_Error(implode('||', $error_msg));
668 668
             }
@@ -704,13 +704,13 @@  discard block
 block discarded – undo
704 704
         // load admin_notices - global, page class, and view specific
705 705
         add_action('admin_notices', [$this, 'admin_notices_global'], 5);
706 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);
707
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
708
+            add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15);
709 709
         }
710 710
         // load network admin_notices - global, page class, and view specific
711 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]);
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 714
         }
715 715
         // this will save any per_page screen options if they are present
716 716
         $this->_set_per_page_screen_options();
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
     protected function _verify_routes()
833 833
     {
834 834
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
835
-        if (! $this->_current_page && ! $this->request->isAjax()) {
835
+        if ( ! $this->_current_page && ! $this->request->isAjax()) {
836 836
             return false;
837 837
         }
838 838
         $this->_route = false;
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
                 $this->_admin_page_title
845 845
             );
846 846
             // developer error msg
847
-            $error_msg .= '||' . $error_msg
847
+            $error_msg .= '||'.$error_msg
848 848
                           . esc_html__(
849 849
                               ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
850 850
                               'event_espresso'
@@ -853,9 +853,9 @@  discard block
 block discarded – undo
853 853
         }
854 854
         // and that the requested page route exists
855 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 ]
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 859
                 : [];
860 860
         } else {
861 861
             // user error msg
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
                 $this->_admin_page_title
868 868
             );
869 869
             // developer error msg
870
-            $error_msg .= '||' . $error_msg
870
+            $error_msg .= '||'.$error_msg
871 871
                           . sprintf(
872 872
                               esc_html__(
873 873
                                   ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
             throw new EE_Error($error_msg);
879 879
         }
880 880
         // and that a default route exists
881
-        if (! array_key_exists('default', $this->_page_routes)) {
881
+        if ( ! array_key_exists('default', $this->_page_routes)) {
882 882
             // user error msg
883 883
             $error_msg = sprintf(
884 884
                 esc_html__(
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
                 $this->_admin_page_title
889 889
             );
890 890
             // developer error msg
891
-            $error_msg .= '||' . $error_msg
891
+            $error_msg .= '||'.$error_msg
892 892
                           . esc_html__(
893 893
                               ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
894 894
                               'event_espresso'
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
             $this->_admin_page_title
930 930
         );
931 931
         // developer error msg
932
-        $error_msg .= '||' . $error_msg
932
+        $error_msg .= '||'.$error_msg
933 933
                       . sprintf(
934 934
                           esc_html__(
935 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',
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
     protected function _verify_nonce($nonce, $nonce_ref)
955 955
     {
956 956
         // verify nonce against expected value
957
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
957
+        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
958 958
             // these are not the droids you are looking for !!!
959 959
             $msg = sprintf(
960 960
                 esc_html__('%sNonce Fail.%s', 'event_espresso'),
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
                     __CLASS__
972 972
                 );
973 973
             }
974
-            if (! $this->request->isAjax()) {
974
+            if ( ! $this->request->isAjax()) {
975 975
                 wp_die($msg);
976 976
             }
977 977
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
      */
996 996
     protected function _route_admin_request()
997 997
     {
998
-        if (! $this->_is_UI_request) {
998
+        if ( ! $this->_is_UI_request) {
999 999
             $this->_verify_routes();
1000 1000
         }
1001 1001
         $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
         $error_msg = '';
1016 1016
         // action right before calling route
1017 1017
         // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1018
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1018
+        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1019 1019
             do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1020 1020
         }
1021 1021
         // right before calling the route, let's clean the _wp_http_referer
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
                 wp_unslash($this->request->getServerParam('REQUEST_URI'))
1027 1027
             )
1028 1028
         );
1029
-        if (! empty($func)) {
1029
+        if ( ! empty($func)) {
1030 1030
             if (is_array($func)) {
1031 1031
                 list($class, $method) = $func;
1032 1032
             } elseif (strpos($func, '::') !== false) {
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
                 $class  = $this;
1036 1036
                 $method = $func;
1037 1037
             }
1038
-            if (! (is_object($class) && $class === $this)) {
1038
+            if ( ! (is_object($class) && $class === $this)) {
1039 1039
                 // send along this admin page object for access by addons.
1040 1040
                 $args['admin_page_object'] = $this;
1041 1041
             }
@@ -1076,7 +1076,7 @@  discard block
 block discarded – undo
1076 1076
                     $method
1077 1077
                 );
1078 1078
             }
1079
-            if (! empty($error_msg)) {
1079
+            if ( ! empty($error_msg)) {
1080 1080
                 throw new EE_Error($error_msg);
1081 1081
             }
1082 1082
         }
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
                 if (strpos($key, 'nonce') !== false) {
1162 1162
                     continue;
1163 1163
                 }
1164
-                $args[ 'wp_referer[' . $key . ']' ] = htmlspecialchars($value);
1164
+                $args['wp_referer['.$key.']'] = htmlspecialchars($value);
1165 1165
             }
1166 1166
         }
1167 1167
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1201,8 +1201,8 @@  discard block
 block discarded – undo
1201 1201
     protected function _add_help_tabs()
1202 1202
     {
1203 1203
         $tour_buttons = '';
1204
-        if (isset($this->_page_config[ $this->_req_action ])) {
1205
-            $config = $this->_page_config[ $this->_req_action ];
1204
+        if (isset($this->_page_config[$this->_req_action])) {
1205
+            $config = $this->_page_config[$this->_req_action];
1206 1206
             // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1207 1207
             // is there a help tour for the current route?  if there is let's setup the tour buttons
1208 1208
             // if (isset($this->_help_tour[ $this->_req_action ])) {
@@ -1225,7 +1225,7 @@  discard block
 block discarded – undo
1225 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 1226
             if (is_array($config) && isset($config['help_sidebar'])) {
1227 1227
                 // check that the callback given is valid
1228
-                if (! method_exists($this, $config['help_sidebar'])) {
1228
+                if ( ! method_exists($this, $config['help_sidebar'])) {
1229 1229
                     throw new EE_Error(
1230 1230
                         sprintf(
1231 1231
                             esc_html__(
@@ -1238,7 +1238,7 @@  discard block
 block discarded – undo
1238 1238
                     );
1239 1239
                 }
1240 1240
                 $content = apply_filters(
1241
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1241
+                    'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar',
1242 1242
                     $this->{$config['help_sidebar']}()
1243 1243
                 );
1244 1244
                 $content .= $tour_buttons; // add help tour buttons.
@@ -1246,27 +1246,27 @@  discard block
 block discarded – undo
1246 1246
                 $this->_current_screen->set_help_sidebar($content);
1247 1247
             }
1248 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)) {
1249
+            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1250 1250
                 $this->_current_screen->set_help_sidebar($tour_buttons);
1251 1251
             }
1252 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)) {
1253
+            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1254 1254
                 $_ht['id']      = $this->page_slug;
1255 1255
                 $_ht['title']   = esc_html__('Help Tours', 'event_espresso');
1256 1256
                 $_ht['content'] = '<p>'
1257 1257
                                   . esc_html__(
1258 1258
                                       'The buttons to the right allow you to start/restart any help tours available for this page',
1259 1259
                                       'event_espresso'
1260
-                                  ) . '</p>';
1260
+                                  ).'</p>';
1261 1261
                 $this->_current_screen->add_help_tab($_ht);
1262 1262
             }
1263
-            if (! isset($config['help_tabs'])) {
1263
+            if ( ! isset($config['help_tabs'])) {
1264 1264
                 return;
1265 1265
             } //no help tabs for this route
1266 1266
             foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1267 1267
                 // we're here so there ARE help tabs!
1268 1268
                 // make sure we've got what we need
1269
-                if (! isset($cfg['title'])) {
1269
+                if ( ! isset($cfg['title'])) {
1270 1270
                     throw new EE_Error(
1271 1271
                         esc_html__(
1272 1272
                             'The _page_config array is not set up properly for help tabs.  It is missing a title',
@@ -1274,7 +1274,7 @@  discard block
 block discarded – undo
1274 1274
                         )
1275 1275
                     );
1276 1276
                 }
1277
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1277
+                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1278 1278
                     throw new EE_Error(
1279 1279
                         esc_html__(
1280 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',
@@ -1283,11 +1283,11 @@  discard block
 block discarded – undo
1283 1283
                     );
1284 1284
                 }
1285 1285
                 // first priority goes to content.
1286
-                if (! empty($cfg['content'])) {
1286
+                if ( ! empty($cfg['content'])) {
1287 1287
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1288 1288
                     // second priority goes to filename
1289
-                } elseif (! empty($cfg['filename'])) {
1290
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1289
+                } elseif ( ! empty($cfg['filename'])) {
1290
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1291 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 1292
                     $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1293 1293
                                                              . basename($this->_get_dir())
@@ -1295,7 +1295,7 @@  discard block
 block discarded – undo
1295 1295
                                                              . $cfg['filename']
1296 1296
                                                              . '.help_tab.php' : $file_path;
1297 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)) {
1298
+                    if ( ! isset($cfg['callback']) && ! is_readable($file_path)) {
1299 1299
                         EE_Error::add_error(
1300 1300
                             sprintf(
1301 1301
                                 esc_html__(
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
                     return;
1344 1344
                 }
1345 1345
                 // setup config array for help tab method
1346
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1346
+                $id  = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1347 1347
                 $_ht = [
1348 1348
                     'id'       => $id,
1349 1349
                     'title'    => $cfg['title'],
@@ -1470,8 +1470,8 @@  discard block
 block discarded – undo
1470 1470
             $qtips = (array) $this->_route_config['qtips'];
1471 1471
             // load qtip loader
1472 1472
             $path = [
1473
-                $this->_get_dir() . '/qtips/',
1474
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1473
+                $this->_get_dir().'/qtips/',
1474
+                EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1475 1475
             ];
1476 1476
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1477 1477
         }
@@ -1493,7 +1493,7 @@  discard block
 block discarded – undo
1493 1493
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1494 1494
         $i = 0;
1495 1495
         foreach ($this->_page_config as $slug => $config) {
1496
-            if (! is_array($config) || empty($config['nav'])) {
1496
+            if ( ! is_array($config) || empty($config['nav'])) {
1497 1497
                 continue;
1498 1498
             }
1499 1499
             // no nav tab for this config
@@ -1502,12 +1502,12 @@  discard block
 block discarded – undo
1502 1502
                 // nav tab is only to appear when route requested.
1503 1503
                 continue;
1504 1504
             }
1505
-            if (! $this->check_user_access($slug, true)) {
1505
+            if ( ! $this->check_user_access($slug, true)) {
1506 1506
                 // no nav tab because current user does not have access.
1507 1507
                 continue;
1508 1508
             }
1509
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1510
-            $this->_nav_tabs[ $slug ] = [
1509
+            $css_class                = isset($config['css_class']) ? $config['css_class'].' ' : '';
1510
+            $this->_nav_tabs[$slug] = [
1511 1511
                 'url'       => isset($config['nav']['url'])
1512 1512
                     ? $config['nav']['url']
1513 1513
                     : self::add_query_args_and_nonce(
@@ -1519,14 +1519,14 @@  discard block
 block discarded – undo
1519 1519
                     : ucwords(
1520 1520
                         str_replace('_', ' ', $slug)
1521 1521
                     ),
1522
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1522
+                'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class,
1523 1523
                 'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1524 1524
             ];
1525 1525
             $i++;
1526 1526
         }
1527 1527
         // if $this->_nav_tabs is empty then lets set the default
1528 1528
         if (empty($this->_nav_tabs)) {
1529
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1529
+            $this->_nav_tabs[$this->_default_nav_tab_name] = [
1530 1530
                 'url'       => $this->_admin_base_url,
1531 1531
                 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1532 1532
                 'css_class' => 'nav-tab-active',
@@ -1551,10 +1551,10 @@  discard block
 block discarded – undo
1551 1551
             foreach ($this->_route_config['labels'] as $label => $text) {
1552 1552
                 if (is_array($text)) {
1553 1553
                     foreach ($text as $sublabel => $subtext) {
1554
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1554
+                        $this->_labels[$label][$sublabel] = $subtext;
1555 1555
                     }
1556 1556
                 } else {
1557
-                    $this->_labels[ $label ] = $text;
1557
+                    $this->_labels[$label] = $text;
1558 1558
                 }
1559 1559
             }
1560 1560
         }
@@ -1576,12 +1576,12 @@  discard block
 block discarded – undo
1576 1576
     {
1577 1577
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1578 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 ])
1579
+        $capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1580 1580
                           && is_array(
1581
-                              $this->_page_routes[ $route_to_check ]
1581
+                              $this->_page_routes[$route_to_check]
1582 1582
                           )
1583
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1584
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1583
+                          && ! empty($this->_page_routes[$route_to_check]['capability'])
1584
+            ? $this->_page_routes[$route_to_check]['capability'] : null;
1585 1585
         if (empty($capability) && empty($route_to_check)) {
1586 1586
             $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1587 1587
                 : $this->_route['capability'];
@@ -1706,7 +1706,7 @@  discard block
 block discarded – undo
1706 1706
         //     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1707 1707
         // }
1708 1708
         // current set timezone for timezone js
1709
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1709
+        echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>';
1710 1710
     }
1711 1711
 
1712 1712
 
@@ -1740,7 +1740,7 @@  discard block
 block discarded – undo
1740 1740
         // loop through the array and setup content
1741 1741
         foreach ($help_array as $trigger => $help) {
1742 1742
             // make sure the array is setup properly
1743
-            if (! isset($help['title']) || ! isset($help['content'])) {
1743
+            if ( ! isset($help['title']) || ! isset($help['content'])) {
1744 1744
                 throw new EE_Error(
1745 1745
                     esc_html__(
1746 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',
@@ -1754,8 +1754,8 @@  discard block
 block discarded – undo
1754 1754
                 'help_popup_title'   => $help['title'],
1755 1755
                 'help_popup_content' => $help['content'],
1756 1756
             ];
1757
-            $content       .= EEH_Template::display_template(
1758
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1757
+            $content .= EEH_Template::display_template(
1758
+                EE_ADMIN_TEMPLATE.'admin_help_popup.template.php',
1759 1759
                 $template_args,
1760 1760
                 true
1761 1761
             );
@@ -1777,15 +1777,15 @@  discard block
 block discarded – undo
1777 1777
     private function _get_help_content()
1778 1778
     {
1779 1779
         // what is the method we're looking for?
1780
-        $method_name = '_help_popup_content_' . $this->_req_action;
1780
+        $method_name = '_help_popup_content_'.$this->_req_action;
1781 1781
         // if method doesn't exist let's get out.
1782
-        if (! method_exists($this, $method_name)) {
1782
+        if ( ! method_exists($this, $method_name)) {
1783 1783
             return [];
1784 1784
         }
1785 1785
         // k we're good to go let's retrieve the help array
1786 1786
         $help_array = call_user_func([$this, $method_name]);
1787 1787
         // make sure we've got an array!
1788
-        if (! is_array($help_array)) {
1788
+        if ( ! is_array($help_array)) {
1789 1789
             throw new EE_Error(
1790 1790
                 esc_html__(
1791 1791
                     'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
@@ -1817,15 +1817,15 @@  discard block
 block discarded – undo
1817 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 1818
         $help_array   = $this->_get_help_content();
1819 1819
         $help_content = '';
1820
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1821
-            $help_array[ $trigger_id ] = [
1820
+        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1821
+            $help_array[$trigger_id] = [
1822 1822
                 'title'   => esc_html__('Missing Content', 'event_espresso'),
1823 1823
                 'content' => esc_html__(
1824 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 1825
                     'event_espresso'
1826 1826
                 ),
1827 1827
             ];
1828
-            $help_content              = $this->_set_help_popup_content($help_array);
1828
+            $help_content = $this->_set_help_popup_content($help_array);
1829 1829
         }
1830 1830
         // let's setup the trigger
1831 1831
         $content = '<a class="ee-dialog" href="?height='
@@ -1893,15 +1893,15 @@  discard block
 block discarded – undo
1893 1893
         // register all styles
1894 1894
         wp_register_style(
1895 1895
             'espresso-ui-theme',
1896
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1896
+            EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1897 1897
             [],
1898 1898
             EVENT_ESPRESSO_VERSION
1899 1899
         );
1900
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1900
+        wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1901 1901
         // helpers styles
1902 1902
         wp_register_style(
1903 1903
             'ee-text-links',
1904
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1904
+            EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css',
1905 1905
             [],
1906 1906
             EVENT_ESPRESSO_VERSION
1907 1907
         );
@@ -1909,21 +1909,21 @@  discard block
 block discarded – undo
1909 1909
         // register all scripts
1910 1910
         wp_register_script(
1911 1911
             'ee-dialog',
1912
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1912
+            EE_ADMIN_URL.'assets/ee-dialog-helper.js',
1913 1913
             ['jquery', 'jquery-ui-draggable'],
1914 1914
             EVENT_ESPRESSO_VERSION,
1915 1915
             true
1916 1916
         );
1917 1917
         wp_register_script(
1918 1918
             'ee_admin_js',
1919
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1919
+            EE_ADMIN_URL.'assets/ee-admin-page.js',
1920 1920
             ['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1921 1921
             EVENT_ESPRESSO_VERSION,
1922 1922
             true
1923 1923
         );
1924 1924
         wp_register_script(
1925 1925
             'jquery-ui-timepicker-addon',
1926
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1926
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js',
1927 1927
             ['jquery-ui-datepicker', 'jquery-ui-slider'],
1928 1928
             EVENT_ESPRESSO_VERSION,
1929 1929
             true
@@ -1935,7 +1935,7 @@  discard block
 block discarded – undo
1935 1935
         // script for sorting tables
1936 1936
         wp_register_script(
1937 1937
             'espresso_ajax_table_sorting',
1938
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1938
+            EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js',
1939 1939
             ['ee_admin_js', 'jquery-ui-sortable'],
1940 1940
             EVENT_ESPRESSO_VERSION,
1941 1941
             true
@@ -1943,7 +1943,7 @@  discard block
 block discarded – undo
1943 1943
         // script for parsing uri's
1944 1944
         wp_register_script(
1945 1945
             'ee-parse-uri',
1946
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1946
+            EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js',
1947 1947
             [],
1948 1948
             EVENT_ESPRESSO_VERSION,
1949 1949
             true
@@ -1951,7 +1951,7 @@  discard block
 block discarded – undo
1951 1951
         // and parsing associative serialized form elements
1952 1952
         wp_register_script(
1953 1953
             'ee-serialize-full-array',
1954
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1954
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js',
1955 1955
             ['jquery'],
1956 1956
             EVENT_ESPRESSO_VERSION,
1957 1957
             true
@@ -1959,28 +1959,28 @@  discard block
 block discarded – undo
1959 1959
         // helpers scripts
1960 1960
         wp_register_script(
1961 1961
             'ee-text-links',
1962
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1962
+            EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js',
1963 1963
             ['jquery'],
1964 1964
             EVENT_ESPRESSO_VERSION,
1965 1965
             true
1966 1966
         );
1967 1967
         wp_register_script(
1968 1968
             'ee-moment-core',
1969
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1969
+            EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js',
1970 1970
             [],
1971 1971
             EVENT_ESPRESSO_VERSION,
1972 1972
             true
1973 1973
         );
1974 1974
         wp_register_script(
1975 1975
             'ee-moment',
1976
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1976
+            EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js',
1977 1977
             ['ee-moment-core'],
1978 1978
             EVENT_ESPRESSO_VERSION,
1979 1979
             true
1980 1980
         );
1981 1981
         wp_register_script(
1982 1982
             'ee-datepicker',
1983
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1983
+            EE_ADMIN_URL.'assets/ee-datepicker.js',
1984 1984
             ['jquery-ui-timepicker-addon', 'ee-moment'],
1985 1985
             EVENT_ESPRESSO_VERSION,
1986 1986
             true
@@ -2040,7 +2040,7 @@  discard block
 block discarded – undo
2040 2040
 
2041 2041
         add_filter(
2042 2042
             'admin_body_class',
2043
-            function ($classes) {
2043
+            function($classes) {
2044 2044
                 if (strpos($classes, 'espresso-admin') === false) {
2045 2045
                     $classes .= ' espresso-admin';
2046 2046
                 }
@@ -2128,12 +2128,12 @@  discard block
 block discarded – undo
2128 2128
     protected function _set_list_table()
2129 2129
     {
2130 2130
         // first is this a list_table view?
2131
-        if (! isset($this->_route_config['list_table'])) {
2131
+        if ( ! isset($this->_route_config['list_table'])) {
2132 2132
             return;
2133 2133
         } //not a list_table view so get out.
2134 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) {
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 2137
             // user error msg
2138 2138
             $error_msg = esc_html__(
2139 2139
                 'An error occurred. The requested list table views could not be found.',
@@ -2153,10 +2153,10 @@  discard block
 block discarded – undo
2153 2153
         }
2154 2154
         // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2155 2155
         $this->_views = apply_filters(
2156
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2156
+            'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action,
2157 2157
             $this->_views
2158 2158
         );
2159
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2159
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
2160 2160
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2161 2161
         $this->_set_list_table_view();
2162 2162
         $this->_set_list_table_object();
@@ -2191,7 +2191,7 @@  discard block
 block discarded – undo
2191 2191
     protected function _set_list_table_object()
2192 2192
     {
2193 2193
         if (isset($this->_route_config['list_table'])) {
2194
-            if (! class_exists($this->_route_config['list_table'])) {
2194
+            if ( ! class_exists($this->_route_config['list_table'])) {
2195 2195
                 throw new EE_Error(
2196 2196
                     sprintf(
2197 2197
                         esc_html__(
@@ -2229,15 +2229,15 @@  discard block
 block discarded – undo
2229 2229
         foreach ($this->_views as $key => $view) {
2230 2230
             $query_args = [];
2231 2231
             // check for current view
2232
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2232
+            $this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2233 2233
             $query_args['action']                        = $this->_req_action;
2234
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2234
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
2235 2235
             $query_args['status']                        = $view['slug'];
2236 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'] ]);
2237
+            if (isset($extra_query_args[$view['slug']])) {
2238
+                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
2239 2239
             }
2240
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2240
+            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2241 2241
         }
2242 2242
         return $this->_views;
2243 2243
     }
@@ -2268,14 +2268,14 @@  discard block
 block discarded – undo
2268 2268
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2269 2269
         foreach ($values as $value) {
2270 2270
             if ($value < $max_entries) {
2271
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2271
+                $selected = $value === $per_page ? ' selected="'.$per_page.'"' : '';
2272 2272
                 $entries_per_page_dropdown .= '
2273
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2273
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
2274 2274
             }
2275 2275
         }
2276
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2276
+        $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : '';
2277 2277
         $entries_per_page_dropdown .= '
2278
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2278
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
2279 2279
         $entries_per_page_dropdown .= '
2280 2280
 					</select>
2281 2281
 					entries
@@ -2299,7 +2299,7 @@  discard block
 block discarded – undo
2299 2299
             empty($this->_search_btn_label) ? $this->page_label
2300 2300
                 : $this->_search_btn_label
2301 2301
         );
2302
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2302
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
2303 2303
     }
2304 2304
 
2305 2305
 
@@ -2387,7 +2387,7 @@  discard block
 block discarded – undo
2387 2387
             $total_columns                                       = ! empty($screen_columns)
2388 2388
                 ? $screen_columns
2389 2389
                 : $this->_route_config['columns'][1];
2390
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2390
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
2391 2391
             $this->_template_args['current_page']                = $this->_wp_page_slug;
2392 2392
             $this->_template_args['screen']                      = $this->_current_screen;
2393 2393
             $this->_column_template_path                         = EE_ADMIN_TEMPLATE
@@ -2432,7 +2432,7 @@  discard block
 block discarded – undo
2432 2432
      */
2433 2433
     protected function _espresso_ratings_request()
2434 2434
     {
2435
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2435
+        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2436 2436
             return;
2437 2437
         }
2438 2438
         $ratings_box_title = apply_filters(
@@ -2460,7 +2460,7 @@  discard block
 block discarded – undo
2460 2460
     public function espresso_ratings_request()
2461 2461
     {
2462 2462
         EEH_Template::display_template(
2463
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2463
+            EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php',
2464 2464
             []
2465 2465
         );
2466 2466
     }
@@ -2468,22 +2468,22 @@  discard block
 block discarded – undo
2468 2468
 
2469 2469
     public static function cached_rss_display($rss_id, $url)
2470 2470
     {
2471
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2471
+        $loading = '<p class="widget-loading hide-if-no-js">'
2472 2472
                      . esc_html__('Loading&#8230;', 'event_espresso')
2473 2473
                      . '</p><p class="hide-if-js">'
2474 2474
                      . esc_html__('This widget requires JavaScript.', 'event_espresso')
2475 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);
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 2480
         $output    = get_transient($cache_key);
2481 2481
         if ($output !== false) {
2482
-            echo $pre . $output . $post; // already escaped
2482
+            echo $pre.$output.$post; // already escaped
2483 2483
             return true;
2484 2484
         }
2485
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2486
-            echo $pre . $loading . $post; // already escaped
2485
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
2486
+            echo $pre.$loading.$post; // already escaped
2487 2487
             return false;
2488 2488
         }
2489 2489
         ob_start();
@@ -2550,19 +2550,19 @@  discard block
 block discarded – undo
2550 2550
     public function espresso_sponsors_post_box()
2551 2551
     {
2552 2552
         EEH_Template::display_template(
2553
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2553
+            EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'
2554 2554
         );
2555 2555
     }
2556 2556
 
2557 2557
 
2558 2558
     private function _publish_post_box()
2559 2559
     {
2560
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2560
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2561 2561
         // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2562 2562
         // then we'll use that for the metabox label.
2563 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 ]
2564
+        if ( ! empty($this->_labels['publishbox'])) {
2565
+            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2566 2566
                 : $this->_labels['publishbox'];
2567 2567
         } else {
2568 2568
             $box_label = esc_html__('Publish', 'event_espresso');
@@ -2591,7 +2591,7 @@  discard block
 block discarded – undo
2591 2591
             ? $this->_template_args['publish_box_extra_content']
2592 2592
             : '';
2593 2593
         echo EEH_Template::display_template(
2594
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2594
+            EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php',
2595 2595
             $this->_template_args,
2596 2596
             true
2597 2597
         );
@@ -2683,18 +2683,18 @@  discard block
 block discarded – undo
2683 2683
             );
2684 2684
         }
2685 2685
         $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2686
-        if (! empty($name) && ! empty($id)) {
2687
-            $hidden_field_arr[ $name ] = [
2686
+        if ( ! empty($name) && ! empty($id)) {
2687
+            $hidden_field_arr[$name] = [
2688 2688
                 'type'  => 'hidden',
2689 2689
                 'value' => $id,
2690 2690
             ];
2691
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2691
+            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2692 2692
         } else {
2693 2693
             $hf = '';
2694 2694
         }
2695 2695
         // add hidden field
2696 2696
         $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2697
-            ? $hf[ $name ]['field']
2697
+            ? $hf[$name]['field']
2698 2698
             : $hf;
2699 2699
     }
2700 2700
 
@@ -2796,7 +2796,7 @@  discard block
 block discarded – undo
2796 2796
         }
2797 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 2798
         $call_back_func = $create_func
2799
-            ? function ($post, $metabox) {
2799
+            ? function($post, $metabox) {
2800 2800
                 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2801 2801
                 echo EEH_Template::display_template(
2802 2802
                     $metabox['args']['template_path'],
@@ -2806,7 +2806,7 @@  discard block
 block discarded – undo
2806 2806
             }
2807 2807
             : $callback;
2808 2808
         add_meta_box(
2809
-            str_replace('_', '-', $action) . '-mbox',
2809
+            str_replace('_', '-', $action).'-mbox',
2810 2810
             $title,
2811 2811
             $call_back_func,
2812 2812
             $this->_wp_page_slug,
@@ -2898,9 +2898,9 @@  discard block
 block discarded – undo
2898 2898
             : 'espresso-default-admin';
2899 2899
         $template_path                                     = $sidebar
2900 2900
             ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2901
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2901
+            : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2902 2902
         if ($this->request->isAjax()) {
2903
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2903
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2904 2904
         }
2905 2905
         $template_path                                     = ! empty($this->_column_template_path)
2906 2906
             ? $this->_column_template_path : $template_path;
@@ -2940,11 +2940,11 @@  discard block
 block discarded – undo
2940 2940
     public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2941 2941
     {
2942 2942
         // let's generate a default preview action button if there isn't one already present.
2943
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2943
+        $this->_labels['buttons']['buy_now'] = esc_html__(
2944 2944
             'Upgrade to Event Espresso 4 Right Now',
2945 2945
             'event_espresso'
2946 2946
         );
2947
-        $buy_now_url                                   = add_query_arg(
2947
+        $buy_now_url = add_query_arg(
2948 2948
             [
2949 2949
                 'ee_ver'       => 'ee4',
2950 2950
                 'utm_source'   => 'ee4_plugin_admin',
@@ -2964,8 +2964,8 @@  discard block
 block discarded – undo
2964 2964
                 true
2965 2965
             )
2966 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',
2967
+        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2968
+            EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php',
2969 2969
             $this->_template_args,
2970 2970
             true
2971 2971
         );
@@ -3014,7 +3014,7 @@  discard block
 block discarded – undo
3014 3014
         // setup search attributes
3015 3015
         $this->_set_search_attributes();
3016 3016
         $this->_template_args['current_page']     = $this->_wp_page_slug;
3017
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3017
+        $template_path                            = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
3018 3018
         $this->_template_args['table_url']        = $this->request->isAjax()
3019 3019
             ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
3020 3020
             : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
@@ -3022,10 +3022,10 @@  discard block
 block discarded – undo
3022 3022
         $this->_template_args['current_route']    = $this->_req_action;
3023 3023
         $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3024 3024
         $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
3025
-        if (! empty($ajax_sorting_callback)) {
3025
+        if ( ! empty($ajax_sorting_callback)) {
3026 3026
             $sortable_list_table_form_fields = wp_nonce_field(
3027
-                $ajax_sorting_callback . '_nonce',
3028
-                $ajax_sorting_callback . '_nonce',
3027
+                $ajax_sorting_callback.'_nonce',
3028
+                $ajax_sorting_callback.'_nonce',
3029 3029
                 false,
3030 3030
                 false
3031 3031
             );
@@ -3043,20 +3043,20 @@  discard block
 block discarded – undo
3043 3043
             isset($this->_template_args['list_table_hidden_fields'])
3044 3044
                 ? $this->_template_args['list_table_hidden_fields']
3045 3045
                 : '';
3046
-        $nonce_ref                                               = $this->_req_action . '_nonce';
3047
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
3046
+        $nonce_ref = $this->_req_action.'_nonce';
3047
+        $hidden_form_fields .= '<input type="hidden" name="'
3048 3048
                                                                     . $nonce_ref
3049 3049
                                                                     . '" value="'
3050 3050
                                                                     . wp_create_nonce($nonce_ref)
3051 3051
                                                                     . '">';
3052
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
3052
+        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3053 3053
         // display message about search results?
3054 3054
         $search = $this->request->getRequestParam('s');
3055 3055
         $this->_template_args['before_list_table'] .= ! empty($search)
3056
-            ? '<p class="ee-search-results">' . sprintf(
3056
+            ? '<p class="ee-search-results">'.sprintf(
3057 3057
                 esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3058 3058
                 trim($search, '%')
3059
-            ) . '</p>'
3059
+            ).'</p>'
3060 3060
             : '';
3061 3061
         // filter before_list_table template arg
3062 3062
         $this->_template_args['before_list_table'] = apply_filters(
@@ -3090,7 +3090,7 @@  discard block
 block discarded – undo
3090 3090
         // convert to array and filter again
3091 3091
         // arrays are easier to inject new items in a specific location,
3092 3092
         // but would not be backwards compatible, so we have to add a new filter
3093
-        $this->_template_args['after_list_table']   = implode(
3093
+        $this->_template_args['after_list_table'] = implode(
3094 3094
             " \n",
3095 3095
             (array) apply_filters(
3096 3096
                 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
@@ -3137,7 +3137,7 @@  discard block
 block discarded – undo
3137 3137
             $this
3138 3138
         );
3139 3139
         return EEH_Template::display_template(
3140
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3140
+            EE_ADMIN_TEMPLATE.'admin_details_legend.template.php',
3141 3141
             $this->_template_args,
3142 3142
             true
3143 3143
         );
@@ -3246,18 +3246,18 @@  discard block
 block discarded – undo
3246 3246
                 : ''
3247 3247
         );
3248 3248
 
3249
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3249
+        $this->_template_args['after_admin_page_content'] = apply_filters(
3250 3250
             "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3251 3251
             isset($this->_template_args['after_admin_page_content'])
3252 3252
                 ? $this->_template_args['after_admin_page_content']
3253 3253
                 : ''
3254 3254
         );
3255
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3255
+        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3256 3256
 
3257 3257
         if ($this->request->isAjax()) {
3258 3258
             $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3259 3259
                 // $template_path,
3260
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3260
+                EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php',
3261 3261
                 $this->_template_args,
3262 3262
                 true
3263 3263
             );
@@ -3266,7 +3266,7 @@  discard block
 block discarded – undo
3266 3266
         // load settings page wrapper template
3267 3267
         $template_path = $about
3268 3268
             ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3269
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3269
+            : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php';
3270 3270
 
3271 3271
         EEH_Template::display_template($template_path, $this->_template_args);
3272 3272
     }
@@ -3351,12 +3351,12 @@  discard block
 block discarded – undo
3351 3351
         $default_names = ['save', 'save_and_close'];
3352 3352
         $buttons = '';
3353 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) {
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 3360
                 break;
3361 3361
             }
3362 3362
         }
@@ -3396,13 +3396,13 @@  discard block
 block discarded – undo
3396 3396
                 'An error occurred. No action was set for this page\'s form.',
3397 3397
                 'event_espresso'
3398 3398
             );
3399
-            $dev_msg  = $user_msg . "\n"
3399
+            $dev_msg = $user_msg."\n"
3400 3400
                         . sprintf(
3401 3401
                             esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3402 3402
                             __FUNCTION__,
3403 3403
                             __CLASS__
3404 3404
                         );
3405
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3405
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
3406 3406
         }
3407 3407
         // open form
3408 3408
         $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
@@ -3411,9 +3411,9 @@  discard block
 block discarded – undo
3411 3411
                                                              . $route
3412 3412
                                                              . '_event_form" >';
3413 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;
3414
+        $nonce =
3415
+            wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
3416
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
3417 3417
         // add REQUIRED form action
3418 3418
         $hidden_fields = [
3419 3419
             'action' => ['type' => 'hidden', 'value' => $route],
@@ -3426,7 +3426,7 @@  discard block
 block discarded – undo
3426 3426
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3427 3427
         // add fields to form
3428 3428
         foreach ((array) $form_fields as $form_field) {
3429
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3429
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
3430 3430
         }
3431 3431
         // close form
3432 3432
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -3517,10 +3517,10 @@  discard block
 block discarded – undo
3517 3517
         $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3518 3518
         $notices      = EE_Error::get_notices(false);
3519 3519
         // overwrite default success messages //BUT ONLY if overwrite not overridden
3520
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3520
+        if ( ! $override_overwrite || ! empty($notices['errors'])) {
3521 3521
             EE_Error::overwrite_success();
3522 3522
         }
3523
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3523
+        if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3524 3524
             // how many records affected ? more than one record ? or just one ?
3525 3525
             if ($success > 1) {
3526 3526
                 // set plural msg
@@ -3549,7 +3549,7 @@  discard block
 block discarded – undo
3549 3549
             }
3550 3550
         }
3551 3551
         // check that $query_args isn't something crazy
3552
-        if (! is_array($query_args)) {
3552
+        if ( ! is_array($query_args)) {
3553 3553
             $query_args = [];
3554 3554
         }
3555 3555
         /**
@@ -3578,7 +3578,7 @@  discard block
 block discarded – undo
3578 3578
             $redirect_url = admin_url('admin.php');
3579 3579
         }
3580 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) {
3581
+        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3582 3582
             $args_to_merge = [];
3583 3583
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
3584 3584
                 // is there a wp_referer array in our _default_route_query_args property?
@@ -3590,15 +3590,15 @@  discard block
 block discarded – undo
3590 3590
                         }
3591 3591
                         // finally we will override any arguments in the referer with
3592 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 ]);
3593
+                        if (isset($this->_default_route_query_args[$reference])) {
3594
+                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3595 3595
                         } else {
3596
-                            $args_to_merge[ $reference ] = urlencode($value);
3596
+                            $args_to_merge[$reference] = urlencode($value);
3597 3597
                         }
3598 3598
                     }
3599 3599
                     continue;
3600 3600
                 }
3601
-                $args_to_merge[ $query_param ] = $query_value;
3601
+                $args_to_merge[$query_param] = $query_value;
3602 3602
             }
3603 3603
             // now let's merge these arguments but override with what was specifically sent in to the
3604 3604
             // redirect.
@@ -3610,19 +3610,19 @@  discard block
 block discarded – undo
3610 3610
         if (isset($query_args['action'])) {
3611 3611
             // manually generate wp_nonce and merge that with the query vars
3612 3612
             // becuz the wp_nonce_url function wrecks havoc on some vars
3613
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3613
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
3614 3614
         }
3615 3615
         // we're adding some hooks and filters in here for processing any things just before redirects
3616 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);
3617
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
3618 3618
         $redirect_url = apply_filters(
3619
-            'FHEE_redirect_' . $classname . $this->_req_action,
3619
+            'FHEE_redirect_'.$classname.$this->_req_action,
3620 3620
             self::add_query_args_and_nonce($query_args, $redirect_url),
3621 3621
             $query_args
3622 3622
         );
3623 3623
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3624 3624
         if ($this->request->isAjax()) {
3625
-            $default_data                    = [
3625
+            $default_data = [
3626 3626
                 'close'        => true,
3627 3627
                 'redirect_url' => $redirect_url,
3628 3628
                 'where'        => 'main',
@@ -3669,7 +3669,7 @@  discard block
 block discarded – undo
3669 3669
         }
3670 3670
         $this->_template_args['notices'] = EE_Error::get_notices();
3671 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) {
3672
+        if ( ! $this->request->isAjax() || $sticky_notices) {
3673 3673
             $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3674 3674
             $this->_add_transient(
3675 3675
                 $route,
@@ -3709,7 +3709,7 @@  discard block
 block discarded – undo
3709 3709
         $exclude_nonce = false
3710 3710
     ) {
3711 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 ])) {
3712
+        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3713 3713
             throw new EE_Error(
3714 3714
                 sprintf(
3715 3715
                     esc_html__(
@@ -3720,7 +3720,7 @@  discard block
 block discarded – undo
3720 3720
                 )
3721 3721
             );
3722 3722
         }
3723
-        if (! isset($this->_labels['buttons'][ $type ])) {
3723
+        if ( ! isset($this->_labels['buttons'][$type])) {
3724 3724
             throw new EE_Error(
3725 3725
                 sprintf(
3726 3726
                     esc_html__(
@@ -3733,7 +3733,7 @@  discard block
 block discarded – undo
3733 3733
         }
3734 3734
         // finally check user access for this button.
3735 3735
         $has_access = $this->check_user_access($action, true);
3736
-        if (! $has_access) {
3736
+        if ( ! $has_access) {
3737 3737
             return '';
3738 3738
         }
3739 3739
         $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
@@ -3741,11 +3741,11 @@  discard block
 block discarded – undo
3741 3741
             'action' => $action,
3742 3742
         ];
3743 3743
         // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3744
-        if (! empty($extra_request)) {
3744
+        if ( ! empty($extra_request)) {
3745 3745
             $query_args = array_merge($extra_request, $query_args);
3746 3746
         }
3747 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);
3748
+        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3749 3749
     }
3750 3750
 
3751 3751
 
@@ -3771,7 +3771,7 @@  discard block
 block discarded – undo
3771 3771
                 'FHEE__EE_Admin_Page___per_page_screen_options__default',
3772 3772
                 20
3773 3773
             ),
3774
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3774
+            'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3775 3775
         ];
3776 3776
         // ONLY add the screen option if the user has access to it.
3777 3777
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3792,18 +3792,18 @@  discard block
 block discarded – undo
3792 3792
     {
3793 3793
         if ($this->request->requestParamIsSet('wp_screen_options')) {
3794 3794
             check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3795
-            if (! $user = wp_get_current_user()) {
3795
+            if ( ! $user = wp_get_current_user()) {
3796 3796
                 return;
3797 3797
             }
3798 3798
             $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3799
-            if (! $option) {
3799
+            if ( ! $option) {
3800 3800
                 return;
3801 3801
             }
3802
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3802
+            $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3803 3803
             $map_option = $option;
3804 3804
             $option     = str_replace('-', '_', $option);
3805 3805
             switch ($map_option) {
3806
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3806
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3807 3807
                     $max_value = apply_filters(
3808 3808
                         'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3809 3809
                         999,
@@ -3860,13 +3860,13 @@  discard block
 block discarded – undo
3860 3860
     protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3861 3861
     {
3862 3862
         $user_id = get_current_user_id();
3863
-        if (! $skip_route_verify) {
3863
+        if ( ! $skip_route_verify) {
3864 3864
             $this->_verify_route($route);
3865 3865
         }
3866 3866
         // now let's set the string for what kind of transient we're setting
3867 3867
         $transient = $notices
3868
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3869
-            : 'rte_tx_' . $route . '_' . $user_id;
3868
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3869
+            : 'rte_tx_'.$route.'_'.$user_id;
3870 3870
         $data      = $notices ? ['notices' => $data] : $data;
3871 3871
         // is there already a transient for this route?  If there is then let's ADD to that transient
3872 3872
         $existing = is_multisite() && is_network_admin()
@@ -3895,8 +3895,8 @@  discard block
 block discarded – undo
3895 3895
         $user_id   = get_current_user_id();
3896 3896
         $route     = ! $route ? $this->_req_action : $route;
3897 3897
         $transient = $notices
3898
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3899
-            : 'rte_tx_' . $route . '_' . $user_id;
3898
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3899
+            : 'rte_tx_'.$route.'_'.$user_id;
3900 3900
         $data      = is_multisite() && is_network_admin()
3901 3901
             ? get_site_transient($transient)
3902 3902
             : get_transient($transient);
@@ -4127,7 +4127,7 @@  discard block
 block discarded – undo
4127 4127
      */
4128 4128
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4129 4129
     {
4130
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4130
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
4131 4131
     }
4132 4132
 
4133 4133
 
@@ -4140,7 +4140,7 @@  discard block
 block discarded – undo
4140 4140
      */
4141 4141
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4142 4142
     {
4143
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4143
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
4144 4144
     }
4145 4145
 
4146 4146
 
Please login to merge, or discard this patch.
core/services/request/sanitizers/RequestSanitizer.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -4,63 +4,63 @@
 block discarded – undo
4 4
 
5 5
 class RequestSanitizer
6 6
 {
7
-    /**
8
-     * Will sanitize the supplied request parameter based on the specified data type
9
-     *
10
-     * @param mixed  $param     the supplied request parameter
11
-     * @param string $type      the specified data type (default: "string")
12
-     *                          valid values: "bool", "float", "int", "key", "url", or "string"
13
-     * @param bool   $is_array  if true, then $param will be treated as an array of $type
14
-     * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator
15
-     * @return array|bool|float|int|string
16
-     * @since 4.10.14.p
17
-     */
18
-    public function clean($param, $type = 'string', $is_array = false, $delimiter = '')
19
-    {
20
-        if ($delimiter !== '' && is_string($param)) {
21
-            $param = explode($delimiter, $param);
22
-            // unset the delimiter else this function will recurse forever when we loop over the array of results
23
-            $delimiter = '';
24
-        }
25
-        // check if we are getting an improperly typed array and correct
26
-        $is_array = $is_array || is_array($param);
27
-        if ($is_array) {
28
-            $values = [];
29
-            foreach ((array) $param as $key => $value) {
30
-                $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter);
31
-            }
32
-            return $values;
33
-        }
34
-        return $this->sanitizeParam($param, $type);
35
-    }
7
+	/**
8
+	 * Will sanitize the supplied request parameter based on the specified data type
9
+	 *
10
+	 * @param mixed  $param     the supplied request parameter
11
+	 * @param string $type      the specified data type (default: "string")
12
+	 *                          valid values: "bool", "float", "int", "key", "url", or "string"
13
+	 * @param bool   $is_array  if true, then $param will be treated as an array of $type
14
+	 * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator
15
+	 * @return array|bool|float|int|string
16
+	 * @since 4.10.14.p
17
+	 */
18
+	public function clean($param, $type = 'string', $is_array = false, $delimiter = '')
19
+	{
20
+		if ($delimiter !== '' && is_string($param)) {
21
+			$param = explode($delimiter, $param);
22
+			// unset the delimiter else this function will recurse forever when we loop over the array of results
23
+			$delimiter = '';
24
+		}
25
+		// check if we are getting an improperly typed array and correct
26
+		$is_array = $is_array || is_array($param);
27
+		if ($is_array) {
28
+			$values = [];
29
+			foreach ((array) $param as $key => $value) {
30
+				$values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter);
31
+			}
32
+			return $values;
33
+		}
34
+		return $this->sanitizeParam($param, $type);
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     * @param mixed  $param
40
-     * @param string $type
41
-     * @return array|float|int|mixed|string|string[]|null
42
-     * @since   4.10.20.p
43
-     */
44
-    public function sanitizeParam($param, $type = 'string')
45
-    {
46
-        switch ($type) {
47
-            case 'bool':
48
-                return filter_var($param, FILTER_VALIDATE_BOOLEAN);
49
-            case 'float':
50
-                return (float) $param;
51
-            case 'fqcn':
52
-                return preg_replace('[^\\\w\d]', '', $param);
53
-            case 'int':
54
-                return (int) $param;
55
-            case 'key':
56
-                return sanitize_key($param);
57
-            case 'title':
58
-                return sanitize_title($param);
59
-            case 'url':
60
-                return esc_url_raw($param);
61
-            case 'string':
62
-            default:
63
-                return sanitize_text_field($param);
64
-        }
65
-    }
38
+	/**
39
+	 * @param mixed  $param
40
+	 * @param string $type
41
+	 * @return array|float|int|mixed|string|string[]|null
42
+	 * @since   4.10.20.p
43
+	 */
44
+	public function sanitizeParam($param, $type = 'string')
45
+	{
46
+		switch ($type) {
47
+			case 'bool':
48
+				return filter_var($param, FILTER_VALIDATE_BOOLEAN);
49
+			case 'float':
50
+				return (float) $param;
51
+			case 'fqcn':
52
+				return preg_replace('[^\\\w\d]', '', $param);
53
+			case 'int':
54
+				return (int) $param;
55
+			case 'key':
56
+				return sanitize_key($param);
57
+			case 'title':
58
+				return sanitize_title($param);
59
+			case 'url':
60
+				return esc_url_raw($param);
61
+			case 'string':
62
+			default:
63
+				return sanitize_text_field($param);
64
+		}
65
+	}
66 66
 }
Please login to merge, or discard this patch.
admin/extend/messages/espresso_events_Messages_Hooks_Extend.class.php 2 patches
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -15,282 +15,282 @@
 block discarded – undo
15 15
 class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * @var Messages_Admin_Page
20
-     */
21
-    protected $_page_object;
22
-
23
-
24
-    /**
25
-     * espresso_events_Messages_Hooks_Extend constructor.
26
-     *
27
-     * @param EE_Admin_Page $admin_page
28
-     * @throws EE_Error
29
-     */
30
-    public function __construct(EE_Admin_Page $admin_page)
31
-    {
32
-        /**
33
-         * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
34
-         */
35
-        if (
36
-            ! EE_Registry::instance()->CAP->current_user_can(
37
-                'ee_edit_messages',
38
-                'messages_events_editor_metabox'
39
-            )
40
-        ) {
41
-            return;
42
-        }
43
-        add_filter(
44
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
45
-            [$this, 'caf_updates'],
46
-            10
47
-        );
48
-        add_action(
49
-            'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
50
-            [$this, 'duplicate_custom_message_settings'],
51
-            10,
52
-            2
53
-        );
54
-        parent::__construct($admin_page);
55
-    }
56
-
57
-
58
-    /**
59
-     * extending the properties set in espresso_events_Messages_Hooks
60
-     *
61
-     * @access protected
62
-     * @return void
63
-     */
64
-    protected function _extend_properties()
65
-    {
66
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
67
-        $this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom'];
68
-        $this->_metaboxes = [
69
-            0 => [
70
-                'page_route' => ['edit', 'create_new'],
71
-                'func'       => 'messages_metabox',
72
-                'label'      => esc_html__('Notifications', 'event_espresso'),
73
-                'priority'   => 'high',
74
-            ],
75
-        ];
76
-
77
-        // see explanation for layout in EE_Admin_Hooks
78
-        $this->_scripts_styles = [
79
-            'registers' => [
80
-                'events_msg_admin'     => [
81
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
82
-                    'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'],
83
-                ],
84
-                'events_msg_admin_css' => [
85
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
86
-                    'type' => 'css',
87
-                ],
88
-            ],
89
-            'enqueues'  => [
90
-                'events_msg_admin'     => ['edit', 'create_new'],
91
-                'events_msg_admin_css' => ['edit', 'create_new'],
92
-            ],
93
-        ];
94
-    }
95
-
96
-
97
-    public function caf_updates($update_callbacks)
98
-    {
99
-        $update_callbacks[] = [$this, 'attach_evt_message_templates'];
100
-        return $update_callbacks;
101
-    }
102
-
103
-
104
-    /**
105
-     * Handles attaching Message Templates to the Event on save.
106
-     *
107
-     * @param EE_Event $event EE event object
108
-     * @param array    $data  The request data from the form
109
-     * @return bool success or fail
110
-     * @throws EE_Error
111
-     * @throws ReflectionException
112
-     */
113
-    public function attach_evt_message_templates($event, $data)
114
-    {
115
-        // first we remove all existing relations on the Event for message types.
116
-        $event->_remove_relations('Message_Template_Group');
117
-        // now let's just loop through the selected templates and add relations!
118
-        if (isset($data['event_message_templates_relation'])) {
119
-            foreach ($data['event_message_templates_relation'] as $grp_ID) {
120
-                $event->_add_relation_to($grp_ID, 'Message_Template_Group');
121
-            }
122
-        }
123
-        // now save
124
-        return $event->save();
125
-    }
126
-
127
-
128
-    /**
129
-     * @param $event
130
-     * @param $callback_args
131
-     * @return string
132
-     * @throws EE_Error
133
-     * @throws ReflectionException
134
-     */
135
-    public function messages_metabox($event, $callback_args)
136
-    {
137
-        // convert 'evt_id' to 'EVT_ID'
138
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
139
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
140
-        $EVT_ID = $this->request->getRequestParam('evt_id', $EVT_ID, 'int');
141
-        $this->request->setRequestParam('EVT_ID', $EVT_ID);
142
-
143
-        // get the active messengers (b/c messenger objects have the active message templates)
144
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
145
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
146
-        $active_messengers        = $message_resource_manager->active_messengers();
147
-        $tabs                     = [];
148
-
149
-        // empty messengers?
150
-        // Note message types will always have at least one available because every messenger has a default message type
151
-        // associated with it (payment) if no other message types are selected.
152
-        if (empty($active_messengers)) {
153
-            $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
154
-                ['action' => 'settings'],
155
-                EE_MSG_ADMIN_URL
156
-            );
157
-            $error_msg        = sprintf(
158
-                esc_html__(
159
-                    'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
160
-                    'event_espresso'
161
-                ),
162
-                '<strong>',
163
-                '</strong>',
164
-                '<a href="' . $msg_activate_url . '">',
165
-                '</a>'
166
-            );
167
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
168
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
169
-
170
-            echo $error_content;
171
-            echo $internal_content;
172
-            return '';
173
-        }
174
-
175
-        // get content for active messengers
176
-        foreach ($active_messengers as $name => $messenger) {
177
-            // first check if there are any active message types for this messenger.
178
-            $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
179
-            if (empty($active_mts)) {
180
-                continue;
181
-            }
182
-
183
-            $tab_content = $messenger->get_messenger_admin_page_content(
184
-                'events',
185
-                'edit',
186
-                ['event' => $EVT_ID]
187
-            );
188
-
189
-            if (! empty($tab_content)) {
190
-                $tabs[ $name ] = $tab_content;
191
-            }
192
-        }
193
-
194
-
195
-        // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
196
-        $tabbed_content = EEH_Tabbed_Content::display($tabs);
197
-        if ($tabbed_content instanceof WP_Error) {
198
-            $tabbed_content = $tabbed_content->get_error_message();
199
-        }
200
-
201
-        $notices = '
18
+	/**
19
+	 * @var Messages_Admin_Page
20
+	 */
21
+	protected $_page_object;
22
+
23
+
24
+	/**
25
+	 * espresso_events_Messages_Hooks_Extend constructor.
26
+	 *
27
+	 * @param EE_Admin_Page $admin_page
28
+	 * @throws EE_Error
29
+	 */
30
+	public function __construct(EE_Admin_Page $admin_page)
31
+	{
32
+		/**
33
+		 * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
34
+		 */
35
+		if (
36
+			! EE_Registry::instance()->CAP->current_user_can(
37
+				'ee_edit_messages',
38
+				'messages_events_editor_metabox'
39
+			)
40
+		) {
41
+			return;
42
+		}
43
+		add_filter(
44
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
45
+			[$this, 'caf_updates'],
46
+			10
47
+		);
48
+		add_action(
49
+			'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
50
+			[$this, 'duplicate_custom_message_settings'],
51
+			10,
52
+			2
53
+		);
54
+		parent::__construct($admin_page);
55
+	}
56
+
57
+
58
+	/**
59
+	 * extending the properties set in espresso_events_Messages_Hooks
60
+	 *
61
+	 * @access protected
62
+	 * @return void
63
+	 */
64
+	protected function _extend_properties()
65
+	{
66
+		define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
67
+		$this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom'];
68
+		$this->_metaboxes = [
69
+			0 => [
70
+				'page_route' => ['edit', 'create_new'],
71
+				'func'       => 'messages_metabox',
72
+				'label'      => esc_html__('Notifications', 'event_espresso'),
73
+				'priority'   => 'high',
74
+			],
75
+		];
76
+
77
+		// see explanation for layout in EE_Admin_Hooks
78
+		$this->_scripts_styles = [
79
+			'registers' => [
80
+				'events_msg_admin'     => [
81
+					'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
82
+					'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'],
83
+				],
84
+				'events_msg_admin_css' => [
85
+					'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
86
+					'type' => 'css',
87
+				],
88
+			],
89
+			'enqueues'  => [
90
+				'events_msg_admin'     => ['edit', 'create_new'],
91
+				'events_msg_admin_css' => ['edit', 'create_new'],
92
+			],
93
+		];
94
+	}
95
+
96
+
97
+	public function caf_updates($update_callbacks)
98
+	{
99
+		$update_callbacks[] = [$this, 'attach_evt_message_templates'];
100
+		return $update_callbacks;
101
+	}
102
+
103
+
104
+	/**
105
+	 * Handles attaching Message Templates to the Event on save.
106
+	 *
107
+	 * @param EE_Event $event EE event object
108
+	 * @param array    $data  The request data from the form
109
+	 * @return bool success or fail
110
+	 * @throws EE_Error
111
+	 * @throws ReflectionException
112
+	 */
113
+	public function attach_evt_message_templates($event, $data)
114
+	{
115
+		// first we remove all existing relations on the Event for message types.
116
+		$event->_remove_relations('Message_Template_Group');
117
+		// now let's just loop through the selected templates and add relations!
118
+		if (isset($data['event_message_templates_relation'])) {
119
+			foreach ($data['event_message_templates_relation'] as $grp_ID) {
120
+				$event->_add_relation_to($grp_ID, 'Message_Template_Group');
121
+			}
122
+		}
123
+		// now save
124
+		return $event->save();
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param $event
130
+	 * @param $callback_args
131
+	 * @return string
132
+	 * @throws EE_Error
133
+	 * @throws ReflectionException
134
+	 */
135
+	public function messages_metabox($event, $callback_args)
136
+	{
137
+		// convert 'evt_id' to 'EVT_ID'
138
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
139
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
140
+		$EVT_ID = $this->request->getRequestParam('evt_id', $EVT_ID, 'int');
141
+		$this->request->setRequestParam('EVT_ID', $EVT_ID);
142
+
143
+		// get the active messengers (b/c messenger objects have the active message templates)
144
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
145
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
146
+		$active_messengers        = $message_resource_manager->active_messengers();
147
+		$tabs                     = [];
148
+
149
+		// empty messengers?
150
+		// Note message types will always have at least one available because every messenger has a default message type
151
+		// associated with it (payment) if no other message types are selected.
152
+		if (empty($active_messengers)) {
153
+			$msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
154
+				['action' => 'settings'],
155
+				EE_MSG_ADMIN_URL
156
+			);
157
+			$error_msg        = sprintf(
158
+				esc_html__(
159
+					'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
160
+					'event_espresso'
161
+				),
162
+				'<strong>',
163
+				'</strong>',
164
+				'<a href="' . $msg_activate_url . '">',
165
+				'</a>'
166
+			);
167
+			$error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
168
+			$internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
169
+
170
+			echo $error_content;
171
+			echo $internal_content;
172
+			return '';
173
+		}
174
+
175
+		// get content for active messengers
176
+		foreach ($active_messengers as $name => $messenger) {
177
+			// first check if there are any active message types for this messenger.
178
+			$active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
179
+			if (empty($active_mts)) {
180
+				continue;
181
+			}
182
+
183
+			$tab_content = $messenger->get_messenger_admin_page_content(
184
+				'events',
185
+				'edit',
186
+				['event' => $EVT_ID]
187
+			);
188
+
189
+			if (! empty($tab_content)) {
190
+				$tabs[ $name ] = $tab_content;
191
+			}
192
+		}
193
+
194
+
195
+		// we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
196
+		$tabbed_content = EEH_Tabbed_Content::display($tabs);
197
+		if ($tabbed_content instanceof WP_Error) {
198
+			$tabbed_content = $tabbed_content->get_error_message();
199
+		}
200
+
201
+		$notices = '
202 202
 	<div id="espresso-ajax-loading" class="ajax-loader-grey">
203 203
 		<span class="ee-spinner ee-spin"></span>
204 204
 		<span class="hidden">' . esc_html__('loading...', 'event_espresso') . '</span>
205 205
 	</div>
206 206
 	<div class="ee-notices"></div>';
207 207
 
208
-        if (defined('DOING_AJAX')) {
209
-            return $tabbed_content;
210
-        }
211
-
212
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
213
-        echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
214
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
215
-        return '';
216
-    }
217
-
218
-
219
-    /**
220
-     * Ajax callback for ee_msgs_create_new_custom ajax request.
221
-     * Takes incoming GRP_ID and name and description values from ajax request
222
-     * to create a new custom template based off of the incoming GRP_ID.
223
-     *
224
-     * @access public
225
-     * @return void
226
-     * @throws EE_Error
227
-     */
228
-    public function create_new_custom()
229
-    {
230
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
231
-            wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso'));
232
-        }
233
-
234
-        /** @var RequestInterface $request */
235
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
236
-
237
-        // let's clean up the request data a bit for downstream usage of name and description.
238
-        $templateName = $this->request->getRequestParam('custom_template_args[MTP_name]', '');
239
-        $request->setRequestParam('templateName', $templateName);
240
-        $templateDescription = $this->request->getRequestParam('custom_template_args[MTP_description]', '');
241
-        $request->setRequestParam('templateDescription', $templateDescription);
242
-
243
-        // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
244
-        $this->_set_page_object();
245
-
246
-        // is this a template switch if so EE_Admin_Page child needs this object
247
-        $this->_page_object->set_hook_object($this);
248
-
249
-        $this->_page_object->add_message_template(
250
-            $this->request->getRequestParam('messageType', ''),
251
-            $this->request->getRequestParam('messenger', ''),
252
-            $this->request->getRequestParam('group_ID', 0, 'int')
253
-        );
254
-    }
255
-
256
-
257
-    public function create_new_admin_footer()
258
-    {
259
-        $this->edit_admin_footer();
260
-    }
261
-
262
-
263
-    /**
264
-     * This is the dynamic method for this class
265
-     * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
266
-     *
267
-     * @return void
268
-     * @throws DomainException
269
-     */
270
-    public function edit_admin_footer()
271
-    {
272
-        EEH_Template::display_template(
273
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
274
-        );
275
-    }
276
-
277
-
278
-    /**
279
-     * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
280
-     * the assigned custom message templates.
281
-     *
282
-     * @param EE_Event $new_event
283
-     * @param EE_Event $original_event
284
-     * @throws EE_Error
285
-     * @throws ReflectionException
286
-     */
287
-    public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
288
-    {
289
-        $message_template_groups = $original_event->get_many_related('Message_Template_Group');
290
-        foreach ($message_template_groups as $message_template_group) {
291
-            $new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
292
-        }
293
-        // save new event
294
-        $new_event->save();
295
-    }
208
+		if (defined('DOING_AJAX')) {
209
+			return $tabbed_content;
210
+		}
211
+
212
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
213
+		echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
214
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
215
+		return '';
216
+	}
217
+
218
+
219
+	/**
220
+	 * Ajax callback for ee_msgs_create_new_custom ajax request.
221
+	 * Takes incoming GRP_ID and name and description values from ajax request
222
+	 * to create a new custom template based off of the incoming GRP_ID.
223
+	 *
224
+	 * @access public
225
+	 * @return void
226
+	 * @throws EE_Error
227
+	 */
228
+	public function create_new_custom()
229
+	{
230
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
231
+			wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso'));
232
+		}
233
+
234
+		/** @var RequestInterface $request */
235
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
236
+
237
+		// let's clean up the request data a bit for downstream usage of name and description.
238
+		$templateName = $this->request->getRequestParam('custom_template_args[MTP_name]', '');
239
+		$request->setRequestParam('templateName', $templateName);
240
+		$templateDescription = $this->request->getRequestParam('custom_template_args[MTP_description]', '');
241
+		$request->setRequestParam('templateDescription', $templateDescription);
242
+
243
+		// set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
244
+		$this->_set_page_object();
245
+
246
+		// is this a template switch if so EE_Admin_Page child needs this object
247
+		$this->_page_object->set_hook_object($this);
248
+
249
+		$this->_page_object->add_message_template(
250
+			$this->request->getRequestParam('messageType', ''),
251
+			$this->request->getRequestParam('messenger', ''),
252
+			$this->request->getRequestParam('group_ID', 0, 'int')
253
+		);
254
+	}
255
+
256
+
257
+	public function create_new_admin_footer()
258
+	{
259
+		$this->edit_admin_footer();
260
+	}
261
+
262
+
263
+	/**
264
+	 * This is the dynamic method for this class
265
+	 * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
266
+	 *
267
+	 * @return void
268
+	 * @throws DomainException
269
+	 */
270
+	public function edit_admin_footer()
271
+	{
272
+		EEH_Template::display_template(
273
+			EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
274
+		);
275
+	}
276
+
277
+
278
+	/**
279
+	 * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
280
+	 * the assigned custom message templates.
281
+	 *
282
+	 * @param EE_Event $new_event
283
+	 * @param EE_Event $original_event
284
+	 * @throws EE_Error
285
+	 * @throws ReflectionException
286
+	 */
287
+	public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
288
+	{
289
+		$message_template_groups = $original_event->get_many_related('Message_Template_Group');
290
+		foreach ($message_template_groups as $message_template_group) {
291
+			$new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
292
+		}
293
+		// save new event
294
+		$new_event->save();
295
+	}
296 296
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     protected function _extend_properties()
65 65
     {
66
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
66
+        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/');
67 67
         $this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom'];
68 68
         $this->_metaboxes = [
69 69
             0 => [
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
         $this->_scripts_styles = [
79 79
             'registers' => [
80 80
                 'events_msg_admin'     => [
81
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
81
+                    'url'     => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js',
82 82
                     'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'],
83 83
                 ],
84 84
                 'events_msg_admin_css' => [
85
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
85
+                    'url'  => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css',
86 86
                     'type' => 'css',
87 87
                 ],
88 88
             ],
@@ -154,18 +154,18 @@  discard block
 block discarded – undo
154 154
                 ['action' => 'settings'],
155 155
                 EE_MSG_ADMIN_URL
156 156
             );
157
-            $error_msg        = sprintf(
157
+            $error_msg = sprintf(
158 158
                 esc_html__(
159 159
                     'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
160 160
                     'event_espresso'
161 161
                 ),
162 162
                 '<strong>',
163 163
                 '</strong>',
164
-                '<a href="' . $msg_activate_url . '">',
164
+                '<a href="'.$msg_activate_url.'">',
165 165
                 '</a>'
166 166
             );
167
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
168
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
167
+            $error_content    = '<div class="error"><p>'.$error_msg.'</p></div>';
168
+            $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>';
169 169
 
170 170
             echo $error_content;
171 171
             echo $internal_content;
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
                 ['event' => $EVT_ID]
187 187
             );
188 188
 
189
-            if (! empty($tab_content)) {
190
-                $tabs[ $name ] = $tab_content;
189
+            if ( ! empty($tab_content)) {
190
+                $tabs[$name] = $tab_content;
191 191
             }
192 192
         }
193 193
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
         $notices = '
202 202
 	<div id="espresso-ajax-loading" class="ajax-loader-grey">
203 203
 		<span class="ee-spinner ee-spin"></span>
204
-		<span class="hidden">' . esc_html__('loading...', 'event_espresso') . '</span>
204
+		<span class="hidden">' . esc_html__('loading...', 'event_espresso').'</span>
205 205
 	</div>
206 206
 	<div class="ee-notices"></div>';
207 207
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         }
211 211
 
212 212
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
213
-        echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
213
+        echo $notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>';
214 214
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
215 215
         return '';
216 216
     }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      */
228 228
     public function create_new_custom()
229 229
     {
230
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
230
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
231 231
             wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso'));
232 232
         }
233 233
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     public function edit_admin_footer()
271 271
     {
272 272
         EEH_Template::display_template(
273
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
273
+            EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php'
274 274
         );
275 275
     }
276 276
 
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4473 added lines, -4473 removed lines patch added patch discarded remove patch
@@ -17,2642 +17,2642 @@  discard block
 block discarded – undo
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19 19
 
20
-    /**
21
-     * @var EE_Message_Resource_Manager $_message_resource_manager
22
-     */
23
-    protected $_message_resource_manager;
24
-
25
-    /**
26
-     * @var string
27
-     */
28
-    protected $_active_message_type_name = '';
29
-
30
-    /**
31
-     * @var string
32
-     */
33
-    protected $_active_messenger_name = '';
34
-
35
-    /**
36
-     * @var EE_messenger $_active_messenger
37
-     */
38
-    protected $_active_messenger;
39
-
40
-    protected $_activate_meta_box_type;
41
-
42
-    protected $_current_message_meta_box;
43
-
44
-    protected $_current_message_meta_box_object;
45
-
46
-    protected $_context_switcher;
47
-
48
-    protected $_shortcodes           = [];
49
-
50
-    protected $_active_messengers    = [];
51
-
52
-    protected $_active_message_types = [];
53
-
54
-    /**
55
-     * @var EE_Message_Template_Group $_message_template_group
56
-     */
57
-    protected $_message_template_group;
58
-
59
-    protected $_m_mt_settings = [];
60
-
61
-
62
-    /**
63
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
64
-     * IF there is no group then it gets automatically set to the Default template pack.
65
-     *
66
-     * @since 4.5.0
67
-     *
68
-     * @var EE_Messages_Template_Pack
69
-     */
70
-    protected $_template_pack;
71
-
72
-
73
-    /**
74
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
75
-     * group is.  If there is no group then it automatically gets set to default.
76
-     *
77
-     * @since 4.5.0
78
-     *
79
-     * @var string
80
-     */
81
-    protected $_variation;
82
-
83
-
84
-    /**
85
-     * @param bool $routing
86
-     * @throws EE_Error
87
-     * @throws ReflectionException
88
-     */
89
-    public function __construct($routing = true)
90
-    {
91
-        // make sure messages autoloader is running
92
-        EED_Messages::set_autoloaders();
93
-        parent::__construct($routing);
94
-    }
95
-
96
-
97
-    /**
98
-     * @throws EE_Error
99
-     * @throws ReflectionException
100
-     */
101
-    protected function _init_page_props()
102
-    {
103
-        $this->page_slug        = EE_MSG_PG_SLUG;
104
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
105
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
106
-        $this->_admin_base_path = EE_MSG_ADMIN;
107
-
108
-        $this->_active_messenger_name    = $this->request->getRequestParam('messenger', '');
109
-        $this->_active_message_type_name = $this->request->getRequestParam('message_type', '');
110
-
111
-        $this->_load_message_resource_manager();
112
-    }
113
-
114
-
115
-    /**
116
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
117
-     *
118
-     * @throws EE_Error
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidInterfaceException
121
-     * @throws InvalidArgumentException
122
-     * @throws ReflectionException
123
-     */
124
-    protected function _load_message_resource_manager()
125
-    {
126
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
127
-    }
128
-
129
-
130
-    /**
131
-     * @return array
132
-     * @throws EE_Error
133
-     * @throws InvalidArgumentException
134
-     * @throws InvalidDataTypeException
135
-     * @throws InvalidInterfaceException
136
-     * @deprecated 4.9.9.rc.014
137
-     */
138
-    public function get_messengers_for_list_table()
139
-    {
140
-        EE_Error::doing_it_wrong(
141
-            __METHOD__,
142
-            sprintf(
143
-                esc_html__(
144
-                    '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',
145
-                    'event_espresso'
146
-                ),
147
-                'Messages_Admin_Page::get_messengers_select_input()'
148
-            ),
149
-            '4.9.9.rc.014'
150
-        );
151
-
152
-        $m_values          = [];
153
-        $active_messengers = EEM_Message::instance()->get_all(['group_by' => 'MSG_messenger']);
154
-        // setup messengers for selects
155
-        $i = 1;
156
-        foreach ($active_messengers as $active_messenger) {
157
-            if ($active_messenger instanceof EE_Message) {
158
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
159
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
160
-                $i++;
161
-            }
162
-        }
163
-
164
-        return $m_values;
165
-    }
166
-
167
-
168
-    /**
169
-     * @return array
170
-     * @throws EE_Error
171
-     * @throws InvalidArgumentException
172
-     * @throws InvalidDataTypeException
173
-     * @throws InvalidInterfaceException
174
-     * @deprecated 4.9.9.rc.014
175
-     */
176
-    public function get_message_types_for_list_table()
177
-    {
178
-        EE_Error::doing_it_wrong(
179
-            __METHOD__,
180
-            sprintf(
181
-                esc_html__(
182
-                    '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',
183
-                    'event_espresso'
184
-                ),
185
-                'Messages_Admin_Page::get_message_types_select_input()'
186
-            ),
187
-            '4.9.9.rc.014'
188
-        );
189
-
190
-        $mt_values       = [];
191
-        $active_messages = EEM_Message::instance()->get_all(['group_by' => 'MSG_message_type']);
192
-        $i               = 1;
193
-        foreach ($active_messages as $active_message) {
194
-            if ($active_message instanceof EE_Message) {
195
-                $mt_values[ $i ]['id']   = $active_message->message_type();
196
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
197
-                $i++;
198
-            }
199
-        }
200
-
201
-        return $mt_values;
202
-    }
203
-
204
-
205
-    /**
206
-     * @return array
207
-     * @throws EE_Error
208
-     * @throws InvalidArgumentException
209
-     * @throws InvalidDataTypeException
210
-     * @throws InvalidInterfaceException
211
-     * @deprecated 4.9.9.rc.014
212
-     */
213
-    public function get_contexts_for_message_types_for_list_table()
214
-    {
215
-        EE_Error::doing_it_wrong(
216
-            __METHOD__,
217
-            sprintf(
218
-                esc_html__(
219
-                    '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',
220
-                    'event_espresso'
221
-                ),
222
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
223
-            ),
224
-            '4.9.9.rc.014'
225
-        );
226
-
227
-        $contexts                = [];
228
-        $active_message_contexts = EEM_Message::instance()->get_all(['group_by' => 'MSG_context']);
229
-        foreach ($active_message_contexts as $active_message) {
230
-            if ($active_message instanceof EE_Message) {
231
-                $message_type = $active_message->message_type_object();
232
-                if ($message_type instanceof EE_message_type) {
233
-                    $message_type_contexts = $message_type->get_contexts();
234
-                    foreach ($message_type_contexts as $context => $context_details) {
235
-                        $contexts[ $context ] = $context_details['label'];
236
-                    }
237
-                }
238
-            }
239
-        }
240
-
241
-        return $contexts;
242
-    }
243
-
244
-
245
-    /**
246
-     * Generate select input with provided messenger options array.
247
-     *
248
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
249
-     *                                 labels.
250
-     * @return string
251
-     * @throws EE_Error
252
-     */
253
-    public function get_messengers_select_input($messenger_options)
254
-    {
255
-        // if empty or just one value then just return an empty string
256
-        if (
257
-            empty($messenger_options)
258
-            || ! is_array($messenger_options)
259
-            || count($messenger_options) === 1
260
-        ) {
261
-            return '';
262
-        }
263
-        // merge in default
264
-        $messenger_options = array_merge(
265
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
266
-            $messenger_options
267
-        );
268
-        $input             = new EE_Select_Input(
269
-            $messenger_options,
270
-            [
271
-                'html_name'  => 'ee_messenger_filter_by',
272
-                'html_id'    => 'ee_messenger_filter_by',
273
-                'html_class' => 'wide',
274
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
275
-            ]
276
-        );
277
-
278
-        return $input->get_html_for_input();
279
-    }
280
-
281
-
282
-    /**
283
-     * Generate select input with provided message type options array.
284
-     *
285
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
286
-     *                                    message type labels
287
-     * @return string
288
-     * @throws EE_Error
289
-     */
290
-    public function get_message_types_select_input($message_type_options)
291
-    {
292
-        // if empty or count of options is 1 then just return an empty string
293
-        if (
294
-            empty($message_type_options)
295
-            || ! is_array($message_type_options)
296
-            || count($message_type_options) === 1
297
-        ) {
298
-            return '';
299
-        }
300
-        // merge in default
301
-        $message_type_options = array_merge(
302
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
303
-            $message_type_options
304
-        );
305
-        $input                = new EE_Select_Input(
306
-            $message_type_options,
307
-            [
308
-                'html_name'  => 'ee_message_type_filter_by',
309
-                'html_id'    => 'ee_message_type_filter_by',
310
-                'html_class' => 'wide',
311
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
312
-            ]
313
-        );
314
-
315
-        return $input->get_html_for_input();
316
-    }
317
-
318
-
319
-    /**
320
-     * Generate select input with provide message type contexts array.
321
-     *
322
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
323
-     *                               context label.
324
-     * @return string
325
-     * @throws EE_Error
326
-     */
327
-    public function get_contexts_for_message_types_select_input($context_options)
328
-    {
329
-        // if empty or count of options is one then just return empty string
330
-        if (
331
-            empty($context_options)
332
-            || ! is_array($context_options)
333
-            || count($context_options) === 1
334
-        ) {
335
-            return '';
336
-        }
337
-        // merge in default
338
-        $context_options = array_merge(
339
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
340
-            $context_options
341
-        );
342
-        $input           = new EE_Select_Input(
343
-            $context_options,
344
-            [
345
-                'html_name'  => 'ee_context_filter_by',
346
-                'html_id'    => 'ee_context_filter_by',
347
-                'html_class' => 'wide',
348
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
349
-            ]
350
-        );
351
-
352
-        return $input->get_html_for_input();
353
-    }
354
-
355
-
356
-    protected function _ajax_hooks()
357
-    {
358
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
359
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
360
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
361
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
362
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
363
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
364
-    }
365
-
366
-
367
-    protected function _define_page_props()
368
-    {
369
-        $this->_admin_page_title = $this->page_label;
370
-        $this->_labels           = [
371
-            'buttons'    => [
372
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
373
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
374
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
375
-            ],
376
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
377
-        ];
378
-    }
379
-
380
-
381
-    /**
382
-     *        an array for storing key => value pairs of request actions and their corresponding methods
383
-     *
384
-     * @access protected
385
-     * @return void
386
-     */
387
-    protected function _set_page_routes()
388
-    {
389
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
390
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
391
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
392
-
393
-        $this->_page_routes = [
394
-            'default'                          => [
395
-                'func'       => '_message_queue_list_table',
396
-                'capability' => 'ee_read_global_messages',
397
-            ],
398
-            'global_mtps'                      => [
399
-                'func'       => '_ee_default_messages_overview_list_table',
400
-                'capability' => 'ee_read_global_messages',
401
-            ],
402
-            'custom_mtps'                      => [
403
-                'func'       => '_custom_mtps_preview',
404
-                'capability' => 'ee_read_messages',
405
-            ],
406
-            'add_new_message_template'         => [
407
-                'func'       => '_add_message_template',
408
-                'capability' => 'ee_edit_messages',
409
-                'noheader'   => true,
410
-            ],
411
-            'edit_message_template'            => [
412
-                'func'       => '_edit_message_template',
413
-                'capability' => 'ee_edit_message',
414
-                'obj_id'     => $GRP_ID,
415
-            ],
416
-            'preview_message'                  => [
417
-                'func'               => '_preview_message',
418
-                'capability'         => 'ee_read_message',
419
-                'obj_id'             => $GRP_ID,
420
-                'noheader'           => true,
421
-                'headers_sent_route' => 'display_preview_message',
422
-            ],
423
-            'display_preview_message'          => [
424
-                'func'       => '_display_preview_message',
425
-                'capability' => 'ee_read_message',
426
-                'obj_id'     => $GRP_ID,
427
-            ],
428
-            'insert_message_template'          => [
429
-                'func'       => '_insert_or_update_message_template',
430
-                'capability' => 'ee_edit_messages',
431
-                'args'       => ['new' => true],
432
-                'noheader'   => true,
433
-            ],
434
-            'update_message_template'          => [
435
-                'func'       => '_insert_or_update_message_template',
436
-                'capability' => 'ee_edit_message',
437
-                'obj_id'     => $GRP_ID,
438
-                'args'       => ['new' => false],
439
-                'noheader'   => true,
440
-            ],
441
-            'trash_message_template'           => [
442
-                'func'       => '_trash_or_restore_message_template',
443
-                'capability' => 'ee_delete_message',
444
-                'obj_id'     => $GRP_ID,
445
-                'args'       => ['trash' => true, 'all' => true],
446
-                'noheader'   => true,
447
-            ],
448
-            'trash_message_template_context'   => [
449
-                'func'       => '_trash_or_restore_message_template',
450
-                'capability' => 'ee_delete_message',
451
-                'obj_id'     => $GRP_ID,
452
-                'args'       => ['trash' => true],
453
-                'noheader'   => true,
454
-            ],
455
-            'restore_message_template'         => [
456
-                'func'       => '_trash_or_restore_message_template',
457
-                'capability' => 'ee_delete_message',
458
-                'obj_id'     => $GRP_ID,
459
-                'args'       => ['trash' => false, 'all' => true],
460
-                'noheader'   => true,
461
-            ],
462
-            'restore_message_template_context' => [
463
-                'func'       => '_trash_or_restore_message_template',
464
-                'capability' => 'ee_delete_message',
465
-                'obj_id'     => $GRP_ID,
466
-                'args'       => ['trash' => false],
467
-                'noheader'   => true,
468
-            ],
469
-            'delete_message_template'          => [
470
-                'func'       => '_delete_message_template',
471
-                'capability' => 'ee_delete_message',
472
-                'obj_id'     => $GRP_ID,
473
-                'noheader'   => true,
474
-            ],
475
-            'reset_to_default'                 => [
476
-                'func'       => '_reset_to_default_template',
477
-                'capability' => 'ee_edit_message',
478
-                'obj_id'     => $GRP_ID,
479
-                'noheader'   => true,
480
-            ],
481
-            'settings'                         => [
482
-                'func'       => '_settings',
483
-                'capability' => 'manage_options',
484
-            ],
485
-            'update_global_settings'           => [
486
-                'func'       => '_update_global_settings',
487
-                'capability' => 'manage_options',
488
-                'noheader'   => true,
489
-            ],
490
-            'generate_now'                     => [
491
-                'func'       => '_generate_now',
492
-                'capability' => 'ee_send_message',
493
-                'noheader'   => true,
494
-            ],
495
-            'generate_and_send_now'            => [
496
-                'func'       => '_generate_and_send_now',
497
-                'capability' => 'ee_send_message',
498
-                'noheader'   => true,
499
-            ],
500
-            'queue_for_resending'              => [
501
-                'func'       => '_queue_for_resending',
502
-                'capability' => 'ee_send_message',
503
-                'noheader'   => true,
504
-            ],
505
-            'send_now'                         => [
506
-                'func'       => '_send_now',
507
-                'capability' => 'ee_send_message',
508
-                'noheader'   => true,
509
-            ],
510
-            'delete_ee_message'                => [
511
-                'func'       => '_delete_ee_messages',
512
-                'capability' => 'ee_delete_messages',
513
-                'noheader'   => true,
514
-            ],
515
-            'delete_ee_messages'               => [
516
-                'func'       => '_delete_ee_messages',
517
-                'capability' => 'ee_delete_messages',
518
-                'noheader'   => true,
519
-                'obj_id'     => $MSG_ID,
520
-            ],
521
-        ];
522
-    }
523
-
524
-
525
-    protected function _set_page_config()
526
-    {
527
-        $this->_page_config = [
528
-            'default'                  => [
529
-                'nav'           => [
530
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
531
-                    'order' => 10,
532
-                ],
533
-                'list_table'    => 'EE_Message_List_Table',
534
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
535
-                'require_nonce' => false,
536
-            ],
537
-            'global_mtps'              => [
538
-                'nav'           => [
539
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
540
-                    'order' => 20,
541
-                ],
542
-                'list_table'    => 'Messages_Template_List_Table',
543
-                'help_tabs'     => [
544
-                    'messages_overview_help_tab'                                => [
545
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
546
-                        'filename' => 'messages_overview',
547
-                    ],
548
-                    'messages_overview_messages_table_column_headings_help_tab' => [
549
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
550
-                        'filename' => 'messages_overview_table_column_headings',
551
-                    ],
552
-                    'messages_overview_messages_filters_help_tab'               => [
553
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
554
-                        'filename' => 'messages_overview_filters',
555
-                    ],
556
-                    'messages_overview_messages_views_help_tab'                 => [
557
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
558
-                        'filename' => 'messages_overview_views',
559
-                    ],
560
-                    'message_overview_message_types_help_tab'                   => [
561
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
562
-                        'filename' => 'messages_overview_types',
563
-                    ],
564
-                    'messages_overview_messengers_help_tab'                     => [
565
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
566
-                        'filename' => 'messages_overview_messengers',
567
-                    ],
568
-                ],
569
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
570
-                // 'help_tour'     => array('Messages_Overview_Help_Tour'),
571
-                'require_nonce' => false,
572
-            ],
573
-            'custom_mtps'              => [
574
-                'nav'           => [
575
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
576
-                    'order' => 30,
577
-                ],
578
-                'help_tabs'     => [],
579
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
580
-                // 'help_tour'     => array(),
581
-                'require_nonce' => false,
582
-            ],
583
-            'add_new_message_template' => [
584
-                'nav'           => [
585
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
586
-                    'order'      => 5,
587
-                    'persistent' => false,
588
-                ],
589
-                'require_nonce' => false,
590
-            ],
591
-            'edit_message_template'    => [
592
-                'labels'        => [
593
-                    'buttons'    => [
594
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
595
-                    ],
596
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
597
-                ],
598
-                'nav'           => [
599
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
600
-                    'order'      => 5,
601
-                    'persistent' => false,
602
-                    'url'        => '',
603
-                ],
604
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
605
-                'has_metaboxes' => true,
606
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
607
-                // 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
608
-                'help_tabs'     => [
609
-                    'edit_message_template'            => [
610
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
611
-                        'callback' => 'edit_message_template_help_tab',
612
-                    ],
613
-                    'message_templates_help_tab'       => [
614
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
615
-                        'filename' => 'messages_templates',
616
-                    ],
617
-                    'message_template_shortcodes'      => [
618
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
619
-                        'callback' => 'message_template_shortcodes_help_tab',
620
-                    ],
621
-                    'message_preview_help_tab'         => [
622
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
623
-                        'filename' => 'messages_preview',
624
-                    ],
625
-                    'messages_overview_other_help_tab' => [
626
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
627
-                        'filename' => 'messages_overview_other',
628
-                    ],
629
-                ],
630
-                'require_nonce' => false,
631
-            ],
632
-            'display_preview_message'  => [
633
-                'nav'           => [
634
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
635
-                    'order'      => 5,
636
-                    'url'        => '',
637
-                    'persistent' => false,
638
-                ],
639
-                'help_tabs'     => [
640
-                    'preview_message' => [
641
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
642
-                        'callback' => 'preview_message_help_tab',
643
-                    ],
644
-                ],
645
-                'require_nonce' => false,
646
-            ],
647
-            'settings'                 => [
648
-                'nav'           => [
649
-                    'label' => esc_html__('Settings', 'event_espresso'),
650
-                    'order' => 40,
651
-                ],
652
-                'metaboxes'     => ['_messages_settings_metaboxes'],
653
-                'help_tabs'     => [
654
-                    'messages_settings_help_tab'               => [
655
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
656
-                        'filename' => 'messages_settings',
657
-                    ],
658
-                    'messages_settings_message_types_help_tab' => [
659
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
660
-                        'filename' => 'messages_settings_message_types',
661
-                    ],
662
-                    'messages_settings_messengers_help_tab'    => [
663
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
664
-                        'filename' => 'messages_settings_messengers',
665
-                    ],
666
-                ],
667
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
668
-                // 'help_tour'     => array('Messages_Settings_Help_Tour'),
669
-                'require_nonce' => false,
670
-            ],
671
-        ];
672
-    }
673
-
674
-
675
-    protected function _add_screen_options()
676
-    {
677
-        // todo
678
-    }
679
-
680
-
681
-    protected function _add_screen_options_global_mtps()
682
-    {
683
-        /**
684
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
685
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
686
-         */
687
-        $page_title              = $this->_admin_page_title;
688
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
689
-        $this->_per_page_screen_option();
690
-        $this->_admin_page_title = $page_title;
691
-    }
692
-
693
-
694
-    protected function _add_screen_options_default()
695
-    {
696
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
697
-        $this->_per_page_screen_option();
698
-    }
699
-
700
-
701
-    // none of the below group are currently used for Messages
702
-    protected function _add_feature_pointers()
703
-    {
704
-    }
705
-
706
-
707
-    public function admin_init()
708
-    {
709
-    }
710
-
711
-
712
-    public function admin_notices()
713
-    {
714
-    }
715
-
716
-
717
-    public function admin_footer_scripts()
718
-    {
719
-    }
720
-
721
-
722
-    public function messages_help_tab()
723
-    {
724
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
725
-    }
726
-
727
-
728
-    public function messengers_help_tab()
729
-    {
730
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
731
-    }
732
-
733
-
734
-    public function message_types_help_tab()
735
-    {
736
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
737
-    }
738
-
739
-
740
-    public function messages_overview_help_tab()
741
-    {
742
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
743
-    }
744
-
745
-
746
-    public function message_templates_help_tab()
747
-    {
748
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
749
-    }
750
-
751
-
752
-    public function edit_message_template_help_tab()
753
-    {
754
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
755
-                        . esc_attr__('Editor Title', 'event_espresso')
756
-                        . '" />';
757
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
758
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
759
-                        . '" />';
760
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
761
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
762
-                        . '" />';
763
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
764
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
765
-                        . '" />';
766
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
767
-                        . esc_attr__('Publish Metabox', 'event_espresso')
768
-                        . '" />';
769
-        EEH_Template::display_template(
770
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
771
-            $args
772
-        );
773
-    }
774
-
775
-
776
-    /**
777
-     * @throws ReflectionException
778
-     * @throws EE_Error
779
-     */
780
-    public function message_template_shortcodes_help_tab()
781
-    {
782
-        $this->_set_shortcodes();
783
-        $args['shortcodes'] = $this->_shortcodes;
784
-        EEH_Template::display_template(
785
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
786
-            $args
787
-        );
788
-    }
789
-
790
-
791
-    public function preview_message_help_tab()
792
-    {
793
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
794
-    }
795
-
796
-
797
-    public function settings_help_tab()
798
-    {
799
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
800
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
801
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
802
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
803
-        $args['img3'] = '<div class="switch">'
804
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
805
-                        . ' type="checkbox" checked="checked">'
806
-                        . '<label for="ee-on-off-toggle-on"></label>'
807
-                        . '</div>';
808
-        $args['img4'] = '<div class="switch">'
809
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
810
-                        . ' type="checkbox">'
811
-                        . '<label for="ee-on-off-toggle-on"></label>'
812
-                        . '</div>';
813
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
814
-    }
815
-
816
-
817
-    public function load_scripts_styles()
818
-    {
819
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
820
-        wp_enqueue_style('espresso_ee_msg');
821
-
822
-        wp_register_script(
823
-            'ee-messages-settings',
824
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
825
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
826
-            EVENT_ESPRESSO_VERSION,
827
-            true
828
-        );
829
-        wp_register_script(
830
-            'ee-msg-list-table-js',
831
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
832
-            ['ee-dialog'],
833
-            EVENT_ESPRESSO_VERSION
834
-        );
835
-    }
836
-
837
-
838
-    public function load_scripts_styles_default()
839
-    {
840
-        wp_enqueue_script('ee-msg-list-table-js');
841
-    }
842
-
843
-
844
-    public function wp_editor_css($mce_css)
845
-    {
846
-        // if we're on the edit_message_template route
847
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
848
-            $message_type_name = $this->_active_message_type_name;
849
-
850
-            // we're going to REPLACE the existing mce css
851
-            // we need to get the css file location from the active messenger
852
-            $mce_css = $this->_active_messenger->get_variation(
853
-                $this->_template_pack,
854
-                $message_type_name,
855
-                true,
856
-                'wpeditor',
857
-                $this->_variation
858
-            );
859
-        }
860
-
861
-        return $mce_css;
862
-    }
863
-
864
-
865
-    /**
866
-     * @throws EE_Error
867
-     * @throws ReflectionException
868
-     */
869
-    public function load_scripts_styles_edit_message_template()
870
-    {
871
-
872
-        $this->_set_shortcodes();
873
-
874
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
875
-            esc_html__(
876
-                '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.',
877
-                'event_espresso'
878
-            ),
879
-            $this->_message_template_group->messenger_obj()->label['singular'],
880
-            $this->_message_template_group->message_type_obj()->label['singular']
881
-        );
882
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
883
-            '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?',
884
-            'event_espresso'
885
-        );
886
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
887
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
888
-            'event_espresso'
889
-        );
890
-
891
-        wp_register_script(
892
-            'ee_msgs_edit_js',
893
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
894
-            ['jquery'],
895
-            EVENT_ESPRESSO_VERSION
896
-        );
897
-
898
-        wp_enqueue_script('ee_admin_js');
899
-        wp_enqueue_script('ee_msgs_edit_js');
900
-
901
-        // add in special css for tiny_mce
902
-        add_filter('mce_css', [$this, 'wp_editor_css']);
903
-    }
904
-
905
-
906
-    /**
907
-     * @throws EE_Error
908
-     * @throws ReflectionException
909
-     */
910
-    public function load_scripts_styles_display_preview_message()
911
-    {
912
-        $this->_set_message_template_group();
913
-        if ($this->_active_messenger_name) {
914
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
915
-                $this->_active_messenger_name
916
-            );
917
-        }
918
-
919
-        wp_enqueue_style(
920
-            'espresso_preview_css',
921
-            $this->_active_messenger->get_variation(
922
-                $this->_template_pack,
923
-                $this->_active_message_type_name,
924
-                true,
925
-                'preview',
926
-                $this->_variation
927
-            )
928
-        );
929
-    }
930
-
931
-
932
-    public function load_scripts_styles_settings()
933
-    {
934
-        wp_register_style(
935
-            'ee-message-settings',
936
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
937
-            [],
938
-            EVENT_ESPRESSO_VERSION
939
-        );
940
-        wp_enqueue_style('ee-text-links');
941
-        wp_enqueue_style('ee-message-settings');
942
-        wp_enqueue_script('ee-messages-settings');
943
-    }
944
-
945
-
946
-    /**
947
-     * set views array for List Table
948
-     */
949
-    public function _set_list_table_views_global_mtps()
950
-    {
951
-        $this->_views = [
952
-            'in_use' => [
953
-                'slug'  => 'in_use',
954
-                'label' => esc_html__('In Use', 'event_espresso'),
955
-                'count' => 0,
956
-            ],
957
-        ];
958
-    }
959
-
960
-
961
-    /**
962
-     * Set views array for the Custom Template List Table
963
-     */
964
-    public function _set_list_table_views_custom_mtps()
965
-    {
966
-        $this->_set_list_table_views_global_mtps();
967
-        $this->_views['in_use']['bulk_action'] = [
968
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
969
-        ];
970
-    }
971
-
972
-
973
-    /**
974
-     * set views array for message queue list table
975
-     *
976
-     * @throws InvalidDataTypeException
977
-     * @throws InvalidInterfaceException
978
-     * @throws InvalidArgumentException
979
-     * @throws EE_Error
980
-     * @throws ReflectionException
981
-     */
982
-    public function _set_list_table_views_default()
983
-    {
984
-        EE_Registry::instance()->load_helper('Template');
985
-
986
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
987
-            'ee_send_message',
988
-            'message_list_table_bulk_actions'
989
-        )
990
-            ? [
991
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
992
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
993
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
994
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
995
-            ]
996
-            : [];
997
-
998
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
999
-            'ee_delete_messages',
1000
-            'message_list_table_bulk_actions'
1001
-        )
1002
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1003
-            : [];
1004
-
1005
-
1006
-        $this->_views = [
1007
-            'all' => [
1008
-                'slug'        => 'all',
1009
-                'label'       => esc_html__('All', 'event_espresso'),
1010
-                'count'       => 0,
1011
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1012
-            ],
1013
-        ];
1014
-
1015
-
1016
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
1017
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1018
-                continue;
1019
-            }
1020
-            $status_bulk_actions = $common_bulk_actions;
1021
-            // unset bulk actions not applying to status
1022
-            if (! empty($status_bulk_actions)) {
1023
-                switch ($status) {
1024
-                    case EEM_Message::status_idle:
1025
-                    case EEM_Message::status_resend:
1026
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1027
-                        break;
1028
-
1029
-                    case EEM_Message::status_failed:
1030
-                    case EEM_Message::status_debug_only:
1031
-                    case EEM_Message::status_messenger_executing:
1032
-                        $status_bulk_actions = [];
1033
-                        break;
1034
-
1035
-                    case EEM_Message::status_incomplete:
1036
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1037
-                        break;
1038
-
1039
-                    case EEM_Message::status_retry:
1040
-                    case EEM_Message::status_sent:
1041
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1042
-                        break;
1043
-                }
1044
-            }
1045
-
1046
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1047
-            if ($status === EEM_Message::status_messenger_executing) {
1048
-                continue;
1049
-            }
1050
-
1051
-            $this->_views[ strtolower($status) ] = [
1052
-                'slug'        => strtolower($status),
1053
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1054
-                'count'       => 0,
1055
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1056
-            ];
1057
-        }
1058
-    }
1059
-
1060
-
1061
-    /**
1062
-     * @throws EE_Error
1063
-     */
1064
-    protected function _ee_default_messages_overview_list_table()
1065
-    {
1066
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1067
-        $this->display_admin_list_table_page_with_no_sidebar();
1068
-    }
1069
-
1070
-
1071
-    /**
1072
-     * @throws EE_Error
1073
-     * @throws ReflectionException
1074
-     */
1075
-    protected function _message_queue_list_table()
1076
-    {
1077
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1078
-        $this->_template_args['per_column']        = 6;
1079
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1080
-        $this->_template_args['before_list_table'] = '<h3>'
1081
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1082
-                                                     . '</h3>';
1083
-        $this->display_admin_list_table_page_with_no_sidebar();
1084
-    }
1085
-
1086
-
1087
-    /**
1088
-     * @throws EE_Error
1089
-     */
1090
-    protected function _message_legend_items()
1091
-    {
1092
-
1093
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1094
-        $action_items       = [];
1095
-
1096
-        foreach ($action_css_classes as $action_item => $action_details) {
1097
-            if ($action_item === 'see_notifications_for') {
1098
-                continue;
1099
-            }
1100
-            $action_items[ $action_item ] = [
1101
-                'class' => $action_details['css_class'],
1102
-                'desc'  => $action_details['label'],
1103
-            ];
1104
-        }
1105
-
1106
-        /** @var array $status_items status legend setup */
1107
-        $status_items = [
1108
-            'sent_status'                => [
1109
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1110
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1111
-            ],
1112
-            'idle_status'                => [
1113
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1114
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1115
-            ],
1116
-            'failed_status'              => [
1117
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1118
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1119
-            ],
1120
-            'messenger_executing_status' => [
1121
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1122
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1123
-            ],
1124
-            'resend_status'              => [
1125
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1126
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1127
-            ],
1128
-            'incomplete_status'          => [
1129
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1130
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1131
-            ],
1132
-            'retry_status'               => [
1133
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1134
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1135
-            ],
1136
-        ];
1137
-        if (EEM_Message::debug()) {
1138
-            $status_items['debug_only_status'] = [
1139
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1140
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1141
-            ];
1142
-        }
1143
-
1144
-        return array_merge($action_items, $status_items);
1145
-    }
1146
-
1147
-
1148
-    /**
1149
-     * @throws EE_Error
1150
-     */
1151
-    protected function _custom_mtps_preview()
1152
-    {
1153
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1154
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1155
-                                                . ' alt="' . esc_attr__(
1156
-                                                    'Preview Custom Message Templates screenshot',
1157
-                                                    'event_espresso'
1158
-                                                ) . '" />';
1159
-        $this->_template_args['preview_text'] = '<strong>'
1160
-                                                . esc_html__(
1161
-                                                    '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.',
1162
-                                                    'event_espresso'
1163
-                                                )
1164
-                                                . '</strong>';
1165
-
1166
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1167
-    }
1168
-
1169
-
1170
-    /**
1171
-     * get_message_templates
1172
-     * This gets all the message templates for listing on the overview list.
1173
-     *
1174
-     * @access public
1175
-     * @param int    $per_page the amount of templates groups to show per page
1176
-     * @param string $type     the current _view we're getting templates for
1177
-     * @param bool   $count    return count?
1178
-     * @param bool   $all      disregard any paging info (get all data);
1179
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1180
-     * @return array
1181
-     * @throws EE_Error
1182
-     * @throws InvalidArgumentException
1183
-     * @throws InvalidDataTypeException
1184
-     * @throws InvalidInterfaceException
1185
-     */
1186
-    public function get_message_templates(
1187
-        $per_page = 10,
1188
-        $type = 'in_use',
1189
-        $count = false,
1190
-        $all = false,
1191
-        $global = true
1192
-    ) {
1193
-
1194
-        $MTP = EEM_Message_Template_Group::instance();
1195
-
1196
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1197
-        $this->request->setRequestParam('orderby', $orderby);
1198
-
1199
-        $order        = $this->request->getRequestParam('order', 'ASC');
1200
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1201
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1202
-
1203
-        $offset = ($current_page - 1) * $per_page;
1204
-        $limit  = $all ? null : [$offset, $per_page];
1205
-
1206
-        // options will match what is in the _views array property
1207
-        switch ($type) {
1208
-            case 'in_use':
1209
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1210
-                break;
1211
-            default:
1212
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1213
-        }
1214
-
1215
-        return $templates;
1216
-    }
1217
-
1218
-
1219
-    /**
1220
-     * filters etc might need a list of installed message_types
1221
-     *
1222
-     * @return array an array of message type objects
1223
-     */
1224
-    public function get_installed_message_types()
1225
-    {
1226
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1227
-        $installed               = [];
1228
-
1229
-        foreach ($installed_message_types as $message_type) {
1230
-            $installed[ $message_type->name ] = $message_type;
1231
-        }
1232
-
1233
-        return $installed;
1234
-    }
1235
-
1236
-
1237
-    /**
1238
-     * _add_message_template
1239
-     *
1240
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1241
-     *
1242
-     * @param string $message_type
1243
-     * @param string $messenger
1244
-     * @param string $GRP_ID
1245
-     *
1246
-     * @throws EE_error
1247
-     * @throws ReflectionException
1248
-     */
1249
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1250
-    {
1251
-        // set values override any request data
1252
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1253
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1254
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1255
-
1256
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1257
-        if (empty($message_type) || empty($messenger)) {
1258
-            throw new EE_Error(
1259
-                esc_html__(
1260
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1261
-                    'event_espresso'
1262
-                )
1263
-            );
1264
-        }
1265
-
1266
-        // we need the GRP_ID for the template being used as the base for the new template
1267
-        if (empty($GRP_ID)) {
1268
-            throw new EE_Error(
1269
-                esc_html__(
1270
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1271
-                    'event_espresso'
1272
-                )
1273
-            );
1274
-        }
1275
-
1276
-        // let's just make sure the template gets generated!
1277
-
1278
-        // we need to reassign some variables for what the insert is expecting
1279
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1280
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1281
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1282
-
1283
-        $this->_insert_or_update_message_template(true);
1284
-    }
1285
-
1286
-
1287
-    /**
1288
-     * public wrapper for the _add_message_template method
1289
-     *
1290
-     * @param string $message_type     message type slug
1291
-     * @param string $messenger        messenger slug
1292
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1293
-     *                                 off of.
1294
-     * @throws EE_error
1295
-     * @throws ReflectionException
1296
-     */
1297
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1298
-    {
1299
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1300
-    }
1301
-
1302
-
1303
-    /**
1304
-     * _edit_message_template
1305
-     *
1306
-     * @access protected
1307
-     * @return void
1308
-     * @throws InvalidIdentifierException
1309
-     * @throws DomainException
1310
-     * @throws EE_Error
1311
-     * @throws InvalidArgumentException
1312
-     * @throws ReflectionException
1313
-     * @throws InvalidDataTypeException
1314
-     * @throws InvalidInterfaceException
1315
-     */
1316
-    protected function _edit_message_template()
1317
-    {
1318
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1319
-        $template_fields = '';
1320
-        $sidebar_fields  = '';
1321
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1322
-        // valid html in the templates.
1323
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1324
-
1325
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1326
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1327
-
1328
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1329
-        $message_template_group = $this->_message_template_group;
1330
-        $c_label                = $message_template_group->context_label();
1331
-        $c_config               = $message_template_group->contexts_config();
1332
-
1333
-        reset($c_config);
1334
-        $context = $this->request->getRequestParam('context', key($c_config));
1335
-        $context = strtolower($context);
1336
-
1337
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1338
-
1339
-        $edit_message_template_form_url = add_query_arg(
1340
-            ['action' => $action, 'noheader' => true],
1341
-            EE_MSG_ADMIN_URL
1342
-        );
1343
-
1344
-        // set active messenger for this view
1345
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1346
-            $message_template_group->messenger()
1347
-        );
1348
-        $this->_active_message_type_name = $message_template_group->message_type();
1349
-
1350
-
1351
-        // Do we have any validation errors?
1352
-        $validators = $this->_get_transient();
1353
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1354
-
1355
-
1356
-        // we need to assemble the title from Various details
1357
-        $context_label = sprintf(
1358
-            esc_html__('(%s %s)', 'event_espresso'),
1359
-            $c_config[ $context ]['label'],
1360
-            ucwords($c_label['label'])
1361
-        );
1362
-
1363
-        $title = sprintf(
1364
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1365
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1366
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1367
-            $context_label
1368
-        );
1369
-
1370
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1371
-        $this->_template_args['message_template'] = $message_template_group;
1372
-        $this->_template_args['is_extra_fields']  = false;
1373
-
1374
-
1375
-        // let's get EEH_MSG_Template so we can get template form fields
1376
-        $template_field_structure = EEH_MSG_Template::get_fields(
1377
-            $message_template_group->messenger(),
1378
-            $message_template_group->message_type()
1379
-        );
1380
-
1381
-        if (! $template_field_structure) {
1382
-            $template_field_structure = false;
1383
-            $template_fields          = esc_html__(
1384
-                'There was an error in assembling the fields for this display (you should see an error message)',
1385
-                'event_espresso'
1386
-            );
1387
-        }
1388
-
1389
-
1390
-        $message_templates = $message_template_group->context_templates();
1391
-
1392
-
1393
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1394
-        // will get handled in the "extra" array.
1395
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1396
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1397
-                unset($template_field_structure[ $context ][ $reference_field ]);
1398
-            }
1399
-        }
1400
-
1401
-        // let's loop through the template_field_structure and actually assemble the input fields!
1402
-        if (! empty($template_field_structure)) {
1403
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1404
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1405
-                // the extra array and reset them.
1406
-                if ($template_field === 'extra') {
1407
-                    $this->_template_args['is_extra_fields'] = true;
1408
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1409
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1410
-                        $content          = $message_template instanceof EE_Message_Template
1411
-                            ? $message_template->get('MTP_content')
1412
-                            : '';
1413
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1414
-                            // let's verify if we need this extra field via the shortcodes parameter.
1415
-                            $continue = false;
1416
-                            if (isset($extra_array['shortcodes_required'])) {
1417
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1418
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1419
-                                        $continue = true;
1420
-                                    }
1421
-                                }
1422
-                                if ($continue) {
1423
-                                    continue;
1424
-                                }
1425
-                            }
1426
-
1427
-                            $field_id                                  = $reference_field
1428
-                                                                         . '-'
1429
-                                                                         . $extra_field
1430
-                                                                         . '-content';
1431
-                            $template_form_fields[ $field_id ]         = $extra_array;
1432
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1433
-                                                                         . $reference_field
1434
-                                                                         . '][content]['
1435
-                                                                         . $extra_field . ']';
1436
-                            $css_class                                 = isset($extra_array['css_class'])
1437
-                                ? $extra_array['css_class']
1438
-                                : '';
1439
-
1440
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1441
-                                                                              && in_array($extra_field, $v_fields, true)
1442
-                                                                              && (
1443
-                                                                                  is_array($validators[ $extra_field ])
1444
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1445
-                                                                              )
1446
-                                ? 'validate-error ' . $css_class
1447
-                                : $css_class;
1448
-
1449
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1450
-                                                                          && isset($content[ $extra_field ])
1451
-                                ? $content[ $extra_field ]
1452
-                                : '';
1453
-
1454
-                            // do we have a validation error?  if we do then let's use that value instead
1455
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1456
-                                ? $validators[ $extra_field ]['value']
1457
-                                : $template_form_fields[ $field_id ]['value'];
1458
-
1459
-
1460
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1461
-
1462
-                            // shortcode selector
1463
-                            $field_name_to_use                                   = $extra_field === 'main'
1464
-                                ? 'content'
1465
-                                : $extra_field;
1466
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1467
-                                $field_name_to_use,
1468
-                                $field_id
1469
-                            );
1470
-                        }
1471
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1472
-                        $template_field_template_name_id = $reference_field . '-name';
1473
-
1474
-                        $template_form_fields[ $template_field_MTP_id ] = [
1475
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1476
-                            'label'      => null,
1477
-                            'input'      => 'hidden',
1478
-                            'type'       => 'int',
1479
-                            'required'   => false,
1480
-                            'validation' => false,
1481
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1482
-                            'css_class'  => '',
1483
-                            'format'     => '%d',
1484
-                            'db-col'     => 'MTP_ID',
1485
-                        ];
1486
-
1487
-                        $template_form_fields[ $template_field_template_name_id ] = [
1488
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1489
-                            'label'      => null,
1490
-                            'input'      => 'hidden',
1491
-                            'type'       => 'string',
1492
-                            'required'   => false,
1493
-                            'validation' => true,
1494
-                            'value'      => $reference_field,
1495
-                            'css_class'  => '',
1496
-                            'format'     => '%s',
1497
-                            'db-col'     => 'MTP_template_field',
1498
-                        ];
1499
-                    }
1500
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1501
-                } else {
1502
-                    $field_id                                   = $template_field . '-content';
1503
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1504
-                    $template_form_fields[ $field_id ]['name']  =
1505
-                        'MTP_template_fields[' . $template_field . '][content]';
1506
-                    $message_template                           =
1507
-                        isset($message_templates[ $context ][ $template_field ])
1508
-                            ? $message_templates[ $context ][ $template_field ]
1509
-                            : null;
1510
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1511
-                                                                  && is_array($message_templates[ $context ])
1512
-                                                                  && $message_template instanceof EE_Message_Template
1513
-                        ? $message_template->get('MTP_content')
1514
-                        : '';
1515
-
1516
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1517
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1518
-                        ? $validators[ $template_field ]['value']
1519
-                        : $template_form_fields[ $field_id ]['value'];
1520
-
1521
-
1522
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1523
-                    $css_class                                      = isset($field_setup_array['css_class'])
1524
-                        ? $field_setup_array['css_class']
1525
-                        : '';
1526
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1527
-                                                                      && in_array($template_field, $v_fields, true)
1528
-                                                                      && isset($validators[ $template_field ]['msg'])
1529
-                        ? 'validate-error ' . $css_class
1530
-                        : $css_class;
1531
-
1532
-                    // shortcode selector
1533
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1534
-                        $template_field,
1535
-                        $field_id
1536
-                    );
1537
-                }
1538
-
1539
-                // k took care of content field(s) now let's take care of others.
1540
-
1541
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1542
-                $template_field_field_template_name_id = $template_field . '-name';
1543
-
1544
-                // foreach template field there are actually two form fields created
1545
-                $template_form_fields[ $template_field_MTP_id ] = [
1546
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1547
-                    'label'      => null,
1548
-                    'input'      => 'hidden',
1549
-                    'type'       => 'int',
1550
-                    'required'   => false,
1551
-                    'validation' => true,
1552
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1553
-                    'css_class'  => '',
1554
-                    'format'     => '%d',
1555
-                    'db-col'     => 'MTP_ID',
1556
-                ];
1557
-
1558
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1559
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1560
-                    'label'      => null,
1561
-                    'input'      => 'hidden',
1562
-                    'type'       => 'string',
1563
-                    'required'   => false,
1564
-                    'validation' => true,
1565
-                    'value'      => $template_field,
1566
-                    'css_class'  => '',
1567
-                    'format'     => '%s',
1568
-                    'db-col'     => 'MTP_template_field',
1569
-                ];
1570
-            }
1571
-
1572
-            // add other fields
1573
-            $template_form_fields['ee-msg-current-context'] = [
1574
-                'name'       => 'MTP_context',
1575
-                'label'      => null,
1576
-                'input'      => 'hidden',
1577
-                'type'       => 'string',
1578
-                'required'   => false,
1579
-                'validation' => true,
1580
-                'value'      => $context,
1581
-                'css_class'  => '',
1582
-                'format'     => '%s',
1583
-                'db-col'     => 'MTP_context',
1584
-            ];
1585
-
1586
-            $template_form_fields['ee-msg-grp-id'] = [
1587
-                'name'       => 'GRP_ID',
1588
-                'label'      => null,
1589
-                'input'      => 'hidden',
1590
-                'type'       => 'int',
1591
-                'required'   => false,
1592
-                'validation' => true,
1593
-                'value'      => $GRP_ID,
1594
-                'css_class'  => '',
1595
-                'format'     => '%d',
1596
-                'db-col'     => 'GRP_ID',
1597
-            ];
1598
-
1599
-            $template_form_fields['ee-msg-messenger'] = [
1600
-                'name'       => 'MTP_messenger',
1601
-                'label'      => null,
1602
-                'input'      => 'hidden',
1603
-                'type'       => 'string',
1604
-                'required'   => false,
1605
-                'validation' => true,
1606
-                'value'      => $message_template_group->messenger(),
1607
-                'css_class'  => '',
1608
-                'format'     => '%s',
1609
-                'db-col'     => 'MTP_messenger',
1610
-            ];
1611
-
1612
-            $template_form_fields['ee-msg-message-type'] = [
1613
-                'name'       => 'MTP_message_type',
1614
-                'label'      => null,
1615
-                'input'      => 'hidden',
1616
-                'type'       => 'string',
1617
-                'required'   => false,
1618
-                'validation' => true,
1619
-                'value'      => $message_template_group->message_type(),
1620
-                'css_class'  => '',
1621
-                'format'     => '%s',
1622
-                'db-col'     => 'MTP_message_type',
1623
-            ];
1624
-
1625
-            $sidebar_form_fields['ee-msg-is-global'] = [
1626
-                'name'       => 'MTP_is_global',
1627
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1628
-                'input'      => 'hidden',
1629
-                'type'       => 'int',
1630
-                'required'   => false,
1631
-                'validation' => true,
1632
-                'value'      => $message_template_group->get('MTP_is_global'),
1633
-                'css_class'  => '',
1634
-                'format'     => '%d',
1635
-                'db-col'     => 'MTP_is_global',
1636
-            ];
1637
-
1638
-            $sidebar_form_fields['ee-msg-is-override'] = [
1639
-                'name'       => 'MTP_is_override',
1640
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1641
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1642
-                'type'       => 'int',
1643
-                'required'   => false,
1644
-                'validation' => true,
1645
-                'value'      => $message_template_group->get('MTP_is_override'),
1646
-                'css_class'  => '',
1647
-                'format'     => '%d',
1648
-                'db-col'     => 'MTP_is_override',
1649
-            ];
1650
-
1651
-            $sidebar_form_fields['ee-msg-is-active'] = [
1652
-                'name'       => 'MTP_is_active',
1653
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1654
-                'input'      => 'hidden',
1655
-                'type'       => 'int',
1656
-                'required'   => false,
1657
-                'validation' => true,
1658
-                'value'      => $message_template_group->is_active(),
1659
-                'css_class'  => '',
1660
-                'format'     => '%d',
1661
-                'db-col'     => 'MTP_is_active',
1662
-            ];
1663
-
1664
-            $sidebar_form_fields['ee-msg-deleted'] = [
1665
-                'name'       => 'MTP_deleted',
1666
-                'label'      => null,
1667
-                'input'      => 'hidden',
1668
-                'type'       => 'int',
1669
-                'required'   => false,
1670
-                'validation' => true,
1671
-                'value'      => $message_template_group->get('MTP_deleted'),
1672
-                'css_class'  => '',
1673
-                'format'     => '%d',
1674
-                'db-col'     => 'MTP_deleted',
1675
-            ];
1676
-            $sidebar_form_fields['ee-msg-author']  = [
1677
-                'name'       => 'MTP_user_id',
1678
-                'label'      => esc_html__('Author', 'event_espresso'),
1679
-                'input'      => 'hidden',
1680
-                'type'       => 'int',
1681
-                'required'   => false,
1682
-                'validation' => false,
1683
-                'value'      => $message_template_group->user(),
1684
-                'format'     => '%d',
1685
-                'db-col'     => 'MTP_user_id',
1686
-            ];
1687
-
1688
-            $sidebar_form_fields['ee-msg-route'] = [
1689
-                'name'  => 'action',
1690
-                'input' => 'hidden',
1691
-                'type'  => 'string',
1692
-                'value' => $action,
1693
-            ];
1694
-
1695
-            $sidebar_form_fields['ee-msg-id']        = [
1696
-                'name'  => 'id',
1697
-                'input' => 'hidden',
1698
-                'type'  => 'int',
1699
-                'value' => $GRP_ID,
1700
-            ];
1701
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1702
-                'name'  => $action . '_nonce',
1703
-                'input' => 'hidden',
1704
-                'type'  => 'string',
1705
-                'value' => wp_create_nonce($action . '_nonce'),
1706
-            ];
1707
-
1708
-            $template_switch = $this->request->getRequestParam('template_switch');
1709
-            if ($template_switch) {
1710
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1711
-                    'name'  => 'template_switch',
1712
-                    'input' => 'hidden',
1713
-                    'type'  => 'int',
1714
-                    'value' => 1,
1715
-                ];
1716
-            }
1717
-
1718
-
1719
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1720
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1721
-        } //end if ( !empty($template_field_structure) )
1722
-
1723
-        // set extra content for publish box
1724
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1725
-        $this->_set_publish_post_box_vars(
1726
-            'id',
1727
-            $GRP_ID,
1728
-            false,
1729
-            add_query_arg(
1730
-                ['action' => 'global_mtps'],
1731
-                $this->_admin_base_url
1732
-            )
1733
-        );
1734
-
1735
-        // add preview button
1736
-        $preview_url    = parent::add_query_args_and_nonce(
1737
-            [
1738
-                'message_type' => $message_template_group->message_type(),
1739
-                'messenger'    => $message_template_group->messenger(),
1740
-                'context'      => $context,
1741
-                'GRP_ID'       => $GRP_ID,
1742
-                'evt_id'       => $EVT_ID,
1743
-                'action'       => 'preview_message',
1744
-            ],
1745
-            $this->_admin_base_url
1746
-        );
1747
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1748
-                          . esc_html__('Preview', 'event_espresso')
1749
-                          . '</a>';
1750
-
1751
-
1752
-        // setup context switcher
1753
-        $context_switcher_args = [
1754
-            'page'    => 'espresso_messages',
1755
-            'action'  => 'edit_message_template',
1756
-            'id'      => $GRP_ID,
1757
-            'evt_id'  => $EVT_ID,
1758
-            'context' => $context,
1759
-            'extra'   => $preview_button,
1760
-        ];
1761
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1762
-
1763
-
1764
-        // main box
1765
-        $this->_template_args['template_fields']                         = $template_fields;
1766
-        $this->_template_args['sidebar_box_id']                          = 'details';
1767
-        $this->_template_args['action']                                  = $action;
1768
-        $this->_template_args['context']                                 = $context;
1769
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1770
-        $this->_template_args['learn_more_about_message_templates_link'] =
1771
-            $this->_learn_more_about_message_templates_link();
1772
-
1773
-
1774
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1775
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1776
-            $message_template_group,
1777
-            $context,
1778
-            $context_label
1779
-        );
1780
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1781
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1782
-
1783
-        $this->_template_path = $this->_template_args['GRP_ID']
1784
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1785
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1786
-
1787
-        // send along EE_Message_Template_Group object for further template use.
1788
-        $this->_template_args['MTP'] = $message_template_group;
1789
-
1790
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1791
-            $this->_template_path,
1792
-            $this->_template_args,
1793
-            true
1794
-        );
1795
-
1796
-
1797
-        // finally, let's set the admin_page title
1798
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1799
-
1800
-
1801
-        // we need to take care of setting the shortcodes property for use elsewhere.
1802
-        $this->_set_shortcodes();
1803
-
1804
-
1805
-        // final template wrapper
1806
-        $this->display_admin_page_with_sidebar();
1807
-    }
1808
-
1809
-
1810
-    public function filter_tinymce_init($mceInit, $editor_id)
1811
-    {
1812
-        return $mceInit;
1813
-    }
1814
-
1815
-
1816
-    public function add_context_switcher()
1817
-    {
1818
-        return $this->_context_switcher;
1819
-    }
1820
-
1821
-
1822
-    /**
1823
-     * Adds the activation/deactivation toggle for the message template context.
1824
-     *
1825
-     * @param EE_Message_Template_Group $message_template_group
1826
-     * @param string                    $context
1827
-     * @param string                    $context_label
1828
-     * @return string
1829
-     * @throws DomainException
1830
-     * @throws EE_Error
1831
-     * @throws InvalidIdentifierException
1832
-     * @throws ReflectionException
1833
-     */
1834
-    protected function add_active_context_element(
1835
-        EE_Message_Template_Group $message_template_group,
1836
-        $context,
1837
-        $context_label
1838
-    ) {
1839
-        $template_args = [
1840
-            'context'                   => $context,
1841
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1842
-            'is_active'                 => $message_template_group->is_context_active($context),
1843
-            'on_off_action'             => $message_template_group->is_context_active($context)
1844
-                ? 'context-off'
1845
-                : 'context-on',
1846
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1847
-            'message_template_group_id' => $message_template_group->ID(),
1848
-        ];
1849
-        return EEH_Template::display_template(
1850
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1851
-            $template_args,
1852
-            true
1853
-        );
1854
-    }
1855
-
1856
-
1857
-    /**
1858
-     * Ajax callback for `toggle_context_template` ajax action.
1859
-     * Handles toggling the message context on or off.
1860
-     *
1861
-     * @throws EE_Error
1862
-     * @throws InvalidArgumentException
1863
-     * @throws InvalidDataTypeException
1864
-     * @throws InvalidIdentifierException
1865
-     * @throws InvalidInterfaceException
1866
-     */
1867
-    public function toggle_context_template()
1868
-    {
1869
-        $success = true;
1870
-        // check for required data
1871
-        if (
1872
-            ! (
1873
-                $this->request->requestParamIsSet('message_template_group_id')
1874
-                && $this->request->requestParamIsSet('context')
1875
-                && $this->request->requestParamIsSet('status')
1876
-            )
1877
-        ) {
1878
-            EE_Error::add_error(
1879
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1880
-                __FILE__,
1881
-                __FUNCTION__,
1882
-                __LINE__
1883
-            );
1884
-            $success = false;
1885
-        }
1886
-
1887
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1888
-        $context = $this->request->getRequestParam('context', '');
1889
-        $status  = $this->request->getRequestParam('status', '');
1890
-
1891
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1892
-
1893
-        if ($status !== 'off' && $status !== 'on') {
1894
-            EE_Error::add_error(
1895
-                sprintf(
1896
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1897
-                    $status
1898
-                ),
1899
-                __FILE__,
1900
-                __FUNCTION__,
1901
-                __LINE__
1902
-            );
1903
-            $success = false;
1904
-        }
1905
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1906
-        $message_template_group    = EEM_Message_Template_Group::instance()->get_one_by_ID($message_template_group_id);
1907
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1908
-            EE_Error::add_error(
1909
-                sprintf(
1910
-                    esc_html__(
1911
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1912
-                        'event_espresso'
1913
-                    ),
1914
-                    $message_template_group_id,
1915
-                    'EE_Message_Template_Group'
1916
-                ),
1917
-                __FILE__,
1918
-                __FUNCTION__,
1919
-                __LINE__
1920
-            );
1921
-            $success = false;
1922
-        }
1923
-        if ($success) {
1924
-            $success = $status === 'off'
1925
-                ? $message_template_group->deactivate_context($context)
1926
-                : $message_template_group->activate_context($context);
1927
-        }
1928
-        $this->_template_args['success'] = $success;
1929
-        $this->_return_json();
1930
-    }
1931
-
1932
-
1933
-    public function _add_form_element_before()
1934
-    {
1935
-        return '<form method="post" action="'
1936
-               . $this->_template_args['edit_message_template_form_url']
1937
-               . '" id="ee-msg-edit-frm">';
1938
-    }
1939
-
1940
-
1941
-    public function _add_form_element_after()
1942
-    {
1943
-        return '</form>';
1944
-    }
1945
-
1946
-
1947
-    /**
1948
-     * This executes switching the template pack for a message template.
1949
-     *
1950
-     * @throws EE_Error
1951
-     * @throws InvalidDataTypeException
1952
-     * @throws InvalidInterfaceException
1953
-     * @throws InvalidArgumentException
1954
-     * @throws ReflectionException
1955
-     * @since 4.5.0
1956
-     */
1957
-    public function switch_template_pack()
1958
-    {
1959
-
1960
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
1961
-        $template_pack = $this->request->getRequestParam('template_pack', '');
1962
-
1963
-        // verify we have needed values.
1964
-        if (empty($GRP_ID) || empty($template_pack)) {
1965
-            $this->_template_args['error'] = true;
1966
-            EE_Error::add_error(
1967
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1968
-                __FILE__,
1969
-                __FUNCTION__,
1970
-                __LINE__
1971
-            );
1972
-        } else {
1973
-            // get template, set the new template_pack and then reset to default
1974
-            /** @var EE_Message_Template_Group $message_template_group */
1975
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1976
-
1977
-            $message_template_group->set_template_pack_name($template_pack);
1978
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
1979
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
1980
-
1981
-            $query_args = $this->_reset_to_default_template();
1982
-
1983
-            if (empty($query_args['id'])) {
1984
-                EE_Error::add_error(
1985
-                    esc_html__(
1986
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1987
-                        'event_espresso'
1988
-                    ),
1989
-                    __FILE__,
1990
-                    __FUNCTION__,
1991
-                    __LINE__
1992
-                );
1993
-                $this->_template_args['error'] = true;
1994
-            } else {
1995
-                $template_label       = $message_template_group->get_template_pack()->label;
1996
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1997
-                EE_Error::add_success(
1998
-                    sprintf(
1999
-                        esc_html__(
2000
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2001
-                            'event_espresso'
2002
-                        ),
2003
-                        $template_label,
2004
-                        $template_pack_labels->template_pack
2005
-                    )
2006
-                );
2007
-                // generate the redirect url for js.
2008
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2009
-
2010
-                $this->_template_args['data']['redirect_url'] = $url;
2011
-                $this->_template_args['success']              = true;
2012
-            }
2013
-
2014
-            $this->_return_json();
2015
-        }
2016
-    }
2017
-
2018
-
2019
-    /**
2020
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2021
-     * they want.
2022
-     *
2023
-     * @access protected
2024
-     * @return array|null
2025
-     * @throws EE_Error
2026
-     * @throws InvalidArgumentException
2027
-     * @throws InvalidDataTypeException
2028
-     * @throws InvalidInterfaceException
2029
-     * @throws ReflectionException
2030
-     */
2031
-    protected function _reset_to_default_template()
2032
-    {
2033
-
2034
-        $templates    = [];
2035
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2036
-        $messenger    = $this->request->getRequestParam('msgr');
2037
-        $message_type = $this->request->getRequestParam('mt');
2038
-        // we need to make sure we've got the info we need.
2039
-        if (! ($GRP_ID && $messenger && $message_type)) {
2040
-            EE_Error::add_error(
2041
-                esc_html__(
2042
-                    '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.',
2043
-                    'event_espresso'
2044
-                ),
2045
-                __FILE__,
2046
-                __FUNCTION__,
2047
-                __LINE__
2048
-            );
2049
-        }
2050
-
2051
-        // all templates will be reset to whatever the defaults are
2052
-        // for the global template matching the messenger and message type.
2053
-        $success = ! empty($GRP_ID);
2054
-
2055
-        if ($success) {
2056
-            // let's first determine if the incoming template is a global template,
2057
-            // if it isn't then we need to get the global template matching messenger and message type.
2058
-            // $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2059
-
2060
-
2061
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2062
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2063
-
2064
-            if ($success) {
2065
-                // if successfully deleted, lets generate the new ones.
2066
-                // Note. We set GLOBAL to true, because resets on ANY template
2067
-                // will use the related global template defaults for regeneration.
2068
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2069
-                // HOWEVER, we DO keep the template pack and template variation set
2070
-                // for the current custom template when resetting.
2071
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2072
-            }
2073
-        }
2074
-
2075
-        // any error messages?
2076
-        if (! $success) {
2077
-            EE_Error::add_error(
2078
-                esc_html__(
2079
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2080
-                    'event_espresso'
2081
-                ),
2082
-                __FILE__,
2083
-                __FUNCTION__,
2084
-                __LINE__
2085
-            );
2086
-        }
2087
-
2088
-        // all good, let's add a success message!
2089
-        if ($success && ! empty($templates)) {
2090
-            // the info for the template we generated is the first element in the returned array
2091
-            // $templates = $templates[0];
2092
-            EE_Error::overwrite_success();
2093
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2094
-        }
2095
-
2096
-
2097
-        $query_args = [
2098
-            'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2099
-            'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2100
-            'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2101
-        ];
2102
-
2103
-        // if called via ajax then we return query args otherwise redirect
2104
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2105
-            return $query_args;
2106
-        } else {
2107
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2108
-
2109
-            return null;
2110
-        }
2111
-    }
2112
-
2113
-
2114
-    /**
2115
-     * Retrieve and set the message preview for display.
2116
-     *
2117
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2118
-     * @return string
2119
-     * @throws ReflectionException
2120
-     * @throws EE_Error
2121
-     * @throws InvalidArgumentException
2122
-     * @throws InvalidDataTypeException
2123
-     * @throws InvalidInterfaceException
2124
-     */
2125
-    public function _preview_message($send = false)
2126
-    {
2127
-        // first make sure we've got the necessary parameters
2128
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2129
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2130
-            EE_Error::add_error(
2131
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2132
-                __FILE__,
2133
-                __FUNCTION__,
2134
-                __LINE__
2135
-            );
2136
-        }
2137
-
2138
-        $context = $this->request->getRequestParam('context');
2139
-        // get the preview!
2140
-        $preview = EED_Messages::preview_message(
2141
-            $this->_active_message_type_name,
2142
-            $context,
2143
-            $this->_active_messenger_name,
2144
-            $send
2145
-        );
2146
-
2147
-        if ($send) {
2148
-            return $preview;
2149
-        }
2150
-
2151
-        // if we have an evt_id set on the request, use it.
2152
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2153
-
2154
-        // let's add a button to go back to the edit view
2155
-        $query_args             = [
2156
-            'id'      => $GRP_ID,
2157
-            'evt_id'  => $EVT_ID,
2158
-            'context' => $context,
2159
-            'action'  => 'edit_message_template',
2160
-        ];
2161
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2162
-        $preview_button         = '<a href="'
2163
-                                  . $go_back_url
2164
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2165
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2166
-                                  . '</a>';
2167
-        $message_types          = $this->get_installed_message_types();
2168
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2169
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2170
-            ? ucwords($active_messenger->label['singular'])
2171
-            : esc_html__('Unknown Messenger', 'event_espresso');
2172
-        // let's provide a helpful title for context
2173
-        $preview_title = sprintf(
2174
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2175
-            $active_messenger_label,
2176
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2177
-        );
2178
-        if (empty($preview)) {
2179
-            $this->noEventsErrorMessage();
2180
-        }
2181
-        // setup display of preview.
2182
-        $this->_admin_page_title                    = $preview_title;
2183
-        $this->_template_args['admin_page_title']   = $preview_title;
2184
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2185
-        $this->_template_args['data']['force_json'] = true;
2186
-
2187
-        return '';
2188
-    }
2189
-
2190
-
2191
-    /**
2192
-     * Used to set an error if there are no events available for generating a preview/test send.
2193
-     *
2194
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2195
-     */
2196
-    protected function noEventsErrorMessage($test_send = false)
2197
-    {
2198
-        $events_url = parent::add_query_args_and_nonce(
2199
-            [
2200
-                'action' => 'default',
2201
-                'page'   => 'espresso_events',
2202
-            ],
2203
-            admin_url('admin.php')
2204
-        );
2205
-        $message    = $test_send
2206
-            ? esc_html__(
2207
-                '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!',
2208
-                'event_espresso'
2209
-            )
2210
-            : esc_html__(
2211
-                '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!',
2212
-                'event_espresso'
2213
-            );
2214
-
2215
-        EE_Error::add_attention(
2216
-            sprintf(
2217
-                $message,
2218
-                "<a href='{$events_url}'>",
2219
-                '</a>'
2220
-            )
2221
-        );
2222
-    }
2223
-
2224
-
2225
-    /**
2226
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2227
-     * gets called automatically.
2228
-     *
2229
-     * @return void
2230
-     * @throws EE_Error
2231
-     * @since 4.5.0
2232
-     *
2233
-     */
2234
-    protected function _display_preview_message()
2235
-    {
2236
-        $this->display_admin_page_with_no_sidebar();
2237
-    }
2238
-
2239
-
2240
-    /**
2241
-     * registers metaboxes that should show up on the "edit_message_template" page
2242
-     *
2243
-     * @access protected
2244
-     * @return void
2245
-     */
2246
-    protected function _register_edit_meta_boxes()
2247
-    {
2248
-        add_meta_box(
2249
-            'mtp_valid_shortcodes',
2250
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2251
-            [$this, 'shortcode_meta_box'],
2252
-            $this->_current_screen->id,
2253
-            'side'
2254
-        );
2255
-        add_meta_box(
2256
-            'mtp_extra_actions',
2257
-            esc_html__('Extra Actions', 'event_espresso'),
2258
-            [$this, 'extra_actions_meta_box'],
2259
-            $this->_current_screen->id,
2260
-            'side',
2261
-            'high'
2262
-        );
2263
-        add_meta_box(
2264
-            'mtp_templates',
2265
-            esc_html__('Template Styles', 'event_espresso'),
2266
-            [$this, 'template_pack_meta_box'],
2267
-            $this->_current_screen->id,
2268
-            'side',
2269
-            'high'
2270
-        );
2271
-    }
2272
-
2273
-
2274
-    /**
2275
-     * metabox content for all template pack and variation selection.
2276
-     *
2277
-     * @return void
2278
-     * @throws DomainException
2279
-     * @throws EE_Error
2280
-     * @throws InvalidArgumentException
2281
-     * @throws ReflectionException
2282
-     * @throws InvalidDataTypeException
2283
-     * @throws InvalidInterfaceException
2284
-     * @since 4.5.0
2285
-     */
2286
-    public function template_pack_meta_box()
2287
-    {
2288
-        $this->_set_message_template_group();
2289
-
2290
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2291
-
2292
-        $tp_select_values = [];
2293
-
2294
-        foreach ($tp_collection as $tp) {
2295
-            // only include template packs that support this messenger and message type!
2296
-            $supports = $tp->get_supports();
2297
-            if (
2298
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2299
-                || ! in_array(
2300
-                    $this->_message_template_group->message_type(),
2301
-                    $supports[ $this->_message_template_group->messenger() ],
2302
-                    true
2303
-                )
2304
-            ) {
2305
-                // not supported
2306
-                continue;
2307
-            }
2308
-
2309
-            $tp_select_values[] = [
2310
-                'text' => $tp->label,
2311
-                'id'   => $tp->dbref,
2312
-            ];
2313
-        }
2314
-
2315
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2316
-        // the default template pack.  This still allows for the odd template pack to override.
2317
-        if (empty($tp_select_values)) {
2318
-            $tp_select_values[] = [
2319
-                'text' => esc_html__('Default', 'event_espresso'),
2320
-                'id'   => 'default',
2321
-            ];
2322
-        }
2323
-
2324
-        // setup variation select values for the currently selected template.
2325
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2326
-            $this->_message_template_group->messenger(),
2327
-            $this->_message_template_group->message_type()
2328
-        );
2329
-        $variations_select_values = [];
2330
-        foreach ($variations as $variation => $label) {
2331
-            $variations_select_values[] = [
2332
-                'text' => $label,
2333
-                'id'   => $variation,
2334
-            ];
2335
-        }
2336
-
2337
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2338
-
2339
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2340
-            'MTP_template_pack',
2341
-            $tp_select_values,
2342
-            $this->_message_template_group->get_template_pack_name()
2343
-        );
2344
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2345
-            'MTP_template_variation',
2346
-            $variations_select_values,
2347
-            $this->_message_template_group->get_template_pack_variation()
2348
-        );
2349
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2350
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2351
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2352
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2353
-
2354
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2355
-
2356
-        EEH_Template::display_template($template, $template_args);
2357
-    }
2358
-
2359
-
2360
-    /**
2361
-     * This meta box holds any extra actions related to Message Templates
2362
-     * For now, this includes Resetting templates to defaults and sending a test email.
2363
-     *
2364
-     * @access  public
2365
-     * @return void
2366
-     * @throws EE_Error
2367
-     */
2368
-    public function extra_actions_meta_box()
2369
-    {
2370
-        $template_form_fields = [];
2371
-
2372
-        $extra_args = [
2373
-            'msgr'   => $this->_message_template_group->messenger(),
2374
-            'mt'     => $this->_message_template_group->message_type(),
2375
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2376
-        ];
2377
-        // first we need to see if there are any fields
2378
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2379
-
2380
-        if (! empty($fields)) {
2381
-            // yup there be fields
2382
-            foreach ($fields as $field => $config) {
2383
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2384
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2385
-                $default  = isset($config['default']) ? $config['default'] : '';
2386
-                $default  = isset($config['value']) ? $config['value'] : $default;
2387
-
2388
-                // if type is hidden and the value is empty
2389
-                // something may have gone wrong so let's correct with the defaults
2390
-                $fix                = $config['input'] === 'hidden'
2391
-                                      && isset($existing[ $field ])
2392
-                                      && empty($existing[ $field ])
2393
-                    ? $default
2394
-                    : '';
2395
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2396
-                    ? $existing[ $field ]
2397
-                    : $fix;
2398
-
2399
-                $template_form_fields[ $field_id ] = [
2400
-                    'name'       => 'test_settings_fld[' . $field . ']',
2401
-                    'label'      => $config['label'],
2402
-                    'input'      => $config['input'],
2403
-                    'type'       => $config['type'],
2404
-                    'required'   => $config['required'],
2405
-                    'validation' => $config['validation'],
2406
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2407
-                    'css_class'  => $config['css_class'],
2408
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2409
-                    'default'    => $default,
2410
-                    'format'     => $config['format'],
2411
-                ];
2412
-            }
2413
-        }
2414
-
2415
-        $test_settings_html = ! empty($template_form_fields)
2416
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2417
-            : '';
2418
-
2419
-        // print out $test_settings_fields
2420
-        if (! empty($test_settings_html)) {
2421
-            $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2422
-            $test_settings_html .= 'name="test_button" value="';
2423
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2424
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2425
-        }
2426
-
2427
-        // and button
2428
-        $test_settings_html .= '<p>';
2429
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2430
-        $test_settings_html .= '</p>';
2431
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2432
-        $test_settings_html .= $this->get_action_link_or_button(
2433
-            'reset_to_default',
2434
-            'reset',
2435
-            $extra_args,
2436
-            'button-primary reset-default-button'
2437
-        );
2438
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2439
-        echo $test_settings_html; // already escaped
2440
-    }
2441
-
2442
-
2443
-    /**
2444
-     * This returns the shortcode selector skeleton for a given context and field.
2445
-     *
2446
-     * @param string $field           The name of the field retrieving shortcodes for.
2447
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2448
-     * @return string
2449
-     * @throws DomainException
2450
-     * @throws EE_Error
2451
-     * @throws InvalidArgumentException
2452
-     * @throws ReflectionException
2453
-     * @throws InvalidDataTypeException
2454
-     * @throws InvalidInterfaceException
2455
-     * @since 4.9.rc.000
2456
-     */
2457
-    protected function _get_shortcode_selector($field, $linked_input_id)
2458
-    {
2459
-        $template_args = [
2460
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2461
-            'fieldname'       => $field,
2462
-            'linked_input_id' => $linked_input_id,
2463
-        ];
2464
-
2465
-        return EEH_Template::display_template(
2466
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2467
-            $template_args,
2468
-            true
2469
-        );
2470
-    }
2471
-
2472
-
2473
-    /**
2474
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2475
-     * page)
2476
-     *
2477
-     * @access public
2478
-     * @return void
2479
-     * @throws EE_Error
2480
-     * @throws InvalidArgumentException
2481
-     * @throws ReflectionException
2482
-     * @throws InvalidDataTypeException
2483
-     * @throws InvalidInterfaceException
2484
-     */
2485
-    public function shortcode_meta_box()
2486
-    {
2487
-        $shortcodes = $this->_get_shortcodes([], false);
2488
-        // just make sure the shortcodes property is set
2489
-        // $messenger = $this->_message_template_group->messenger_obj();
2490
-        // now let's set the content depending on the status of the shortcodes array
2491
-        if (empty($shortcodes)) {
2492
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2493
-            return;
2494
-        }
2495
-        ?>
20
+	/**
21
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
22
+	 */
23
+	protected $_message_resource_manager;
24
+
25
+	/**
26
+	 * @var string
27
+	 */
28
+	protected $_active_message_type_name = '';
29
+
30
+	/**
31
+	 * @var string
32
+	 */
33
+	protected $_active_messenger_name = '';
34
+
35
+	/**
36
+	 * @var EE_messenger $_active_messenger
37
+	 */
38
+	protected $_active_messenger;
39
+
40
+	protected $_activate_meta_box_type;
41
+
42
+	protected $_current_message_meta_box;
43
+
44
+	protected $_current_message_meta_box_object;
45
+
46
+	protected $_context_switcher;
47
+
48
+	protected $_shortcodes           = [];
49
+
50
+	protected $_active_messengers    = [];
51
+
52
+	protected $_active_message_types = [];
53
+
54
+	/**
55
+	 * @var EE_Message_Template_Group $_message_template_group
56
+	 */
57
+	protected $_message_template_group;
58
+
59
+	protected $_m_mt_settings = [];
60
+
61
+
62
+	/**
63
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
64
+	 * IF there is no group then it gets automatically set to the Default template pack.
65
+	 *
66
+	 * @since 4.5.0
67
+	 *
68
+	 * @var EE_Messages_Template_Pack
69
+	 */
70
+	protected $_template_pack;
71
+
72
+
73
+	/**
74
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
75
+	 * group is.  If there is no group then it automatically gets set to default.
76
+	 *
77
+	 * @since 4.5.0
78
+	 *
79
+	 * @var string
80
+	 */
81
+	protected $_variation;
82
+
83
+
84
+	/**
85
+	 * @param bool $routing
86
+	 * @throws EE_Error
87
+	 * @throws ReflectionException
88
+	 */
89
+	public function __construct($routing = true)
90
+	{
91
+		// make sure messages autoloader is running
92
+		EED_Messages::set_autoloaders();
93
+		parent::__construct($routing);
94
+	}
95
+
96
+
97
+	/**
98
+	 * @throws EE_Error
99
+	 * @throws ReflectionException
100
+	 */
101
+	protected function _init_page_props()
102
+	{
103
+		$this->page_slug        = EE_MSG_PG_SLUG;
104
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
105
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
106
+		$this->_admin_base_path = EE_MSG_ADMIN;
107
+
108
+		$this->_active_messenger_name    = $this->request->getRequestParam('messenger', '');
109
+		$this->_active_message_type_name = $this->request->getRequestParam('message_type', '');
110
+
111
+		$this->_load_message_resource_manager();
112
+	}
113
+
114
+
115
+	/**
116
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
117
+	 *
118
+	 * @throws EE_Error
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidInterfaceException
121
+	 * @throws InvalidArgumentException
122
+	 * @throws ReflectionException
123
+	 */
124
+	protected function _load_message_resource_manager()
125
+	{
126
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
127
+	}
128
+
129
+
130
+	/**
131
+	 * @return array
132
+	 * @throws EE_Error
133
+	 * @throws InvalidArgumentException
134
+	 * @throws InvalidDataTypeException
135
+	 * @throws InvalidInterfaceException
136
+	 * @deprecated 4.9.9.rc.014
137
+	 */
138
+	public function get_messengers_for_list_table()
139
+	{
140
+		EE_Error::doing_it_wrong(
141
+			__METHOD__,
142
+			sprintf(
143
+				esc_html__(
144
+					'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',
145
+					'event_espresso'
146
+				),
147
+				'Messages_Admin_Page::get_messengers_select_input()'
148
+			),
149
+			'4.9.9.rc.014'
150
+		);
151
+
152
+		$m_values          = [];
153
+		$active_messengers = EEM_Message::instance()->get_all(['group_by' => 'MSG_messenger']);
154
+		// setup messengers for selects
155
+		$i = 1;
156
+		foreach ($active_messengers as $active_messenger) {
157
+			if ($active_messenger instanceof EE_Message) {
158
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
159
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
160
+				$i++;
161
+			}
162
+		}
163
+
164
+		return $m_values;
165
+	}
166
+
167
+
168
+	/**
169
+	 * @return array
170
+	 * @throws EE_Error
171
+	 * @throws InvalidArgumentException
172
+	 * @throws InvalidDataTypeException
173
+	 * @throws InvalidInterfaceException
174
+	 * @deprecated 4.9.9.rc.014
175
+	 */
176
+	public function get_message_types_for_list_table()
177
+	{
178
+		EE_Error::doing_it_wrong(
179
+			__METHOD__,
180
+			sprintf(
181
+				esc_html__(
182
+					'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',
183
+					'event_espresso'
184
+				),
185
+				'Messages_Admin_Page::get_message_types_select_input()'
186
+			),
187
+			'4.9.9.rc.014'
188
+		);
189
+
190
+		$mt_values       = [];
191
+		$active_messages = EEM_Message::instance()->get_all(['group_by' => 'MSG_message_type']);
192
+		$i               = 1;
193
+		foreach ($active_messages as $active_message) {
194
+			if ($active_message instanceof EE_Message) {
195
+				$mt_values[ $i ]['id']   = $active_message->message_type();
196
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
197
+				$i++;
198
+			}
199
+		}
200
+
201
+		return $mt_values;
202
+	}
203
+
204
+
205
+	/**
206
+	 * @return array
207
+	 * @throws EE_Error
208
+	 * @throws InvalidArgumentException
209
+	 * @throws InvalidDataTypeException
210
+	 * @throws InvalidInterfaceException
211
+	 * @deprecated 4.9.9.rc.014
212
+	 */
213
+	public function get_contexts_for_message_types_for_list_table()
214
+	{
215
+		EE_Error::doing_it_wrong(
216
+			__METHOD__,
217
+			sprintf(
218
+				esc_html__(
219
+					'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',
220
+					'event_espresso'
221
+				),
222
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
223
+			),
224
+			'4.9.9.rc.014'
225
+		);
226
+
227
+		$contexts                = [];
228
+		$active_message_contexts = EEM_Message::instance()->get_all(['group_by' => 'MSG_context']);
229
+		foreach ($active_message_contexts as $active_message) {
230
+			if ($active_message instanceof EE_Message) {
231
+				$message_type = $active_message->message_type_object();
232
+				if ($message_type instanceof EE_message_type) {
233
+					$message_type_contexts = $message_type->get_contexts();
234
+					foreach ($message_type_contexts as $context => $context_details) {
235
+						$contexts[ $context ] = $context_details['label'];
236
+					}
237
+				}
238
+			}
239
+		}
240
+
241
+		return $contexts;
242
+	}
243
+
244
+
245
+	/**
246
+	 * Generate select input with provided messenger options array.
247
+	 *
248
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
249
+	 *                                 labels.
250
+	 * @return string
251
+	 * @throws EE_Error
252
+	 */
253
+	public function get_messengers_select_input($messenger_options)
254
+	{
255
+		// if empty or just one value then just return an empty string
256
+		if (
257
+			empty($messenger_options)
258
+			|| ! is_array($messenger_options)
259
+			|| count($messenger_options) === 1
260
+		) {
261
+			return '';
262
+		}
263
+		// merge in default
264
+		$messenger_options = array_merge(
265
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
266
+			$messenger_options
267
+		);
268
+		$input             = new EE_Select_Input(
269
+			$messenger_options,
270
+			[
271
+				'html_name'  => 'ee_messenger_filter_by',
272
+				'html_id'    => 'ee_messenger_filter_by',
273
+				'html_class' => 'wide',
274
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
275
+			]
276
+		);
277
+
278
+		return $input->get_html_for_input();
279
+	}
280
+
281
+
282
+	/**
283
+	 * Generate select input with provided message type options array.
284
+	 *
285
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
286
+	 *                                    message type labels
287
+	 * @return string
288
+	 * @throws EE_Error
289
+	 */
290
+	public function get_message_types_select_input($message_type_options)
291
+	{
292
+		// if empty or count of options is 1 then just return an empty string
293
+		if (
294
+			empty($message_type_options)
295
+			|| ! is_array($message_type_options)
296
+			|| count($message_type_options) === 1
297
+		) {
298
+			return '';
299
+		}
300
+		// merge in default
301
+		$message_type_options = array_merge(
302
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
303
+			$message_type_options
304
+		);
305
+		$input                = new EE_Select_Input(
306
+			$message_type_options,
307
+			[
308
+				'html_name'  => 'ee_message_type_filter_by',
309
+				'html_id'    => 'ee_message_type_filter_by',
310
+				'html_class' => 'wide',
311
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
312
+			]
313
+		);
314
+
315
+		return $input->get_html_for_input();
316
+	}
317
+
318
+
319
+	/**
320
+	 * Generate select input with provide message type contexts array.
321
+	 *
322
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
323
+	 *                               context label.
324
+	 * @return string
325
+	 * @throws EE_Error
326
+	 */
327
+	public function get_contexts_for_message_types_select_input($context_options)
328
+	{
329
+		// if empty or count of options is one then just return empty string
330
+		if (
331
+			empty($context_options)
332
+			|| ! is_array($context_options)
333
+			|| count($context_options) === 1
334
+		) {
335
+			return '';
336
+		}
337
+		// merge in default
338
+		$context_options = array_merge(
339
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
340
+			$context_options
341
+		);
342
+		$input           = new EE_Select_Input(
343
+			$context_options,
344
+			[
345
+				'html_name'  => 'ee_context_filter_by',
346
+				'html_id'    => 'ee_context_filter_by',
347
+				'html_class' => 'wide',
348
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
349
+			]
350
+		);
351
+
352
+		return $input->get_html_for_input();
353
+	}
354
+
355
+
356
+	protected function _ajax_hooks()
357
+	{
358
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
359
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
360
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
361
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
362
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
363
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
364
+	}
365
+
366
+
367
+	protected function _define_page_props()
368
+	{
369
+		$this->_admin_page_title = $this->page_label;
370
+		$this->_labels           = [
371
+			'buttons'    => [
372
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
373
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
374
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
375
+			],
376
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
377
+		];
378
+	}
379
+
380
+
381
+	/**
382
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
383
+	 *
384
+	 * @access protected
385
+	 * @return void
386
+	 */
387
+	protected function _set_page_routes()
388
+	{
389
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
390
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
391
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
392
+
393
+		$this->_page_routes = [
394
+			'default'                          => [
395
+				'func'       => '_message_queue_list_table',
396
+				'capability' => 'ee_read_global_messages',
397
+			],
398
+			'global_mtps'                      => [
399
+				'func'       => '_ee_default_messages_overview_list_table',
400
+				'capability' => 'ee_read_global_messages',
401
+			],
402
+			'custom_mtps'                      => [
403
+				'func'       => '_custom_mtps_preview',
404
+				'capability' => 'ee_read_messages',
405
+			],
406
+			'add_new_message_template'         => [
407
+				'func'       => '_add_message_template',
408
+				'capability' => 'ee_edit_messages',
409
+				'noheader'   => true,
410
+			],
411
+			'edit_message_template'            => [
412
+				'func'       => '_edit_message_template',
413
+				'capability' => 'ee_edit_message',
414
+				'obj_id'     => $GRP_ID,
415
+			],
416
+			'preview_message'                  => [
417
+				'func'               => '_preview_message',
418
+				'capability'         => 'ee_read_message',
419
+				'obj_id'             => $GRP_ID,
420
+				'noheader'           => true,
421
+				'headers_sent_route' => 'display_preview_message',
422
+			],
423
+			'display_preview_message'          => [
424
+				'func'       => '_display_preview_message',
425
+				'capability' => 'ee_read_message',
426
+				'obj_id'     => $GRP_ID,
427
+			],
428
+			'insert_message_template'          => [
429
+				'func'       => '_insert_or_update_message_template',
430
+				'capability' => 'ee_edit_messages',
431
+				'args'       => ['new' => true],
432
+				'noheader'   => true,
433
+			],
434
+			'update_message_template'          => [
435
+				'func'       => '_insert_or_update_message_template',
436
+				'capability' => 'ee_edit_message',
437
+				'obj_id'     => $GRP_ID,
438
+				'args'       => ['new' => false],
439
+				'noheader'   => true,
440
+			],
441
+			'trash_message_template'           => [
442
+				'func'       => '_trash_or_restore_message_template',
443
+				'capability' => 'ee_delete_message',
444
+				'obj_id'     => $GRP_ID,
445
+				'args'       => ['trash' => true, 'all' => true],
446
+				'noheader'   => true,
447
+			],
448
+			'trash_message_template_context'   => [
449
+				'func'       => '_trash_or_restore_message_template',
450
+				'capability' => 'ee_delete_message',
451
+				'obj_id'     => $GRP_ID,
452
+				'args'       => ['trash' => true],
453
+				'noheader'   => true,
454
+			],
455
+			'restore_message_template'         => [
456
+				'func'       => '_trash_or_restore_message_template',
457
+				'capability' => 'ee_delete_message',
458
+				'obj_id'     => $GRP_ID,
459
+				'args'       => ['trash' => false, 'all' => true],
460
+				'noheader'   => true,
461
+			],
462
+			'restore_message_template_context' => [
463
+				'func'       => '_trash_or_restore_message_template',
464
+				'capability' => 'ee_delete_message',
465
+				'obj_id'     => $GRP_ID,
466
+				'args'       => ['trash' => false],
467
+				'noheader'   => true,
468
+			],
469
+			'delete_message_template'          => [
470
+				'func'       => '_delete_message_template',
471
+				'capability' => 'ee_delete_message',
472
+				'obj_id'     => $GRP_ID,
473
+				'noheader'   => true,
474
+			],
475
+			'reset_to_default'                 => [
476
+				'func'       => '_reset_to_default_template',
477
+				'capability' => 'ee_edit_message',
478
+				'obj_id'     => $GRP_ID,
479
+				'noheader'   => true,
480
+			],
481
+			'settings'                         => [
482
+				'func'       => '_settings',
483
+				'capability' => 'manage_options',
484
+			],
485
+			'update_global_settings'           => [
486
+				'func'       => '_update_global_settings',
487
+				'capability' => 'manage_options',
488
+				'noheader'   => true,
489
+			],
490
+			'generate_now'                     => [
491
+				'func'       => '_generate_now',
492
+				'capability' => 'ee_send_message',
493
+				'noheader'   => true,
494
+			],
495
+			'generate_and_send_now'            => [
496
+				'func'       => '_generate_and_send_now',
497
+				'capability' => 'ee_send_message',
498
+				'noheader'   => true,
499
+			],
500
+			'queue_for_resending'              => [
501
+				'func'       => '_queue_for_resending',
502
+				'capability' => 'ee_send_message',
503
+				'noheader'   => true,
504
+			],
505
+			'send_now'                         => [
506
+				'func'       => '_send_now',
507
+				'capability' => 'ee_send_message',
508
+				'noheader'   => true,
509
+			],
510
+			'delete_ee_message'                => [
511
+				'func'       => '_delete_ee_messages',
512
+				'capability' => 'ee_delete_messages',
513
+				'noheader'   => true,
514
+			],
515
+			'delete_ee_messages'               => [
516
+				'func'       => '_delete_ee_messages',
517
+				'capability' => 'ee_delete_messages',
518
+				'noheader'   => true,
519
+				'obj_id'     => $MSG_ID,
520
+			],
521
+		];
522
+	}
523
+
524
+
525
+	protected function _set_page_config()
526
+	{
527
+		$this->_page_config = [
528
+			'default'                  => [
529
+				'nav'           => [
530
+					'label' => esc_html__('Message Activity', 'event_espresso'),
531
+					'order' => 10,
532
+				],
533
+				'list_table'    => 'EE_Message_List_Table',
534
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
535
+				'require_nonce' => false,
536
+			],
537
+			'global_mtps'              => [
538
+				'nav'           => [
539
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
540
+					'order' => 20,
541
+				],
542
+				'list_table'    => 'Messages_Template_List_Table',
543
+				'help_tabs'     => [
544
+					'messages_overview_help_tab'                                => [
545
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
546
+						'filename' => 'messages_overview',
547
+					],
548
+					'messages_overview_messages_table_column_headings_help_tab' => [
549
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
550
+						'filename' => 'messages_overview_table_column_headings',
551
+					],
552
+					'messages_overview_messages_filters_help_tab'               => [
553
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
554
+						'filename' => 'messages_overview_filters',
555
+					],
556
+					'messages_overview_messages_views_help_tab'                 => [
557
+						'title'    => esc_html__('Message Views', 'event_espresso'),
558
+						'filename' => 'messages_overview_views',
559
+					],
560
+					'message_overview_message_types_help_tab'                   => [
561
+						'title'    => esc_html__('Message Types', 'event_espresso'),
562
+						'filename' => 'messages_overview_types',
563
+					],
564
+					'messages_overview_messengers_help_tab'                     => [
565
+						'title'    => esc_html__('Messengers', 'event_espresso'),
566
+						'filename' => 'messages_overview_messengers',
567
+					],
568
+				],
569
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
570
+				// 'help_tour'     => array('Messages_Overview_Help_Tour'),
571
+				'require_nonce' => false,
572
+			],
573
+			'custom_mtps'              => [
574
+				'nav'           => [
575
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
576
+					'order' => 30,
577
+				],
578
+				'help_tabs'     => [],
579
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
580
+				// 'help_tour'     => array(),
581
+				'require_nonce' => false,
582
+			],
583
+			'add_new_message_template' => [
584
+				'nav'           => [
585
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
586
+					'order'      => 5,
587
+					'persistent' => false,
588
+				],
589
+				'require_nonce' => false,
590
+			],
591
+			'edit_message_template'    => [
592
+				'labels'        => [
593
+					'buttons'    => [
594
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
595
+					],
596
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
597
+				],
598
+				'nav'           => [
599
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
600
+					'order'      => 5,
601
+					'persistent' => false,
602
+					'url'        => '',
603
+				],
604
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
605
+				'has_metaboxes' => true,
606
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
607
+				// 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
608
+				'help_tabs'     => [
609
+					'edit_message_template'            => [
610
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
611
+						'callback' => 'edit_message_template_help_tab',
612
+					],
613
+					'message_templates_help_tab'       => [
614
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
615
+						'filename' => 'messages_templates',
616
+					],
617
+					'message_template_shortcodes'      => [
618
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
619
+						'callback' => 'message_template_shortcodes_help_tab',
620
+					],
621
+					'message_preview_help_tab'         => [
622
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
623
+						'filename' => 'messages_preview',
624
+					],
625
+					'messages_overview_other_help_tab' => [
626
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
627
+						'filename' => 'messages_overview_other',
628
+					],
629
+				],
630
+				'require_nonce' => false,
631
+			],
632
+			'display_preview_message'  => [
633
+				'nav'           => [
634
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
635
+					'order'      => 5,
636
+					'url'        => '',
637
+					'persistent' => false,
638
+				],
639
+				'help_tabs'     => [
640
+					'preview_message' => [
641
+						'title'    => esc_html__('About Previews', 'event_espresso'),
642
+						'callback' => 'preview_message_help_tab',
643
+					],
644
+				],
645
+				'require_nonce' => false,
646
+			],
647
+			'settings'                 => [
648
+				'nav'           => [
649
+					'label' => esc_html__('Settings', 'event_espresso'),
650
+					'order' => 40,
651
+				],
652
+				'metaboxes'     => ['_messages_settings_metaboxes'],
653
+				'help_tabs'     => [
654
+					'messages_settings_help_tab'               => [
655
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
656
+						'filename' => 'messages_settings',
657
+					],
658
+					'messages_settings_message_types_help_tab' => [
659
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
660
+						'filename' => 'messages_settings_message_types',
661
+					],
662
+					'messages_settings_messengers_help_tab'    => [
663
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
664
+						'filename' => 'messages_settings_messengers',
665
+					],
666
+				],
667
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
668
+				// 'help_tour'     => array('Messages_Settings_Help_Tour'),
669
+				'require_nonce' => false,
670
+			],
671
+		];
672
+	}
673
+
674
+
675
+	protected function _add_screen_options()
676
+	{
677
+		// todo
678
+	}
679
+
680
+
681
+	protected function _add_screen_options_global_mtps()
682
+	{
683
+		/**
684
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
685
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
686
+		 */
687
+		$page_title              = $this->_admin_page_title;
688
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
689
+		$this->_per_page_screen_option();
690
+		$this->_admin_page_title = $page_title;
691
+	}
692
+
693
+
694
+	protected function _add_screen_options_default()
695
+	{
696
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
697
+		$this->_per_page_screen_option();
698
+	}
699
+
700
+
701
+	// none of the below group are currently used for Messages
702
+	protected function _add_feature_pointers()
703
+	{
704
+	}
705
+
706
+
707
+	public function admin_init()
708
+	{
709
+	}
710
+
711
+
712
+	public function admin_notices()
713
+	{
714
+	}
715
+
716
+
717
+	public function admin_footer_scripts()
718
+	{
719
+	}
720
+
721
+
722
+	public function messages_help_tab()
723
+	{
724
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
725
+	}
726
+
727
+
728
+	public function messengers_help_tab()
729
+	{
730
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
731
+	}
732
+
733
+
734
+	public function message_types_help_tab()
735
+	{
736
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
737
+	}
738
+
739
+
740
+	public function messages_overview_help_tab()
741
+	{
742
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
743
+	}
744
+
745
+
746
+	public function message_templates_help_tab()
747
+	{
748
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
749
+	}
750
+
751
+
752
+	public function edit_message_template_help_tab()
753
+	{
754
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
755
+						. esc_attr__('Editor Title', 'event_espresso')
756
+						. '" />';
757
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
758
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
759
+						. '" />';
760
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
761
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
762
+						. '" />';
763
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
764
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
765
+						. '" />';
766
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
767
+						. esc_attr__('Publish Metabox', 'event_espresso')
768
+						. '" />';
769
+		EEH_Template::display_template(
770
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
771
+			$args
772
+		);
773
+	}
774
+
775
+
776
+	/**
777
+	 * @throws ReflectionException
778
+	 * @throws EE_Error
779
+	 */
780
+	public function message_template_shortcodes_help_tab()
781
+	{
782
+		$this->_set_shortcodes();
783
+		$args['shortcodes'] = $this->_shortcodes;
784
+		EEH_Template::display_template(
785
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
786
+			$args
787
+		);
788
+	}
789
+
790
+
791
+	public function preview_message_help_tab()
792
+	{
793
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
794
+	}
795
+
796
+
797
+	public function settings_help_tab()
798
+	{
799
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
800
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
801
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
802
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
803
+		$args['img3'] = '<div class="switch">'
804
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
805
+						. ' type="checkbox" checked="checked">'
806
+						. '<label for="ee-on-off-toggle-on"></label>'
807
+						. '</div>';
808
+		$args['img4'] = '<div class="switch">'
809
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
810
+						. ' type="checkbox">'
811
+						. '<label for="ee-on-off-toggle-on"></label>'
812
+						. '</div>';
813
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
814
+	}
815
+
816
+
817
+	public function load_scripts_styles()
818
+	{
819
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
820
+		wp_enqueue_style('espresso_ee_msg');
821
+
822
+		wp_register_script(
823
+			'ee-messages-settings',
824
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
825
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
826
+			EVENT_ESPRESSO_VERSION,
827
+			true
828
+		);
829
+		wp_register_script(
830
+			'ee-msg-list-table-js',
831
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
832
+			['ee-dialog'],
833
+			EVENT_ESPRESSO_VERSION
834
+		);
835
+	}
836
+
837
+
838
+	public function load_scripts_styles_default()
839
+	{
840
+		wp_enqueue_script('ee-msg-list-table-js');
841
+	}
842
+
843
+
844
+	public function wp_editor_css($mce_css)
845
+	{
846
+		// if we're on the edit_message_template route
847
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
848
+			$message_type_name = $this->_active_message_type_name;
849
+
850
+			// we're going to REPLACE the existing mce css
851
+			// we need to get the css file location from the active messenger
852
+			$mce_css = $this->_active_messenger->get_variation(
853
+				$this->_template_pack,
854
+				$message_type_name,
855
+				true,
856
+				'wpeditor',
857
+				$this->_variation
858
+			);
859
+		}
860
+
861
+		return $mce_css;
862
+	}
863
+
864
+
865
+	/**
866
+	 * @throws EE_Error
867
+	 * @throws ReflectionException
868
+	 */
869
+	public function load_scripts_styles_edit_message_template()
870
+	{
871
+
872
+		$this->_set_shortcodes();
873
+
874
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
875
+			esc_html__(
876
+				'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.',
877
+				'event_espresso'
878
+			),
879
+			$this->_message_template_group->messenger_obj()->label['singular'],
880
+			$this->_message_template_group->message_type_obj()->label['singular']
881
+		);
882
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
883
+			'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?',
884
+			'event_espresso'
885
+		);
886
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
887
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
888
+			'event_espresso'
889
+		);
890
+
891
+		wp_register_script(
892
+			'ee_msgs_edit_js',
893
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
894
+			['jquery'],
895
+			EVENT_ESPRESSO_VERSION
896
+		);
897
+
898
+		wp_enqueue_script('ee_admin_js');
899
+		wp_enqueue_script('ee_msgs_edit_js');
900
+
901
+		// add in special css for tiny_mce
902
+		add_filter('mce_css', [$this, 'wp_editor_css']);
903
+	}
904
+
905
+
906
+	/**
907
+	 * @throws EE_Error
908
+	 * @throws ReflectionException
909
+	 */
910
+	public function load_scripts_styles_display_preview_message()
911
+	{
912
+		$this->_set_message_template_group();
913
+		if ($this->_active_messenger_name) {
914
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
915
+				$this->_active_messenger_name
916
+			);
917
+		}
918
+
919
+		wp_enqueue_style(
920
+			'espresso_preview_css',
921
+			$this->_active_messenger->get_variation(
922
+				$this->_template_pack,
923
+				$this->_active_message_type_name,
924
+				true,
925
+				'preview',
926
+				$this->_variation
927
+			)
928
+		);
929
+	}
930
+
931
+
932
+	public function load_scripts_styles_settings()
933
+	{
934
+		wp_register_style(
935
+			'ee-message-settings',
936
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
937
+			[],
938
+			EVENT_ESPRESSO_VERSION
939
+		);
940
+		wp_enqueue_style('ee-text-links');
941
+		wp_enqueue_style('ee-message-settings');
942
+		wp_enqueue_script('ee-messages-settings');
943
+	}
944
+
945
+
946
+	/**
947
+	 * set views array for List Table
948
+	 */
949
+	public function _set_list_table_views_global_mtps()
950
+	{
951
+		$this->_views = [
952
+			'in_use' => [
953
+				'slug'  => 'in_use',
954
+				'label' => esc_html__('In Use', 'event_espresso'),
955
+				'count' => 0,
956
+			],
957
+		];
958
+	}
959
+
960
+
961
+	/**
962
+	 * Set views array for the Custom Template List Table
963
+	 */
964
+	public function _set_list_table_views_custom_mtps()
965
+	{
966
+		$this->_set_list_table_views_global_mtps();
967
+		$this->_views['in_use']['bulk_action'] = [
968
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
969
+		];
970
+	}
971
+
972
+
973
+	/**
974
+	 * set views array for message queue list table
975
+	 *
976
+	 * @throws InvalidDataTypeException
977
+	 * @throws InvalidInterfaceException
978
+	 * @throws InvalidArgumentException
979
+	 * @throws EE_Error
980
+	 * @throws ReflectionException
981
+	 */
982
+	public function _set_list_table_views_default()
983
+	{
984
+		EE_Registry::instance()->load_helper('Template');
985
+
986
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
987
+			'ee_send_message',
988
+			'message_list_table_bulk_actions'
989
+		)
990
+			? [
991
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
992
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
993
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
994
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
995
+			]
996
+			: [];
997
+
998
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
999
+			'ee_delete_messages',
1000
+			'message_list_table_bulk_actions'
1001
+		)
1002
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1003
+			: [];
1004
+
1005
+
1006
+		$this->_views = [
1007
+			'all' => [
1008
+				'slug'        => 'all',
1009
+				'label'       => esc_html__('All', 'event_espresso'),
1010
+				'count'       => 0,
1011
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1012
+			],
1013
+		];
1014
+
1015
+
1016
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
1017
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1018
+				continue;
1019
+			}
1020
+			$status_bulk_actions = $common_bulk_actions;
1021
+			// unset bulk actions not applying to status
1022
+			if (! empty($status_bulk_actions)) {
1023
+				switch ($status) {
1024
+					case EEM_Message::status_idle:
1025
+					case EEM_Message::status_resend:
1026
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1027
+						break;
1028
+
1029
+					case EEM_Message::status_failed:
1030
+					case EEM_Message::status_debug_only:
1031
+					case EEM_Message::status_messenger_executing:
1032
+						$status_bulk_actions = [];
1033
+						break;
1034
+
1035
+					case EEM_Message::status_incomplete:
1036
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1037
+						break;
1038
+
1039
+					case EEM_Message::status_retry:
1040
+					case EEM_Message::status_sent:
1041
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1042
+						break;
1043
+				}
1044
+			}
1045
+
1046
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1047
+			if ($status === EEM_Message::status_messenger_executing) {
1048
+				continue;
1049
+			}
1050
+
1051
+			$this->_views[ strtolower($status) ] = [
1052
+				'slug'        => strtolower($status),
1053
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1054
+				'count'       => 0,
1055
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1056
+			];
1057
+		}
1058
+	}
1059
+
1060
+
1061
+	/**
1062
+	 * @throws EE_Error
1063
+	 */
1064
+	protected function _ee_default_messages_overview_list_table()
1065
+	{
1066
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1067
+		$this->display_admin_list_table_page_with_no_sidebar();
1068
+	}
1069
+
1070
+
1071
+	/**
1072
+	 * @throws EE_Error
1073
+	 * @throws ReflectionException
1074
+	 */
1075
+	protected function _message_queue_list_table()
1076
+	{
1077
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1078
+		$this->_template_args['per_column']        = 6;
1079
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1080
+		$this->_template_args['before_list_table'] = '<h3>'
1081
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1082
+													 . '</h3>';
1083
+		$this->display_admin_list_table_page_with_no_sidebar();
1084
+	}
1085
+
1086
+
1087
+	/**
1088
+	 * @throws EE_Error
1089
+	 */
1090
+	protected function _message_legend_items()
1091
+	{
1092
+
1093
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1094
+		$action_items       = [];
1095
+
1096
+		foreach ($action_css_classes as $action_item => $action_details) {
1097
+			if ($action_item === 'see_notifications_for') {
1098
+				continue;
1099
+			}
1100
+			$action_items[ $action_item ] = [
1101
+				'class' => $action_details['css_class'],
1102
+				'desc'  => $action_details['label'],
1103
+			];
1104
+		}
1105
+
1106
+		/** @var array $status_items status legend setup */
1107
+		$status_items = [
1108
+			'sent_status'                => [
1109
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1110
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1111
+			],
1112
+			'idle_status'                => [
1113
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1114
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1115
+			],
1116
+			'failed_status'              => [
1117
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1118
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1119
+			],
1120
+			'messenger_executing_status' => [
1121
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1122
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1123
+			],
1124
+			'resend_status'              => [
1125
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1126
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1127
+			],
1128
+			'incomplete_status'          => [
1129
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1130
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1131
+			],
1132
+			'retry_status'               => [
1133
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1134
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1135
+			],
1136
+		];
1137
+		if (EEM_Message::debug()) {
1138
+			$status_items['debug_only_status'] = [
1139
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1140
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1141
+			];
1142
+		}
1143
+
1144
+		return array_merge($action_items, $status_items);
1145
+	}
1146
+
1147
+
1148
+	/**
1149
+	 * @throws EE_Error
1150
+	 */
1151
+	protected function _custom_mtps_preview()
1152
+	{
1153
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1154
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1155
+												. ' alt="' . esc_attr__(
1156
+													'Preview Custom Message Templates screenshot',
1157
+													'event_espresso'
1158
+												) . '" />';
1159
+		$this->_template_args['preview_text'] = '<strong>'
1160
+												. esc_html__(
1161
+													'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.',
1162
+													'event_espresso'
1163
+												)
1164
+												. '</strong>';
1165
+
1166
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1167
+	}
1168
+
1169
+
1170
+	/**
1171
+	 * get_message_templates
1172
+	 * This gets all the message templates for listing on the overview list.
1173
+	 *
1174
+	 * @access public
1175
+	 * @param int    $per_page the amount of templates groups to show per page
1176
+	 * @param string $type     the current _view we're getting templates for
1177
+	 * @param bool   $count    return count?
1178
+	 * @param bool   $all      disregard any paging info (get all data);
1179
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1180
+	 * @return array
1181
+	 * @throws EE_Error
1182
+	 * @throws InvalidArgumentException
1183
+	 * @throws InvalidDataTypeException
1184
+	 * @throws InvalidInterfaceException
1185
+	 */
1186
+	public function get_message_templates(
1187
+		$per_page = 10,
1188
+		$type = 'in_use',
1189
+		$count = false,
1190
+		$all = false,
1191
+		$global = true
1192
+	) {
1193
+
1194
+		$MTP = EEM_Message_Template_Group::instance();
1195
+
1196
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1197
+		$this->request->setRequestParam('orderby', $orderby);
1198
+
1199
+		$order        = $this->request->getRequestParam('order', 'ASC');
1200
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1201
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1202
+
1203
+		$offset = ($current_page - 1) * $per_page;
1204
+		$limit  = $all ? null : [$offset, $per_page];
1205
+
1206
+		// options will match what is in the _views array property
1207
+		switch ($type) {
1208
+			case 'in_use':
1209
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1210
+				break;
1211
+			default:
1212
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1213
+		}
1214
+
1215
+		return $templates;
1216
+	}
1217
+
1218
+
1219
+	/**
1220
+	 * filters etc might need a list of installed message_types
1221
+	 *
1222
+	 * @return array an array of message type objects
1223
+	 */
1224
+	public function get_installed_message_types()
1225
+	{
1226
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1227
+		$installed               = [];
1228
+
1229
+		foreach ($installed_message_types as $message_type) {
1230
+			$installed[ $message_type->name ] = $message_type;
1231
+		}
1232
+
1233
+		return $installed;
1234
+	}
1235
+
1236
+
1237
+	/**
1238
+	 * _add_message_template
1239
+	 *
1240
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1241
+	 *
1242
+	 * @param string $message_type
1243
+	 * @param string $messenger
1244
+	 * @param string $GRP_ID
1245
+	 *
1246
+	 * @throws EE_error
1247
+	 * @throws ReflectionException
1248
+	 */
1249
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1250
+	{
1251
+		// set values override any request data
1252
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1253
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1254
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1255
+
1256
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1257
+		if (empty($message_type) || empty($messenger)) {
1258
+			throw new EE_Error(
1259
+				esc_html__(
1260
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1261
+					'event_espresso'
1262
+				)
1263
+			);
1264
+		}
1265
+
1266
+		// we need the GRP_ID for the template being used as the base for the new template
1267
+		if (empty($GRP_ID)) {
1268
+			throw new EE_Error(
1269
+				esc_html__(
1270
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1271
+					'event_espresso'
1272
+				)
1273
+			);
1274
+		}
1275
+
1276
+		// let's just make sure the template gets generated!
1277
+
1278
+		// we need to reassign some variables for what the insert is expecting
1279
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1280
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1281
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1282
+
1283
+		$this->_insert_or_update_message_template(true);
1284
+	}
1285
+
1286
+
1287
+	/**
1288
+	 * public wrapper for the _add_message_template method
1289
+	 *
1290
+	 * @param string $message_type     message type slug
1291
+	 * @param string $messenger        messenger slug
1292
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1293
+	 *                                 off of.
1294
+	 * @throws EE_error
1295
+	 * @throws ReflectionException
1296
+	 */
1297
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1298
+	{
1299
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1300
+	}
1301
+
1302
+
1303
+	/**
1304
+	 * _edit_message_template
1305
+	 *
1306
+	 * @access protected
1307
+	 * @return void
1308
+	 * @throws InvalidIdentifierException
1309
+	 * @throws DomainException
1310
+	 * @throws EE_Error
1311
+	 * @throws InvalidArgumentException
1312
+	 * @throws ReflectionException
1313
+	 * @throws InvalidDataTypeException
1314
+	 * @throws InvalidInterfaceException
1315
+	 */
1316
+	protected function _edit_message_template()
1317
+	{
1318
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1319
+		$template_fields = '';
1320
+		$sidebar_fields  = '';
1321
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1322
+		// valid html in the templates.
1323
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1324
+
1325
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1326
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1327
+
1328
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1329
+		$message_template_group = $this->_message_template_group;
1330
+		$c_label                = $message_template_group->context_label();
1331
+		$c_config               = $message_template_group->contexts_config();
1332
+
1333
+		reset($c_config);
1334
+		$context = $this->request->getRequestParam('context', key($c_config));
1335
+		$context = strtolower($context);
1336
+
1337
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1338
+
1339
+		$edit_message_template_form_url = add_query_arg(
1340
+			['action' => $action, 'noheader' => true],
1341
+			EE_MSG_ADMIN_URL
1342
+		);
1343
+
1344
+		// set active messenger for this view
1345
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1346
+			$message_template_group->messenger()
1347
+		);
1348
+		$this->_active_message_type_name = $message_template_group->message_type();
1349
+
1350
+
1351
+		// Do we have any validation errors?
1352
+		$validators = $this->_get_transient();
1353
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1354
+
1355
+
1356
+		// we need to assemble the title from Various details
1357
+		$context_label = sprintf(
1358
+			esc_html__('(%s %s)', 'event_espresso'),
1359
+			$c_config[ $context ]['label'],
1360
+			ucwords($c_label['label'])
1361
+		);
1362
+
1363
+		$title = sprintf(
1364
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1365
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1366
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1367
+			$context_label
1368
+		);
1369
+
1370
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1371
+		$this->_template_args['message_template'] = $message_template_group;
1372
+		$this->_template_args['is_extra_fields']  = false;
1373
+
1374
+
1375
+		// let's get EEH_MSG_Template so we can get template form fields
1376
+		$template_field_structure = EEH_MSG_Template::get_fields(
1377
+			$message_template_group->messenger(),
1378
+			$message_template_group->message_type()
1379
+		);
1380
+
1381
+		if (! $template_field_structure) {
1382
+			$template_field_structure = false;
1383
+			$template_fields          = esc_html__(
1384
+				'There was an error in assembling the fields for this display (you should see an error message)',
1385
+				'event_espresso'
1386
+			);
1387
+		}
1388
+
1389
+
1390
+		$message_templates = $message_template_group->context_templates();
1391
+
1392
+
1393
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1394
+		// will get handled in the "extra" array.
1395
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1396
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1397
+				unset($template_field_structure[ $context ][ $reference_field ]);
1398
+			}
1399
+		}
1400
+
1401
+		// let's loop through the template_field_structure and actually assemble the input fields!
1402
+		if (! empty($template_field_structure)) {
1403
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1404
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1405
+				// the extra array and reset them.
1406
+				if ($template_field === 'extra') {
1407
+					$this->_template_args['is_extra_fields'] = true;
1408
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1409
+						$message_template = $message_templates[ $context ][ $reference_field ];
1410
+						$content          = $message_template instanceof EE_Message_Template
1411
+							? $message_template->get('MTP_content')
1412
+							: '';
1413
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1414
+							// let's verify if we need this extra field via the shortcodes parameter.
1415
+							$continue = false;
1416
+							if (isset($extra_array['shortcodes_required'])) {
1417
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1418
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1419
+										$continue = true;
1420
+									}
1421
+								}
1422
+								if ($continue) {
1423
+									continue;
1424
+								}
1425
+							}
1426
+
1427
+							$field_id                                  = $reference_field
1428
+																		 . '-'
1429
+																		 . $extra_field
1430
+																		 . '-content';
1431
+							$template_form_fields[ $field_id ]         = $extra_array;
1432
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1433
+																		 . $reference_field
1434
+																		 . '][content]['
1435
+																		 . $extra_field . ']';
1436
+							$css_class                                 = isset($extra_array['css_class'])
1437
+								? $extra_array['css_class']
1438
+								: '';
1439
+
1440
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1441
+																			  && in_array($extra_field, $v_fields, true)
1442
+																			  && (
1443
+																				  is_array($validators[ $extra_field ])
1444
+																				  && isset($validators[ $extra_field ]['msg'])
1445
+																			  )
1446
+								? 'validate-error ' . $css_class
1447
+								: $css_class;
1448
+
1449
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1450
+																		  && isset($content[ $extra_field ])
1451
+								? $content[ $extra_field ]
1452
+								: '';
1453
+
1454
+							// do we have a validation error?  if we do then let's use that value instead
1455
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1456
+								? $validators[ $extra_field ]['value']
1457
+								: $template_form_fields[ $field_id ]['value'];
1458
+
1459
+
1460
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1461
+
1462
+							// shortcode selector
1463
+							$field_name_to_use                                   = $extra_field === 'main'
1464
+								? 'content'
1465
+								: $extra_field;
1466
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1467
+								$field_name_to_use,
1468
+								$field_id
1469
+							);
1470
+						}
1471
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1472
+						$template_field_template_name_id = $reference_field . '-name';
1473
+
1474
+						$template_form_fields[ $template_field_MTP_id ] = [
1475
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1476
+							'label'      => null,
1477
+							'input'      => 'hidden',
1478
+							'type'       => 'int',
1479
+							'required'   => false,
1480
+							'validation' => false,
1481
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1482
+							'css_class'  => '',
1483
+							'format'     => '%d',
1484
+							'db-col'     => 'MTP_ID',
1485
+						];
1486
+
1487
+						$template_form_fields[ $template_field_template_name_id ] = [
1488
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1489
+							'label'      => null,
1490
+							'input'      => 'hidden',
1491
+							'type'       => 'string',
1492
+							'required'   => false,
1493
+							'validation' => true,
1494
+							'value'      => $reference_field,
1495
+							'css_class'  => '',
1496
+							'format'     => '%s',
1497
+							'db-col'     => 'MTP_template_field',
1498
+						];
1499
+					}
1500
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1501
+				} else {
1502
+					$field_id                                   = $template_field . '-content';
1503
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1504
+					$template_form_fields[ $field_id ]['name']  =
1505
+						'MTP_template_fields[' . $template_field . '][content]';
1506
+					$message_template                           =
1507
+						isset($message_templates[ $context ][ $template_field ])
1508
+							? $message_templates[ $context ][ $template_field ]
1509
+							: null;
1510
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1511
+																  && is_array($message_templates[ $context ])
1512
+																  && $message_template instanceof EE_Message_Template
1513
+						? $message_template->get('MTP_content')
1514
+						: '';
1515
+
1516
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1517
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1518
+						? $validators[ $template_field ]['value']
1519
+						: $template_form_fields[ $field_id ]['value'];
1520
+
1521
+
1522
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1523
+					$css_class                                      = isset($field_setup_array['css_class'])
1524
+						? $field_setup_array['css_class']
1525
+						: '';
1526
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1527
+																	  && in_array($template_field, $v_fields, true)
1528
+																	  && isset($validators[ $template_field ]['msg'])
1529
+						? 'validate-error ' . $css_class
1530
+						: $css_class;
1531
+
1532
+					// shortcode selector
1533
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1534
+						$template_field,
1535
+						$field_id
1536
+					);
1537
+				}
1538
+
1539
+				// k took care of content field(s) now let's take care of others.
1540
+
1541
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1542
+				$template_field_field_template_name_id = $template_field . '-name';
1543
+
1544
+				// foreach template field there are actually two form fields created
1545
+				$template_form_fields[ $template_field_MTP_id ] = [
1546
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1547
+					'label'      => null,
1548
+					'input'      => 'hidden',
1549
+					'type'       => 'int',
1550
+					'required'   => false,
1551
+					'validation' => true,
1552
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1553
+					'css_class'  => '',
1554
+					'format'     => '%d',
1555
+					'db-col'     => 'MTP_ID',
1556
+				];
1557
+
1558
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1559
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1560
+					'label'      => null,
1561
+					'input'      => 'hidden',
1562
+					'type'       => 'string',
1563
+					'required'   => false,
1564
+					'validation' => true,
1565
+					'value'      => $template_field,
1566
+					'css_class'  => '',
1567
+					'format'     => '%s',
1568
+					'db-col'     => 'MTP_template_field',
1569
+				];
1570
+			}
1571
+
1572
+			// add other fields
1573
+			$template_form_fields['ee-msg-current-context'] = [
1574
+				'name'       => 'MTP_context',
1575
+				'label'      => null,
1576
+				'input'      => 'hidden',
1577
+				'type'       => 'string',
1578
+				'required'   => false,
1579
+				'validation' => true,
1580
+				'value'      => $context,
1581
+				'css_class'  => '',
1582
+				'format'     => '%s',
1583
+				'db-col'     => 'MTP_context',
1584
+			];
1585
+
1586
+			$template_form_fields['ee-msg-grp-id'] = [
1587
+				'name'       => 'GRP_ID',
1588
+				'label'      => null,
1589
+				'input'      => 'hidden',
1590
+				'type'       => 'int',
1591
+				'required'   => false,
1592
+				'validation' => true,
1593
+				'value'      => $GRP_ID,
1594
+				'css_class'  => '',
1595
+				'format'     => '%d',
1596
+				'db-col'     => 'GRP_ID',
1597
+			];
1598
+
1599
+			$template_form_fields['ee-msg-messenger'] = [
1600
+				'name'       => 'MTP_messenger',
1601
+				'label'      => null,
1602
+				'input'      => 'hidden',
1603
+				'type'       => 'string',
1604
+				'required'   => false,
1605
+				'validation' => true,
1606
+				'value'      => $message_template_group->messenger(),
1607
+				'css_class'  => '',
1608
+				'format'     => '%s',
1609
+				'db-col'     => 'MTP_messenger',
1610
+			];
1611
+
1612
+			$template_form_fields['ee-msg-message-type'] = [
1613
+				'name'       => 'MTP_message_type',
1614
+				'label'      => null,
1615
+				'input'      => 'hidden',
1616
+				'type'       => 'string',
1617
+				'required'   => false,
1618
+				'validation' => true,
1619
+				'value'      => $message_template_group->message_type(),
1620
+				'css_class'  => '',
1621
+				'format'     => '%s',
1622
+				'db-col'     => 'MTP_message_type',
1623
+			];
1624
+
1625
+			$sidebar_form_fields['ee-msg-is-global'] = [
1626
+				'name'       => 'MTP_is_global',
1627
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1628
+				'input'      => 'hidden',
1629
+				'type'       => 'int',
1630
+				'required'   => false,
1631
+				'validation' => true,
1632
+				'value'      => $message_template_group->get('MTP_is_global'),
1633
+				'css_class'  => '',
1634
+				'format'     => '%d',
1635
+				'db-col'     => 'MTP_is_global',
1636
+			];
1637
+
1638
+			$sidebar_form_fields['ee-msg-is-override'] = [
1639
+				'name'       => 'MTP_is_override',
1640
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1641
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1642
+				'type'       => 'int',
1643
+				'required'   => false,
1644
+				'validation' => true,
1645
+				'value'      => $message_template_group->get('MTP_is_override'),
1646
+				'css_class'  => '',
1647
+				'format'     => '%d',
1648
+				'db-col'     => 'MTP_is_override',
1649
+			];
1650
+
1651
+			$sidebar_form_fields['ee-msg-is-active'] = [
1652
+				'name'       => 'MTP_is_active',
1653
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1654
+				'input'      => 'hidden',
1655
+				'type'       => 'int',
1656
+				'required'   => false,
1657
+				'validation' => true,
1658
+				'value'      => $message_template_group->is_active(),
1659
+				'css_class'  => '',
1660
+				'format'     => '%d',
1661
+				'db-col'     => 'MTP_is_active',
1662
+			];
1663
+
1664
+			$sidebar_form_fields['ee-msg-deleted'] = [
1665
+				'name'       => 'MTP_deleted',
1666
+				'label'      => null,
1667
+				'input'      => 'hidden',
1668
+				'type'       => 'int',
1669
+				'required'   => false,
1670
+				'validation' => true,
1671
+				'value'      => $message_template_group->get('MTP_deleted'),
1672
+				'css_class'  => '',
1673
+				'format'     => '%d',
1674
+				'db-col'     => 'MTP_deleted',
1675
+			];
1676
+			$sidebar_form_fields['ee-msg-author']  = [
1677
+				'name'       => 'MTP_user_id',
1678
+				'label'      => esc_html__('Author', 'event_espresso'),
1679
+				'input'      => 'hidden',
1680
+				'type'       => 'int',
1681
+				'required'   => false,
1682
+				'validation' => false,
1683
+				'value'      => $message_template_group->user(),
1684
+				'format'     => '%d',
1685
+				'db-col'     => 'MTP_user_id',
1686
+			];
1687
+
1688
+			$sidebar_form_fields['ee-msg-route'] = [
1689
+				'name'  => 'action',
1690
+				'input' => 'hidden',
1691
+				'type'  => 'string',
1692
+				'value' => $action,
1693
+			];
1694
+
1695
+			$sidebar_form_fields['ee-msg-id']        = [
1696
+				'name'  => 'id',
1697
+				'input' => 'hidden',
1698
+				'type'  => 'int',
1699
+				'value' => $GRP_ID,
1700
+			];
1701
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1702
+				'name'  => $action . '_nonce',
1703
+				'input' => 'hidden',
1704
+				'type'  => 'string',
1705
+				'value' => wp_create_nonce($action . '_nonce'),
1706
+			];
1707
+
1708
+			$template_switch = $this->request->getRequestParam('template_switch');
1709
+			if ($template_switch) {
1710
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1711
+					'name'  => 'template_switch',
1712
+					'input' => 'hidden',
1713
+					'type'  => 'int',
1714
+					'value' => 1,
1715
+				];
1716
+			}
1717
+
1718
+
1719
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1720
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1721
+		} //end if ( !empty($template_field_structure) )
1722
+
1723
+		// set extra content for publish box
1724
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1725
+		$this->_set_publish_post_box_vars(
1726
+			'id',
1727
+			$GRP_ID,
1728
+			false,
1729
+			add_query_arg(
1730
+				['action' => 'global_mtps'],
1731
+				$this->_admin_base_url
1732
+			)
1733
+		);
1734
+
1735
+		// add preview button
1736
+		$preview_url    = parent::add_query_args_and_nonce(
1737
+			[
1738
+				'message_type' => $message_template_group->message_type(),
1739
+				'messenger'    => $message_template_group->messenger(),
1740
+				'context'      => $context,
1741
+				'GRP_ID'       => $GRP_ID,
1742
+				'evt_id'       => $EVT_ID,
1743
+				'action'       => 'preview_message',
1744
+			],
1745
+			$this->_admin_base_url
1746
+		);
1747
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1748
+						  . esc_html__('Preview', 'event_espresso')
1749
+						  . '</a>';
1750
+
1751
+
1752
+		// setup context switcher
1753
+		$context_switcher_args = [
1754
+			'page'    => 'espresso_messages',
1755
+			'action'  => 'edit_message_template',
1756
+			'id'      => $GRP_ID,
1757
+			'evt_id'  => $EVT_ID,
1758
+			'context' => $context,
1759
+			'extra'   => $preview_button,
1760
+		];
1761
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1762
+
1763
+
1764
+		// main box
1765
+		$this->_template_args['template_fields']                         = $template_fields;
1766
+		$this->_template_args['sidebar_box_id']                          = 'details';
1767
+		$this->_template_args['action']                                  = $action;
1768
+		$this->_template_args['context']                                 = $context;
1769
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1770
+		$this->_template_args['learn_more_about_message_templates_link'] =
1771
+			$this->_learn_more_about_message_templates_link();
1772
+
1773
+
1774
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1775
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1776
+			$message_template_group,
1777
+			$context,
1778
+			$context_label
1779
+		);
1780
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1781
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1782
+
1783
+		$this->_template_path = $this->_template_args['GRP_ID']
1784
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1785
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1786
+
1787
+		// send along EE_Message_Template_Group object for further template use.
1788
+		$this->_template_args['MTP'] = $message_template_group;
1789
+
1790
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1791
+			$this->_template_path,
1792
+			$this->_template_args,
1793
+			true
1794
+		);
1795
+
1796
+
1797
+		// finally, let's set the admin_page title
1798
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1799
+
1800
+
1801
+		// we need to take care of setting the shortcodes property for use elsewhere.
1802
+		$this->_set_shortcodes();
1803
+
1804
+
1805
+		// final template wrapper
1806
+		$this->display_admin_page_with_sidebar();
1807
+	}
1808
+
1809
+
1810
+	public function filter_tinymce_init($mceInit, $editor_id)
1811
+	{
1812
+		return $mceInit;
1813
+	}
1814
+
1815
+
1816
+	public function add_context_switcher()
1817
+	{
1818
+		return $this->_context_switcher;
1819
+	}
1820
+
1821
+
1822
+	/**
1823
+	 * Adds the activation/deactivation toggle for the message template context.
1824
+	 *
1825
+	 * @param EE_Message_Template_Group $message_template_group
1826
+	 * @param string                    $context
1827
+	 * @param string                    $context_label
1828
+	 * @return string
1829
+	 * @throws DomainException
1830
+	 * @throws EE_Error
1831
+	 * @throws InvalidIdentifierException
1832
+	 * @throws ReflectionException
1833
+	 */
1834
+	protected function add_active_context_element(
1835
+		EE_Message_Template_Group $message_template_group,
1836
+		$context,
1837
+		$context_label
1838
+	) {
1839
+		$template_args = [
1840
+			'context'                   => $context,
1841
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1842
+			'is_active'                 => $message_template_group->is_context_active($context),
1843
+			'on_off_action'             => $message_template_group->is_context_active($context)
1844
+				? 'context-off'
1845
+				: 'context-on',
1846
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1847
+			'message_template_group_id' => $message_template_group->ID(),
1848
+		];
1849
+		return EEH_Template::display_template(
1850
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1851
+			$template_args,
1852
+			true
1853
+		);
1854
+	}
1855
+
1856
+
1857
+	/**
1858
+	 * Ajax callback for `toggle_context_template` ajax action.
1859
+	 * Handles toggling the message context on or off.
1860
+	 *
1861
+	 * @throws EE_Error
1862
+	 * @throws InvalidArgumentException
1863
+	 * @throws InvalidDataTypeException
1864
+	 * @throws InvalidIdentifierException
1865
+	 * @throws InvalidInterfaceException
1866
+	 */
1867
+	public function toggle_context_template()
1868
+	{
1869
+		$success = true;
1870
+		// check for required data
1871
+		if (
1872
+			! (
1873
+				$this->request->requestParamIsSet('message_template_group_id')
1874
+				&& $this->request->requestParamIsSet('context')
1875
+				&& $this->request->requestParamIsSet('status')
1876
+			)
1877
+		) {
1878
+			EE_Error::add_error(
1879
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1880
+				__FILE__,
1881
+				__FUNCTION__,
1882
+				__LINE__
1883
+			);
1884
+			$success = false;
1885
+		}
1886
+
1887
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1888
+		$context = $this->request->getRequestParam('context', '');
1889
+		$status  = $this->request->getRequestParam('status', '');
1890
+
1891
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1892
+
1893
+		if ($status !== 'off' && $status !== 'on') {
1894
+			EE_Error::add_error(
1895
+				sprintf(
1896
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1897
+					$status
1898
+				),
1899
+				__FILE__,
1900
+				__FUNCTION__,
1901
+				__LINE__
1902
+			);
1903
+			$success = false;
1904
+		}
1905
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1906
+		$message_template_group    = EEM_Message_Template_Group::instance()->get_one_by_ID($message_template_group_id);
1907
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1908
+			EE_Error::add_error(
1909
+				sprintf(
1910
+					esc_html__(
1911
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1912
+						'event_espresso'
1913
+					),
1914
+					$message_template_group_id,
1915
+					'EE_Message_Template_Group'
1916
+				),
1917
+				__FILE__,
1918
+				__FUNCTION__,
1919
+				__LINE__
1920
+			);
1921
+			$success = false;
1922
+		}
1923
+		if ($success) {
1924
+			$success = $status === 'off'
1925
+				? $message_template_group->deactivate_context($context)
1926
+				: $message_template_group->activate_context($context);
1927
+		}
1928
+		$this->_template_args['success'] = $success;
1929
+		$this->_return_json();
1930
+	}
1931
+
1932
+
1933
+	public function _add_form_element_before()
1934
+	{
1935
+		return '<form method="post" action="'
1936
+			   . $this->_template_args['edit_message_template_form_url']
1937
+			   . '" id="ee-msg-edit-frm">';
1938
+	}
1939
+
1940
+
1941
+	public function _add_form_element_after()
1942
+	{
1943
+		return '</form>';
1944
+	}
1945
+
1946
+
1947
+	/**
1948
+	 * This executes switching the template pack for a message template.
1949
+	 *
1950
+	 * @throws EE_Error
1951
+	 * @throws InvalidDataTypeException
1952
+	 * @throws InvalidInterfaceException
1953
+	 * @throws InvalidArgumentException
1954
+	 * @throws ReflectionException
1955
+	 * @since 4.5.0
1956
+	 */
1957
+	public function switch_template_pack()
1958
+	{
1959
+
1960
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
1961
+		$template_pack = $this->request->getRequestParam('template_pack', '');
1962
+
1963
+		// verify we have needed values.
1964
+		if (empty($GRP_ID) || empty($template_pack)) {
1965
+			$this->_template_args['error'] = true;
1966
+			EE_Error::add_error(
1967
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1968
+				__FILE__,
1969
+				__FUNCTION__,
1970
+				__LINE__
1971
+			);
1972
+		} else {
1973
+			// get template, set the new template_pack and then reset to default
1974
+			/** @var EE_Message_Template_Group $message_template_group */
1975
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1976
+
1977
+			$message_template_group->set_template_pack_name($template_pack);
1978
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
1979
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
1980
+
1981
+			$query_args = $this->_reset_to_default_template();
1982
+
1983
+			if (empty($query_args['id'])) {
1984
+				EE_Error::add_error(
1985
+					esc_html__(
1986
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1987
+						'event_espresso'
1988
+					),
1989
+					__FILE__,
1990
+					__FUNCTION__,
1991
+					__LINE__
1992
+				);
1993
+				$this->_template_args['error'] = true;
1994
+			} else {
1995
+				$template_label       = $message_template_group->get_template_pack()->label;
1996
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1997
+				EE_Error::add_success(
1998
+					sprintf(
1999
+						esc_html__(
2000
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2001
+							'event_espresso'
2002
+						),
2003
+						$template_label,
2004
+						$template_pack_labels->template_pack
2005
+					)
2006
+				);
2007
+				// generate the redirect url for js.
2008
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2009
+
2010
+				$this->_template_args['data']['redirect_url'] = $url;
2011
+				$this->_template_args['success']              = true;
2012
+			}
2013
+
2014
+			$this->_return_json();
2015
+		}
2016
+	}
2017
+
2018
+
2019
+	/**
2020
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2021
+	 * they want.
2022
+	 *
2023
+	 * @access protected
2024
+	 * @return array|null
2025
+	 * @throws EE_Error
2026
+	 * @throws InvalidArgumentException
2027
+	 * @throws InvalidDataTypeException
2028
+	 * @throws InvalidInterfaceException
2029
+	 * @throws ReflectionException
2030
+	 */
2031
+	protected function _reset_to_default_template()
2032
+	{
2033
+
2034
+		$templates    = [];
2035
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2036
+		$messenger    = $this->request->getRequestParam('msgr');
2037
+		$message_type = $this->request->getRequestParam('mt');
2038
+		// we need to make sure we've got the info we need.
2039
+		if (! ($GRP_ID && $messenger && $message_type)) {
2040
+			EE_Error::add_error(
2041
+				esc_html__(
2042
+					'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.',
2043
+					'event_espresso'
2044
+				),
2045
+				__FILE__,
2046
+				__FUNCTION__,
2047
+				__LINE__
2048
+			);
2049
+		}
2050
+
2051
+		// all templates will be reset to whatever the defaults are
2052
+		// for the global template matching the messenger and message type.
2053
+		$success = ! empty($GRP_ID);
2054
+
2055
+		if ($success) {
2056
+			// let's first determine if the incoming template is a global template,
2057
+			// if it isn't then we need to get the global template matching messenger and message type.
2058
+			// $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2059
+
2060
+
2061
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2062
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2063
+
2064
+			if ($success) {
2065
+				// if successfully deleted, lets generate the new ones.
2066
+				// Note. We set GLOBAL to true, because resets on ANY template
2067
+				// will use the related global template defaults for regeneration.
2068
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2069
+				// HOWEVER, we DO keep the template pack and template variation set
2070
+				// for the current custom template when resetting.
2071
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2072
+			}
2073
+		}
2074
+
2075
+		// any error messages?
2076
+		if (! $success) {
2077
+			EE_Error::add_error(
2078
+				esc_html__(
2079
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2080
+					'event_espresso'
2081
+				),
2082
+				__FILE__,
2083
+				__FUNCTION__,
2084
+				__LINE__
2085
+			);
2086
+		}
2087
+
2088
+		// all good, let's add a success message!
2089
+		if ($success && ! empty($templates)) {
2090
+			// the info for the template we generated is the first element in the returned array
2091
+			// $templates = $templates[0];
2092
+			EE_Error::overwrite_success();
2093
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2094
+		}
2095
+
2096
+
2097
+		$query_args = [
2098
+			'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2099
+			'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2100
+			'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2101
+		];
2102
+
2103
+		// if called via ajax then we return query args otherwise redirect
2104
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2105
+			return $query_args;
2106
+		} else {
2107
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2108
+
2109
+			return null;
2110
+		}
2111
+	}
2112
+
2113
+
2114
+	/**
2115
+	 * Retrieve and set the message preview for display.
2116
+	 *
2117
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2118
+	 * @return string
2119
+	 * @throws ReflectionException
2120
+	 * @throws EE_Error
2121
+	 * @throws InvalidArgumentException
2122
+	 * @throws InvalidDataTypeException
2123
+	 * @throws InvalidInterfaceException
2124
+	 */
2125
+	public function _preview_message($send = false)
2126
+	{
2127
+		// first make sure we've got the necessary parameters
2128
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2129
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2130
+			EE_Error::add_error(
2131
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2132
+				__FILE__,
2133
+				__FUNCTION__,
2134
+				__LINE__
2135
+			);
2136
+		}
2137
+
2138
+		$context = $this->request->getRequestParam('context');
2139
+		// get the preview!
2140
+		$preview = EED_Messages::preview_message(
2141
+			$this->_active_message_type_name,
2142
+			$context,
2143
+			$this->_active_messenger_name,
2144
+			$send
2145
+		);
2146
+
2147
+		if ($send) {
2148
+			return $preview;
2149
+		}
2150
+
2151
+		// if we have an evt_id set on the request, use it.
2152
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2153
+
2154
+		// let's add a button to go back to the edit view
2155
+		$query_args             = [
2156
+			'id'      => $GRP_ID,
2157
+			'evt_id'  => $EVT_ID,
2158
+			'context' => $context,
2159
+			'action'  => 'edit_message_template',
2160
+		];
2161
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2162
+		$preview_button         = '<a href="'
2163
+								  . $go_back_url
2164
+								  . '" class="button-secondary messages-preview-go-back-button">'
2165
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2166
+								  . '</a>';
2167
+		$message_types          = $this->get_installed_message_types();
2168
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2169
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2170
+			? ucwords($active_messenger->label['singular'])
2171
+			: esc_html__('Unknown Messenger', 'event_espresso');
2172
+		// let's provide a helpful title for context
2173
+		$preview_title = sprintf(
2174
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2175
+			$active_messenger_label,
2176
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2177
+		);
2178
+		if (empty($preview)) {
2179
+			$this->noEventsErrorMessage();
2180
+		}
2181
+		// setup display of preview.
2182
+		$this->_admin_page_title                    = $preview_title;
2183
+		$this->_template_args['admin_page_title']   = $preview_title;
2184
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2185
+		$this->_template_args['data']['force_json'] = true;
2186
+
2187
+		return '';
2188
+	}
2189
+
2190
+
2191
+	/**
2192
+	 * Used to set an error if there are no events available for generating a preview/test send.
2193
+	 *
2194
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2195
+	 */
2196
+	protected function noEventsErrorMessage($test_send = false)
2197
+	{
2198
+		$events_url = parent::add_query_args_and_nonce(
2199
+			[
2200
+				'action' => 'default',
2201
+				'page'   => 'espresso_events',
2202
+			],
2203
+			admin_url('admin.php')
2204
+		);
2205
+		$message    = $test_send
2206
+			? esc_html__(
2207
+				'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!',
2208
+				'event_espresso'
2209
+			)
2210
+			: esc_html__(
2211
+				'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!',
2212
+				'event_espresso'
2213
+			);
2214
+
2215
+		EE_Error::add_attention(
2216
+			sprintf(
2217
+				$message,
2218
+				"<a href='{$events_url}'>",
2219
+				'</a>'
2220
+			)
2221
+		);
2222
+	}
2223
+
2224
+
2225
+	/**
2226
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2227
+	 * gets called automatically.
2228
+	 *
2229
+	 * @return void
2230
+	 * @throws EE_Error
2231
+	 * @since 4.5.0
2232
+	 *
2233
+	 */
2234
+	protected function _display_preview_message()
2235
+	{
2236
+		$this->display_admin_page_with_no_sidebar();
2237
+	}
2238
+
2239
+
2240
+	/**
2241
+	 * registers metaboxes that should show up on the "edit_message_template" page
2242
+	 *
2243
+	 * @access protected
2244
+	 * @return void
2245
+	 */
2246
+	protected function _register_edit_meta_boxes()
2247
+	{
2248
+		add_meta_box(
2249
+			'mtp_valid_shortcodes',
2250
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2251
+			[$this, 'shortcode_meta_box'],
2252
+			$this->_current_screen->id,
2253
+			'side'
2254
+		);
2255
+		add_meta_box(
2256
+			'mtp_extra_actions',
2257
+			esc_html__('Extra Actions', 'event_espresso'),
2258
+			[$this, 'extra_actions_meta_box'],
2259
+			$this->_current_screen->id,
2260
+			'side',
2261
+			'high'
2262
+		);
2263
+		add_meta_box(
2264
+			'mtp_templates',
2265
+			esc_html__('Template Styles', 'event_espresso'),
2266
+			[$this, 'template_pack_meta_box'],
2267
+			$this->_current_screen->id,
2268
+			'side',
2269
+			'high'
2270
+		);
2271
+	}
2272
+
2273
+
2274
+	/**
2275
+	 * metabox content for all template pack and variation selection.
2276
+	 *
2277
+	 * @return void
2278
+	 * @throws DomainException
2279
+	 * @throws EE_Error
2280
+	 * @throws InvalidArgumentException
2281
+	 * @throws ReflectionException
2282
+	 * @throws InvalidDataTypeException
2283
+	 * @throws InvalidInterfaceException
2284
+	 * @since 4.5.0
2285
+	 */
2286
+	public function template_pack_meta_box()
2287
+	{
2288
+		$this->_set_message_template_group();
2289
+
2290
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2291
+
2292
+		$tp_select_values = [];
2293
+
2294
+		foreach ($tp_collection as $tp) {
2295
+			// only include template packs that support this messenger and message type!
2296
+			$supports = $tp->get_supports();
2297
+			if (
2298
+				! isset($supports[ $this->_message_template_group->messenger() ])
2299
+				|| ! in_array(
2300
+					$this->_message_template_group->message_type(),
2301
+					$supports[ $this->_message_template_group->messenger() ],
2302
+					true
2303
+				)
2304
+			) {
2305
+				// not supported
2306
+				continue;
2307
+			}
2308
+
2309
+			$tp_select_values[] = [
2310
+				'text' => $tp->label,
2311
+				'id'   => $tp->dbref,
2312
+			];
2313
+		}
2314
+
2315
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2316
+		// the default template pack.  This still allows for the odd template pack to override.
2317
+		if (empty($tp_select_values)) {
2318
+			$tp_select_values[] = [
2319
+				'text' => esc_html__('Default', 'event_espresso'),
2320
+				'id'   => 'default',
2321
+			];
2322
+		}
2323
+
2324
+		// setup variation select values for the currently selected template.
2325
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2326
+			$this->_message_template_group->messenger(),
2327
+			$this->_message_template_group->message_type()
2328
+		);
2329
+		$variations_select_values = [];
2330
+		foreach ($variations as $variation => $label) {
2331
+			$variations_select_values[] = [
2332
+				'text' => $label,
2333
+				'id'   => $variation,
2334
+			];
2335
+		}
2336
+
2337
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2338
+
2339
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2340
+			'MTP_template_pack',
2341
+			$tp_select_values,
2342
+			$this->_message_template_group->get_template_pack_name()
2343
+		);
2344
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2345
+			'MTP_template_variation',
2346
+			$variations_select_values,
2347
+			$this->_message_template_group->get_template_pack_variation()
2348
+		);
2349
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2350
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2351
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2352
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2353
+
2354
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2355
+
2356
+		EEH_Template::display_template($template, $template_args);
2357
+	}
2358
+
2359
+
2360
+	/**
2361
+	 * This meta box holds any extra actions related to Message Templates
2362
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2363
+	 *
2364
+	 * @access  public
2365
+	 * @return void
2366
+	 * @throws EE_Error
2367
+	 */
2368
+	public function extra_actions_meta_box()
2369
+	{
2370
+		$template_form_fields = [];
2371
+
2372
+		$extra_args = [
2373
+			'msgr'   => $this->_message_template_group->messenger(),
2374
+			'mt'     => $this->_message_template_group->message_type(),
2375
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2376
+		];
2377
+		// first we need to see if there are any fields
2378
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2379
+
2380
+		if (! empty($fields)) {
2381
+			// yup there be fields
2382
+			foreach ($fields as $field => $config) {
2383
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2384
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2385
+				$default  = isset($config['default']) ? $config['default'] : '';
2386
+				$default  = isset($config['value']) ? $config['value'] : $default;
2387
+
2388
+				// if type is hidden and the value is empty
2389
+				// something may have gone wrong so let's correct with the defaults
2390
+				$fix                = $config['input'] === 'hidden'
2391
+									  && isset($existing[ $field ])
2392
+									  && empty($existing[ $field ])
2393
+					? $default
2394
+					: '';
2395
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2396
+					? $existing[ $field ]
2397
+					: $fix;
2398
+
2399
+				$template_form_fields[ $field_id ] = [
2400
+					'name'       => 'test_settings_fld[' . $field . ']',
2401
+					'label'      => $config['label'],
2402
+					'input'      => $config['input'],
2403
+					'type'       => $config['type'],
2404
+					'required'   => $config['required'],
2405
+					'validation' => $config['validation'],
2406
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2407
+					'css_class'  => $config['css_class'],
2408
+					'options'    => isset($config['options']) ? $config['options'] : [],
2409
+					'default'    => $default,
2410
+					'format'     => $config['format'],
2411
+				];
2412
+			}
2413
+		}
2414
+
2415
+		$test_settings_html = ! empty($template_form_fields)
2416
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2417
+			: '';
2418
+
2419
+		// print out $test_settings_fields
2420
+		if (! empty($test_settings_html)) {
2421
+			$test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2422
+			$test_settings_html .= 'name="test_button" value="';
2423
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2424
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2425
+		}
2426
+
2427
+		// and button
2428
+		$test_settings_html .= '<p>';
2429
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2430
+		$test_settings_html .= '</p>';
2431
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2432
+		$test_settings_html .= $this->get_action_link_or_button(
2433
+			'reset_to_default',
2434
+			'reset',
2435
+			$extra_args,
2436
+			'button-primary reset-default-button'
2437
+		);
2438
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2439
+		echo $test_settings_html; // already escaped
2440
+	}
2441
+
2442
+
2443
+	/**
2444
+	 * This returns the shortcode selector skeleton for a given context and field.
2445
+	 *
2446
+	 * @param string $field           The name of the field retrieving shortcodes for.
2447
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2448
+	 * @return string
2449
+	 * @throws DomainException
2450
+	 * @throws EE_Error
2451
+	 * @throws InvalidArgumentException
2452
+	 * @throws ReflectionException
2453
+	 * @throws InvalidDataTypeException
2454
+	 * @throws InvalidInterfaceException
2455
+	 * @since 4.9.rc.000
2456
+	 */
2457
+	protected function _get_shortcode_selector($field, $linked_input_id)
2458
+	{
2459
+		$template_args = [
2460
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2461
+			'fieldname'       => $field,
2462
+			'linked_input_id' => $linked_input_id,
2463
+		];
2464
+
2465
+		return EEH_Template::display_template(
2466
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2467
+			$template_args,
2468
+			true
2469
+		);
2470
+	}
2471
+
2472
+
2473
+	/**
2474
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2475
+	 * page)
2476
+	 *
2477
+	 * @access public
2478
+	 * @return void
2479
+	 * @throws EE_Error
2480
+	 * @throws InvalidArgumentException
2481
+	 * @throws ReflectionException
2482
+	 * @throws InvalidDataTypeException
2483
+	 * @throws InvalidInterfaceException
2484
+	 */
2485
+	public function shortcode_meta_box()
2486
+	{
2487
+		$shortcodes = $this->_get_shortcodes([], false);
2488
+		// just make sure the shortcodes property is set
2489
+		// $messenger = $this->_message_template_group->messenger_obj();
2490
+		// now let's set the content depending on the status of the shortcodes array
2491
+		if (empty($shortcodes)) {
2492
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2493
+			return;
2494
+		}
2495
+		?>
2496 2496
         <div style="float:right; margin-top:10px">
2497 2497
             <?php echo $this->_get_help_tab_link('message_template_shortcodes'); // already escaped
2498
-            ?>
2498
+			?>
2499 2499
         </div>
2500 2500
         <p class="small-text">
2501 2501
             <?php printf(
2502
-                esc_html__(
2503
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2504
-                    'event_espresso'
2505
-                ),
2506
-                '<span class="dashicons dashicons-menu"></span>'
2507
-            ); ?>
2502
+				esc_html__(
2503
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2504
+					'event_espresso'
2505
+				),
2506
+				'<span class="dashicons dashicons-menu"></span>'
2507
+			); ?>
2508 2508
         </p>
2509 2509
         <?php
2510
-    }
2511
-
2512
-
2513
-    /**
2514
-     * used to set the $_shortcodes property for when its needed elsewhere.
2515
-     *
2516
-     * @access protected
2517
-     * @return void
2518
-     * @throws EE_Error
2519
-     * @throws InvalidArgumentException
2520
-     * @throws ReflectionException
2521
-     * @throws InvalidDataTypeException
2522
-     * @throws InvalidInterfaceException
2523
-     */
2524
-    protected function _set_shortcodes()
2525
-    {
2526
-
2527
-        // no need to run this if the property is already set
2528
-        if (! empty($this->_shortcodes)) {
2529
-            return;
2530
-        }
2531
-
2532
-        $this->_shortcodes = $this->_get_shortcodes();
2533
-    }
2534
-
2535
-
2536
-    /**
2537
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2538
-     * property)
2539
-     *
2540
-     * @access  protected
2541
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2542
-     *                         for. Defaults to all (for the given context)
2543
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2544
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2545
-     *                         true just an array of shortcode/label pairs.
2546
-     * @throws EE_Error
2547
-     * @throws InvalidArgumentException
2548
-     * @throws ReflectionException
2549
-     * @throws InvalidDataTypeException
2550
-     * @throws InvalidInterfaceException
2551
-     */
2552
-    protected function _get_shortcodes($fields = [], $merged = true)
2553
-    {
2554
-        $this->_set_message_template_group();
2555
-
2556
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2557
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2558
-        if (empty($GRP_ID)) {
2559
-            return [];
2560
-        }
2561
-        $context = $this->request->getRequestParam(
2562
-            'messenger',
2563
-            key($this->_message_template_group->contexts_config())
2564
-        );
2565
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2566
-    }
2567
-
2568
-
2569
-    /**
2570
-     * This sets the _message_template property (containing the called message_template object)
2571
-     *
2572
-     * @access protected
2573
-     * @return void
2574
-     * @throws EE_Error
2575
-     * @throws InvalidArgumentException
2576
-     * @throws ReflectionException
2577
-     * @throws InvalidDataTypeException
2578
-     * @throws InvalidInterfaceException
2579
-     */
2580
-    protected function _set_message_template_group()
2581
-    {
2582
-
2583
-        if (! empty($this->_message_template_group)) {
2584
-            return;
2585
-        } //get out if this is already set.
2586
-
2587
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2588
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2589
-
2590
-        // let's get the message templates
2591
-        $MTP = EEM_Message_Template_Group::instance();
2592
-
2593
-        if (empty($GRP_ID)) {
2594
-            $this->_message_template_group = $MTP->create_default_object();
2595
-        } else {
2596
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2597
-        }
2598
-
2599
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2600
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2601
-    }
2602
-
2603
-
2604
-    /**
2605
-     * sets up a context switcher for edit forms
2606
-     *
2607
-     * @access  protected
2608
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2609
-     * @param array                     $args                  various things the context switcher needs.
2610
-     * @throws EE_Error
2611
-     */
2612
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2613
-    {
2614
-        $context_details = $template_group_object->contexts_config();
2615
-        $context_label   = $template_group_object->context_label();
2616
-        ob_start();
2617
-        ?>
2510
+	}
2511
+
2512
+
2513
+	/**
2514
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2515
+	 *
2516
+	 * @access protected
2517
+	 * @return void
2518
+	 * @throws EE_Error
2519
+	 * @throws InvalidArgumentException
2520
+	 * @throws ReflectionException
2521
+	 * @throws InvalidDataTypeException
2522
+	 * @throws InvalidInterfaceException
2523
+	 */
2524
+	protected function _set_shortcodes()
2525
+	{
2526
+
2527
+		// no need to run this if the property is already set
2528
+		if (! empty($this->_shortcodes)) {
2529
+			return;
2530
+		}
2531
+
2532
+		$this->_shortcodes = $this->_get_shortcodes();
2533
+	}
2534
+
2535
+
2536
+	/**
2537
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2538
+	 * property)
2539
+	 *
2540
+	 * @access  protected
2541
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2542
+	 *                         for. Defaults to all (for the given context)
2543
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2544
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2545
+	 *                         true just an array of shortcode/label pairs.
2546
+	 * @throws EE_Error
2547
+	 * @throws InvalidArgumentException
2548
+	 * @throws ReflectionException
2549
+	 * @throws InvalidDataTypeException
2550
+	 * @throws InvalidInterfaceException
2551
+	 */
2552
+	protected function _get_shortcodes($fields = [], $merged = true)
2553
+	{
2554
+		$this->_set_message_template_group();
2555
+
2556
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2557
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2558
+		if (empty($GRP_ID)) {
2559
+			return [];
2560
+		}
2561
+		$context = $this->request->getRequestParam(
2562
+			'messenger',
2563
+			key($this->_message_template_group->contexts_config())
2564
+		);
2565
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2566
+	}
2567
+
2568
+
2569
+	/**
2570
+	 * This sets the _message_template property (containing the called message_template object)
2571
+	 *
2572
+	 * @access protected
2573
+	 * @return void
2574
+	 * @throws EE_Error
2575
+	 * @throws InvalidArgumentException
2576
+	 * @throws ReflectionException
2577
+	 * @throws InvalidDataTypeException
2578
+	 * @throws InvalidInterfaceException
2579
+	 */
2580
+	protected function _set_message_template_group()
2581
+	{
2582
+
2583
+		if (! empty($this->_message_template_group)) {
2584
+			return;
2585
+		} //get out if this is already set.
2586
+
2587
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2588
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2589
+
2590
+		// let's get the message templates
2591
+		$MTP = EEM_Message_Template_Group::instance();
2592
+
2593
+		if (empty($GRP_ID)) {
2594
+			$this->_message_template_group = $MTP->create_default_object();
2595
+		} else {
2596
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2597
+		}
2598
+
2599
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2600
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2601
+	}
2602
+
2603
+
2604
+	/**
2605
+	 * sets up a context switcher for edit forms
2606
+	 *
2607
+	 * @access  protected
2608
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2609
+	 * @param array                     $args                  various things the context switcher needs.
2610
+	 * @throws EE_Error
2611
+	 */
2612
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2613
+	{
2614
+		$context_details = $template_group_object->contexts_config();
2615
+		$context_label   = $template_group_object->context_label();
2616
+		ob_start();
2617
+		?>
2618 2618
         <div class="ee-msg-switcher-container">
2619 2619
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2620 2620
                 <?php
2621
-                foreach ($args as $name => $value) {
2622
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2623
-                        continue;
2624
-                    }
2625
-                    ?>
2621
+				foreach ($args as $name => $value) {
2622
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2623
+						continue;
2624
+					}
2625
+					?>
2626 2626
                     <input type="hidden"
2627 2627
                            name="<?php echo esc_attr($name); ?>"
2628 2628
                            value="<?php echo esc_attr($value); ?>"
2629 2629
                     />
2630 2630
                     <?php
2631
-                }
2632
-                // setup nonce_url
2633
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2634
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2635
-                ?>
2631
+				}
2632
+				// setup nonce_url
2633
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2634
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2635
+				?>
2636 2636
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2637 2637
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2638 2638
                 </label>
2639 2639
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2640 2640
                     <?php
2641
-                    $context_templates = $template_group_object->context_templates();
2642
-                    if (is_array($context_templates)) :
2643
-                        foreach ($context_templates as $context => $template_fields) :
2644
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2645
-                            ?>
2641
+					$context_templates = $template_group_object->context_templates();
2642
+					if (is_array($context_templates)) :
2643
+						foreach ($context_templates as $context => $template_fields) :
2644
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2645
+							?>
2646 2646
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2647 2647
                                 <?php echo $context_details[ $context ]['label']; // already escaped ?>
2648 2648
                             </option>
2649 2649
                         <?php endforeach;
2650
-                    endif; ?>
2650
+					endif; ?>
2651 2651
                 </select>
2652 2652
                 <?php $button_text = sprintf(
2653
-                    esc_html__('Switch %s', 'event_espresso'),
2654
-                    ucwords($context_label['label'])
2655
-                ); ?>
2653
+					esc_html__('Switch %s', 'event_espresso'),
2654
+					ucwords($context_label['label'])
2655
+				); ?>
2656 2656
                 <input class='button-secondary'
2657 2657
                        id="submit-msg-context-switcher-sbmt"
2658 2658
                        type="submit"
@@ -2662,1867 +2662,1867 @@  discard block
 block discarded – undo
2662 2662
             <?php echo $args['extra']; // already escaped ?>
2663 2663
         </div> <!-- end .ee-msg-switcher-container -->
2664 2664
         <?php
2665
-        $this->_context_switcher = ob_get_clean();
2666
-    }
2667
-
2668
-
2669
-    /**
2670
-     * utility for sanitizing new values coming in.
2671
-     * Note: this is only used when updating a context.
2672
-     *
2673
-     * @access protected
2674
-     *
2675
-     * @param int $index This helps us know which template field to select from the request array.
2676
-     *
2677
-     * @return array
2678
-     */
2679
-    protected function _set_message_template_column_values($index)
2680
-    {
2681
-        return [
2682
-            'MTP_ID'             => $this->request->getRequestParam('MTP_ID', 0, 'int'),
2683
-            'GRP_ID'             => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2684
-            'MTP_user_id'        => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2685
-            'MTP_messenger'      => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2686
-            'MTP_message_type'   => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2687
-            'MTP_template_field' => strtolower($this->request->getRequestParam("MTP_template_fields[{$index}][name]", '')),
2688
-            'MTP_context'        => strtolower($this->request->getRequestParam('MTP_context', '')),
2689
-            'MTP_content'        => $this->request->getRequestParam(
2690
-                "MTP_template_fields[{$index}][content]",
2691
-                '',
2692
-                'string'
2693
-            ),
2694
-            'MTP_is_global'      => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2695
-            'MTP_is_override'    => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2696
-            'MTP_deleted'        => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2697
-            'MTP_is_active'      => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2698
-        ];
2699
-    }
2700
-
2701
-
2702
-    /**
2703
-     * @throws EE_Error
2704
-     * @throws ReflectionException
2705
-     */
2706
-    protected function _insert_or_update_message_template($new = false)
2707
-    {
2708
-
2709
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2710
-        $success  = 0;
2711
-        $override = false;
2712
-
2713
-        // setup notices description
2714
-        $messenger_slug = $this->request->getRequestParam('MTP_messenger', '');
2715
-
2716
-        // need the message type and messenger objects to be able to use the labels for the notices
2717
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2718
-        $messenger_label  = $messenger_object instanceof EE_messenger
2719
-            ? ucwords($messenger_object->label['singular'])
2720
-            : '';
2721
-
2722
-        $message_type_slug   = $this->request->getRequestParam('MTP_message_type', '');
2723
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2724
-
2725
-        $message_type_label = $message_type_object instanceof EE_message_type
2726
-            ? ucwords($message_type_object->label['singular'])
2727
-            : '';
2728
-
2729
-        $context_slug = $this->request->getRequestParam('MTP_context', '');
2730
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2731
-
2732
-        $item_desc   = $messenger_label && $message_type_label
2733
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2734
-            : '';
2735
-        $item_desc   .= 'Message Template';
2736
-        $query_args  = [];
2737
-        $edit_array  = [];
2738
-        $action_desc = '';
2739
-
2740
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2741
-        // if this is "new" then we need to generate the default contexts
2742
-        // for the selected messenger/message_type for user to edit.
2743
-        if ($new) {
2744
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2745
-                if (empty($edit_array)) {
2746
-                    $success = 0;
2747
-                } else {
2748
-                    $success    = 1;
2749
-                    $edit_array = $edit_array[0];
2750
-                    $query_args = [
2751
-                        'id'      => $edit_array['GRP_ID'],
2752
-                        'context' => $edit_array['MTP_context'],
2753
-                        'action'  => 'edit_message_template',
2754
-                    ];
2755
-                }
2756
-            }
2757
-            $action_desc = 'created';
2758
-        } else {
2759
-            $MTPG = EEM_Message_Template_Group::instance();
2760
-            $MTP  = EEM_Message_Template::instance();
2761
-
2762
-
2763
-            // run update for each template field in displayed context
2764
-            $template_fields = $this->request->getRequestParam('MTP_template_fields');
2765
-            if (! $template_fields) {
2766
-                EE_Error::add_error(
2767
-                    esc_html__(
2768
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2769
-                        'event_espresso'
2770
-                    ),
2771
-                    __FILE__,
2772
-                    __FUNCTION__,
2773
-                    __LINE__
2774
-                );
2775
-                $success = 0;
2776
-            } else {
2777
-                // first validate all fields!
2778
-                // this filter allows client code to add its own validation to the template fields as well.
2779
-                // returning an empty array means everything passed validation.
2780
-                // errors in validation should be represented in an array with the following shape:
2781
-                // array(
2782
-                //   'fieldname' => array(
2783
-                //          'msg' => 'error message'
2784
-                //          'value' => 'value for field producing error'
2785
-                // )
2786
-                $custom_validation = (array) apply_filters(
2787
-                    'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2788
-                    [],
2789
-                    $template_fields,
2790
-                    $context_slug,
2791
-                    $messenger_slug,
2792
-                    $message_type_slug
2793
-                );
2794
-
2795
-                $system_validation = $MTPG->validate(
2796
-                    $template_fields,
2797
-                    $context_slug,
2798
-                    $messenger_slug,
2799
-                    $message_type_slug
2800
-                );
2801
-
2802
-                $system_validation = ! is_array($system_validation) && $system_validation ? []
2803
-                    : $system_validation;
2804
-                $validates         = array_merge($custom_validation, $system_validation);
2805
-
2806
-                // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2807
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2808
-                //  WE need to make sure there is no actual error messages in validates.
2809
-                if (is_array($validates) && ! empty($validates)) {
2810
-                    // add the transient so when the form loads we know which fields to highlight
2811
-                    $this->_add_transient('edit_message_template', $validates);
2812
-
2813
-                    $success = 0;
2814
-
2815
-                    // setup notices
2816
-                    foreach ($validates as $error) {
2817
-                        if (isset($error['msg'])) {
2818
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2819
-                        }
2820
-                    }
2821
-                } else {
2822
-                    $set_column_values = [];
2823
-                    foreach ($template_fields as $template_field => $content) {
2824
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2825
-
2826
-                        $where_cols_n_values = ['MTP_ID' => $content['MTP_ID']];
2827
-                        // if they aren't allowed to use all JS, restrict them to just posty-y tags
2828
-                        if (! current_user_can('unfiltered_html')) {
2829
-                            if (is_array($set_column_values['MTP_content'])) {
2830
-                                foreach ($set_column_values['MTP_content'] as $key => $value) {
2831
-                                    // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2832
-                                    // only removes slashes from double-quotes, so attributes using single quotes always
2833
-                                    // appear invalid.) But currently the models expect slashed data, so after wp_kses
2834
-                                    // runs we need to re-slash the data. Sheesh. See
2835
-                                    // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2836
-                                    $set_column_values['MTP_content'][ $key ] = addslashes(
2837
-                                        wp_kses(
2838
-                                            stripslashes($value),
2839
-                                            wp_kses_allowed_html('post')
2840
-                                        )
2841
-                                    );
2842
-                                }
2843
-                            } else {
2844
-                                $set_column_values['MTP_content'] = wp_kses(
2845
-                                    $set_column_values['MTP_content'],
2846
-                                    wp_kses_allowed_html('post')
2847
-                                );
2848
-                            }
2849
-                        }
2850
-                        $message_template_fields = [
2851
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2852
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2853
-                            'MTP_context'        => $set_column_values['MTP_context'],
2854
-                            'MTP_content'        => $set_column_values['MTP_content'],
2855
-                        ];
2856
-                        if ($updated = $MTP->update($message_template_fields, [$where_cols_n_values])) {
2857
-                            if ($updated === false) {
2858
-                                EE_Error::add_error(
2859
-                                    sprintf(
2860
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2861
-                                        $template_field
2862
-                                    ),
2863
-                                    __FILE__,
2864
-                                    __FUNCTION__,
2865
-                                    __LINE__
2866
-                                );
2867
-                            } else {
2868
-                                $success = 1;
2869
-                            }
2870
-                        } else {
2871
-                            // only do this logic if we don't have a MTP_ID for this field
2872
-                            if (empty($content['MTP_ID'])) {
2873
-                                // this has already been through the template field validator and sanitized, so it will be
2874
-                                // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2875
-                                // message template field in a messenger/message type and existing users don't have the
2876
-                                // default setup for it.
2877
-                                // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2878
-                                $updated = $MTP->insert($message_template_fields);
2879
-                                if (! $updated || is_wp_error($updated)) {
2880
-                                    EE_Error::add_error(
2881
-                                        sprintf(
2882
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2883
-                                            $template_field
2884
-                                        ),
2885
-                                        __FILE__,
2886
-                                        __FUNCTION__,
2887
-                                        __LINE__
2888
-                                    );
2889
-                                    $success = 0;
2890
-                                } else {
2891
-                                    $success = 1;
2892
-                                }
2893
-                            }
2894
-                        }
2895
-                        $action_desc = 'updated';
2896
-                    }
2897
-
2898
-                    // we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2899
-                    $mtpg_fields = [
2900
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2901
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2902
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2903
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2904
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2905
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2906
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2907
-                        'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
2908
-                        'MTP_description'  => $this->request->getRequestParam(
2909
-                            'ee_msg_non_global_fields[MTP_description]',
2910
-                            ''
2911
-                        ),
2912
-                    ];
2913
-
2914
-                    $mtpg_where = ['GRP_ID' => $set_column_values['GRP_ID']];
2915
-                    $updated    = $MTPG->update($mtpg_fields, [$mtpg_where]);
2916
-
2917
-                    if ($updated === false) {
2918
-                        EE_Error::add_error(
2919
-                            sprintf(
2920
-                                esc_html__(
2921
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2922
-                                    'event_espresso'
2923
-                                ),
2924
-                                $set_column_values['GRP_ID']
2925
-                            ),
2926
-                            __FILE__,
2927
-                            __FUNCTION__,
2928
-                            __LINE__
2929
-                        );
2930
-                    } else {
2931
-                        // k now we need to ensure the template_pack and template_variation fields are set.
2932
-                        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
2933
-                        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
2934
-
2935
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2936
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2937
-                            $mtpg_obj->set_template_pack_name($template_pack);
2938
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2939
-                        }
2940
-                        $success = 1;
2941
-                    }
2942
-                }
2943
-            }
2944
-        }
2945
-
2946
-        // we return things differently if doing ajax
2947
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2948
-            $this->_template_args['success'] = $success;
2949
-            $this->_template_args['error']   = ! $success;
2950
-            $this->_template_args['content'] = '';
2951
-            $this->_template_args['data']    = [
2952
-                'grpID'        => $edit_array['GRP_ID'],
2953
-                'templateName' => $edit_array['template_name'],
2954
-            ];
2955
-            if ($success) {
2956
-                EE_Error::overwrite_success();
2957
-                EE_Error::add_success(
2958
-                    esc_html__(
2959
-                        '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.',
2960
-                        'event_espresso'
2961
-                    )
2962
-                );
2963
-            }
2964
-
2965
-            $this->_return_json();
2966
-        }
2967
-
2968
-
2969
-        // was a test send triggered?
2970
-        if ($this->request->getRequestParam('test_button', false, 'bool')) {
2971
-            EE_Error::overwrite_success();
2972
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2973
-            $override = true;
2974
-        }
2975
-
2976
-        if (empty($query_args)) {
2977
-            $query_args = [
2978
-                'id'      => $GRP_ID,
2979
-                'context' => $context_slug,
2980
-                'action'  => 'edit_message_template',
2981
-            ];
2982
-        }
2983
-
2984
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2985
-    }
2986
-
2987
-
2988
-    /**
2989
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2990
-     *
2991
-     * @param string $context      what context being tested
2992
-     * @param string $messenger    messenger being tested
2993
-     * @param string $message_type message type being tested
2994
-     * @throws EE_Error
2995
-     * @throws InvalidArgumentException
2996
-     * @throws InvalidDataTypeException
2997
-     * @throws InvalidInterfaceException
2998
-     * @throws ReflectionException
2999
-     */
3000
-    protected function _do_test_send($context, $messenger, $message_type)
3001
-    {
3002
-        // set things up for preview
3003
-        $this->request->setRequestParam('messenger', $messenger);
3004
-        $this->request->setRequestParam('message_type', $message_type);
3005
-        $this->request->setRequestParam('context', $context);
3006
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3007
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3008
-
3009
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3010
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3011
-
3012
-        // let's save any existing fields that might be required by the messenger
3013
-        if (
3014
-            ! empty($test_settings_fld)
3015
-            && $active_messenger instanceof EE_messenger
3016
-            && apply_filters(
3017
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3018
-                true,
3019
-                $test_settings_fld,
3020
-                $active_messenger
3021
-            )
3022
-        ) {
3023
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3024
-        }
3025
-
3026
-        /**
3027
-         * Use filter to add additional controls on whether message can send or not
3028
-         */
3029
-        if (
3030
-            apply_filters(
3031
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3032
-                true,
3033
-                $context,
3034
-                $this->request->requestParams(),
3035
-                $messenger,
3036
-                $message_type
3037
-            )
3038
-        ) {
3039
-            if (EEM_Event::instance()->count() > 0) {
3040
-                $success = $this->_preview_message(true);
3041
-                if ($success) {
3042
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3043
-                } else {
3044
-                    EE_Error::add_error(
3045
-                        esc_html__('The test message was not sent', 'event_espresso'),
3046
-                        __FILE__,
3047
-                        __FUNCTION__,
3048
-                        __LINE__
3049
-                    );
3050
-                }
3051
-            } else {
3052
-                $this->noEventsErrorMessage(true);
3053
-            }
3054
-        }
3055
-    }
3056
-
3057
-
3058
-    /**
3059
-     * _generate_new_templates
3060
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3061
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3062
-     * for the event.
3063
-     *
3064
-     *
3065
-     * @param string $messenger      the messenger we are generating templates for
3066
-     * @param array  $message_types  array of message types that the templates are generated for.
3067
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3068
-     *                               indicate the message_template_group being used as the base.
3069
-     *
3070
-     * @param bool   $global
3071
-     *
3072
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3073
-     *                               encountering problems.
3074
-     * @throws EE_Error
3075
-     * @throws ReflectionException
3076
-     */
3077
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3078
-    {
3079
-
3080
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3081
-        // just don't generate any templates.
3082
-        if (empty($message_types)) {
3083
-            return true;
3084
-        }
3085
-
3086
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3087
-    }
3088
-
3089
-
3090
-    /**
3091
-     * [_trash_or_restore_message_template]
3092
-     *
3093
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3094
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3095
-     *                        an individual context (FALSE).
3096
-     * @return void
3097
-     * @throws EE_Error
3098
-     * @throws InvalidArgumentException
3099
-     * @throws InvalidDataTypeException
3100
-     * @throws InvalidInterfaceException
3101
-     */
3102
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3103
-    {
3104
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3105
-        $MTP = EEM_Message_Template_Group::instance();
3106
-
3107
-        $success = 1;
3108
-
3109
-        // incoming GRP_IDs
3110
-        if ($all) {
3111
-            // Checkboxes
3112
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3113
-            if (! empty($checkboxes)) {
3114
-                // if array has more than one element then success message should be plural.
3115
-                // todo: what about nonce?
3116
-                $success = count($checkboxes) > 1 ? 2 : 1;
3117
-
3118
-                // cycle through checkboxes
3119
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3120
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3121
-                    if (! $trashed_or_restored) {
3122
-                        $success = 0;
3123
-                    }
3124
-                }
3125
-            } else {
3126
-                // grab single GRP_ID and handle
3127
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3128
-                if (! empty($GRP_ID)) {
3129
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3130
-                    if (! $trashed_or_restored) {
3131
-                        $success = 0;
3132
-                    }
3133
-                } else {
3134
-                    $success = 0;
3135
-                }
3136
-            }
3137
-        }
3138
-
3139
-        $action_desc = $trash
3140
-            ? esc_html__('moved to the trash', 'event_espresso')
3141
-            : esc_html__('restored', 'event_espresso');
3142
-
3143
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3144
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3145
-
3146
-        $item_desc = $all ? _n(
3147
-            'Message Template Group',
3148
-            'Message Template Groups',
3149
-            $success,
3150
-            'event_espresso'
3151
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3152
-
3153
-        $item_desc = $template_switch
3154
-            ? _n('template', 'templates', $success, 'event_espresso')
3155
-            : $item_desc;
3156
-
3157
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3158
-    }
3159
-
3160
-
3161
-    /**
3162
-     * [_delete_message_template]
3163
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3164
-     *
3165
-     * @return void
3166
-     * @throws EE_Error
3167
-     * @throws InvalidArgumentException
3168
-     * @throws InvalidDataTypeException
3169
-     * @throws InvalidInterfaceException
3170
-     * @throws ReflectionException
3171
-     */
3172
-    protected function _delete_message_template()
3173
-    {
3174
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3175
-
3176
-        // checkboxes
3177
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3178
-        if (! empty($checkboxes)) {
3179
-            // if array has more than one element then success message should be plural
3180
-            $success = count($checkboxes) > 1 ? 2 : 1;
3181
-
3182
-            // cycle through bulk action checkboxes
3183
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3184
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3185
-            }
3186
-        } else {
3187
-            // grab single grp_id and delete
3188
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3189
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3190
-        }
3191
-
3192
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3193
-    }
3194
-
3195
-
3196
-    /**
3197
-     * helper for permanently deleting a mtP group and all related message_templates
3198
-     *
3199
-     * @param int  $GRP_ID        The group being deleted
3200
-     * @param bool $include_group whether to delete the Message Template Group as well.
3201
-     * @return bool boolean to indicate the success of the deletes or not.
3202
-     * @throws EE_Error
3203
-     * @throws InvalidArgumentException
3204
-     * @throws InvalidDataTypeException
3205
-     * @throws InvalidInterfaceException
3206
-     * @throws ReflectionException
3207
-     * @throws ReflectionException
3208
-     */
3209
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3210
-    {
3211
-        $success = true;
3212
-        $MTPG    = EEM_Message_Template_Group::instance();
3213
-        // first let's GET this group
3214
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3215
-        // then delete permanently all the related Message Templates
3216
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3217
-
3218
-        if ($deleted === 0) {
3219
-            $success = false;
3220
-        }
3221
-
3222
-        // now delete permanently this particular group
3223
-
3224
-        if ($include_group && ! $MTG->delete_permanently()) {
3225
-            $success = false;
3226
-        }
3227
-
3228
-        return $success;
3229
-    }
3230
-
3231
-
3232
-    /**
3233
-     *    _learn_more_about_message_templates_link
3234
-     *
3235
-     * @access protected
3236
-     * @return string
3237
-     */
3238
-    protected function _learn_more_about_message_templates_link()
3239
-    {
3240
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3241
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3242
-               . '</a>';
3243
-    }
3244
-
3245
-
3246
-    /**
3247
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3248
-     * ajax and other routes.
3249
-     *
3250
-     * @return void
3251
-     * @throws DomainException
3252
-     * @throws EE_Error
3253
-     */
3254
-    protected function _settings()
3255
-    {
3256
-        $this->_set_m_mt_settings();
3257
-
3258
-        // let's setup the messenger tabs
3259
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3260
-            $this->_m_mt_settings['messenger_tabs'],
3261
-            'messenger_links',
3262
-            '|',
3263
-            $this->request->getRequestParam('selected_messenger', 'email')
3264
-        );
3265
-
3266
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3267
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3268
-
3269
-        $this->display_admin_page_with_sidebar();
3270
-    }
3271
-
3272
-
3273
-    /**
3274
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3275
-     *
3276
-     * @access protected
3277
-     * @return void
3278
-     * @throws DomainException
3279
-     */
3280
-    protected function _set_m_mt_settings()
3281
-    {
3282
-        // first if this is already set then lets get out no need to regenerate data.
3283
-        if (! empty($this->_m_mt_settings)) {
3284
-            return;
3285
-        }
3286
-
3287
-        // get all installed messengers and message_types
3288
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3289
-        $message_types = $this->_message_resource_manager->installed_message_types();
3290
-
3291
-
3292
-        // assemble the array for the _tab_text_links helper
3293
-
3294
-        foreach ($messengers as $messenger) {
3295
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3296
-                'label' => ucwords($messenger->label['singular']),
3297
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3298
-                    ? 'messenger-active'
3299
-                    : '',
3300
-                'href'  => $messenger->name,
3301
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3302
-                'slug'  => $messenger->name,
3303
-                'obj'   => $messenger,
3304
-            ];
3305
-
3306
-
3307
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3308
-
3309
-            foreach ($message_types as $message_type) {
3310
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3311
-                // it shouldn't show in either the inactive OR active metabox.
3312
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3313
-                    continue;
3314
-                }
3315
-
3316
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3317
-                    $messenger->name,
3318
-                    $message_type->name
3319
-                )
3320
-                    ? 'active'
3321
-                    : 'inactive';
3322
-
3323
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3324
-                    'label'    => ucwords($message_type->label['singular']),
3325
-                    'class'    => 'message-type-' . $a_or_i,
3326
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3327
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3328
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3329
-                    'title'    => $a_or_i === 'active'
3330
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3331
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3332
-                    'content'  => $a_or_i === 'active'
3333
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3334
-                        : $this->_message_type_settings_content($message_type, $messenger),
3335
-                    'slug'     => $message_type->name,
3336
-                    'active'   => $a_or_i === 'active',
3337
-                    'obj'      => $message_type,
3338
-                ];
3339
-            }
3340
-        }
3341
-    }
3342
-
3343
-
3344
-    /**
3345
-     * This just prepares the content for the message type settings
3346
-     *
3347
-     * @param EE_message_type $message_type The message type object
3348
-     * @param EE_messenger    $messenger    The messenger object
3349
-     * @param boolean         $active       Whether the message type is active or not
3350
-     * @return string html output for the content
3351
-     * @throws DomainException
3352
-     */
3353
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3354
-    {
3355
-        // get message type fields
3356
-        $fields                                         = $message_type->get_admin_settings_fields();
3357
-        $settings_template_args['template_form_fields'] = '';
3358
-
3359
-        if (! empty($fields) && $active) {
3360
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3361
-            foreach ($fields as $fldname => $fldprops) {
3362
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3363
-                $template_form_field[ $field_id ] = [
3364
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3365
-                    'label'      => $fldprops['label'],
3366
-                    'input'      => $fldprops['field_type'],
3367
-                    'type'       => $fldprops['value_type'],
3368
-                    'required'   => $fldprops['required'],
3369
-                    'validation' => $fldprops['validation'],
3370
-                    'value'      => isset($existing_settings[ $fldname ])
3371
-                        ? $existing_settings[ $fldname ]
3372
-                        : $fldprops['default'],
3373
-                    'options'    => isset($fldprops['options'])
3374
-                        ? $fldprops['options']
3375
-                        : [],
3376
-                    'default'    => isset($existing_settings[ $fldname ])
3377
-                        ? $existing_settings[ $fldname ]
3378
-                        : $fldprops['default'],
3379
-                    'css_class'  => 'no-drag',
3380
-                    'format'     => $fldprops['format'],
3381
-                ];
3382
-            }
3383
-
3384
-
3385
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3386
-                ? $this->_generate_admin_form_fields(
3387
-                    $template_form_field,
3388
-                    'string',
3389
-                    'ee_mt_activate_form'
3390
-                )
3391
-                : '';
3392
-        }
3393
-
3394
-        $settings_template_args['description'] = $message_type->description;
3395
-        // we also need some hidden fields
3396
-        $hidden_fields = [
3397
-            'message_type_settings[messenger]' . $message_type->name    => [
3398
-                'type'  => 'hidden',
3399
-                'value' => $messenger->name,
3400
-            ],
3401
-            'message_type_settings[message_type]' . $message_type->name => [
3402
-                'type'  => 'hidden',
3403
-                'value' => $message_type->name,
3404
-            ],
3405
-            'type' . $message_type->name                                => [
3406
-                'type'  => 'hidden',
3407
-                'value' => 'message_type',
3408
-            ],
3409
-        ];
3410
-
3411
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3412
-            $hidden_fields,
3413
-            'array'
3414
-        );
3415
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3416
-            ? ' hidden'
3417
-            : '';
3418
-
3419
-
3420
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3421
-        return EEH_Template::display_template($template, $settings_template_args, true);
3422
-    }
3423
-
3424
-
3425
-    /**
3426
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3427
-     *
3428
-     * @access protected
3429
-     * @return void
3430
-     * @throws DomainException
3431
-     */
3432
-    protected function _messages_settings_metaboxes()
3433
-    {
3434
-        $this->_set_m_mt_settings();
3435
-        $m_boxes         = $mt_boxes = [];
3436
-        $m_template_args = $mt_template_args = [];
3437
-
3438
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3439
-
3440
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3441
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3442
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3443
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3444
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3445
-
3446
-                // messenger meta boxes
3447
-                $active         = $selected_messenger === $messenger;
3448
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3449
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3450
-                    : '';
3451
-
3452
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3453
-                    esc_html__('%s Settings', 'event_espresso'),
3454
-                    $tab_array['label']
3455
-                );
3456
-
3457
-                $m_template_args[ $messenger . '_a_box' ] = [
3458
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3459
-                    'inactive_message_types' => isset(
3460
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3461
-                    )
3462
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3463
-                        : '',
3464
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3465
-                    'hidden'                 => $active ? '' : ' hidden',
3466
-                    'hide_on_message'        => $hide_on_message,
3467
-                    'messenger'              => $messenger,
3468
-                    'active'                 => $active,
3469
-                ];
3470
-
3471
-                // message type meta boxes
3472
-                // (which is really just the inactive container for each messenger
3473
-                // showing inactive message types for that messenger)
3474
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3475
-                $mt_template_args[ $messenger . '_i_box' ] = [
3476
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3477
-                    'inactive_message_types' => isset(
3478
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3479
-                    )
3480
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3481
-                        : '',
3482
-                    'hidden'                 => $active ? '' : ' hidden',
3483
-                    'hide_on_message'        => $hide_on_message,
3484
-                    'hide_off_message'       => $hide_off_message,
3485
-                    'messenger'              => $messenger,
3486
-                    'active'                 => $active,
3487
-                ];
3488
-            }
3489
-        }
3490
-
3491
-
3492
-        // register messenger metaboxes
3493
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3494
-        foreach ($m_boxes as $box => $label) {
3495
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3496
-            $msgr          = str_replace('_a_box', '', $box);
3497
-            add_meta_box(
3498
-                'espresso_' . $msgr . '_settings',
3499
-                $label,
3500
-                function ($post, $metabox) {
3501
-                    EEH_Template::display_template(
3502
-                        $metabox['args']['template_path'],
3503
-                        $metabox['args']['template_args']
3504
-                    );
3505
-                },
3506
-                $this->_current_screen->id,
3507
-                'normal',
3508
-                'high',
3509
-                $callback_args
3510
-            );
3511
-        }
3512
-
3513
-        // register message type metaboxes
3514
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3515
-        foreach ($mt_boxes as $box => $label) {
3516
-            $callback_args = [
3517
-                'template_path' => $mt_template_path,
3518
-                'template_args' => $mt_template_args[ $box ],
3519
-            ];
3520
-            $mt            = str_replace('_i_box', '', $box);
3521
-            add_meta_box(
3522
-                'espresso_' . $mt . '_inactive_mts',
3523
-                $label,
3524
-                function ($post, $metabox) {
3525
-                    EEH_Template::display_template(
3526
-                        $metabox['args']['template_path'],
3527
-                        $metabox['args']['template_args']
3528
-                    );
3529
-                },
3530
-                $this->_current_screen->id,
3531
-                'side',
3532
-                'high',
3533
-                $callback_args
3534
-            );
3535
-        }
3536
-
3537
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3538
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3539
-        if (is_main_site()) {
3540
-            add_meta_box(
3541
-                'espresso_global_message_settings',
3542
-                esc_html__('Global Message Settings', 'event_espresso'),
3543
-                [$this, 'global_messages_settings_metabox_content'],
3544
-                $this->_current_screen->id,
3545
-                'normal',
3546
-                'low',
3547
-                []
3548
-            );
3549
-        }
3550
-    }
3551
-
3552
-
3553
-    /**
3554
-     *  This generates the content for the global messages settings metabox.
3555
-     *
3556
-     * @return void
3557
-     * @throws EE_Error
3558
-     * @throws InvalidArgumentException
3559
-     * @throws ReflectionException
3560
-     * @throws InvalidDataTypeException
3561
-     * @throws InvalidInterfaceException
3562
-     */
3563
-    public function global_messages_settings_metabox_content()
3564
-    {
3565
-        $form = $this->_generate_global_settings_form();
3566
-        // already escaped
3567
-        echo $form->form_open(
3568
-            $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3569
-            'POST'
3570
-        );
3571
-        echo $form->get_html();
3572
-        echo $form->form_close();
3573
-    }
3574
-
3575
-
3576
-    /**
3577
-     * This generates and returns the form object for the global messages settings.
3578
-     *
3579
-     * @return EE_Form_Section_Proper
3580
-     * @throws EE_Error
3581
-     * @throws InvalidArgumentException
3582
-     * @throws ReflectionException
3583
-     * @throws InvalidDataTypeException
3584
-     * @throws InvalidInterfaceException
3585
-     */
3586
-    protected function _generate_global_settings_form()
3587
-    {
3588
-        /** @var EE_Network_Core_Config $network_config */
3589
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3590
-
3591
-        return new EE_Form_Section_Proper(
3592
-            [
3593
-                'name'            => 'global_messages_settings',
3594
-                'html_id'         => 'global_messages_settings',
3595
-                'html_class'      => 'form-table',
3596
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3597
-                'subsections'     => apply_filters(
3598
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3599
-                    [
3600
-                        'do_messages_on_same_request' => new EE_Select_Input(
3601
-                            [
3602
-                                true  => esc_html__('On the same request', 'event_espresso'),
3603
-                                false => esc_html__('On a separate request', 'event_espresso'),
3604
-                            ],
3605
-                            [
3606
-                                'default'         => $network_config->do_messages_on_same_request,
3607
-                                'html_label_text' => esc_html__(
3608
-                                    'Generate and send all messages:',
3609
-                                    'event_espresso'
3610
-                                ),
3611
-                                'html_help_text'  => esc_html__(
3612
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3613
-                                    'event_espresso'
3614
-                                ),
3615
-                            ]
3616
-                        ),
3617
-                        'delete_threshold'            => new EE_Select_Input(
3618
-                            [
3619
-                                0  => esc_html__('Forever', 'event_espresso'),
3620
-                                3  => esc_html__('3 Months', 'event_espresso'),
3621
-                                6  => esc_html__('6 Months', 'event_espresso'),
3622
-                                9  => esc_html__('9 Months', 'event_espresso'),
3623
-                                12 => esc_html__('12 Months', 'event_espresso'),
3624
-                                24 => esc_html__('24 Months', 'event_espresso'),
3625
-                                36 => esc_html__('36 Months', 'event_espresso'),
3626
-                            ],
3627
-                            [
3628
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3629
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3630
-                                'html_help_text'  => esc_html__(
3631
-                                    'You can control how long a record of processed messages is kept via this option.',
3632
-                                    'event_espresso'
3633
-                                ),
3634
-                            ]
3635
-                        ),
3636
-                        'update_settings'             => new EE_Submit_Input(
3637
-                            [
3638
-                                'default'         => esc_html__('Update', 'event_espresso'),
3639
-                                'html_label_text' => '&nbsp',
3640
-                            ]
3641
-                        ),
3642
-                    ]
3643
-                ),
3644
-            ]
3645
-        );
3646
-    }
3647
-
3648
-
3649
-    /**
3650
-     * This handles updating the global settings set on the admin page.
3651
-     *
3652
-     * @throws EE_Error
3653
-     * @throws InvalidDataTypeException
3654
-     * @throws InvalidInterfaceException
3655
-     * @throws InvalidArgumentException
3656
-     * @throws ReflectionException
3657
-     */
3658
-    protected function _update_global_settings()
3659
-    {
3660
-        /** @var EE_Network_Core_Config $network_config */
3661
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3662
-        $messages_config = EE_Registry::instance()->CFG->messages;
3663
-        $form            = $this->_generate_global_settings_form();
3664
-        if ($form->was_submitted()) {
3665
-            $form->receive_form_submission();
3666
-            if ($form->is_valid()) {
3667
-                $valid_data = $form->valid_data();
3668
-                foreach ($valid_data as $property => $value) {
3669
-                    $setter = 'set_' . $property;
3670
-                    if (method_exists($network_config, $setter)) {
3671
-                        $network_config->{$setter}($value);
3672
-                    } elseif (
3673
-                        property_exists($network_config, $property)
3674
-                        && $network_config->{$property} !== $value
3675
-                    ) {
3676
-                        $network_config->{$property} = $value;
3677
-                    } elseif (
3678
-                        property_exists($messages_config, $property)
3679
-                        && $messages_config->{$property} !== $value
3680
-                    ) {
3681
-                        $messages_config->{$property} = $value;
3682
-                    }
3683
-                }
3684
-                // only update if the form submission was valid!
3685
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3686
-                EE_Registry::instance()->CFG->update_espresso_config();
3687
-                EE_Error::overwrite_success();
3688
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3689
-            }
3690
-        }
3691
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3692
-    }
3693
-
3694
-
3695
-    /**
3696
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3697
-     *
3698
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3699
-     * @return string html formatted tabs
3700
-     * @throws DomainException
3701
-     */
3702
-    protected function _get_mt_tabs($tab_array)
3703
-    {
3704
-        $tab_array = (array) $tab_array;
3705
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3706
-        $tabs      = '';
3707
-
3708
-        foreach ($tab_array as $tab) {
3709
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3710
-        }
3711
-
3712
-        return $tabs;
3713
-    }
3714
-
3715
-
3716
-    /**
3717
-     * This prepares the content of the messenger meta box admin settings
3718
-     *
3719
-     * @param EE_messenger $messenger The messenger we're setting up content for
3720
-     * @return string html formatted content
3721
-     * @throws DomainException
3722
-     */
3723
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3724
-    {
3725
-
3726
-        $fields                                         = $messenger->get_admin_settings_fields();
3727
-        $settings_template_args['template_form_fields'] = '';
3728
-
3729
-        // is $messenger active?
3730
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3731
-
3732
-
3733
-        if (! empty($fields)) {
3734
-            $existing_settings = $messenger->get_existing_admin_settings();
3735
-
3736
-            foreach ($fields as $fldname => $fldprops) {
3737
-                $field_id                         = $messenger->name . '-' . $fldname;
3738
-                $template_form_field[ $field_id ] = [
3739
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3740
-                    'label'      => $fldprops['label'],
3741
-                    'input'      => $fldprops['field_type'],
3742
-                    'type'       => $fldprops['value_type'],
3743
-                    'required'   => $fldprops['required'],
3744
-                    'validation' => $fldprops['validation'],
3745
-                    'value'      => isset($existing_settings[ $field_id ])
3746
-                        ? $existing_settings[ $field_id ]
3747
-                        : $fldprops['default'],
3748
-                    'css_class'  => '',
3749
-                    'format'     => $fldprops['format'],
3750
-                ];
3751
-            }
3752
-
3753
-
3754
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3755
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3756
-                : '';
3757
-        }
3758
-
3759
-        // we also need some hidden fields
3760
-        $settings_template_args['hidden_fields'] = [
3761
-            'messenger_settings[messenger]' . $messenger->name => [
3762
-                'type'  => 'hidden',
3763
-                'value' => $messenger->name,
3764
-            ],
3765
-            'type' . $messenger->name                          => [
3766
-                'type'  => 'hidden',
3767
-                'value' => 'messenger',
3768
-            ],
3769
-        ];
3770
-
3771
-        // make sure any active message types that are existing are included in the hidden fields
3772
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3773
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3774
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3775
-                    'type'  => 'hidden',
3776
-                    'value' => $mt,
3777
-                ];
3778
-            }
3779
-        }
3780
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3781
-            $settings_template_args['hidden_fields'],
3782
-            'array'
3783
-        );
3784
-        $active                                  =
3785
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3786
-
3787
-        $settings_template_args['messenger']           = $messenger->name;
3788
-        $settings_template_args['description']         = $messenger->description;
3789
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3790
-
3791
-
3792
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3793
-            $messenger->name
3794
-        )
3795
-            ? $settings_template_args['show_hide_edit_form']
3796
-            : ' hidden';
3797
-
3798
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3799
-            ? ' hidden'
3800
-            : $settings_template_args['show_hide_edit_form'];
3801
-
3802
-
3803
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3804
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3805
-        $settings_template_args['on_off_status'] = $active;
3806
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3807
-        return EEH_Template::display_template(
3808
-            $template,
3809
-            $settings_template_args,
3810
-            true
3811
-        );
3812
-    }
3813
-
3814
-
3815
-    /**
3816
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3817
-     *
3818
-     * @throws DomainException
3819
-     * @throws EE_Error
3820
-     * @throws InvalidDataTypeException
3821
-     * @throws InvalidInterfaceException
3822
-     * @throws InvalidArgumentException
3823
-     * @throws ReflectionException
3824
-     */
3825
-    public function activate_messenger_toggle()
3826
-    {
3827
-        $success = true;
3828
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3829
-        // let's check that we have required data
3830
-
3831
-        if (! $this->_active_messenger_name) {
3832
-            EE_Error::add_error(
3833
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3834
-                __FILE__,
3835
-                __FUNCTION__,
3836
-                __LINE__
3837
-            );
3838
-            $success = false;
3839
-        }
3840
-
3841
-        // do a nonce check here since we're not arriving via a normal route
3842
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
3843
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
3844
-
3845
-        $this->_verify_nonce($nonce, $nonce_ref);
3846
-
3847
-
3848
-        $status = $this->request->getRequestParam('status');
3849
-        if (! $status) {
3850
-            EE_Error::add_error(
3851
-                esc_html__(
3852
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3853
-                    'event_espresso'
3854
-                ),
3855
-                __FILE__,
3856
-                __FUNCTION__,
3857
-                __LINE__
3858
-            );
3859
-            $success = false;
3860
-        }
3861
-
3862
-        // do check to verify we have a valid status.
3863
-        if ($status !== 'off' && $status !== 'on') {
3864
-            EE_Error::add_error(
3865
-                sprintf(
3866
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3867
-                    $status
3868
-                ),
3869
-                __FILE__,
3870
-                __FUNCTION__,
3871
-                __LINE__
3872
-            );
3873
-            $success = false;
3874
-        }
3875
-
3876
-        if ($success) {
3877
-            // made it here?  Stop dawdling then!!
3878
-            $success = $status === 'off'
3879
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
3880
-                : $this->_activate_messenger($this->_active_messenger_name);
3881
-        }
3882
-
3883
-        $this->_template_args['success'] = $success;
3884
-
3885
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
3886
-        $this->_return_json();
3887
-    }
3888
-
3889
-
3890
-    /**
3891
-     * used by ajax from the messages settings page to activate|deactivate a message type
3892
-     *
3893
-     * @throws DomainException
3894
-     * @throws EE_Error
3895
-     * @throws ReflectionException
3896
-     * @throws InvalidDataTypeException
3897
-     * @throws InvalidInterfaceException
3898
-     * @throws InvalidArgumentException
3899
-     */
3900
-    public function activate_mt_toggle()
3901
-    {
3902
-        $success = true;
3903
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3904
-
3905
-        // let's make sure we have the necessary data
3906
-        if (! $this->_active_message_type_name) {
3907
-            EE_Error::add_error(
3908
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3909
-                __FILE__,
3910
-                __FUNCTION__,
3911
-                __LINE__
3912
-            );
3913
-            $success = false;
3914
-        }
3915
-
3916
-        if (! $this->_active_messenger_name) {
3917
-            EE_Error::add_error(
3918
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3919
-                __FILE__,
3920
-                __FUNCTION__,
3921
-                __LINE__
3922
-            );
3923
-            $success = false;
3924
-        }
3925
-
3926
-        $status = $this->request->getRequestParam('status');
3927
-        if (! $status) {
3928
-            EE_Error::add_error(
3929
-                esc_html__(
3930
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3931
-                    'event_espresso'
3932
-                ),
3933
-                __FILE__,
3934
-                __FUNCTION__,
3935
-                __LINE__
3936
-            );
3937
-            $success = false;
3938
-        }
3939
-
3940
-
3941
-        // do check to verify we have a valid status.
3942
-        if ($status !== 'activate' && $status !== 'deactivate') {
3943
-            EE_Error::add_error(
3944
-                sprintf(
3945
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3946
-                    $status
3947
-                ),
3948
-                __FILE__,
3949
-                __FUNCTION__,
3950
-                __LINE__
3951
-            );
3952
-            $success = false;
3953
-        }
3954
-
3955
-
3956
-        // do a nonce check here since we're not arriving via a normal route
3957
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
3958
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
3959
-
3960
-        if ($success) {
3961
-            // made it here? um, what are you waiting for then?
3962
-            $success = $status === 'deactivate'
3963
-                ? $this->_deactivate_message_type_for_messenger(
3964
-                    $this->_active_messenger_name,
3965
-                    $this->_active_message_type_name
3966
-                )
3967
-                : $this->_activate_message_type_for_messenger(
3968
-                    $this->_active_messenger_name,
3969
-                    $this->_active_message_type_name
3970
-                );
3971
-        }
3972
-
3973
-        $this->_template_args['success'] = $success;
3974
-        $this->_return_json();
3975
-    }
3976
-
3977
-
3978
-    /**
3979
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3980
-     *
3981
-     * @param string $messenger_name The name of the messenger being activated
3982
-     * @return bool
3983
-     * @throws DomainException
3984
-     * @throws EE_Error
3985
-     * @throws InvalidArgumentException
3986
-     * @throws ReflectionException
3987
-     * @throws InvalidDataTypeException
3988
-     * @throws InvalidInterfaceException
3989
-     */
3990
-    protected function _activate_messenger($messenger_name)
3991
-    {
3992
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3993
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3994
-            ? $active_messenger->get_default_message_types()
3995
-            : [];
3996
-
3997
-        // ensure is active
3998
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
3999
-
4000
-        // set response_data for reload
4001
-        foreach ($message_types_to_activate as $message_type_name) {
4002
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4003
-            if (
4004
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4005
-                    $messenger_name,
4006
-                    $message_type_name
4007
-                )
4008
-                && $message_type instanceof EE_message_type
4009
-            ) {
4010
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4011
-                if ($message_type->get_admin_settings_fields()) {
4012
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4013
-                }
4014
-            }
4015
-        }
4016
-
4017
-        // add success message for activating messenger
4018
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4019
-    }
4020
-
4021
-
4022
-    /**
4023
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4024
-     *
4025
-     * @param string $messenger_name The name of the messenger being activated
4026
-     * @return bool
4027
-     * @throws DomainException
4028
-     * @throws EE_Error
4029
-     * @throws InvalidArgumentException
4030
-     * @throws ReflectionException
4031
-     * @throws InvalidDataTypeException
4032
-     * @throws InvalidInterfaceException
4033
-     */
4034
-    protected function _deactivate_messenger($messenger_name)
4035
-    {
4036
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4037
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4038
-
4039
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4040
-    }
4041
-
4042
-
4043
-    /**
4044
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4045
-     *
4046
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4047
-     * @param string $message_type_name The name of the message type being activated for the messenger
4048
-     * @return bool
4049
-     * @throws DomainException
4050
-     * @throws EE_Error
4051
-     * @throws InvalidArgumentException
4052
-     * @throws ReflectionException
4053
-     * @throws InvalidDataTypeException
4054
-     * @throws InvalidInterfaceException
4055
-     */
4056
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4057
-    {
4058
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4059
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4060
-
4061
-        // ensure is active
4062
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4063
-
4064
-        // set response for load
4065
-        if (
4066
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4067
-                $messenger_name,
4068
-                $message_type_name
4069
-            )
4070
-        ) {
4071
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4072
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4073
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4074
-            }
4075
-        }
4076
-
4077
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4078
-            $active_messenger,
4079
-            $message_type_to_activate
4080
-        );
4081
-    }
4082
-
4083
-
4084
-    /**
4085
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4086
-     *
4087
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4088
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4089
-     * @return bool
4090
-     * @throws DomainException
4091
-     * @throws EE_Error
4092
-     * @throws InvalidArgumentException
4093
-     * @throws ReflectionException
4094
-     * @throws InvalidDataTypeException
4095
-     * @throws InvalidInterfaceException
4096
-     */
4097
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4098
-    {
4099
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4100
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4101
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4102
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4103
-
4104
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4105
-            $active_messenger,
4106
-            $message_type_to_deactivate
4107
-        );
4108
-    }
4109
-
4110
-
4111
-    /**
4112
-     * This just initializes the defaults for activating messenger and message type responses.
4113
-     */
4114
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4115
-    {
4116
-        $this->_template_args['data']['active_mts'] = [];
4117
-        $this->_template_args['data']['mt_reload']  = [];
4118
-    }
4119
-
4120
-
4121
-    /**
4122
-     * Setup appropriate response for activating a messenger and/or message types
4123
-     *
4124
-     * @param EE_messenger         $messenger
4125
-     * @param EE_message_type|null $message_type
4126
-     * @return bool
4127
-     * @throws DomainException
4128
-     * @throws EE_Error
4129
-     * @throws InvalidArgumentException
4130
-     * @throws ReflectionException
4131
-     * @throws InvalidDataTypeException
4132
-     * @throws InvalidInterfaceException
4133
-     */
4134
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4135
-        $messenger,
4136
-        EE_Message_Type $message_type = null
4137
-    ) {
4138
-        // if $messenger isn't a valid messenger object then get out.
4139
-        if (! $messenger instanceof EE_Messenger) {
4140
-            EE_Error::add_error(
4141
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4142
-                __FILE__,
4143
-                __FUNCTION__,
4144
-                __LINE__
4145
-            );
4146
-            return false;
4147
-        }
4148
-        // activated
4149
-        if ($this->_template_args['data']['active_mts']) {
4150
-            EE_Error::overwrite_success();
4151
-            // activated a message type with the messenger
4152
-            if ($message_type instanceof EE_message_type) {
4153
-                EE_Error::add_success(
4154
-                    sprintf(
4155
-                        esc_html__(
4156
-                            '%s message type has been successfully activated with the %s messenger',
4157
-                            'event_espresso'
4158
-                        ),
4159
-                        ucwords($message_type->label['singular']),
4160
-                        ucwords($messenger->label['singular'])
4161
-                    )
4162
-                );
4163
-
4164
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4165
-                if ($message_type->name === 'invoice') {
4166
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4167
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4168
-                    if ($pm instanceof EE_Payment_Method) {
4169
-                        EE_Error::add_attention(
4170
-                            esc_html__(
4171
-                                '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.',
4172
-                                'event_espresso'
4173
-                            )
4174
-                        );
4175
-                    }
4176
-                }
4177
-                // just toggles the entire messenger
4178
-            } else {
4179
-                EE_Error::add_success(
4180
-                    sprintf(
4181
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4182
-                        ucwords($messenger->label['singular'])
4183
-                    )
4184
-                );
4185
-            }
4186
-
4187
-            return true;
4188
-
4189
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4190
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4191
-            // in which case we just give a success message for the messenger being successfully activated.
4192
-        } else {
4193
-            if (! $messenger->get_default_message_types()) {
4194
-                // messenger doesn't have any default message types so still a success.
4195
-                EE_Error::add_success(
4196
-                    sprintf(
4197
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4198
-                        ucwords($messenger->label['singular'])
4199
-                    )
4200
-                );
4201
-
4202
-                return true;
4203
-            } else {
4204
-                EE_Error::add_error(
4205
-                    $message_type instanceof EE_message_type
4206
-                        ? sprintf(
4207
-                            esc_html__(
4208
-                                '%s message type was not successfully activated with the %s messenger',
4209
-                                'event_espresso'
4210
-                            ),
4211
-                            ucwords($message_type->label['singular']),
4212
-                            ucwords($messenger->label['singular'])
4213
-                        )
4214
-                        : sprintf(
4215
-                            esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4216
-                            ucwords($messenger->label['singular'])
4217
-                        ),
4218
-                    __FILE__,
4219
-                    __FUNCTION__,
4220
-                    __LINE__
4221
-                );
4222
-
4223
-                return false;
4224
-            }
4225
-        }
4226
-    }
4227
-
4228
-
4229
-    /**
4230
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4231
-     *
4232
-     * @param EE_messenger         $messenger
4233
-     * @param EE_message_type|null $message_type
4234
-     * @return bool
4235
-     * @throws DomainException
4236
-     * @throws EE_Error
4237
-     * @throws InvalidArgumentException
4238
-     * @throws ReflectionException
4239
-     * @throws InvalidDataTypeException
4240
-     * @throws InvalidInterfaceException
4241
-     */
4242
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4243
-        $messenger,
4244
-        EE_message_type $message_type = null
4245
-    ) {
4246
-        EE_Error::overwrite_success();
4247
-
4248
-        // if $messenger isn't a valid messenger object then get out.
4249
-        if (! $messenger instanceof EE_Messenger) {
4250
-            EE_Error::add_error(
4251
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4252
-                __FILE__,
4253
-                __FUNCTION__,
4254
-                __LINE__
4255
-            );
4256
-
4257
-            return false;
4258
-        }
4259
-
4260
-        if ($message_type instanceof EE_message_type) {
4261
-            $message_type_name = $message_type->name;
4262
-            EE_Error::add_success(
4263
-                sprintf(
4264
-                    esc_html__(
4265
-                        '%s message type has been successfully deactivated for the %s messenger.',
4266
-                        'event_espresso'
4267
-                    ),
4268
-                    ucwords($message_type->label['singular']),
4269
-                    ucwords($messenger->label['singular'])
4270
-                )
4271
-            );
4272
-        } else {
4273
-            $message_type_name = '';
4274
-            EE_Error::add_success(
4275
-                sprintf(
4276
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4277
-                    ucwords($messenger->label['singular'])
4278
-                )
4279
-            );
4280
-        }
4281
-
4282
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4283
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4284
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4285
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4286
-            if ($count_updated > 0) {
4287
-                $msg = $message_type_name === 'invoice'
4288
-                    ? esc_html__(
4289
-                        '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.',
4290
-                        'event_espresso'
4291
-                    )
4292
-                    : esc_html__(
4293
-                        '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.',
4294
-                        'event_espresso'
4295
-                    );
4296
-                EE_Error::add_attention($msg);
4297
-            }
4298
-        }
4299
-
4300
-        return true;
4301
-    }
4302
-
4303
-
4304
-    /**
4305
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4306
-     *
4307
-     * @throws DomainException
4308
-     * @throws EE_Error
4309
-     * @throws EE_Error
4310
-     */
4311
-    public function update_mt_form()
4312
-    {
4313
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4314
-            EE_Error::add_error(
4315
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4316
-                __FILE__,
4317
-                __FUNCTION__,
4318
-                __LINE__
4319
-            );
4320
-            $this->_return_json();
4321
-        }
4322
-
4323
-        $message_types = $this->get_installed_message_types();
4324
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4325
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4326
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4327
-
4328
-        $this->_template_args['success'] = true;
4329
-        $this->_template_args['content'] = $content;
4330
-        $this->_return_json();
4331
-    }
4332
-
4333
-
4334
-    /**
4335
-     * this handles saving the settings for a messenger or message type
4336
-     *
4337
-     * @throws EE_Error
4338
-     * @throws EE_Error
4339
-     */
4340
-    public function save_settings()
4341
-    {
4342
-        $type = $this->request->getRequestParam('type');
4343
-        if (! $type) {
4344
-            EE_Error::add_error(
4345
-                esc_html__(
4346
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4347
-                    'event_espresso'
4348
-                ),
4349
-                __FILE__,
4350
-                __FUNCTION__,
4351
-                __LINE__
4352
-            );
4353
-            $this->_template_args['error'] = true;
4354
-            $this->_return_json();
4355
-        }
4356
-
4357
-
4358
-        if ($type === 'messenger') {
4359
-            // this should be an array.
4360
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4361
-            $messenger = $settings['messenger'];
4362
-            // remove messenger and message_types from settings array
4363
-            unset($settings['messenger'], $settings['message_types']);
4364
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4365
-        } elseif ($type === 'message_type') {
4366
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4367
-            $messenger    = $settings['messenger'];
4368
-            $message_type = $settings['message_type'];
4369
-            // remove messenger and message_types from settings array
4370
-            unset($settings['messenger'], $settings['message_types']);
4371
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4372
-        }
4373
-
4374
-        // okay we should have the data all setup.  Now we just update!
4375
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4376
-
4377
-        if ($success) {
4378
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4379
-        } else {
4380
-            EE_Error::add_error(
4381
-                esc_html__('Settings did not get updated', 'event_espresso'),
4382
-                __FILE__,
4383
-                __FUNCTION__,
4384
-                __LINE__
4385
-            );
4386
-        }
4387
-
4388
-        $this->_template_args['success'] = $success;
4389
-        $this->_return_json();
4390
-    }
4391
-
4392
-
4393
-
4394
-
4395
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4396
-
4397
-
4398
-    /**
4399
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4400
-     * However, this does not send immediately, it just queues for sending.
4401
-     *
4402
-     * @throws EE_Error
4403
-     * @throws InvalidDataTypeException
4404
-     * @throws InvalidInterfaceException
4405
-     * @throws InvalidArgumentException
4406
-     * @throws ReflectionException
4407
-     * @since 4.9.0
4408
-     */
4409
-    protected function _generate_now()
4410
-    {
4411
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4412
-        $this->_redirect_after_action(false, '', '', [], true);
4413
-    }
4414
-
4415
-
4416
-    /**
4417
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4418
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4419
-     *
4420
-     * @throws EE_Error
4421
-     * @throws InvalidDataTypeException
4422
-     * @throws InvalidInterfaceException
4423
-     * @throws InvalidArgumentException
4424
-     * @throws ReflectionException
4425
-     * @since 4.9.0
4426
-     */
4427
-    protected function _generate_and_send_now()
4428
-    {
4429
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4430
-        $this->_redirect_after_action(false, '', '', [], true);
4431
-    }
4432
-
4433
-
4434
-    /**
4435
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4436
-     *
4437
-     * @throws EE_Error
4438
-     * @throws InvalidDataTypeException
4439
-     * @throws InvalidInterfaceException
4440
-     * @throws InvalidArgumentException
4441
-     * @throws ReflectionException
4442
-     * @since 4.9.0
4443
-     */
4444
-    protected function _queue_for_resending()
4445
-    {
4446
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4447
-        $this->_redirect_after_action(false, '', '', [], true);
4448
-    }
4449
-
4450
-
4451
-    /**
4452
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4453
-     *
4454
-     * @throws EE_Error
4455
-     * @throws InvalidDataTypeException
4456
-     * @throws InvalidInterfaceException
4457
-     * @throws InvalidArgumentException
4458
-     * @throws ReflectionException
4459
-     * @since 4.9.0
4460
-     */
4461
-    protected function _send_now()
4462
-    {
4463
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4464
-        $this->_redirect_after_action(false, '', '', [], true);
4465
-    }
4466
-
4467
-
4468
-    /**
4469
-     * Deletes EE_messages for IDs in the request.
4470
-     *
4471
-     * @throws EE_Error
4472
-     * @throws InvalidDataTypeException
4473
-     * @throws InvalidInterfaceException
4474
-     * @throws InvalidArgumentException
4475
-     * @since 4.9.0
4476
-     */
4477
-    protected function _delete_ee_messages()
4478
-    {
4479
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4480
-        $deleted_count = 0;
4481
-        foreach ($MSG_IDs as $MSG_ID) {
4482
-            if (EEM_Message::instance()->delete_by_ID($MSG_ID)) {
4483
-                $deleted_count++;
4484
-            }
4485
-        }
4486
-        if ($deleted_count) {
4487
-            EE_Error::add_success(
4488
-                esc_html(
4489
-                    _n(
4490
-                        'Message successfully deleted',
4491
-                        'Messages successfully deleted',
4492
-                        $deleted_count,
4493
-                        'event_espresso'
4494
-                    )
4495
-                )
4496
-            );
4497
-        } else {
4498
-            EE_Error::add_error(
4499
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4500
-                __FILE__,
4501
-                __FUNCTION__,
4502
-                __LINE__
4503
-            );
4504
-        }
4505
-        $this->_redirect_after_action(false, '', '', [], true);
4506
-    }
4507
-
4508
-
4509
-    /**
4510
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4511
-     *
4512
-     * @return array
4513
-     * @since 4.9.0
4514
-     */
4515
-    protected function _get_msg_ids_from_request()
4516
-    {
4517
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4518
-        if (empty($MSG_IDs)) {
4519
-            return [];
4520
-        }
4521
-        // if 'MSG_ID' was just a single ID (not an array)
4522
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4523
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4524
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4525
-            ? $MSG_IDs
4526
-            : array_keys($MSG_IDs);
4527
-    }
2665
+		$this->_context_switcher = ob_get_clean();
2666
+	}
2667
+
2668
+
2669
+	/**
2670
+	 * utility for sanitizing new values coming in.
2671
+	 * Note: this is only used when updating a context.
2672
+	 *
2673
+	 * @access protected
2674
+	 *
2675
+	 * @param int $index This helps us know which template field to select from the request array.
2676
+	 *
2677
+	 * @return array
2678
+	 */
2679
+	protected function _set_message_template_column_values($index)
2680
+	{
2681
+		return [
2682
+			'MTP_ID'             => $this->request->getRequestParam('MTP_ID', 0, 'int'),
2683
+			'GRP_ID'             => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2684
+			'MTP_user_id'        => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2685
+			'MTP_messenger'      => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2686
+			'MTP_message_type'   => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2687
+			'MTP_template_field' => strtolower($this->request->getRequestParam("MTP_template_fields[{$index}][name]", '')),
2688
+			'MTP_context'        => strtolower($this->request->getRequestParam('MTP_context', '')),
2689
+			'MTP_content'        => $this->request->getRequestParam(
2690
+				"MTP_template_fields[{$index}][content]",
2691
+				'',
2692
+				'string'
2693
+			),
2694
+			'MTP_is_global'      => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2695
+			'MTP_is_override'    => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2696
+			'MTP_deleted'        => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2697
+			'MTP_is_active'      => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2698
+		];
2699
+	}
2700
+
2701
+
2702
+	/**
2703
+	 * @throws EE_Error
2704
+	 * @throws ReflectionException
2705
+	 */
2706
+	protected function _insert_or_update_message_template($new = false)
2707
+	{
2708
+
2709
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2710
+		$success  = 0;
2711
+		$override = false;
2712
+
2713
+		// setup notices description
2714
+		$messenger_slug = $this->request->getRequestParam('MTP_messenger', '');
2715
+
2716
+		// need the message type and messenger objects to be able to use the labels for the notices
2717
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2718
+		$messenger_label  = $messenger_object instanceof EE_messenger
2719
+			? ucwords($messenger_object->label['singular'])
2720
+			: '';
2721
+
2722
+		$message_type_slug   = $this->request->getRequestParam('MTP_message_type', '');
2723
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2724
+
2725
+		$message_type_label = $message_type_object instanceof EE_message_type
2726
+			? ucwords($message_type_object->label['singular'])
2727
+			: '';
2728
+
2729
+		$context_slug = $this->request->getRequestParam('MTP_context', '');
2730
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2731
+
2732
+		$item_desc   = $messenger_label && $message_type_label
2733
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2734
+			: '';
2735
+		$item_desc   .= 'Message Template';
2736
+		$query_args  = [];
2737
+		$edit_array  = [];
2738
+		$action_desc = '';
2739
+
2740
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2741
+		// if this is "new" then we need to generate the default contexts
2742
+		// for the selected messenger/message_type for user to edit.
2743
+		if ($new) {
2744
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2745
+				if (empty($edit_array)) {
2746
+					$success = 0;
2747
+				} else {
2748
+					$success    = 1;
2749
+					$edit_array = $edit_array[0];
2750
+					$query_args = [
2751
+						'id'      => $edit_array['GRP_ID'],
2752
+						'context' => $edit_array['MTP_context'],
2753
+						'action'  => 'edit_message_template',
2754
+					];
2755
+				}
2756
+			}
2757
+			$action_desc = 'created';
2758
+		} else {
2759
+			$MTPG = EEM_Message_Template_Group::instance();
2760
+			$MTP  = EEM_Message_Template::instance();
2761
+
2762
+
2763
+			// run update for each template field in displayed context
2764
+			$template_fields = $this->request->getRequestParam('MTP_template_fields');
2765
+			if (! $template_fields) {
2766
+				EE_Error::add_error(
2767
+					esc_html__(
2768
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2769
+						'event_espresso'
2770
+					),
2771
+					__FILE__,
2772
+					__FUNCTION__,
2773
+					__LINE__
2774
+				);
2775
+				$success = 0;
2776
+			} else {
2777
+				// first validate all fields!
2778
+				// this filter allows client code to add its own validation to the template fields as well.
2779
+				// returning an empty array means everything passed validation.
2780
+				// errors in validation should be represented in an array with the following shape:
2781
+				// array(
2782
+				//   'fieldname' => array(
2783
+				//          'msg' => 'error message'
2784
+				//          'value' => 'value for field producing error'
2785
+				// )
2786
+				$custom_validation = (array) apply_filters(
2787
+					'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2788
+					[],
2789
+					$template_fields,
2790
+					$context_slug,
2791
+					$messenger_slug,
2792
+					$message_type_slug
2793
+				);
2794
+
2795
+				$system_validation = $MTPG->validate(
2796
+					$template_fields,
2797
+					$context_slug,
2798
+					$messenger_slug,
2799
+					$message_type_slug
2800
+				);
2801
+
2802
+				$system_validation = ! is_array($system_validation) && $system_validation ? []
2803
+					: $system_validation;
2804
+				$validates         = array_merge($custom_validation, $system_validation);
2805
+
2806
+				// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2807
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2808
+				//  WE need to make sure there is no actual error messages in validates.
2809
+				if (is_array($validates) && ! empty($validates)) {
2810
+					// add the transient so when the form loads we know which fields to highlight
2811
+					$this->_add_transient('edit_message_template', $validates);
2812
+
2813
+					$success = 0;
2814
+
2815
+					// setup notices
2816
+					foreach ($validates as $error) {
2817
+						if (isset($error['msg'])) {
2818
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2819
+						}
2820
+					}
2821
+				} else {
2822
+					$set_column_values = [];
2823
+					foreach ($template_fields as $template_field => $content) {
2824
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2825
+
2826
+						$where_cols_n_values = ['MTP_ID' => $content['MTP_ID']];
2827
+						// if they aren't allowed to use all JS, restrict them to just posty-y tags
2828
+						if (! current_user_can('unfiltered_html')) {
2829
+							if (is_array($set_column_values['MTP_content'])) {
2830
+								foreach ($set_column_values['MTP_content'] as $key => $value) {
2831
+									// remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2832
+									// only removes slashes from double-quotes, so attributes using single quotes always
2833
+									// appear invalid.) But currently the models expect slashed data, so after wp_kses
2834
+									// runs we need to re-slash the data. Sheesh. See
2835
+									// https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2836
+									$set_column_values['MTP_content'][ $key ] = addslashes(
2837
+										wp_kses(
2838
+											stripslashes($value),
2839
+											wp_kses_allowed_html('post')
2840
+										)
2841
+									);
2842
+								}
2843
+							} else {
2844
+								$set_column_values['MTP_content'] = wp_kses(
2845
+									$set_column_values['MTP_content'],
2846
+									wp_kses_allowed_html('post')
2847
+								);
2848
+							}
2849
+						}
2850
+						$message_template_fields = [
2851
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2852
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2853
+							'MTP_context'        => $set_column_values['MTP_context'],
2854
+							'MTP_content'        => $set_column_values['MTP_content'],
2855
+						];
2856
+						if ($updated = $MTP->update($message_template_fields, [$where_cols_n_values])) {
2857
+							if ($updated === false) {
2858
+								EE_Error::add_error(
2859
+									sprintf(
2860
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2861
+										$template_field
2862
+									),
2863
+									__FILE__,
2864
+									__FUNCTION__,
2865
+									__LINE__
2866
+								);
2867
+							} else {
2868
+								$success = 1;
2869
+							}
2870
+						} else {
2871
+							// only do this logic if we don't have a MTP_ID for this field
2872
+							if (empty($content['MTP_ID'])) {
2873
+								// this has already been through the template field validator and sanitized, so it will be
2874
+								// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2875
+								// message template field in a messenger/message type and existing users don't have the
2876
+								// default setup for it.
2877
+								// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2878
+								$updated = $MTP->insert($message_template_fields);
2879
+								if (! $updated || is_wp_error($updated)) {
2880
+									EE_Error::add_error(
2881
+										sprintf(
2882
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2883
+											$template_field
2884
+										),
2885
+										__FILE__,
2886
+										__FUNCTION__,
2887
+										__LINE__
2888
+									);
2889
+									$success = 0;
2890
+								} else {
2891
+									$success = 1;
2892
+								}
2893
+							}
2894
+						}
2895
+						$action_desc = 'updated';
2896
+					}
2897
+
2898
+					// we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2899
+					$mtpg_fields = [
2900
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2901
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2902
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2903
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2904
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2905
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2906
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2907
+						'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
2908
+						'MTP_description'  => $this->request->getRequestParam(
2909
+							'ee_msg_non_global_fields[MTP_description]',
2910
+							''
2911
+						),
2912
+					];
2913
+
2914
+					$mtpg_where = ['GRP_ID' => $set_column_values['GRP_ID']];
2915
+					$updated    = $MTPG->update($mtpg_fields, [$mtpg_where]);
2916
+
2917
+					if ($updated === false) {
2918
+						EE_Error::add_error(
2919
+							sprintf(
2920
+								esc_html__(
2921
+									'The Message Template Group (%d) was NOT updated for some reason',
2922
+									'event_espresso'
2923
+								),
2924
+								$set_column_values['GRP_ID']
2925
+							),
2926
+							__FILE__,
2927
+							__FUNCTION__,
2928
+							__LINE__
2929
+						);
2930
+					} else {
2931
+						// k now we need to ensure the template_pack and template_variation fields are set.
2932
+						$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
2933
+						$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
2934
+
2935
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2936
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2937
+							$mtpg_obj->set_template_pack_name($template_pack);
2938
+							$mtpg_obj->set_template_pack_variation($template_variation);
2939
+						}
2940
+						$success = 1;
2941
+					}
2942
+				}
2943
+			}
2944
+		}
2945
+
2946
+		// we return things differently if doing ajax
2947
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2948
+			$this->_template_args['success'] = $success;
2949
+			$this->_template_args['error']   = ! $success;
2950
+			$this->_template_args['content'] = '';
2951
+			$this->_template_args['data']    = [
2952
+				'grpID'        => $edit_array['GRP_ID'],
2953
+				'templateName' => $edit_array['template_name'],
2954
+			];
2955
+			if ($success) {
2956
+				EE_Error::overwrite_success();
2957
+				EE_Error::add_success(
2958
+					esc_html__(
2959
+						'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.',
2960
+						'event_espresso'
2961
+					)
2962
+				);
2963
+			}
2964
+
2965
+			$this->_return_json();
2966
+		}
2967
+
2968
+
2969
+		// was a test send triggered?
2970
+		if ($this->request->getRequestParam('test_button', false, 'bool')) {
2971
+			EE_Error::overwrite_success();
2972
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2973
+			$override = true;
2974
+		}
2975
+
2976
+		if (empty($query_args)) {
2977
+			$query_args = [
2978
+				'id'      => $GRP_ID,
2979
+				'context' => $context_slug,
2980
+				'action'  => 'edit_message_template',
2981
+			];
2982
+		}
2983
+
2984
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2985
+	}
2986
+
2987
+
2988
+	/**
2989
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2990
+	 *
2991
+	 * @param string $context      what context being tested
2992
+	 * @param string $messenger    messenger being tested
2993
+	 * @param string $message_type message type being tested
2994
+	 * @throws EE_Error
2995
+	 * @throws InvalidArgumentException
2996
+	 * @throws InvalidDataTypeException
2997
+	 * @throws InvalidInterfaceException
2998
+	 * @throws ReflectionException
2999
+	 */
3000
+	protected function _do_test_send($context, $messenger, $message_type)
3001
+	{
3002
+		// set things up for preview
3003
+		$this->request->setRequestParam('messenger', $messenger);
3004
+		$this->request->setRequestParam('message_type', $message_type);
3005
+		$this->request->setRequestParam('context', $context);
3006
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3007
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3008
+
3009
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3010
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3011
+
3012
+		// let's save any existing fields that might be required by the messenger
3013
+		if (
3014
+			! empty($test_settings_fld)
3015
+			&& $active_messenger instanceof EE_messenger
3016
+			&& apply_filters(
3017
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3018
+				true,
3019
+				$test_settings_fld,
3020
+				$active_messenger
3021
+			)
3022
+		) {
3023
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3024
+		}
3025
+
3026
+		/**
3027
+		 * Use filter to add additional controls on whether message can send or not
3028
+		 */
3029
+		if (
3030
+			apply_filters(
3031
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3032
+				true,
3033
+				$context,
3034
+				$this->request->requestParams(),
3035
+				$messenger,
3036
+				$message_type
3037
+			)
3038
+		) {
3039
+			if (EEM_Event::instance()->count() > 0) {
3040
+				$success = $this->_preview_message(true);
3041
+				if ($success) {
3042
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3043
+				} else {
3044
+					EE_Error::add_error(
3045
+						esc_html__('The test message was not sent', 'event_espresso'),
3046
+						__FILE__,
3047
+						__FUNCTION__,
3048
+						__LINE__
3049
+					);
3050
+				}
3051
+			} else {
3052
+				$this->noEventsErrorMessage(true);
3053
+			}
3054
+		}
3055
+	}
3056
+
3057
+
3058
+	/**
3059
+	 * _generate_new_templates
3060
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3061
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3062
+	 * for the event.
3063
+	 *
3064
+	 *
3065
+	 * @param string $messenger      the messenger we are generating templates for
3066
+	 * @param array  $message_types  array of message types that the templates are generated for.
3067
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3068
+	 *                               indicate the message_template_group being used as the base.
3069
+	 *
3070
+	 * @param bool   $global
3071
+	 *
3072
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3073
+	 *                               encountering problems.
3074
+	 * @throws EE_Error
3075
+	 * @throws ReflectionException
3076
+	 */
3077
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3078
+	{
3079
+
3080
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3081
+		// just don't generate any templates.
3082
+		if (empty($message_types)) {
3083
+			return true;
3084
+		}
3085
+
3086
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3087
+	}
3088
+
3089
+
3090
+	/**
3091
+	 * [_trash_or_restore_message_template]
3092
+	 *
3093
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3094
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3095
+	 *                        an individual context (FALSE).
3096
+	 * @return void
3097
+	 * @throws EE_Error
3098
+	 * @throws InvalidArgumentException
3099
+	 * @throws InvalidDataTypeException
3100
+	 * @throws InvalidInterfaceException
3101
+	 */
3102
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3103
+	{
3104
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3105
+		$MTP = EEM_Message_Template_Group::instance();
3106
+
3107
+		$success = 1;
3108
+
3109
+		// incoming GRP_IDs
3110
+		if ($all) {
3111
+			// Checkboxes
3112
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3113
+			if (! empty($checkboxes)) {
3114
+				// if array has more than one element then success message should be plural.
3115
+				// todo: what about nonce?
3116
+				$success = count($checkboxes) > 1 ? 2 : 1;
3117
+
3118
+				// cycle through checkboxes
3119
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3120
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3121
+					if (! $trashed_or_restored) {
3122
+						$success = 0;
3123
+					}
3124
+				}
3125
+			} else {
3126
+				// grab single GRP_ID and handle
3127
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3128
+				if (! empty($GRP_ID)) {
3129
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3130
+					if (! $trashed_or_restored) {
3131
+						$success = 0;
3132
+					}
3133
+				} else {
3134
+					$success = 0;
3135
+				}
3136
+			}
3137
+		}
3138
+
3139
+		$action_desc = $trash
3140
+			? esc_html__('moved to the trash', 'event_espresso')
3141
+			: esc_html__('restored', 'event_espresso');
3142
+
3143
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3144
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3145
+
3146
+		$item_desc = $all ? _n(
3147
+			'Message Template Group',
3148
+			'Message Template Groups',
3149
+			$success,
3150
+			'event_espresso'
3151
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3152
+
3153
+		$item_desc = $template_switch
3154
+			? _n('template', 'templates', $success, 'event_espresso')
3155
+			: $item_desc;
3156
+
3157
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3158
+	}
3159
+
3160
+
3161
+	/**
3162
+	 * [_delete_message_template]
3163
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3164
+	 *
3165
+	 * @return void
3166
+	 * @throws EE_Error
3167
+	 * @throws InvalidArgumentException
3168
+	 * @throws InvalidDataTypeException
3169
+	 * @throws InvalidInterfaceException
3170
+	 * @throws ReflectionException
3171
+	 */
3172
+	protected function _delete_message_template()
3173
+	{
3174
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3175
+
3176
+		// checkboxes
3177
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3178
+		if (! empty($checkboxes)) {
3179
+			// if array has more than one element then success message should be plural
3180
+			$success = count($checkboxes) > 1 ? 2 : 1;
3181
+
3182
+			// cycle through bulk action checkboxes
3183
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3184
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3185
+			}
3186
+		} else {
3187
+			// grab single grp_id and delete
3188
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3189
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3190
+		}
3191
+
3192
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3193
+	}
3194
+
3195
+
3196
+	/**
3197
+	 * helper for permanently deleting a mtP group and all related message_templates
3198
+	 *
3199
+	 * @param int  $GRP_ID        The group being deleted
3200
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3201
+	 * @return bool boolean to indicate the success of the deletes or not.
3202
+	 * @throws EE_Error
3203
+	 * @throws InvalidArgumentException
3204
+	 * @throws InvalidDataTypeException
3205
+	 * @throws InvalidInterfaceException
3206
+	 * @throws ReflectionException
3207
+	 * @throws ReflectionException
3208
+	 */
3209
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3210
+	{
3211
+		$success = true;
3212
+		$MTPG    = EEM_Message_Template_Group::instance();
3213
+		// first let's GET this group
3214
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3215
+		// then delete permanently all the related Message Templates
3216
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3217
+
3218
+		if ($deleted === 0) {
3219
+			$success = false;
3220
+		}
3221
+
3222
+		// now delete permanently this particular group
3223
+
3224
+		if ($include_group && ! $MTG->delete_permanently()) {
3225
+			$success = false;
3226
+		}
3227
+
3228
+		return $success;
3229
+	}
3230
+
3231
+
3232
+	/**
3233
+	 *    _learn_more_about_message_templates_link
3234
+	 *
3235
+	 * @access protected
3236
+	 * @return string
3237
+	 */
3238
+	protected function _learn_more_about_message_templates_link()
3239
+	{
3240
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3241
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3242
+			   . '</a>';
3243
+	}
3244
+
3245
+
3246
+	/**
3247
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3248
+	 * ajax and other routes.
3249
+	 *
3250
+	 * @return void
3251
+	 * @throws DomainException
3252
+	 * @throws EE_Error
3253
+	 */
3254
+	protected function _settings()
3255
+	{
3256
+		$this->_set_m_mt_settings();
3257
+
3258
+		// let's setup the messenger tabs
3259
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3260
+			$this->_m_mt_settings['messenger_tabs'],
3261
+			'messenger_links',
3262
+			'|',
3263
+			$this->request->getRequestParam('selected_messenger', 'email')
3264
+		);
3265
+
3266
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3267
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3268
+
3269
+		$this->display_admin_page_with_sidebar();
3270
+	}
3271
+
3272
+
3273
+	/**
3274
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3275
+	 *
3276
+	 * @access protected
3277
+	 * @return void
3278
+	 * @throws DomainException
3279
+	 */
3280
+	protected function _set_m_mt_settings()
3281
+	{
3282
+		// first if this is already set then lets get out no need to regenerate data.
3283
+		if (! empty($this->_m_mt_settings)) {
3284
+			return;
3285
+		}
3286
+
3287
+		// get all installed messengers and message_types
3288
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3289
+		$message_types = $this->_message_resource_manager->installed_message_types();
3290
+
3291
+
3292
+		// assemble the array for the _tab_text_links helper
3293
+
3294
+		foreach ($messengers as $messenger) {
3295
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3296
+				'label' => ucwords($messenger->label['singular']),
3297
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3298
+					? 'messenger-active'
3299
+					: '',
3300
+				'href'  => $messenger->name,
3301
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3302
+				'slug'  => $messenger->name,
3303
+				'obj'   => $messenger,
3304
+			];
3305
+
3306
+
3307
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3308
+
3309
+			foreach ($message_types as $message_type) {
3310
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3311
+				// it shouldn't show in either the inactive OR active metabox.
3312
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3313
+					continue;
3314
+				}
3315
+
3316
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3317
+					$messenger->name,
3318
+					$message_type->name
3319
+				)
3320
+					? 'active'
3321
+					: 'inactive';
3322
+
3323
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3324
+					'label'    => ucwords($message_type->label['singular']),
3325
+					'class'    => 'message-type-' . $a_or_i,
3326
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3327
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3328
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3329
+					'title'    => $a_or_i === 'active'
3330
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3331
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3332
+					'content'  => $a_or_i === 'active'
3333
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3334
+						: $this->_message_type_settings_content($message_type, $messenger),
3335
+					'slug'     => $message_type->name,
3336
+					'active'   => $a_or_i === 'active',
3337
+					'obj'      => $message_type,
3338
+				];
3339
+			}
3340
+		}
3341
+	}
3342
+
3343
+
3344
+	/**
3345
+	 * This just prepares the content for the message type settings
3346
+	 *
3347
+	 * @param EE_message_type $message_type The message type object
3348
+	 * @param EE_messenger    $messenger    The messenger object
3349
+	 * @param boolean         $active       Whether the message type is active or not
3350
+	 * @return string html output for the content
3351
+	 * @throws DomainException
3352
+	 */
3353
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3354
+	{
3355
+		// get message type fields
3356
+		$fields                                         = $message_type->get_admin_settings_fields();
3357
+		$settings_template_args['template_form_fields'] = '';
3358
+
3359
+		if (! empty($fields) && $active) {
3360
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3361
+			foreach ($fields as $fldname => $fldprops) {
3362
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3363
+				$template_form_field[ $field_id ] = [
3364
+					'name'       => 'message_type_settings[' . $fldname . ']',
3365
+					'label'      => $fldprops['label'],
3366
+					'input'      => $fldprops['field_type'],
3367
+					'type'       => $fldprops['value_type'],
3368
+					'required'   => $fldprops['required'],
3369
+					'validation' => $fldprops['validation'],
3370
+					'value'      => isset($existing_settings[ $fldname ])
3371
+						? $existing_settings[ $fldname ]
3372
+						: $fldprops['default'],
3373
+					'options'    => isset($fldprops['options'])
3374
+						? $fldprops['options']
3375
+						: [],
3376
+					'default'    => isset($existing_settings[ $fldname ])
3377
+						? $existing_settings[ $fldname ]
3378
+						: $fldprops['default'],
3379
+					'css_class'  => 'no-drag',
3380
+					'format'     => $fldprops['format'],
3381
+				];
3382
+			}
3383
+
3384
+
3385
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3386
+				? $this->_generate_admin_form_fields(
3387
+					$template_form_field,
3388
+					'string',
3389
+					'ee_mt_activate_form'
3390
+				)
3391
+				: '';
3392
+		}
3393
+
3394
+		$settings_template_args['description'] = $message_type->description;
3395
+		// we also need some hidden fields
3396
+		$hidden_fields = [
3397
+			'message_type_settings[messenger]' . $message_type->name    => [
3398
+				'type'  => 'hidden',
3399
+				'value' => $messenger->name,
3400
+			],
3401
+			'message_type_settings[message_type]' . $message_type->name => [
3402
+				'type'  => 'hidden',
3403
+				'value' => $message_type->name,
3404
+			],
3405
+			'type' . $message_type->name                                => [
3406
+				'type'  => 'hidden',
3407
+				'value' => 'message_type',
3408
+			],
3409
+		];
3410
+
3411
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3412
+			$hidden_fields,
3413
+			'array'
3414
+		);
3415
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3416
+			? ' hidden'
3417
+			: '';
3418
+
3419
+
3420
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3421
+		return EEH_Template::display_template($template, $settings_template_args, true);
3422
+	}
3423
+
3424
+
3425
+	/**
3426
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3427
+	 *
3428
+	 * @access protected
3429
+	 * @return void
3430
+	 * @throws DomainException
3431
+	 */
3432
+	protected function _messages_settings_metaboxes()
3433
+	{
3434
+		$this->_set_m_mt_settings();
3435
+		$m_boxes         = $mt_boxes = [];
3436
+		$m_template_args = $mt_template_args = [];
3437
+
3438
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3439
+
3440
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3441
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3442
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3443
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3444
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3445
+
3446
+				// messenger meta boxes
3447
+				$active         = $selected_messenger === $messenger;
3448
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3449
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3450
+					: '';
3451
+
3452
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3453
+					esc_html__('%s Settings', 'event_espresso'),
3454
+					$tab_array['label']
3455
+				);
3456
+
3457
+				$m_template_args[ $messenger . '_a_box' ] = [
3458
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3459
+					'inactive_message_types' => isset(
3460
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3461
+					)
3462
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3463
+						: '',
3464
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3465
+					'hidden'                 => $active ? '' : ' hidden',
3466
+					'hide_on_message'        => $hide_on_message,
3467
+					'messenger'              => $messenger,
3468
+					'active'                 => $active,
3469
+				];
3470
+
3471
+				// message type meta boxes
3472
+				// (which is really just the inactive container for each messenger
3473
+				// showing inactive message types for that messenger)
3474
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3475
+				$mt_template_args[ $messenger . '_i_box' ] = [
3476
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3477
+					'inactive_message_types' => isset(
3478
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3479
+					)
3480
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3481
+						: '',
3482
+					'hidden'                 => $active ? '' : ' hidden',
3483
+					'hide_on_message'        => $hide_on_message,
3484
+					'hide_off_message'       => $hide_off_message,
3485
+					'messenger'              => $messenger,
3486
+					'active'                 => $active,
3487
+				];
3488
+			}
3489
+		}
3490
+
3491
+
3492
+		// register messenger metaboxes
3493
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3494
+		foreach ($m_boxes as $box => $label) {
3495
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3496
+			$msgr          = str_replace('_a_box', '', $box);
3497
+			add_meta_box(
3498
+				'espresso_' . $msgr . '_settings',
3499
+				$label,
3500
+				function ($post, $metabox) {
3501
+					EEH_Template::display_template(
3502
+						$metabox['args']['template_path'],
3503
+						$metabox['args']['template_args']
3504
+					);
3505
+				},
3506
+				$this->_current_screen->id,
3507
+				'normal',
3508
+				'high',
3509
+				$callback_args
3510
+			);
3511
+		}
3512
+
3513
+		// register message type metaboxes
3514
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3515
+		foreach ($mt_boxes as $box => $label) {
3516
+			$callback_args = [
3517
+				'template_path' => $mt_template_path,
3518
+				'template_args' => $mt_template_args[ $box ],
3519
+			];
3520
+			$mt            = str_replace('_i_box', '', $box);
3521
+			add_meta_box(
3522
+				'espresso_' . $mt . '_inactive_mts',
3523
+				$label,
3524
+				function ($post, $metabox) {
3525
+					EEH_Template::display_template(
3526
+						$metabox['args']['template_path'],
3527
+						$metabox['args']['template_args']
3528
+					);
3529
+				},
3530
+				$this->_current_screen->id,
3531
+				'side',
3532
+				'high',
3533
+				$callback_args
3534
+			);
3535
+		}
3536
+
3537
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3538
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3539
+		if (is_main_site()) {
3540
+			add_meta_box(
3541
+				'espresso_global_message_settings',
3542
+				esc_html__('Global Message Settings', 'event_espresso'),
3543
+				[$this, 'global_messages_settings_metabox_content'],
3544
+				$this->_current_screen->id,
3545
+				'normal',
3546
+				'low',
3547
+				[]
3548
+			);
3549
+		}
3550
+	}
3551
+
3552
+
3553
+	/**
3554
+	 *  This generates the content for the global messages settings metabox.
3555
+	 *
3556
+	 * @return void
3557
+	 * @throws EE_Error
3558
+	 * @throws InvalidArgumentException
3559
+	 * @throws ReflectionException
3560
+	 * @throws InvalidDataTypeException
3561
+	 * @throws InvalidInterfaceException
3562
+	 */
3563
+	public function global_messages_settings_metabox_content()
3564
+	{
3565
+		$form = $this->_generate_global_settings_form();
3566
+		// already escaped
3567
+		echo $form->form_open(
3568
+			$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3569
+			'POST'
3570
+		);
3571
+		echo $form->get_html();
3572
+		echo $form->form_close();
3573
+	}
3574
+
3575
+
3576
+	/**
3577
+	 * This generates and returns the form object for the global messages settings.
3578
+	 *
3579
+	 * @return EE_Form_Section_Proper
3580
+	 * @throws EE_Error
3581
+	 * @throws InvalidArgumentException
3582
+	 * @throws ReflectionException
3583
+	 * @throws InvalidDataTypeException
3584
+	 * @throws InvalidInterfaceException
3585
+	 */
3586
+	protected function _generate_global_settings_form()
3587
+	{
3588
+		/** @var EE_Network_Core_Config $network_config */
3589
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3590
+
3591
+		return new EE_Form_Section_Proper(
3592
+			[
3593
+				'name'            => 'global_messages_settings',
3594
+				'html_id'         => 'global_messages_settings',
3595
+				'html_class'      => 'form-table',
3596
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3597
+				'subsections'     => apply_filters(
3598
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3599
+					[
3600
+						'do_messages_on_same_request' => new EE_Select_Input(
3601
+							[
3602
+								true  => esc_html__('On the same request', 'event_espresso'),
3603
+								false => esc_html__('On a separate request', 'event_espresso'),
3604
+							],
3605
+							[
3606
+								'default'         => $network_config->do_messages_on_same_request,
3607
+								'html_label_text' => esc_html__(
3608
+									'Generate and send all messages:',
3609
+									'event_espresso'
3610
+								),
3611
+								'html_help_text'  => esc_html__(
3612
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3613
+									'event_espresso'
3614
+								),
3615
+							]
3616
+						),
3617
+						'delete_threshold'            => new EE_Select_Input(
3618
+							[
3619
+								0  => esc_html__('Forever', 'event_espresso'),
3620
+								3  => esc_html__('3 Months', 'event_espresso'),
3621
+								6  => esc_html__('6 Months', 'event_espresso'),
3622
+								9  => esc_html__('9 Months', 'event_espresso'),
3623
+								12 => esc_html__('12 Months', 'event_espresso'),
3624
+								24 => esc_html__('24 Months', 'event_espresso'),
3625
+								36 => esc_html__('36 Months', 'event_espresso'),
3626
+							],
3627
+							[
3628
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3629
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3630
+								'html_help_text'  => esc_html__(
3631
+									'You can control how long a record of processed messages is kept via this option.',
3632
+									'event_espresso'
3633
+								),
3634
+							]
3635
+						),
3636
+						'update_settings'             => new EE_Submit_Input(
3637
+							[
3638
+								'default'         => esc_html__('Update', 'event_espresso'),
3639
+								'html_label_text' => '&nbsp',
3640
+							]
3641
+						),
3642
+					]
3643
+				),
3644
+			]
3645
+		);
3646
+	}
3647
+
3648
+
3649
+	/**
3650
+	 * This handles updating the global settings set on the admin page.
3651
+	 *
3652
+	 * @throws EE_Error
3653
+	 * @throws InvalidDataTypeException
3654
+	 * @throws InvalidInterfaceException
3655
+	 * @throws InvalidArgumentException
3656
+	 * @throws ReflectionException
3657
+	 */
3658
+	protected function _update_global_settings()
3659
+	{
3660
+		/** @var EE_Network_Core_Config $network_config */
3661
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3662
+		$messages_config = EE_Registry::instance()->CFG->messages;
3663
+		$form            = $this->_generate_global_settings_form();
3664
+		if ($form->was_submitted()) {
3665
+			$form->receive_form_submission();
3666
+			if ($form->is_valid()) {
3667
+				$valid_data = $form->valid_data();
3668
+				foreach ($valid_data as $property => $value) {
3669
+					$setter = 'set_' . $property;
3670
+					if (method_exists($network_config, $setter)) {
3671
+						$network_config->{$setter}($value);
3672
+					} elseif (
3673
+						property_exists($network_config, $property)
3674
+						&& $network_config->{$property} !== $value
3675
+					) {
3676
+						$network_config->{$property} = $value;
3677
+					} elseif (
3678
+						property_exists($messages_config, $property)
3679
+						&& $messages_config->{$property} !== $value
3680
+					) {
3681
+						$messages_config->{$property} = $value;
3682
+					}
3683
+				}
3684
+				// only update if the form submission was valid!
3685
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3686
+				EE_Registry::instance()->CFG->update_espresso_config();
3687
+				EE_Error::overwrite_success();
3688
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3689
+			}
3690
+		}
3691
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3692
+	}
3693
+
3694
+
3695
+	/**
3696
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3697
+	 *
3698
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3699
+	 * @return string html formatted tabs
3700
+	 * @throws DomainException
3701
+	 */
3702
+	protected function _get_mt_tabs($tab_array)
3703
+	{
3704
+		$tab_array = (array) $tab_array;
3705
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3706
+		$tabs      = '';
3707
+
3708
+		foreach ($tab_array as $tab) {
3709
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3710
+		}
3711
+
3712
+		return $tabs;
3713
+	}
3714
+
3715
+
3716
+	/**
3717
+	 * This prepares the content of the messenger meta box admin settings
3718
+	 *
3719
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3720
+	 * @return string html formatted content
3721
+	 * @throws DomainException
3722
+	 */
3723
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3724
+	{
3725
+
3726
+		$fields                                         = $messenger->get_admin_settings_fields();
3727
+		$settings_template_args['template_form_fields'] = '';
3728
+
3729
+		// is $messenger active?
3730
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3731
+
3732
+
3733
+		if (! empty($fields)) {
3734
+			$existing_settings = $messenger->get_existing_admin_settings();
3735
+
3736
+			foreach ($fields as $fldname => $fldprops) {
3737
+				$field_id                         = $messenger->name . '-' . $fldname;
3738
+				$template_form_field[ $field_id ] = [
3739
+					'name'       => 'messenger_settings[' . $field_id . ']',
3740
+					'label'      => $fldprops['label'],
3741
+					'input'      => $fldprops['field_type'],
3742
+					'type'       => $fldprops['value_type'],
3743
+					'required'   => $fldprops['required'],
3744
+					'validation' => $fldprops['validation'],
3745
+					'value'      => isset($existing_settings[ $field_id ])
3746
+						? $existing_settings[ $field_id ]
3747
+						: $fldprops['default'],
3748
+					'css_class'  => '',
3749
+					'format'     => $fldprops['format'],
3750
+				];
3751
+			}
3752
+
3753
+
3754
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3755
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3756
+				: '';
3757
+		}
3758
+
3759
+		// we also need some hidden fields
3760
+		$settings_template_args['hidden_fields'] = [
3761
+			'messenger_settings[messenger]' . $messenger->name => [
3762
+				'type'  => 'hidden',
3763
+				'value' => $messenger->name,
3764
+			],
3765
+			'type' . $messenger->name                          => [
3766
+				'type'  => 'hidden',
3767
+				'value' => 'messenger',
3768
+			],
3769
+		];
3770
+
3771
+		// make sure any active message types that are existing are included in the hidden fields
3772
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3773
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3774
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3775
+					'type'  => 'hidden',
3776
+					'value' => $mt,
3777
+				];
3778
+			}
3779
+		}
3780
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3781
+			$settings_template_args['hidden_fields'],
3782
+			'array'
3783
+		);
3784
+		$active                                  =
3785
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3786
+
3787
+		$settings_template_args['messenger']           = $messenger->name;
3788
+		$settings_template_args['description']         = $messenger->description;
3789
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3790
+
3791
+
3792
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3793
+			$messenger->name
3794
+		)
3795
+			? $settings_template_args['show_hide_edit_form']
3796
+			: ' hidden';
3797
+
3798
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3799
+			? ' hidden'
3800
+			: $settings_template_args['show_hide_edit_form'];
3801
+
3802
+
3803
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3804
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3805
+		$settings_template_args['on_off_status'] = $active;
3806
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3807
+		return EEH_Template::display_template(
3808
+			$template,
3809
+			$settings_template_args,
3810
+			true
3811
+		);
3812
+	}
3813
+
3814
+
3815
+	/**
3816
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3817
+	 *
3818
+	 * @throws DomainException
3819
+	 * @throws EE_Error
3820
+	 * @throws InvalidDataTypeException
3821
+	 * @throws InvalidInterfaceException
3822
+	 * @throws InvalidArgumentException
3823
+	 * @throws ReflectionException
3824
+	 */
3825
+	public function activate_messenger_toggle()
3826
+	{
3827
+		$success = true;
3828
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3829
+		// let's check that we have required data
3830
+
3831
+		if (! $this->_active_messenger_name) {
3832
+			EE_Error::add_error(
3833
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3834
+				__FILE__,
3835
+				__FUNCTION__,
3836
+				__LINE__
3837
+			);
3838
+			$success = false;
3839
+		}
3840
+
3841
+		// do a nonce check here since we're not arriving via a normal route
3842
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
3843
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
3844
+
3845
+		$this->_verify_nonce($nonce, $nonce_ref);
3846
+
3847
+
3848
+		$status = $this->request->getRequestParam('status');
3849
+		if (! $status) {
3850
+			EE_Error::add_error(
3851
+				esc_html__(
3852
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3853
+					'event_espresso'
3854
+				),
3855
+				__FILE__,
3856
+				__FUNCTION__,
3857
+				__LINE__
3858
+			);
3859
+			$success = false;
3860
+		}
3861
+
3862
+		// do check to verify we have a valid status.
3863
+		if ($status !== 'off' && $status !== 'on') {
3864
+			EE_Error::add_error(
3865
+				sprintf(
3866
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3867
+					$status
3868
+				),
3869
+				__FILE__,
3870
+				__FUNCTION__,
3871
+				__LINE__
3872
+			);
3873
+			$success = false;
3874
+		}
3875
+
3876
+		if ($success) {
3877
+			// made it here?  Stop dawdling then!!
3878
+			$success = $status === 'off'
3879
+				? $this->_deactivate_messenger($this->_active_messenger_name)
3880
+				: $this->_activate_messenger($this->_active_messenger_name);
3881
+		}
3882
+
3883
+		$this->_template_args['success'] = $success;
3884
+
3885
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
3886
+		$this->_return_json();
3887
+	}
3888
+
3889
+
3890
+	/**
3891
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3892
+	 *
3893
+	 * @throws DomainException
3894
+	 * @throws EE_Error
3895
+	 * @throws ReflectionException
3896
+	 * @throws InvalidDataTypeException
3897
+	 * @throws InvalidInterfaceException
3898
+	 * @throws InvalidArgumentException
3899
+	 */
3900
+	public function activate_mt_toggle()
3901
+	{
3902
+		$success = true;
3903
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3904
+
3905
+		// let's make sure we have the necessary data
3906
+		if (! $this->_active_message_type_name) {
3907
+			EE_Error::add_error(
3908
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3909
+				__FILE__,
3910
+				__FUNCTION__,
3911
+				__LINE__
3912
+			);
3913
+			$success = false;
3914
+		}
3915
+
3916
+		if (! $this->_active_messenger_name) {
3917
+			EE_Error::add_error(
3918
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3919
+				__FILE__,
3920
+				__FUNCTION__,
3921
+				__LINE__
3922
+			);
3923
+			$success = false;
3924
+		}
3925
+
3926
+		$status = $this->request->getRequestParam('status');
3927
+		if (! $status) {
3928
+			EE_Error::add_error(
3929
+				esc_html__(
3930
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3931
+					'event_espresso'
3932
+				),
3933
+				__FILE__,
3934
+				__FUNCTION__,
3935
+				__LINE__
3936
+			);
3937
+			$success = false;
3938
+		}
3939
+
3940
+
3941
+		// do check to verify we have a valid status.
3942
+		if ($status !== 'activate' && $status !== 'deactivate') {
3943
+			EE_Error::add_error(
3944
+				sprintf(
3945
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3946
+					$status
3947
+				),
3948
+				__FILE__,
3949
+				__FUNCTION__,
3950
+				__LINE__
3951
+			);
3952
+			$success = false;
3953
+		}
3954
+
3955
+
3956
+		// do a nonce check here since we're not arriving via a normal route
3957
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
3958
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
3959
+
3960
+		if ($success) {
3961
+			// made it here? um, what are you waiting for then?
3962
+			$success = $status === 'deactivate'
3963
+				? $this->_deactivate_message_type_for_messenger(
3964
+					$this->_active_messenger_name,
3965
+					$this->_active_message_type_name
3966
+				)
3967
+				: $this->_activate_message_type_for_messenger(
3968
+					$this->_active_messenger_name,
3969
+					$this->_active_message_type_name
3970
+				);
3971
+		}
3972
+
3973
+		$this->_template_args['success'] = $success;
3974
+		$this->_return_json();
3975
+	}
3976
+
3977
+
3978
+	/**
3979
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3980
+	 *
3981
+	 * @param string $messenger_name The name of the messenger being activated
3982
+	 * @return bool
3983
+	 * @throws DomainException
3984
+	 * @throws EE_Error
3985
+	 * @throws InvalidArgumentException
3986
+	 * @throws ReflectionException
3987
+	 * @throws InvalidDataTypeException
3988
+	 * @throws InvalidInterfaceException
3989
+	 */
3990
+	protected function _activate_messenger($messenger_name)
3991
+	{
3992
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3993
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3994
+			? $active_messenger->get_default_message_types()
3995
+			: [];
3996
+
3997
+		// ensure is active
3998
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
3999
+
4000
+		// set response_data for reload
4001
+		foreach ($message_types_to_activate as $message_type_name) {
4002
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4003
+			if (
4004
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4005
+					$messenger_name,
4006
+					$message_type_name
4007
+				)
4008
+				&& $message_type instanceof EE_message_type
4009
+			) {
4010
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4011
+				if ($message_type->get_admin_settings_fields()) {
4012
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4013
+				}
4014
+			}
4015
+		}
4016
+
4017
+		// add success message for activating messenger
4018
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4019
+	}
4020
+
4021
+
4022
+	/**
4023
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4024
+	 *
4025
+	 * @param string $messenger_name The name of the messenger being activated
4026
+	 * @return bool
4027
+	 * @throws DomainException
4028
+	 * @throws EE_Error
4029
+	 * @throws InvalidArgumentException
4030
+	 * @throws ReflectionException
4031
+	 * @throws InvalidDataTypeException
4032
+	 * @throws InvalidInterfaceException
4033
+	 */
4034
+	protected function _deactivate_messenger($messenger_name)
4035
+	{
4036
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4037
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4038
+
4039
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4040
+	}
4041
+
4042
+
4043
+	/**
4044
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4045
+	 *
4046
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4047
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4048
+	 * @return bool
4049
+	 * @throws DomainException
4050
+	 * @throws EE_Error
4051
+	 * @throws InvalidArgumentException
4052
+	 * @throws ReflectionException
4053
+	 * @throws InvalidDataTypeException
4054
+	 * @throws InvalidInterfaceException
4055
+	 */
4056
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4057
+	{
4058
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4059
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4060
+
4061
+		// ensure is active
4062
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4063
+
4064
+		// set response for load
4065
+		if (
4066
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4067
+				$messenger_name,
4068
+				$message_type_name
4069
+			)
4070
+		) {
4071
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4072
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4073
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4074
+			}
4075
+		}
4076
+
4077
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4078
+			$active_messenger,
4079
+			$message_type_to_activate
4080
+		);
4081
+	}
4082
+
4083
+
4084
+	/**
4085
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4086
+	 *
4087
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4088
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4089
+	 * @return bool
4090
+	 * @throws DomainException
4091
+	 * @throws EE_Error
4092
+	 * @throws InvalidArgumentException
4093
+	 * @throws ReflectionException
4094
+	 * @throws InvalidDataTypeException
4095
+	 * @throws InvalidInterfaceException
4096
+	 */
4097
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4098
+	{
4099
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4100
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4101
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4102
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4103
+
4104
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4105
+			$active_messenger,
4106
+			$message_type_to_deactivate
4107
+		);
4108
+	}
4109
+
4110
+
4111
+	/**
4112
+	 * This just initializes the defaults for activating messenger and message type responses.
4113
+	 */
4114
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4115
+	{
4116
+		$this->_template_args['data']['active_mts'] = [];
4117
+		$this->_template_args['data']['mt_reload']  = [];
4118
+	}
4119
+
4120
+
4121
+	/**
4122
+	 * Setup appropriate response for activating a messenger and/or message types
4123
+	 *
4124
+	 * @param EE_messenger         $messenger
4125
+	 * @param EE_message_type|null $message_type
4126
+	 * @return bool
4127
+	 * @throws DomainException
4128
+	 * @throws EE_Error
4129
+	 * @throws InvalidArgumentException
4130
+	 * @throws ReflectionException
4131
+	 * @throws InvalidDataTypeException
4132
+	 * @throws InvalidInterfaceException
4133
+	 */
4134
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4135
+		$messenger,
4136
+		EE_Message_Type $message_type = null
4137
+	) {
4138
+		// if $messenger isn't a valid messenger object then get out.
4139
+		if (! $messenger instanceof EE_Messenger) {
4140
+			EE_Error::add_error(
4141
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4142
+				__FILE__,
4143
+				__FUNCTION__,
4144
+				__LINE__
4145
+			);
4146
+			return false;
4147
+		}
4148
+		// activated
4149
+		if ($this->_template_args['data']['active_mts']) {
4150
+			EE_Error::overwrite_success();
4151
+			// activated a message type with the messenger
4152
+			if ($message_type instanceof EE_message_type) {
4153
+				EE_Error::add_success(
4154
+					sprintf(
4155
+						esc_html__(
4156
+							'%s message type has been successfully activated with the %s messenger',
4157
+							'event_espresso'
4158
+						),
4159
+						ucwords($message_type->label['singular']),
4160
+						ucwords($messenger->label['singular'])
4161
+					)
4162
+				);
4163
+
4164
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4165
+				if ($message_type->name === 'invoice') {
4166
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4167
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4168
+					if ($pm instanceof EE_Payment_Method) {
4169
+						EE_Error::add_attention(
4170
+							esc_html__(
4171
+								'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.',
4172
+								'event_espresso'
4173
+							)
4174
+						);
4175
+					}
4176
+				}
4177
+				// just toggles the entire messenger
4178
+			} else {
4179
+				EE_Error::add_success(
4180
+					sprintf(
4181
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4182
+						ucwords($messenger->label['singular'])
4183
+					)
4184
+				);
4185
+			}
4186
+
4187
+			return true;
4188
+
4189
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4190
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4191
+			// in which case we just give a success message for the messenger being successfully activated.
4192
+		} else {
4193
+			if (! $messenger->get_default_message_types()) {
4194
+				// messenger doesn't have any default message types so still a success.
4195
+				EE_Error::add_success(
4196
+					sprintf(
4197
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4198
+						ucwords($messenger->label['singular'])
4199
+					)
4200
+				);
4201
+
4202
+				return true;
4203
+			} else {
4204
+				EE_Error::add_error(
4205
+					$message_type instanceof EE_message_type
4206
+						? sprintf(
4207
+							esc_html__(
4208
+								'%s message type was not successfully activated with the %s messenger',
4209
+								'event_espresso'
4210
+							),
4211
+							ucwords($message_type->label['singular']),
4212
+							ucwords($messenger->label['singular'])
4213
+						)
4214
+						: sprintf(
4215
+							esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4216
+							ucwords($messenger->label['singular'])
4217
+						),
4218
+					__FILE__,
4219
+					__FUNCTION__,
4220
+					__LINE__
4221
+				);
4222
+
4223
+				return false;
4224
+			}
4225
+		}
4226
+	}
4227
+
4228
+
4229
+	/**
4230
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4231
+	 *
4232
+	 * @param EE_messenger         $messenger
4233
+	 * @param EE_message_type|null $message_type
4234
+	 * @return bool
4235
+	 * @throws DomainException
4236
+	 * @throws EE_Error
4237
+	 * @throws InvalidArgumentException
4238
+	 * @throws ReflectionException
4239
+	 * @throws InvalidDataTypeException
4240
+	 * @throws InvalidInterfaceException
4241
+	 */
4242
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4243
+		$messenger,
4244
+		EE_message_type $message_type = null
4245
+	) {
4246
+		EE_Error::overwrite_success();
4247
+
4248
+		// if $messenger isn't a valid messenger object then get out.
4249
+		if (! $messenger instanceof EE_Messenger) {
4250
+			EE_Error::add_error(
4251
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4252
+				__FILE__,
4253
+				__FUNCTION__,
4254
+				__LINE__
4255
+			);
4256
+
4257
+			return false;
4258
+		}
4259
+
4260
+		if ($message_type instanceof EE_message_type) {
4261
+			$message_type_name = $message_type->name;
4262
+			EE_Error::add_success(
4263
+				sprintf(
4264
+					esc_html__(
4265
+						'%s message type has been successfully deactivated for the %s messenger.',
4266
+						'event_espresso'
4267
+					),
4268
+					ucwords($message_type->label['singular']),
4269
+					ucwords($messenger->label['singular'])
4270
+				)
4271
+			);
4272
+		} else {
4273
+			$message_type_name = '';
4274
+			EE_Error::add_success(
4275
+				sprintf(
4276
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4277
+					ucwords($messenger->label['singular'])
4278
+				)
4279
+			);
4280
+		}
4281
+
4282
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4283
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4284
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4285
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4286
+			if ($count_updated > 0) {
4287
+				$msg = $message_type_name === 'invoice'
4288
+					? esc_html__(
4289
+						'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.',
4290
+						'event_espresso'
4291
+					)
4292
+					: esc_html__(
4293
+						'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.',
4294
+						'event_espresso'
4295
+					);
4296
+				EE_Error::add_attention($msg);
4297
+			}
4298
+		}
4299
+
4300
+		return true;
4301
+	}
4302
+
4303
+
4304
+	/**
4305
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4306
+	 *
4307
+	 * @throws DomainException
4308
+	 * @throws EE_Error
4309
+	 * @throws EE_Error
4310
+	 */
4311
+	public function update_mt_form()
4312
+	{
4313
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4314
+			EE_Error::add_error(
4315
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4316
+				__FILE__,
4317
+				__FUNCTION__,
4318
+				__LINE__
4319
+			);
4320
+			$this->_return_json();
4321
+		}
4322
+
4323
+		$message_types = $this->get_installed_message_types();
4324
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4325
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4326
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4327
+
4328
+		$this->_template_args['success'] = true;
4329
+		$this->_template_args['content'] = $content;
4330
+		$this->_return_json();
4331
+	}
4332
+
4333
+
4334
+	/**
4335
+	 * this handles saving the settings for a messenger or message type
4336
+	 *
4337
+	 * @throws EE_Error
4338
+	 * @throws EE_Error
4339
+	 */
4340
+	public function save_settings()
4341
+	{
4342
+		$type = $this->request->getRequestParam('type');
4343
+		if (! $type) {
4344
+			EE_Error::add_error(
4345
+				esc_html__(
4346
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4347
+					'event_espresso'
4348
+				),
4349
+				__FILE__,
4350
+				__FUNCTION__,
4351
+				__LINE__
4352
+			);
4353
+			$this->_template_args['error'] = true;
4354
+			$this->_return_json();
4355
+		}
4356
+
4357
+
4358
+		if ($type === 'messenger') {
4359
+			// this should be an array.
4360
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4361
+			$messenger = $settings['messenger'];
4362
+			// remove messenger and message_types from settings array
4363
+			unset($settings['messenger'], $settings['message_types']);
4364
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4365
+		} elseif ($type === 'message_type') {
4366
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4367
+			$messenger    = $settings['messenger'];
4368
+			$message_type = $settings['message_type'];
4369
+			// remove messenger and message_types from settings array
4370
+			unset($settings['messenger'], $settings['message_types']);
4371
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4372
+		}
4373
+
4374
+		// okay we should have the data all setup.  Now we just update!
4375
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4376
+
4377
+		if ($success) {
4378
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4379
+		} else {
4380
+			EE_Error::add_error(
4381
+				esc_html__('Settings did not get updated', 'event_espresso'),
4382
+				__FILE__,
4383
+				__FUNCTION__,
4384
+				__LINE__
4385
+			);
4386
+		}
4387
+
4388
+		$this->_template_args['success'] = $success;
4389
+		$this->_return_json();
4390
+	}
4391
+
4392
+
4393
+
4394
+
4395
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4396
+
4397
+
4398
+	/**
4399
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4400
+	 * However, this does not send immediately, it just queues for sending.
4401
+	 *
4402
+	 * @throws EE_Error
4403
+	 * @throws InvalidDataTypeException
4404
+	 * @throws InvalidInterfaceException
4405
+	 * @throws InvalidArgumentException
4406
+	 * @throws ReflectionException
4407
+	 * @since 4.9.0
4408
+	 */
4409
+	protected function _generate_now()
4410
+	{
4411
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4412
+		$this->_redirect_after_action(false, '', '', [], true);
4413
+	}
4414
+
4415
+
4416
+	/**
4417
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4418
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4419
+	 *
4420
+	 * @throws EE_Error
4421
+	 * @throws InvalidDataTypeException
4422
+	 * @throws InvalidInterfaceException
4423
+	 * @throws InvalidArgumentException
4424
+	 * @throws ReflectionException
4425
+	 * @since 4.9.0
4426
+	 */
4427
+	protected function _generate_and_send_now()
4428
+	{
4429
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4430
+		$this->_redirect_after_action(false, '', '', [], true);
4431
+	}
4432
+
4433
+
4434
+	/**
4435
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4436
+	 *
4437
+	 * @throws EE_Error
4438
+	 * @throws InvalidDataTypeException
4439
+	 * @throws InvalidInterfaceException
4440
+	 * @throws InvalidArgumentException
4441
+	 * @throws ReflectionException
4442
+	 * @since 4.9.0
4443
+	 */
4444
+	protected function _queue_for_resending()
4445
+	{
4446
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4447
+		$this->_redirect_after_action(false, '', '', [], true);
4448
+	}
4449
+
4450
+
4451
+	/**
4452
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4453
+	 *
4454
+	 * @throws EE_Error
4455
+	 * @throws InvalidDataTypeException
4456
+	 * @throws InvalidInterfaceException
4457
+	 * @throws InvalidArgumentException
4458
+	 * @throws ReflectionException
4459
+	 * @since 4.9.0
4460
+	 */
4461
+	protected function _send_now()
4462
+	{
4463
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4464
+		$this->_redirect_after_action(false, '', '', [], true);
4465
+	}
4466
+
4467
+
4468
+	/**
4469
+	 * Deletes EE_messages for IDs in the request.
4470
+	 *
4471
+	 * @throws EE_Error
4472
+	 * @throws InvalidDataTypeException
4473
+	 * @throws InvalidInterfaceException
4474
+	 * @throws InvalidArgumentException
4475
+	 * @since 4.9.0
4476
+	 */
4477
+	protected function _delete_ee_messages()
4478
+	{
4479
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4480
+		$deleted_count = 0;
4481
+		foreach ($MSG_IDs as $MSG_ID) {
4482
+			if (EEM_Message::instance()->delete_by_ID($MSG_ID)) {
4483
+				$deleted_count++;
4484
+			}
4485
+		}
4486
+		if ($deleted_count) {
4487
+			EE_Error::add_success(
4488
+				esc_html(
4489
+					_n(
4490
+						'Message successfully deleted',
4491
+						'Messages successfully deleted',
4492
+						$deleted_count,
4493
+						'event_espresso'
4494
+					)
4495
+				)
4496
+			);
4497
+		} else {
4498
+			EE_Error::add_error(
4499
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4500
+				__FILE__,
4501
+				__FUNCTION__,
4502
+				__LINE__
4503
+			);
4504
+		}
4505
+		$this->_redirect_after_action(false, '', '', [], true);
4506
+	}
4507
+
4508
+
4509
+	/**
4510
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4511
+	 *
4512
+	 * @return array
4513
+	 * @since 4.9.0
4514
+	 */
4515
+	protected function _get_msg_ids_from_request()
4516
+	{
4517
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4518
+		if (empty($MSG_IDs)) {
4519
+			return [];
4520
+		}
4521
+		// if 'MSG_ID' was just a single ID (not an array)
4522
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4523
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4524
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4525
+			? $MSG_IDs
4526
+			: array_keys($MSG_IDs);
4527
+	}
4528 4528
 }
Please login to merge, or discard this patch.
Spacing   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
         $i = 1;
156 156
         foreach ($active_messengers as $active_messenger) {
157 157
             if ($active_messenger instanceof EE_Message) {
158
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
159
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
158
+                $m_values[$i]['id']   = $active_messenger->messenger();
159
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
160 160
                 $i++;
161 161
             }
162 162
         }
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
         $i               = 1;
193 193
         foreach ($active_messages as $active_message) {
194 194
             if ($active_message instanceof EE_Message) {
195
-                $mt_values[ $i ]['id']   = $active_message->message_type();
196
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
195
+                $mt_values[$i]['id']   = $active_message->message_type();
196
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
197 197
                 $i++;
198 198
             }
199 199
         }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
                 if ($message_type instanceof EE_message_type) {
233 233
                     $message_type_contexts = $message_type->get_contexts();
234 234
                     foreach ($message_type_contexts as $context => $context_details) {
235
-                        $contexts[ $context ] = $context_details['label'];
235
+                        $contexts[$context] = $context_details['label'];
236 236
                     }
237 237
                 }
238 238
             }
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
266 266
             $messenger_options
267 267
         );
268
-        $input             = new EE_Select_Input(
268
+        $input = new EE_Select_Input(
269 269
             $messenger_options,
270 270
             [
271 271
                 'html_name'  => 'ee_messenger_filter_by',
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
303 303
             $message_type_options
304 304
         );
305
-        $input                = new EE_Select_Input(
305
+        $input = new EE_Select_Input(
306 306
             $message_type_options,
307 307
             [
308 308
                 'html_name'  => 'ee_message_type_filter_by',
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
340 340
             $context_options
341 341
         );
342
-        $input           = new EE_Select_Input(
342
+        $input = new EE_Select_Input(
343 343
             $context_options,
344 344
             [
345 345
                 'html_name'  => 'ee_context_filter_by',
@@ -721,53 +721,53 @@  discard block
 block discarded – undo
721 721
 
722 722
     public function messages_help_tab()
723 723
     {
724
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
724
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
725 725
     }
726 726
 
727 727
 
728 728
     public function messengers_help_tab()
729 729
     {
730
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
730
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
731 731
     }
732 732
 
733 733
 
734 734
     public function message_types_help_tab()
735 735
     {
736
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
736
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
737 737
     }
738 738
 
739 739
 
740 740
     public function messages_overview_help_tab()
741 741
     {
742
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
742
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
743 743
     }
744 744
 
745 745
 
746 746
     public function message_templates_help_tab()
747 747
     {
748
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
748
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
749 749
     }
750 750
 
751 751
 
752 752
     public function edit_message_template_help_tab()
753 753
     {
754
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
754
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
755 755
                         . esc_attr__('Editor Title', 'event_espresso')
756 756
                         . '" />';
757
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
757
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
758 758
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
759 759
                         . '" />';
760
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
760
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
761 761
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
762 762
                         . '" />';
763
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
763
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
764 764
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
765 765
                         . '" />';
766
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
766
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
767 767
                         . esc_attr__('Publish Metabox', 'event_espresso')
768 768
                         . '" />';
769 769
         EEH_Template::display_template(
770
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
770
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
771 771
             $args
772 772
         );
773 773
     }
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
         $this->_set_shortcodes();
783 783
         $args['shortcodes'] = $this->_shortcodes;
784 784
         EEH_Template::display_template(
785
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
785
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
786 786
             $args
787 787
         );
788 788
     }
@@ -790,16 +790,16 @@  discard block
 block discarded – undo
790 790
 
791 791
     public function preview_message_help_tab()
792 792
     {
793
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
793
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
794 794
     }
795 795
 
796 796
 
797 797
     public function settings_help_tab()
798 798
     {
799
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
800
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
801
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
802
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
799
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
800
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
801
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
802
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
803 803
         $args['img3'] = '<div class="switch">'
804 804
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
805 805
                         . ' type="checkbox" checked="checked">'
@@ -810,25 +810,25 @@  discard block
 block discarded – undo
810 810
                         . ' type="checkbox">'
811 811
                         . '<label for="ee-on-off-toggle-on"></label>'
812 812
                         . '</div>';
813
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
813
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
814 814
     }
815 815
 
816 816
 
817 817
     public function load_scripts_styles()
818 818
     {
819
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
819
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
820 820
         wp_enqueue_style('espresso_ee_msg');
821 821
 
822 822
         wp_register_script(
823 823
             'ee-messages-settings',
824
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
824
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
825 825
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
826 826
             EVENT_ESPRESSO_VERSION,
827 827
             true
828 828
         );
829 829
         wp_register_script(
830 830
             'ee-msg-list-table-js',
831
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
831
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
832 832
             ['ee-dialog'],
833 833
             EVENT_ESPRESSO_VERSION
834 834
         );
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
 
872 872
         $this->_set_shortcodes();
873 873
 
874
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
874
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
875 875
             esc_html__(
876 876
                 '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.',
877 877
                 'event_espresso'
@@ -883,14 +883,14 @@  discard block
 block discarded – undo
883 883
             '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?',
884 884
             'event_espresso'
885 885
         );
886
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
886
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
887 887
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
888 888
             'event_espresso'
889 889
         );
890 890
 
891 891
         wp_register_script(
892 892
             'ee_msgs_edit_js',
893
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
893
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
894 894
             ['jquery'],
895 895
             EVENT_ESPRESSO_VERSION
896 896
         );
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
     {
934 934
         wp_register_style(
935 935
             'ee-message-settings',
936
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
936
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
937 937
             [],
938 938
             EVENT_ESPRESSO_VERSION
939 939
         );
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
             }
1020 1020
             $status_bulk_actions = $common_bulk_actions;
1021 1021
             // unset bulk actions not applying to status
1022
-            if (! empty($status_bulk_actions)) {
1022
+            if ( ! empty($status_bulk_actions)) {
1023 1023
                 switch ($status) {
1024 1024
                     case EEM_Message::status_idle:
1025 1025
                     case EEM_Message::status_resend:
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
                 continue;
1049 1049
             }
1050 1050
 
1051
-            $this->_views[ strtolower($status) ] = [
1051
+            $this->_views[strtolower($status)] = [
1052 1052
                 'slug'        => strtolower($status),
1053 1053
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1054 1054
                 'count'       => 0,
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
             if ($action_item === 'see_notifications_for') {
1098 1098
                 continue;
1099 1099
             }
1100
-            $action_items[ $action_item ] = [
1100
+            $action_items[$action_item] = [
1101 1101
                 'class' => $action_details['css_class'],
1102 1102
                 'desc'  => $action_details['label'],
1103 1103
             ];
@@ -1106,37 +1106,37 @@  discard block
 block discarded – undo
1106 1106
         /** @var array $status_items status legend setup */
1107 1107
         $status_items = [
1108 1108
             'sent_status'                => [
1109
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1109
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1110 1110
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1111 1111
             ],
1112 1112
             'idle_status'                => [
1113
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1113
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1114 1114
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1115 1115
             ],
1116 1116
             'failed_status'              => [
1117
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1117
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1118 1118
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1119 1119
             ],
1120 1120
             'messenger_executing_status' => [
1121
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1121
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1122 1122
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1123 1123
             ],
1124 1124
             'resend_status'              => [
1125
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1125
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1126 1126
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1127 1127
             ],
1128 1128
             'incomplete_status'          => [
1129
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1129
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1130 1130
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1131 1131
             ],
1132 1132
             'retry_status'               => [
1133
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1133
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1134 1134
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1135 1135
             ],
1136 1136
         ];
1137 1137
         if (EEM_Message::debug()) {
1138 1138
             $status_items['debug_only_status'] = [
1139
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1139
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1140 1140
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1141 1141
             ];
1142 1142
         }
@@ -1151,11 +1151,11 @@  discard block
 block discarded – undo
1151 1151
     protected function _custom_mtps_preview()
1152 1152
     {
1153 1153
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1154
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1155
-                                                . ' alt="' . esc_attr__(
1154
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1155
+                                                . ' alt="'.esc_attr__(
1156 1156
                                                     'Preview Custom Message Templates screenshot',
1157 1157
                                                     'event_espresso'
1158
-                                                ) . '" />';
1158
+                                                ).'" />';
1159 1159
         $this->_template_args['preview_text'] = '<strong>'
1160 1160
                                                 . esc_html__(
1161 1161
                                                     '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.',
@@ -1227,7 +1227,7 @@  discard block
 block discarded – undo
1227 1227
         $installed               = [];
1228 1228
 
1229 1229
         foreach ($installed_message_types as $message_type) {
1230
-            $installed[ $message_type->name ] = $message_type;
1230
+            $installed[$message_type->name] = $message_type;
1231 1231
         }
1232 1232
 
1233 1233
         return $installed;
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
         // we need to assemble the title from Various details
1357 1357
         $context_label = sprintf(
1358 1358
             esc_html__('(%s %s)', 'event_espresso'),
1359
-            $c_config[ $context ]['label'],
1359
+            $c_config[$context]['label'],
1360 1360
             ucwords($c_label['label'])
1361 1361
         );
1362 1362
 
@@ -1378,7 +1378,7 @@  discard block
 block discarded – undo
1378 1378
             $message_template_group->message_type()
1379 1379
         );
1380 1380
 
1381
-        if (! $template_field_structure) {
1381
+        if ( ! $template_field_structure) {
1382 1382
             $template_field_structure = false;
1383 1383
             $template_fields          = esc_html__(
1384 1384
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1392,21 +1392,21 @@  discard block
 block discarded – undo
1392 1392
 
1393 1393
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1394 1394
         // will get handled in the "extra" array.
1395
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1396
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1397
-                unset($template_field_structure[ $context ][ $reference_field ]);
1395
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1396
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1397
+                unset($template_field_structure[$context][$reference_field]);
1398 1398
             }
1399 1399
         }
1400 1400
 
1401 1401
         // let's loop through the template_field_structure and actually assemble the input fields!
1402
-        if (! empty($template_field_structure)) {
1403
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1402
+        if ( ! empty($template_field_structure)) {
1403
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1404 1404
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1405 1405
                 // the extra array and reset them.
1406 1406
                 if ($template_field === 'extra') {
1407 1407
                     $this->_template_args['is_extra_fields'] = true;
1408 1408
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1409
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1409
+                        $message_template = $message_templates[$context][$reference_field];
1410 1410
                         $content          = $message_template instanceof EE_Message_Template
1411 1411
                             ? $message_template->get('MTP_content')
1412 1412
                             : '';
@@ -1415,7 +1415,7 @@  discard block
 block discarded – undo
1415 1415
                             $continue = false;
1416 1416
                             if (isset($extra_array['shortcodes_required'])) {
1417 1417
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1418
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1418
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1419 1419
                                         $continue = true;
1420 1420
                                     }
1421 1421
                                 }
@@ -1424,55 +1424,55 @@  discard block
 block discarded – undo
1424 1424
                                 }
1425 1425
                             }
1426 1426
 
1427
-                            $field_id                                  = $reference_field
1427
+                            $field_id = $reference_field
1428 1428
                                                                          . '-'
1429 1429
                                                                          . $extra_field
1430 1430
                                                                          . '-content';
1431
-                            $template_form_fields[ $field_id ]         = $extra_array;
1432
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1431
+                            $template_form_fields[$field_id]         = $extra_array;
1432
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1433 1433
                                                                          . $reference_field
1434 1434
                                                                          . '][content]['
1435
-                                                                         . $extra_field . ']';
1436
-                            $css_class                                 = isset($extra_array['css_class'])
1435
+                                                                         . $extra_field.']';
1436
+                            $css_class = isset($extra_array['css_class'])
1437 1437
                                 ? $extra_array['css_class']
1438 1438
                                 : '';
1439 1439
 
1440
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1440
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1441 1441
                                                                               && in_array($extra_field, $v_fields, true)
1442 1442
                                                                               && (
1443
-                                                                                  is_array($validators[ $extra_field ])
1444
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1443
+                                                                                  is_array($validators[$extra_field])
1444
+                                                                                  && isset($validators[$extra_field]['msg'])
1445 1445
                                                                               )
1446
-                                ? 'validate-error ' . $css_class
1446
+                                ? 'validate-error '.$css_class
1447 1447
                                 : $css_class;
1448 1448
 
1449
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1450
-                                                                          && isset($content[ $extra_field ])
1451
-                                ? $content[ $extra_field ]
1449
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1450
+                                                                          && isset($content[$extra_field])
1451
+                                ? $content[$extra_field]
1452 1452
                                 : '';
1453 1453
 
1454 1454
                             // do we have a validation error?  if we do then let's use that value instead
1455
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1456
-                                ? $validators[ $extra_field ]['value']
1457
-                                : $template_form_fields[ $field_id ]['value'];
1455
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1456
+                                ? $validators[$extra_field]['value']
1457
+                                : $template_form_fields[$field_id]['value'];
1458 1458
 
1459 1459
 
1460
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1460
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1461 1461
 
1462 1462
                             // shortcode selector
1463 1463
                             $field_name_to_use                                   = $extra_field === 'main'
1464 1464
                                 ? 'content'
1465 1465
                                 : $extra_field;
1466
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1466
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1467 1467
                                 $field_name_to_use,
1468 1468
                                 $field_id
1469 1469
                             );
1470 1470
                         }
1471
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1472
-                        $template_field_template_name_id = $reference_field . '-name';
1471
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1472
+                        $template_field_template_name_id = $reference_field.'-name';
1473 1473
 
1474
-                        $template_form_fields[ $template_field_MTP_id ] = [
1475
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1474
+                        $template_form_fields[$template_field_MTP_id] = [
1475
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1476 1476
                             'label'      => null,
1477 1477
                             'input'      => 'hidden',
1478 1478
                             'type'       => 'int',
@@ -1484,8 +1484,8 @@  discard block
 block discarded – undo
1484 1484
                             'db-col'     => 'MTP_ID',
1485 1485
                         ];
1486 1486
 
1487
-                        $template_form_fields[ $template_field_template_name_id ] = [
1488
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1487
+                        $template_form_fields[$template_field_template_name_id] = [
1488
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1489 1489
                             'label'      => null,
1490 1490
                             'input'      => 'hidden',
1491 1491
                             'type'       => 'string',
@@ -1499,38 +1499,38 @@  discard block
 block discarded – undo
1499 1499
                     }
1500 1500
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1501 1501
                 } else {
1502
-                    $field_id                                   = $template_field . '-content';
1503
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1504
-                    $template_form_fields[ $field_id ]['name']  =
1505
-                        'MTP_template_fields[' . $template_field . '][content]';
1502
+                    $field_id                                   = $template_field.'-content';
1503
+                    $template_form_fields[$field_id]          = $field_setup_array;
1504
+                    $template_form_fields[$field_id]['name']  =
1505
+                        'MTP_template_fields['.$template_field.'][content]';
1506 1506
                     $message_template                           =
1507
-                        isset($message_templates[ $context ][ $template_field ])
1508
-                            ? $message_templates[ $context ][ $template_field ]
1507
+                        isset($message_templates[$context][$template_field])
1508
+                            ? $message_templates[$context][$template_field]
1509 1509
                             : null;
1510
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1511
-                                                                  && is_array($message_templates[ $context ])
1510
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1511
+                                                                  && is_array($message_templates[$context])
1512 1512
                                                                   && $message_template instanceof EE_Message_Template
1513 1513
                         ? $message_template->get('MTP_content')
1514 1514
                         : '';
1515 1515
 
1516 1516
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1517
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1518
-                        ? $validators[ $template_field ]['value']
1519
-                        : $template_form_fields[ $field_id ]['value'];
1517
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1518
+                        ? $validators[$template_field]['value']
1519
+                        : $template_form_fields[$field_id]['value'];
1520 1520
 
1521 1521
 
1522
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1522
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1523 1523
                     $css_class                                      = isset($field_setup_array['css_class'])
1524 1524
                         ? $field_setup_array['css_class']
1525 1525
                         : '';
1526
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1526
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1527 1527
                                                                       && in_array($template_field, $v_fields, true)
1528
-                                                                      && isset($validators[ $template_field ]['msg'])
1529
-                        ? 'validate-error ' . $css_class
1528
+                                                                      && isset($validators[$template_field]['msg'])
1529
+                        ? 'validate-error '.$css_class
1530 1530
                         : $css_class;
1531 1531
 
1532 1532
                     // shortcode selector
1533
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1533
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1534 1534
                         $template_field,
1535 1535
                         $field_id
1536 1536
                     );
@@ -1538,12 +1538,12 @@  discard block
 block discarded – undo
1538 1538
 
1539 1539
                 // k took care of content field(s) now let's take care of others.
1540 1540
 
1541
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1542
-                $template_field_field_template_name_id = $template_field . '-name';
1541
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1542
+                $template_field_field_template_name_id = $template_field.'-name';
1543 1543
 
1544 1544
                 // foreach template field there are actually two form fields created
1545
-                $template_form_fields[ $template_field_MTP_id ] = [
1546
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1545
+                $template_form_fields[$template_field_MTP_id] = [
1546
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1547 1547
                     'label'      => null,
1548 1548
                     'input'      => 'hidden',
1549 1549
                     'type'       => 'int',
@@ -1555,8 +1555,8 @@  discard block
 block discarded – undo
1555 1555
                     'db-col'     => 'MTP_ID',
1556 1556
                 ];
1557 1557
 
1558
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1559
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1558
+                $template_form_fields[$template_field_field_template_name_id] = [
1559
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1560 1560
                     'label'      => null,
1561 1561
                     'input'      => 'hidden',
1562 1562
                     'type'       => 'string',
@@ -1673,7 +1673,7 @@  discard block
 block discarded – undo
1673 1673
                 'format'     => '%d',
1674 1674
                 'db-col'     => 'MTP_deleted',
1675 1675
             ];
1676
-            $sidebar_form_fields['ee-msg-author']  = [
1676
+            $sidebar_form_fields['ee-msg-author'] = [
1677 1677
                 'name'       => 'MTP_user_id',
1678 1678
                 'label'      => esc_html__('Author', 'event_espresso'),
1679 1679
                 'input'      => 'hidden',
@@ -1692,17 +1692,17 @@  discard block
 block discarded – undo
1692 1692
                 'value' => $action,
1693 1693
             ];
1694 1694
 
1695
-            $sidebar_form_fields['ee-msg-id']        = [
1695
+            $sidebar_form_fields['ee-msg-id'] = [
1696 1696
                 'name'  => 'id',
1697 1697
                 'input' => 'hidden',
1698 1698
                 'type'  => 'int',
1699 1699
                 'value' => $GRP_ID,
1700 1700
             ];
1701 1701
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1702
-                'name'  => $action . '_nonce',
1702
+                'name'  => $action.'_nonce',
1703 1703
                 'input' => 'hidden',
1704 1704
                 'type'  => 'string',
1705
-                'value' => wp_create_nonce($action . '_nonce'),
1705
+                'value' => wp_create_nonce($action.'_nonce'),
1706 1706
             ];
1707 1707
 
1708 1708
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1733,7 +1733,7 @@  discard block
 block discarded – undo
1733 1733
         );
1734 1734
 
1735 1735
         // add preview button
1736
-        $preview_url    = parent::add_query_args_and_nonce(
1736
+        $preview_url = parent::add_query_args_and_nonce(
1737 1737
             [
1738 1738
                 'message_type' => $message_template_group->message_type(),
1739 1739
                 'messenger'    => $message_template_group->messenger(),
@@ -1744,7 +1744,7 @@  discard block
 block discarded – undo
1744 1744
             ],
1745 1745
             $this->_admin_base_url
1746 1746
         );
1747
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1747
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1748 1748
                           . esc_html__('Preview', 'event_espresso')
1749 1749
                           . '</a>';
1750 1750
 
@@ -1778,11 +1778,11 @@  discard block
 block discarded – undo
1778 1778
             $context_label
1779 1779
         );
1780 1780
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1781
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1781
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1782 1782
 
1783 1783
         $this->_template_path = $this->_template_args['GRP_ID']
1784 1784
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1785
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1785
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1786 1786
 
1787 1787
         // send along EE_Message_Template_Group object for further template use.
1788 1788
         $this->_template_args['MTP'] = $message_template_group;
@@ -1838,7 +1838,7 @@  discard block
 block discarded – undo
1838 1838
     ) {
1839 1839
         $template_args = [
1840 1840
             'context'                   => $context,
1841
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1841
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1842 1842
             'is_active'                 => $message_template_group->is_context_active($context),
1843 1843
             'on_off_action'             => $message_template_group->is_context_active($context)
1844 1844
                 ? 'context-off'
@@ -1847,7 +1847,7 @@  discard block
 block discarded – undo
1847 1847
             'message_template_group_id' => $message_template_group->ID(),
1848 1848
         ];
1849 1849
         return EEH_Template::display_template(
1850
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1850
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1851 1851
             $template_args,
1852 1852
             true
1853 1853
         );
@@ -1904,7 +1904,7 @@  discard block
 block discarded – undo
1904 1904
         }
1905 1905
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1906 1906
         $message_template_group    = EEM_Message_Template_Group::instance()->get_one_by_ID($message_template_group_id);
1907
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1907
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1908 1908
             EE_Error::add_error(
1909 1909
                 sprintf(
1910 1910
                     esc_html__(
@@ -2036,7 +2036,7 @@  discard block
 block discarded – undo
2036 2036
         $messenger    = $this->request->getRequestParam('msgr');
2037 2037
         $message_type = $this->request->getRequestParam('mt');
2038 2038
         // we need to make sure we've got the info we need.
2039
-        if (! ($GRP_ID && $messenger && $message_type)) {
2039
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2040 2040
             EE_Error::add_error(
2041 2041
                 esc_html__(
2042 2042
                     '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.',
@@ -2073,7 +2073,7 @@  discard block
 block discarded – undo
2073 2073
         }
2074 2074
 
2075 2075
         // any error messages?
2076
-        if (! $success) {
2076
+        if ( ! $success) {
2077 2077
             EE_Error::add_error(
2078 2078
                 esc_html__(
2079 2079
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2125,8 +2125,8 @@  discard block
 block discarded – undo
2125 2125
     public function _preview_message($send = false)
2126 2126
     {
2127 2127
         // first make sure we've got the necessary parameters
2128
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2129
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2128
+        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2129
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2130 2130
             EE_Error::add_error(
2131 2131
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2132 2132
                 __FILE__,
@@ -2152,7 +2152,7 @@  discard block
 block discarded – undo
2152 2152
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2153 2153
 
2154 2154
         // let's add a button to go back to the edit view
2155
-        $query_args             = [
2155
+        $query_args = [
2156 2156
             'id'      => $GRP_ID,
2157 2157
             'evt_id'  => $EVT_ID,
2158 2158
             'context' => $context,
@@ -2173,7 +2173,7 @@  discard block
 block discarded – undo
2173 2173
         $preview_title = sprintf(
2174 2174
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2175 2175
             $active_messenger_label,
2176
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2176
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2177 2177
         );
2178 2178
         if (empty($preview)) {
2179 2179
             $this->noEventsErrorMessage();
@@ -2181,7 +2181,7 @@  discard block
 block discarded – undo
2181 2181
         // setup display of preview.
2182 2182
         $this->_admin_page_title                    = $preview_title;
2183 2183
         $this->_template_args['admin_page_title']   = $preview_title;
2184
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2184
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2185 2185
         $this->_template_args['data']['force_json'] = true;
2186 2186
 
2187 2187
         return '';
@@ -2202,7 +2202,7 @@  discard block
 block discarded – undo
2202 2202
             ],
2203 2203
             admin_url('admin.php')
2204 2204
         );
2205
-        $message    = $test_send
2205
+        $message = $test_send
2206 2206
             ? esc_html__(
2207 2207
                 '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!',
2208 2208
                 'event_espresso'
@@ -2295,10 +2295,10 @@  discard block
 block discarded – undo
2295 2295
             // only include template packs that support this messenger and message type!
2296 2296
             $supports = $tp->get_supports();
2297 2297
             if (
2298
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2298
+                ! isset($supports[$this->_message_template_group->messenger()])
2299 2299
                 || ! in_array(
2300 2300
                     $this->_message_template_group->message_type(),
2301
-                    $supports[ $this->_message_template_group->messenger() ],
2301
+                    $supports[$this->_message_template_group->messenger()],
2302 2302
                     true
2303 2303
                 )
2304 2304
             ) {
@@ -2322,7 +2322,7 @@  discard block
 block discarded – undo
2322 2322
         }
2323 2323
 
2324 2324
         // setup variation select values for the currently selected template.
2325
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2325
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2326 2326
             $this->_message_template_group->messenger(),
2327 2327
             $this->_message_template_group->message_type()
2328 2328
         );
@@ -2336,12 +2336,12 @@  discard block
 block discarded – undo
2336 2336
 
2337 2337
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2338 2338
 
2339
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2339
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2340 2340
             'MTP_template_pack',
2341 2341
             $tp_select_values,
2342 2342
             $this->_message_template_group->get_template_pack_name()
2343 2343
         );
2344
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2344
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2345 2345
             'MTP_template_variation',
2346 2346
             $variations_select_values,
2347 2347
             $this->_message_template_group->get_template_pack_variation()
@@ -2351,7 +2351,7 @@  discard block
 block discarded – undo
2351 2351
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2352 2352
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2353 2353
 
2354
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2354
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2355 2355
 
2356 2356
         EEH_Template::display_template($template, $template_args);
2357 2357
     }
@@ -2377,33 +2377,33 @@  discard block
 block discarded – undo
2377 2377
         // first we need to see if there are any fields
2378 2378
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2379 2379
 
2380
-        if (! empty($fields)) {
2380
+        if ( ! empty($fields)) {
2381 2381
             // yup there be fields
2382 2382
             foreach ($fields as $field => $config) {
2383
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2383
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2384 2384
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2385 2385
                 $default  = isset($config['default']) ? $config['default'] : '';
2386 2386
                 $default  = isset($config['value']) ? $config['value'] : $default;
2387 2387
 
2388 2388
                 // if type is hidden and the value is empty
2389 2389
                 // something may have gone wrong so let's correct with the defaults
2390
-                $fix                = $config['input'] === 'hidden'
2391
-                                      && isset($existing[ $field ])
2392
-                                      && empty($existing[ $field ])
2390
+                $fix = $config['input'] === 'hidden'
2391
+                                      && isset($existing[$field])
2392
+                                      && empty($existing[$field])
2393 2393
                     ? $default
2394 2394
                     : '';
2395
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2396
-                    ? $existing[ $field ]
2395
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2396
+                    ? $existing[$field]
2397 2397
                     : $fix;
2398 2398
 
2399
-                $template_form_fields[ $field_id ] = [
2400
-                    'name'       => 'test_settings_fld[' . $field . ']',
2399
+                $template_form_fields[$field_id] = [
2400
+                    'name'       => 'test_settings_fld['.$field.']',
2401 2401
                     'label'      => $config['label'],
2402 2402
                     'input'      => $config['input'],
2403 2403
                     'type'       => $config['type'],
2404 2404
                     'required'   => $config['required'],
2405 2405
                     'validation' => $config['validation'],
2406
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2406
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2407 2407
                     'css_class'  => $config['css_class'],
2408 2408
                     'options'    => isset($config['options']) ? $config['options'] : [],
2409 2409
                     'default'    => $default,
@@ -2417,7 +2417,7 @@  discard block
 block discarded – undo
2417 2417
             : '';
2418 2418
 
2419 2419
         // print out $test_settings_fields
2420
-        if (! empty($test_settings_html)) {
2420
+        if ( ! empty($test_settings_html)) {
2421 2421
             $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2422 2422
             $test_settings_html .= 'name="test_button" value="';
2423 2423
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2463,7 +2463,7 @@  discard block
 block discarded – undo
2463 2463
         ];
2464 2464
 
2465 2465
         return EEH_Template::display_template(
2466
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2466
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2467 2467
             $template_args,
2468 2468
             true
2469 2469
         );
@@ -2489,7 +2489,7 @@  discard block
 block discarded – undo
2489 2489
         // $messenger = $this->_message_template_group->messenger_obj();
2490 2490
         // now let's set the content depending on the status of the shortcodes array
2491 2491
         if (empty($shortcodes)) {
2492
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2492
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2493 2493
             return;
2494 2494
         }
2495 2495
         ?>
@@ -2525,7 +2525,7 @@  discard block
 block discarded – undo
2525 2525
     {
2526 2526
 
2527 2527
         // no need to run this if the property is already set
2528
-        if (! empty($this->_shortcodes)) {
2528
+        if ( ! empty($this->_shortcodes)) {
2529 2529
             return;
2530 2530
         }
2531 2531
 
@@ -2580,7 +2580,7 @@  discard block
 block discarded – undo
2580 2580
     protected function _set_message_template_group()
2581 2581
     {
2582 2582
 
2583
-        if (! empty($this->_message_template_group)) {
2583
+        if ( ! empty($this->_message_template_group)) {
2584 2584
             return;
2585 2585
         } //get out if this is already set.
2586 2586
 
@@ -2630,8 +2630,8 @@  discard block
 block discarded – undo
2630 2630
                     <?php
2631 2631
                 }
2632 2632
                 // setup nonce_url
2633
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2634
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2633
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2634
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2635 2635
                 ?>
2636 2636
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2637 2637
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2644,7 +2644,7 @@  discard block
 block discarded – undo
2644 2644
                             $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2645 2645
                             ?>
2646 2646
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2647
-                                <?php echo $context_details[ $context ]['label']; // already escaped ?>
2647
+                                <?php echo $context_details[$context]['label']; // already escaped ?>
2648 2648
                             </option>
2649 2649
                         <?php endforeach;
2650 2650
                     endif; ?>
@@ -2729,10 +2729,10 @@  discard block
 block discarded – undo
2729 2729
         $context_slug = $this->request->getRequestParam('MTP_context', '');
2730 2730
         $context      = ucwords(str_replace('_', ' ', $context_slug));
2731 2731
 
2732
-        $item_desc   = $messenger_label && $message_type_label
2733
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2732
+        $item_desc = $messenger_label && $message_type_label
2733
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
2734 2734
             : '';
2735
-        $item_desc   .= 'Message Template';
2735
+        $item_desc .= 'Message Template';
2736 2736
         $query_args  = [];
2737 2737
         $edit_array  = [];
2738 2738
         $action_desc = '';
@@ -2762,7 +2762,7 @@  discard block
 block discarded – undo
2762 2762
 
2763 2763
             // run update for each template field in displayed context
2764 2764
             $template_fields = $this->request->getRequestParam('MTP_template_fields');
2765
-            if (! $template_fields) {
2765
+            if ( ! $template_fields) {
2766 2766
                 EE_Error::add_error(
2767 2767
                     esc_html__(
2768 2768
                         'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
@@ -2825,7 +2825,7 @@  discard block
 block discarded – undo
2825 2825
 
2826 2826
                         $where_cols_n_values = ['MTP_ID' => $content['MTP_ID']];
2827 2827
                         // if they aren't allowed to use all JS, restrict them to just posty-y tags
2828
-                        if (! current_user_can('unfiltered_html')) {
2828
+                        if ( ! current_user_can('unfiltered_html')) {
2829 2829
                             if (is_array($set_column_values['MTP_content'])) {
2830 2830
                                 foreach ($set_column_values['MTP_content'] as $key => $value) {
2831 2831
                                     // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
@@ -2833,7 +2833,7 @@  discard block
 block discarded – undo
2833 2833
                                     // appear invalid.) But currently the models expect slashed data, so after wp_kses
2834 2834
                                     // runs we need to re-slash the data. Sheesh. See
2835 2835
                                     // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2836
-                                    $set_column_values['MTP_content'][ $key ] = addslashes(
2836
+                                    $set_column_values['MTP_content'][$key] = addslashes(
2837 2837
                                         wp_kses(
2838 2838
                                             stripslashes($value),
2839 2839
                                             wp_kses_allowed_html('post')
@@ -2876,7 +2876,7 @@  discard block
 block discarded – undo
2876 2876
                                 // default setup for it.
2877 2877
                                 // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2878 2878
                                 $updated = $MTP->insert($message_template_fields);
2879
-                                if (! $updated || is_wp_error($updated)) {
2879
+                                if ( ! $updated || is_wp_error($updated)) {
2880 2880
                                     EE_Error::add_error(
2881 2881
                                         sprintf(
2882 2882
                                             esc_html__('%s field could not be updated.', 'event_espresso'),
@@ -3110,7 +3110,7 @@  discard block
 block discarded – undo
3110 3110
         if ($all) {
3111 3111
             // Checkboxes
3112 3112
             $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3113
-            if (! empty($checkboxes)) {
3113
+            if ( ! empty($checkboxes)) {
3114 3114
                 // if array has more than one element then success message should be plural.
3115 3115
                 // todo: what about nonce?
3116 3116
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -3118,16 +3118,16 @@  discard block
 block discarded – undo
3118 3118
                 // cycle through checkboxes
3119 3119
                 while (list($GRP_ID, $value) = each($checkboxes)) {
3120 3120
                     $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3121
-                    if (! $trashed_or_restored) {
3121
+                    if ( ! $trashed_or_restored) {
3122 3122
                         $success = 0;
3123 3123
                     }
3124 3124
                 }
3125 3125
             } else {
3126 3126
                 // grab single GRP_ID and handle
3127 3127
                 $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3128
-                if (! empty($GRP_ID)) {
3128
+                if ( ! empty($GRP_ID)) {
3129 3129
                     $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3130
-                    if (! $trashed_or_restored) {
3130
+                    if ( ! $trashed_or_restored) {
3131 3131
                         $success = 0;
3132 3132
                     }
3133 3133
                 } else {
@@ -3175,7 +3175,7 @@  discard block
 block discarded – undo
3175 3175
 
3176 3176
         // checkboxes
3177 3177
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3178
-        if (! empty($checkboxes)) {
3178
+        if ( ! empty($checkboxes)) {
3179 3179
             // if array has more than one element then success message should be plural
3180 3180
             $success = count($checkboxes) > 1 ? 2 : 1;
3181 3181
 
@@ -3280,7 +3280,7 @@  discard block
 block discarded – undo
3280 3280
     protected function _set_m_mt_settings()
3281 3281
     {
3282 3282
         // first if this is already set then lets get out no need to regenerate data.
3283
-        if (! empty($this->_m_mt_settings)) {
3283
+        if ( ! empty($this->_m_mt_settings)) {
3284 3284
             return;
3285 3285
         }
3286 3286
 
@@ -3292,7 +3292,7 @@  discard block
 block discarded – undo
3292 3292
         // assemble the array for the _tab_text_links helper
3293 3293
 
3294 3294
         foreach ($messengers as $messenger) {
3295
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3295
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3296 3296
                 'label' => ucwords($messenger->label['singular']),
3297 3297
                 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3298 3298
                     ? 'messenger-active'
@@ -3309,7 +3309,7 @@  discard block
 block discarded – undo
3309 3309
             foreach ($message_types as $message_type) {
3310 3310
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3311 3311
                 // it shouldn't show in either the inactive OR active metabox.
3312
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3312
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3313 3313
                     continue;
3314 3314
                 }
3315 3315
 
@@ -3320,12 +3320,12 @@  discard block
 block discarded – undo
3320 3320
                     ? 'active'
3321 3321
                     : 'inactive';
3322 3322
 
3323
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3323
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3324 3324
                     'label'    => ucwords($message_type->label['singular']),
3325
-                    'class'    => 'message-type-' . $a_or_i,
3326
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3327
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3328
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3325
+                    'class'    => 'message-type-'.$a_or_i,
3326
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3327
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3328
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3329 3329
                     'title'    => $a_or_i === 'active'
3330 3330
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3331 3331
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3356,25 +3356,25 @@  discard block
 block discarded – undo
3356 3356
         $fields                                         = $message_type->get_admin_settings_fields();
3357 3357
         $settings_template_args['template_form_fields'] = '';
3358 3358
 
3359
-        if (! empty($fields) && $active) {
3359
+        if ( ! empty($fields) && $active) {
3360 3360
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3361 3361
             foreach ($fields as $fldname => $fldprops) {
3362
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3363
-                $template_form_field[ $field_id ] = [
3364
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3362
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3363
+                $template_form_field[$field_id] = [
3364
+                    'name'       => 'message_type_settings['.$fldname.']',
3365 3365
                     'label'      => $fldprops['label'],
3366 3366
                     'input'      => $fldprops['field_type'],
3367 3367
                     'type'       => $fldprops['value_type'],
3368 3368
                     'required'   => $fldprops['required'],
3369 3369
                     'validation' => $fldprops['validation'],
3370
-                    'value'      => isset($existing_settings[ $fldname ])
3371
-                        ? $existing_settings[ $fldname ]
3370
+                    'value'      => isset($existing_settings[$fldname])
3371
+                        ? $existing_settings[$fldname]
3372 3372
                         : $fldprops['default'],
3373 3373
                     'options'    => isset($fldprops['options'])
3374 3374
                         ? $fldprops['options']
3375 3375
                         : [],
3376
-                    'default'    => isset($existing_settings[ $fldname ])
3377
-                        ? $existing_settings[ $fldname ]
3376
+                    'default'    => isset($existing_settings[$fldname])
3377
+                        ? $existing_settings[$fldname]
3378 3378
                         : $fldprops['default'],
3379 3379
                     'css_class'  => 'no-drag',
3380 3380
                     'format'     => $fldprops['format'],
@@ -3394,15 +3394,15 @@  discard block
 block discarded – undo
3394 3394
         $settings_template_args['description'] = $message_type->description;
3395 3395
         // we also need some hidden fields
3396 3396
         $hidden_fields = [
3397
-            'message_type_settings[messenger]' . $message_type->name    => [
3397
+            'message_type_settings[messenger]'.$message_type->name    => [
3398 3398
                 'type'  => 'hidden',
3399 3399
                 'value' => $messenger->name,
3400 3400
             ],
3401
-            'message_type_settings[message_type]' . $message_type->name => [
3401
+            'message_type_settings[message_type]'.$message_type->name => [
3402 3402
                 'type'  => 'hidden',
3403 3403
                 'value' => $message_type->name,
3404 3404
             ],
3405
-            'type' . $message_type->name                                => [
3405
+            'type'.$message_type->name                                => [
3406 3406
                 'type'  => 'hidden',
3407 3407
                 'value' => 'message_type',
3408 3408
             ],
@@ -3412,12 +3412,12 @@  discard block
 block discarded – undo
3412 3412
             $hidden_fields,
3413 3413
             'array'
3414 3414
         );
3415
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3415
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3416 3416
             ? ' hidden'
3417 3417
             : '';
3418 3418
 
3419 3419
 
3420
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3420
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3421 3421
         return EEH_Template::display_template($template, $settings_template_args, true);
3422 3422
     }
3423 3423
 
@@ -3445,21 +3445,21 @@  discard block
 block discarded – undo
3445 3445
 
3446 3446
                 // messenger meta boxes
3447 3447
                 $active         = $selected_messenger === $messenger;
3448
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3449
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3448
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3449
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3450 3450
                     : '';
3451 3451
 
3452
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3452
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3453 3453
                     esc_html__('%s Settings', 'event_espresso'),
3454 3454
                     $tab_array['label']
3455 3455
                 );
3456 3456
 
3457
-                $m_template_args[ $messenger . '_a_box' ] = [
3457
+                $m_template_args[$messenger.'_a_box'] = [
3458 3458
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3459 3459
                     'inactive_message_types' => isset(
3460
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3460
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3461 3461
                     )
3462
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3462
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3463 3463
                         : '',
3464 3464
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3465 3465
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3471,13 +3471,13 @@  discard block
 block discarded – undo
3471 3471
                 // message type meta boxes
3472 3472
                 // (which is really just the inactive container for each messenger
3473 3473
                 // showing inactive message types for that messenger)
3474
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3475
-                $mt_template_args[ $messenger . '_i_box' ] = [
3474
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3475
+                $mt_template_args[$messenger.'_i_box'] = [
3476 3476
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3477 3477
                     'inactive_message_types' => isset(
3478
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3478
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3479 3479
                     )
3480
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3480
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3481 3481
                         : '',
3482 3482
                     'hidden'                 => $active ? '' : ' hidden',
3483 3483
                     'hide_on_message'        => $hide_on_message,
@@ -3490,14 +3490,14 @@  discard block
 block discarded – undo
3490 3490
 
3491 3491
 
3492 3492
         // register messenger metaboxes
3493
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3493
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3494 3494
         foreach ($m_boxes as $box => $label) {
3495
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3495
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3496 3496
             $msgr          = str_replace('_a_box', '', $box);
3497 3497
             add_meta_box(
3498
-                'espresso_' . $msgr . '_settings',
3498
+                'espresso_'.$msgr.'_settings',
3499 3499
                 $label,
3500
-                function ($post, $metabox) {
3500
+                function($post, $metabox) {
3501 3501
                     EEH_Template::display_template(
3502 3502
                         $metabox['args']['template_path'],
3503 3503
                         $metabox['args']['template_args']
@@ -3511,17 +3511,17 @@  discard block
 block discarded – undo
3511 3511
         }
3512 3512
 
3513 3513
         // register message type metaboxes
3514
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3514
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3515 3515
         foreach ($mt_boxes as $box => $label) {
3516 3516
             $callback_args = [
3517 3517
                 'template_path' => $mt_template_path,
3518
-                'template_args' => $mt_template_args[ $box ],
3518
+                'template_args' => $mt_template_args[$box],
3519 3519
             ];
3520
-            $mt            = str_replace('_i_box', '', $box);
3520
+            $mt = str_replace('_i_box', '', $box);
3521 3521
             add_meta_box(
3522
-                'espresso_' . $mt . '_inactive_mts',
3522
+                'espresso_'.$mt.'_inactive_mts',
3523 3523
                 $label,
3524
-                function ($post, $metabox) {
3524
+                function($post, $metabox) {
3525 3525
                     EEH_Template::display_template(
3526 3526
                         $metabox['args']['template_path'],
3527 3527
                         $metabox['args']['template_args']
@@ -3666,7 +3666,7 @@  discard block
 block discarded – undo
3666 3666
             if ($form->is_valid()) {
3667 3667
                 $valid_data = $form->valid_data();
3668 3668
                 foreach ($valid_data as $property => $value) {
3669
-                    $setter = 'set_' . $property;
3669
+                    $setter = 'set_'.$property;
3670 3670
                     if (method_exists($network_config, $setter)) {
3671 3671
                         $network_config->{$setter}($value);
3672 3672
                     } elseif (
@@ -3702,7 +3702,7 @@  discard block
 block discarded – undo
3702 3702
     protected function _get_mt_tabs($tab_array)
3703 3703
     {
3704 3704
         $tab_array = (array) $tab_array;
3705
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3705
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3706 3706
         $tabs      = '';
3707 3707
 
3708 3708
         foreach ($tab_array as $tab) {
@@ -3730,20 +3730,20 @@  discard block
 block discarded – undo
3730 3730
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3731 3731
 
3732 3732
 
3733
-        if (! empty($fields)) {
3733
+        if ( ! empty($fields)) {
3734 3734
             $existing_settings = $messenger->get_existing_admin_settings();
3735 3735
 
3736 3736
             foreach ($fields as $fldname => $fldprops) {
3737
-                $field_id                         = $messenger->name . '-' . $fldname;
3738
-                $template_form_field[ $field_id ] = [
3739
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3737
+                $field_id                         = $messenger->name.'-'.$fldname;
3738
+                $template_form_field[$field_id] = [
3739
+                    'name'       => 'messenger_settings['.$field_id.']',
3740 3740
                     'label'      => $fldprops['label'],
3741 3741
                     'input'      => $fldprops['field_type'],
3742 3742
                     'type'       => $fldprops['value_type'],
3743 3743
                     'required'   => $fldprops['required'],
3744 3744
                     'validation' => $fldprops['validation'],
3745
-                    'value'      => isset($existing_settings[ $field_id ])
3746
-                        ? $existing_settings[ $field_id ]
3745
+                    'value'      => isset($existing_settings[$field_id])
3746
+                        ? $existing_settings[$field_id]
3747 3747
                         : $fldprops['default'],
3748 3748
                     'css_class'  => '',
3749 3749
                     'format'     => $fldprops['format'],
@@ -3758,20 +3758,20 @@  discard block
 block discarded – undo
3758 3758
 
3759 3759
         // we also need some hidden fields
3760 3760
         $settings_template_args['hidden_fields'] = [
3761
-            'messenger_settings[messenger]' . $messenger->name => [
3761
+            'messenger_settings[messenger]'.$messenger->name => [
3762 3762
                 'type'  => 'hidden',
3763 3763
                 'value' => $messenger->name,
3764 3764
             ],
3765
-            'type' . $messenger->name                          => [
3765
+            'type'.$messenger->name                          => [
3766 3766
                 'type'  => 'hidden',
3767 3767
                 'value' => 'messenger',
3768 3768
             ],
3769 3769
         ];
3770 3770
 
3771 3771
         // make sure any active message types that are existing are included in the hidden fields
3772
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3773
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3774
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3772
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3773
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3774
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3775 3775
                     'type'  => 'hidden',
3776 3776
                     'value' => $mt,
3777 3777
                 ];
@@ -3781,7 +3781,7 @@  discard block
 block discarded – undo
3781 3781
             $settings_template_args['hidden_fields'],
3782 3782
             'array'
3783 3783
         );
3784
-        $active                                  =
3784
+        $active =
3785 3785
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3786 3786
 
3787 3787
         $settings_template_args['messenger']           = $messenger->name;
@@ -3801,9 +3801,9 @@  discard block
 block discarded – undo
3801 3801
 
3802 3802
 
3803 3803
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3804
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3804
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3805 3805
         $settings_template_args['on_off_status'] = $active;
3806
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3806
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3807 3807
         return EEH_Template::display_template(
3808 3808
             $template,
3809 3809
             $settings_template_args,
@@ -3828,7 +3828,7 @@  discard block
 block discarded – undo
3828 3828
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3829 3829
         // let's check that we have required data
3830 3830
 
3831
-        if (! $this->_active_messenger_name) {
3831
+        if ( ! $this->_active_messenger_name) {
3832 3832
             EE_Error::add_error(
3833 3833
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3834 3834
                 __FILE__,
@@ -3846,7 +3846,7 @@  discard block
 block discarded – undo
3846 3846
 
3847 3847
 
3848 3848
         $status = $this->request->getRequestParam('status');
3849
-        if (! $status) {
3849
+        if ( ! $status) {
3850 3850
             EE_Error::add_error(
3851 3851
                 esc_html__(
3852 3852
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -3903,7 +3903,7 @@  discard block
 block discarded – undo
3903 3903
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3904 3904
 
3905 3905
         // let's make sure we have the necessary data
3906
-        if (! $this->_active_message_type_name) {
3906
+        if ( ! $this->_active_message_type_name) {
3907 3907
             EE_Error::add_error(
3908 3908
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3909 3909
                 __FILE__,
@@ -3913,7 +3913,7 @@  discard block
 block discarded – undo
3913 3913
             $success = false;
3914 3914
         }
3915 3915
 
3916
-        if (! $this->_active_messenger_name) {
3916
+        if ( ! $this->_active_messenger_name) {
3917 3917
             EE_Error::add_error(
3918 3918
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3919 3919
                 __FILE__,
@@ -3924,7 +3924,7 @@  discard block
 block discarded – undo
3924 3924
         }
3925 3925
 
3926 3926
         $status = $this->request->getRequestParam('status');
3927
-        if (! $status) {
3927
+        if ( ! $status) {
3928 3928
             EE_Error::add_error(
3929 3929
                 esc_html__(
3930 3930
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4136,7 +4136,7 @@  discard block
 block discarded – undo
4136 4136
         EE_Message_Type $message_type = null
4137 4137
     ) {
4138 4138
         // if $messenger isn't a valid messenger object then get out.
4139
-        if (! $messenger instanceof EE_Messenger) {
4139
+        if ( ! $messenger instanceof EE_Messenger) {
4140 4140
             EE_Error::add_error(
4141 4141
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4142 4142
                 __FILE__,
@@ -4190,7 +4190,7 @@  discard block
 block discarded – undo
4190 4190
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4191 4191
             // in which case we just give a success message for the messenger being successfully activated.
4192 4192
         } else {
4193
-            if (! $messenger->get_default_message_types()) {
4193
+            if ( ! $messenger->get_default_message_types()) {
4194 4194
                 // messenger doesn't have any default message types so still a success.
4195 4195
                 EE_Error::add_success(
4196 4196
                     sprintf(
@@ -4246,7 +4246,7 @@  discard block
 block discarded – undo
4246 4246
         EE_Error::overwrite_success();
4247 4247
 
4248 4248
         // if $messenger isn't a valid messenger object then get out.
4249
-        if (! $messenger instanceof EE_Messenger) {
4249
+        if ( ! $messenger instanceof EE_Messenger) {
4250 4250
             EE_Error::add_error(
4251 4251
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4252 4252
                 __FILE__,
@@ -4310,7 +4310,7 @@  discard block
 block discarded – undo
4310 4310
      */
4311 4311
     public function update_mt_form()
4312 4312
     {
4313
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4313
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4314 4314
             EE_Error::add_error(
4315 4315
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4316 4316
                 __FILE__,
@@ -4321,7 +4321,7 @@  discard block
 block discarded – undo
4321 4321
         }
4322 4322
 
4323 4323
         $message_types = $this->get_installed_message_types();
4324
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4324
+        $message_type  = $message_types[$this->_active_message_type_name];
4325 4325
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4326 4326
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4327 4327
 
@@ -4340,7 +4340,7 @@  discard block
 block discarded – undo
4340 4340
     public function save_settings()
4341 4341
     {
4342 4342
         $type = $this->request->getRequestParam('type');
4343
-        if (! $type) {
4343
+        if ( ! $type) {
4344 4344
             EE_Error::add_error(
4345 4345
                 esc_html__(
4346 4346
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.