Completed
Branch dev (18e544)
by
unknown
02:53 queued 17s
created
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4092 added lines, -4092 removed lines patch added patch discarded remove patch
@@ -18,4162 +18,4162 @@
 block discarded – undo
18 18
  */
19 19
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
20 20
 {
21
-    /**
22
-     * @var EE_Admin_Config
23
-     */
24
-    protected $admin_config;
21
+	/**
22
+	 * @var EE_Admin_Config
23
+	 */
24
+	protected $admin_config;
25 25
 
26
-    /**
27
-     * @var LoaderInterface $loader
28
-     */
29
-    protected $loader;
26
+	/**
27
+	 * @var LoaderInterface $loader
28
+	 */
29
+	protected $loader;
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
-    // nav tabs
52
-    protected $_nav_tabs;
51
+	// nav tabs
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 = array();
56
+	/**
57
+	 * @var array $_help_tour
58
+	 */
59
+	protected $_help_tour = array();
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 = array();
67
+	/**
68
+	 * @var array $_template_args
69
+	 */
70
+	protected $_template_args = array();
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
-    // boolean
80
-    protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
79
+	// boolean
80
+	protected $_is_UI_request; // 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;
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 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
-    // sanitized request action (and nonce)
132
-
133
-    /**
134
-     * @var string $_req_action
135
-     */
136
-    protected $_req_action;
137
-
138
-    /**
139
-     * @var string $_req_nonce
140
-     */
141
-    protected $_req_nonce;
142
-
143
-    // search related
144
-    protected $_search_btn_label;
145
-
146
-    protected $_search_box_callback;
147
-
148
-    /**
149
-     * WP Current Screen object
150
-     *
151
-     * @var WP_Screen
152
-     */
153
-    protected $_current_screen;
154
-
155
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
156
-    protected $_hook_obj;
157
-
158
-    // for holding incoming request data
159
-    protected $_req_data = [];
160
-
161
-    // yes / no array for admin form fields
162
-    protected $_yes_no_values = array();
163
-
164
-    // some default things shared by all child classes
165
-    protected $_default_espresso_metaboxes;
166
-
167
-    /**
168
-     *    EE_Registry Object
169
-     *
170
-     * @var    EE_Registry
171
-     */
172
-    protected $EE;
173
-
174
-
175
-    /**
176
-     * This is just a property that flags whether the given route is a caffeinated route or not.
177
-     *
178
-     * @var boolean
179
-     */
180
-    protected $_is_caf = false;
181
-
182
-    /**
183
-     * whether or not initializePage() has run
184
-     *
185
-     * @var boolean
186
-     */
187
-    protected $initialized = false;
188
-
189
-
190
-    /**
191
-     * @Constructor
192
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
193
-     * @throws InvalidArgumentException
194
-     * @throws InvalidDataTypeException
195
-     * @throws InvalidInterfaceException
196
-     * @throws ReflectionException
197
-     */
198
-    public function __construct($routing = true)
199
-    {
200
-        $this->loader = LoaderFactory::getLoader();
201
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
202
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
203
-            $this->_is_caf = true;
204
-        }
205
-        $this->_yes_no_values = array(
206
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
207
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
208
-        );
209
-        // set the _req_data property.
210
-        $this->_req_data = array_merge($_GET, $_POST);
211
-        // routing enabled?
212
-        $this->_routing = $routing;
213
-    }
214
-
215
-
216
-    /**
217
-     * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
218
-     * for child classes that needed to set properties prior to these methods getting called,
219
-     * but also needed the parent class to have its construction completed as well.
220
-     * Bottom line is that constructors should ONLY be used for setting initial properties
221
-     * and any complex initialization logic should only run after instantiation is complete.
222
-     *
223
-     * This method gets called immediately after construction from within
224
-     *      EE_Admin_Page_Init::_initialize_admin_page()
225
-     *
226
-     * @throws EE_Error
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidDataTypeException
229
-     * @throws InvalidInterfaceException
230
-     * @throws ReflectionException
231
-     * @since $VID:$
232
-     */
233
-    public function initializePage()
234
-    {
235
-        if ($this->initialized) {
236
-            return;
237
-        }
238
-        // set initial page props (child method)
239
-        $this->_init_page_props();
240
-        // set global defaults
241
-        $this->_set_defaults();
242
-        // set early because incoming requests could be ajax related and we need to register those hooks.
243
-        $this->_global_ajax_hooks();
244
-        $this->_ajax_hooks();
245
-        // other_page_hooks have to be early too.
246
-        $this->_do_other_page_hooks();
247
-        // This just allows us to have extending classes do something specific
248
-        // before the parent constructor runs _page_setup().
249
-        if (method_exists($this, '_before_page_setup')) {
250
-            $this->_before_page_setup();
251
-        }
252
-        // set up page dependencies
253
-        $this->_page_setup();
254
-        $this->initialized = true;
255
-    }
256
-
257
-
258
-    /**
259
-     * _init_page_props
260
-     * Child classes use to set at least the following properties:
261
-     * $page_slug.
262
-     * $page_label.
263
-     *
264
-     * @abstract
265
-     * @return void
266
-     */
267
-    abstract protected function _init_page_props();
268
-
269
-
270
-    /**
271
-     * _ajax_hooks
272
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
273
-     * Note: within the ajax callback methods.
274
-     *
275
-     * @abstract
276
-     * @return void
277
-     */
278
-    abstract protected function _ajax_hooks();
279
-
280
-
281
-    /**
282
-     * _define_page_props
283
-     * child classes define page properties in here.  Must include at least:
284
-     * $_admin_base_url = base_url for all admin pages
285
-     * $_admin_page_title = default admin_page_title for admin pages
286
-     * $_labels = array of default labels for various automatically generated elements:
287
-     *    array(
288
-     *        'buttons' => array(
289
-     *            'add' => esc_html__('label for add new button'),
290
-     *            'edit' => esc_html__('label for edit button'),
291
-     *            'delete' => esc_html__('label for delete button')
292
-     *            )
293
-     *        )
294
-     *
295
-     * @abstract
296
-     * @return void
297
-     */
298
-    abstract protected function _define_page_props();
299
-
300
-
301
-    /**
302
-     * _set_page_routes
303
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
304
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
305
-     * have a 'default' route. Here's the format
306
-     * $this->_page_routes = array(
307
-     *        'default' => array(
308
-     *            'func' => '_default_method_handling_route',
309
-     *            'args' => array('array','of','args'),
310
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
311
-     *            ajax request, backend processing)
312
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
313
-     *            headers route after.  The string you enter here should match the defined route reference for a
314
-     *            headers sent route.
315
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
316
-     *            this route.
317
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
318
-     *            checks).
319
-     *        ),
320
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
321
-     *        handling method.
322
-     *        )
323
-     * )
324
-     *
325
-     * @abstract
326
-     * @return void
327
-     */
328
-    abstract protected function _set_page_routes();
329
-
330
-
331
-    /**
332
-     * _set_page_config
333
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
334
-     * array corresponds to the page_route for the loaded page. Format:
335
-     * $this->_page_config = array(
336
-     *        'default' => array(
337
-     *            'labels' => array(
338
-     *                'buttons' => array(
339
-     *                    'add' => esc_html__('label for adding item'),
340
-     *                    'edit' => esc_html__('label for editing item'),
341
-     *                    'delete' => esc_html__('label for deleting item')
342
-     *                ),
343
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
344
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
345
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
346
-     *            _define_page_props() method
347
-     *            'nav' => array(
348
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
349
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
350
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
351
-     *                'order' => 10, //required to indicate tab position.
352
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
353
-     *                displayed then add this parameter.
354
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
355
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
356
-     *            metaboxes set for eventespresso admin pages.
357
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
358
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
359
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
360
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
361
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
362
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
363
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
364
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
365
-     *            want to display.
366
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
367
-     *                'tab_id' => array(
368
-     *                    'title' => 'tab_title',
369
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
370
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
371
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
372
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
373
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
374
-     *                    attempt to use the callback which should match the name of a method in the class
375
-     *                    ),
376
-     *                'tab2_id' => array(
377
-     *                    'title' => 'tab2 title',
378
-     *                    'filename' => 'file_name_2'
379
-     *                    'callback' => 'callback_method_for_content',
380
-     *                 ),
381
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
382
-     *            help tab area on an admin page. @link
383
-     *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
384
-     *            'help_tour' => array(
385
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
386
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
387
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
388
-     *            ),
389
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
390
-     *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
391
-     *            just set
392
-     *            'require_nonce' to FALSE
393
-     *            )
394
-     * )
395
-     *
396
-     * @abstract
397
-     * @return void
398
-     */
399
-    abstract protected function _set_page_config();
400
-
401
-
402
-
403
-
404
-
405
-    /** end sample help_tour methods **/
406
-    /**
407
-     * _add_screen_options
408
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
409
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
410
-     * to a particular view.
411
-     *
412
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
413
-     *         see also WP_Screen object documents...
414
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
415
-     * @abstract
416
-     * @return void
417
-     */
418
-    abstract protected function _add_screen_options();
419
-
420
-
421
-    /**
422
-     * _add_feature_pointers
423
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
424
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
425
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
426
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
427
-     * extended) also see:
428
-     *
429
-     * @link   http://eamann.com/tech/wordpress-portland/
430
-     * @abstract
431
-     * @return void
432
-     */
433
-    abstract protected function _add_feature_pointers();
434
-
435
-
436
-    /**
437
-     * load_scripts_styles
438
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
439
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
440
-     * scripts/styles per view by putting them in a dynamic function in this format
441
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
442
-     *
443
-     * @abstract
444
-     * @return void
445
-     */
446
-    abstract public function load_scripts_styles();
447
-
448
-
449
-    /**
450
-     * admin_init
451
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
452
-     * all pages/views loaded by child class.
453
-     *
454
-     * @abstract
455
-     * @return void
456
-     */
457
-    abstract public function admin_init();
458
-
459
-
460
-    /**
461
-     * admin_notices
462
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
463
-     * all pages/views loaded by child class.
464
-     *
465
-     * @abstract
466
-     * @return void
467
-     */
468
-    abstract public function admin_notices();
469
-
470
-
471
-    /**
472
-     * admin_footer_scripts
473
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
474
-     * will apply to all pages/views loaded by child class.
475
-     *
476
-     * @return void
477
-     */
478
-    abstract public function admin_footer_scripts();
479
-
480
-
481
-    /**
482
-     * admin_footer
483
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
484
-     * apply to all pages/views loaded by child class.
485
-     *
486
-     * @return void
487
-     */
488
-    public function admin_footer()
489
-    {
490
-    }
491
-
492
-
493
-    /**
494
-     * _global_ajax_hooks
495
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
496
-     * Note: within the ajax callback methods.
497
-     *
498
-     * @abstract
499
-     * @return void
500
-     */
501
-    protected function _global_ajax_hooks()
502
-    {
503
-        // for lazy loading of metabox content
504
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
505
-
506
-        add_action(
507
-            'wp_ajax_espresso_hide_status_change_notice',
508
-            [$this, 'hideStatusChangeNotice']
509
-        );
510
-        add_action(
511
-            'wp_ajax_nopriv_espresso_hide_status_change_notice',
512
-            [$this, 'hideStatusChangeNotice']
513
-        );
514
-    }
515
-
516
-
517
-    public function ajax_metabox_content()
518
-    {
519
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
520
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
521
-        EE_Admin_Page::cached_rss_display($contentid, $url);
522
-        wp_die();
523
-    }
524
-
525
-
526
-    public function hideStatusChangeNotice()
527
-    {
528
-        $response = [];
529
-        try {
530
-            /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
531
-            $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
532
-            $response['success'] = $status_change_notice->dismiss() > -1;
533
-        } catch (Exception $exception) {
534
-            $response['errors'] = $exception->getMessage();
535
-        }
536
-        echo wp_json_encode($response);
537
-        exit();
538
-    }
539
-
540
-
541
-    /**
542
-     * _page_setup
543
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
544
-     * doesn't match the object.
545
-     *
546
-     * @final
547
-     * @return void
548
-     * @throws EE_Error
549
-     * @throws InvalidArgumentException
550
-     * @throws ReflectionException
551
-     * @throws InvalidDataTypeException
552
-     * @throws InvalidInterfaceException
553
-     */
554
-    final protected function _page_setup()
555
-    {
556
-        // requires?
557
-        // admin_init stuff - global - we're setting this REALLY early
558
-        // so if EE_Admin pages have to hook into other WP pages they can.
559
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
560
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
561
-        // next verify if we need to load anything...
562
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
563
-        $this->page_folder = strtolower(
564
-            str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
565
-        );
566
-        global $ee_menu_slugs;
567
-        $ee_menu_slugs = (array) $ee_menu_slugs;
568
-        if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
569
-            return;
570
-        }
571
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
572
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
573
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
574
-                ? $this->_req_data['action2']
575
-                : $this->_req_data['action'];
576
-        }
577
-        // then set blank or -1 action values to 'default'
578
-        $this->_req_action = isset($this->_req_data['action'])
579
-                             && ! empty($this->_req_data['action'])
580
-                             && $this->_req_data['action'] !== '-1'
581
-            ? sanitize_key($this->_req_data['action'])
582
-            : 'default';
583
-        // if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
584
-        //  This covers cases where we're coming in from a list table that isn't on the default route.
585
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
586
-            ? $this->_req_data['route'] : $this->_req_action;
587
-        // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
588
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
589
-            ? $this->_req_data['route']
590
-            : $this->_req_action;
591
-        $this->_current_view = $this->_req_action;
592
-        $this->_req_nonce = $this->_req_action . '_nonce';
593
-        $this->_define_page_props();
594
-        $this->_current_page_view_url = add_query_arg(
595
-            array('page' => $this->_current_page, 'action' => $this->_current_view),
596
-            $this->_admin_base_url
597
-        );
598
-        // default things
599
-        $this->_default_espresso_metaboxes = array(
600
-            '_espresso_news_post_box',
601
-            '_espresso_links_post_box',
602
-            '_espresso_ratings_request',
603
-            '_espresso_sponsors_post_box',
604
-        );
605
-        // set page configs
606
-        $this->_set_page_routes();
607
-        $this->_set_page_config();
608
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
609
-        if (isset($this->_req_data['wp_referer'])) {
610
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
611
-        }
612
-        // for caffeinated and other extended functionality.
613
-        //  If there is a _extend_page_config method
614
-        // then let's run that to modify the all the various page configuration arrays
615
-        if (method_exists($this, '_extend_page_config')) {
616
-            $this->_extend_page_config();
617
-        }
618
-        // for CPT and other extended functionality.
619
-        // If there is an _extend_page_config_for_cpt
620
-        // then let's run that to modify all the various page configuration arrays.
621
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
622
-            $this->_extend_page_config_for_cpt();
623
-        }
624
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
625
-        $this->_page_routes = apply_filters(
626
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
627
-            $this->_page_routes,
628
-            $this
629
-        );
630
-        $this->_page_config = apply_filters(
631
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
632
-            $this->_page_config,
633
-            $this
634
-        );
635
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
636
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
637
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
638
-            add_action(
639
-                'AHEE__EE_Admin_Page__route_admin_request',
640
-                array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
641
-                10,
642
-                2
643
-            );
644
-        }
645
-        // next route only if routing enabled
646
-        if ($this->_routing && ! defined('DOING_AJAX')) {
647
-            $this->_verify_routes();
648
-            // next let's just check user_access and kill if no access
649
-            $this->check_user_access();
650
-            if ($this->_is_UI_request) {
651
-                // admin_init stuff - global, all views for this page class, specific view
652
-                add_action('admin_init', array($this, 'admin_init'), 10);
653
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
654
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
655
-                }
656
-            } else {
657
-                // hijack regular WP loading and route admin request immediately
658
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
659
-                $this->route_admin_request();
660
-            }
661
-        }
662
-    }
663
-
664
-
665
-    /**
666
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
667
-     *
668
-     * @return void
669
-     * @throws EE_Error
670
-     */
671
-    private function _do_other_page_hooks()
672
-    {
673
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
674
-        foreach ($registered_pages as $page) {
675
-            // now let's setup the file name and class that should be present
676
-            $classname = str_replace('.class.php', '', $page);
677
-            // autoloaders should take care of loading file
678
-            if (! class_exists($classname)) {
679
-                $error_msg[] = sprintf(
680
-                    esc_html__(
681
-                        'Something went wrong with loading the %s admin hooks page.',
682
-                        'event_espresso'
683
-                    ),
684
-                    $page
685
-                );
686
-                $error_msg[] = $error_msg[0]
687
-                               . "\r\n"
688
-                               . sprintf(
689
-                                   esc_html__(
690
-                                       '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',
691
-                                       'event_espresso'
692
-                                   ),
693
-                                   $page,
694
-                                   '<br />',
695
-                                   '<strong>' . $classname . '</strong>'
696
-                               );
697
-                throw new EE_Error(implode('||', $error_msg));
698
-            }
699
-            // // notice we are passing the instance of this class to the hook object.
700
-            $this->loader->getShared($classname, [$this]);
701
-        }
702
-    }
703
-
704
-
705
-    /**
706
-     * @throws DomainException
707
-     * @throws EE_Error
708
-     * @throws InvalidArgumentException
709
-     * @throws InvalidDataTypeException
710
-     * @throws InvalidInterfaceException
711
-     * @throws ReflectionException
712
-     * @since $VID:$
713
-     */
714
-    public function load_page_dependencies()
715
-    {
716
-        try {
717
-            $this->_load_page_dependencies();
718
-        } catch (EE_Error $e) {
719
-            $e->get_error();
720
-        }
721
-    }
722
-
723
-
724
-    /**
725
-     * load_page_dependencies
726
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
727
-     *
728
-     * @return void
729
-     * @throws DomainException
730
-     * @throws EE_Error
731
-     * @throws InvalidArgumentException
732
-     * @throws InvalidDataTypeException
733
-     * @throws InvalidInterfaceException
734
-     * @throws ReflectionException
735
-     */
736
-    protected function _load_page_dependencies()
737
-    {
738
-        // let's set the current_screen and screen options to override what WP set
739
-        $this->_current_screen = get_current_screen();
740
-        // load admin_notices - global, page class, and view specific
741
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
742
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
743
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
744
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
745
-        }
746
-        // load network admin_notices - global, page class, and view specific
747
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
748
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
749
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
750
-        }
751
-        // this will save any per_page screen options if they are present
752
-        $this->_set_per_page_screen_options();
753
-        // setup list table properties
754
-        $this->_set_list_table();
755
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
756
-        // However in some cases the metaboxes will need to be added within a route handling callback.
757
-        $this->_add_registered_meta_boxes();
758
-        $this->_add_screen_columns();
759
-        // add screen options - global, page child class, and view specific
760
-        $this->_add_global_screen_options();
761
-        $this->_add_screen_options();
762
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
763
-        if (method_exists($this, $add_screen_options)) {
764
-            $this->{$add_screen_options}();
765
-        }
766
-        // add help tab(s) and tours- set via page_config and qtips.
767
-        // $this->_add_help_tour();
768
-        $this->_add_help_tabs();
769
-        $this->_add_qtips();
770
-        // add feature_pointers - global, page child class, and view specific
771
-        $this->_add_feature_pointers();
772
-        $this->_add_global_feature_pointers();
773
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
774
-        if (method_exists($this, $add_feature_pointer)) {
775
-            $this->{$add_feature_pointer}();
776
-        }
777
-        // enqueue scripts/styles - global, page class, and view specific
778
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
779
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
780
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
781
-            add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
782
-        }
783
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
784
-        // admin_print_footer_scripts - global, page child class, and view specific.
785
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
786
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
787
-        // is a good use case. Notice the late priority we're giving these
788
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
789
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
790
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
791
-            add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
792
-        }
793
-        // admin footer scripts
794
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
795
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
796
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
797
-            add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
798
-        }
799
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
800
-        // targeted hook
801
-        do_action(
802
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
803
-        );
804
-    }
805
-
806
-
807
-    /**
808
-     * _set_defaults
809
-     * This sets some global defaults for class properties.
810
-     */
811
-    private function _set_defaults()
812
-    {
813
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
814
-        $this->_event = $this->_template_path = $this->_column_template_path = null;
815
-        $this->_nav_tabs = $this->_views = $this->_page_routes = array();
816
-        $this->_page_config = $this->_default_route_query_args = array();
817
-        $this->_default_nav_tab_name = 'overview';
818
-        // init template args
819
-        $this->_template_args = array(
820
-            'admin_page_header'  => '',
821
-            'admin_page_content' => '',
822
-            'post_body_content'  => '',
823
-            'before_list_table'  => '',
824
-            'after_list_table'   => '',
825
-        );
826
-    }
827
-
828
-
829
-    /**
830
-     * route_admin_request
831
-     *
832
-     * @see    _route_admin_request()
833
-     * @return exception|void error
834
-     * @throws InvalidArgumentException
835
-     * @throws InvalidInterfaceException
836
-     * @throws InvalidDataTypeException
837
-     * @throws EE_Error
838
-     * @throws ReflectionException
839
-     */
840
-    public function route_admin_request()
841
-    {
842
-        try {
843
-            $this->_route_admin_request();
844
-        } catch (EE_Error $e) {
845
-            $e->get_error();
846
-        }
847
-    }
848
-
849
-
850
-    public function set_wp_page_slug($wp_page_slug)
851
-    {
852
-        $this->_wp_page_slug = $wp_page_slug;
853
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
854
-        if (is_network_admin()) {
855
-            $this->_wp_page_slug .= '-network';
856
-        }
857
-    }
858
-
859
-
860
-    /**
861
-     * _verify_routes
862
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
863
-     * we know if we need to drop out.
864
-     *
865
-     * @return bool
866
-     * @throws EE_Error
867
-     */
868
-    protected function _verify_routes()
869
-    {
870
-        if (! $this->_current_page && ! defined('DOING_AJAX')) {
871
-            return false;
872
-        }
873
-        $this->_route = false;
874
-        // check that the page_routes array is not empty
875
-        if (empty($this->_page_routes)) {
876
-            // user error msg
877
-            $error_msg = sprintf(
878
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
879
-                $this->_admin_page_title
880
-            );
881
-            // developer error msg
882
-            $error_msg .= '||' . $error_msg
883
-                          . esc_html__(
884
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
885
-                              'event_espresso'
886
-                          );
887
-            throw new EE_Error($error_msg);
888
-        }
889
-        // and that the requested page route exists
890
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
891
-            $this->_route = $this->_page_routes[ $this->_req_action ];
892
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
893
-                ? $this->_page_config[ $this->_req_action ] : array();
894
-        } else {
895
-            // user error msg
896
-            $error_msg = sprintf(
897
-                esc_html__(
898
-                    'The requested page route does not exist for the %s admin page.',
899
-                    'event_espresso'
900
-                ),
901
-                $this->_admin_page_title
902
-            );
903
-            // developer error msg
904
-            $error_msg .= '||' . $error_msg
905
-                          . sprintf(
906
-                              esc_html__(
907
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
908
-                                  'event_espresso'
909
-                              ),
910
-                              $this->_req_action
911
-                          );
912
-            throw new EE_Error($error_msg);
913
-        }
914
-        // and that a default route exists
915
-        if (! array_key_exists('default', $this->_page_routes)) {
916
-            // user error msg
917
-            $error_msg = sprintf(
918
-                esc_html__(
919
-                    'A default page route has not been set for the % admin page.',
920
-                    'event_espresso'
921
-                ),
922
-                $this->_admin_page_title
923
-            );
924
-            // developer error msg
925
-            $error_msg .= '||' . $error_msg
926
-                          . esc_html__(
927
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
928
-                              'event_espresso'
929
-                          );
930
-            throw new EE_Error($error_msg);
931
-        }
932
-
933
-        // first lets' catch if the UI request has EVER been set.
934
-        if ($this->_is_UI_request === null) {
935
-            // lets set if this is a UI request or not.
936
-            $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
937
-            // wait a minute... we might have a noheader in the route array
938
-            $this->_is_UI_request = is_array($this->_route)
939
-                                    && isset($this->_route['noheader'])
940
-                                    && $this->_route['noheader'] ? false : $this->_is_UI_request;
941
-        }
942
-        $this->_set_current_labels();
943
-        return true;
944
-    }
945
-
946
-
947
-    /**
948
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
949
-     *
950
-     * @param  string $route the route name we're verifying
951
-     * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
952
-     * @throws EE_Error
953
-     */
954
-    protected function _verify_route($route)
955
-    {
956
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
957
-            return true;
958
-        }
959
-        // user error msg
960
-        $error_msg = sprintf(
961
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
962
-            $this->_admin_page_title
963
-        );
964
-        // developer error msg
965
-        $error_msg .= '||' . $error_msg
966
-                      . sprintf(
967
-                          esc_html__(
968
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
969
-                              'event_espresso'
970
-                          ),
971
-                          $route
972
-                      );
973
-        throw new EE_Error($error_msg);
974
-    }
975
-
976
-
977
-    /**
978
-     * perform nonce verification
979
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
980
-     * using this method (and save retyping!)
981
-     *
982
-     * @param string $nonce     The nonce sent
983
-     * @param string $nonce_ref The nonce reference string (name0)
984
-     * @return void
985
-     * @throws EE_Error
986
-     * @throws InvalidArgumentException
987
-     * @throws InvalidDataTypeException
988
-     * @throws InvalidInterfaceException
989
-     */
990
-    protected function _verify_nonce($nonce, $nonce_ref)
991
-    {
992
-        // verify nonce against expected value
993
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
994
-            // these are not the droids you are looking for !!!
995
-            $msg = sprintf(
996
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
997
-                '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
998
-                '</a>'
999
-            );
1000
-            if (WP_DEBUG) {
1001
-                $msg .= "\n  "
1002
-                        . sprintf(
1003
-                            esc_html__(
1004
-                                'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1005
-                                'event_espresso'
1006
-                            ),
1007
-                            EE_Admin_Page::class
1008
-                        );
1009
-            }
1010
-            if (! defined('DOING_AJAX')) {
1011
-                wp_die($msg);
1012
-            } else {
1013
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1014
-                $this->_return_json();
1015
-            }
1016
-        }
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * _route_admin_request()
1022
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1023
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1024
-     * in the page routes and then will try to load the corresponding method.
1025
-     *
1026
-     * @return void
1027
-     * @throws EE_Error
1028
-     * @throws InvalidArgumentException
1029
-     * @throws InvalidDataTypeException
1030
-     * @throws InvalidInterfaceException
1031
-     * @throws ReflectionException
1032
-     */
1033
-    protected function _route_admin_request()
1034
-    {
1035
-        if (! $this->_is_UI_request) {
1036
-            $this->_verify_routes();
1037
-        }
1038
-        $nonce_check = isset($this->_route_config['require_nonce'])
1039
-            ? $this->_route_config['require_nonce']
1040
-            : true;
1041
-        if ($this->_req_action !== 'default' && $nonce_check) {
1042
-            // set nonce from post data
1043
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
1044
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
1045
-                : '';
1046
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1047
-        }
1048
-        // set the nav_tabs array but ONLY if this is  UI_request
1049
-        if ($this->_is_UI_request) {
1050
-            $this->_set_nav_tabs();
1051
-        }
1052
-        // grab callback function
1053
-        $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1054
-        // check if callback has args
1055
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1056
-        $error_msg = '';
1057
-        // action right before calling route
1058
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1059
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1060
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1061
-        }
1062
-        // right before calling the route, let's remove _wp_http_referer from the
1063
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1064
-        $_SERVER['REQUEST_URI'] = remove_query_arg(
1065
-            '_wp_http_referer',
1066
-            wp_unslash($_SERVER['REQUEST_URI'])
1067
-        );
1068
-        if (! empty($func)) {
1069
-            if (is_array($func)) {
1070
-                list($class, $method) = $func;
1071
-            } elseif (strpos($func, '::') !== false) {
1072
-                list($class, $method) = explode('::', $func);
1073
-            } else {
1074
-                $class = $this;
1075
-                $method = $func;
1076
-            }
1077
-            if (! (is_object($class) && $class === $this)) {
1078
-                // send along this admin page object for access by addons.
1079
-                $args['admin_page_object'] = $this;
1080
-            }
1081
-            // is it a method on a class that doesn't work?
1082
-            if (
1083
-                ((method_exists($class, $method)
1084
-                  && call_user_func_array(array($class, $method), $args) === false)
1085
-                 && (// is it a standalone function that doesn't work?
1086
-                     function_exists($method)
1087
-                     && call_user_func_array(
1088
-                         $func,
1089
-                         array_merge(array('admin_page_object' => $this), $args)
1090
-                     ) === false
1091
-                 )) || (// is it neither a class method NOR a standalone function?
1092
-                    ! function_exists($method)
1093
-                    && ! method_exists($class, $method)
1094
-                )
1095
-            ) {
1096
-                // user error msg
1097
-                $error_msg = esc_html__(
1098
-                    'An error occurred. The  requested page route could not be found.',
1099
-                    'event_espresso'
1100
-                );
1101
-                // developer error msg
1102
-                $error_msg .= '||';
1103
-                $error_msg .= sprintf(
1104
-                    esc_html__(
1105
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1106
-                        'event_espresso'
1107
-                    ),
1108
-                    $method
1109
-                );
1110
-            }
1111
-            if (! empty($error_msg)) {
1112
-                throw new EE_Error($error_msg);
1113
-            }
1114
-        }
1115
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1116
-        // then we need to reset the routing properties to the new route.
1117
-        // 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.
1118
-        if (
1119
-            $this->_is_UI_request === false
1120
-            && is_array($this->_route)
1121
-            && ! empty($this->_route['headers_sent_route'])
1122
-        ) {
1123
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1124
-        }
1125
-    }
1126
-
1127
-
1128
-    /**
1129
-     * This method just allows the resetting of page properties in the case where a no headers
1130
-     * route redirects to a headers route in its route config.
1131
-     *
1132
-     * @since   4.3.0
1133
-     * @param  string $new_route New (non header) route to redirect to.
1134
-     * @return   void
1135
-     * @throws ReflectionException
1136
-     * @throws InvalidArgumentException
1137
-     * @throws InvalidInterfaceException
1138
-     * @throws InvalidDataTypeException
1139
-     * @throws EE_Error
1140
-     */
1141
-    protected function _reset_routing_properties($new_route)
1142
-    {
1143
-        $this->_is_UI_request = true;
1144
-        // now we set the current route to whatever the headers_sent_route is set at
1145
-        $this->_req_data['action'] = $new_route;
1146
-        // rerun page setup
1147
-        $this->_page_setup();
1148
-    }
1149
-
1150
-
1151
-    /**
1152
-     * _add_query_arg
1153
-     * adds nonce to array of arguments then calls WP add_query_arg function
1154
-     *(internally just uses EEH_URL's function with the same name)
1155
-     *
1156
-     * @param array  $args
1157
-     * @param string $url
1158
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1159
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1160
-     *                                        Example usage: If the current page is:
1161
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1162
-     *                                        &action=default&event_id=20&month_range=March%202015
1163
-     *                                        &_wpnonce=5467821
1164
-     *                                        and you call:
1165
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1166
-     *                                        array(
1167
-     *                                        'action' => 'resend_something',
1168
-     *                                        'page=>espresso_registrations'
1169
-     *                                        ),
1170
-     *                                        $some_url,
1171
-     *                                        true
1172
-     *                                        );
1173
-     *                                        It will produce a url in this structure:
1174
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1175
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1176
-     *                                        month_range]=March%202015
1177
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1178
-     * @return string
1179
-     */
1180
-    public static function add_query_args_and_nonce(
1181
-        $args = array(),
1182
-        $url = '',
1183
-        $sticky = false,
1184
-        $exclude_nonce = false
1185
-    ) {
1186
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1187
-        if ($sticky) {
1188
-            $request = $_REQUEST;
1189
-            unset($request['_wp_http_referer'], $request['wp_referer']);
1190
-            foreach ($request as $key => $value) {
1191
-                // do not add nonces
1192
-                if (strpos($key, 'nonce') !== false) {
1193
-                    continue;
1194
-                }
1195
-                $args[ 'wp_referer[' . $key . ']' ] = $value;
1196
-            }
1197
-        }
1198
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * This returns a generated link that will load the related help tab.
1204
-     *
1205
-     * @param  string $help_tab_id the id for the connected help tab
1206
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1207
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1208
-     * @uses EEH_Template::get_help_tab_link()
1209
-     * @return string              generated link
1210
-     */
1211
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1212
-    {
1213
-        return EEH_Template::get_help_tab_link(
1214
-            $help_tab_id,
1215
-            $this->page_slug,
1216
-            $this->_req_action,
1217
-            $icon_style,
1218
-            $help_text
1219
-        );
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * _add_help_tabs
1225
-     * Note child classes define their help tabs within the page_config array.
1226
-     *
1227
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1228
-     * @return void
1229
-     * @throws DomainException
1230
-     * @throws EE_Error
1231
-     * @throws ReflectionException
1232
-     */
1233
-    protected function _add_help_tabs()
1234
-    {
1235
-        $tour_buttons = '';
1236
-        if (isset($this->_page_config[ $this->_req_action ])) {
1237
-            $config = $this->_page_config[ $this->_req_action ];
1238
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1239
-            // is there a help tour for the current route?  if there is let's setup the tour buttons
1240
-            // if (isset($this->_help_tour[ $this->_req_action ])) {
1241
-            //     $tb = array();
1242
-            //     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1243
-            //     foreach ($this->_help_tour['tours'] as $tour) {
1244
-            //         // if this is the end tour then we don't need to setup a button
1245
-            //         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1246
-            //             continue;
1247
-            //         }
1248
-            //         $tb[] = '<button id="trigger-tour-'
1249
-            //                 . $tour->get_slug()
1250
-            //                 . '" class="button-primary trigger-ee-help-tour">'
1251
-            //                 . $tour->get_label()
1252
-            //                 . '</button>';
1253
-            //     }
1254
-            //     $tour_buttons .= implode('<br />', $tb);
1255
-            //     $tour_buttons .= '</div></div>';
1256
-            // }
1257
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1258
-            if (is_array($config) && isset($config['help_sidebar'])) {
1259
-                // check that the callback given is valid
1260
-                if (! method_exists($this, $config['help_sidebar'])) {
1261
-                    throw new EE_Error(
1262
-                        sprintf(
1263
-                            esc_html__(
1264
-                                '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',
1265
-                                'event_espresso'
1266
-                            ),
1267
-                            $config['help_sidebar'],
1268
-                            get_class($this)
1269
-                        )
1270
-                    );
1271
-                }
1272
-                $content = apply_filters(
1273
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1274
-                    $this->{$config['help_sidebar']}()
1275
-                );
1276
-                $content .= $tour_buttons; // add help tour buttons.
1277
-                // do we have any help tours setup?  Cause if we do we want to add the buttons
1278
-                $this->_current_screen->set_help_sidebar($content);
1279
-            }
1280
-            // if there ARE tour buttons...
1281
-            if (! empty($tour_buttons)) {
1282
-                // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar.
1283
-                if (! isset($config['help_sidebar'])) {
1284
-                    $this->_current_screen->set_help_sidebar($tour_buttons);
1285
-                }
1286
-                // handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1287
-                if (! isset($config['help_tabs'])) {
1288
-                    $_ht['id'] = $this->page_slug;
1289
-                    $_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1290
-                    $_ht['content'] = '<p>'
1291
-                                      . esc_html__(
1292
-                                          'The buttons to the right allow you to start/restart any help tours available for this page',
1293
-                                          'event_espresso'
1294
-                                      ) . '</p>';
1295
-                    $this->_current_screen->add_help_tab($_ht);
1296
-                }
1297
-            }
1298
-            if (! isset($config['help_tabs'])) {
1299
-                return;
1300
-            } //no help tabs for this route
1301
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1302
-                // we're here so there ARE help tabs!
1303
-                // make sure we've got what we need
1304
-                if (! isset($cfg['title'])) {
1305
-                    throw new EE_Error(
1306
-                        esc_html__(
1307
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1308
-                            'event_espresso'
1309
-                        )
1310
-                    );
1311
-                }
1312
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1313
-                    throw new EE_Error(
1314
-                        esc_html__(
1315
-                            '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',
1316
-                            'event_espresso'
1317
-                        )
1318
-                    );
1319
-                }
1320
-                // first priority goes to content.
1321
-                if (! empty($cfg['content'])) {
1322
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1323
-                    // second priority goes to filename
1324
-                } elseif (! empty($cfg['filename'])) {
1325
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1326
-                    // 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)
1327
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1328
-                                                             . basename($this->_get_dir())
1329
-                                                             . '/help_tabs/'
1330
-                                                             . $cfg['filename']
1331
-                                                             . '.help_tab.php' : $file_path;
1332
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1333
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1334
-                        EE_Error::add_error(
1335
-                            sprintf(
1336
-                                esc_html__(
1337
-                                    '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',
1338
-                                    'event_espresso'
1339
-                                ),
1340
-                                $tab_id,
1341
-                                key($config),
1342
-                                $file_path
1343
-                            ),
1344
-                            __FILE__,
1345
-                            __FUNCTION__,
1346
-                            __LINE__
1347
-                        );
1348
-                        return;
1349
-                    }
1350
-                    $template_args['admin_page_obj'] = $this;
1351
-                    $content = EEH_Template::display_template(
1352
-                        $file_path,
1353
-                        $template_args,
1354
-                        true
1355
-                    );
1356
-                } else {
1357
-                    $content = '';
1358
-                }
1359
-                // check if callback is valid
1360
-                if (
1361
-                    empty($content) && (
1362
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1363
-                    )
1364
-                ) {
1365
-                    EE_Error::add_error(
1366
-                        sprintf(
1367
-                            esc_html__(
1368
-                                '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.',
1369
-                                'event_espresso'
1370
-                            ),
1371
-                            $cfg['title']
1372
-                        ),
1373
-                        __FILE__,
1374
-                        __FUNCTION__,
1375
-                        __LINE__
1376
-                    );
1377
-                    return;
1378
-                }
1379
-                // setup config array for help tab method
1380
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1381
-                $_ht = array(
1382
-                    'id'       => $id,
1383
-                    'title'    => $cfg['title'],
1384
-                    'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1385
-                    'content'  => $content,
1386
-                );
1387
-                $this->_current_screen->add_help_tab($_ht);
1388
-            }
1389
-        }
1390
-    }
1391
-
1392
-
1393
-    /**
1394
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1395
-     * an array with properties for setting up usage of the joyride plugin
1396
-     *
1397
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1398
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1399
-     *         _set_page_config() comments
1400
-     * @return void
1401
-     * @throws EE_Error
1402
-     * @throws InvalidArgumentException
1403
-     * @throws InvalidDataTypeException
1404
-     * @throws InvalidInterfaceException
1405
-     * @throws ReflectionException
1406
-     */
1407
-    protected function _add_help_tour()
1408
-    {
1409
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1410
-        // $tours = array();
1411
-        // $this->_help_tour = array();
1412
-        // // exit early if help tours are turned off globally
1413
-        // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1414
-        //     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1415
-        // ) {
1416
-        //     return;
1417
-        // }
1418
-        // // loop through _page_config to find any help_tour defined
1419
-        // foreach ($this->_page_config as $route => $config) {
1420
-        //     // we're only going to set things up for this route
1421
-        //     if ($route !== $this->_req_action) {
1422
-        //         continue;
1423
-        //     }
1424
-        //     if (isset($config['help_tour'])) {
1425
-        //         foreach ($config['help_tour'] as $tour) {
1426
-        //             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1427
-        //             // let's see if we can get that file...
1428
-        //             // if not its possible this is a decaf route not set in caffeinated
1429
-        //             // so lets try and get the caffeinated equivalent
1430
-        //             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1431
-        //                                                      . basename($this->_get_dir())
1432
-        //                                                      . '/help_tours/'
1433
-        //                                                      . $tour
1434
-        //                                                      . '.class.php' : $file_path;
1435
-        //             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1436
-        //             if (! is_readable($file_path)) {
1437
-        //                 EE_Error::add_error(
1438
-        //                     sprintf(
1439
-        //                         esc_html__(
1440
-        //                             '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',
1441
-        //                             'event_espresso'
1442
-        //                         ),
1443
-        //                         $file_path,
1444
-        //                         $tour
1445
-        //                     ),
1446
-        //                     __FILE__,
1447
-        //                     __FUNCTION__,
1448
-        //                     __LINE__
1449
-        //                 );
1450
-        //                 return;
1451
-        //             }
1452
-        //             require_once $file_path;
1453
-        //             if (! class_exists($tour)) {
1454
-        //                 $error_msg[] = sprintf(
1455
-        //                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1456
-        //                     $tour
1457
-        //                 );
1458
-        //                 $error_msg[] = $error_msg[0] . "\r\n"
1459
-        //                                . sprintf(
1460
-        //                                    esc_html__(
1461
-        //                                        '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.',
1462
-        //                                        'event_espresso'
1463
-        //                                    ),
1464
-        //                                    $tour,
1465
-        //                                    '<br />',
1466
-        //                                    $tour,
1467
-        //                                    $this->_req_action,
1468
-        //                                    get_class($this)
1469
-        //                                );
1470
-        //                 throw new EE_Error(implode('||', $error_msg));
1471
-        //             }
1472
-        //             $tour_obj = new $tour($this->_is_caf);
1473
-        //             $tours[] = $tour_obj;
1474
-        //             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1475
-        //         }
1476
-        //         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1477
-        //         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1478
-        //         $tours[] = $end_stop_tour;
1479
-        //         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1480
-        //     }
1481
-        // }
1482
-        //
1483
-        // if (! empty($tours)) {
1484
-        //     $this->_help_tour['tours'] = $tours;
1485
-        // }
1486
-        // // that's it!  Now that the $_help_tours property is set (or not)
1487
-        // // the scripts and html should be taken care of automatically.
1488
-        //
1489
-        // /**
1490
-        //  * Allow extending the help tours variable.
1491
-        //  *
1492
-        //  * @param Array $_help_tour The array containing all help tour information to be displayed.
1493
-        //  */
1494
-        // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1495
-    }
1496
-
1497
-
1498
-    /**
1499
-     * This simply sets up any qtips that have been defined in the page config
1500
-     *
1501
-     * @return void
1502
-     * @throws ReflectionException
1503
-     * @throws EE_Error
1504
-     */
1505
-    protected function _add_qtips()
1506
-    {
1507
-        if (isset($this->_route_config['qtips'])) {
1508
-            $qtips = (array) $this->_route_config['qtips'];
1509
-            // load qtip loader
1510
-            $path = array(
1511
-                $this->_get_dir() . '/qtips/',
1512
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1513
-            );
1514
-            $qtip_loader = EEH_Qtip_Loader::instance();
1515
-            if ($qtip_loader instanceof EEH_Qtip_Loader) {
1516
-                $qtip_loader->register($qtips, $path);
1517
-            }
1518
-        }
1519
-    }
1520
-
1521
-
1522
-    /**
1523
-     * _set_nav_tabs
1524
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1525
-     * wish to add additional tabs or modify accordingly.
1526
-     *
1527
-     * @return void
1528
-     * @throws InvalidArgumentException
1529
-     * @throws InvalidInterfaceException
1530
-     * @throws InvalidDataTypeException
1531
-     */
1532
-    protected function _set_nav_tabs()
1533
-    {
1534
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1535
-        $i = 0;
1536
-        foreach ($this->_page_config as $slug => $config) {
1537
-            if (
1538
-                ! is_array($config)
1539
-                || (
1540
-                    is_array($config)
1541
-                    && (
1542
-                        (isset($config['nav']) && ! $config['nav'])
1543
-                        || ! isset($config['nav'])
1544
-                    )
1545
-                )
1546
-            ) {
1547
-                continue;
1548
-            }
1549
-            // no nav tab for this config
1550
-            // check for persistent flag
1551
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1552
-                // nav tab is only to appear when route requested.
1553
-                continue;
1554
-            }
1555
-            if (! $this->check_user_access($slug, true)) {
1556
-                // no nav tab because current user does not have access.
1557
-                continue;
1558
-            }
1559
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1560
-            $this->_nav_tabs[ $slug ] = array(
1561
-                'url'       => isset($config['nav']['url'])
1562
-                    ? $config['nav']['url']
1563
-                    : EE_Admin_Page::add_query_args_and_nonce(
1564
-                        array('action' => $slug),
1565
-                        $this->_admin_base_url
1566
-                    ),
1567
-                'link_text' => isset($config['nav']['label'])
1568
-                    ? $config['nav']['label']
1569
-                    : ucwords(
1570
-                        str_replace('_', ' ', $slug)
1571
-                    ),
1572
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1573
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1574
-            );
1575
-            $i++;
1576
-        }
1577
-        // if $this->_nav_tabs is empty then lets set the default
1578
-        if (empty($this->_nav_tabs)) {
1579
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1580
-                'url'       => $this->_admin_base_url,
1581
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1582
-                'css_class' => 'nav-tab-active',
1583
-                'order'     => 10,
1584
-            );
1585
-        }
1586
-        // now let's sort the tabs according to order
1587
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1588
-    }
1589
-
1590
-
1591
-    /**
1592
-     * _set_current_labels
1593
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1594
-     * property array
1595
-     *
1596
-     * @return void
1597
-     */
1598
-    private function _set_current_labels()
1599
-    {
1600
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1601
-            foreach ($this->_route_config['labels'] as $label => $text) {
1602
-                if (is_array($text)) {
1603
-                    foreach ($text as $sublabel => $subtext) {
1604
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1605
-                    }
1606
-                } else {
1607
-                    $this->_labels[ $label ] = $text;
1608
-                }
1609
-            }
1610
-        }
1611
-    }
1612
-
1613
-
1614
-    /**
1615
-     *        verifies user access for this admin page
1616
-     *
1617
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1618
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1619
-     *                               return false if verify fail.
1620
-     * @return bool
1621
-     * @throws InvalidArgumentException
1622
-     * @throws InvalidDataTypeException
1623
-     * @throws InvalidInterfaceException
1624
-     */
1625
-    public function check_user_access($route_to_check = '', $verify_only = false)
1626
-    {
1627
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1628
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1629
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1630
-                      && is_array(
1631
-                          $this->_page_routes[ $route_to_check ]
1632
-                      )
1633
-                      && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1634
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1635
-        if (empty($capability) && empty($route_to_check)) {
1636
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1637
-                : $this->_route['capability'];
1638
-        } else {
1639
-            $capability = empty($capability) ? 'manage_options' : $capability;
1640
-        }
1641
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1642
-        if (
1643
-            ! defined('DOING_AJAX')
1644
-            && (
1645
-                ! function_exists('is_admin')
1646
-                || ! EE_Registry::instance()->CAP->current_user_can(
1647
-                    $capability,
1648
-                    $this->page_slug
1649
-                    . '_'
1650
-                    . $route_to_check,
1651
-                    $id
1652
-                )
1653
-            )
1654
-        ) {
1655
-            if ($verify_only) {
1656
-                return false;
1657
-            }
1658
-            if (is_user_logged_in()) {
1659
-                wp_die(__('You do not have access to this route.', 'event_espresso'));
1660
-            } else {
1661
-                return false;
1662
-            }
1663
-        }
1664
-        return true;
1665
-    }
1666
-
1667
-
1668
-    /**
1669
-     * admin_init_global
1670
-     * This runs all the code that we want executed within the WP admin_init hook.
1671
-     * This method executes for ALL EE Admin pages.
1672
-     *
1673
-     * @return void
1674
-     */
1675
-    public function admin_init_global()
1676
-    {
1677
-    }
1678
-
1679
-
1680
-    /**
1681
-     * wp_loaded_global
1682
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1683
-     * EE_Admin page and will execute on every EE Admin Page load
1684
-     *
1685
-     * @return void
1686
-     */
1687
-    public function wp_loaded()
1688
-    {
1689
-    }
1690
-
1691
-
1692
-    /**
1693
-     * admin_notices
1694
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1695
-     * ALL EE_Admin pages.
1696
-     *
1697
-     * @return void
1698
-     */
1699
-    public function admin_notices_global()
1700
-    {
1701
-        $this->_display_no_javascript_warning();
1702
-        $this->_display_espresso_notices();
1703
-    }
1704
-
1705
-
1706
-    public function network_admin_notices_global()
1707
-    {
1708
-        $this->_display_no_javascript_warning();
1709
-        $this->_display_espresso_notices();
1710
-    }
1711
-
1712
-
1713
-    /**
1714
-     * admin_footer_scripts_global
1715
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1716
-     * will apply on ALL EE_Admin pages.
1717
-     *
1718
-     * @return void
1719
-     */
1720
-    public function admin_footer_scripts_global()
1721
-    {
1722
-        $this->_add_admin_page_ajax_loading_img();
1723
-        $this->_add_admin_page_overlay();
1724
-        // if metaboxes are present we need to add the nonce field
1725
-        if (
1726
-            isset($this->_route_config['metaboxes'])
1727
-            || isset($this->_route_config['list_table'])
1728
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1729
-        ) {
1730
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1731
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1732
-        }
1733
-    }
1734
-
1735
-
1736
-    /**
1737
-     * admin_footer_global
1738
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1739
-     * This particular method will apply on ALL EE_Admin Pages.
1740
-     *
1741
-     * @return void
1742
-     * @throws InvalidArgumentException
1743
-     * @throws InvalidDataTypeException
1744
-     * @throws InvalidInterfaceException
1745
-     */
1746
-    public function admin_footer_global()
1747
-    {
1748
-        // dialog container for dialog helper
1749
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1750
-        $d_cont .= '<div class="ee-notices"></div>';
1751
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1752
-        $d_cont .= '</div>';
1753
-        echo $d_cont;
1754
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1755
-        // help tour stuff?
1756
-        // if (isset($this->_help_tour[ $this->_req_action ])) {
1757
-        //     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1758
-        // }
1759
-        // current set timezone for timezone js
1760
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1761
-    }
1762
-
1763
-
1764
-    /**
1765
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1766
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1767
-     * help popups then in your templates or your content you set "triggers" for the content using the
1768
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1769
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1770
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1771
-     * for the
1772
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1773
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1774
-     *    'help_trigger_id' => array(
1775
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1776
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1777
-     *    )
1778
-     * );
1779
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1780
-     *
1781
-     * @param array $help_array
1782
-     * @param bool  $display
1783
-     * @return string content
1784
-     * @throws DomainException
1785
-     * @throws EE_Error
1786
-     */
1787
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1788
-    {
1789
-        $content = '';
1790
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1791
-        // loop through the array and setup content
1792
-        foreach ($help_array as $trigger => $help) {
1793
-            // make sure the array is setup properly
1794
-            if (! isset($help['title'], $help['content'])) {
1795
-                throw new EE_Error(
1796
-                    esc_html__(
1797
-                        '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',
1798
-                        'event_espresso'
1799
-                    )
1800
-                );
1801
-            }
1802
-            // we're good so let'd setup the template vars and then assign parsed template content to our content.
1803
-            $template_args = array(
1804
-                'help_popup_id'      => $trigger,
1805
-                'help_popup_title'   => $help['title'],
1806
-                'help_popup_content' => $help['content'],
1807
-            );
1808
-            $content .= EEH_Template::display_template(
1809
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1810
-                $template_args,
1811
-                true
1812
-            );
1813
-        }
1814
-        if ($display) {
1815
-            echo $content;
1816
-            return '';
1817
-        }
1818
-        return $content;
1819
-    }
1820
-
1821
-
1822
-    /**
1823
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1824
-     *
1825
-     * @return array properly formatted array for help popup content
1826
-     * @throws EE_Error
1827
-     */
1828
-    private function _get_help_content()
1829
-    {
1830
-        // what is the method we're looking for?
1831
-        $method_name = '_help_popup_content_' . $this->_req_action;
1832
-        // if method doesn't exist let's get out.
1833
-        if (! method_exists($this, $method_name)) {
1834
-            return array();
1835
-        }
1836
-        // k we're good to go let's retrieve the help array
1837
-        $help_array = $this->{$method_name}();
1838
-        // make sure we've got an array!
1839
-        if (! is_array($help_array)) {
1840
-            throw new EE_Error(
1841
-                esc_html__(
1842
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1843
-                    'event_espresso'
1844
-                )
1845
-            );
1846
-        }
1847
-        return $help_array;
1848
-    }
1849
-
1850
-
1851
-    /**
1852
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1853
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1854
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1855
-     *
1856
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1857
-     * @param boolean $display    if false then we return the trigger string
1858
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1859
-     * @return string
1860
-     * @throws DomainException
1861
-     * @throws EE_Error
1862
-     */
1863
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1864
-    {
1865
-        if (defined('DOING_AJAX')) {
1866
-            return '';
1867
-        }
1868
-        // 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
1869
-        $help_array = $this->_get_help_content();
1870
-        $help_content = '';
1871
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1872
-            $help_array[ $trigger_id ] = array(
1873
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1874
-                'content' => esc_html__(
1875
-                    '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.)',
1876
-                    'event_espresso'
1877
-                ),
1878
-            );
1879
-            $help_content = $this->_set_help_popup_content($help_array);
1880
-        }
1881
-        // let's setup the trigger
1882
-        $content = '<a class="ee-dialog" href="?height='
1883
-                   . $dimensions[0]
1884
-                   . '&width='
1885
-                   . $dimensions[1]
1886
-                   . '&inlineId='
1887
-                   . $trigger_id
1888
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1889
-        $content .= $help_content;
1890
-        if ($display) {
1891
-            echo $content;
1892
-            return '';
1893
-        }
1894
-        return $content;
1895
-    }
1896
-
1897
-
1898
-    /**
1899
-     * _add_global_screen_options
1900
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1901
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1902
-     *
1903
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1904
-     *         see also WP_Screen object documents...
1905
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1906
-     * @abstract
1907
-     * @return void
1908
-     */
1909
-    private function _add_global_screen_options()
1910
-    {
1911
-    }
1912
-
1913
-
1914
-    /**
1915
-     * _add_global_feature_pointers
1916
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1917
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1918
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1919
-     *
1920
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1921
-     *         extended) also see:
1922
-     * @link   http://eamann.com/tech/wordpress-portland/
1923
-     * @abstract
1924
-     * @return void
1925
-     */
1926
-    private function _add_global_feature_pointers()
1927
-    {
1928
-    }
1929
-
1930
-
1931
-    /**
1932
-     * load_global_scripts_styles
1933
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1934
-     *
1935
-     * @return void
1936
-     * @throws EE_Error
1937
-     */
1938
-    public function load_global_scripts_styles()
1939
-    {
1940
-        // add debugging styles
1941
-        if (WP_DEBUG) {
1942
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1943
-        }
1944
-        // taking care of metaboxes
1945
-        if (
1946
-            empty($this->_cpt_route)
1947
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1948
-        ) {
1949
-            wp_enqueue_script('dashboard');
1950
-        }
1951
-
1952
-        // LOCALIZED DATA
1953
-        // localize script for ajax lazy loading
1954
-        wp_localize_script(
1955
-            EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1956
-            'eeLazyLoadingContainers',
1957
-            apply_filters(
1958
-                'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1959
-                ['espresso_news_post_box_content']
1960
-            )
1961
-        );
1962
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1963
-        // /**
1964
-        //  * help tour stuff
1965
-        //  */
1966
-        // if (! empty($this->_help_tour)) {
1967
-        //     // register the js for kicking things off
1968
-        //     wp_enqueue_script(
1969
-        //         'ee-help-tour',
1970
-        //         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1971
-        //         array('jquery-joyride'),
1972
-        //         EVENT_ESPRESSO_VERSION,
1973
-        //         true
1974
-        //     );
1975
-        //     $tours = array();
1976
-        //     // setup tours for the js tour object
1977
-        //     foreach ($this->_help_tour['tours'] as $tour) {
1978
-        //         if ($tour instanceof EE_Help_Tour) {
1979
-        //             $tours[] = array(
1980
-        //                 'id'      => $tour->get_slug(),
1981
-        //                 'options' => $tour->get_options(),
1982
-        //             );
1983
-        //         }
1984
-        //     }
1985
-        //     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1986
-        //     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1987
-        // }
1988
-    }
1989
-
1990
-
1991
-    /**
1992
-     *        admin_footer_scripts_eei18n_js_strings
1993
-     *
1994
-     * @return        void
1995
-     */
1996
-    public function admin_footer_scripts_eei18n_js_strings()
1997
-    {
1998
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1999
-        EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2000
-            '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!!!',
2001
-            'event_espresso'
2002
-        );
2003
-        EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso');
2004
-        EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso');
2005
-        EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso');
2006
-        EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso');
2007
-        EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2008
-        EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso');
2009
-        EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso');
2010
-        EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso');
2011
-        EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso');
2012
-        EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso');
2013
-        EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso');
2014
-        EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso');
2015
-        EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso');
2016
-        EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso');
2017
-        EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso');
2018
-        EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso');
2019
-        EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2020
-        EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso');
2021
-        EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso');
2022
-        EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso');
2023
-        EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso');
2024
-        EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso');
2025
-        EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso');
2026
-        EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso');
2027
-        EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso');
2028
-        EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso');
2029
-        EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso');
2030
-        EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso');
2031
-        EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso');
2032
-        EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso');
2033
-        EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso');
2034
-        EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso');
2035
-        EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso');
2036
-        EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso');
2037
-        EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso');
2038
-        EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso');
2039
-        EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso');
2040
-        EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso');
2041
-    }
2042
-
2043
-
2044
-    /**
2045
-     *        load enhanced xdebug styles for ppl with failing eyesight
2046
-     *
2047
-     * @return        void
2048
-     */
2049
-    public function add_xdebug_style()
2050
-    {
2051
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2052
-    }
2053
-
2054
-
2055
-    /************************/
2056
-    /** LIST TABLE METHODS **/
2057
-    /************************/
2058
-    /**
2059
-     * this sets up the list table if the current view requires it.
2060
-     *
2061
-     * @return void
2062
-     * @throws EE_Error
2063
-     * @throws InvalidArgumentException
2064
-     * @throws InvalidDataTypeException
2065
-     * @throws InvalidInterfaceException
2066
-     */
2067
-    protected function _set_list_table()
2068
-    {
2069
-        // first is this a list_table view?
2070
-        if (! isset($this->_route_config['list_table'])) {
2071
-            return;
2072
-        } //not a list_table view so get out.
2073
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2074
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2075
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2076
-            // user error msg
2077
-            $error_msg = esc_html__(
2078
-                'An error occurred. The requested list table views could not be found.',
2079
-                'event_espresso'
2080
-            );
2081
-            // developer error msg
2082
-            $error_msg .= '||'
2083
-                          . sprintf(
2084
-                              esc_html__(
2085
-                                  '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.',
2086
-                                  'event_espresso'
2087
-                              ),
2088
-                              $this->_req_action,
2089
-                              $list_table_view
2090
-                          );
2091
-            throw new EE_Error($error_msg);
2092
-        }
2093
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2094
-        $this->_views = apply_filters(
2095
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2096
-            $this->_views
2097
-        );
2098
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2099
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2100
-        $this->_set_list_table_view();
2101
-        $this->_set_list_table_object();
2102
-    }
2103
-
2104
-
2105
-    /**
2106
-     * set current view for List Table
2107
-     *
2108
-     * @return void
2109
-     */
2110
-    protected function _set_list_table_view()
2111
-    {
2112
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2113
-        // looking at active items or dumpster diving ?
2114
-        if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2115
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2116
-        } else {
2117
-            $this->_view = sanitize_key($this->_req_data['status']);
2118
-        }
2119
-    }
2120
-
2121
-
2122
-    /**
2123
-     * _set_list_table_object
2124
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2125
-     *
2126
-     * @throws InvalidInterfaceException
2127
-     * @throws InvalidArgumentException
2128
-     * @throws InvalidDataTypeException
2129
-     * @throws EE_Error
2130
-     * @throws InvalidInterfaceException
2131
-     */
2132
-    protected function _set_list_table_object()
2133
-    {
2134
-        if (isset($this->_route_config['list_table'])) {
2135
-            if (! class_exists($this->_route_config['list_table'])) {
2136
-                throw new EE_Error(
2137
-                    sprintf(
2138
-                        esc_html__(
2139
-                            '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.',
2140
-                            'event_espresso'
2141
-                        ),
2142
-                        $this->_route_config['list_table'],
2143
-                        get_class($this)
2144
-                    )
2145
-                );
2146
-            }
2147
-            $this->_list_table_object = $this->loader->getShared(
2148
-                $this->_route_config['list_table'],
2149
-                array($this)
2150
-            );
2151
-        }
2152
-    }
2153
-
2154
-
2155
-    /**
2156
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2157
-     *
2158
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2159
-     *                                                    urls.  The array should be indexed by the view it is being
2160
-     *                                                    added to.
2161
-     * @return array
2162
-     */
2163
-    public function get_list_table_view_RLs($extra_query_args = array())
2164
-    {
2165
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2166
-        if (empty($this->_views)) {
2167
-            $this->_views = array();
2168
-        }
2169
-        // cycle thru views
2170
-        foreach ($this->_views as $key => $view) {
2171
-            $query_args = array();
2172
-            // check for current view
2173
-            $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2174
-            $query_args['action'] = $this->_req_action;
2175
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2176
-            $query_args['status'] = $view['slug'];
2177
-            // merge any other arguments sent in.
2178
-            if (isset($extra_query_args[ $view['slug'] ])) {
2179
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2180
-                    $query_args[] = $extra_query_arg;
2181
-                }
2182
-            }
2183
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2184
-        }
2185
-        return $this->_views;
2186
-    }
2187
-
2188
-
2189
-    /**
2190
-     * _entries_per_page_dropdown
2191
-     * generates a drop down box for selecting the number of visible rows in an admin page list table
2192
-     *
2193
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2194
-     *         WP does it.
2195
-     * @param int $max_entries total number of rows in the table
2196
-     * @return string
2197
-     */
2198
-    protected function _entries_per_page_dropdown($max_entries = 0)
2199
-    {
2200
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2201
-        $values = array(10, 25, 50, 100);
2202
-        $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2203
-        if ($max_entries) {
2204
-            $values[] = $max_entries;
2205
-            sort($values);
2206
-        }
2207
-        $entries_per_page_dropdown = '
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
+	// sanitized request action (and nonce)
132
+
133
+	/**
134
+	 * @var string $_req_action
135
+	 */
136
+	protected $_req_action;
137
+
138
+	/**
139
+	 * @var string $_req_nonce
140
+	 */
141
+	protected $_req_nonce;
142
+
143
+	// search related
144
+	protected $_search_btn_label;
145
+
146
+	protected $_search_box_callback;
147
+
148
+	/**
149
+	 * WP Current Screen object
150
+	 *
151
+	 * @var WP_Screen
152
+	 */
153
+	protected $_current_screen;
154
+
155
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
156
+	protected $_hook_obj;
157
+
158
+	// for holding incoming request data
159
+	protected $_req_data = [];
160
+
161
+	// yes / no array for admin form fields
162
+	protected $_yes_no_values = array();
163
+
164
+	// some default things shared by all child classes
165
+	protected $_default_espresso_metaboxes;
166
+
167
+	/**
168
+	 *    EE_Registry Object
169
+	 *
170
+	 * @var    EE_Registry
171
+	 */
172
+	protected $EE;
173
+
174
+
175
+	/**
176
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
177
+	 *
178
+	 * @var boolean
179
+	 */
180
+	protected $_is_caf = false;
181
+
182
+	/**
183
+	 * whether or not initializePage() has run
184
+	 *
185
+	 * @var boolean
186
+	 */
187
+	protected $initialized = false;
188
+
189
+
190
+	/**
191
+	 * @Constructor
192
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
193
+	 * @throws InvalidArgumentException
194
+	 * @throws InvalidDataTypeException
195
+	 * @throws InvalidInterfaceException
196
+	 * @throws ReflectionException
197
+	 */
198
+	public function __construct($routing = true)
199
+	{
200
+		$this->loader = LoaderFactory::getLoader();
201
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
202
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
203
+			$this->_is_caf = true;
204
+		}
205
+		$this->_yes_no_values = array(
206
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
207
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
208
+		);
209
+		// set the _req_data property.
210
+		$this->_req_data = array_merge($_GET, $_POST);
211
+		// routing enabled?
212
+		$this->_routing = $routing;
213
+	}
214
+
215
+
216
+	/**
217
+	 * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
218
+	 * for child classes that needed to set properties prior to these methods getting called,
219
+	 * but also needed the parent class to have its construction completed as well.
220
+	 * Bottom line is that constructors should ONLY be used for setting initial properties
221
+	 * and any complex initialization logic should only run after instantiation is complete.
222
+	 *
223
+	 * This method gets called immediately after construction from within
224
+	 *      EE_Admin_Page_Init::_initialize_admin_page()
225
+	 *
226
+	 * @throws EE_Error
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidDataTypeException
229
+	 * @throws InvalidInterfaceException
230
+	 * @throws ReflectionException
231
+	 * @since $VID:$
232
+	 */
233
+	public function initializePage()
234
+	{
235
+		if ($this->initialized) {
236
+			return;
237
+		}
238
+		// set initial page props (child method)
239
+		$this->_init_page_props();
240
+		// set global defaults
241
+		$this->_set_defaults();
242
+		// set early because incoming requests could be ajax related and we need to register those hooks.
243
+		$this->_global_ajax_hooks();
244
+		$this->_ajax_hooks();
245
+		// other_page_hooks have to be early too.
246
+		$this->_do_other_page_hooks();
247
+		// This just allows us to have extending classes do something specific
248
+		// before the parent constructor runs _page_setup().
249
+		if (method_exists($this, '_before_page_setup')) {
250
+			$this->_before_page_setup();
251
+		}
252
+		// set up page dependencies
253
+		$this->_page_setup();
254
+		$this->initialized = true;
255
+	}
256
+
257
+
258
+	/**
259
+	 * _init_page_props
260
+	 * Child classes use to set at least the following properties:
261
+	 * $page_slug.
262
+	 * $page_label.
263
+	 *
264
+	 * @abstract
265
+	 * @return void
266
+	 */
267
+	abstract protected function _init_page_props();
268
+
269
+
270
+	/**
271
+	 * _ajax_hooks
272
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
273
+	 * Note: within the ajax callback methods.
274
+	 *
275
+	 * @abstract
276
+	 * @return void
277
+	 */
278
+	abstract protected function _ajax_hooks();
279
+
280
+
281
+	/**
282
+	 * _define_page_props
283
+	 * child classes define page properties in here.  Must include at least:
284
+	 * $_admin_base_url = base_url for all admin pages
285
+	 * $_admin_page_title = default admin_page_title for admin pages
286
+	 * $_labels = array of default labels for various automatically generated elements:
287
+	 *    array(
288
+	 *        'buttons' => array(
289
+	 *            'add' => esc_html__('label for add new button'),
290
+	 *            'edit' => esc_html__('label for edit button'),
291
+	 *            'delete' => esc_html__('label for delete button')
292
+	 *            )
293
+	 *        )
294
+	 *
295
+	 * @abstract
296
+	 * @return void
297
+	 */
298
+	abstract protected function _define_page_props();
299
+
300
+
301
+	/**
302
+	 * _set_page_routes
303
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
304
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
305
+	 * have a 'default' route. Here's the format
306
+	 * $this->_page_routes = array(
307
+	 *        'default' => array(
308
+	 *            'func' => '_default_method_handling_route',
309
+	 *            'args' => array('array','of','args'),
310
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
311
+	 *            ajax request, backend processing)
312
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
313
+	 *            headers route after.  The string you enter here should match the defined route reference for a
314
+	 *            headers sent route.
315
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
316
+	 *            this route.
317
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
318
+	 *            checks).
319
+	 *        ),
320
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
321
+	 *        handling method.
322
+	 *        )
323
+	 * )
324
+	 *
325
+	 * @abstract
326
+	 * @return void
327
+	 */
328
+	abstract protected function _set_page_routes();
329
+
330
+
331
+	/**
332
+	 * _set_page_config
333
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
334
+	 * array corresponds to the page_route for the loaded page. Format:
335
+	 * $this->_page_config = array(
336
+	 *        'default' => array(
337
+	 *            'labels' => array(
338
+	 *                'buttons' => array(
339
+	 *                    'add' => esc_html__('label for adding item'),
340
+	 *                    'edit' => esc_html__('label for editing item'),
341
+	 *                    'delete' => esc_html__('label for deleting item')
342
+	 *                ),
343
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
344
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
345
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
346
+	 *            _define_page_props() method
347
+	 *            'nav' => array(
348
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
349
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
350
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
351
+	 *                'order' => 10, //required to indicate tab position.
352
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
353
+	 *                displayed then add this parameter.
354
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
355
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
356
+	 *            metaboxes set for eventespresso admin pages.
357
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
358
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
359
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
360
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
361
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
362
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
363
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
364
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
365
+	 *            want to display.
366
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
367
+	 *                'tab_id' => array(
368
+	 *                    'title' => 'tab_title',
369
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
370
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
371
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
372
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
373
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
374
+	 *                    attempt to use the callback which should match the name of a method in the class
375
+	 *                    ),
376
+	 *                'tab2_id' => array(
377
+	 *                    'title' => 'tab2 title',
378
+	 *                    'filename' => 'file_name_2'
379
+	 *                    'callback' => 'callback_method_for_content',
380
+	 *                 ),
381
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
382
+	 *            help tab area on an admin page. @link
383
+	 *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
384
+	 *            'help_tour' => array(
385
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
386
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
387
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
388
+	 *            ),
389
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
390
+	 *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
391
+	 *            just set
392
+	 *            'require_nonce' to FALSE
393
+	 *            )
394
+	 * )
395
+	 *
396
+	 * @abstract
397
+	 * @return void
398
+	 */
399
+	abstract protected function _set_page_config();
400
+
401
+
402
+
403
+
404
+
405
+	/** end sample help_tour methods **/
406
+	/**
407
+	 * _add_screen_options
408
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
409
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
410
+	 * to a particular view.
411
+	 *
412
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
413
+	 *         see also WP_Screen object documents...
414
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
415
+	 * @abstract
416
+	 * @return void
417
+	 */
418
+	abstract protected function _add_screen_options();
419
+
420
+
421
+	/**
422
+	 * _add_feature_pointers
423
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
424
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
425
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
426
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
427
+	 * extended) also see:
428
+	 *
429
+	 * @link   http://eamann.com/tech/wordpress-portland/
430
+	 * @abstract
431
+	 * @return void
432
+	 */
433
+	abstract protected function _add_feature_pointers();
434
+
435
+
436
+	/**
437
+	 * load_scripts_styles
438
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
439
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
440
+	 * scripts/styles per view by putting them in a dynamic function in this format
441
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
442
+	 *
443
+	 * @abstract
444
+	 * @return void
445
+	 */
446
+	abstract public function load_scripts_styles();
447
+
448
+
449
+	/**
450
+	 * admin_init
451
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
452
+	 * all pages/views loaded by child class.
453
+	 *
454
+	 * @abstract
455
+	 * @return void
456
+	 */
457
+	abstract public function admin_init();
458
+
459
+
460
+	/**
461
+	 * admin_notices
462
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
463
+	 * all pages/views loaded by child class.
464
+	 *
465
+	 * @abstract
466
+	 * @return void
467
+	 */
468
+	abstract public function admin_notices();
469
+
470
+
471
+	/**
472
+	 * admin_footer_scripts
473
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
474
+	 * will apply to all pages/views loaded by child class.
475
+	 *
476
+	 * @return void
477
+	 */
478
+	abstract public function admin_footer_scripts();
479
+
480
+
481
+	/**
482
+	 * admin_footer
483
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
484
+	 * apply to all pages/views loaded by child class.
485
+	 *
486
+	 * @return void
487
+	 */
488
+	public function admin_footer()
489
+	{
490
+	}
491
+
492
+
493
+	/**
494
+	 * _global_ajax_hooks
495
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
496
+	 * Note: within the ajax callback methods.
497
+	 *
498
+	 * @abstract
499
+	 * @return void
500
+	 */
501
+	protected function _global_ajax_hooks()
502
+	{
503
+		// for lazy loading of metabox content
504
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
505
+
506
+		add_action(
507
+			'wp_ajax_espresso_hide_status_change_notice',
508
+			[$this, 'hideStatusChangeNotice']
509
+		);
510
+		add_action(
511
+			'wp_ajax_nopriv_espresso_hide_status_change_notice',
512
+			[$this, 'hideStatusChangeNotice']
513
+		);
514
+	}
515
+
516
+
517
+	public function ajax_metabox_content()
518
+	{
519
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
520
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
521
+		EE_Admin_Page::cached_rss_display($contentid, $url);
522
+		wp_die();
523
+	}
524
+
525
+
526
+	public function hideStatusChangeNotice()
527
+	{
528
+		$response = [];
529
+		try {
530
+			/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
531
+			$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
532
+			$response['success'] = $status_change_notice->dismiss() > -1;
533
+		} catch (Exception $exception) {
534
+			$response['errors'] = $exception->getMessage();
535
+		}
536
+		echo wp_json_encode($response);
537
+		exit();
538
+	}
539
+
540
+
541
+	/**
542
+	 * _page_setup
543
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
544
+	 * doesn't match the object.
545
+	 *
546
+	 * @final
547
+	 * @return void
548
+	 * @throws EE_Error
549
+	 * @throws InvalidArgumentException
550
+	 * @throws ReflectionException
551
+	 * @throws InvalidDataTypeException
552
+	 * @throws InvalidInterfaceException
553
+	 */
554
+	final protected function _page_setup()
555
+	{
556
+		// requires?
557
+		// admin_init stuff - global - we're setting this REALLY early
558
+		// so if EE_Admin pages have to hook into other WP pages they can.
559
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
560
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
561
+		// next verify if we need to load anything...
562
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
563
+		$this->page_folder = strtolower(
564
+			str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
565
+		);
566
+		global $ee_menu_slugs;
567
+		$ee_menu_slugs = (array) $ee_menu_slugs;
568
+		if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
569
+			return;
570
+		}
571
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
572
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
573
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
574
+				? $this->_req_data['action2']
575
+				: $this->_req_data['action'];
576
+		}
577
+		// then set blank or -1 action values to 'default'
578
+		$this->_req_action = isset($this->_req_data['action'])
579
+							 && ! empty($this->_req_data['action'])
580
+							 && $this->_req_data['action'] !== '-1'
581
+			? sanitize_key($this->_req_data['action'])
582
+			: 'default';
583
+		// if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
584
+		//  This covers cases where we're coming in from a list table that isn't on the default route.
585
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
586
+			? $this->_req_data['route'] : $this->_req_action;
587
+		// however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
588
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
589
+			? $this->_req_data['route']
590
+			: $this->_req_action;
591
+		$this->_current_view = $this->_req_action;
592
+		$this->_req_nonce = $this->_req_action . '_nonce';
593
+		$this->_define_page_props();
594
+		$this->_current_page_view_url = add_query_arg(
595
+			array('page' => $this->_current_page, 'action' => $this->_current_view),
596
+			$this->_admin_base_url
597
+		);
598
+		// default things
599
+		$this->_default_espresso_metaboxes = array(
600
+			'_espresso_news_post_box',
601
+			'_espresso_links_post_box',
602
+			'_espresso_ratings_request',
603
+			'_espresso_sponsors_post_box',
604
+		);
605
+		// set page configs
606
+		$this->_set_page_routes();
607
+		$this->_set_page_config();
608
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
609
+		if (isset($this->_req_data['wp_referer'])) {
610
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
611
+		}
612
+		// for caffeinated and other extended functionality.
613
+		//  If there is a _extend_page_config method
614
+		// then let's run that to modify the all the various page configuration arrays
615
+		if (method_exists($this, '_extend_page_config')) {
616
+			$this->_extend_page_config();
617
+		}
618
+		// for CPT and other extended functionality.
619
+		// If there is an _extend_page_config_for_cpt
620
+		// then let's run that to modify all the various page configuration arrays.
621
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
622
+			$this->_extend_page_config_for_cpt();
623
+		}
624
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
625
+		$this->_page_routes = apply_filters(
626
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
627
+			$this->_page_routes,
628
+			$this
629
+		);
630
+		$this->_page_config = apply_filters(
631
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
632
+			$this->_page_config,
633
+			$this
634
+		);
635
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
636
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
637
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
638
+			add_action(
639
+				'AHEE__EE_Admin_Page__route_admin_request',
640
+				array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
641
+				10,
642
+				2
643
+			);
644
+		}
645
+		// next route only if routing enabled
646
+		if ($this->_routing && ! defined('DOING_AJAX')) {
647
+			$this->_verify_routes();
648
+			// next let's just check user_access and kill if no access
649
+			$this->check_user_access();
650
+			if ($this->_is_UI_request) {
651
+				// admin_init stuff - global, all views for this page class, specific view
652
+				add_action('admin_init', array($this, 'admin_init'), 10);
653
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
654
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
655
+				}
656
+			} else {
657
+				// hijack regular WP loading and route admin request immediately
658
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
659
+				$this->route_admin_request();
660
+			}
661
+		}
662
+	}
663
+
664
+
665
+	/**
666
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
667
+	 *
668
+	 * @return void
669
+	 * @throws EE_Error
670
+	 */
671
+	private function _do_other_page_hooks()
672
+	{
673
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
674
+		foreach ($registered_pages as $page) {
675
+			// now let's setup the file name and class that should be present
676
+			$classname = str_replace('.class.php', '', $page);
677
+			// autoloaders should take care of loading file
678
+			if (! class_exists($classname)) {
679
+				$error_msg[] = sprintf(
680
+					esc_html__(
681
+						'Something went wrong with loading the %s admin hooks page.',
682
+						'event_espresso'
683
+					),
684
+					$page
685
+				);
686
+				$error_msg[] = $error_msg[0]
687
+							   . "\r\n"
688
+							   . sprintf(
689
+								   esc_html__(
690
+									   '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',
691
+									   'event_espresso'
692
+								   ),
693
+								   $page,
694
+								   '<br />',
695
+								   '<strong>' . $classname . '</strong>'
696
+							   );
697
+				throw new EE_Error(implode('||', $error_msg));
698
+			}
699
+			// // notice we are passing the instance of this class to the hook object.
700
+			$this->loader->getShared($classname, [$this]);
701
+		}
702
+	}
703
+
704
+
705
+	/**
706
+	 * @throws DomainException
707
+	 * @throws EE_Error
708
+	 * @throws InvalidArgumentException
709
+	 * @throws InvalidDataTypeException
710
+	 * @throws InvalidInterfaceException
711
+	 * @throws ReflectionException
712
+	 * @since $VID:$
713
+	 */
714
+	public function load_page_dependencies()
715
+	{
716
+		try {
717
+			$this->_load_page_dependencies();
718
+		} catch (EE_Error $e) {
719
+			$e->get_error();
720
+		}
721
+	}
722
+
723
+
724
+	/**
725
+	 * load_page_dependencies
726
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
727
+	 *
728
+	 * @return void
729
+	 * @throws DomainException
730
+	 * @throws EE_Error
731
+	 * @throws InvalidArgumentException
732
+	 * @throws InvalidDataTypeException
733
+	 * @throws InvalidInterfaceException
734
+	 * @throws ReflectionException
735
+	 */
736
+	protected function _load_page_dependencies()
737
+	{
738
+		// let's set the current_screen and screen options to override what WP set
739
+		$this->_current_screen = get_current_screen();
740
+		// load admin_notices - global, page class, and view specific
741
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
742
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
743
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
744
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
745
+		}
746
+		// load network admin_notices - global, page class, and view specific
747
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
748
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
749
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
750
+		}
751
+		// this will save any per_page screen options if they are present
752
+		$this->_set_per_page_screen_options();
753
+		// setup list table properties
754
+		$this->_set_list_table();
755
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
756
+		// However in some cases the metaboxes will need to be added within a route handling callback.
757
+		$this->_add_registered_meta_boxes();
758
+		$this->_add_screen_columns();
759
+		// add screen options - global, page child class, and view specific
760
+		$this->_add_global_screen_options();
761
+		$this->_add_screen_options();
762
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
763
+		if (method_exists($this, $add_screen_options)) {
764
+			$this->{$add_screen_options}();
765
+		}
766
+		// add help tab(s) and tours- set via page_config and qtips.
767
+		// $this->_add_help_tour();
768
+		$this->_add_help_tabs();
769
+		$this->_add_qtips();
770
+		// add feature_pointers - global, page child class, and view specific
771
+		$this->_add_feature_pointers();
772
+		$this->_add_global_feature_pointers();
773
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
774
+		if (method_exists($this, $add_feature_pointer)) {
775
+			$this->{$add_feature_pointer}();
776
+		}
777
+		// enqueue scripts/styles - global, page class, and view specific
778
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
779
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
780
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
781
+			add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
782
+		}
783
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
784
+		// admin_print_footer_scripts - global, page child class, and view specific.
785
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
786
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
787
+		// is a good use case. Notice the late priority we're giving these
788
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
789
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
790
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
791
+			add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
792
+		}
793
+		// admin footer scripts
794
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
795
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
796
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
797
+			add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
798
+		}
799
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
800
+		// targeted hook
801
+		do_action(
802
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
803
+		);
804
+	}
805
+
806
+
807
+	/**
808
+	 * _set_defaults
809
+	 * This sets some global defaults for class properties.
810
+	 */
811
+	private function _set_defaults()
812
+	{
813
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
814
+		$this->_event = $this->_template_path = $this->_column_template_path = null;
815
+		$this->_nav_tabs = $this->_views = $this->_page_routes = array();
816
+		$this->_page_config = $this->_default_route_query_args = array();
817
+		$this->_default_nav_tab_name = 'overview';
818
+		// init template args
819
+		$this->_template_args = array(
820
+			'admin_page_header'  => '',
821
+			'admin_page_content' => '',
822
+			'post_body_content'  => '',
823
+			'before_list_table'  => '',
824
+			'after_list_table'   => '',
825
+		);
826
+	}
827
+
828
+
829
+	/**
830
+	 * route_admin_request
831
+	 *
832
+	 * @see    _route_admin_request()
833
+	 * @return exception|void error
834
+	 * @throws InvalidArgumentException
835
+	 * @throws InvalidInterfaceException
836
+	 * @throws InvalidDataTypeException
837
+	 * @throws EE_Error
838
+	 * @throws ReflectionException
839
+	 */
840
+	public function route_admin_request()
841
+	{
842
+		try {
843
+			$this->_route_admin_request();
844
+		} catch (EE_Error $e) {
845
+			$e->get_error();
846
+		}
847
+	}
848
+
849
+
850
+	public function set_wp_page_slug($wp_page_slug)
851
+	{
852
+		$this->_wp_page_slug = $wp_page_slug;
853
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
854
+		if (is_network_admin()) {
855
+			$this->_wp_page_slug .= '-network';
856
+		}
857
+	}
858
+
859
+
860
+	/**
861
+	 * _verify_routes
862
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
863
+	 * we know if we need to drop out.
864
+	 *
865
+	 * @return bool
866
+	 * @throws EE_Error
867
+	 */
868
+	protected function _verify_routes()
869
+	{
870
+		if (! $this->_current_page && ! defined('DOING_AJAX')) {
871
+			return false;
872
+		}
873
+		$this->_route = false;
874
+		// check that the page_routes array is not empty
875
+		if (empty($this->_page_routes)) {
876
+			// user error msg
877
+			$error_msg = sprintf(
878
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
879
+				$this->_admin_page_title
880
+			);
881
+			// developer error msg
882
+			$error_msg .= '||' . $error_msg
883
+						  . esc_html__(
884
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
885
+							  'event_espresso'
886
+						  );
887
+			throw new EE_Error($error_msg);
888
+		}
889
+		// and that the requested page route exists
890
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
891
+			$this->_route = $this->_page_routes[ $this->_req_action ];
892
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
893
+				? $this->_page_config[ $this->_req_action ] : array();
894
+		} else {
895
+			// user error msg
896
+			$error_msg = sprintf(
897
+				esc_html__(
898
+					'The requested page route does not exist for the %s admin page.',
899
+					'event_espresso'
900
+				),
901
+				$this->_admin_page_title
902
+			);
903
+			// developer error msg
904
+			$error_msg .= '||' . $error_msg
905
+						  . sprintf(
906
+							  esc_html__(
907
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
908
+								  'event_espresso'
909
+							  ),
910
+							  $this->_req_action
911
+						  );
912
+			throw new EE_Error($error_msg);
913
+		}
914
+		// and that a default route exists
915
+		if (! array_key_exists('default', $this->_page_routes)) {
916
+			// user error msg
917
+			$error_msg = sprintf(
918
+				esc_html__(
919
+					'A default page route has not been set for the % admin page.',
920
+					'event_espresso'
921
+				),
922
+				$this->_admin_page_title
923
+			);
924
+			// developer error msg
925
+			$error_msg .= '||' . $error_msg
926
+						  . esc_html__(
927
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
928
+							  'event_espresso'
929
+						  );
930
+			throw new EE_Error($error_msg);
931
+		}
932
+
933
+		// first lets' catch if the UI request has EVER been set.
934
+		if ($this->_is_UI_request === null) {
935
+			// lets set if this is a UI request or not.
936
+			$this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
937
+			// wait a minute... we might have a noheader in the route array
938
+			$this->_is_UI_request = is_array($this->_route)
939
+									&& isset($this->_route['noheader'])
940
+									&& $this->_route['noheader'] ? false : $this->_is_UI_request;
941
+		}
942
+		$this->_set_current_labels();
943
+		return true;
944
+	}
945
+
946
+
947
+	/**
948
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
949
+	 *
950
+	 * @param  string $route the route name we're verifying
951
+	 * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
952
+	 * @throws EE_Error
953
+	 */
954
+	protected function _verify_route($route)
955
+	{
956
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
957
+			return true;
958
+		}
959
+		// user error msg
960
+		$error_msg = sprintf(
961
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
962
+			$this->_admin_page_title
963
+		);
964
+		// developer error msg
965
+		$error_msg .= '||' . $error_msg
966
+					  . sprintf(
967
+						  esc_html__(
968
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
969
+							  'event_espresso'
970
+						  ),
971
+						  $route
972
+					  );
973
+		throw new EE_Error($error_msg);
974
+	}
975
+
976
+
977
+	/**
978
+	 * perform nonce verification
979
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
980
+	 * using this method (and save retyping!)
981
+	 *
982
+	 * @param string $nonce     The nonce sent
983
+	 * @param string $nonce_ref The nonce reference string (name0)
984
+	 * @return void
985
+	 * @throws EE_Error
986
+	 * @throws InvalidArgumentException
987
+	 * @throws InvalidDataTypeException
988
+	 * @throws InvalidInterfaceException
989
+	 */
990
+	protected function _verify_nonce($nonce, $nonce_ref)
991
+	{
992
+		// verify nonce against expected value
993
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
994
+			// these are not the droids you are looking for !!!
995
+			$msg = sprintf(
996
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
997
+				'<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
998
+				'</a>'
999
+			);
1000
+			if (WP_DEBUG) {
1001
+				$msg .= "\n  "
1002
+						. sprintf(
1003
+							esc_html__(
1004
+								'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1005
+								'event_espresso'
1006
+							),
1007
+							EE_Admin_Page::class
1008
+						);
1009
+			}
1010
+			if (! defined('DOING_AJAX')) {
1011
+				wp_die($msg);
1012
+			} else {
1013
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1014
+				$this->_return_json();
1015
+			}
1016
+		}
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * _route_admin_request()
1022
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1023
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1024
+	 * in the page routes and then will try to load the corresponding method.
1025
+	 *
1026
+	 * @return void
1027
+	 * @throws EE_Error
1028
+	 * @throws InvalidArgumentException
1029
+	 * @throws InvalidDataTypeException
1030
+	 * @throws InvalidInterfaceException
1031
+	 * @throws ReflectionException
1032
+	 */
1033
+	protected function _route_admin_request()
1034
+	{
1035
+		if (! $this->_is_UI_request) {
1036
+			$this->_verify_routes();
1037
+		}
1038
+		$nonce_check = isset($this->_route_config['require_nonce'])
1039
+			? $this->_route_config['require_nonce']
1040
+			: true;
1041
+		if ($this->_req_action !== 'default' && $nonce_check) {
1042
+			// set nonce from post data
1043
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
1044
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
1045
+				: '';
1046
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1047
+		}
1048
+		// set the nav_tabs array but ONLY if this is  UI_request
1049
+		if ($this->_is_UI_request) {
1050
+			$this->_set_nav_tabs();
1051
+		}
1052
+		// grab callback function
1053
+		$func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1054
+		// check if callback has args
1055
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1056
+		$error_msg = '';
1057
+		// action right before calling route
1058
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1059
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1060
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1061
+		}
1062
+		// right before calling the route, let's remove _wp_http_referer from the
1063
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1064
+		$_SERVER['REQUEST_URI'] = remove_query_arg(
1065
+			'_wp_http_referer',
1066
+			wp_unslash($_SERVER['REQUEST_URI'])
1067
+		);
1068
+		if (! empty($func)) {
1069
+			if (is_array($func)) {
1070
+				list($class, $method) = $func;
1071
+			} elseif (strpos($func, '::') !== false) {
1072
+				list($class, $method) = explode('::', $func);
1073
+			} else {
1074
+				$class = $this;
1075
+				$method = $func;
1076
+			}
1077
+			if (! (is_object($class) && $class === $this)) {
1078
+				// send along this admin page object for access by addons.
1079
+				$args['admin_page_object'] = $this;
1080
+			}
1081
+			// is it a method on a class that doesn't work?
1082
+			if (
1083
+				((method_exists($class, $method)
1084
+				  && call_user_func_array(array($class, $method), $args) === false)
1085
+				 && (// is it a standalone function that doesn't work?
1086
+					 function_exists($method)
1087
+					 && call_user_func_array(
1088
+						 $func,
1089
+						 array_merge(array('admin_page_object' => $this), $args)
1090
+					 ) === false
1091
+				 )) || (// is it neither a class method NOR a standalone function?
1092
+					! function_exists($method)
1093
+					&& ! method_exists($class, $method)
1094
+				)
1095
+			) {
1096
+				// user error msg
1097
+				$error_msg = esc_html__(
1098
+					'An error occurred. The  requested page route could not be found.',
1099
+					'event_espresso'
1100
+				);
1101
+				// developer error msg
1102
+				$error_msg .= '||';
1103
+				$error_msg .= sprintf(
1104
+					esc_html__(
1105
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1106
+						'event_espresso'
1107
+					),
1108
+					$method
1109
+				);
1110
+			}
1111
+			if (! empty($error_msg)) {
1112
+				throw new EE_Error($error_msg);
1113
+			}
1114
+		}
1115
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1116
+		// then we need to reset the routing properties to the new route.
1117
+		// 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.
1118
+		if (
1119
+			$this->_is_UI_request === false
1120
+			&& is_array($this->_route)
1121
+			&& ! empty($this->_route['headers_sent_route'])
1122
+		) {
1123
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1124
+		}
1125
+	}
1126
+
1127
+
1128
+	/**
1129
+	 * This method just allows the resetting of page properties in the case where a no headers
1130
+	 * route redirects to a headers route in its route config.
1131
+	 *
1132
+	 * @since   4.3.0
1133
+	 * @param  string $new_route New (non header) route to redirect to.
1134
+	 * @return   void
1135
+	 * @throws ReflectionException
1136
+	 * @throws InvalidArgumentException
1137
+	 * @throws InvalidInterfaceException
1138
+	 * @throws InvalidDataTypeException
1139
+	 * @throws EE_Error
1140
+	 */
1141
+	protected function _reset_routing_properties($new_route)
1142
+	{
1143
+		$this->_is_UI_request = true;
1144
+		// now we set the current route to whatever the headers_sent_route is set at
1145
+		$this->_req_data['action'] = $new_route;
1146
+		// rerun page setup
1147
+		$this->_page_setup();
1148
+	}
1149
+
1150
+
1151
+	/**
1152
+	 * _add_query_arg
1153
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1154
+	 *(internally just uses EEH_URL's function with the same name)
1155
+	 *
1156
+	 * @param array  $args
1157
+	 * @param string $url
1158
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1159
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1160
+	 *                                        Example usage: If the current page is:
1161
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1162
+	 *                                        &action=default&event_id=20&month_range=March%202015
1163
+	 *                                        &_wpnonce=5467821
1164
+	 *                                        and you call:
1165
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1166
+	 *                                        array(
1167
+	 *                                        'action' => 'resend_something',
1168
+	 *                                        'page=>espresso_registrations'
1169
+	 *                                        ),
1170
+	 *                                        $some_url,
1171
+	 *                                        true
1172
+	 *                                        );
1173
+	 *                                        It will produce a url in this structure:
1174
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1175
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1176
+	 *                                        month_range]=March%202015
1177
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1178
+	 * @return string
1179
+	 */
1180
+	public static function add_query_args_and_nonce(
1181
+		$args = array(),
1182
+		$url = '',
1183
+		$sticky = false,
1184
+		$exclude_nonce = false
1185
+	) {
1186
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1187
+		if ($sticky) {
1188
+			$request = $_REQUEST;
1189
+			unset($request['_wp_http_referer'], $request['wp_referer']);
1190
+			foreach ($request as $key => $value) {
1191
+				// do not add nonces
1192
+				if (strpos($key, 'nonce') !== false) {
1193
+					continue;
1194
+				}
1195
+				$args[ 'wp_referer[' . $key . ']' ] = $value;
1196
+			}
1197
+		}
1198
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * This returns a generated link that will load the related help tab.
1204
+	 *
1205
+	 * @param  string $help_tab_id the id for the connected help tab
1206
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1207
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1208
+	 * @uses EEH_Template::get_help_tab_link()
1209
+	 * @return string              generated link
1210
+	 */
1211
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1212
+	{
1213
+		return EEH_Template::get_help_tab_link(
1214
+			$help_tab_id,
1215
+			$this->page_slug,
1216
+			$this->_req_action,
1217
+			$icon_style,
1218
+			$help_text
1219
+		);
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * _add_help_tabs
1225
+	 * Note child classes define their help tabs within the page_config array.
1226
+	 *
1227
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1228
+	 * @return void
1229
+	 * @throws DomainException
1230
+	 * @throws EE_Error
1231
+	 * @throws ReflectionException
1232
+	 */
1233
+	protected function _add_help_tabs()
1234
+	{
1235
+		$tour_buttons = '';
1236
+		if (isset($this->_page_config[ $this->_req_action ])) {
1237
+			$config = $this->_page_config[ $this->_req_action ];
1238
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1239
+			// is there a help tour for the current route?  if there is let's setup the tour buttons
1240
+			// if (isset($this->_help_tour[ $this->_req_action ])) {
1241
+			//     $tb = array();
1242
+			//     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1243
+			//     foreach ($this->_help_tour['tours'] as $tour) {
1244
+			//         // if this is the end tour then we don't need to setup a button
1245
+			//         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1246
+			//             continue;
1247
+			//         }
1248
+			//         $tb[] = '<button id="trigger-tour-'
1249
+			//                 . $tour->get_slug()
1250
+			//                 . '" class="button-primary trigger-ee-help-tour">'
1251
+			//                 . $tour->get_label()
1252
+			//                 . '</button>';
1253
+			//     }
1254
+			//     $tour_buttons .= implode('<br />', $tb);
1255
+			//     $tour_buttons .= '</div></div>';
1256
+			// }
1257
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1258
+			if (is_array($config) && isset($config['help_sidebar'])) {
1259
+				// check that the callback given is valid
1260
+				if (! method_exists($this, $config['help_sidebar'])) {
1261
+					throw new EE_Error(
1262
+						sprintf(
1263
+							esc_html__(
1264
+								'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',
1265
+								'event_espresso'
1266
+							),
1267
+							$config['help_sidebar'],
1268
+							get_class($this)
1269
+						)
1270
+					);
1271
+				}
1272
+				$content = apply_filters(
1273
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1274
+					$this->{$config['help_sidebar']}()
1275
+				);
1276
+				$content .= $tour_buttons; // add help tour buttons.
1277
+				// do we have any help tours setup?  Cause if we do we want to add the buttons
1278
+				$this->_current_screen->set_help_sidebar($content);
1279
+			}
1280
+			// if there ARE tour buttons...
1281
+			if (! empty($tour_buttons)) {
1282
+				// if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar.
1283
+				if (! isset($config['help_sidebar'])) {
1284
+					$this->_current_screen->set_help_sidebar($tour_buttons);
1285
+				}
1286
+				// handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1287
+				if (! isset($config['help_tabs'])) {
1288
+					$_ht['id'] = $this->page_slug;
1289
+					$_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1290
+					$_ht['content'] = '<p>'
1291
+									  . esc_html__(
1292
+										  'The buttons to the right allow you to start/restart any help tours available for this page',
1293
+										  'event_espresso'
1294
+									  ) . '</p>';
1295
+					$this->_current_screen->add_help_tab($_ht);
1296
+				}
1297
+			}
1298
+			if (! isset($config['help_tabs'])) {
1299
+				return;
1300
+			} //no help tabs for this route
1301
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1302
+				// we're here so there ARE help tabs!
1303
+				// make sure we've got what we need
1304
+				if (! isset($cfg['title'])) {
1305
+					throw new EE_Error(
1306
+						esc_html__(
1307
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1308
+							'event_espresso'
1309
+						)
1310
+					);
1311
+				}
1312
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1313
+					throw new EE_Error(
1314
+						esc_html__(
1315
+							'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',
1316
+							'event_espresso'
1317
+						)
1318
+					);
1319
+				}
1320
+				// first priority goes to content.
1321
+				if (! empty($cfg['content'])) {
1322
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1323
+					// second priority goes to filename
1324
+				} elseif (! empty($cfg['filename'])) {
1325
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1326
+					// 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)
1327
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1328
+															 . basename($this->_get_dir())
1329
+															 . '/help_tabs/'
1330
+															 . $cfg['filename']
1331
+															 . '.help_tab.php' : $file_path;
1332
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1333
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1334
+						EE_Error::add_error(
1335
+							sprintf(
1336
+								esc_html__(
1337
+									'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',
1338
+									'event_espresso'
1339
+								),
1340
+								$tab_id,
1341
+								key($config),
1342
+								$file_path
1343
+							),
1344
+							__FILE__,
1345
+							__FUNCTION__,
1346
+							__LINE__
1347
+						);
1348
+						return;
1349
+					}
1350
+					$template_args['admin_page_obj'] = $this;
1351
+					$content = EEH_Template::display_template(
1352
+						$file_path,
1353
+						$template_args,
1354
+						true
1355
+					);
1356
+				} else {
1357
+					$content = '';
1358
+				}
1359
+				// check if callback is valid
1360
+				if (
1361
+					empty($content) && (
1362
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1363
+					)
1364
+				) {
1365
+					EE_Error::add_error(
1366
+						sprintf(
1367
+							esc_html__(
1368
+								'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.',
1369
+								'event_espresso'
1370
+							),
1371
+							$cfg['title']
1372
+						),
1373
+						__FILE__,
1374
+						__FUNCTION__,
1375
+						__LINE__
1376
+					);
1377
+					return;
1378
+				}
1379
+				// setup config array for help tab method
1380
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1381
+				$_ht = array(
1382
+					'id'       => $id,
1383
+					'title'    => $cfg['title'],
1384
+					'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1385
+					'content'  => $content,
1386
+				);
1387
+				$this->_current_screen->add_help_tab($_ht);
1388
+			}
1389
+		}
1390
+	}
1391
+
1392
+
1393
+	/**
1394
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1395
+	 * an array with properties for setting up usage of the joyride plugin
1396
+	 *
1397
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1398
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1399
+	 *         _set_page_config() comments
1400
+	 * @return void
1401
+	 * @throws EE_Error
1402
+	 * @throws InvalidArgumentException
1403
+	 * @throws InvalidDataTypeException
1404
+	 * @throws InvalidInterfaceException
1405
+	 * @throws ReflectionException
1406
+	 */
1407
+	protected function _add_help_tour()
1408
+	{
1409
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1410
+		// $tours = array();
1411
+		// $this->_help_tour = array();
1412
+		// // exit early if help tours are turned off globally
1413
+		// if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1414
+		//     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1415
+		// ) {
1416
+		//     return;
1417
+		// }
1418
+		// // loop through _page_config to find any help_tour defined
1419
+		// foreach ($this->_page_config as $route => $config) {
1420
+		//     // we're only going to set things up for this route
1421
+		//     if ($route !== $this->_req_action) {
1422
+		//         continue;
1423
+		//     }
1424
+		//     if (isset($config['help_tour'])) {
1425
+		//         foreach ($config['help_tour'] as $tour) {
1426
+		//             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1427
+		//             // let's see if we can get that file...
1428
+		//             // if not its possible this is a decaf route not set in caffeinated
1429
+		//             // so lets try and get the caffeinated equivalent
1430
+		//             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1431
+		//                                                      . basename($this->_get_dir())
1432
+		//                                                      . '/help_tours/'
1433
+		//                                                      . $tour
1434
+		//                                                      . '.class.php' : $file_path;
1435
+		//             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1436
+		//             if (! is_readable($file_path)) {
1437
+		//                 EE_Error::add_error(
1438
+		//                     sprintf(
1439
+		//                         esc_html__(
1440
+		//                             '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',
1441
+		//                             'event_espresso'
1442
+		//                         ),
1443
+		//                         $file_path,
1444
+		//                         $tour
1445
+		//                     ),
1446
+		//                     __FILE__,
1447
+		//                     __FUNCTION__,
1448
+		//                     __LINE__
1449
+		//                 );
1450
+		//                 return;
1451
+		//             }
1452
+		//             require_once $file_path;
1453
+		//             if (! class_exists($tour)) {
1454
+		//                 $error_msg[] = sprintf(
1455
+		//                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1456
+		//                     $tour
1457
+		//                 );
1458
+		//                 $error_msg[] = $error_msg[0] . "\r\n"
1459
+		//                                . sprintf(
1460
+		//                                    esc_html__(
1461
+		//                                        '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.',
1462
+		//                                        'event_espresso'
1463
+		//                                    ),
1464
+		//                                    $tour,
1465
+		//                                    '<br />',
1466
+		//                                    $tour,
1467
+		//                                    $this->_req_action,
1468
+		//                                    get_class($this)
1469
+		//                                );
1470
+		//                 throw new EE_Error(implode('||', $error_msg));
1471
+		//             }
1472
+		//             $tour_obj = new $tour($this->_is_caf);
1473
+		//             $tours[] = $tour_obj;
1474
+		//             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1475
+		//         }
1476
+		//         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1477
+		//         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1478
+		//         $tours[] = $end_stop_tour;
1479
+		//         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1480
+		//     }
1481
+		// }
1482
+		//
1483
+		// if (! empty($tours)) {
1484
+		//     $this->_help_tour['tours'] = $tours;
1485
+		// }
1486
+		// // that's it!  Now that the $_help_tours property is set (or not)
1487
+		// // the scripts and html should be taken care of automatically.
1488
+		//
1489
+		// /**
1490
+		//  * Allow extending the help tours variable.
1491
+		//  *
1492
+		//  * @param Array $_help_tour The array containing all help tour information to be displayed.
1493
+		//  */
1494
+		// $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1495
+	}
1496
+
1497
+
1498
+	/**
1499
+	 * This simply sets up any qtips that have been defined in the page config
1500
+	 *
1501
+	 * @return void
1502
+	 * @throws ReflectionException
1503
+	 * @throws EE_Error
1504
+	 */
1505
+	protected function _add_qtips()
1506
+	{
1507
+		if (isset($this->_route_config['qtips'])) {
1508
+			$qtips = (array) $this->_route_config['qtips'];
1509
+			// load qtip loader
1510
+			$path = array(
1511
+				$this->_get_dir() . '/qtips/',
1512
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1513
+			);
1514
+			$qtip_loader = EEH_Qtip_Loader::instance();
1515
+			if ($qtip_loader instanceof EEH_Qtip_Loader) {
1516
+				$qtip_loader->register($qtips, $path);
1517
+			}
1518
+		}
1519
+	}
1520
+
1521
+
1522
+	/**
1523
+	 * _set_nav_tabs
1524
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1525
+	 * wish to add additional tabs or modify accordingly.
1526
+	 *
1527
+	 * @return void
1528
+	 * @throws InvalidArgumentException
1529
+	 * @throws InvalidInterfaceException
1530
+	 * @throws InvalidDataTypeException
1531
+	 */
1532
+	protected function _set_nav_tabs()
1533
+	{
1534
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1535
+		$i = 0;
1536
+		foreach ($this->_page_config as $slug => $config) {
1537
+			if (
1538
+				! is_array($config)
1539
+				|| (
1540
+					is_array($config)
1541
+					&& (
1542
+						(isset($config['nav']) && ! $config['nav'])
1543
+						|| ! isset($config['nav'])
1544
+					)
1545
+				)
1546
+			) {
1547
+				continue;
1548
+			}
1549
+			// no nav tab for this config
1550
+			// check for persistent flag
1551
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1552
+				// nav tab is only to appear when route requested.
1553
+				continue;
1554
+			}
1555
+			if (! $this->check_user_access($slug, true)) {
1556
+				// no nav tab because current user does not have access.
1557
+				continue;
1558
+			}
1559
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1560
+			$this->_nav_tabs[ $slug ] = array(
1561
+				'url'       => isset($config['nav']['url'])
1562
+					? $config['nav']['url']
1563
+					: EE_Admin_Page::add_query_args_and_nonce(
1564
+						array('action' => $slug),
1565
+						$this->_admin_base_url
1566
+					),
1567
+				'link_text' => isset($config['nav']['label'])
1568
+					? $config['nav']['label']
1569
+					: ucwords(
1570
+						str_replace('_', ' ', $slug)
1571
+					),
1572
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1573
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1574
+			);
1575
+			$i++;
1576
+		}
1577
+		// if $this->_nav_tabs is empty then lets set the default
1578
+		if (empty($this->_nav_tabs)) {
1579
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1580
+				'url'       => $this->_admin_base_url,
1581
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1582
+				'css_class' => 'nav-tab-active',
1583
+				'order'     => 10,
1584
+			);
1585
+		}
1586
+		// now let's sort the tabs according to order
1587
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1588
+	}
1589
+
1590
+
1591
+	/**
1592
+	 * _set_current_labels
1593
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1594
+	 * property array
1595
+	 *
1596
+	 * @return void
1597
+	 */
1598
+	private function _set_current_labels()
1599
+	{
1600
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1601
+			foreach ($this->_route_config['labels'] as $label => $text) {
1602
+				if (is_array($text)) {
1603
+					foreach ($text as $sublabel => $subtext) {
1604
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1605
+					}
1606
+				} else {
1607
+					$this->_labels[ $label ] = $text;
1608
+				}
1609
+			}
1610
+		}
1611
+	}
1612
+
1613
+
1614
+	/**
1615
+	 *        verifies user access for this admin page
1616
+	 *
1617
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1618
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1619
+	 *                               return false if verify fail.
1620
+	 * @return bool
1621
+	 * @throws InvalidArgumentException
1622
+	 * @throws InvalidDataTypeException
1623
+	 * @throws InvalidInterfaceException
1624
+	 */
1625
+	public function check_user_access($route_to_check = '', $verify_only = false)
1626
+	{
1627
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1628
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1629
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1630
+					  && is_array(
1631
+						  $this->_page_routes[ $route_to_check ]
1632
+					  )
1633
+					  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1634
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1635
+		if (empty($capability) && empty($route_to_check)) {
1636
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1637
+				: $this->_route['capability'];
1638
+		} else {
1639
+			$capability = empty($capability) ? 'manage_options' : $capability;
1640
+		}
1641
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1642
+		if (
1643
+			! defined('DOING_AJAX')
1644
+			&& (
1645
+				! function_exists('is_admin')
1646
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1647
+					$capability,
1648
+					$this->page_slug
1649
+					. '_'
1650
+					. $route_to_check,
1651
+					$id
1652
+				)
1653
+			)
1654
+		) {
1655
+			if ($verify_only) {
1656
+				return false;
1657
+			}
1658
+			if (is_user_logged_in()) {
1659
+				wp_die(__('You do not have access to this route.', 'event_espresso'));
1660
+			} else {
1661
+				return false;
1662
+			}
1663
+		}
1664
+		return true;
1665
+	}
1666
+
1667
+
1668
+	/**
1669
+	 * admin_init_global
1670
+	 * This runs all the code that we want executed within the WP admin_init hook.
1671
+	 * This method executes for ALL EE Admin pages.
1672
+	 *
1673
+	 * @return void
1674
+	 */
1675
+	public function admin_init_global()
1676
+	{
1677
+	}
1678
+
1679
+
1680
+	/**
1681
+	 * wp_loaded_global
1682
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1683
+	 * EE_Admin page and will execute on every EE Admin Page load
1684
+	 *
1685
+	 * @return void
1686
+	 */
1687
+	public function wp_loaded()
1688
+	{
1689
+	}
1690
+
1691
+
1692
+	/**
1693
+	 * admin_notices
1694
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1695
+	 * ALL EE_Admin pages.
1696
+	 *
1697
+	 * @return void
1698
+	 */
1699
+	public function admin_notices_global()
1700
+	{
1701
+		$this->_display_no_javascript_warning();
1702
+		$this->_display_espresso_notices();
1703
+	}
1704
+
1705
+
1706
+	public function network_admin_notices_global()
1707
+	{
1708
+		$this->_display_no_javascript_warning();
1709
+		$this->_display_espresso_notices();
1710
+	}
1711
+
1712
+
1713
+	/**
1714
+	 * admin_footer_scripts_global
1715
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1716
+	 * will apply on ALL EE_Admin pages.
1717
+	 *
1718
+	 * @return void
1719
+	 */
1720
+	public function admin_footer_scripts_global()
1721
+	{
1722
+		$this->_add_admin_page_ajax_loading_img();
1723
+		$this->_add_admin_page_overlay();
1724
+		// if metaboxes are present we need to add the nonce field
1725
+		if (
1726
+			isset($this->_route_config['metaboxes'])
1727
+			|| isset($this->_route_config['list_table'])
1728
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1729
+		) {
1730
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1731
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1732
+		}
1733
+	}
1734
+
1735
+
1736
+	/**
1737
+	 * admin_footer_global
1738
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1739
+	 * This particular method will apply on ALL EE_Admin Pages.
1740
+	 *
1741
+	 * @return void
1742
+	 * @throws InvalidArgumentException
1743
+	 * @throws InvalidDataTypeException
1744
+	 * @throws InvalidInterfaceException
1745
+	 */
1746
+	public function admin_footer_global()
1747
+	{
1748
+		// dialog container for dialog helper
1749
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1750
+		$d_cont .= '<div class="ee-notices"></div>';
1751
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1752
+		$d_cont .= '</div>';
1753
+		echo $d_cont;
1754
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1755
+		// help tour stuff?
1756
+		// if (isset($this->_help_tour[ $this->_req_action ])) {
1757
+		//     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1758
+		// }
1759
+		// current set timezone for timezone js
1760
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1761
+	}
1762
+
1763
+
1764
+	/**
1765
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1766
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1767
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1768
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1769
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1770
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1771
+	 * for the
1772
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1773
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1774
+	 *    'help_trigger_id' => array(
1775
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1776
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1777
+	 *    )
1778
+	 * );
1779
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1780
+	 *
1781
+	 * @param array $help_array
1782
+	 * @param bool  $display
1783
+	 * @return string content
1784
+	 * @throws DomainException
1785
+	 * @throws EE_Error
1786
+	 */
1787
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1788
+	{
1789
+		$content = '';
1790
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1791
+		// loop through the array and setup content
1792
+		foreach ($help_array as $trigger => $help) {
1793
+			// make sure the array is setup properly
1794
+			if (! isset($help['title'], $help['content'])) {
1795
+				throw new EE_Error(
1796
+					esc_html__(
1797
+						'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',
1798
+						'event_espresso'
1799
+					)
1800
+				);
1801
+			}
1802
+			// we're good so let'd setup the template vars and then assign parsed template content to our content.
1803
+			$template_args = array(
1804
+				'help_popup_id'      => $trigger,
1805
+				'help_popup_title'   => $help['title'],
1806
+				'help_popup_content' => $help['content'],
1807
+			);
1808
+			$content .= EEH_Template::display_template(
1809
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1810
+				$template_args,
1811
+				true
1812
+			);
1813
+		}
1814
+		if ($display) {
1815
+			echo $content;
1816
+			return '';
1817
+		}
1818
+		return $content;
1819
+	}
1820
+
1821
+
1822
+	/**
1823
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1824
+	 *
1825
+	 * @return array properly formatted array for help popup content
1826
+	 * @throws EE_Error
1827
+	 */
1828
+	private function _get_help_content()
1829
+	{
1830
+		// what is the method we're looking for?
1831
+		$method_name = '_help_popup_content_' . $this->_req_action;
1832
+		// if method doesn't exist let's get out.
1833
+		if (! method_exists($this, $method_name)) {
1834
+			return array();
1835
+		}
1836
+		// k we're good to go let's retrieve the help array
1837
+		$help_array = $this->{$method_name}();
1838
+		// make sure we've got an array!
1839
+		if (! is_array($help_array)) {
1840
+			throw new EE_Error(
1841
+				esc_html__(
1842
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1843
+					'event_espresso'
1844
+				)
1845
+			);
1846
+		}
1847
+		return $help_array;
1848
+	}
1849
+
1850
+
1851
+	/**
1852
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1853
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1854
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1855
+	 *
1856
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1857
+	 * @param boolean $display    if false then we return the trigger string
1858
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1859
+	 * @return string
1860
+	 * @throws DomainException
1861
+	 * @throws EE_Error
1862
+	 */
1863
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1864
+	{
1865
+		if (defined('DOING_AJAX')) {
1866
+			return '';
1867
+		}
1868
+		// 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
1869
+		$help_array = $this->_get_help_content();
1870
+		$help_content = '';
1871
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1872
+			$help_array[ $trigger_id ] = array(
1873
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1874
+				'content' => esc_html__(
1875
+					'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.)',
1876
+					'event_espresso'
1877
+				),
1878
+			);
1879
+			$help_content = $this->_set_help_popup_content($help_array);
1880
+		}
1881
+		// let's setup the trigger
1882
+		$content = '<a class="ee-dialog" href="?height='
1883
+				   . $dimensions[0]
1884
+				   . '&width='
1885
+				   . $dimensions[1]
1886
+				   . '&inlineId='
1887
+				   . $trigger_id
1888
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1889
+		$content .= $help_content;
1890
+		if ($display) {
1891
+			echo $content;
1892
+			return '';
1893
+		}
1894
+		return $content;
1895
+	}
1896
+
1897
+
1898
+	/**
1899
+	 * _add_global_screen_options
1900
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1901
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1902
+	 *
1903
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1904
+	 *         see also WP_Screen object documents...
1905
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1906
+	 * @abstract
1907
+	 * @return void
1908
+	 */
1909
+	private function _add_global_screen_options()
1910
+	{
1911
+	}
1912
+
1913
+
1914
+	/**
1915
+	 * _add_global_feature_pointers
1916
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1917
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1918
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1919
+	 *
1920
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1921
+	 *         extended) also see:
1922
+	 * @link   http://eamann.com/tech/wordpress-portland/
1923
+	 * @abstract
1924
+	 * @return void
1925
+	 */
1926
+	private function _add_global_feature_pointers()
1927
+	{
1928
+	}
1929
+
1930
+
1931
+	/**
1932
+	 * load_global_scripts_styles
1933
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1934
+	 *
1935
+	 * @return void
1936
+	 * @throws EE_Error
1937
+	 */
1938
+	public function load_global_scripts_styles()
1939
+	{
1940
+		// add debugging styles
1941
+		if (WP_DEBUG) {
1942
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1943
+		}
1944
+		// taking care of metaboxes
1945
+		if (
1946
+			empty($this->_cpt_route)
1947
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1948
+		) {
1949
+			wp_enqueue_script('dashboard');
1950
+		}
1951
+
1952
+		// LOCALIZED DATA
1953
+		// localize script for ajax lazy loading
1954
+		wp_localize_script(
1955
+			EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1956
+			'eeLazyLoadingContainers',
1957
+			apply_filters(
1958
+				'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1959
+				['espresso_news_post_box_content']
1960
+			)
1961
+		);
1962
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1963
+		// /**
1964
+		//  * help tour stuff
1965
+		//  */
1966
+		// if (! empty($this->_help_tour)) {
1967
+		//     // register the js for kicking things off
1968
+		//     wp_enqueue_script(
1969
+		//         'ee-help-tour',
1970
+		//         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1971
+		//         array('jquery-joyride'),
1972
+		//         EVENT_ESPRESSO_VERSION,
1973
+		//         true
1974
+		//     );
1975
+		//     $tours = array();
1976
+		//     // setup tours for the js tour object
1977
+		//     foreach ($this->_help_tour['tours'] as $tour) {
1978
+		//         if ($tour instanceof EE_Help_Tour) {
1979
+		//             $tours[] = array(
1980
+		//                 'id'      => $tour->get_slug(),
1981
+		//                 'options' => $tour->get_options(),
1982
+		//             );
1983
+		//         }
1984
+		//     }
1985
+		//     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1986
+		//     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1987
+		// }
1988
+	}
1989
+
1990
+
1991
+	/**
1992
+	 *        admin_footer_scripts_eei18n_js_strings
1993
+	 *
1994
+	 * @return        void
1995
+	 */
1996
+	public function admin_footer_scripts_eei18n_js_strings()
1997
+	{
1998
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1999
+		EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2000
+			'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!!!',
2001
+			'event_espresso'
2002
+		);
2003
+		EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso');
2004
+		EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso');
2005
+		EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso');
2006
+		EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso');
2007
+		EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2008
+		EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso');
2009
+		EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso');
2010
+		EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso');
2011
+		EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso');
2012
+		EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso');
2013
+		EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso');
2014
+		EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso');
2015
+		EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso');
2016
+		EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso');
2017
+		EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso');
2018
+		EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso');
2019
+		EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2020
+		EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso');
2021
+		EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso');
2022
+		EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso');
2023
+		EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso');
2024
+		EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso');
2025
+		EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso');
2026
+		EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso');
2027
+		EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso');
2028
+		EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso');
2029
+		EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso');
2030
+		EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso');
2031
+		EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso');
2032
+		EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso');
2033
+		EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso');
2034
+		EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso');
2035
+		EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso');
2036
+		EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso');
2037
+		EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso');
2038
+		EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso');
2039
+		EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso');
2040
+		EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso');
2041
+	}
2042
+
2043
+
2044
+	/**
2045
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2046
+	 *
2047
+	 * @return        void
2048
+	 */
2049
+	public function add_xdebug_style()
2050
+	{
2051
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2052
+	}
2053
+
2054
+
2055
+	/************************/
2056
+	/** LIST TABLE METHODS **/
2057
+	/************************/
2058
+	/**
2059
+	 * this sets up the list table if the current view requires it.
2060
+	 *
2061
+	 * @return void
2062
+	 * @throws EE_Error
2063
+	 * @throws InvalidArgumentException
2064
+	 * @throws InvalidDataTypeException
2065
+	 * @throws InvalidInterfaceException
2066
+	 */
2067
+	protected function _set_list_table()
2068
+	{
2069
+		// first is this a list_table view?
2070
+		if (! isset($this->_route_config['list_table'])) {
2071
+			return;
2072
+		} //not a list_table view so get out.
2073
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2074
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2075
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2076
+			// user error msg
2077
+			$error_msg = esc_html__(
2078
+				'An error occurred. The requested list table views could not be found.',
2079
+				'event_espresso'
2080
+			);
2081
+			// developer error msg
2082
+			$error_msg .= '||'
2083
+						  . sprintf(
2084
+							  esc_html__(
2085
+								  '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.',
2086
+								  'event_espresso'
2087
+							  ),
2088
+							  $this->_req_action,
2089
+							  $list_table_view
2090
+						  );
2091
+			throw new EE_Error($error_msg);
2092
+		}
2093
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2094
+		$this->_views = apply_filters(
2095
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2096
+			$this->_views
2097
+		);
2098
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2099
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2100
+		$this->_set_list_table_view();
2101
+		$this->_set_list_table_object();
2102
+	}
2103
+
2104
+
2105
+	/**
2106
+	 * set current view for List Table
2107
+	 *
2108
+	 * @return void
2109
+	 */
2110
+	protected function _set_list_table_view()
2111
+	{
2112
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2113
+		// looking at active items or dumpster diving ?
2114
+		if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2115
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2116
+		} else {
2117
+			$this->_view = sanitize_key($this->_req_data['status']);
2118
+		}
2119
+	}
2120
+
2121
+
2122
+	/**
2123
+	 * _set_list_table_object
2124
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2125
+	 *
2126
+	 * @throws InvalidInterfaceException
2127
+	 * @throws InvalidArgumentException
2128
+	 * @throws InvalidDataTypeException
2129
+	 * @throws EE_Error
2130
+	 * @throws InvalidInterfaceException
2131
+	 */
2132
+	protected function _set_list_table_object()
2133
+	{
2134
+		if (isset($this->_route_config['list_table'])) {
2135
+			if (! class_exists($this->_route_config['list_table'])) {
2136
+				throw new EE_Error(
2137
+					sprintf(
2138
+						esc_html__(
2139
+							'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.',
2140
+							'event_espresso'
2141
+						),
2142
+						$this->_route_config['list_table'],
2143
+						get_class($this)
2144
+					)
2145
+				);
2146
+			}
2147
+			$this->_list_table_object = $this->loader->getShared(
2148
+				$this->_route_config['list_table'],
2149
+				array($this)
2150
+			);
2151
+		}
2152
+	}
2153
+
2154
+
2155
+	/**
2156
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2157
+	 *
2158
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2159
+	 *                                                    urls.  The array should be indexed by the view it is being
2160
+	 *                                                    added to.
2161
+	 * @return array
2162
+	 */
2163
+	public function get_list_table_view_RLs($extra_query_args = array())
2164
+	{
2165
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2166
+		if (empty($this->_views)) {
2167
+			$this->_views = array();
2168
+		}
2169
+		// cycle thru views
2170
+		foreach ($this->_views as $key => $view) {
2171
+			$query_args = array();
2172
+			// check for current view
2173
+			$this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2174
+			$query_args['action'] = $this->_req_action;
2175
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2176
+			$query_args['status'] = $view['slug'];
2177
+			// merge any other arguments sent in.
2178
+			if (isset($extra_query_args[ $view['slug'] ])) {
2179
+				foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2180
+					$query_args[] = $extra_query_arg;
2181
+				}
2182
+			}
2183
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2184
+		}
2185
+		return $this->_views;
2186
+	}
2187
+
2188
+
2189
+	/**
2190
+	 * _entries_per_page_dropdown
2191
+	 * generates a drop down box for selecting the number of visible rows in an admin page list table
2192
+	 *
2193
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2194
+	 *         WP does it.
2195
+	 * @param int $max_entries total number of rows in the table
2196
+	 * @return string
2197
+	 */
2198
+	protected function _entries_per_page_dropdown($max_entries = 0)
2199
+	{
2200
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2201
+		$values = array(10, 25, 50, 100);
2202
+		$per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2203
+		if ($max_entries) {
2204
+			$values[] = $max_entries;
2205
+			sort($values);
2206
+		}
2207
+		$entries_per_page_dropdown = '
2208 2208
 			<div id="entries-per-page-dv" class="alignleft actions">
2209 2209
 				<label class="hide-if-no-js">
2210 2210
 					Show
2211 2211
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2212
-        foreach ($values as $value) {
2213
-            if ($value < $max_entries) {
2214
-                $selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2215
-                $entries_per_page_dropdown .= '
2212
+		foreach ($values as $value) {
2213
+			if ($value < $max_entries) {
2214
+				$selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2215
+				$entries_per_page_dropdown .= '
2216 2216
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2217
-            }
2218
-        }
2219
-        $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2220
-        $entries_per_page_dropdown .= '
2217
+			}
2218
+		}
2219
+		$selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2220
+		$entries_per_page_dropdown .= '
2221 2221
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2222
-        $entries_per_page_dropdown .= '
2222
+		$entries_per_page_dropdown .= '
2223 2223
 					</select>
2224 2224
 					entries
2225 2225
 				</label>
2226 2226
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2227 2227
 			</div>
2228 2228
 		';
2229
-        return $entries_per_page_dropdown;
2230
-    }
2231
-
2232
-
2233
-    /**
2234
-     *        _set_search_attributes
2235
-     *
2236
-     * @return        void
2237
-     */
2238
-    public function _set_search_attributes()
2239
-    {
2240
-        $this->_template_args['search']['btn_label'] = sprintf(
2241
-            esc_html__('Search %s', 'event_espresso'),
2242
-            empty($this->_search_btn_label) ? $this->page_label
2243
-                : $this->_search_btn_label
2244
-        );
2245
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2246
-    }
2247
-
2248
-
2249
-
2250
-    /*** END LIST TABLE METHODS **/
2251
-
2252
-
2253
-    /**
2254
-     * _add_registered_metaboxes
2255
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2256
-     *
2257
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2258
-     * @return void
2259
-     * @throws EE_Error
2260
-     */
2261
-    private function _add_registered_meta_boxes()
2262
-    {
2263
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2264
-        // we only add meta boxes if the page_route calls for it
2265
-        if (
2266
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2267
-            && is_array(
2268
-                $this->_route_config['metaboxes']
2269
-            )
2270
-        ) {
2271
-            // this simply loops through the callbacks provided
2272
-            // and checks if there is a corresponding callback registered by the child
2273
-            // if there is then we go ahead and process the metabox loader.
2274
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2275
-                // first check for Closures
2276
-                if ($metabox_callback instanceof Closure) {
2277
-                    $result = $metabox_callback();
2278
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2279
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2280
-                } else {
2281
-                    $result = $this->{$metabox_callback}();
2282
-                }
2283
-                if ($result === false) {
2284
-                    // user error msg
2285
-                    $error_msg = esc_html__(
2286
-                        'An error occurred. The  requested metabox could not be found.',
2287
-                        'event_espresso'
2288
-                    );
2289
-                    // developer error msg
2290
-                    $error_msg .= '||'
2291
-                                  . sprintf(
2292
-                                      esc_html__(
2293
-                                          '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.',
2294
-                                          'event_espresso'
2295
-                                      ),
2296
-                                      $metabox_callback
2297
-                                  );
2298
-                    throw new EE_Error($error_msg);
2299
-                }
2300
-            }
2301
-        }
2302
-    }
2303
-
2304
-
2305
-    /**
2306
-     * _add_screen_columns
2307
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2308
-     * the dynamic column template and we'll setup the column options for the page.
2309
-     *
2310
-     * @return void
2311
-     */
2312
-    private function _add_screen_columns()
2313
-    {
2314
-        if (
2315
-            is_array($this->_route_config)
2316
-            && isset($this->_route_config['columns'])
2317
-            && is_array($this->_route_config['columns'])
2318
-            && count($this->_route_config['columns']) === 2
2319
-        ) {
2320
-            add_screen_option(
2321
-                'layout_columns',
2322
-                array(
2323
-                    'max'     => (int) $this->_route_config['columns'][0],
2324
-                    'default' => (int) $this->_route_config['columns'][1],
2325
-                )
2326
-            );
2327
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2328
-            $screen_id = $this->_current_screen->id;
2329
-            $screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2330
-            $total_columns = ! empty($screen_columns)
2331
-                ? $screen_columns
2332
-                : $this->_route_config['columns'][1];
2333
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2334
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
2335
-            $this->_template_args['screen'] = $this->_current_screen;
2336
-            $this->_column_template_path = EE_ADMIN_TEMPLATE
2337
-                                           . 'admin_details_metabox_column_wrapper.template.php';
2338
-            // finally if we don't have has_metaboxes set in the route config
2339
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2340
-            $this->_route_config['has_metaboxes'] = true;
2341
-        }
2342
-    }
2343
-
2344
-
2345
-
2346
-    /** GLOBALLY AVAILABLE METABOXES **/
2347
-
2348
-
2349
-    /**
2350
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2351
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2352
-     * these get loaded on.
2353
-     */
2354
-    private function _espresso_news_post_box()
2355
-    {
2356
-        $news_box_title = apply_filters(
2357
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2358
-            esc_html__('New @ Event Espresso', 'event_espresso')
2359
-        );
2360
-        add_meta_box(
2361
-            'espresso_news_post_box',
2362
-            $news_box_title,
2363
-            array(
2364
-                $this,
2365
-                'espresso_news_post_box',
2366
-            ),
2367
-            $this->_wp_page_slug,
2368
-            'side'
2369
-        );
2370
-    }
2371
-
2372
-
2373
-    /**
2374
-     * Code for setting up espresso ratings request metabox.
2375
-     */
2376
-    protected function _espresso_ratings_request()
2377
-    {
2378
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2379
-            return;
2380
-        }
2381
-        $ratings_box_title = apply_filters(
2382
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2383
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2384
-        );
2385
-        add_meta_box(
2386
-            'espresso_ratings_request',
2387
-            $ratings_box_title,
2388
-            array(
2389
-                $this,
2390
-                'espresso_ratings_request',
2391
-            ),
2392
-            $this->_wp_page_slug,
2393
-            'side'
2394
-        );
2395
-    }
2396
-
2397
-
2398
-    /**
2399
-     * Code for setting up espresso ratings request metabox content.
2400
-     *
2401
-     * @throws DomainException
2402
-     */
2403
-    public function espresso_ratings_request()
2404
-    {
2405
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2406
-    }
2407
-
2408
-
2409
-    public static function cached_rss_display($rss_id, $url)
2410
-    {
2411
-        $loading = '<p class="widget-loading hide-if-no-js">'
2412
-                   . __('Loading&#8230;', 'event_espresso')
2413
-                   . '</p><p class="hide-if-js">'
2414
-                   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2415
-                   . '</p>';
2416
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
2417
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2418
-        $post = '</div>' . "\n";
2419
-        $cache_key = 'ee_rss_' . md5($rss_id);
2420
-        $output = get_transient($cache_key);
2421
-        if ($output !== false) {
2422
-            echo $pre . $output . $post;
2423
-            return true;
2424
-        }
2425
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2426
-            echo $pre . $loading . $post;
2427
-            return false;
2428
-        }
2429
-        ob_start();
2430
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2431
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2432
-        return true;
2433
-    }
2434
-
2435
-
2436
-    public function espresso_news_post_box()
2437
-    {
2438
-        ?>
2229
+		return $entries_per_page_dropdown;
2230
+	}
2231
+
2232
+
2233
+	/**
2234
+	 *        _set_search_attributes
2235
+	 *
2236
+	 * @return        void
2237
+	 */
2238
+	public function _set_search_attributes()
2239
+	{
2240
+		$this->_template_args['search']['btn_label'] = sprintf(
2241
+			esc_html__('Search %s', 'event_espresso'),
2242
+			empty($this->_search_btn_label) ? $this->page_label
2243
+				: $this->_search_btn_label
2244
+		);
2245
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2246
+	}
2247
+
2248
+
2249
+
2250
+	/*** END LIST TABLE METHODS **/
2251
+
2252
+
2253
+	/**
2254
+	 * _add_registered_metaboxes
2255
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2256
+	 *
2257
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2258
+	 * @return void
2259
+	 * @throws EE_Error
2260
+	 */
2261
+	private function _add_registered_meta_boxes()
2262
+	{
2263
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2264
+		// we only add meta boxes if the page_route calls for it
2265
+		if (
2266
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2267
+			&& is_array(
2268
+				$this->_route_config['metaboxes']
2269
+			)
2270
+		) {
2271
+			// this simply loops through the callbacks provided
2272
+			// and checks if there is a corresponding callback registered by the child
2273
+			// if there is then we go ahead and process the metabox loader.
2274
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2275
+				// first check for Closures
2276
+				if ($metabox_callback instanceof Closure) {
2277
+					$result = $metabox_callback();
2278
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2279
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2280
+				} else {
2281
+					$result = $this->{$metabox_callback}();
2282
+				}
2283
+				if ($result === false) {
2284
+					// user error msg
2285
+					$error_msg = esc_html__(
2286
+						'An error occurred. The  requested metabox could not be found.',
2287
+						'event_espresso'
2288
+					);
2289
+					// developer error msg
2290
+					$error_msg .= '||'
2291
+								  . sprintf(
2292
+									  esc_html__(
2293
+										  '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.',
2294
+										  'event_espresso'
2295
+									  ),
2296
+									  $metabox_callback
2297
+								  );
2298
+					throw new EE_Error($error_msg);
2299
+				}
2300
+			}
2301
+		}
2302
+	}
2303
+
2304
+
2305
+	/**
2306
+	 * _add_screen_columns
2307
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2308
+	 * the dynamic column template and we'll setup the column options for the page.
2309
+	 *
2310
+	 * @return void
2311
+	 */
2312
+	private function _add_screen_columns()
2313
+	{
2314
+		if (
2315
+			is_array($this->_route_config)
2316
+			&& isset($this->_route_config['columns'])
2317
+			&& is_array($this->_route_config['columns'])
2318
+			&& count($this->_route_config['columns']) === 2
2319
+		) {
2320
+			add_screen_option(
2321
+				'layout_columns',
2322
+				array(
2323
+					'max'     => (int) $this->_route_config['columns'][0],
2324
+					'default' => (int) $this->_route_config['columns'][1],
2325
+				)
2326
+			);
2327
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2328
+			$screen_id = $this->_current_screen->id;
2329
+			$screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2330
+			$total_columns = ! empty($screen_columns)
2331
+				? $screen_columns
2332
+				: $this->_route_config['columns'][1];
2333
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2334
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
2335
+			$this->_template_args['screen'] = $this->_current_screen;
2336
+			$this->_column_template_path = EE_ADMIN_TEMPLATE
2337
+										   . 'admin_details_metabox_column_wrapper.template.php';
2338
+			// finally if we don't have has_metaboxes set in the route config
2339
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2340
+			$this->_route_config['has_metaboxes'] = true;
2341
+		}
2342
+	}
2343
+
2344
+
2345
+
2346
+	/** GLOBALLY AVAILABLE METABOXES **/
2347
+
2348
+
2349
+	/**
2350
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2351
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2352
+	 * these get loaded on.
2353
+	 */
2354
+	private function _espresso_news_post_box()
2355
+	{
2356
+		$news_box_title = apply_filters(
2357
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2358
+			esc_html__('New @ Event Espresso', 'event_espresso')
2359
+		);
2360
+		add_meta_box(
2361
+			'espresso_news_post_box',
2362
+			$news_box_title,
2363
+			array(
2364
+				$this,
2365
+				'espresso_news_post_box',
2366
+			),
2367
+			$this->_wp_page_slug,
2368
+			'side'
2369
+		);
2370
+	}
2371
+
2372
+
2373
+	/**
2374
+	 * Code for setting up espresso ratings request metabox.
2375
+	 */
2376
+	protected function _espresso_ratings_request()
2377
+	{
2378
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2379
+			return;
2380
+		}
2381
+		$ratings_box_title = apply_filters(
2382
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2383
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2384
+		);
2385
+		add_meta_box(
2386
+			'espresso_ratings_request',
2387
+			$ratings_box_title,
2388
+			array(
2389
+				$this,
2390
+				'espresso_ratings_request',
2391
+			),
2392
+			$this->_wp_page_slug,
2393
+			'side'
2394
+		);
2395
+	}
2396
+
2397
+
2398
+	/**
2399
+	 * Code for setting up espresso ratings request metabox content.
2400
+	 *
2401
+	 * @throws DomainException
2402
+	 */
2403
+	public function espresso_ratings_request()
2404
+	{
2405
+		EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2406
+	}
2407
+
2408
+
2409
+	public static function cached_rss_display($rss_id, $url)
2410
+	{
2411
+		$loading = '<p class="widget-loading hide-if-no-js">'
2412
+				   . __('Loading&#8230;', 'event_espresso')
2413
+				   . '</p><p class="hide-if-js">'
2414
+				   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2415
+				   . '</p>';
2416
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
2417
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2418
+		$post = '</div>' . "\n";
2419
+		$cache_key = 'ee_rss_' . md5($rss_id);
2420
+		$output = get_transient($cache_key);
2421
+		if ($output !== false) {
2422
+			echo $pre . $output . $post;
2423
+			return true;
2424
+		}
2425
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2426
+			echo $pre . $loading . $post;
2427
+			return false;
2428
+		}
2429
+		ob_start();
2430
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2431
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2432
+		return true;
2433
+	}
2434
+
2435
+
2436
+	public function espresso_news_post_box()
2437
+	{
2438
+		?>
2439 2439
         <div class="padding">
2440 2440
             <div id="espresso_news_post_box_content" class="infolinks">
2441 2441
                 <?php
2442
-                // Get RSS Feed(s)
2443
-                EE_Admin_Page::cached_rss_display(
2444
-                    'espresso_news_post_box_content',
2445
-                    urlencode(
2446
-                        apply_filters(
2447
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2448
-                            'http://eventespresso.com/feed/'
2449
-                        )
2450
-                    )
2451
-                );
2452
-                ?>
2442
+				// Get RSS Feed(s)
2443
+				EE_Admin_Page::cached_rss_display(
2444
+					'espresso_news_post_box_content',
2445
+					urlencode(
2446
+						apply_filters(
2447
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2448
+							'http://eventespresso.com/feed/'
2449
+						)
2450
+					)
2451
+				);
2452
+				?>
2453 2453
             </div>
2454 2454
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2455 2455
         </div>
2456 2456
         <?php
2457
-    }
2458
-
2459
-
2460
-    private function _espresso_links_post_box()
2461
-    {
2462
-        // Hiding until we actually have content to put in here...
2463
-        // 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');
2464
-    }
2465
-
2466
-
2467
-    public function espresso_links_post_box()
2468
-    {
2469
-        // Hiding until we actually have content to put in here...
2470
-        // EEH_Template::display_template(
2471
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2472
-        // );
2473
-    }
2474
-
2475
-
2476
-    protected function _espresso_sponsors_post_box()
2477
-    {
2478
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2479
-            add_meta_box(
2480
-                'espresso_sponsors_post_box',
2481
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2482
-                array($this, 'espresso_sponsors_post_box'),
2483
-                $this->_wp_page_slug,
2484
-                'side'
2485
-            );
2486
-        }
2487
-    }
2488
-
2489
-
2490
-    public function espresso_sponsors_post_box()
2491
-    {
2492
-        EEH_Template::display_template(
2493
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2494
-        );
2495
-    }
2496
-
2497
-
2498
-    private function _publish_post_box()
2499
-    {
2500
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2501
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2502
-        // then we'll use that for the metabox label.
2503
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2504
-        if (! empty($this->_labels['publishbox'])) {
2505
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2506
-                : $this->_labels['publishbox'];
2507
-        } else {
2508
-            $box_label = esc_html__('Publish', 'event_espresso');
2509
-        }
2510
-        $box_label = apply_filters(
2511
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2512
-            $box_label,
2513
-            $this->_req_action,
2514
-            $this
2515
-        );
2516
-        add_meta_box(
2517
-            $meta_box_ref,
2518
-            $box_label,
2519
-            array($this, 'editor_overview'),
2520
-            $this->_current_screen->id,
2521
-            'side',
2522
-            'high'
2523
-        );
2524
-    }
2525
-
2526
-
2527
-    public function editor_overview()
2528
-    {
2529
-        // if we have extra content set let's add it in if not make sure its empty
2530
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2531
-            ? $this->_template_args['publish_box_extra_content']
2532
-            : '';
2533
-        echo EEH_Template::display_template(
2534
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2535
-            $this->_template_args,
2536
-            true
2537
-        );
2538
-    }
2539
-
2540
-
2541
-    /** end of globally available metaboxes section **/
2542
-
2543
-
2544
-    /**
2545
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2546
-     * protected method.
2547
-     *
2548
-     * @see   $this->_set_publish_post_box_vars for param details
2549
-     * @since 4.6.0
2550
-     * @param string $name
2551
-     * @param int    $id
2552
-     * @param bool   $delete
2553
-     * @param string $save_close_redirect_URL
2554
-     * @param bool   $both_btns
2555
-     * @throws EE_Error
2556
-     * @throws InvalidArgumentException
2557
-     * @throws InvalidDataTypeException
2558
-     * @throws InvalidInterfaceException
2559
-     */
2560
-    public function set_publish_post_box_vars(
2561
-        $name = '',
2562
-        $id = 0,
2563
-        $delete = false,
2564
-        $save_close_redirect_URL = '',
2565
-        $both_btns = true
2566
-    ) {
2567
-        $this->_set_publish_post_box_vars(
2568
-            $name,
2569
-            $id,
2570
-            $delete,
2571
-            $save_close_redirect_URL,
2572
-            $both_btns
2573
-        );
2574
-    }
2575
-
2576
-
2577
-    /**
2578
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2579
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2580
-     * save, and save and close buttons to work properly, then you will want to include a
2581
-     * values for the name and id arguments.
2582
-     *
2583
-     * @todo  Add in validation for name/id arguments.
2584
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2585
-     * @param    int     $id                      id attached to the item published
2586
-     * @param    string  $delete                  page route callback for the delete action
2587
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2588
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2589
-     *                                            the Save button
2590
-     * @throws EE_Error
2591
-     * @throws InvalidArgumentException
2592
-     * @throws InvalidDataTypeException
2593
-     * @throws InvalidInterfaceException
2594
-     */
2595
-    protected function _set_publish_post_box_vars(
2596
-        $name = '',
2597
-        $id = 0,
2598
-        $delete = '',
2599
-        $save_close_redirect_URL = '',
2600
-        $both_btns = true
2601
-    ) {
2602
-        // if Save & Close, use a custom redirect URL or default to the main page?
2603
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2604
-            ? $save_close_redirect_URL
2605
-            : $this->_admin_base_url;
2606
-        // create the Save & Close and Save buttons
2607
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2608
-        // if we have extra content set let's add it in if not make sure its empty
2609
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2610
-            ? $this->_template_args['publish_box_extra_content']
2611
-            : '';
2612
-        if ($delete && ! empty($id)) {
2613
-            // make sure we have a default if just true is sent.
2614
-            $delete = ! empty($delete) ? $delete : 'delete';
2615
-            $delete_link_args = array($name => $id);
2616
-            $delete = $this->get_action_link_or_button(
2617
-                $delete,
2618
-                $delete,
2619
-                $delete_link_args,
2620
-                'submitdelete deletion'
2621
-            );
2622
-        }
2623
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2624
-        if (! empty($name) && ! empty($id)) {
2625
-            $hidden_field_arr[ $name ] = array(
2626
-                'type'  => 'hidden',
2627
-                'value' => $id,
2628
-            );
2629
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2630
-        } else {
2631
-            $hf = '';
2632
-        }
2633
-        // add hidden field
2634
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2635
-            ? $hf[ $name ]['field']
2636
-            : $hf;
2637
-    }
2638
-
2639
-
2640
-    /**
2641
-     * displays an error message to ppl who have javascript disabled
2642
-     *
2643
-     * @return void
2644
-     */
2645
-    private function _display_no_javascript_warning()
2646
-    {
2647
-        ?>
2457
+	}
2458
+
2459
+
2460
+	private function _espresso_links_post_box()
2461
+	{
2462
+		// Hiding until we actually have content to put in here...
2463
+		// 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');
2464
+	}
2465
+
2466
+
2467
+	public function espresso_links_post_box()
2468
+	{
2469
+		// Hiding until we actually have content to put in here...
2470
+		// EEH_Template::display_template(
2471
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2472
+		// );
2473
+	}
2474
+
2475
+
2476
+	protected function _espresso_sponsors_post_box()
2477
+	{
2478
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2479
+			add_meta_box(
2480
+				'espresso_sponsors_post_box',
2481
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2482
+				array($this, 'espresso_sponsors_post_box'),
2483
+				$this->_wp_page_slug,
2484
+				'side'
2485
+			);
2486
+		}
2487
+	}
2488
+
2489
+
2490
+	public function espresso_sponsors_post_box()
2491
+	{
2492
+		EEH_Template::display_template(
2493
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2494
+		);
2495
+	}
2496
+
2497
+
2498
+	private function _publish_post_box()
2499
+	{
2500
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2501
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2502
+		// then we'll use that for the metabox label.
2503
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2504
+		if (! empty($this->_labels['publishbox'])) {
2505
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2506
+				: $this->_labels['publishbox'];
2507
+		} else {
2508
+			$box_label = esc_html__('Publish', 'event_espresso');
2509
+		}
2510
+		$box_label = apply_filters(
2511
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2512
+			$box_label,
2513
+			$this->_req_action,
2514
+			$this
2515
+		);
2516
+		add_meta_box(
2517
+			$meta_box_ref,
2518
+			$box_label,
2519
+			array($this, 'editor_overview'),
2520
+			$this->_current_screen->id,
2521
+			'side',
2522
+			'high'
2523
+		);
2524
+	}
2525
+
2526
+
2527
+	public function editor_overview()
2528
+	{
2529
+		// if we have extra content set let's add it in if not make sure its empty
2530
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2531
+			? $this->_template_args['publish_box_extra_content']
2532
+			: '';
2533
+		echo EEH_Template::display_template(
2534
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2535
+			$this->_template_args,
2536
+			true
2537
+		);
2538
+	}
2539
+
2540
+
2541
+	/** end of globally available metaboxes section **/
2542
+
2543
+
2544
+	/**
2545
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2546
+	 * protected method.
2547
+	 *
2548
+	 * @see   $this->_set_publish_post_box_vars for param details
2549
+	 * @since 4.6.0
2550
+	 * @param string $name
2551
+	 * @param int    $id
2552
+	 * @param bool   $delete
2553
+	 * @param string $save_close_redirect_URL
2554
+	 * @param bool   $both_btns
2555
+	 * @throws EE_Error
2556
+	 * @throws InvalidArgumentException
2557
+	 * @throws InvalidDataTypeException
2558
+	 * @throws InvalidInterfaceException
2559
+	 */
2560
+	public function set_publish_post_box_vars(
2561
+		$name = '',
2562
+		$id = 0,
2563
+		$delete = false,
2564
+		$save_close_redirect_URL = '',
2565
+		$both_btns = true
2566
+	) {
2567
+		$this->_set_publish_post_box_vars(
2568
+			$name,
2569
+			$id,
2570
+			$delete,
2571
+			$save_close_redirect_URL,
2572
+			$both_btns
2573
+		);
2574
+	}
2575
+
2576
+
2577
+	/**
2578
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2579
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2580
+	 * save, and save and close buttons to work properly, then you will want to include a
2581
+	 * values for the name and id arguments.
2582
+	 *
2583
+	 * @todo  Add in validation for name/id arguments.
2584
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2585
+	 * @param    int     $id                      id attached to the item published
2586
+	 * @param    string  $delete                  page route callback for the delete action
2587
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2588
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2589
+	 *                                            the Save button
2590
+	 * @throws EE_Error
2591
+	 * @throws InvalidArgumentException
2592
+	 * @throws InvalidDataTypeException
2593
+	 * @throws InvalidInterfaceException
2594
+	 */
2595
+	protected function _set_publish_post_box_vars(
2596
+		$name = '',
2597
+		$id = 0,
2598
+		$delete = '',
2599
+		$save_close_redirect_URL = '',
2600
+		$both_btns = true
2601
+	) {
2602
+		// if Save & Close, use a custom redirect URL or default to the main page?
2603
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2604
+			? $save_close_redirect_URL
2605
+			: $this->_admin_base_url;
2606
+		// create the Save & Close and Save buttons
2607
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2608
+		// if we have extra content set let's add it in if not make sure its empty
2609
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2610
+			? $this->_template_args['publish_box_extra_content']
2611
+			: '';
2612
+		if ($delete && ! empty($id)) {
2613
+			// make sure we have a default if just true is sent.
2614
+			$delete = ! empty($delete) ? $delete : 'delete';
2615
+			$delete_link_args = array($name => $id);
2616
+			$delete = $this->get_action_link_or_button(
2617
+				$delete,
2618
+				$delete,
2619
+				$delete_link_args,
2620
+				'submitdelete deletion'
2621
+			);
2622
+		}
2623
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2624
+		if (! empty($name) && ! empty($id)) {
2625
+			$hidden_field_arr[ $name ] = array(
2626
+				'type'  => 'hidden',
2627
+				'value' => $id,
2628
+			);
2629
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2630
+		} else {
2631
+			$hf = '';
2632
+		}
2633
+		// add hidden field
2634
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2635
+			? $hf[ $name ]['field']
2636
+			: $hf;
2637
+	}
2638
+
2639
+
2640
+	/**
2641
+	 * displays an error message to ppl who have javascript disabled
2642
+	 *
2643
+	 * @return void
2644
+	 */
2645
+	private function _display_no_javascript_warning()
2646
+	{
2647
+		?>
2648 2648
         <noscript>
2649 2649
             <div id="no-js-message" class="error">
2650 2650
                 <p style="font-size:1.3em;">
2651 2651
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2652 2652
                     <?php esc_html_e(
2653
-                        '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.',
2654
-                        'event_espresso'
2655
-                    ); ?>
2653
+						'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.',
2654
+						'event_espresso'
2655
+					); ?>
2656 2656
                 </p>
2657 2657
             </div>
2658 2658
         </noscript>
2659 2659
         <?php
2660
-    }
2661
-
2662
-
2663
-    /**
2664
-     * displays espresso success and/or error notices
2665
-     *
2666
-     * @return void
2667
-     */
2668
-    private function _display_espresso_notices()
2669
-    {
2670
-        $notices = $this->_get_transient(true);
2671
-        echo stripslashes($notices);
2672
-    }
2673
-
2674
-
2675
-    /**
2676
-     * spinny things pacify the masses
2677
-     *
2678
-     * @return void
2679
-     */
2680
-    protected function _add_admin_page_ajax_loading_img()
2681
-    {
2682
-        ?>
2660
+	}
2661
+
2662
+
2663
+	/**
2664
+	 * displays espresso success and/or error notices
2665
+	 *
2666
+	 * @return void
2667
+	 */
2668
+	private function _display_espresso_notices()
2669
+	{
2670
+		$notices = $this->_get_transient(true);
2671
+		echo stripslashes($notices);
2672
+	}
2673
+
2674
+
2675
+	/**
2676
+	 * spinny things pacify the masses
2677
+	 *
2678
+	 * @return void
2679
+	 */
2680
+	protected function _add_admin_page_ajax_loading_img()
2681
+	{
2682
+		?>
2683 2683
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2684 2684
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2685
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2685
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2686 2686
         </div>
2687 2687
         <?php
2688
-    }
2688
+	}
2689 2689
 
2690 2690
 
2691
-    /**
2692
-     * add admin page overlay for modal boxes
2693
-     *
2694
-     * @return void
2695
-     */
2696
-    protected function _add_admin_page_overlay()
2697
-    {
2698
-        ?>
2691
+	/**
2692
+	 * add admin page overlay for modal boxes
2693
+	 *
2694
+	 * @return void
2695
+	 */
2696
+	protected function _add_admin_page_overlay()
2697
+	{
2698
+		?>
2699 2699
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2700 2700
         <?php
2701
-    }
2702
-
2703
-
2704
-    /**
2705
-     * facade for add_meta_box
2706
-     *
2707
-     * @param string  $action        where the metabox get's displayed
2708
-     * @param string  $title         Title of Metabox (output in metabox header)
2709
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2710
-     *                               instead of the one created in here.
2711
-     * @param array   $callback_args an array of args supplied for the metabox
2712
-     * @param string  $column        what metabox column
2713
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2714
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2715
-     *                               created but just set our own callback for wp's add_meta_box.
2716
-     * @throws DomainException
2717
-     */
2718
-    public function _add_admin_page_meta_box(
2719
-        $action,
2720
-        $title,
2721
-        $callback,
2722
-        $callback_args,
2723
-        $column = 'normal',
2724
-        $priority = 'high',
2725
-        $create_func = true
2726
-    ) {
2727
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2728
-        // 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.
2729
-        if (empty($callback_args) && $create_func) {
2730
-            $callback_args = array(
2731
-                'template_path' => $this->_template_path,
2732
-                'template_args' => $this->_template_args,
2733
-            );
2734
-        }
2735
-        // 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)
2736
-        $call_back_func = $create_func
2737
-            ? static function ($post, $metabox) {
2738
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2739
-                echo EEH_Template::display_template(
2740
-                    $metabox['args']['template_path'],
2741
-                    $metabox['args']['template_args'],
2742
-                    true
2743
-                );
2744
-            }
2745
-            : $callback;
2746
-        add_meta_box(
2747
-            str_replace('_', '-', $action) . '-mbox',
2748
-            $title,
2749
-            $call_back_func,
2750
-            $this->_wp_page_slug,
2751
-            $column,
2752
-            $priority,
2753
-            $callback_args
2754
-        );
2755
-    }
2756
-
2757
-
2758
-    /**
2759
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2760
-     *
2761
-     * @throws DomainException
2762
-     * @throws EE_Error
2763
-     * @throws InvalidArgumentException
2764
-     * @throws InvalidDataTypeException
2765
-     * @throws InvalidInterfaceException
2766
-     */
2767
-    public function display_admin_page_with_metabox_columns()
2768
-    {
2769
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2770
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2771
-            $this->_column_template_path,
2772
-            $this->_template_args,
2773
-            true
2774
-        );
2775
-        // the final wrapper
2776
-        $this->admin_page_wrapper();
2777
-    }
2778
-
2779
-
2780
-    /**
2781
-     * generates  HTML wrapper for an admin details page
2782
-     *
2783
-     * @return void
2784
-     * @throws DomainException
2785
-     * @throws EE_Error
2786
-     * @throws InvalidArgumentException
2787
-     * @throws InvalidDataTypeException
2788
-     * @throws InvalidInterfaceException
2789
-     */
2790
-    public function display_admin_page_with_sidebar()
2791
-    {
2792
-        $this->_display_admin_page(true);
2793
-    }
2794
-
2795
-
2796
-    /**
2797
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2798
-     *
2799
-     * @return void
2800
-     * @throws DomainException
2801
-     * @throws EE_Error
2802
-     * @throws InvalidArgumentException
2803
-     * @throws InvalidDataTypeException
2804
-     * @throws InvalidInterfaceException
2805
-     */
2806
-    public function display_admin_page_with_no_sidebar()
2807
-    {
2808
-        $this->_display_admin_page();
2809
-    }
2810
-
2811
-
2812
-    /**
2813
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2814
-     *
2815
-     * @return void
2816
-     * @throws DomainException
2817
-     * @throws EE_Error
2818
-     * @throws InvalidArgumentException
2819
-     * @throws InvalidDataTypeException
2820
-     * @throws InvalidInterfaceException
2821
-     */
2822
-    public function display_about_admin_page()
2823
-    {
2824
-        $this->_display_admin_page(false, true);
2825
-    }
2826
-
2827
-
2828
-    /**
2829
-     * display_admin_page
2830
-     * contains the code for actually displaying an admin page
2831
-     *
2832
-     * @param boolean $sidebar true with sidebar, false without
2833
-     * @param boolean $about   use the about admin wrapper instead of the default.
2834
-     * @return void
2835
-     * @throws DomainException
2836
-     * @throws EE_Error
2837
-     * @throws InvalidArgumentException
2838
-     * @throws InvalidDataTypeException
2839
-     * @throws InvalidInterfaceException
2840
-     */
2841
-    private function _display_admin_page($sidebar = false, $about = false)
2842
-    {
2843
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2844
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2845
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2846
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2847
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2848
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2849
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2850
-            ? 'poststuff'
2851
-            : 'espresso-default-admin';
2852
-        $template_path = $sidebar
2853
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2854
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2855
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2856
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2857
-        }
2858
-        $template_path = ! empty($this->_column_template_path)
2859
-            ? $this->_column_template_path : $template_path;
2860
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2861
-            ? $this->_template_args['admin_page_content']
2862
-            : '';
2863
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2864
-            ? $this->_template_args['before_admin_page_content']
2865
-            : '';
2866
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2867
-            ? $this->_template_args['after_admin_page_content']
2868
-            : '';
2869
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2870
-            $template_path,
2871
-            $this->_template_args,
2872
-            true
2873
-        );
2874
-        // the final template wrapper
2875
-        $this->admin_page_wrapper($about);
2876
-    }
2877
-
2878
-
2879
-    /**
2880
-     * This is used to display caf preview pages.
2881
-     *
2882
-     * @since 4.3.2
2883
-     * @param string $utm_campaign_source what is the key used for google analytics link
2884
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2885
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2886
-     * @return void
2887
-     * @throws DomainException
2888
-     * @throws EE_Error
2889
-     * @throws InvalidArgumentException
2890
-     * @throws InvalidDataTypeException
2891
-     * @throws InvalidInterfaceException
2892
-     */
2893
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2894
-    {
2895
-        // let's generate a default preview action button if there isn't one already present.
2896
-        $this->_labels['buttons']['buy_now'] = esc_html__(
2897
-            'Upgrade to Event Espresso 4 Right Now',
2898
-            'event_espresso'
2899
-        );
2900
-        $buy_now_url = add_query_arg(
2901
-            array(
2902
-                'ee_ver'       => 'ee4',
2903
-                'utm_source'   => 'ee4_plugin_admin',
2904
-                'utm_medium'   => 'link',
2905
-                'utm_campaign' => $utm_campaign_source,
2906
-                'utm_content'  => 'buy_now_button',
2907
-            ),
2908
-            'http://eventespresso.com/pricing/'
2909
-        );
2910
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2911
-            ? $this->get_action_link_or_button(
2912
-                '',
2913
-                'buy_now',
2914
-                array(),
2915
-                'button-primary button-large',
2916
-                $buy_now_url,
2917
-                true
2918
-            )
2919
-            : $this->_template_args['preview_action_button'];
2920
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2921
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2922
-            $this->_template_args,
2923
-            true
2924
-        );
2925
-        $this->_display_admin_page($display_sidebar);
2926
-    }
2927
-
2928
-
2929
-    /**
2930
-     * display_admin_list_table_page_with_sidebar
2931
-     * generates HTML wrapper for an admin_page with list_table
2932
-     *
2933
-     * @return void
2934
-     * @throws DomainException
2935
-     * @throws EE_Error
2936
-     * @throws InvalidArgumentException
2937
-     * @throws InvalidDataTypeException
2938
-     * @throws InvalidInterfaceException
2939
-     */
2940
-    public function display_admin_list_table_page_with_sidebar()
2941
-    {
2942
-        $this->_display_admin_list_table_page(true);
2943
-    }
2944
-
2945
-
2946
-    /**
2947
-     * display_admin_list_table_page_with_no_sidebar
2948
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2949
-     *
2950
-     * @return void
2951
-     * @throws DomainException
2952
-     * @throws EE_Error
2953
-     * @throws InvalidArgumentException
2954
-     * @throws InvalidDataTypeException
2955
-     * @throws InvalidInterfaceException
2956
-     */
2957
-    public function display_admin_list_table_page_with_no_sidebar()
2958
-    {
2959
-        $this->_display_admin_list_table_page();
2960
-    }
2961
-
2962
-
2963
-    /**
2964
-     * generates html wrapper for an admin_list_table page
2965
-     *
2966
-     * @param boolean $sidebar whether to display with sidebar or not.
2967
-     * @return void
2968
-     * @throws DomainException
2969
-     * @throws EE_Error
2970
-     * @throws InvalidArgumentException
2971
-     * @throws InvalidDataTypeException
2972
-     * @throws InvalidInterfaceException
2973
-     */
2974
-    private function _display_admin_list_table_page($sidebar = false)
2975
-    {
2976
-        // setup search attributes
2977
-        $this->_set_search_attributes();
2978
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2979
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2980
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2981
-            ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2982
-            : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2983
-        $this->_template_args['list_table'] = $this->_list_table_object;
2984
-        $this->_template_args['current_route'] = $this->_req_action;
2985
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2986
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2987
-        if (! empty($ajax_sorting_callback)) {
2988
-            $sortable_list_table_form_fields = wp_nonce_field(
2989
-                $ajax_sorting_callback . '_nonce',
2990
-                $ajax_sorting_callback . '_nonce',
2991
-                false,
2992
-                false
2993
-            );
2994
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2995
-                                                . $this->page_slug
2996
-                                                . '" />';
2997
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2998
-                                                . $ajax_sorting_callback
2999
-                                                . '" />';
3000
-        } else {
3001
-            $sortable_list_table_form_fields = '';
3002
-        }
3003
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3004
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
3005
-            ? $this->_template_args['list_table_hidden_fields']
3006
-            : '';
3007
-        $nonce_ref = $this->_req_action . '_nonce';
3008
-        $hidden_form_fields .= '<input type="hidden" name="'
3009
-                               . $nonce_ref
3010
-                               . '" value="'
3011
-                               . wp_create_nonce($nonce_ref)
3012
-                               . '">';
3013
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3014
-        // display message about search results?
3015
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3016
-            ? '<p class="ee-search-results">' . sprintf(
3017
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3018
-                trim($this->_req_data['s'], '%')
3019
-            ) . '</p>'
3020
-            : '';
3021
-        // filter before_list_table template arg
3022
-        $this->_template_args['before_list_table'] = apply_filters(
3023
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3024
-            $this->_template_args['before_list_table'],
3025
-            $this->page_slug,
3026
-            $this->_req_data,
3027
-            $this->_req_action
3028
-        );
3029
-        // convert to array and filter again
3030
-        // arrays are easier to inject new items in a specific location,
3031
-        // but would not be backwards compatible, so we have to add a new filter
3032
-        $this->_template_args['before_list_table'] = implode(
3033
-            " \n",
3034
-            (array) apply_filters(
3035
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3036
-                (array) $this->_template_args['before_list_table'],
3037
-                $this->page_slug,
3038
-                $this->_req_data,
3039
-                $this->_req_action
3040
-            )
3041
-        );
3042
-        // filter after_list_table template arg
3043
-        $this->_template_args['after_list_table'] = apply_filters(
3044
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3045
-            $this->_template_args['after_list_table'],
3046
-            $this->page_slug,
3047
-            $this->_req_data,
3048
-            $this->_req_action
3049
-        );
3050
-        // convert to array and filter again
3051
-        // arrays are easier to inject new items in a specific location,
3052
-        // but would not be backwards compatible, so we have to add a new filter
3053
-        $this->_template_args['after_list_table'] = implode(
3054
-            " \n",
3055
-            (array) apply_filters(
3056
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3057
-                (array) $this->_template_args['after_list_table'],
3058
-                $this->page_slug,
3059
-                $this->_req_data,
3060
-                $this->_req_action
3061
-            )
3062
-        );
3063
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3064
-            $template_path,
3065
-            $this->_template_args,
3066
-            true
3067
-        );
3068
-        // the final template wrapper
3069
-        if ($sidebar) {
3070
-            $this->display_admin_page_with_sidebar();
3071
-        } else {
3072
-            $this->display_admin_page_with_no_sidebar();
3073
-        }
3074
-    }
3075
-
3076
-
3077
-    /**
3078
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3079
-     * html string for the legend.
3080
-     * $items are expected in an array in the following format:
3081
-     * $legend_items = array(
3082
-     *        'item_id' => array(
3083
-     *            'icon' => 'http://url_to_icon_being_described.png',
3084
-     *            'desc' => esc_html__('localized description of item');
3085
-     *        )
3086
-     * );
3087
-     *
3088
-     * @param  array $items see above for format of array
3089
-     * @return string html string of legend
3090
-     * @throws DomainException
3091
-     */
3092
-    protected function _display_legend($items)
3093
-    {
3094
-        $this->_template_args['items'] = apply_filters(
3095
-            'FHEE__EE_Admin_Page___display_legend__items',
3096
-            (array) $items,
3097
-            $this
3098
-        );
3099
-        /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
3100
-        $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
3101
-        if (! $status_change_notice->isDismissed()) {
3102
-            $this->_template_args['status_change_notice'] = EEH_Template::display_template(
3103
-                EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
3104
-                [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
3105
-                true
3106
-            );
3107
-        }
3108
-        return EEH_Template::display_template(
3109
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3110
-            $this->_template_args,
3111
-            true
3112
-        );
3113
-    }
3114
-
3115
-
3116
-    /**
3117
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3118
-     * The returned json object is created from an array in the following format:
3119
-     * array(
3120
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3121
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3122
-     *  'notices' => '', // - contains any EE_Error formatted notices
3123
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3124
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3125
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3126
-     *  that might be included in here)
3127
-     * )
3128
-     * The json object is populated by whatever is set in the $_template_args property.
3129
-     *
3130
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3131
-     *                                 instead of displayed.
3132
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3133
-     * @return void
3134
-     * @throws EE_Error
3135
-     * @throws InvalidArgumentException
3136
-     * @throws InvalidDataTypeException
3137
-     * @throws InvalidInterfaceException
3138
-     */
3139
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
3140
-    {
3141
-        // make sure any EE_Error notices have been handled.
3142
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3143
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3144
-        unset($this->_template_args['data']);
3145
-        $json = array(
3146
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3147
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3148
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3149
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3150
-            'notices'   => EE_Error::get_notices(),
3151
-            'content'   => isset($this->_template_args['admin_page_content'])
3152
-                ? $this->_template_args['admin_page_content'] : '',
3153
-            'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3154
-            'isEEajax'  => true
3155
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3156
-        );
3157
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3158
-        if (null === error_get_last() || ! headers_sent()) {
3159
-            header('Content-Type: application/json; charset=UTF-8');
3160
-        }
3161
-        echo wp_json_encode($json);
3162
-        exit();
3163
-    }
3164
-
3165
-
3166
-    /**
3167
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3168
-     *
3169
-     * @return void
3170
-     * @throws EE_Error
3171
-     * @throws InvalidArgumentException
3172
-     * @throws InvalidDataTypeException
3173
-     * @throws InvalidInterfaceException
3174
-     */
3175
-    public function return_json()
3176
-    {
3177
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3178
-            $this->_return_json();
3179
-        } else {
3180
-            throw new EE_Error(
3181
-                sprintf(
3182
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3183
-                    __FUNCTION__
3184
-                )
3185
-            );
3186
-        }
3187
-    }
3188
-
3189
-
3190
-    /**
3191
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3192
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3193
-     *
3194
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3195
-     */
3196
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3197
-    {
3198
-        $this->_hook_obj = $hook_obj;
3199
-    }
3200
-
3201
-
3202
-    /**
3203
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3204
-     *
3205
-     * @param boolean $about whether to use the special about page wrapper or default.
3206
-     * @return void
3207
-     * @throws DomainException
3208
-     * @throws EE_Error
3209
-     * @throws InvalidArgumentException
3210
-     * @throws InvalidDataTypeException
3211
-     * @throws InvalidInterfaceException
3212
-     */
3213
-    public function admin_page_wrapper($about = false)
3214
-    {
3215
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3216
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
3217
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
3218
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
3219
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3220
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3221
-            isset($this->_template_args['before_admin_page_content'])
3222
-                ? $this->_template_args['before_admin_page_content']
3223
-                : ''
3224
-        );
3225
-        $this->_template_args['after_admin_page_content'] = apply_filters(
3226
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3227
-            isset($this->_template_args['after_admin_page_content'])
3228
-                ? $this->_template_args['after_admin_page_content']
3229
-                : ''
3230
-        );
3231
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3232
-        // load settings page wrapper template
3233
-        $template_path = ! defined('DOING_AJAX')
3234
-            ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3235
-            : EE_ADMIN_TEMPLATE
3236
-              . 'admin_wrapper_ajax.template.php';
3237
-        // about page?
3238
-        $template_path = $about
3239
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3240
-            : $template_path;
3241
-        if (defined('DOING_AJAX')) {
3242
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3243
-                $template_path,
3244
-                $this->_template_args,
3245
-                true
3246
-            );
3247
-            $this->_return_json();
3248
-        } else {
3249
-            EEH_Template::display_template($template_path, $this->_template_args);
3250
-        }
3251
-    }
3252
-
3253
-
3254
-    /**
3255
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3256
-     *
3257
-     * @return string html
3258
-     * @throws EE_Error
3259
-     */
3260
-    protected function _get_main_nav_tabs()
3261
-    {
3262
-        // let's generate the html using the EEH_Tabbed_Content helper.
3263
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3264
-        // (rather than setting in the page_routes array)
3265
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3266
-    }
3267
-
3268
-
3269
-    /**
3270
-     *        sort nav tabs
3271
-     *
3272
-     * @param $a
3273
-     * @param $b
3274
-     * @return int
3275
-     */
3276
-    private function _sort_nav_tabs($a, $b)
3277
-    {
3278
-        if ($a['order'] === $b['order']) {
3279
-            return 0;
3280
-        }
3281
-        return ($a['order'] < $b['order']) ? -1 : 1;
3282
-    }
3283
-
3284
-
3285
-    /**
3286
-     * generates HTML for the forms used on admin pages
3287
-     *
3288
-     * @param array  $input_vars - array of input field details
3289
-     * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3290
-     * @param bool   $id
3291
-     * @return array|string
3292
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3293
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3294
-     */
3295
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3296
-    {
3297
-        return $generator === 'string'
3298
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3299
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3300
-    }
3301
-
3302
-
3303
-    /**
3304
-     * generates the "Save" and "Save & Close" buttons for edit forms
3305
-     *
3306
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3307
-     *                                   Close" button.
3308
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3309
-     *                                   'Save', [1] => 'save & close')
3310
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3311
-     *                                   via the "name" value in the button).  We can also use this to just dump
3312
-     *                                   default actions by submitting some other value.
3313
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3314
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3315
-     *                                   close (normal form handling).
3316
-     */
3317
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3318
-    {
3319
-        // make sure $text and $actions are in an array
3320
-        $text = (array) $text;
3321
-        $actions = (array) $actions;
3322
-        $referrer_url = empty($referrer)
3323
-            ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3324
-              . $_SERVER['REQUEST_URI']
3325
-              . '" />'
3326
-            : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3327
-              . $referrer
3328
-              . '" />';
3329
-        $button_text = ! empty($text)
3330
-            ? $text
3331
-            : array(
3332
-                esc_html__('Save', 'event_espresso'),
3333
-                esc_html__('Save and Close', 'event_espresso'),
3334
-            );
3335
-        $default_names = array('save', 'save_and_close');
3336
-        // add in a hidden index for the current page (so save and close redirects properly)
3337
-        $this->_template_args['save_buttons'] = $referrer_url;
3338
-        foreach ($button_text as $key => $button) {
3339
-            $ref = $default_names[ $key ];
3340
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3341
-                                                     . $ref
3342
-                                                     . '" value="'
3343
-                                                     . $button
3344
-                                                     . '" name="'
3345
-                                                     . (! empty($actions) ? $actions[ $key ] : $ref)
3346
-                                                     . '" id="'
3347
-                                                     . $this->_current_view . '_' . $ref
3348
-                                                     . '" />';
3349
-            if (! $both) {
3350
-                break;
3351
-            }
3352
-        }
3353
-    }
3354
-
3355
-
3356
-    /**
3357
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3358
-     *
3359
-     * @see   $this->_set_add_edit_form_tags() for details on params
3360
-     * @since 4.6.0
3361
-     * @param string $route
3362
-     * @param array  $additional_hidden_fields
3363
-     */
3364
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3365
-    {
3366
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3367
-    }
3368
-
3369
-
3370
-    /**
3371
-     * set form open and close tags on add/edit pages.
3372
-     *
3373
-     * @param string $route                    the route you want the form to direct to
3374
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3375
-     * @return void
3376
-     */
3377
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3378
-    {
3379
-        if (empty($route)) {
3380
-            $user_msg = esc_html__(
3381
-                'An error occurred. No action was set for this page\'s form.',
3382
-                'event_espresso'
3383
-            );
3384
-            $dev_msg = $user_msg . "\n"
3385
-                       . sprintf(
3386
-                           esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3387
-                           __FUNCTION__,
3388
-                           EE_Admin_Page::class
3389
-                       );
3390
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3391
-        }
3392
-        // open form
3393
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3394
-                                                             . $this->_admin_base_url
3395
-                                                             . '" id="'
3396
-                                                             . $route
3397
-                                                             . '_event_form" >';
3398
-        // add nonce
3399
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3400
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3401
-        // add REQUIRED form action
3402
-        $hidden_fields = array(
3403
-            'action' => array('type' => 'hidden', 'value' => $route),
3404
-        );
3405
-        // merge arrays
3406
-        $hidden_fields = is_array($additional_hidden_fields)
3407
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3408
-            : $hidden_fields;
3409
-        // generate form fields
3410
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3411
-        // add fields to form
3412
-        foreach ((array) $form_fields as $field_name => $form_field) {
3413
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3414
-        }
3415
-        // close form
3416
-        $this->_template_args['after_admin_page_content'] = '</form>';
3417
-    }
3418
-
3419
-
3420
-    /**
3421
-     * Public Wrapper for _redirect_after_action() method since its
3422
-     * discovered it would be useful for external code to have access.
3423
-     *
3424
-     * @param bool   $success
3425
-     * @param string $what
3426
-     * @param string $action_desc
3427
-     * @param array  $query_args
3428
-     * @param bool   $override_overwrite
3429
-     * @throws EE_Error
3430
-     * @throws InvalidArgumentException
3431
-     * @throws InvalidDataTypeException
3432
-     * @throws InvalidInterfaceException
3433
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3434
-     * @since 4.5.0
3435
-     */
3436
-    public function redirect_after_action(
3437
-        $success = false,
3438
-        $what = 'item',
3439
-        $action_desc = 'processed',
3440
-        $query_args = array(),
3441
-        $override_overwrite = false
3442
-    ) {
3443
-        $this->_redirect_after_action(
3444
-            $success,
3445
-            $what,
3446
-            $action_desc,
3447
-            $query_args,
3448
-            $override_overwrite
3449
-        );
3450
-    }
3451
-
3452
-
3453
-    /**
3454
-     * Helper method for merging existing request data with the returned redirect url.
3455
-     *
3456
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3457
-     * filters are still applied.
3458
-     *
3459
-     * @param array $new_route_data
3460
-     * @return array
3461
-     */
3462
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3463
-    {
3464
-        foreach ($this->_req_data as $ref => $value) {
3465
-            // unset nonces
3466
-            if (strpos($ref, 'nonce') !== false) {
3467
-                unset($this->_req_data[ $ref ]);
3468
-                continue;
3469
-            }
3470
-            // urlencode values.
3471
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3472
-            $this->_req_data[ $ref ] = $value;
3473
-        }
3474
-        return array_merge($this->_req_data, $new_route_data);
3475
-    }
3476
-
3477
-
3478
-    /**
3479
-     *    _redirect_after_action
3480
-     *
3481
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3482
-     * @param string $what               - what the action was performed on
3483
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3484
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3485
-     *                                   action is completed
3486
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3487
-     *                                   override this so that they show.
3488
-     * @return void
3489
-     * @throws EE_Error
3490
-     * @throws InvalidArgumentException
3491
-     * @throws InvalidDataTypeException
3492
-     * @throws InvalidInterfaceException
3493
-     */
3494
-    protected function _redirect_after_action(
3495
-        $success = 0,
3496
-        $what = 'item',
3497
-        $action_desc = 'processed',
3498
-        $query_args = array(),
3499
-        $override_overwrite = false
3500
-    ) {
3501
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3502
-        // class name for actions/filters.
3503
-        $classname = get_class($this);
3504
-        // set redirect url.
3505
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3506
-        // otherwise we go with whatever is set as the _admin_base_url
3507
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3508
-        $notices = EE_Error::get_notices(false);
3509
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3510
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3511
-            EE_Error::overwrite_success();
3512
-        }
3513
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3514
-            // how many records affected ? more than one record ? or just one ?
3515
-            if ($success > 1) {
3516
-                // set plural msg
3517
-                EE_Error::add_success(
3518
-                    sprintf(
3519
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3520
-                        $what,
3521
-                        $action_desc
3522
-                    ),
3523
-                    __FILE__,
3524
-                    __FUNCTION__,
3525
-                    __LINE__
3526
-                );
3527
-            } elseif ($success === 1) {
3528
-                // set singular msg
3529
-                EE_Error::add_success(
3530
-                    sprintf(
3531
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3532
-                        $what,
3533
-                        $action_desc
3534
-                    ),
3535
-                    __FILE__,
3536
-                    __FUNCTION__,
3537
-                    __LINE__
3538
-                );
3539
-            }
3540
-        }
3541
-        // check that $query_args isn't something crazy
3542
-        if (! is_array($query_args)) {
3543
-            $query_args = array();
3544
-        }
3545
-        /**
3546
-         * Allow injecting actions before the query_args are modified for possible different
3547
-         * redirections on save and close actions
3548
-         *
3549
-         * @since 4.2.0
3550
-         * @param array $query_args       The original query_args array coming into the
3551
-         *                                method.
3552
-         */
3553
-        do_action(
3554
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3555
-            $query_args
3556
-        );
3557
-        // calculate where we're going (if we have a "save and close" button pushed)
3558
-        if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3559
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3560
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3561
-            // regenerate query args array from referrer URL
3562
-            parse_str($parsed_url['query'], $query_args);
3563
-            // correct page and action will be in the query args now
3564
-            $redirect_url = admin_url('admin.php');
3565
-        }
3566
-        // merge any default query_args set in _default_route_query_args property
3567
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3568
-            $args_to_merge = array();
3569
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3570
-                // is there a wp_referer array in our _default_route_query_args property?
3571
-                if ($query_param === 'wp_referer') {
3572
-                    $query_value = (array) $query_value;
3573
-                    foreach ($query_value as $reference => $value) {
3574
-                        if (strpos($reference, 'nonce') !== false) {
3575
-                            continue;
3576
-                        }
3577
-                        // finally we will override any arguments in the referer with
3578
-                        // what might be set on the _default_route_query_args array.
3579
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3580
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3581
-                        } else {
3582
-                            $args_to_merge[ $reference ] = urlencode($value);
3583
-                        }
3584
-                    }
3585
-                    continue;
3586
-                }
3587
-                $args_to_merge[ $query_param ] = $query_value;
3588
-            }
3589
-            // now let's merge these arguments but override with what was specifically sent in to the
3590
-            // redirect.
3591
-            $query_args = array_merge($args_to_merge, $query_args);
3592
-        }
3593
-        $this->_process_notices($query_args);
3594
-        // generate redirect url
3595
-        // if redirecting to anything other than the main page, add a nonce
3596
-        if (isset($query_args['action'])) {
3597
-            // manually generate wp_nonce and merge that with the query vars
3598
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3599
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3600
-        }
3601
-        // we're adding some hooks and filters in here for processing any things just before redirects
3602
-        // (example: an admin page has done an insert or update and we want to run something after that).
3603
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3604
-        $redirect_url = apply_filters(
3605
-            'FHEE_redirect_' . $classname . $this->_req_action,
3606
-            EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3607
-            $query_args
3608
-        );
3609
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3610
-        if (defined('DOING_AJAX')) {
3611
-            $default_data = array(
3612
-                'close'        => true,
3613
-                'redirect_url' => $redirect_url,
3614
-                'where'        => 'main',
3615
-                'what'         => 'append',
3616
-            );
3617
-            $this->_template_args['success'] = $success;
3618
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3619
-                $default_data,
3620
-                $this->_template_args['data']
3621
-            ) : $default_data;
3622
-            $this->_return_json();
3623
-        }
3624
-        wp_safe_redirect($redirect_url);
3625
-        exit();
3626
-    }
3627
-
3628
-
3629
-    /**
3630
-     * process any notices before redirecting (or returning ajax request)
3631
-     * This method sets the $this->_template_args['notices'] attribute;
3632
-     *
3633
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3634
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3635
-     *                                  page_routes haven't been defined yet.
3636
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3637
-     *                                  still save a transient for the notice.
3638
-     * @return void
3639
-     * @throws EE_Error
3640
-     * @throws InvalidArgumentException
3641
-     * @throws InvalidDataTypeException
3642
-     * @throws InvalidInterfaceException
3643
-     */
3644
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3645
-    {
3646
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3647
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3648
-            $notices = EE_Error::get_notices(false);
3649
-            if (empty($this->_template_args['success'])) {
3650
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3651
-            }
3652
-            if (empty($this->_template_args['errors'])) {
3653
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3654
-            }
3655
-            if (empty($this->_template_args['attention'])) {
3656
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3657
-            }
3658
-        }
3659
-        $this->_template_args['notices'] = EE_Error::get_notices();
3660
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3661
-        if (! defined('DOING_AJAX') || $sticky_notices) {
3662
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3663
-            $this->_add_transient(
3664
-                $route,
3665
-                $this->_template_args['notices'],
3666
-                true,
3667
-                $skip_route_verify
3668
-            );
3669
-        }
3670
-    }
3671
-
3672
-
3673
-    /**
3674
-     * get_action_link_or_button
3675
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3676
-     *
3677
-     * @param string $action        use this to indicate which action the url is generated with.
3678
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3679
-     *                              property.
3680
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3681
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3682
-     * @param string $base_url      If this is not provided
3683
-     *                              the _admin_base_url will be used as the default for the button base_url.
3684
-     *                              Otherwise this value will be used.
3685
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3686
-     * @return string
3687
-     * @throws InvalidArgumentException
3688
-     * @throws InvalidInterfaceException
3689
-     * @throws InvalidDataTypeException
3690
-     * @throws EE_Error
3691
-     */
3692
-    public function get_action_link_or_button(
3693
-        $action,
3694
-        $type = 'add',
3695
-        $extra_request = array(),
3696
-        $class = 'button-primary',
3697
-        $base_url = '',
3698
-        $exclude_nonce = false
3699
-    ) {
3700
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3701
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3702
-            throw new EE_Error(
3703
-                sprintf(
3704
-                    esc_html__(
3705
-                        'There is no page route for given action for the button.  This action was given: %s',
3706
-                        'event_espresso'
3707
-                    ),
3708
-                    $action
3709
-                )
3710
-            );
3711
-        }
3712
-        if (! isset($this->_labels['buttons'][ $type ])) {
3713
-            throw new EE_Error(
3714
-                sprintf(
3715
-                    __(
3716
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3717
-                        'event_espresso'
3718
-                    ),
3719
-                    $type
3720
-                )
3721
-            );
3722
-        }
3723
-        // finally check user access for this button.
3724
-        $has_access = $this->check_user_access($action, true);
3725
-        if (! $has_access) {
3726
-            return '';
3727
-        }
3728
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3729
-        $query_args = array(
3730
-            'action' => $action,
3731
-        );
3732
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3733
-        if (! empty($extra_request)) {
3734
-            $query_args = array_merge($extra_request, $query_args);
3735
-        }
3736
-        $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3737
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3738
-    }
3739
-
3740
-
3741
-    /**
3742
-     * _per_page_screen_option
3743
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3744
-     *
3745
-     * @return void
3746
-     * @throws InvalidArgumentException
3747
-     * @throws InvalidInterfaceException
3748
-     * @throws InvalidDataTypeException
3749
-     */
3750
-    protected function _per_page_screen_option()
3751
-    {
3752
-        $option = 'per_page';
3753
-        $args = array(
3754
-            'label'   => apply_filters(
3755
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3756
-                $this->_admin_page_title,
3757
-                $this
3758
-            ),
3759
-            'default' => (int) apply_filters(
3760
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3761
-                20
3762
-            ),
3763
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3764
-        );
3765
-        // ONLY add the screen option if the user has access to it.
3766
-        if ($this->check_user_access($this->_current_view, true)) {
3767
-            add_screen_option($option, $args);
3768
-        }
3769
-    }
3770
-
3771
-
3772
-    /**
3773
-     * set_per_page_screen_option
3774
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3775
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3776
-     * admin_menu.
3777
-     *
3778
-     * @return void
3779
-     */
3780
-    private function _set_per_page_screen_options()
3781
-    {
3782
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3783
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3784
-            if (! $user = wp_get_current_user()) {
3785
-                return;
3786
-            }
3787
-            $option = $_POST['wp_screen_options']['option'];
3788
-            $value = $_POST['wp_screen_options']['value'];
3789
-            if ($option !== sanitize_key($option)) {
3790
-                return;
3791
-            }
3792
-            $map_option = $option;
3793
-            $option = str_replace('-', '_', $option);
3794
-            switch ($map_option) {
3795
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3796
-                    $value = (int) $value;
3797
-                    $max_value = apply_filters(
3798
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3799
-                        999,
3800
-                        $this->_current_page,
3801
-                        $this->_current_view
3802
-                    );
3803
-                    if ($value < 1) {
3804
-                        return;
3805
-                    }
3806
-                    $value = min($value, $max_value);
3807
-                    break;
3808
-                default:
3809
-                    $value = apply_filters(
3810
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3811
-                        false,
3812
-                        $option,
3813
-                        $value
3814
-                    );
3815
-                    if (false === $value) {
3816
-                        return;
3817
-                    }
3818
-                    break;
3819
-            }
3820
-            update_user_meta($user->ID, $option, $value);
3821
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3822
-            exit;
3823
-        }
3824
-    }
3825
-
3826
-
3827
-    /**
3828
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3829
-     *
3830
-     * @param array $data array that will be assigned to template args.
3831
-     */
3832
-    public function set_template_args($data)
3833
-    {
3834
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3835
-    }
3836
-
3837
-
3838
-    /**
3839
-     * This makes available the WP transient system for temporarily moving data between routes
3840
-     *
3841
-     * @param string $route             the route that should receive the transient
3842
-     * @param array  $data              the data that gets sent
3843
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3844
-     *                                  normal route transient.
3845
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3846
-     *                                  when we are adding a transient before page_routes have been defined.
3847
-     * @return void
3848
-     * @throws EE_Error
3849
-     */
3850
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3851
-    {
3852
-        $user_id = get_current_user_id();
3853
-        if (! $skip_route_verify) {
3854
-            $this->_verify_route($route);
3855
-        }
3856
-        // now let's set the string for what kind of transient we're setting
3857
-        $transient = $notices
3858
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3859
-            : 'rte_tx_' . $route . '_' . $user_id;
3860
-        $data = $notices ? array('notices' => $data) : $data;
3861
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3862
-        $existing = is_multisite() && is_network_admin()
3863
-            ? get_site_transient($transient)
3864
-            : get_transient($transient);
3865
-        if ($existing) {
3866
-            $data = array_merge((array) $data, (array) $existing);
3867
-        }
3868
-        if (is_multisite() && is_network_admin()) {
3869
-            set_site_transient($transient, $data, 8);
3870
-        } else {
3871
-            set_transient($transient, $data, 8);
3872
-        }
3873
-    }
3874
-
3875
-
3876
-    /**
3877
-     * this retrieves the temporary transient that has been set for moving data between routes.
3878
-     *
3879
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3880
-     * @param string $route
3881
-     * @return mixed data
3882
-     */
3883
-    protected function _get_transient($notices = false, $route = '')
3884
-    {
3885
-        $user_id = get_current_user_id();
3886
-        $route = ! $route ? $this->_req_action : $route;
3887
-        $transient = $notices
3888
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3889
-            : 'rte_tx_' . $route . '_' . $user_id;
3890
-        $data = is_multisite() && is_network_admin()
3891
-            ? get_site_transient($transient)
3892
-            : get_transient($transient);
3893
-        // delete transient after retrieval (just in case it hasn't expired);
3894
-        if (is_multisite() && is_network_admin()) {
3895
-            delete_site_transient($transient);
3896
-        } else {
3897
-            delete_transient($transient);
3898
-        }
3899
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3900
-    }
3901
-
3902
-
3903
-    /**
3904
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3905
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3906
-     * default route callback on the EE_Admin page you want it run.)
3907
-     *
3908
-     * @return void
3909
-     */
3910
-    protected function _transient_garbage_collection()
3911
-    {
3912
-        global $wpdb;
3913
-        // retrieve all existing transients
3914
-        $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3915
-        if ($results = $wpdb->get_results($query)) {
3916
-            foreach ($results as $result) {
3917
-                $transient = str_replace('_transient_', '', $result->option_name);
3918
-                get_transient($transient);
3919
-                if (is_multisite() && is_network_admin()) {
3920
-                    get_site_transient($transient);
3921
-                }
3922
-            }
3923
-        }
3924
-    }
3925
-
3926
-
3927
-    /**
3928
-     * get_view
3929
-     *
3930
-     * @return string content of _view property
3931
-     */
3932
-    public function get_view()
3933
-    {
3934
-        return $this->_view;
3935
-    }
3936
-
3937
-
3938
-    /**
3939
-     * getter for the protected $_views property
3940
-     *
3941
-     * @return array
3942
-     */
3943
-    public function get_views()
3944
-    {
3945
-        return $this->_views;
3946
-    }
3947
-
3948
-
3949
-    /**
3950
-     * get_current_page
3951
-     *
3952
-     * @return string _current_page property value
3953
-     */
3954
-    public function get_current_page()
3955
-    {
3956
-        return $this->_current_page;
3957
-    }
3958
-
3959
-
3960
-    /**
3961
-     * get_current_view
3962
-     *
3963
-     * @return string _current_view property value
3964
-     */
3965
-    public function get_current_view()
3966
-    {
3967
-        return $this->_current_view;
3968
-    }
3969
-
3970
-
3971
-    /**
3972
-     * get_current_screen
3973
-     *
3974
-     * @return object The current WP_Screen object
3975
-     */
3976
-    public function get_current_screen()
3977
-    {
3978
-        return $this->_current_screen;
3979
-    }
3980
-
3981
-
3982
-    /**
3983
-     * get_current_page_view_url
3984
-     *
3985
-     * @return string This returns the url for the current_page_view.
3986
-     */
3987
-    public function get_current_page_view_url()
3988
-    {
3989
-        return $this->_current_page_view_url;
3990
-    }
3991
-
3992
-
3993
-    /**
3994
-     * just returns the _req_data property
3995
-     *
3996
-     * @return array
3997
-     */
3998
-    public function get_request_data()
3999
-    {
4000
-        return $this->_req_data;
4001
-    }
4002
-
4003
-
4004
-    /**
4005
-     * returns the _req_data protected property
4006
-     *
4007
-     * @return string
4008
-     */
4009
-    public function get_req_action()
4010
-    {
4011
-        return $this->_req_action;
4012
-    }
4013
-
4014
-
4015
-    /**
4016
-     * @return bool  value of $_is_caf property
4017
-     */
4018
-    public function is_caf()
4019
-    {
4020
-        return $this->_is_caf;
4021
-    }
4022
-
4023
-
4024
-    /**
4025
-     * @return mixed
4026
-     */
4027
-    public function default_espresso_metaboxes()
4028
-    {
4029
-        return $this->_default_espresso_metaboxes;
4030
-    }
4031
-
4032
-
4033
-    /**
4034
-     * @return mixed
4035
-     */
4036
-    public function admin_base_url()
4037
-    {
4038
-        return $this->_admin_base_url;
4039
-    }
4040
-
4041
-
4042
-    /**
4043
-     * @return mixed
4044
-     */
4045
-    public function wp_page_slug()
4046
-    {
4047
-        return $this->_wp_page_slug;
4048
-    }
4049
-
4050
-
4051
-    /**
4052
-     * updates  espresso configuration settings
4053
-     *
4054
-     * @param string                   $tab
4055
-     * @param EE_Config_Base|EE_Config $config
4056
-     * @param string                   $file file where error occurred
4057
-     * @param string                   $func function  where error occurred
4058
-     * @param string                   $line line no where error occurred
4059
-     * @return boolean
4060
-     */
4061
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4062
-    {
4063
-        // remove any options that are NOT going to be saved with the config settings.
4064
-        if (isset($config->core->ee_ueip_optin)) {
4065
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4066
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4067
-            update_option('ee_ueip_has_notified', true);
4068
-        }
4069
-        // and save it (note we're also doing the network save here)
4070
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4071
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4072
-        if ($config_saved && $net_saved) {
4073
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4074
-            return true;
4075
-        }
4076
-        EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4077
-        return false;
4078
-    }
4079
-
4080
-
4081
-    /**
4082
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4083
-     *
4084
-     * @return array
4085
-     */
4086
-    public function get_yes_no_values()
4087
-    {
4088
-        return $this->_yes_no_values;
4089
-    }
4090
-
4091
-
4092
-    /**
4093
-     * @return string
4094
-     * @throws ReflectionException
4095
-     * @since $VID:$
4096
-     */
4097
-    protected function _get_dir()
4098
-    {
4099
-        $reflector = new ReflectionClass(get_class($this));
4100
-        return dirname($reflector->getFileName());
4101
-    }
4102
-
4103
-
4104
-    /**
4105
-     * A helper for getting a "next link".
4106
-     *
4107
-     * @param string $url   The url to link to
4108
-     * @param string $class The class to use.
4109
-     * @return string
4110
-     */
4111
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4112
-    {
4113
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4114
-    }
4115
-
4116
-
4117
-    /**
4118
-     * A helper for getting a "previous link".
4119
-     *
4120
-     * @param string $url   The url to link to
4121
-     * @param string $class The class to use.
4122
-     * @return string
4123
-     */
4124
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4125
-    {
4126
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4127
-    }
4128
-
4129
-
4130
-
4131
-
4132
-
4133
-
4134
-
4135
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4136
-
4137
-
4138
-    /**
4139
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4140
-     * 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
4141
-     * _req_data array.
4142
-     *
4143
-     * @return bool success/fail
4144
-     * @throws EE_Error
4145
-     * @throws InvalidArgumentException
4146
-     * @throws ReflectionException
4147
-     * @throws InvalidDataTypeException
4148
-     * @throws InvalidInterfaceException
4149
-     */
4150
-    protected function _process_resend_registration()
4151
-    {
4152
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4153
-        do_action(
4154
-            'AHEE__EE_Admin_Page___process_resend_registration',
4155
-            $this->_template_args['success'],
4156
-            $this->_req_data
4157
-        );
4158
-        return $this->_template_args['success'];
4159
-    }
4160
-
4161
-
4162
-    /**
4163
-     * This automatically processes any payment message notifications when manual payment has been applied.
4164
-     *
4165
-     * @param EE_Payment $payment
4166
-     * @return bool success/fail
4167
-     */
4168
-    protected function _process_payment_notification(EE_Payment $payment)
4169
-    {
4170
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4171
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4172
-        $this->_template_args['success'] = apply_filters(
4173
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4174
-            false,
4175
-            $payment
4176
-        );
4177
-        return $this->_template_args['success'];
4178
-    }
2701
+	}
2702
+
2703
+
2704
+	/**
2705
+	 * facade for add_meta_box
2706
+	 *
2707
+	 * @param string  $action        where the metabox get's displayed
2708
+	 * @param string  $title         Title of Metabox (output in metabox header)
2709
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2710
+	 *                               instead of the one created in here.
2711
+	 * @param array   $callback_args an array of args supplied for the metabox
2712
+	 * @param string  $column        what metabox column
2713
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2714
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2715
+	 *                               created but just set our own callback for wp's add_meta_box.
2716
+	 * @throws DomainException
2717
+	 */
2718
+	public function _add_admin_page_meta_box(
2719
+		$action,
2720
+		$title,
2721
+		$callback,
2722
+		$callback_args,
2723
+		$column = 'normal',
2724
+		$priority = 'high',
2725
+		$create_func = true
2726
+	) {
2727
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2728
+		// 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.
2729
+		if (empty($callback_args) && $create_func) {
2730
+			$callback_args = array(
2731
+				'template_path' => $this->_template_path,
2732
+				'template_args' => $this->_template_args,
2733
+			);
2734
+		}
2735
+		// 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)
2736
+		$call_back_func = $create_func
2737
+			? static function ($post, $metabox) {
2738
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2739
+				echo EEH_Template::display_template(
2740
+					$metabox['args']['template_path'],
2741
+					$metabox['args']['template_args'],
2742
+					true
2743
+				);
2744
+			}
2745
+			: $callback;
2746
+		add_meta_box(
2747
+			str_replace('_', '-', $action) . '-mbox',
2748
+			$title,
2749
+			$call_back_func,
2750
+			$this->_wp_page_slug,
2751
+			$column,
2752
+			$priority,
2753
+			$callback_args
2754
+		);
2755
+	}
2756
+
2757
+
2758
+	/**
2759
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2760
+	 *
2761
+	 * @throws DomainException
2762
+	 * @throws EE_Error
2763
+	 * @throws InvalidArgumentException
2764
+	 * @throws InvalidDataTypeException
2765
+	 * @throws InvalidInterfaceException
2766
+	 */
2767
+	public function display_admin_page_with_metabox_columns()
2768
+	{
2769
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2770
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2771
+			$this->_column_template_path,
2772
+			$this->_template_args,
2773
+			true
2774
+		);
2775
+		// the final wrapper
2776
+		$this->admin_page_wrapper();
2777
+	}
2778
+
2779
+
2780
+	/**
2781
+	 * generates  HTML wrapper for an admin details page
2782
+	 *
2783
+	 * @return void
2784
+	 * @throws DomainException
2785
+	 * @throws EE_Error
2786
+	 * @throws InvalidArgumentException
2787
+	 * @throws InvalidDataTypeException
2788
+	 * @throws InvalidInterfaceException
2789
+	 */
2790
+	public function display_admin_page_with_sidebar()
2791
+	{
2792
+		$this->_display_admin_page(true);
2793
+	}
2794
+
2795
+
2796
+	/**
2797
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2798
+	 *
2799
+	 * @return void
2800
+	 * @throws DomainException
2801
+	 * @throws EE_Error
2802
+	 * @throws InvalidArgumentException
2803
+	 * @throws InvalidDataTypeException
2804
+	 * @throws InvalidInterfaceException
2805
+	 */
2806
+	public function display_admin_page_with_no_sidebar()
2807
+	{
2808
+		$this->_display_admin_page();
2809
+	}
2810
+
2811
+
2812
+	/**
2813
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2814
+	 *
2815
+	 * @return void
2816
+	 * @throws DomainException
2817
+	 * @throws EE_Error
2818
+	 * @throws InvalidArgumentException
2819
+	 * @throws InvalidDataTypeException
2820
+	 * @throws InvalidInterfaceException
2821
+	 */
2822
+	public function display_about_admin_page()
2823
+	{
2824
+		$this->_display_admin_page(false, true);
2825
+	}
2826
+
2827
+
2828
+	/**
2829
+	 * display_admin_page
2830
+	 * contains the code for actually displaying an admin page
2831
+	 *
2832
+	 * @param boolean $sidebar true with sidebar, false without
2833
+	 * @param boolean $about   use the about admin wrapper instead of the default.
2834
+	 * @return void
2835
+	 * @throws DomainException
2836
+	 * @throws EE_Error
2837
+	 * @throws InvalidArgumentException
2838
+	 * @throws InvalidDataTypeException
2839
+	 * @throws InvalidInterfaceException
2840
+	 */
2841
+	private function _display_admin_page($sidebar = false, $about = false)
2842
+	{
2843
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2844
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2845
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2846
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2847
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2848
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2849
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2850
+			? 'poststuff'
2851
+			: 'espresso-default-admin';
2852
+		$template_path = $sidebar
2853
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2854
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2855
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2856
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2857
+		}
2858
+		$template_path = ! empty($this->_column_template_path)
2859
+			? $this->_column_template_path : $template_path;
2860
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2861
+			? $this->_template_args['admin_page_content']
2862
+			: '';
2863
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2864
+			? $this->_template_args['before_admin_page_content']
2865
+			: '';
2866
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2867
+			? $this->_template_args['after_admin_page_content']
2868
+			: '';
2869
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2870
+			$template_path,
2871
+			$this->_template_args,
2872
+			true
2873
+		);
2874
+		// the final template wrapper
2875
+		$this->admin_page_wrapper($about);
2876
+	}
2877
+
2878
+
2879
+	/**
2880
+	 * This is used to display caf preview pages.
2881
+	 *
2882
+	 * @since 4.3.2
2883
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2884
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2885
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2886
+	 * @return void
2887
+	 * @throws DomainException
2888
+	 * @throws EE_Error
2889
+	 * @throws InvalidArgumentException
2890
+	 * @throws InvalidDataTypeException
2891
+	 * @throws InvalidInterfaceException
2892
+	 */
2893
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2894
+	{
2895
+		// let's generate a default preview action button if there isn't one already present.
2896
+		$this->_labels['buttons']['buy_now'] = esc_html__(
2897
+			'Upgrade to Event Espresso 4 Right Now',
2898
+			'event_espresso'
2899
+		);
2900
+		$buy_now_url = add_query_arg(
2901
+			array(
2902
+				'ee_ver'       => 'ee4',
2903
+				'utm_source'   => 'ee4_plugin_admin',
2904
+				'utm_medium'   => 'link',
2905
+				'utm_campaign' => $utm_campaign_source,
2906
+				'utm_content'  => 'buy_now_button',
2907
+			),
2908
+			'http://eventespresso.com/pricing/'
2909
+		);
2910
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2911
+			? $this->get_action_link_or_button(
2912
+				'',
2913
+				'buy_now',
2914
+				array(),
2915
+				'button-primary button-large',
2916
+				$buy_now_url,
2917
+				true
2918
+			)
2919
+			: $this->_template_args['preview_action_button'];
2920
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2921
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2922
+			$this->_template_args,
2923
+			true
2924
+		);
2925
+		$this->_display_admin_page($display_sidebar);
2926
+	}
2927
+
2928
+
2929
+	/**
2930
+	 * display_admin_list_table_page_with_sidebar
2931
+	 * generates HTML wrapper for an admin_page with list_table
2932
+	 *
2933
+	 * @return void
2934
+	 * @throws DomainException
2935
+	 * @throws EE_Error
2936
+	 * @throws InvalidArgumentException
2937
+	 * @throws InvalidDataTypeException
2938
+	 * @throws InvalidInterfaceException
2939
+	 */
2940
+	public function display_admin_list_table_page_with_sidebar()
2941
+	{
2942
+		$this->_display_admin_list_table_page(true);
2943
+	}
2944
+
2945
+
2946
+	/**
2947
+	 * display_admin_list_table_page_with_no_sidebar
2948
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2949
+	 *
2950
+	 * @return void
2951
+	 * @throws DomainException
2952
+	 * @throws EE_Error
2953
+	 * @throws InvalidArgumentException
2954
+	 * @throws InvalidDataTypeException
2955
+	 * @throws InvalidInterfaceException
2956
+	 */
2957
+	public function display_admin_list_table_page_with_no_sidebar()
2958
+	{
2959
+		$this->_display_admin_list_table_page();
2960
+	}
2961
+
2962
+
2963
+	/**
2964
+	 * generates html wrapper for an admin_list_table page
2965
+	 *
2966
+	 * @param boolean $sidebar whether to display with sidebar or not.
2967
+	 * @return void
2968
+	 * @throws DomainException
2969
+	 * @throws EE_Error
2970
+	 * @throws InvalidArgumentException
2971
+	 * @throws InvalidDataTypeException
2972
+	 * @throws InvalidInterfaceException
2973
+	 */
2974
+	private function _display_admin_list_table_page($sidebar = false)
2975
+	{
2976
+		// setup search attributes
2977
+		$this->_set_search_attributes();
2978
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2979
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2980
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2981
+			? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2982
+			: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2983
+		$this->_template_args['list_table'] = $this->_list_table_object;
2984
+		$this->_template_args['current_route'] = $this->_req_action;
2985
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2986
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2987
+		if (! empty($ajax_sorting_callback)) {
2988
+			$sortable_list_table_form_fields = wp_nonce_field(
2989
+				$ajax_sorting_callback . '_nonce',
2990
+				$ajax_sorting_callback . '_nonce',
2991
+				false,
2992
+				false
2993
+			);
2994
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2995
+												. $this->page_slug
2996
+												. '" />';
2997
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2998
+												. $ajax_sorting_callback
2999
+												. '" />';
3000
+		} else {
3001
+			$sortable_list_table_form_fields = '';
3002
+		}
3003
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3004
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
3005
+			? $this->_template_args['list_table_hidden_fields']
3006
+			: '';
3007
+		$nonce_ref = $this->_req_action . '_nonce';
3008
+		$hidden_form_fields .= '<input type="hidden" name="'
3009
+							   . $nonce_ref
3010
+							   . '" value="'
3011
+							   . wp_create_nonce($nonce_ref)
3012
+							   . '">';
3013
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3014
+		// display message about search results?
3015
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3016
+			? '<p class="ee-search-results">' . sprintf(
3017
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3018
+				trim($this->_req_data['s'], '%')
3019
+			) . '</p>'
3020
+			: '';
3021
+		// filter before_list_table template arg
3022
+		$this->_template_args['before_list_table'] = apply_filters(
3023
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3024
+			$this->_template_args['before_list_table'],
3025
+			$this->page_slug,
3026
+			$this->_req_data,
3027
+			$this->_req_action
3028
+		);
3029
+		// convert to array and filter again
3030
+		// arrays are easier to inject new items in a specific location,
3031
+		// but would not be backwards compatible, so we have to add a new filter
3032
+		$this->_template_args['before_list_table'] = implode(
3033
+			" \n",
3034
+			(array) apply_filters(
3035
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3036
+				(array) $this->_template_args['before_list_table'],
3037
+				$this->page_slug,
3038
+				$this->_req_data,
3039
+				$this->_req_action
3040
+			)
3041
+		);
3042
+		// filter after_list_table template arg
3043
+		$this->_template_args['after_list_table'] = apply_filters(
3044
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3045
+			$this->_template_args['after_list_table'],
3046
+			$this->page_slug,
3047
+			$this->_req_data,
3048
+			$this->_req_action
3049
+		);
3050
+		// convert to array and filter again
3051
+		// arrays are easier to inject new items in a specific location,
3052
+		// but would not be backwards compatible, so we have to add a new filter
3053
+		$this->_template_args['after_list_table'] = implode(
3054
+			" \n",
3055
+			(array) apply_filters(
3056
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3057
+				(array) $this->_template_args['after_list_table'],
3058
+				$this->page_slug,
3059
+				$this->_req_data,
3060
+				$this->_req_action
3061
+			)
3062
+		);
3063
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3064
+			$template_path,
3065
+			$this->_template_args,
3066
+			true
3067
+		);
3068
+		// the final template wrapper
3069
+		if ($sidebar) {
3070
+			$this->display_admin_page_with_sidebar();
3071
+		} else {
3072
+			$this->display_admin_page_with_no_sidebar();
3073
+		}
3074
+	}
3075
+
3076
+
3077
+	/**
3078
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3079
+	 * html string for the legend.
3080
+	 * $items are expected in an array in the following format:
3081
+	 * $legend_items = array(
3082
+	 *        'item_id' => array(
3083
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3084
+	 *            'desc' => esc_html__('localized description of item');
3085
+	 *        )
3086
+	 * );
3087
+	 *
3088
+	 * @param  array $items see above for format of array
3089
+	 * @return string html string of legend
3090
+	 * @throws DomainException
3091
+	 */
3092
+	protected function _display_legend($items)
3093
+	{
3094
+		$this->_template_args['items'] = apply_filters(
3095
+			'FHEE__EE_Admin_Page___display_legend__items',
3096
+			(array) $items,
3097
+			$this
3098
+		);
3099
+		/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
3100
+		$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
3101
+		if (! $status_change_notice->isDismissed()) {
3102
+			$this->_template_args['status_change_notice'] = EEH_Template::display_template(
3103
+				EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
3104
+				[ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
3105
+				true
3106
+			);
3107
+		}
3108
+		return EEH_Template::display_template(
3109
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3110
+			$this->_template_args,
3111
+			true
3112
+		);
3113
+	}
3114
+
3115
+
3116
+	/**
3117
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3118
+	 * The returned json object is created from an array in the following format:
3119
+	 * array(
3120
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3121
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3122
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3123
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3124
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3125
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3126
+	 *  that might be included in here)
3127
+	 * )
3128
+	 * The json object is populated by whatever is set in the $_template_args property.
3129
+	 *
3130
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3131
+	 *                                 instead of displayed.
3132
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3133
+	 * @return void
3134
+	 * @throws EE_Error
3135
+	 * @throws InvalidArgumentException
3136
+	 * @throws InvalidDataTypeException
3137
+	 * @throws InvalidInterfaceException
3138
+	 */
3139
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
3140
+	{
3141
+		// make sure any EE_Error notices have been handled.
3142
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3143
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3144
+		unset($this->_template_args['data']);
3145
+		$json = array(
3146
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3147
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3148
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3149
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3150
+			'notices'   => EE_Error::get_notices(),
3151
+			'content'   => isset($this->_template_args['admin_page_content'])
3152
+				? $this->_template_args['admin_page_content'] : '',
3153
+			'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3154
+			'isEEajax'  => true
3155
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3156
+		);
3157
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3158
+		if (null === error_get_last() || ! headers_sent()) {
3159
+			header('Content-Type: application/json; charset=UTF-8');
3160
+		}
3161
+		echo wp_json_encode($json);
3162
+		exit();
3163
+	}
3164
+
3165
+
3166
+	/**
3167
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3168
+	 *
3169
+	 * @return void
3170
+	 * @throws EE_Error
3171
+	 * @throws InvalidArgumentException
3172
+	 * @throws InvalidDataTypeException
3173
+	 * @throws InvalidInterfaceException
3174
+	 */
3175
+	public function return_json()
3176
+	{
3177
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3178
+			$this->_return_json();
3179
+		} else {
3180
+			throw new EE_Error(
3181
+				sprintf(
3182
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3183
+					__FUNCTION__
3184
+				)
3185
+			);
3186
+		}
3187
+	}
3188
+
3189
+
3190
+	/**
3191
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3192
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3193
+	 *
3194
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3195
+	 */
3196
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3197
+	{
3198
+		$this->_hook_obj = $hook_obj;
3199
+	}
3200
+
3201
+
3202
+	/**
3203
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3204
+	 *
3205
+	 * @param boolean $about whether to use the special about page wrapper or default.
3206
+	 * @return void
3207
+	 * @throws DomainException
3208
+	 * @throws EE_Error
3209
+	 * @throws InvalidArgumentException
3210
+	 * @throws InvalidDataTypeException
3211
+	 * @throws InvalidInterfaceException
3212
+	 */
3213
+	public function admin_page_wrapper($about = false)
3214
+	{
3215
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3216
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
3217
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
3218
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
3219
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3220
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3221
+			isset($this->_template_args['before_admin_page_content'])
3222
+				? $this->_template_args['before_admin_page_content']
3223
+				: ''
3224
+		);
3225
+		$this->_template_args['after_admin_page_content'] = apply_filters(
3226
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3227
+			isset($this->_template_args['after_admin_page_content'])
3228
+				? $this->_template_args['after_admin_page_content']
3229
+				: ''
3230
+		);
3231
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3232
+		// load settings page wrapper template
3233
+		$template_path = ! defined('DOING_AJAX')
3234
+			? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3235
+			: EE_ADMIN_TEMPLATE
3236
+			  . 'admin_wrapper_ajax.template.php';
3237
+		// about page?
3238
+		$template_path = $about
3239
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3240
+			: $template_path;
3241
+		if (defined('DOING_AJAX')) {
3242
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3243
+				$template_path,
3244
+				$this->_template_args,
3245
+				true
3246
+			);
3247
+			$this->_return_json();
3248
+		} else {
3249
+			EEH_Template::display_template($template_path, $this->_template_args);
3250
+		}
3251
+	}
3252
+
3253
+
3254
+	/**
3255
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3256
+	 *
3257
+	 * @return string html
3258
+	 * @throws EE_Error
3259
+	 */
3260
+	protected function _get_main_nav_tabs()
3261
+	{
3262
+		// let's generate the html using the EEH_Tabbed_Content helper.
3263
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3264
+		// (rather than setting in the page_routes array)
3265
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3266
+	}
3267
+
3268
+
3269
+	/**
3270
+	 *        sort nav tabs
3271
+	 *
3272
+	 * @param $a
3273
+	 * @param $b
3274
+	 * @return int
3275
+	 */
3276
+	private function _sort_nav_tabs($a, $b)
3277
+	{
3278
+		if ($a['order'] === $b['order']) {
3279
+			return 0;
3280
+		}
3281
+		return ($a['order'] < $b['order']) ? -1 : 1;
3282
+	}
3283
+
3284
+
3285
+	/**
3286
+	 * generates HTML for the forms used on admin pages
3287
+	 *
3288
+	 * @param array  $input_vars - array of input field details
3289
+	 * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3290
+	 * @param bool   $id
3291
+	 * @return array|string
3292
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3293
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3294
+	 */
3295
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3296
+	{
3297
+		return $generator === 'string'
3298
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3299
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3300
+	}
3301
+
3302
+
3303
+	/**
3304
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3305
+	 *
3306
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3307
+	 *                                   Close" button.
3308
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3309
+	 *                                   'Save', [1] => 'save & close')
3310
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3311
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3312
+	 *                                   default actions by submitting some other value.
3313
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3314
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3315
+	 *                                   close (normal form handling).
3316
+	 */
3317
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3318
+	{
3319
+		// make sure $text and $actions are in an array
3320
+		$text = (array) $text;
3321
+		$actions = (array) $actions;
3322
+		$referrer_url = empty($referrer)
3323
+			? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3324
+			  . $_SERVER['REQUEST_URI']
3325
+			  . '" />'
3326
+			: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3327
+			  . $referrer
3328
+			  . '" />';
3329
+		$button_text = ! empty($text)
3330
+			? $text
3331
+			: array(
3332
+				esc_html__('Save', 'event_espresso'),
3333
+				esc_html__('Save and Close', 'event_espresso'),
3334
+			);
3335
+		$default_names = array('save', 'save_and_close');
3336
+		// add in a hidden index for the current page (so save and close redirects properly)
3337
+		$this->_template_args['save_buttons'] = $referrer_url;
3338
+		foreach ($button_text as $key => $button) {
3339
+			$ref = $default_names[ $key ];
3340
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3341
+													 . $ref
3342
+													 . '" value="'
3343
+													 . $button
3344
+													 . '" name="'
3345
+													 . (! empty($actions) ? $actions[ $key ] : $ref)
3346
+													 . '" id="'
3347
+													 . $this->_current_view . '_' . $ref
3348
+													 . '" />';
3349
+			if (! $both) {
3350
+				break;
3351
+			}
3352
+		}
3353
+	}
3354
+
3355
+
3356
+	/**
3357
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3358
+	 *
3359
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3360
+	 * @since 4.6.0
3361
+	 * @param string $route
3362
+	 * @param array  $additional_hidden_fields
3363
+	 */
3364
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3365
+	{
3366
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3367
+	}
3368
+
3369
+
3370
+	/**
3371
+	 * set form open and close tags on add/edit pages.
3372
+	 *
3373
+	 * @param string $route                    the route you want the form to direct to
3374
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3375
+	 * @return void
3376
+	 */
3377
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3378
+	{
3379
+		if (empty($route)) {
3380
+			$user_msg = esc_html__(
3381
+				'An error occurred. No action was set for this page\'s form.',
3382
+				'event_espresso'
3383
+			);
3384
+			$dev_msg = $user_msg . "\n"
3385
+					   . sprintf(
3386
+						   esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3387
+						   __FUNCTION__,
3388
+						   EE_Admin_Page::class
3389
+					   );
3390
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3391
+		}
3392
+		// open form
3393
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3394
+															 . $this->_admin_base_url
3395
+															 . '" id="'
3396
+															 . $route
3397
+															 . '_event_form" >';
3398
+		// add nonce
3399
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3400
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3401
+		// add REQUIRED form action
3402
+		$hidden_fields = array(
3403
+			'action' => array('type' => 'hidden', 'value' => $route),
3404
+		);
3405
+		// merge arrays
3406
+		$hidden_fields = is_array($additional_hidden_fields)
3407
+			? array_merge($hidden_fields, $additional_hidden_fields)
3408
+			: $hidden_fields;
3409
+		// generate form fields
3410
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3411
+		// add fields to form
3412
+		foreach ((array) $form_fields as $field_name => $form_field) {
3413
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3414
+		}
3415
+		// close form
3416
+		$this->_template_args['after_admin_page_content'] = '</form>';
3417
+	}
3418
+
3419
+
3420
+	/**
3421
+	 * Public Wrapper for _redirect_after_action() method since its
3422
+	 * discovered it would be useful for external code to have access.
3423
+	 *
3424
+	 * @param bool   $success
3425
+	 * @param string $what
3426
+	 * @param string $action_desc
3427
+	 * @param array  $query_args
3428
+	 * @param bool   $override_overwrite
3429
+	 * @throws EE_Error
3430
+	 * @throws InvalidArgumentException
3431
+	 * @throws InvalidDataTypeException
3432
+	 * @throws InvalidInterfaceException
3433
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3434
+	 * @since 4.5.0
3435
+	 */
3436
+	public function redirect_after_action(
3437
+		$success = false,
3438
+		$what = 'item',
3439
+		$action_desc = 'processed',
3440
+		$query_args = array(),
3441
+		$override_overwrite = false
3442
+	) {
3443
+		$this->_redirect_after_action(
3444
+			$success,
3445
+			$what,
3446
+			$action_desc,
3447
+			$query_args,
3448
+			$override_overwrite
3449
+		);
3450
+	}
3451
+
3452
+
3453
+	/**
3454
+	 * Helper method for merging existing request data with the returned redirect url.
3455
+	 *
3456
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3457
+	 * filters are still applied.
3458
+	 *
3459
+	 * @param array $new_route_data
3460
+	 * @return array
3461
+	 */
3462
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3463
+	{
3464
+		foreach ($this->_req_data as $ref => $value) {
3465
+			// unset nonces
3466
+			if (strpos($ref, 'nonce') !== false) {
3467
+				unset($this->_req_data[ $ref ]);
3468
+				continue;
3469
+			}
3470
+			// urlencode values.
3471
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3472
+			$this->_req_data[ $ref ] = $value;
3473
+		}
3474
+		return array_merge($this->_req_data, $new_route_data);
3475
+	}
3476
+
3477
+
3478
+	/**
3479
+	 *    _redirect_after_action
3480
+	 *
3481
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3482
+	 * @param string $what               - what the action was performed on
3483
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3484
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3485
+	 *                                   action is completed
3486
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3487
+	 *                                   override this so that they show.
3488
+	 * @return void
3489
+	 * @throws EE_Error
3490
+	 * @throws InvalidArgumentException
3491
+	 * @throws InvalidDataTypeException
3492
+	 * @throws InvalidInterfaceException
3493
+	 */
3494
+	protected function _redirect_after_action(
3495
+		$success = 0,
3496
+		$what = 'item',
3497
+		$action_desc = 'processed',
3498
+		$query_args = array(),
3499
+		$override_overwrite = false
3500
+	) {
3501
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3502
+		// class name for actions/filters.
3503
+		$classname = get_class($this);
3504
+		// set redirect url.
3505
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3506
+		// otherwise we go with whatever is set as the _admin_base_url
3507
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3508
+		$notices = EE_Error::get_notices(false);
3509
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3510
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3511
+			EE_Error::overwrite_success();
3512
+		}
3513
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3514
+			// how many records affected ? more than one record ? or just one ?
3515
+			if ($success > 1) {
3516
+				// set plural msg
3517
+				EE_Error::add_success(
3518
+					sprintf(
3519
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3520
+						$what,
3521
+						$action_desc
3522
+					),
3523
+					__FILE__,
3524
+					__FUNCTION__,
3525
+					__LINE__
3526
+				);
3527
+			} elseif ($success === 1) {
3528
+				// set singular msg
3529
+				EE_Error::add_success(
3530
+					sprintf(
3531
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3532
+						$what,
3533
+						$action_desc
3534
+					),
3535
+					__FILE__,
3536
+					__FUNCTION__,
3537
+					__LINE__
3538
+				);
3539
+			}
3540
+		}
3541
+		// check that $query_args isn't something crazy
3542
+		if (! is_array($query_args)) {
3543
+			$query_args = array();
3544
+		}
3545
+		/**
3546
+		 * Allow injecting actions before the query_args are modified for possible different
3547
+		 * redirections on save and close actions
3548
+		 *
3549
+		 * @since 4.2.0
3550
+		 * @param array $query_args       The original query_args array coming into the
3551
+		 *                                method.
3552
+		 */
3553
+		do_action(
3554
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3555
+			$query_args
3556
+		);
3557
+		// calculate where we're going (if we have a "save and close" button pushed)
3558
+		if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3559
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3560
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3561
+			// regenerate query args array from referrer URL
3562
+			parse_str($parsed_url['query'], $query_args);
3563
+			// correct page and action will be in the query args now
3564
+			$redirect_url = admin_url('admin.php');
3565
+		}
3566
+		// merge any default query_args set in _default_route_query_args property
3567
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3568
+			$args_to_merge = array();
3569
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3570
+				// is there a wp_referer array in our _default_route_query_args property?
3571
+				if ($query_param === 'wp_referer') {
3572
+					$query_value = (array) $query_value;
3573
+					foreach ($query_value as $reference => $value) {
3574
+						if (strpos($reference, 'nonce') !== false) {
3575
+							continue;
3576
+						}
3577
+						// finally we will override any arguments in the referer with
3578
+						// what might be set on the _default_route_query_args array.
3579
+						if (isset($this->_default_route_query_args[ $reference ])) {
3580
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3581
+						} else {
3582
+							$args_to_merge[ $reference ] = urlencode($value);
3583
+						}
3584
+					}
3585
+					continue;
3586
+				}
3587
+				$args_to_merge[ $query_param ] = $query_value;
3588
+			}
3589
+			// now let's merge these arguments but override with what was specifically sent in to the
3590
+			// redirect.
3591
+			$query_args = array_merge($args_to_merge, $query_args);
3592
+		}
3593
+		$this->_process_notices($query_args);
3594
+		// generate redirect url
3595
+		// if redirecting to anything other than the main page, add a nonce
3596
+		if (isset($query_args['action'])) {
3597
+			// manually generate wp_nonce and merge that with the query vars
3598
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3599
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3600
+		}
3601
+		// we're adding some hooks and filters in here for processing any things just before redirects
3602
+		// (example: an admin page has done an insert or update and we want to run something after that).
3603
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3604
+		$redirect_url = apply_filters(
3605
+			'FHEE_redirect_' . $classname . $this->_req_action,
3606
+			EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3607
+			$query_args
3608
+		);
3609
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3610
+		if (defined('DOING_AJAX')) {
3611
+			$default_data = array(
3612
+				'close'        => true,
3613
+				'redirect_url' => $redirect_url,
3614
+				'where'        => 'main',
3615
+				'what'         => 'append',
3616
+			);
3617
+			$this->_template_args['success'] = $success;
3618
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3619
+				$default_data,
3620
+				$this->_template_args['data']
3621
+			) : $default_data;
3622
+			$this->_return_json();
3623
+		}
3624
+		wp_safe_redirect($redirect_url);
3625
+		exit();
3626
+	}
3627
+
3628
+
3629
+	/**
3630
+	 * process any notices before redirecting (or returning ajax request)
3631
+	 * This method sets the $this->_template_args['notices'] attribute;
3632
+	 *
3633
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3634
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3635
+	 *                                  page_routes haven't been defined yet.
3636
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3637
+	 *                                  still save a transient for the notice.
3638
+	 * @return void
3639
+	 * @throws EE_Error
3640
+	 * @throws InvalidArgumentException
3641
+	 * @throws InvalidDataTypeException
3642
+	 * @throws InvalidInterfaceException
3643
+	 */
3644
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3645
+	{
3646
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3647
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3648
+			$notices = EE_Error::get_notices(false);
3649
+			if (empty($this->_template_args['success'])) {
3650
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3651
+			}
3652
+			if (empty($this->_template_args['errors'])) {
3653
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3654
+			}
3655
+			if (empty($this->_template_args['attention'])) {
3656
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3657
+			}
3658
+		}
3659
+		$this->_template_args['notices'] = EE_Error::get_notices();
3660
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3661
+		if (! defined('DOING_AJAX') || $sticky_notices) {
3662
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3663
+			$this->_add_transient(
3664
+				$route,
3665
+				$this->_template_args['notices'],
3666
+				true,
3667
+				$skip_route_verify
3668
+			);
3669
+		}
3670
+	}
3671
+
3672
+
3673
+	/**
3674
+	 * get_action_link_or_button
3675
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3676
+	 *
3677
+	 * @param string $action        use this to indicate which action the url is generated with.
3678
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3679
+	 *                              property.
3680
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3681
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3682
+	 * @param string $base_url      If this is not provided
3683
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3684
+	 *                              Otherwise this value will be used.
3685
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3686
+	 * @return string
3687
+	 * @throws InvalidArgumentException
3688
+	 * @throws InvalidInterfaceException
3689
+	 * @throws InvalidDataTypeException
3690
+	 * @throws EE_Error
3691
+	 */
3692
+	public function get_action_link_or_button(
3693
+		$action,
3694
+		$type = 'add',
3695
+		$extra_request = array(),
3696
+		$class = 'button-primary',
3697
+		$base_url = '',
3698
+		$exclude_nonce = false
3699
+	) {
3700
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3701
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3702
+			throw new EE_Error(
3703
+				sprintf(
3704
+					esc_html__(
3705
+						'There is no page route for given action for the button.  This action was given: %s',
3706
+						'event_espresso'
3707
+					),
3708
+					$action
3709
+				)
3710
+			);
3711
+		}
3712
+		if (! isset($this->_labels['buttons'][ $type ])) {
3713
+			throw new EE_Error(
3714
+				sprintf(
3715
+					__(
3716
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3717
+						'event_espresso'
3718
+					),
3719
+					$type
3720
+				)
3721
+			);
3722
+		}
3723
+		// finally check user access for this button.
3724
+		$has_access = $this->check_user_access($action, true);
3725
+		if (! $has_access) {
3726
+			return '';
3727
+		}
3728
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3729
+		$query_args = array(
3730
+			'action' => $action,
3731
+		);
3732
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3733
+		if (! empty($extra_request)) {
3734
+			$query_args = array_merge($extra_request, $query_args);
3735
+		}
3736
+		$url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3737
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3738
+	}
3739
+
3740
+
3741
+	/**
3742
+	 * _per_page_screen_option
3743
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3744
+	 *
3745
+	 * @return void
3746
+	 * @throws InvalidArgumentException
3747
+	 * @throws InvalidInterfaceException
3748
+	 * @throws InvalidDataTypeException
3749
+	 */
3750
+	protected function _per_page_screen_option()
3751
+	{
3752
+		$option = 'per_page';
3753
+		$args = array(
3754
+			'label'   => apply_filters(
3755
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3756
+				$this->_admin_page_title,
3757
+				$this
3758
+			),
3759
+			'default' => (int) apply_filters(
3760
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3761
+				20
3762
+			),
3763
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3764
+		);
3765
+		// ONLY add the screen option if the user has access to it.
3766
+		if ($this->check_user_access($this->_current_view, true)) {
3767
+			add_screen_option($option, $args);
3768
+		}
3769
+	}
3770
+
3771
+
3772
+	/**
3773
+	 * set_per_page_screen_option
3774
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3775
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3776
+	 * admin_menu.
3777
+	 *
3778
+	 * @return void
3779
+	 */
3780
+	private function _set_per_page_screen_options()
3781
+	{
3782
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3783
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3784
+			if (! $user = wp_get_current_user()) {
3785
+				return;
3786
+			}
3787
+			$option = $_POST['wp_screen_options']['option'];
3788
+			$value = $_POST['wp_screen_options']['value'];
3789
+			if ($option !== sanitize_key($option)) {
3790
+				return;
3791
+			}
3792
+			$map_option = $option;
3793
+			$option = str_replace('-', '_', $option);
3794
+			switch ($map_option) {
3795
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3796
+					$value = (int) $value;
3797
+					$max_value = apply_filters(
3798
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3799
+						999,
3800
+						$this->_current_page,
3801
+						$this->_current_view
3802
+					);
3803
+					if ($value < 1) {
3804
+						return;
3805
+					}
3806
+					$value = min($value, $max_value);
3807
+					break;
3808
+				default:
3809
+					$value = apply_filters(
3810
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3811
+						false,
3812
+						$option,
3813
+						$value
3814
+					);
3815
+					if (false === $value) {
3816
+						return;
3817
+					}
3818
+					break;
3819
+			}
3820
+			update_user_meta($user->ID, $option, $value);
3821
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3822
+			exit;
3823
+		}
3824
+	}
3825
+
3826
+
3827
+	/**
3828
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3829
+	 *
3830
+	 * @param array $data array that will be assigned to template args.
3831
+	 */
3832
+	public function set_template_args($data)
3833
+	{
3834
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3835
+	}
3836
+
3837
+
3838
+	/**
3839
+	 * This makes available the WP transient system for temporarily moving data between routes
3840
+	 *
3841
+	 * @param string $route             the route that should receive the transient
3842
+	 * @param array  $data              the data that gets sent
3843
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3844
+	 *                                  normal route transient.
3845
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3846
+	 *                                  when we are adding a transient before page_routes have been defined.
3847
+	 * @return void
3848
+	 * @throws EE_Error
3849
+	 */
3850
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3851
+	{
3852
+		$user_id = get_current_user_id();
3853
+		if (! $skip_route_verify) {
3854
+			$this->_verify_route($route);
3855
+		}
3856
+		// now let's set the string for what kind of transient we're setting
3857
+		$transient = $notices
3858
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3859
+			: 'rte_tx_' . $route . '_' . $user_id;
3860
+		$data = $notices ? array('notices' => $data) : $data;
3861
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3862
+		$existing = is_multisite() && is_network_admin()
3863
+			? get_site_transient($transient)
3864
+			: get_transient($transient);
3865
+		if ($existing) {
3866
+			$data = array_merge((array) $data, (array) $existing);
3867
+		}
3868
+		if (is_multisite() && is_network_admin()) {
3869
+			set_site_transient($transient, $data, 8);
3870
+		} else {
3871
+			set_transient($transient, $data, 8);
3872
+		}
3873
+	}
3874
+
3875
+
3876
+	/**
3877
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3878
+	 *
3879
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3880
+	 * @param string $route
3881
+	 * @return mixed data
3882
+	 */
3883
+	protected function _get_transient($notices = false, $route = '')
3884
+	{
3885
+		$user_id = get_current_user_id();
3886
+		$route = ! $route ? $this->_req_action : $route;
3887
+		$transient = $notices
3888
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3889
+			: 'rte_tx_' . $route . '_' . $user_id;
3890
+		$data = is_multisite() && is_network_admin()
3891
+			? get_site_transient($transient)
3892
+			: get_transient($transient);
3893
+		// delete transient after retrieval (just in case it hasn't expired);
3894
+		if (is_multisite() && is_network_admin()) {
3895
+			delete_site_transient($transient);
3896
+		} else {
3897
+			delete_transient($transient);
3898
+		}
3899
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3900
+	}
3901
+
3902
+
3903
+	/**
3904
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3905
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3906
+	 * default route callback on the EE_Admin page you want it run.)
3907
+	 *
3908
+	 * @return void
3909
+	 */
3910
+	protected function _transient_garbage_collection()
3911
+	{
3912
+		global $wpdb;
3913
+		// retrieve all existing transients
3914
+		$query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3915
+		if ($results = $wpdb->get_results($query)) {
3916
+			foreach ($results as $result) {
3917
+				$transient = str_replace('_transient_', '', $result->option_name);
3918
+				get_transient($transient);
3919
+				if (is_multisite() && is_network_admin()) {
3920
+					get_site_transient($transient);
3921
+				}
3922
+			}
3923
+		}
3924
+	}
3925
+
3926
+
3927
+	/**
3928
+	 * get_view
3929
+	 *
3930
+	 * @return string content of _view property
3931
+	 */
3932
+	public function get_view()
3933
+	{
3934
+		return $this->_view;
3935
+	}
3936
+
3937
+
3938
+	/**
3939
+	 * getter for the protected $_views property
3940
+	 *
3941
+	 * @return array
3942
+	 */
3943
+	public function get_views()
3944
+	{
3945
+		return $this->_views;
3946
+	}
3947
+
3948
+
3949
+	/**
3950
+	 * get_current_page
3951
+	 *
3952
+	 * @return string _current_page property value
3953
+	 */
3954
+	public function get_current_page()
3955
+	{
3956
+		return $this->_current_page;
3957
+	}
3958
+
3959
+
3960
+	/**
3961
+	 * get_current_view
3962
+	 *
3963
+	 * @return string _current_view property value
3964
+	 */
3965
+	public function get_current_view()
3966
+	{
3967
+		return $this->_current_view;
3968
+	}
3969
+
3970
+
3971
+	/**
3972
+	 * get_current_screen
3973
+	 *
3974
+	 * @return object The current WP_Screen object
3975
+	 */
3976
+	public function get_current_screen()
3977
+	{
3978
+		return $this->_current_screen;
3979
+	}
3980
+
3981
+
3982
+	/**
3983
+	 * get_current_page_view_url
3984
+	 *
3985
+	 * @return string This returns the url for the current_page_view.
3986
+	 */
3987
+	public function get_current_page_view_url()
3988
+	{
3989
+		return $this->_current_page_view_url;
3990
+	}
3991
+
3992
+
3993
+	/**
3994
+	 * just returns the _req_data property
3995
+	 *
3996
+	 * @return array
3997
+	 */
3998
+	public function get_request_data()
3999
+	{
4000
+		return $this->_req_data;
4001
+	}
4002
+
4003
+
4004
+	/**
4005
+	 * returns the _req_data protected property
4006
+	 *
4007
+	 * @return string
4008
+	 */
4009
+	public function get_req_action()
4010
+	{
4011
+		return $this->_req_action;
4012
+	}
4013
+
4014
+
4015
+	/**
4016
+	 * @return bool  value of $_is_caf property
4017
+	 */
4018
+	public function is_caf()
4019
+	{
4020
+		return $this->_is_caf;
4021
+	}
4022
+
4023
+
4024
+	/**
4025
+	 * @return mixed
4026
+	 */
4027
+	public function default_espresso_metaboxes()
4028
+	{
4029
+		return $this->_default_espresso_metaboxes;
4030
+	}
4031
+
4032
+
4033
+	/**
4034
+	 * @return mixed
4035
+	 */
4036
+	public function admin_base_url()
4037
+	{
4038
+		return $this->_admin_base_url;
4039
+	}
4040
+
4041
+
4042
+	/**
4043
+	 * @return mixed
4044
+	 */
4045
+	public function wp_page_slug()
4046
+	{
4047
+		return $this->_wp_page_slug;
4048
+	}
4049
+
4050
+
4051
+	/**
4052
+	 * updates  espresso configuration settings
4053
+	 *
4054
+	 * @param string                   $tab
4055
+	 * @param EE_Config_Base|EE_Config $config
4056
+	 * @param string                   $file file where error occurred
4057
+	 * @param string                   $func function  where error occurred
4058
+	 * @param string                   $line line no where error occurred
4059
+	 * @return boolean
4060
+	 */
4061
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4062
+	{
4063
+		// remove any options that are NOT going to be saved with the config settings.
4064
+		if (isset($config->core->ee_ueip_optin)) {
4065
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4066
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4067
+			update_option('ee_ueip_has_notified', true);
4068
+		}
4069
+		// and save it (note we're also doing the network save here)
4070
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4071
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4072
+		if ($config_saved && $net_saved) {
4073
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4074
+			return true;
4075
+		}
4076
+		EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4077
+		return false;
4078
+	}
4079
+
4080
+
4081
+	/**
4082
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4083
+	 *
4084
+	 * @return array
4085
+	 */
4086
+	public function get_yes_no_values()
4087
+	{
4088
+		return $this->_yes_no_values;
4089
+	}
4090
+
4091
+
4092
+	/**
4093
+	 * @return string
4094
+	 * @throws ReflectionException
4095
+	 * @since $VID:$
4096
+	 */
4097
+	protected function _get_dir()
4098
+	{
4099
+		$reflector = new ReflectionClass(get_class($this));
4100
+		return dirname($reflector->getFileName());
4101
+	}
4102
+
4103
+
4104
+	/**
4105
+	 * A helper for getting a "next link".
4106
+	 *
4107
+	 * @param string $url   The url to link to
4108
+	 * @param string $class The class to use.
4109
+	 * @return string
4110
+	 */
4111
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4112
+	{
4113
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4114
+	}
4115
+
4116
+
4117
+	/**
4118
+	 * A helper for getting a "previous link".
4119
+	 *
4120
+	 * @param string $url   The url to link to
4121
+	 * @param string $class The class to use.
4122
+	 * @return string
4123
+	 */
4124
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4125
+	{
4126
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4127
+	}
4128
+
4129
+
4130
+
4131
+
4132
+
4133
+
4134
+
4135
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4136
+
4137
+
4138
+	/**
4139
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4140
+	 * 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
4141
+	 * _req_data array.
4142
+	 *
4143
+	 * @return bool success/fail
4144
+	 * @throws EE_Error
4145
+	 * @throws InvalidArgumentException
4146
+	 * @throws ReflectionException
4147
+	 * @throws InvalidDataTypeException
4148
+	 * @throws InvalidInterfaceException
4149
+	 */
4150
+	protected function _process_resend_registration()
4151
+	{
4152
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4153
+		do_action(
4154
+			'AHEE__EE_Admin_Page___process_resend_registration',
4155
+			$this->_template_args['success'],
4156
+			$this->_req_data
4157
+		);
4158
+		return $this->_template_args['success'];
4159
+	}
4160
+
4161
+
4162
+	/**
4163
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4164
+	 *
4165
+	 * @param EE_Payment $payment
4166
+	 * @return bool success/fail
4167
+	 */
4168
+	protected function _process_payment_notification(EE_Payment $payment)
4169
+	{
4170
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4171
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4172
+		$this->_template_args['success'] = apply_filters(
4173
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4174
+			false,
4175
+			$payment
4176
+		);
4177
+		return $this->_template_args['success'];
4178
+	}
4179 4179
 }
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/NodeGroupDao.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -22,125 +22,125 @@
 block discarded – undo
22 22
  */
23 23
 class NodeGroupDao
24 24
 {
25
-    /**
26
-     * @return mixed|void
27
-     */
28
-    public function generateGroupCode()
29
-    {
30
-        return wp_generate_password(6, false);
31
-    }
25
+	/**
26
+	 * @return mixed|void
27
+	 */
28
+	public function generateGroupCode()
29
+	{
30
+		return wp_generate_password(6, false);
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * Gets the string we put in front of the WP Option name used to store the jobs.
36
-     *
37
-     * @return string
38
-     */
39
-    private function getOptionPrefix()
40
-    {
41
-        return 'ee_deletion_';
42
-    }
34
+	/**
35
+	 * Gets the string we put in front of the WP Option name used to store the jobs.
36
+	 *
37
+	 * @return string
38
+	 */
39
+	private function getOptionPrefix()
40
+	{
41
+		return 'ee_deletion_';
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * @param $code
47
-     * @return ModelObjNode[]
48
-     * @throws Exception
49
-     * @throws UnexpectedEntityException
50
-     * @throws Exception
51
-     */
52
-    public function getModelObjNodesInGroup($code)
53
-    {
54
-        if (! $code) {
55
-            throw new Exception(
56
-                esc_html__(
57
-                    'We aren’t sure which job you are performing. Please press back in your browser and try again.',
58
-                    'event_espresso'
59
-                )
60
-            );
61
-        }
62
-        $deletion_data = get_option($this->getOptionPrefix() . $code, []);
63
-        foreach ($deletion_data as $root) {
64
-            if (! $root instanceof ModelObjNode) {
65
-                throw new UnexpectedEntityException($root, 'ModelObjNode');
66
-            }
67
-        }
68
-        return $deletion_data;
69
-    }
45
+	/**
46
+	 * @param $code
47
+	 * @return ModelObjNode[]
48
+	 * @throws Exception
49
+	 * @throws UnexpectedEntityException
50
+	 * @throws Exception
51
+	 */
52
+	public function getModelObjNodesInGroup($code)
53
+	{
54
+		if (! $code) {
55
+			throw new Exception(
56
+				esc_html__(
57
+					'We aren’t sure which job you are performing. Please press back in your browser and try again.',
58
+					'event_espresso'
59
+				)
60
+			);
61
+		}
62
+		$deletion_data = get_option($this->getOptionPrefix() . $code, []);
63
+		foreach ($deletion_data as $root) {
64
+			if (! $root instanceof ModelObjNode) {
65
+				throw new UnexpectedEntityException($root, 'ModelObjNode');
66
+			}
67
+		}
68
+		return $deletion_data;
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * Gets an array indicating what database rows are contained in the job.
74
-     * Each top-level key is a model name, and its value is an array of IDs.
75
-     *
76
-     * @param ModelObjNode[] $model_obj_nodes
77
-     * @return array
78
-     * @throws EE_Error
79
-     * @throws InvalidDataTypeException
80
-     * @throws InvalidInterfaceException
81
-     * @throws InvalidArgumentException
82
-     * @throws ReflectionException
83
-     */
84
-    public function getModelsAndIdsContainedIn(array $model_obj_nodes)
85
-    {
86
-        $models_and_ids_to_delete = [];
87
-        foreach ($model_obj_nodes as $root) {
88
-            $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
89
-        }
90
-        return $models_and_ids_to_delete;
91
-    }
72
+	/**
73
+	 * Gets an array indicating what database rows are contained in the job.
74
+	 * Each top-level key is a model name, and its value is an array of IDs.
75
+	 *
76
+	 * @param ModelObjNode[] $model_obj_nodes
77
+	 * @return array
78
+	 * @throws EE_Error
79
+	 * @throws InvalidDataTypeException
80
+	 * @throws InvalidInterfaceException
81
+	 * @throws InvalidArgumentException
82
+	 * @throws ReflectionException
83
+	 */
84
+	public function getModelsAndIdsContainedIn(array $model_obj_nodes)
85
+	{
86
+		$models_and_ids_to_delete = [];
87
+		foreach ($model_obj_nodes as $root) {
88
+			$models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
89
+		}
90
+		return $models_and_ids_to_delete;
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * Gets an array indicating what database rows are contained in the job.
96
-     * Each top-level key is a model name, and its value is an array of IDs.
97
-     *
98
-     * @param string $code
99
-     * @return array
100
-     * @throws EE_Error
101
-     * @throws Exception
102
-     * @throws InvalidArgumentException
103
-     * @throws InvalidDataTypeException
104
-     * @throws InvalidInterfaceException
105
-     * @throws ReflectionException
106
-     * @throws UnexpectedEntityException
107
-     * @throws Exception
108
-     */
109
-    public function getModelsAndIdsFromGroup($code)
110
-    {
111
-        $model_obj_nodes = $this->getModelObjNodesInGroup($code);
112
-        return $this->getModelsAndIdsContainedIn($model_obj_nodes);
113
-    }
94
+	/**
95
+	 * Gets an array indicating what database rows are contained in the job.
96
+	 * Each top-level key is a model name, and its value is an array of IDs.
97
+	 *
98
+	 * @param string $code
99
+	 * @return array
100
+	 * @throws EE_Error
101
+	 * @throws Exception
102
+	 * @throws InvalidArgumentException
103
+	 * @throws InvalidDataTypeException
104
+	 * @throws InvalidInterfaceException
105
+	 * @throws ReflectionException
106
+	 * @throws UnexpectedEntityException
107
+	 * @throws Exception
108
+	 */
109
+	public function getModelsAndIdsFromGroup($code)
110
+	{
111
+		$model_obj_nodes = $this->getModelObjNodesInGroup($code);
112
+		return $this->getModelsAndIdsContainedIn($model_obj_nodes);
113
+	}
114 114
 
115 115
 
116
-    /**
117
-     * Persists the ModelObjNodes for future requests, using the code for reference.
118
-     *
119
-     * @param ModelObjNode[] $model_obj_nodes
120
-     * @param string         $code
121
-     * @return bool
122
-     */
123
-    public function persistModelObjNodesGroup(array $model_obj_nodes, $code)
124
-    {
125
-        return add_option(
126
-            $this->getOptionPrefix() . $code,
127
-            $model_obj_nodes,
128
-            null,
129
-            'no'
130
-        );
131
-    }
116
+	/**
117
+	 * Persists the ModelObjNodes for future requests, using the code for reference.
118
+	 *
119
+	 * @param ModelObjNode[] $model_obj_nodes
120
+	 * @param string         $code
121
+	 * @return bool
122
+	 */
123
+	public function persistModelObjNodesGroup(array $model_obj_nodes, $code)
124
+	{
125
+		return add_option(
126
+			$this->getOptionPrefix() . $code,
127
+			$model_obj_nodes,
128
+			null,
129
+			'no'
130
+		);
131
+	}
132 132
 
133 133
 
134
-    /**
135
-     * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though.
136
-     *
137
-     * @param $code
138
-     * @return bool
139
-     */
140
-    public function deleteModelObjNodesInGroup($code)
141
-    {
142
-        return delete_option($this->getOptionPrefix() . $code);
143
-    }
134
+	/**
135
+	 * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though.
136
+	 *
137
+	 * @param $code
138
+	 * @return bool
139
+	 */
140
+	public function deleteModelObjNodesInGroup($code)
141
+	{
142
+		return delete_option($this->getOptionPrefix() . $code);
143
+	}
144 144
 }
145 145
 // End of file NodeGroupDao.php
146 146
 // Location: EventEspresso\core\services\orm\tree_traversal/NodeGroupDao.php
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/RelationNode.php 1 patch
Indentation   +303 added lines, -303 removed lines patch added patch discarded remove patch
@@ -25,309 +25,309 @@
 block discarded – undo
25 25
 class RelationNode extends BaseNode
26 26
 {
27 27
 
28
-    /**
29
-     * @var int
30
-     */
31
-    protected $count;
32
-
33
-    /**
34
-     * @var string|int
35
-     */
36
-    protected $id;
37
-
38
-    /**
39
-     * @var EEM_Base
40
-     */
41
-    protected $main_model;
42
-
43
-    /**
44
-     * @var ModelObjNode[]
45
-     */
46
-    protected $nodes;
47
-
48
-    /**
49
-     * @var EEM_Base
50
-     */
51
-    protected $related_model;
52
-
53
-
54
-
55
-    /**
56
-     * RelationNode constructor.
57
-     *
58
-     * @param          $main_model_obj_id
59
-     * @param EEM_Base $main_model
60
-     * @param EEM_Base $related_model
61
-     * @param array    $dont_traverse_models array of model names we DON'T want to traverse
62
-     */
63
-    public function __construct(
64
-        $main_model_obj_id,
65
-        EEM_Base $main_model,
66
-        EEM_Base $related_model,
67
-        array $dont_traverse_models = []
68
-    ) {
69
-        $this->id                   = $main_model_obj_id;
70
-        $this->main_model           = $main_model;
71
-        $this->related_model        = $related_model;
72
-        $this->nodes                = [];
73
-        $this->dont_traverse_models = $dont_traverse_models;
74
-    }
75
-
76
-
77
-    /**
78
-     * Here is where most of the work happens. We've counted how many related model objects exist, here we identify
79
-     * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.
80
-     *
81
-     * @param int $model_objects_to_identify
82
-     * @return int
83
-     * @throws EE_Error
84
-     * @throws InvalidArgumentException
85
-     * @throws InvalidDataTypeException
86
-     * @throws InvalidInterfaceException
87
-     * @throws ReflectionException
88
-     */
89
-    protected function work($model_objects_to_identify)
90
-    {
91
-        $num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify);
92
-        if ($num_identified < $model_objects_to_identify) {
93
-            $related_model_objs = $this->related_model->get_all(
94
-                [
95
-                    $this->whereQueryParams(),
96
-                    'limit' => [
97
-                        count($this->nodes),
98
-                        $model_objects_to_identify - $num_identified,
99
-                    ],
100
-                ]
101
-            );
102
-            $new_item_nodes     = [];
103
-
104
-            // Add entity nodes for each of the model objects we fetched.
105
-            foreach ($related_model_objs as $related_model_obj) {
106
-                $entity_node                                = new ModelObjNode(
107
-                    $related_model_obj->ID(),
108
-                    $related_model_obj->get_model(),
109
-                    $this->dont_traverse_models
110
-                );
111
-                $this->nodes[ $related_model_obj->ID() ]    = $entity_node;
112
-                $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
113
-            }
114
-            $num_identified += count($new_item_nodes);
115
-            if ($num_identified < $model_objects_to_identify) {
116
-                // And lastly do the work.
117
-                $num_identified += $this->visitAlreadyDiscoveredNodes(
118
-                    $new_item_nodes,
119
-                    $model_objects_to_identify - $num_identified
120
-                );
121
-            }
122
-        }
123
-
124
-        if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) {
125
-            $this->complete = true;
126
-        }
127
-        return $num_identified;
128
-    }
129
-
130
-
131
-    /**
132
-     * Checks if all the identified child nodes are complete or not.
133
-     *
134
-     * @return bool
135
-     */
136
-    protected function allChildrenComplete()
137
-    {
138
-        foreach ($this->nodes as $model_obj_node) {
139
-            if (! $model_obj_node->isComplete()) {
140
-                return false;
141
-            }
142
-        }
143
-        return true;
144
-    }
145
-
146
-
147
-    /**
148
-     * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
149
-     *
150
-     * @param ModelObjNode[] $model_obj_nodes
151
-     * @param                $work_budget
152
-     * @return int
153
-     */
154
-    protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
155
-    {
156
-        $work_done = 0;
157
-        if (! $model_obj_nodes) {
158
-            return 0;
159
-        }
160
-        foreach ($model_obj_nodes as $model_obj_node) {
161
-            if ($work_done >= $work_budget) {
162
-                break;
163
-            }
164
-            $work_done += $model_obj_node->visit($work_budget - $work_done);
165
-        }
166
-        return $work_done;
167
-    }
168
-
169
-
170
-    /**
171
-     * Whether this item has already been initialized
172
-     */
173
-    protected function isDiscovered()
174
-    {
175
-        return $this->count !== null;
176
-    }
177
-
178
-
179
-    /**
180
-     * @return boolean
181
-     */
182
-    public function isComplete()
183
-    {
184
-        if ($this->complete === null) {
185
-            if (count($this->nodes) === $this->count) {
186
-                $this->complete = true;
187
-            } else {
188
-                $this->complete = false;
189
-            }
190
-        }
191
-        return $this->complete;
192
-    }
193
-
194
-
195
-    /**
196
-     * Discovers how many related model objects exist.
197
-     *
198
-     * @return void
199
-     * @throws EE_Error
200
-     * @throws InvalidArgumentException
201
-     * @throws InvalidDataTypeException
202
-     * @throws InvalidInterfaceException
203
-     */
204
-    protected function discover()
205
-    {
206
-        $this->count = $this->related_model->count([$this->whereQueryParams()]);
207
-    }
208
-
209
-
210
-    /**
211
-     * @return array
212
-     * @throws EE_Error
213
-     * @throws InvalidDataTypeException
214
-     * @throws InvalidInterfaceException
215
-     * @throws InvalidArgumentException
216
-     */
217
-    protected function whereQueryParams()
218
-    {
219
-        $where_params = [
220
-            $this->related_model->get_foreign_key_to(
221
-                $this->main_model->get_this_model_name()
222
-            )->get_name() => $this->id,
223
-        ];
224
-        try {
225
-            $relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name());
226
-        } catch (EE_Error $e) {
227
-            // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table
228
-            // which hasn't been explicitly declared in the main model object's model's relations.
229
-            $relation_settings = null;
230
-        }
231
-        if ($relation_settings instanceof EE_Has_Many_Any_Relation) {
232
-            $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] =
233
-                $this->main_model->get_this_model_name();
234
-        }
235
-        return $where_params;
236
-    }
237
-
238
-
239
-    /**
240
-     * @return array
241
-     * @throws EE_Error
242
-     * @throws ReflectionException
243
-     */
244
-    public function toArray()
245
-    {
246
-        $tree = [
247
-            'count'    => $this->count,
248
-            'complete' => $this->isComplete(),
249
-            'objs'     => [],
250
-        ];
251
-        foreach ($this->nodes as $id => $model_obj_node) {
252
-            $tree['objs'][ $id ] = $model_obj_node->toArray();
253
-        }
254
-        return $tree;
255
-    }
256
-
257
-
258
-    /**
259
-     * Gets the IDs of all the model objects to delete; indexed first by model object name.
260
-     *
261
-     * @return array
262
-     * @throws EE_Error
263
-     * @throws ReflectionException
264
-     */
265
-    public function getIds()
266
-    {
267
-        if (empty($this->nodes)) {
268
-            return [];
269
-        }
270
-        $ids = [
271
-            $this->related_model->get_this_model_name() => array_combine(
272
-                array_keys($this->nodes),
273
-                array_keys($this->nodes)
274
-            ),
275
-        ];
276
-        foreach ($this->nodes as $model_obj_node) {
277
-            $ids = array_replace_recursive($ids, $model_obj_node->getIds());
278
-        }
279
-        return $ids;
280
-    }
281
-
282
-
283
-    /**
284
-     * Returns the number of sub-nodes found (ie, related model objects across this relation.)
285
-     *
286
-     * @return int
287
-     */
288
-    public function countSubNodes()
289
-    {
290
-        return count($this->nodes);
291
-    }
292
-
293
-
294
-    /**
295
-     * Don't serialize the models. Just record their names on some dynamic properties.
296
-     *
297
-     * @return array
298
-     */
299
-    public function __sleep()
300
-    {
301
-        $this->m  = $this->main_model->get_this_model_name();
302
-        $this->rm = $this->related_model->get_this_model_name();
303
-        return array_merge(
304
-            [
305
-                'm',
306
-                'rm',
307
-                'id',
308
-                'count',
309
-                'nodes',
310
-            ],
311
-            parent::__sleep()
312
-        );
313
-    }
314
-
315
-
316
-    /**
317
-     * Use the dynamic properties to instantiate the models we use.
318
-     *
319
-     * @throws EE_Error
320
-     * @throws InvalidArgumentException
321
-     * @throws InvalidDataTypeException
322
-     * @throws InvalidInterfaceException
323
-     * @throws ReflectionException
324
-     */
325
-    public function __wakeup()
326
-    {
327
-        $this->main_model    = EE_Registry::instance()->load_model($this->m);
328
-        $this->related_model = EE_Registry::instance()->load_model($this->rm);
329
-        parent::__wakeup();
330
-    }
28
+	/**
29
+	 * @var int
30
+	 */
31
+	protected $count;
32
+
33
+	/**
34
+	 * @var string|int
35
+	 */
36
+	protected $id;
37
+
38
+	/**
39
+	 * @var EEM_Base
40
+	 */
41
+	protected $main_model;
42
+
43
+	/**
44
+	 * @var ModelObjNode[]
45
+	 */
46
+	protected $nodes;
47
+
48
+	/**
49
+	 * @var EEM_Base
50
+	 */
51
+	protected $related_model;
52
+
53
+
54
+
55
+	/**
56
+	 * RelationNode constructor.
57
+	 *
58
+	 * @param          $main_model_obj_id
59
+	 * @param EEM_Base $main_model
60
+	 * @param EEM_Base $related_model
61
+	 * @param array    $dont_traverse_models array of model names we DON'T want to traverse
62
+	 */
63
+	public function __construct(
64
+		$main_model_obj_id,
65
+		EEM_Base $main_model,
66
+		EEM_Base $related_model,
67
+		array $dont_traverse_models = []
68
+	) {
69
+		$this->id                   = $main_model_obj_id;
70
+		$this->main_model           = $main_model;
71
+		$this->related_model        = $related_model;
72
+		$this->nodes                = [];
73
+		$this->dont_traverse_models = $dont_traverse_models;
74
+	}
75
+
76
+
77
+	/**
78
+	 * Here is where most of the work happens. We've counted how many related model objects exist, here we identify
79
+	 * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.
80
+	 *
81
+	 * @param int $model_objects_to_identify
82
+	 * @return int
83
+	 * @throws EE_Error
84
+	 * @throws InvalidArgumentException
85
+	 * @throws InvalidDataTypeException
86
+	 * @throws InvalidInterfaceException
87
+	 * @throws ReflectionException
88
+	 */
89
+	protected function work($model_objects_to_identify)
90
+	{
91
+		$num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify);
92
+		if ($num_identified < $model_objects_to_identify) {
93
+			$related_model_objs = $this->related_model->get_all(
94
+				[
95
+					$this->whereQueryParams(),
96
+					'limit' => [
97
+						count($this->nodes),
98
+						$model_objects_to_identify - $num_identified,
99
+					],
100
+				]
101
+			);
102
+			$new_item_nodes     = [];
103
+
104
+			// Add entity nodes for each of the model objects we fetched.
105
+			foreach ($related_model_objs as $related_model_obj) {
106
+				$entity_node                                = new ModelObjNode(
107
+					$related_model_obj->ID(),
108
+					$related_model_obj->get_model(),
109
+					$this->dont_traverse_models
110
+				);
111
+				$this->nodes[ $related_model_obj->ID() ]    = $entity_node;
112
+				$new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
113
+			}
114
+			$num_identified += count($new_item_nodes);
115
+			if ($num_identified < $model_objects_to_identify) {
116
+				// And lastly do the work.
117
+				$num_identified += $this->visitAlreadyDiscoveredNodes(
118
+					$new_item_nodes,
119
+					$model_objects_to_identify - $num_identified
120
+				);
121
+			}
122
+		}
123
+
124
+		if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) {
125
+			$this->complete = true;
126
+		}
127
+		return $num_identified;
128
+	}
129
+
130
+
131
+	/**
132
+	 * Checks if all the identified child nodes are complete or not.
133
+	 *
134
+	 * @return bool
135
+	 */
136
+	protected function allChildrenComplete()
137
+	{
138
+		foreach ($this->nodes as $model_obj_node) {
139
+			if (! $model_obj_node->isComplete()) {
140
+				return false;
141
+			}
142
+		}
143
+		return true;
144
+	}
145
+
146
+
147
+	/**
148
+	 * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
149
+	 *
150
+	 * @param ModelObjNode[] $model_obj_nodes
151
+	 * @param                $work_budget
152
+	 * @return int
153
+	 */
154
+	protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
155
+	{
156
+		$work_done = 0;
157
+		if (! $model_obj_nodes) {
158
+			return 0;
159
+		}
160
+		foreach ($model_obj_nodes as $model_obj_node) {
161
+			if ($work_done >= $work_budget) {
162
+				break;
163
+			}
164
+			$work_done += $model_obj_node->visit($work_budget - $work_done);
165
+		}
166
+		return $work_done;
167
+	}
168
+
169
+
170
+	/**
171
+	 * Whether this item has already been initialized
172
+	 */
173
+	protected function isDiscovered()
174
+	{
175
+		return $this->count !== null;
176
+	}
177
+
178
+
179
+	/**
180
+	 * @return boolean
181
+	 */
182
+	public function isComplete()
183
+	{
184
+		if ($this->complete === null) {
185
+			if (count($this->nodes) === $this->count) {
186
+				$this->complete = true;
187
+			} else {
188
+				$this->complete = false;
189
+			}
190
+		}
191
+		return $this->complete;
192
+	}
193
+
194
+
195
+	/**
196
+	 * Discovers how many related model objects exist.
197
+	 *
198
+	 * @return void
199
+	 * @throws EE_Error
200
+	 * @throws InvalidArgumentException
201
+	 * @throws InvalidDataTypeException
202
+	 * @throws InvalidInterfaceException
203
+	 */
204
+	protected function discover()
205
+	{
206
+		$this->count = $this->related_model->count([$this->whereQueryParams()]);
207
+	}
208
+
209
+
210
+	/**
211
+	 * @return array
212
+	 * @throws EE_Error
213
+	 * @throws InvalidDataTypeException
214
+	 * @throws InvalidInterfaceException
215
+	 * @throws InvalidArgumentException
216
+	 */
217
+	protected function whereQueryParams()
218
+	{
219
+		$where_params = [
220
+			$this->related_model->get_foreign_key_to(
221
+				$this->main_model->get_this_model_name()
222
+			)->get_name() => $this->id,
223
+		];
224
+		try {
225
+			$relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name());
226
+		} catch (EE_Error $e) {
227
+			// This will happen for has-and-belongs-to-many relations, when this node's related model is that join table
228
+			// which hasn't been explicitly declared in the main model object's model's relations.
229
+			$relation_settings = null;
230
+		}
231
+		if ($relation_settings instanceof EE_Has_Many_Any_Relation) {
232
+			$where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] =
233
+				$this->main_model->get_this_model_name();
234
+		}
235
+		return $where_params;
236
+	}
237
+
238
+
239
+	/**
240
+	 * @return array
241
+	 * @throws EE_Error
242
+	 * @throws ReflectionException
243
+	 */
244
+	public function toArray()
245
+	{
246
+		$tree = [
247
+			'count'    => $this->count,
248
+			'complete' => $this->isComplete(),
249
+			'objs'     => [],
250
+		];
251
+		foreach ($this->nodes as $id => $model_obj_node) {
252
+			$tree['objs'][ $id ] = $model_obj_node->toArray();
253
+		}
254
+		return $tree;
255
+	}
256
+
257
+
258
+	/**
259
+	 * Gets the IDs of all the model objects to delete; indexed first by model object name.
260
+	 *
261
+	 * @return array
262
+	 * @throws EE_Error
263
+	 * @throws ReflectionException
264
+	 */
265
+	public function getIds()
266
+	{
267
+		if (empty($this->nodes)) {
268
+			return [];
269
+		}
270
+		$ids = [
271
+			$this->related_model->get_this_model_name() => array_combine(
272
+				array_keys($this->nodes),
273
+				array_keys($this->nodes)
274
+			),
275
+		];
276
+		foreach ($this->nodes as $model_obj_node) {
277
+			$ids = array_replace_recursive($ids, $model_obj_node->getIds());
278
+		}
279
+		return $ids;
280
+	}
281
+
282
+
283
+	/**
284
+	 * Returns the number of sub-nodes found (ie, related model objects across this relation.)
285
+	 *
286
+	 * @return int
287
+	 */
288
+	public function countSubNodes()
289
+	{
290
+		return count($this->nodes);
291
+	}
292
+
293
+
294
+	/**
295
+	 * Don't serialize the models. Just record their names on some dynamic properties.
296
+	 *
297
+	 * @return array
298
+	 */
299
+	public function __sleep()
300
+	{
301
+		$this->m  = $this->main_model->get_this_model_name();
302
+		$this->rm = $this->related_model->get_this_model_name();
303
+		return array_merge(
304
+			[
305
+				'm',
306
+				'rm',
307
+				'id',
308
+				'count',
309
+				'nodes',
310
+			],
311
+			parent::__sleep()
312
+		);
313
+	}
314
+
315
+
316
+	/**
317
+	 * Use the dynamic properties to instantiate the models we use.
318
+	 *
319
+	 * @throws EE_Error
320
+	 * @throws InvalidArgumentException
321
+	 * @throws InvalidDataTypeException
322
+	 * @throws InvalidInterfaceException
323
+	 * @throws ReflectionException
324
+	 */
325
+	public function __wakeup()
326
+	{
327
+		$this->main_model    = EE_Registry::instance()->load_model($this->m);
328
+		$this->related_model = EE_Registry::instance()->load_model($this->rm);
329
+		parent::__wakeup();
330
+	}
331 331
 }
332 332
 // End of file RelationNode.php
333 333
 // Location: EventEspresso\core\services\orm\tree_traversal/RelationNode.php
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Messages_Template_Pack.lib.php 2 patches
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -12,202 +12,202 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * Holds values for registered template pack
17
-     *
18
-     * @since 4.5.0
19
-     *
20
-     * @var array
21
-     */
22
-    protected static $_registry = [];
23
-
24
-
25
-    /**
26
-     * Used to register a new template pack with the messages system.
27
-     *
28
-     * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to
29
-     * change entire layouts for a set of message templates.  This method is used to register the new template pack and
30
-     * automatically have it loaded in the appropriate places.
31
-     *
32
-     * This registry also verifies that there isn't already a template pack registered with the same name and if there
33
-     * is then it will add an EE_Error notice.
34
-     *
35
-     * Note that this only handles registering the your Template Pack class with the message template pack system.
36
-     * However, there is also a naming schema you must follow for templates you are providing with your template pack.
37
-     *
38
-     * @param string $addon_name The internal reference used to refer to this template pack.  Note, this is first come,
39
-     *                           first serve.  If there is already a template pack registered with this name then the
40
-     *                           registry will assign a unique reference for it so it can still be activated (but this
41
-     *                           makes it harder to deregister as it will be unique per load - so its best to try to
42
-     *                           make this a unique string!)
43
-     * @param array  $setup_args array {
44
-     *                           An array of required values for registering the template pack.
45
-     * @type string  $path       The path for the new template pack class.
46
-     * @type string  $classname  The name of the new Template Pack Class.
47
-     *                           }
48
-     * @return bool
49
-     * @throws EE_Error
50
-     *
51
-     * @see    core/libraries/messages/defaults/default/* for all the example templates the default template pack
52
-     *         supports.
53
-     *
54
-     *
55
-     * @since  4.5.0
56
-     * @see    EE_Messages_Template_Pack_Default for an example class
57
-     */
58
-    public static function register(string $addon_name = '', array $setup_args = []): bool
59
-    {
60
-
61
-        // check for required params
62
-        if (empty($addon_name) || empty($setup_args['path']) || empty($setup_args['classname'])) {
63
-            throw new EE_Error(
64
-                __(
65
-                    'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ',
66
-                    'event_espresso'
67
-                )
68
-            );
69
-        }
70
-
71
-        // make sure we don't register twice
72
-        if (isset(self::$_registry[ $addon_name ])) {
73
-            return true;
74
-        }
75
-
76
-        // check that incoming $addon_name doesn't already exist. If it does then we'll create a unique reference for this template pack.
77
-        if (isset(self::$_registry[ $addon_name ])) {
78
-            $addon_name = uniqid() . '_' . $addon_name;
79
-        }
80
-
81
-
82
-        // make sure this was called in the right place!
83
-        if (
84
-            ! did_action('EE_Brewing_Regular___messages_caf')
85
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
86
-        ) {
87
-            EE_Error::doing_it_wrong(
88
-                __METHOD__,
89
-                sprintf(
90
-                    __(
91
-                        'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
92
-                        'event_espresso'
93
-                    ),
94
-                    $addon_name
95
-                ),
96
-                '4.5.0'
97
-            );
98
-        }
99
-
100
-        if (self::_verify_class_not_exist($setup_args['classname'])) {
101
-            self::$_registry[ $addon_name ] = [
102
-                'path'      => (string) $setup_args['path'],
103
-                'classname' => (string) $setup_args['classname'],
104
-            ];
105
-        }
106
-
107
-        // hook into the system
108
-        add_filter(
109
-            'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
110
-            ['EE_Register_Messages_Template_Pack', 'set_template_pack_path'],
111
-            10
112
-        );
113
-        add_filter(
114
-            'FHEE__EED_Messages__get_template_packs__template_packs',
115
-            ['EE_Register_Messages_Template_Pack', 'set_template_pack'],
116
-            10
117
-        );
118
-        return true;
119
-    }
120
-
121
-
122
-    /**
123
-     * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.  This adds this template packs path
124
-     * to the messages autoloader paths.
125
-     *
126
-     * @param array $paths Array of paths already registered with the messages autoloader
127
-     *
128
-     * @return array
129
-     * @since  4.5.0
130
-     *
131
-     */
132
-    public static function set_template_pack_path(array $paths): array
133
-    {
134
-        foreach (self::$_registry as $args) {
135
-            $paths[] = $args['path'];
136
-        }
137
-        return $paths;
138
-    }
139
-
140
-
141
-    /**
142
-     * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated,
143
-     * registered template pack to the template packs array when requested by client code.
144
-     *
145
-     * @param EE_Messages_Template_Pack[] $template_packs
146
-     * @return EE_Messages_Template_Pack[]
147
-     * @since 4.5.0
148
-     *
149
-     */
150
-    public static function set_template_pack(array $template_packs): array
151
-    {
152
-        foreach (self::$_registry as $args) {
153
-            // verify class_exists
154
-            if (! class_exists($args['classname'])) {
155
-                require_once($args['path'] . '/' . $args['classname'] . '.class.php');
156
-            }
157
-
158
-            // check again!
159
-            if (class_exists($args['classname'])) {
160
-                $template_pack                           = new $args['classname']();
161
-                $template_packs[ $template_pack->dbref ] = $template_pack;
162
-            }
163
-        }
164
-
165
-        return $template_packs;
166
-    }
167
-
168
-
169
-    /**
170
-     * This verifies that the classes for each registered template pack are unique  names.
171
-     *
172
-     * @param string $classname The classname being checked
173
-     *
174
-     * @return bool
175
-     */
176
-    private static function _verify_class_not_exist(string $classname): bool
177
-    {
178
-        // loop through the existing registry and see if the classname is already present.
179
-        foreach (self::$_registry as $args) {
180
-            if ($args['classname'] == $classname) {
181
-                EE_Error::add_error(
182
-                    sprintf(
183
-                        __(
184
-                            'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname.  Contact the author of this template pack to let them know of the conflict.  To stop seeing this message you will need to deactivate this template pack.',
185
-                            'event_espresso'
186
-                        ),
187
-                        $classname
188
-                    ),
189
-                    __FILE__,
190
-                    __LINE__,
191
-                    __FUNCTION__
192
-                );
193
-                return false;
194
-            }
195
-        }
196
-        return true;
197
-    }
198
-
199
-
200
-    /**
201
-     * This deregisters a variation set that was previously registered with the given slug.
202
-     *
203
-     * @param string $addon_name The name for the variation set that was previously registered.
204
-     *
205
-     * @return void
206
-     * @since 4.5.0
207
-     *
208
-     */
209
-    public static function deregister(string $addon_name = '')
210
-    {
211
-        unset(self::$_registry[ $addon_name ]);
212
-    }
15
+	/**
16
+	 * Holds values for registered template pack
17
+	 *
18
+	 * @since 4.5.0
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected static $_registry = [];
23
+
24
+
25
+	/**
26
+	 * Used to register a new template pack with the messages system.
27
+	 *
28
+	 * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to
29
+	 * change entire layouts for a set of message templates.  This method is used to register the new template pack and
30
+	 * automatically have it loaded in the appropriate places.
31
+	 *
32
+	 * This registry also verifies that there isn't already a template pack registered with the same name and if there
33
+	 * is then it will add an EE_Error notice.
34
+	 *
35
+	 * Note that this only handles registering the your Template Pack class with the message template pack system.
36
+	 * However, there is also a naming schema you must follow for templates you are providing with your template pack.
37
+	 *
38
+	 * @param string $addon_name The internal reference used to refer to this template pack.  Note, this is first come,
39
+	 *                           first serve.  If there is already a template pack registered with this name then the
40
+	 *                           registry will assign a unique reference for it so it can still be activated (but this
41
+	 *                           makes it harder to deregister as it will be unique per load - so its best to try to
42
+	 *                           make this a unique string!)
43
+	 * @param array  $setup_args array {
44
+	 *                           An array of required values for registering the template pack.
45
+	 * @type string  $path       The path for the new template pack class.
46
+	 * @type string  $classname  The name of the new Template Pack Class.
47
+	 *                           }
48
+	 * @return bool
49
+	 * @throws EE_Error
50
+	 *
51
+	 * @see    core/libraries/messages/defaults/default/* for all the example templates the default template pack
52
+	 *         supports.
53
+	 *
54
+	 *
55
+	 * @since  4.5.0
56
+	 * @see    EE_Messages_Template_Pack_Default for an example class
57
+	 */
58
+	public static function register(string $addon_name = '', array $setup_args = []): bool
59
+	{
60
+
61
+		// check for required params
62
+		if (empty($addon_name) || empty($setup_args['path']) || empty($setup_args['classname'])) {
63
+			throw new EE_Error(
64
+				__(
65
+					'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ',
66
+					'event_espresso'
67
+				)
68
+			);
69
+		}
70
+
71
+		// make sure we don't register twice
72
+		if (isset(self::$_registry[ $addon_name ])) {
73
+			return true;
74
+		}
75
+
76
+		// check that incoming $addon_name doesn't already exist. If it does then we'll create a unique reference for this template pack.
77
+		if (isset(self::$_registry[ $addon_name ])) {
78
+			$addon_name = uniqid() . '_' . $addon_name;
79
+		}
80
+
81
+
82
+		// make sure this was called in the right place!
83
+		if (
84
+			! did_action('EE_Brewing_Regular___messages_caf')
85
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
86
+		) {
87
+			EE_Error::doing_it_wrong(
88
+				__METHOD__,
89
+				sprintf(
90
+					__(
91
+						'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
92
+						'event_espresso'
93
+					),
94
+					$addon_name
95
+				),
96
+				'4.5.0'
97
+			);
98
+		}
99
+
100
+		if (self::_verify_class_not_exist($setup_args['classname'])) {
101
+			self::$_registry[ $addon_name ] = [
102
+				'path'      => (string) $setup_args['path'],
103
+				'classname' => (string) $setup_args['classname'],
104
+			];
105
+		}
106
+
107
+		// hook into the system
108
+		add_filter(
109
+			'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
110
+			['EE_Register_Messages_Template_Pack', 'set_template_pack_path'],
111
+			10
112
+		);
113
+		add_filter(
114
+			'FHEE__EED_Messages__get_template_packs__template_packs',
115
+			['EE_Register_Messages_Template_Pack', 'set_template_pack'],
116
+			10
117
+		);
118
+		return true;
119
+	}
120
+
121
+
122
+	/**
123
+	 * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.  This adds this template packs path
124
+	 * to the messages autoloader paths.
125
+	 *
126
+	 * @param array $paths Array of paths already registered with the messages autoloader
127
+	 *
128
+	 * @return array
129
+	 * @since  4.5.0
130
+	 *
131
+	 */
132
+	public static function set_template_pack_path(array $paths): array
133
+	{
134
+		foreach (self::$_registry as $args) {
135
+			$paths[] = $args['path'];
136
+		}
137
+		return $paths;
138
+	}
139
+
140
+
141
+	/**
142
+	 * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated,
143
+	 * registered template pack to the template packs array when requested by client code.
144
+	 *
145
+	 * @param EE_Messages_Template_Pack[] $template_packs
146
+	 * @return EE_Messages_Template_Pack[]
147
+	 * @since 4.5.0
148
+	 *
149
+	 */
150
+	public static function set_template_pack(array $template_packs): array
151
+	{
152
+		foreach (self::$_registry as $args) {
153
+			// verify class_exists
154
+			if (! class_exists($args['classname'])) {
155
+				require_once($args['path'] . '/' . $args['classname'] . '.class.php');
156
+			}
157
+
158
+			// check again!
159
+			if (class_exists($args['classname'])) {
160
+				$template_pack                           = new $args['classname']();
161
+				$template_packs[ $template_pack->dbref ] = $template_pack;
162
+			}
163
+		}
164
+
165
+		return $template_packs;
166
+	}
167
+
168
+
169
+	/**
170
+	 * This verifies that the classes for each registered template pack are unique  names.
171
+	 *
172
+	 * @param string $classname The classname being checked
173
+	 *
174
+	 * @return bool
175
+	 */
176
+	private static function _verify_class_not_exist(string $classname): bool
177
+	{
178
+		// loop through the existing registry and see if the classname is already present.
179
+		foreach (self::$_registry as $args) {
180
+			if ($args['classname'] == $classname) {
181
+				EE_Error::add_error(
182
+					sprintf(
183
+						__(
184
+							'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname.  Contact the author of this template pack to let them know of the conflict.  To stop seeing this message you will need to deactivate this template pack.',
185
+							'event_espresso'
186
+						),
187
+						$classname
188
+					),
189
+					__FILE__,
190
+					__LINE__,
191
+					__FUNCTION__
192
+				);
193
+				return false;
194
+			}
195
+		}
196
+		return true;
197
+	}
198
+
199
+
200
+	/**
201
+	 * This deregisters a variation set that was previously registered with the given slug.
202
+	 *
203
+	 * @param string $addon_name The name for the variation set that was previously registered.
204
+	 *
205
+	 * @return void
206
+	 * @since 4.5.0
207
+	 *
208
+	 */
209
+	public static function deregister(string $addon_name = '')
210
+	{
211
+		unset(self::$_registry[ $addon_name ]);
212
+	}
213 213
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
         }
70 70
 
71 71
         // make sure we don't register twice
72
-        if (isset(self::$_registry[ $addon_name ])) {
72
+        if (isset(self::$_registry[$addon_name])) {
73 73
             return true;
74 74
         }
75 75
 
76 76
         // check that incoming $addon_name doesn't already exist. If it does then we'll create a unique reference for this template pack.
77
-        if (isset(self::$_registry[ $addon_name ])) {
78
-            $addon_name = uniqid() . '_' . $addon_name;
77
+        if (isset(self::$_registry[$addon_name])) {
78
+            $addon_name = uniqid().'_'.$addon_name;
79 79
         }
80 80
 
81 81
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
         }
99 99
 
100 100
         if (self::_verify_class_not_exist($setup_args['classname'])) {
101
-            self::$_registry[ $addon_name ] = [
101
+            self::$_registry[$addon_name] = [
102 102
                 'path'      => (string) $setup_args['path'],
103 103
                 'classname' => (string) $setup_args['classname'],
104 104
             ];
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
     {
152 152
         foreach (self::$_registry as $args) {
153 153
             // verify class_exists
154
-            if (! class_exists($args['classname'])) {
155
-                require_once($args['path'] . '/' . $args['classname'] . '.class.php');
154
+            if ( ! class_exists($args['classname'])) {
155
+                require_once($args['path'].'/'.$args['classname'].'.class.php');
156 156
             }
157 157
 
158 158
             // check again!
159 159
             if (class_exists($args['classname'])) {
160 160
                 $template_pack                           = new $args['classname']();
161
-                $template_packs[ $template_pack->dbref ] = $template_pack;
161
+                $template_packs[$template_pack->dbref] = $template_pack;
162 162
             }
163 163
         }
164 164
 
@@ -208,6 +208,6 @@  discard block
 block discarded – undo
208 208
      */
209 209
     public static function deregister(string $addon_name = '')
210 210
     {
211
-        unset(self::$_registry[ $addon_name ]);
211
+        unset(self::$_registry[$addon_name]);
212 212
     }
213 213
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model_Extensions.lib.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
         }
71 71
 
72 72
         // make sure we don't register twice
73
-        if (isset(self::$_registry[ $addon_name ])) {
73
+        if (isset(self::$_registry[$addon_name])) {
74 74
             return true;
75 75
         }
76 76
         // check correct loading
77
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
77
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
78 78
             EE_Error::doing_it_wrong(
79 79
                 __METHOD__,
80 80
                 sprintf(
@@ -91,30 +91,30 @@  discard block
 block discarded – undo
91 91
             );
92 92
         }
93 93
 
94
-        self::$_registry[ $addon_name ]   = $setup_args;
95
-        self::$_extensions[ $addon_name ] = [];
94
+        self::$_registry[$addon_name]   = $setup_args;
95
+        self::$_extensions[$addon_name] = [];
96 96
 
97 97
         if (isset($setup_args['model_extension_paths'])) {
98
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
98
+            require_once(EE_LIBRARIES.'plugin_api/db/EEME_Base.lib.php');
99 99
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
100 100
             // remove all files that are not PHP
101 101
             foreach ($class_to_filepath_map as $class => $path) {
102 102
                 if (substr($path, strlen($path) - 3) !== 'php') {
103
-                    unset($class_to_filepath_map[ $class ]);
103
+                    unset($class_to_filepath_map[$class]);
104 104
                 }
105 105
             }
106 106
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
107 107
             foreach (array_keys($class_to_filepath_map) as $classname) {
108
-                self::$_extensions[ $addon_name ]['models'][ $classname ] = new $classname();
108
+                self::$_extensions[$addon_name]['models'][$classname] = new $classname();
109 109
             }
110 110
             unset($setup_args['model_extension_paths']);
111 111
         }
112 112
         if (isset($setup_args['class_extension_paths'])) {
113
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
113
+            require_once(EE_LIBRARIES.'plugin_api/db/EEE_Base_Class.lib.php');
114 114
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
115 115
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
116 116
             foreach (array_keys($class_to_filepath_map) as $classname) {
117
-                self::$_extensions[ $addon_name ]['classes'][ $classname ] = new $classname();
117
+                self::$_extensions[$addon_name]['classes'][$classname] = new $classname();
118 118
             }
119 119
             unset($setup_args['class_extension_paths']);
120 120
         }
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
      */
135 135
     public static function deregister(string $addon_name = '')
136 136
     {
137
-        if (isset(self::$_registry[ $addon_name ])) {
138
-            unset(self::$_registry[ $addon_name ]);
139
-            foreach (self::$_extensions[ $addon_name ] as $extension_of_type) {
137
+        if (isset(self::$_registry[$addon_name])) {
138
+            unset(self::$_registry[$addon_name]);
139
+            foreach (self::$_extensions[$addon_name] as $extension_of_type) {
140 140
                 foreach ($extension_of_type as $extension) {
141 141
                     $extension->deregister();
142 142
                 }
Please login to merge, or discard this patch.
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -12,133 +12,133 @@
 block discarded – undo
12 12
 class EE_Register_Model_Extensions implements EEI_Plugin_API
13 13
 {
14 14
 
15
-    protected static $_registry;
15
+	protected static $_registry;
16 16
 
17
-    protected static $_extensions = [];
17
+	protected static $_extensions = [];
18 18
 
19 19
 
20
-    /**
21
-     * register method for setting up model extensions
22
-     *
23
-     * @param string $addon_name            unique id for the extensions being setup
24
-     * @param array  $setup_args            {
25
-     * @return bool
26
-     * @throws EE_Error
27
-     * @type  array  $model_extension_paths array of folders containing DB model extensions, where each file follows
28
-     *                                      the models naming convention, which is:
29
-     *                                      EEME_{your_plugin_slug}_model_name_extended}.model_ext.php.
30
-     *                                      Where {your_plugin_slug} is really anything you want (but something having
31
-     *                                      to do with your addon, like 'Calendar' or '3D_View') and
32
-     *                                      model_name_extended} is the model extended.
33
-     *                                      The class contained in teh file should extend
34
-     *                                      EEME_Base_{model_name_extended}.model_ext.php.
35
-     *                                      Where {your_plugin_slug} is really anything you want (but something
36
-     *                                      having to do with your addon, like 'Calendar' or '3D_View') and
37
-     *                                      {model_name_extended} is the model extended. The class contained in teh
38
-     *                                      file should extend EEME_Base
39
-     * @type array   $class_extension_paths array of folders containing DB class extensions, where each file follows
40
-     *                                      the model class extension naming convention, which is:
41
-     *                                      EEE_{your_plugin_slug}_model_name_extended}.class_ext.php.
42
-     *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
43
-     *                                      and model_name_extended} is the name of the model extended, eg
44
-     *                                      'Attendee','Event',etc.
45
-     *                                      The class contained in the file should extend EEE_Base_Class
46
-     *                                      ._{model_name_extended}.class_ext.php.
47
-     *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
48
-     *                                      and {model_name_extended} is the name of the model extended, eg
49
-     *                                      'Attendee','Event',etc. The class contained in the file should extend
50
-     *                                      EEE_Base_Class.
51
-     *                                      }
52
-     *
53
-     */
54
-    public static function register(string $addon_name = '', array $setup_args = []): bool
55
-    {
56
-        // required fields MUST be present, so let's make sure they are.
57
-        if (
58
-            empty($addon_name)
59
-            || ! is_array($setup_args)
60
-            || (empty($setup_args['model_extension_paths']) && empty($setup_args['class_extension_paths']))
61
-        ) {
62
-            throw new EE_Error(
63
-                __(
64
-                    'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)',
65
-                    'event_espresso'
66
-                )
67
-            );
68
-        }
20
+	/**
21
+	 * register method for setting up model extensions
22
+	 *
23
+	 * @param string $addon_name            unique id for the extensions being setup
24
+	 * @param array  $setup_args            {
25
+	 * @return bool
26
+	 * @throws EE_Error
27
+	 * @type  array  $model_extension_paths array of folders containing DB model extensions, where each file follows
28
+	 *                                      the models naming convention, which is:
29
+	 *                                      EEME_{your_plugin_slug}_model_name_extended}.model_ext.php.
30
+	 *                                      Where {your_plugin_slug} is really anything you want (but something having
31
+	 *                                      to do with your addon, like 'Calendar' or '3D_View') and
32
+	 *                                      model_name_extended} is the model extended.
33
+	 *                                      The class contained in teh file should extend
34
+	 *                                      EEME_Base_{model_name_extended}.model_ext.php.
35
+	 *                                      Where {your_plugin_slug} is really anything you want (but something
36
+	 *                                      having to do with your addon, like 'Calendar' or '3D_View') and
37
+	 *                                      {model_name_extended} is the model extended. The class contained in teh
38
+	 *                                      file should extend EEME_Base
39
+	 * @type array   $class_extension_paths array of folders containing DB class extensions, where each file follows
40
+	 *                                      the model class extension naming convention, which is:
41
+	 *                                      EEE_{your_plugin_slug}_model_name_extended}.class_ext.php.
42
+	 *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
43
+	 *                                      and model_name_extended} is the name of the model extended, eg
44
+	 *                                      'Attendee','Event',etc.
45
+	 *                                      The class contained in the file should extend EEE_Base_Class
46
+	 *                                      ._{model_name_extended}.class_ext.php.
47
+	 *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
48
+	 *                                      and {model_name_extended} is the name of the model extended, eg
49
+	 *                                      'Attendee','Event',etc. The class contained in the file should extend
50
+	 *                                      EEE_Base_Class.
51
+	 *                                      }
52
+	 *
53
+	 */
54
+	public static function register(string $addon_name = '', array $setup_args = []): bool
55
+	{
56
+		// required fields MUST be present, so let's make sure they are.
57
+		if (
58
+			empty($addon_name)
59
+			|| ! is_array($setup_args)
60
+			|| (empty($setup_args['model_extension_paths']) && empty($setup_args['class_extension_paths']))
61
+		) {
62
+			throw new EE_Error(
63
+				__(
64
+					'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)',
65
+					'event_espresso'
66
+				)
67
+			);
68
+		}
69 69
 
70
-        // make sure we don't register twice
71
-        if (isset(self::$_registry[ $addon_name ])) {
72
-            return true;
73
-        }
74
-        // check correct loading
75
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
76
-            EE_Error::doing_it_wrong(
77
-                __METHOD__,
78
-                sprintf(
79
-                    __(
80
-                        'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s',
81
-                        'event_espresso'
82
-                    ),
83
-                    $addon_name,
84
-                    '<br />',
85
-                    did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done',
86
-                    did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done'
87
-                ),
88
-                '4.3'
89
-            );
90
-        }
70
+		// make sure we don't register twice
71
+		if (isset(self::$_registry[ $addon_name ])) {
72
+			return true;
73
+		}
74
+		// check correct loading
75
+		if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
76
+			EE_Error::doing_it_wrong(
77
+				__METHOD__,
78
+				sprintf(
79
+					__(
80
+						'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s',
81
+						'event_espresso'
82
+					),
83
+					$addon_name,
84
+					'<br />',
85
+					did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done',
86
+					did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done'
87
+				),
88
+				'4.3'
89
+			);
90
+		}
91 91
 
92
-        self::$_registry[ $addon_name ]   = $setup_args;
93
-        self::$_extensions[ $addon_name ] = [];
92
+		self::$_registry[ $addon_name ]   = $setup_args;
93
+		self::$_extensions[ $addon_name ] = [];
94 94
 
95
-        if (isset($setup_args['model_extension_paths'])) {
96
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
97
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
98
-            // remove all files that are not PHP
99
-            foreach ($class_to_filepath_map as $class => $path) {
100
-                if (substr($path, strlen($path) - 3) !== 'php') {
101
-                    unset($class_to_filepath_map[ $class ]);
102
-                }
103
-            }
104
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
105
-            foreach (array_keys($class_to_filepath_map) as $classname) {
106
-                self::$_extensions[ $addon_name ]['models'][ $classname ] = new $classname();
107
-            }
108
-            unset($setup_args['model_extension_paths']);
109
-        }
110
-        if (isset($setup_args['class_extension_paths'])) {
111
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
112
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
113
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
114
-            foreach (array_keys($class_to_filepath_map) as $classname) {
115
-                self::$_extensions[ $addon_name ]['classes'][ $classname ] = new $classname();
116
-            }
117
-            unset($setup_args['class_extension_paths']);
118
-        }
119
-        foreach ($setup_args as $unknown_key => $unknown_config) {
120
-            throw new EE_Error(
121
-                sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
122
-            );
123
-        }
124
-        return true;
125
-    }
95
+		if (isset($setup_args['model_extension_paths'])) {
96
+			require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
97
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
98
+			// remove all files that are not PHP
99
+			foreach ($class_to_filepath_map as $class => $path) {
100
+				if (substr($path, strlen($path) - 3) !== 'php') {
101
+					unset($class_to_filepath_map[ $class ]);
102
+				}
103
+			}
104
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
105
+			foreach (array_keys($class_to_filepath_map) as $classname) {
106
+				self::$_extensions[ $addon_name ]['models'][ $classname ] = new $classname();
107
+			}
108
+			unset($setup_args['model_extension_paths']);
109
+		}
110
+		if (isset($setup_args['class_extension_paths'])) {
111
+			require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
112
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
113
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
114
+			foreach (array_keys($class_to_filepath_map) as $classname) {
115
+				self::$_extensions[ $addon_name ]['classes'][ $classname ] = new $classname();
116
+			}
117
+			unset($setup_args['class_extension_paths']);
118
+		}
119
+		foreach ($setup_args as $unknown_key => $unknown_config) {
120
+			throw new EE_Error(
121
+				sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
122
+			);
123
+		}
124
+		return true;
125
+	}
126 126
 
127 127
 
128
-    /**
129
-     * deregister
130
-     *
131
-     * @param string $addon_name
132
-     */
133
-    public static function deregister(string $addon_name = '')
134
-    {
135
-        if (isset(self::$_registry[ $addon_name ])) {
136
-            unset(self::$_registry[ $addon_name ]);
137
-            foreach (self::$_extensions[ $addon_name ] as $extension_of_type) {
138
-                foreach ($extension_of_type as $extension) {
139
-                    $extension->deregister();
140
-                }
141
-            }
142
-        }
143
-    }
128
+	/**
129
+	 * deregister
130
+	 *
131
+	 * @param string $addon_name
132
+	 */
133
+	public static function deregister(string $addon_name = '')
134
+	{
135
+		if (isset(self::$_registry[ $addon_name ])) {
136
+			unset(self::$_registry[ $addon_name ]);
137
+			foreach (self::$_extensions[ $addon_name ] as $extension_of_type) {
138
+				foreach ($extension_of_type as $extension) {
139
+					$extension->deregister();
140
+				}
141
+			}
142
+		}
143
+	}
144 144
 }
Please login to merge, or discard this patch.
core/services/addon/api/IncompatibleAddonHandler.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -6,75 +6,75 @@
 block discarded – undo
6 6
 
7 7
 class IncompatibleAddonHandler
8 8
 {
9
-    /**
10
-     * @return void
11
-     */
12
-    public function deactivateIncompatibleAddons()
13
-    {
14
-        $this->deactivateIncompatibleAddon(
15
-            'Wait Lists',
16
-            'EE_WAIT_LISTS_VERSION',
17
-            '1.0.0.beta.074',
18
-            'load_espresso_wait_lists',
19
-            'EE_WAIT_LISTS_PLUGIN_FILE'
20
-        );
21
-        $this->deactivateIncompatibleAddon(
22
-            'Automated Upcoming Event Notifications',
23
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
24
-            '1.0.0.beta.091',
25
-            'load_espresso_automated_upcoming_event_notification',
26
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
27
-        );
28
-        // $this->deactivateIncompatibleAddon(
29
-        //     'WP Users Integration',
30
-        //     'EE_WPUSERS_VERSION',
31
-        //     '2.1.0.rc.003',
32
-        //     'load_ee_core_wpusers',
33
-        //     'EE_WPUSERS_PLUGIN_FILE'
34
-        // );
35
-    }
9
+	/**
10
+	 * @return void
11
+	 */
12
+	public function deactivateIncompatibleAddons()
13
+	{
14
+		$this->deactivateIncompatibleAddon(
15
+			'Wait Lists',
16
+			'EE_WAIT_LISTS_VERSION',
17
+			'1.0.0.beta.074',
18
+			'load_espresso_wait_lists',
19
+			'EE_WAIT_LISTS_PLUGIN_FILE'
20
+		);
21
+		$this->deactivateIncompatibleAddon(
22
+			'Automated Upcoming Event Notifications',
23
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
24
+			'1.0.0.beta.091',
25
+			'load_espresso_automated_upcoming_event_notification',
26
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
27
+		);
28
+		// $this->deactivateIncompatibleAddon(
29
+		//     'WP Users Integration',
30
+		//     'EE_WPUSERS_VERSION',
31
+		//     '2.1.0.rc.003',
32
+		//     'load_ee_core_wpusers',
33
+		//     'EE_WPUSERS_PLUGIN_FILE'
34
+		// );
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     * @param string $addon_name
40
-     * @param string $version_constant
41
-     * @param string $min_version_required
42
-     * @param string $load_callback
43
-     * @param string $plugin_file_constant
44
-     * @return void
45
-     */
46
-    private function deactivateIncompatibleAddon(
47
-        string $addon_name,
48
-        string $version_constant,
49
-        string $min_version_required,
50
-        string $load_callback,
51
-        string $plugin_file_constant
52
-    ) {
53
-        if (! defined($version_constant)) {
54
-            return;
55
-        }
56
-        $addon_version = constant($version_constant);
57
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
58
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
59
-            if (! function_exists('deactivate_plugins')) {
60
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
61
-            }
62
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
63
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
64
-            EE_Error::add_error(
65
-                sprintf(
66
-                    esc_html__(
67
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
68
-                        'event_espresso'
69
-                    ),
70
-                    $addon_name,
71
-                    $min_version_required
72
-                ),
73
-                __FILE__,
74
-                __FUNCTION__ . "({$addon_name})",
75
-                __LINE__
76
-            );
77
-            EE_Error::get_notices(false, true);
78
-        }
79
-    }
38
+	/**
39
+	 * @param string $addon_name
40
+	 * @param string $version_constant
41
+	 * @param string $min_version_required
42
+	 * @param string $load_callback
43
+	 * @param string $plugin_file_constant
44
+	 * @return void
45
+	 */
46
+	private function deactivateIncompatibleAddon(
47
+		string $addon_name,
48
+		string $version_constant,
49
+		string $min_version_required,
50
+		string $load_callback,
51
+		string $plugin_file_constant
52
+	) {
53
+		if (! defined($version_constant)) {
54
+			return;
55
+		}
56
+		$addon_version = constant($version_constant);
57
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
58
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
59
+			if (! function_exists('deactivate_plugins')) {
60
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
61
+			}
62
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
63
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
64
+			EE_Error::add_error(
65
+				sprintf(
66
+					esc_html__(
67
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
68
+						'event_espresso'
69
+					),
70
+					$addon_name,
71
+					$min_version_required
72
+				),
73
+				__FILE__,
74
+				__FUNCTION__ . "({$addon_name})",
75
+				__LINE__
76
+			);
77
+			EE_Error::get_notices(false, true);
78
+		}
79
+	}
80 80
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2893 added lines, -2893 removed lines patch added patch discarded remove patch
@@ -17,2900 +17,2900 @@
 block discarded – undo
17 17
 class Events_Admin_Page extends EE_Admin_Page_CPT
18 18
 {
19 19
 
20
-    /**
21
-     * This will hold the event object for event_details screen.
22
-     *
23
-     * @access protected
24
-     * @var EE_Event $_event
25
-     */
26
-    protected $_event;
27
-
28
-
29
-    /**
30
-     * This will hold the category object for category_details screen.
31
-     *
32
-     * @var stdClass $_category
33
-     */
34
-    protected $_category;
35
-
36
-
37
-    /**
38
-     * This will hold the event model instance
39
-     *
40
-     * @var EEM_Event $_event_model
41
-     */
42
-    protected $_event_model;
43
-
44
-
45
-    /**
46
-     * @var EE_Event
47
-     */
48
-    protected $_cpt_model_obj = false;
49
-
50
-
51
-    /**
52
-     * @var NodeGroupDao
53
-     */
54
-    protected $model_obj_node_group_persister;
55
-
56
-
57
-    /**
58
-     * Initialize page props for this admin page group.
59
-     */
60
-    protected function _init_page_props()
61
-    {
62
-        $this->page_slug        = EVENTS_PG_SLUG;
63
-        $this->page_label       = EVENTS_LABEL;
64
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
65
-        $this->_admin_base_path = EVENTS_ADMIN;
66
-        $this->_cpt_model_names = [
67
-            'create_new' => 'EEM_Event',
68
-            'edit'       => 'EEM_Event',
69
-        ];
70
-        $this->_cpt_edit_routes = [
71
-            'espresso_events' => 'edit',
72
-        ];
73
-        add_action(
74
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
75
-            [$this, 'verify_event_edit'],
76
-            10,
77
-            2
78
-        );
79
-    }
80
-
81
-
82
-    /**
83
-     * Sets the ajax hooks used for this admin page group.
84
-     */
85
-    protected function _ajax_hooks()
86
-    {
87
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
88
-    }
89
-
90
-
91
-    /**
92
-     * Sets the page properties for this admin page group.
93
-     */
94
-    protected function _define_page_props()
95
-    {
96
-        $this->_admin_page_title = EVENTS_LABEL;
97
-        $this->_labels           = [
98
-            'buttons'      => [
99
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
100
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
101
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
102
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
103
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
104
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
105
-            ],
106
-            'editor_title' => [
107
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
108
-            ],
109
-            'publishbox'   => [
110
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
111
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
112
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
113
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
114
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
115
-            ],
116
-        ];
117
-    }
118
-
119
-
120
-    /**
121
-     * Sets the page routes property for this admin page group.
122
-     */
123
-    protected function _set_page_routes()
124
-    {
125
-        // load formatter helper
126
-        // load field generator helper
127
-        // is there a evt_id in the request?
128
-        $evt_id             = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
129
-            ? $this->_req_data['EVT_ID']
130
-            : 0;
131
-        $evt_id             = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
132
-        $this->_page_routes = [
133
-            'default'                       => [
134
-                'func'       => '_events_overview_list_table',
135
-                'capability' => 'ee_read_events',
136
-            ],
137
-            'create_new'                    => [
138
-                'func'       => '_create_new_cpt_item',
139
-                'capability' => 'ee_edit_events',
140
-            ],
141
-            'edit'                          => [
142
-                'func'       => '_edit_cpt_item',
143
-                'capability' => 'ee_edit_event',
144
-                'obj_id'     => $evt_id,
145
-            ],
146
-            'copy_event'                    => [
147
-                'func'       => '_copy_events',
148
-                'capability' => 'ee_edit_event',
149
-                'obj_id'     => $evt_id,
150
-                'noheader'   => true,
151
-            ],
152
-            'trash_event'                   => [
153
-                'func'       => '_trash_or_restore_event',
154
-                'args'       => ['event_status' => 'trash'],
155
-                'capability' => 'ee_delete_event',
156
-                'obj_id'     => $evt_id,
157
-                'noheader'   => true,
158
-            ],
159
-            'trash_events'                  => [
160
-                'func'       => '_trash_or_restore_events',
161
-                'args'       => ['event_status' => 'trash'],
162
-                'capability' => 'ee_delete_events',
163
-                'noheader'   => true,
164
-            ],
165
-            'restore_event'                 => [
166
-                'func'       => '_trash_or_restore_event',
167
-                'args'       => ['event_status' => 'draft'],
168
-                'capability' => 'ee_delete_event',
169
-                'obj_id'     => $evt_id,
170
-                'noheader'   => true,
171
-            ],
172
-            'restore_events'                => [
173
-                'func'       => '_trash_or_restore_events',
174
-                'args'       => ['event_status' => 'draft'],
175
-                'capability' => 'ee_delete_events',
176
-                'noheader'   => true,
177
-            ],
178
-            'delete_event'                  => [
179
-                'func'       => '_delete_event',
180
-                'capability' => 'ee_delete_event',
181
-                'obj_id'     => $evt_id,
182
-                'noheader'   => true,
183
-            ],
184
-            'delete_events'                 => [
185
-                'func'       => '_delete_events',
186
-                'capability' => 'ee_delete_events',
187
-                'noheader'   => true,
188
-            ],
189
-            'view_report'                   => [
190
-                'func'       => '_view_report',
191
-                'capability' => 'ee_edit_events',
192
-            ],
193
-            'default_event_settings'        => [
194
-                'func'       => '_default_event_settings',
195
-                'capability' => 'manage_options',
196
-            ],
197
-            'update_default_event_settings' => [
198
-                'func'       => '_update_default_event_settings',
199
-                'capability' => 'manage_options',
200
-                'noheader'   => true,
201
-            ],
202
-            'template_settings'             => [
203
-                'func'       => '_template_settings',
204
-                'capability' => 'manage_options',
205
-            ],
206
-            // event category tab related
207
-            'add_category'                  => [
208
-                'func'       => '_category_details',
209
-                'capability' => 'ee_edit_event_category',
210
-                'args'       => ['add'],
211
-            ],
212
-            'edit_category'                 => [
213
-                'func'       => '_category_details',
214
-                'capability' => 'ee_edit_event_category',
215
-                'args'       => ['edit'],
216
-            ],
217
-            'delete_categories'             => [
218
-                'func'       => '_delete_categories',
219
-                'capability' => 'ee_delete_event_category',
220
-                'noheader'   => true,
221
-            ],
222
-            'delete_category'               => [
223
-                'func'       => '_delete_categories',
224
-                'capability' => 'ee_delete_event_category',
225
-                'noheader'   => true,
226
-            ],
227
-            'insert_category'               => [
228
-                'func'       => '_insert_or_update_category',
229
-                'args'       => ['new_category' => true],
230
-                'capability' => 'ee_edit_event_category',
231
-                'noheader'   => true,
232
-            ],
233
-            'update_category'               => [
234
-                'func'       => '_insert_or_update_category',
235
-                'args'       => ['new_category' => false],
236
-                'capability' => 'ee_edit_event_category',
237
-                'noheader'   => true,
238
-            ],
239
-            'category_list'                 => [
240
-                'func'       => '_category_list_table',
241
-                'capability' => 'ee_manage_event_categories',
242
-            ],
243
-            'preview_deletion'              => [
244
-                'func'       => 'previewDeletion',
245
-                'capability' => 'ee_delete_events',
246
-            ],
247
-            'confirm_deletion'              => [
248
-                'func'       => 'confirmDeletion',
249
-                'capability' => 'ee_delete_events',
250
-                'noheader'   => true,
251
-            ],
252
-        ];
253
-    }
254
-
255
-
256
-    /**
257
-     * Set the _page_config property for this admin page group.
258
-     */
259
-    protected function _set_page_config()
260
-    {
261
-        $this->_page_config = [
262
-            'default'                => [
263
-                'nav'           => [
264
-                    'label' => esc_html__('Overview', 'event_espresso'),
265
-                    'order' => 10,
266
-                ],
267
-                'list_table'    => 'Events_Admin_List_Table',
268
-                'help_tabs'     => [
269
-                    'events_overview_help_tab'                       => [
270
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
271
-                        'filename' => 'events_overview',
272
-                    ],
273
-                    'events_overview_table_column_headings_help_tab' => [
274
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
275
-                        'filename' => 'events_overview_table_column_headings',
276
-                    ],
277
-                    'events_overview_filters_help_tab'               => [
278
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
279
-                        'filename' => 'events_overview_filters',
280
-                    ],
281
-                    'events_overview_view_help_tab'                  => [
282
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
283
-                        'filename' => 'events_overview_views',
284
-                    ],
285
-                    'events_overview_other_help_tab'                 => [
286
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
287
-                        'filename' => 'events_overview_other',
288
-                    ],
289
-                ],
290
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
291
-                // 'help_tour'     => [
292
-                //     'Event_Overview_Help_Tour',
293
-                //     // 'New_Features_Test_Help_Tour' for testing multiple help tour
294
-                // ],
295
-                'require_nonce' => false,
296
-                'qtips'         => ['EE_Event_List_Table_Tips'],
297
-            ],
298
-            'create_new'             => [
299
-                'nav'           => [
300
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
301
-                    'order'      => 5,
302
-                    'persistent' => false,
303
-                ],
304
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
305
-                'help_tabs'     => [
306
-                    'event_editor_help_tab'                            => [
307
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
308
-                        'filename' => 'event_editor',
309
-                    ],
310
-                    'event_editor_title_richtexteditor_help_tab'       => [
311
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
312
-                        'filename' => 'event_editor_title_richtexteditor',
313
-                    ],
314
-                    'event_editor_venue_details_help_tab'              => [
315
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
316
-                        'filename' => 'event_editor_venue_details',
317
-                    ],
318
-                    'event_editor_event_datetimes_help_tab'            => [
319
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
320
-                        'filename' => 'event_editor_event_datetimes',
321
-                    ],
322
-                    'event_editor_event_tickets_help_tab'              => [
323
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
324
-                        'filename' => 'event_editor_event_tickets',
325
-                    ],
326
-                    'event_editor_event_registration_options_help_tab' => [
327
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
328
-                        'filename' => 'event_editor_event_registration_options',
329
-                    ],
330
-                    'event_editor_tags_categories_help_tab'            => [
331
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
332
-                        'filename' => 'event_editor_tags_categories',
333
-                    ],
334
-                    'event_editor_questions_registrants_help_tab'      => [
335
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
336
-                        'filename' => 'event_editor_questions_registrants',
337
-                    ],
338
-                    'event_editor_save_new_event_help_tab'             => [
339
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
340
-                        'filename' => 'event_editor_save_new_event',
341
-                    ],
342
-                    'event_editor_other_help_tab'                      => [
343
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
344
-                        'filename' => 'event_editor_other',
345
-                    ],
346
-                ],
347
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
348
-                // 'help_tour'     => [
349
-                //     'Event_Editor_Help_Tour',
350
-                // ],
351
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
352
-                'require_nonce' => false,
353
-            ],
354
-            'edit'                   => [
355
-                'nav'           => [
356
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
357
-                    'order'      => 5,
358
-                    'persistent' => false,
359
-                    'url'        => isset($this->_req_data['post'])
360
-                        ? EE_Admin_Page::add_query_args_and_nonce(
361
-                            ['post' => $this->_req_data['post'], 'action' => 'edit'],
362
-                            $this->_current_page_view_url
363
-                        )
364
-                        : $this->_admin_base_url,
365
-                ],
366
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
367
-                'help_tabs'     => [
368
-                    'event_editor_help_tab'                            => [
369
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
370
-                        'filename' => 'event_editor',
371
-                    ],
372
-                    'event_editor_title_richtexteditor_help_tab'       => [
373
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
374
-                        'filename' => 'event_editor_title_richtexteditor',
375
-                    ],
376
-                    'event_editor_venue_details_help_tab'              => [
377
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
378
-                        'filename' => 'event_editor_venue_details',
379
-                    ],
380
-                    'event_editor_event_datetimes_help_tab'            => [
381
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
382
-                        'filename' => 'event_editor_event_datetimes',
383
-                    ],
384
-                    'event_editor_event_tickets_help_tab'              => [
385
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
386
-                        'filename' => 'event_editor_event_tickets',
387
-                    ],
388
-                    'event_editor_event_registration_options_help_tab' => [
389
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
390
-                        'filename' => 'event_editor_event_registration_options',
391
-                    ],
392
-                    'event_editor_tags_categories_help_tab'            => [
393
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
394
-                        'filename' => 'event_editor_tags_categories',
395
-                    ],
396
-                    'event_editor_questions_registrants_help_tab'      => [
397
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
398
-                        'filename' => 'event_editor_questions_registrants',
399
-                    ],
400
-                    'event_editor_save_new_event_help_tab'             => [
401
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
402
-                        'filename' => 'event_editor_save_new_event',
403
-                    ],
404
-                    'event_editor_other_help_tab'                      => [
405
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
406
-                        'filename' => 'event_editor_other',
407
-                    ],
408
-                ],
409
-                'require_nonce' => false,
410
-            ],
411
-            'default_event_settings' => [
412
-                'nav'           => [
413
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
414
-                    'order' => 40,
415
-                ],
416
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
417
-                'labels'        => [
418
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
419
-                ],
420
-                'help_tabs'     => [
421
-                    'default_settings_help_tab'        => [
422
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
423
-                        'filename' => 'events_default_settings',
424
-                    ],
425
-                    'default_settings_status_help_tab' => [
426
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
427
-                        'filename' => 'events_default_settings_status',
428
-                    ],
429
-                    'default_maximum_tickets_help_tab' => [
430
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
431
-                        'filename' => 'events_default_settings_max_tickets',
432
-                    ],
433
-                ],
434
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
435
-                // 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
436
-                'require_nonce' => false,
437
-            ],
438
-            // template settings
439
-            'template_settings'      => [
440
-                'nav'           => [
441
-                    'label' => esc_html__('Templates', 'event_espresso'),
442
-                    'order' => 30,
443
-                ],
444
-                'metaboxes'     => $this->_default_espresso_metaboxes,
445
-                'help_tabs'     => [
446
-                    'general_settings_templates_help_tab' => [
447
-                        'title'    => esc_html__('Templates', 'event_espresso'),
448
-                        'filename' => 'general_settings_templates',
449
-                    ],
450
-                ],
451
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
452
-                // 'help_tour'     => ['Templates_Help_Tour'],
453
-                'require_nonce' => false,
454
-            ],
455
-            // event category stuff
456
-            'add_category'           => [
457
-                'nav'           => [
458
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
459
-                    'order'      => 15,
460
-                    'persistent' => false,
461
-                ],
462
-                'help_tabs'     => [
463
-                    'add_category_help_tab' => [
464
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
465
-                        'filename' => 'events_add_category',
466
-                    ],
467
-                ],
468
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
469
-                // 'help_tour'     => ['Event_Add_Category_Help_Tour'],
470
-                'metaboxes'     => ['_publish_post_box'],
471
-                'require_nonce' => false,
472
-            ],
473
-            'edit_category'          => [
474
-                'nav'           => [
475
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
476
-                    'order'      => 15,
477
-                    'persistent' => false,
478
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
479
-                        ? add_query_arg(
480
-                            ['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']],
481
-                            $this->_current_page_view_url
482
-                        )
483
-                        : $this->_admin_base_url,
484
-                ],
485
-                'help_tabs'     => [
486
-                    'edit_category_help_tab' => [
487
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
488
-                        'filename' => 'events_edit_category',
489
-                    ],
490
-                ],
491
-                /*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
492
-                'metaboxes'     => ['_publish_post_box'],
493
-                'require_nonce' => false,
494
-            ],
495
-            'category_list'          => [
496
-                'nav'           => [
497
-                    'label' => esc_html__('Categories', 'event_espresso'),
498
-                    'order' => 20,
499
-                ],
500
-                'list_table'    => 'Event_Categories_Admin_List_Table',
501
-                'help_tabs'     => [
502
-                    'events_categories_help_tab'                       => [
503
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
504
-                        'filename' => 'events_categories',
505
-                    ],
506
-                    'events_categories_table_column_headings_help_tab' => [
507
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
508
-                        'filename' => 'events_categories_table_column_headings',
509
-                    ],
510
-                    'events_categories_view_help_tab'                  => [
511
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
512
-                        'filename' => 'events_categories_views',
513
-                    ],
514
-                    'events_categories_other_help_tab'                 => [
515
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
516
-                        'filename' => 'events_categories_other',
517
-                    ],
518
-                ],
519
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
520
-                // 'help_tour'     => [
521
-                //     'Event_Categories_Help_Tour',
522
-                // ],
523
-                'metaboxes'     => $this->_default_espresso_metaboxes,
524
-                'require_nonce' => false,
525
-            ],
526
-            'preview_deletion'       => [
527
-                'nav'           => [
528
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
529
-                    'order'      => 15,
530
-                    'persistent' => false,
531
-                    'url'        => '',
532
-                ],
533
-                'require_nonce' => false,
534
-            ],
535
-        ];
536
-        // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
537
-        $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
538
-        if (! $domain->isCaffeinated()) {
539
-            $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
540
-            $this->_page_config['edit']['qtips']       = ['EE_Event_Editor_Decaf_Tips'];
541
-        }
542
-    }
543
-
544
-
545
-    /**
546
-     * Used to register any global screen options if necessary for every route in this admin page group.
547
-     */
548
-    protected function _add_screen_options()
549
-    {
550
-    }
551
-
552
-
553
-    /**
554
-     * Implementing the screen options for the 'default' route.
555
-     *
556
-     * @throws InvalidArgumentException
557
-     * @throws InvalidDataTypeException
558
-     * @throws InvalidInterfaceException
559
-     */
560
-    protected function _add_screen_options_default()
561
-    {
562
-        $this->_per_page_screen_option();
563
-    }
564
-
565
-
566
-    /**
567
-     * Implementing screen options for the category list route.
568
-     *
569
-     * @throws InvalidArgumentException
570
-     * @throws InvalidDataTypeException
571
-     * @throws InvalidInterfaceException
572
-     */
573
-    protected function _add_screen_options_category_list()
574
-    {
575
-        $page_title              = $this->_admin_page_title;
576
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
577
-        $this->_per_page_screen_option();
578
-        $this->_admin_page_title = $page_title;
579
-    }
580
-
581
-
582
-    /**
583
-     * Used to register any global feature pointers for the admin page group.
584
-     */
585
-    protected function _add_feature_pointers()
586
-    {
587
-    }
588
-
589
-
590
-    /**
591
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
592
-     */
593
-    public function load_scripts_styles()
594
-    {
595
-        wp_register_style(
596
-            'events-admin-css',
597
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
598
-            [],
599
-            EVENT_ESPRESSO_VERSION
600
-        );
601
-        wp_register_style(
602
-            'ee-cat-admin',
603
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
604
-            [],
605
-            EVENT_ESPRESSO_VERSION
606
-        );
607
-        wp_enqueue_style('events-admin-css');
608
-        wp_enqueue_style('ee-cat-admin');
609
-        // scripts
610
-        wp_register_script(
611
-            'event_editor_js',
612
-            EVENTS_ASSETS_URL . 'event_editor.js',
613
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
614
-            EVENT_ESPRESSO_VERSION,
615
-            true
616
-        );
617
-    }
618
-
619
-
620
-    /**
621
-     * Enqueuing scripts and styles specific to this view
622
-     */
623
-    public function load_scripts_styles_create_new()
624
-    {
625
-        $this->load_scripts_styles_edit();
626
-    }
627
-
628
-
629
-    /**
630
-     * Enqueuing scripts and styles specific to this view
631
-     */
632
-    public function load_scripts_styles_edit()
633
-    {
634
-        // styles
635
-        wp_enqueue_style('espresso-ui-theme');
636
-        wp_register_style(
637
-            'event-editor-css',
638
-            EVENTS_ASSETS_URL . 'event-editor.css',
639
-            ['ee-admin-css'],
640
-            EVENT_ESPRESSO_VERSION
641
-        );
642
-        wp_enqueue_style('event-editor-css');
643
-        // scripts
644
-        if (! $this->admin_config->useAdvancedEditor()) {
645
-            wp_register_script(
646
-                'event-datetime-metabox',
647
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
648
-                ['event_editor_js', 'ee-datepicker'],
649
-                EVENT_ESPRESSO_VERSION
650
-            );
651
-            wp_enqueue_script('event-datetime-metabox');
652
-        }
653
-    }
654
-
655
-
656
-    /**
657
-     * Populating the _views property for the category list table view.
658
-     */
659
-    protected function _set_list_table_views_category_list()
660
-    {
661
-        $this->_views = [
662
-            'all' => [
663
-                'slug'        => 'all',
664
-                'label'       => esc_html__('All', 'event_espresso'),
665
-                'count'       => 0,
666
-                'bulk_action' => [
667
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
668
-                ],
669
-            ],
670
-        ];
671
-    }
672
-
673
-
674
-    /**
675
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
676
-     */
677
-    public function admin_init()
678
-    {
679
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
680
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
681
-            'event_espresso'
682
-        );
683
-    }
684
-
685
-
686
-    /**
687
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
688
-     * group.
689
-     */
690
-    public function admin_notices()
691
-    {
692
-    }
693
-
694
-
695
-    /**
696
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
697
-     * this admin page group.
698
-     */
699
-    public function admin_footer_scripts()
700
-    {
701
-    }
702
-
703
-
704
-    /**
705
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
706
-     * warning (via EE_Error::add_error());
707
-     *
708
-     * @param EE_Event $event Event object
709
-     * @param string   $req_type
710
-     * @return void
711
-     * @throws EE_Error
712
-     * @access public
713
-     */
714
-    public function verify_event_edit($event = null, $req_type = '')
715
-    {
716
-        // don't need to do this when processing
717
-        if (! empty($req_type)) {
718
-            return;
719
-        }
720
-        // no event?
721
-        if (! $event instanceof EE_Event) {
722
-            $event = $this->_cpt_model_obj;
723
-        }
724
-        // STILL no event?
725
-        if (! $event instanceof EE_Event) {
726
-            return;
727
-        }
728
-        $orig_status = $event->status();
729
-        // first check if event is active.
730
-        if (
731
-            $orig_status === EEM_Event::cancelled
732
-            || $orig_status === EEM_Event::postponed
733
-            || $event->is_expired()
734
-            || $event->is_inactive()
735
-        ) {
736
-            return;
737
-        }
738
-        // made it here so it IS active... next check that any of the tickets are sold.
739
-        if ($event->is_sold_out(true)) {
740
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
741
-                EE_Error::add_attention(
742
-                    sprintf(
743
-                        esc_html__(
744
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
745
-                            'event_espresso'
746
-                        ),
747
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
748
-                    )
749
-                );
750
-            }
751
-            return;
752
-        }
753
-        if ($orig_status === EEM_Event::sold_out) {
754
-            EE_Error::add_attention(
755
-                sprintf(
756
-                    esc_html__(
757
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
758
-                        'event_espresso'
759
-                    ),
760
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
761
-                )
762
-            );
763
-        }
764
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
765
-        if (! $event->tickets_on_sale()) {
766
-            return;
767
-        }
768
-        // made it here so show warning
769
-        $this->_edit_event_warning();
770
-    }
771
-
772
-
773
-    /**
774
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
775
-     * When needed, hook this into a EE_Error::add_error() notice.
776
-     *
777
-     * @access protected
778
-     * @return void
779
-     */
780
-    protected function _edit_event_warning()
781
-    {
782
-        // we don't want to add warnings during these requests
783
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
784
-            return;
785
-        }
786
-        EE_Error::add_attention(
787
-            sprintf(
788
-                esc_html__(
789
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
790
-                    'event_espresso'
791
-                ),
792
-                '<a class="espresso-help-tab-lnk">',
793
-                '</a>'
794
-            )
795
-        );
796
-    }
797
-
798
-
799
-    /**
800
-     * When a user is creating a new event, notify them if they haven't set their timezone.
801
-     * Otherwise, do the normal logic
802
-     *
803
-     * @return void
804
-     * @throws EE_Error
805
-     * @throws InvalidArgumentException
806
-     * @throws InvalidDataTypeException
807
-     * @throws InvalidInterfaceException
808
-     */
809
-    protected function _create_new_cpt_item()
810
-    {
811
-        $has_timezone_string = get_option('timezone_string');
812
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
813
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
814
-            EE_Error::add_attention(
815
-                sprintf(
816
-                    __(
817
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
818
-                        'event_espresso'
819
-                    ),
820
-                    '<br>',
821
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
822
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
823
-                    . '</select>',
824
-                    '<button class="button button-secondary timezone-submit">',
825
-                    '</button><span class="spinner"></span>'
826
-                ),
827
-                __FILE__,
828
-                __FUNCTION__,
829
-                __LINE__
830
-            );
831
-        }
832
-        parent::_create_new_cpt_item();
833
-    }
834
-
835
-
836
-    /**
837
-     * Sets the _views property for the default route in this admin page group.
838
-     */
839
-    protected function _set_list_table_views_default()
840
-    {
841
-        $this->_views = [
842
-            'all'   => [
843
-                'slug'        => 'all',
844
-                'label'       => esc_html__('View All Events', 'event_espresso'),
845
-                'count'       => 0,
846
-                'bulk_action' => [
847
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
848
-                ],
849
-            ],
850
-            'draft' => [
851
-                'slug'        => 'draft',
852
-                'label'       => esc_html__('Draft', 'event_espresso'),
853
-                'count'       => 0,
854
-                'bulk_action' => [
855
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
856
-                ],
857
-            ],
858
-        ];
859
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
860
-            $this->_views['trash'] = [
861
-                'slug'        => 'trash',
862
-                'label'       => esc_html__('Trash', 'event_espresso'),
863
-                'count'       => 0,
864
-                'bulk_action' => [
865
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
866
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
867
-                ],
868
-            ];
869
-        }
870
-    }
871
-
872
-
873
-    /**
874
-     * Provides the legend item array for the default list table view.
875
-     *
876
-     * @return array
877
-     */
878
-    protected function _event_legend_items()
879
-    {
880
-        $items    = [
881
-            'view_details'   => [
882
-                'class' => 'dashicons dashicons-search',
883
-                'desc'  => esc_html__('View Event', 'event_espresso'),
884
-            ],
885
-            'edit_event'     => [
886
-                'class' => 'ee-icon ee-icon-calendar-edit',
887
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
888
-            ],
889
-            'view_attendees' => [
890
-                'class' => 'dashicons dashicons-groups',
891
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
892
-            ],
893
-        ];
894
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
895
-        $statuses = [
896
-            'sold_out_status'  => [
897
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
898
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
899
-            ],
900
-            'active_status'    => [
901
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
902
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
903
-            ],
904
-            'upcoming_status'  => [
905
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
906
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
907
-            ],
908
-            'postponed_status' => [
909
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
910
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
911
-            ],
912
-            'cancelled_status' => [
913
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
914
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
915
-            ],
916
-            'expired_status'   => [
917
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
918
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
919
-            ],
920
-            'inactive_status'  => [
921
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
922
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
923
-            ],
924
-        ];
925
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
926
-        return array_merge($items, $statuses);
927
-    }
928
-
929
-
930
-    /**
931
-     * @return EEM_Event
932
-     * @throws EE_Error
933
-     * @throws InvalidArgumentException
934
-     * @throws InvalidDataTypeException
935
-     * @throws InvalidInterfaceException
936
-     * @throws ReflectionException
937
-     */
938
-    private function _event_model()
939
-    {
940
-        if (! $this->_event_model instanceof EEM_Event) {
941
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
942
-        }
943
-        return $this->_event_model;
944
-    }
945
-
946
-
947
-    /**
948
-     * Adds extra buttons to the WP CPT permalink field row.
949
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
950
-     *
951
-     * @param string $return    the current html
952
-     * @param int    $id        the post id for the page
953
-     * @param string $new_title What the title is
954
-     * @param string $new_slug  what the slug is
955
-     * @return string            The new html string for the permalink area
956
-     */
957
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
958
-    {
959
-        // make sure this is only when editing
960
-        if (! empty($id)) {
961
-            $post   = get_post($id);
962
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
963
-                       . esc_html__('Shortcode', 'event_espresso')
964
-                       . '</a> ';
965
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
966
-                       . $post->ID
967
-                       . ']">';
968
-        }
969
-        return $return;
970
-    }
971
-
972
-
973
-    /**
974
-     * _events_overview_list_table
975
-     * This contains the logic for showing the events_overview list
976
-     *
977
-     * @access protected
978
-     * @return void
979
-     * @throws DomainException
980
-     * @throws EE_Error
981
-     * @throws InvalidArgumentException
982
-     * @throws InvalidDataTypeException
983
-     * @throws InvalidInterfaceException
984
-     */
985
-    protected function _events_overview_list_table()
986
-    {
987
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
988
-        $after_list_table                           = [];
989
-        $after_list_table['view_event_list_button'] = EEH_HTML::br();
990
-        $after_list_table['view_event_list_button'] .= EEH_Template::get_button_or_link(
991
-            get_post_type_archive_link('espresso_events'),
992
-            esc_html__('View Event Archive Page', 'event_espresso'),
993
-            'button'
994
-        );
995
-        $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
996
-        $this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
997
-            'create_new',
998
-            'add',
999
-            [],
1000
-            'add-new-h2'
1001
-        );
1002
-        $this->_template_args['after_list_table']   = array_merge(
1003
-            (array) $this->_template_args['after_list_table'],
1004
-            $after_list_table
1005
-        );
1006
-        $this->display_admin_list_table_page_with_no_sidebar();
1007
-    }
1008
-
1009
-
1010
-    /**
1011
-     * this allows for extra misc actions in the default WP publish box
1012
-     *
1013
-     * @return void
1014
-     * @throws DomainException
1015
-     * @throws EE_Error
1016
-     * @throws InvalidArgumentException
1017
-     * @throws InvalidDataTypeException
1018
-     * @throws InvalidInterfaceException
1019
-     * @throws ReflectionException
1020
-     */
1021
-    public function extra_misc_actions_publish_box()
1022
-    {
1023
-        $this->_generate_publish_box_extra_content();
1024
-    }
1025
-
1026
-
1027
-    /**
1028
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1029
-     * saved.
1030
-     * Typically you would use this to save any additional data.
1031
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1032
-     * ALSO very important.  When a post transitions from scheduled to published,
1033
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1034
-     * other meta saves. So MAKE sure that you handle this accordingly.
1035
-     *
1036
-     * @access protected
1037
-     * @abstract
1038
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1039
-     * @param object $post    The post object of the cpt that was saved.
1040
-     * @return void
1041
-     * @throws EE_Error
1042
-     * @throws InvalidArgumentException
1043
-     * @throws InvalidDataTypeException
1044
-     * @throws InvalidInterfaceException
1045
-     * @throws ReflectionException
1046
-     */
1047
-    protected function _insert_update_cpt_item($post_id, $post)
1048
-    {
1049
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1050
-            // get out we're not processing an event save.
1051
-            return;
1052
-        }
1053
-        $event_values = [
1054
-            'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1055
-            'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1056
-            'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1057
-                ? sanitize_text_field($this->_req_data['timezone_string'])
1058
-                : null,
1059
-        ];
1060
-        /** @var FeatureFlags $flags */
1061
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1062
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1063
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1064
-            $event_values['EVT_display_ticket_selector']     =
1065
-                ! empty($this->_req_data['display_ticket_selector'])
1066
-                    ? 1
1067
-                    : 0;
1068
-            $event_values['EVT_additional_limit']            = min(
1069
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1070
-                ! empty($this->_req_data['additional_limit'])
1071
-                    ? absint($this->_req_data['additional_limit'])
1072
-                    : null
1073
-            );
1074
-            $event_values['EVT_default_registration_status'] =
1075
-                ! empty($this->_req_data['EVT_default_registration_status'])
1076
-                    ? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1077
-                    : EE_Registry::instance()->CFG->registration->default_STS_ID;
1078
-            $event_values['EVT_external_URL']                = ! empty($this->_req_data['externalURL'])
1079
-                ? esc_url_raw($this->_req_data['externalURL'])
1080
-                : null;
1081
-            $event_values['EVT_phone']                       = ! empty($this->_req_data['event_phone'])
1082
-                ? sanitize_text_field($this->_req_data['event_phone'])
1083
-                : null;
1084
-        }
1085
-        // update event
1086
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1087
-        // get event_object for other metaboxes...
1088
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1089
-        // i have to setup where conditions to override the filters in the model that filter out autodraft
1090
-        // and inherit statuses so we GET the inherit id!
1091
-        $get_one_where = [
1092
-            $this->_event_model()->primary_key_name() => $post_id,
1093
-            'OR'                                      => [
1094
-                'status'   => $post->post_status,
1095
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1096
-                // but the returned object here has a status of "publish", so use the original post status as well
1097
-                'status*1' => $this->_req_data['original_post_status'],
1098
-            ],
1099
-        ];
1100
-        $event         = $this->_event_model()->get_one([$get_one_where]);
1101
-        // the following are default callbacks for event attachment updates
1102
-        // that can be overridden by caffeinated functionality and/or addons.
1103
-        $event_update_callbacks = apply_filters(
1104
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1105
-            [
1106
-                [$this, '_default_venue_update'],
1107
-                [$this, '_default_tickets_update'],
1108
-            ]
1109
-        );
1110
-        $att_success            = true;
1111
-        foreach ($event_update_callbacks as $e_callback) {
1112
-            $_success = is_callable($e_callback)
1113
-                ? $e_callback($event, $this->_req_data)
1114
-                : false;
1115
-            // if ANY of these updates fail then we want the appropriate global error message
1116
-            $att_success = ! $att_success ? $att_success : $_success;
1117
-        }
1118
-        // any errors?
1119
-        if ($success && false === $att_success) {
1120
-            EE_Error::add_error(
1121
-                esc_html__(
1122
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1123
-                    'event_espresso'
1124
-                ),
1125
-                __FILE__,
1126
-                __FUNCTION__,
1127
-                __LINE__
1128
-            );
1129
-        } elseif ($success === false) {
1130
-            EE_Error::add_error(
1131
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1132
-                __FILE__,
1133
-                __FUNCTION__,
1134
-                __LINE__
1135
-            );
1136
-        }
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * @param int $post_id
1142
-     * @param int $revision_id
1143
-     * @throws EE_Error
1144
-     * @throws InvalidArgumentException
1145
-     * @throws InvalidDataTypeException
1146
-     * @throws InvalidInterfaceException
1147
-     * @throws ReflectionException
1148
-     * @see parent::restore_item()
1149
-     */
1150
-    protected function _restore_cpt_item($post_id, $revision_id)
1151
-    {
1152
-        // copy existing event meta to new post
1153
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1154
-        if ($post_evt instanceof EE_Event) {
1155
-            // meta revision restore
1156
-            $post_evt->restore_revision($revision_id);
1157
-            // related objs restore
1158
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1159
-        }
1160
-    }
1161
-
1162
-
1163
-    /**
1164
-     * Attach the venue to the Event
1165
-     *
1166
-     * @param EE_Event $evtobj Event Object to add the venue to
1167
-     * @param array    $data   The request data from the form
1168
-     * @return bool           Success or fail.
1169
-     * @throws EE_Error
1170
-     * @throws InvalidArgumentException
1171
-     * @throws InvalidDataTypeException
1172
-     * @throws InvalidInterfaceException
1173
-     * @throws ReflectionException
1174
-     */
1175
-    protected function _default_venue_update(EE_Event $evtobj, $data)
1176
-    {
1177
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1178
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1179
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1180
-        // very important.  If we don't have a venue name...
1181
-        // then we'll get out because not necessary to create empty venue
1182
-        if (empty($data['venue_title'])) {
1183
-            return false;
1184
-        }
1185
-        $venue_array = [
1186
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1187
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1188
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1189
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1190
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1191
-                : null,
1192
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1193
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1194
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1195
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1196
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1197
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1198
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1199
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1200
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1201
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1202
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1203
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1204
-            'status'              => 'publish',
1205
-        ];
1206
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1207
-        if (! empty($venue_id)) {
1208
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1209
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1210
-            // we've gotta make sure that the venue is always attached to a revision..
1211
-            // add_relation_to should take care of making sure that the relation is already present.
1212
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1213
-            return $rows_affected > 0;
1214
-        }
1215
-        // we insert the venue
1216
-        $venue_id = $venue_model->insert($venue_array);
1217
-        $evtobj->_add_relation_to($venue_id, 'Venue');
1218
-        return ! empty($venue_id);
1219
-        // when we have the ancestor come in it's already been handled by the revision save.
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1225
-     *
1226
-     * @param EE_Event $evtobj The Event object we're attaching data to
1227
-     * @param array    $data   The request data from the form
1228
-     * @return array
1229
-     * @throws EE_Error
1230
-     * @throws InvalidArgumentException
1231
-     * @throws InvalidDataTypeException
1232
-     * @throws InvalidInterfaceException
1233
-     * @throws ReflectionException
1234
-     * @throws Exception
1235
-     */
1236
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1237
-    {
1238
-        if ($this->admin_config->useAdvancedEditor()) {
1239
-            return [];
1240
-        }
1241
-        $success               = true;
1242
-        $saved_dtt             = null;
1243
-        $saved_tickets         = [];
1244
-        $incoming_date_formats = ['Y-m-d', 'h:i a'];
1245
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1246
-            // trim all values to ensure any excess whitespace is removed.
1247
-            $dtt                = array_map('trim', $dtt);
1248
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1249
-                : $dtt['DTT_EVT_start'];
1250
-            $datetime_values    = [
1251
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1252
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1253
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1254
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1255
-                'DTT_order'     => $row,
1256
-            ];
1257
-            // if we have an id then let's get existing object first and then set the new values.
1258
-            //  Otherwise we instantiate a new object for save.
1259
-            if (! empty($dtt['DTT_ID'])) {
1260
-                $DTM = EE_Registry::instance()
1261
-                                  ->load_model('Datetime', [$evtobj->get_timezone()])
1262
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1263
-                $DTM->set_date_format($incoming_date_formats[0]);
1264
-                $DTM->set_time_format($incoming_date_formats[1]);
1265
-                foreach ($datetime_values as $field => $value) {
1266
-                    $DTM->set($field, $value);
1267
-                }
1268
-                // make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it.
1269
-                // We need to do this so we dont' TRASH the parent DTT.
1270
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1271
-            } else {
1272
-                $DTM = EE_Registry::instance()->load_class(
1273
-                    'Datetime',
1274
-                    [$datetime_values, $evtobj->get_timezone(), $incoming_date_formats],
1275
-                    false,
1276
-                    false
1277
-                );
1278
-                foreach ($datetime_values as $field => $value) {
1279
-                    $DTM->set($field, $value);
1280
-                }
1281
-            }
1282
-            $DTM->save();
1283
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1284
-            // load DTT helper
1285
-            // before going any further make sure our dates are setup correctly
1286
-            // so that the end date is always equal or greater than the start date.
1287
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1288
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1289
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1290
-                $DTT->save();
1291
-            }
1292
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array
1293
-            //  because it is possible there was a new one created for the autosave.
1294
-            $saved_dtt = $DTT;
1295
-            $success   = ! $success ? $success : $DTT;
1296
-            // if ANY of these updates fail then we want the appropriate global error message.
1297
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1298
-        }
1299
-        // no dtts get deleted so we don't do any of that logic here.
1300
-        // update tickets next
1301
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1302
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1303
-            $incoming_date_formats = ['Y-m-d', 'h:i a'];
1304
-            $update_prices         = false;
1305
-            $ticket_price          = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1306
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1307
-                : 0;
1308
-            // trim inputs to ensure any excess whitespace is removed.
1309
-            $tkt = array_map('trim', $tkt);
1310
-            if (empty($tkt['TKT_start_date'])) {
1311
-                // let's use now in the set timezone.
1312
-                $now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1313
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1314
-            }
1315
-            if (empty($tkt['TKT_end_date'])) {
1316
-                // use the start date of the first datetime
1317
-                $dtt                 = $evtobj->first_datetime();
1318
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1319
-                    $incoming_date_formats[0],
1320
-                    $incoming_date_formats[1]
1321
-                );
1322
-            }
1323
-            $TKT_values = [
1324
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1325
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1326
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1327
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1328
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1329
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1330
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1331
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1332
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1333
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1334
-                'TKT_row'         => $row,
1335
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1336
-                'TKT_price'       => $ticket_price,
1337
-            ];
1338
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
1339
-            // which means in turn that the prices will become new prices as well.
1340
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1341
-                $TKT_values['TKT_ID']         = 0;
1342
-                $TKT_values['TKT_is_default'] = 0;
1343
-                $TKT_values['TKT_price']      = $ticket_price;
1344
-                $update_prices                = true;
1345
-            }
1346
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1347
-            // we actually do our saves a head of doing any add_relations to because its entirely possible
1348
-            // that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1349
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
1350
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1351
-            if (! empty($tkt['TKT_ID'])) {
1352
-                $TKT = EE_Registry::instance()
1353
-                                  ->load_model('Ticket', [$evtobj->get_timezone()])
1354
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1355
-                if ($TKT instanceof EE_Ticket) {
1356
-                    $ticket_sold = $TKT->count_related(
1357
-                        'Registration',
1358
-                        [
1359
-                            [
1360
-                                'STS_ID' => [
1361
-                                    'NOT IN',
1362
-                                    [EEM_Registration::status_id_incomplete],
1363
-                                ],
1364
-                            ],
1365
-                        ]
1366
-                    ) > 0;
1367
-                    // let's just check the total price for the existing ticket and determine if it matches the new
1368
-                    // total price.  if they are different then we create a new ticket (if tickets sold)
1369
-                    // if they aren't different then we go ahead and modify existing ticket.
1370
-                    $create_new_TKT = $ticket_sold
1371
-                                      && ! $TKT->deleted()
1372
-                                      && EEH_Money::compare_floats(
1373
-                                          $ticket_price,
1374
-                                          $TKT->get('TKT_price'),
1375
-                                          '!=='
1376
-                                      );
1377
-                    $TKT->set_date_format($incoming_date_formats[0]);
1378
-                    $TKT->set_time_format($incoming_date_formats[1]);
1379
-                    // set new values
1380
-                    foreach ($TKT_values as $field => $value) {
1381
-                        if ($field === 'TKT_qty') {
1382
-                            $TKT->set_qty($value);
1383
-                        } else {
1384
-                            $TKT->set($field, $value);
1385
-                        }
1386
-                    }
1387
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
1388
-                    //  Otherwise we have to create a new ticket.
1389
-                    if ($create_new_TKT) {
1390
-                        // archive the old ticket first
1391
-                        $TKT->set('TKT_deleted', 1);
1392
-                        $TKT->save();
1393
-                        // make sure this ticket is still recorded in our saved_tkts
1394
-                        // so we don't run it through the regular trash routine.
1395
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1396
-                        // create new ticket that's a copy of the existing except a new id of course
1397
-                        // (and not archived) AND has the new TKT_price associated with it.
1398
-                        $TKT = clone $TKT;
1399
-                        $TKT->set('TKT_ID', 0);
1400
-                        $TKT->set('TKT_deleted', 0);
1401
-                        $TKT->set('TKT_price', $ticket_price);
1402
-                        $TKT->set('TKT_sold', 0);
1403
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1404
-                        $update_prices = true;
1405
-                    }
1406
-                    // make sure price is set if it hasn't been already
1407
-                    $TKT->set('TKT_price', $ticket_price);
1408
-                }
1409
-            } else {
1410
-                // no TKT_id so a new TKT
1411
-                $TKT_values['TKT_price'] = $ticket_price;
1412
-                $TKT                     = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1413
-                if ($TKT instanceof EE_Ticket) {
1414
-                    // need to reset values to properly account for the date formats
1415
-                    $TKT->set_date_format($incoming_date_formats[0]);
1416
-                    $TKT->set_time_format($incoming_date_formats[1]);
1417
-                    $TKT->set_timezone($evtobj->get_timezone());
1418
-                    // set new values
1419
-                    foreach ($TKT_values as $field => $value) {
1420
-                        if ($field === 'TKT_qty') {
1421
-                            $TKT->set_qty($value);
1422
-                        } else {
1423
-                            $TKT->set($field, $value);
1424
-                        }
1425
-                    }
1426
-                    $update_prices = true;
1427
-                }
1428
-            }
1429
-            // cap ticket qty by datetime reg limits
1430
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1431
-            // update ticket.
1432
-            $TKT->save();
1433
-            // before going any further make sure our dates are setup correctly
1434
-            // so that the end date is always equal or greater than the start date.
1435
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1436
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1437
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1438
-                $TKT->save();
1439
-            }
1440
-            // initially let's add the ticket to the dtt
1441
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1442
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1443
-            // add prices to ticket
1444
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1445
-        }
1446
-        // however now we need to handle permanently deleting tickets via the ui.
1447
-        //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1448
-        //  However, it does allow for deleting tickets that have no tickets sold,
1449
-        // in which case we want to get rid of permanently because there is no need to save in db.
1450
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1451
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1452
-        foreach ($tickets_removed as $id) {
1453
-            $id = absint($id);
1454
-            // get the ticket for this id
1455
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1456
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1457
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
1458
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1459
-            foreach ($dtts as $dtt) {
1460
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1461
-            }
1462
-            // need to do the same for prices (except these prices can also be deleted because again,
1463
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1464
-            $tkt_to_remove->delete_related_permanently('Price');
1465
-            // finally let's delete this ticket
1466
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1467
-            $tkt_to_remove->delete_permanently();
1468
-        }
1469
-        return [$saved_dtt, $saved_tickets];
1470
-    }
1471
-
1472
-
1473
-    /**
1474
-     * This attaches a list of given prices to a ticket.
1475
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1476
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1477
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1478
-     *
1479
-     * @access  private
1480
-     * @param array     $prices     Array of prices from the form.
1481
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1482
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1483
-     * @return  void
1484
-     * @throws EE_Error
1485
-     * @throws InvalidArgumentException
1486
-     * @throws InvalidDataTypeException
1487
-     * @throws InvalidInterfaceException
1488
-     * @throws ReflectionException
1489
-     */
1490
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1491
-    {
1492
-        foreach ($prices as $row => $prc) {
1493
-            $PRC_values = [
1494
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1495
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1496
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1497
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1498
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1499
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1500
-                'PRC_order'      => $row,
1501
-            ];
1502
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1503
-                $PRC_values['PRC_ID'] = 0;
1504
-                $PRC                  = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1505
-            } else {
1506
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1507
-                // update this price with new values
1508
-                foreach ($PRC_values as $field => $newprc) {
1509
-                    $PRC->set($field, $newprc);
1510
-                }
1511
-                $PRC->save();
1512
-            }
1513
-            $ticket->_add_relation_to($PRC, 'Price');
1514
-        }
1515
-    }
1516
-
1517
-
1518
-    /**
1519
-     * Add in our autosave ajax handlers
1520
-     *
1521
-     */
1522
-    protected function _ee_autosave_create_new()
1523
-    {
1524
-    }
1525
-
1526
-
1527
-    /**
1528
-     * More autosave handlers.
1529
-     */
1530
-    protected function _ee_autosave_edit()
1531
-    {
1532
-    }
1533
-
1534
-
1535
-    /**
1536
-     *    _generate_publish_box_extra_content
1537
-     *
1538
-     * @throws DomainException
1539
-     * @throws EE_Error
1540
-     * @throws InvalidArgumentException
1541
-     * @throws InvalidDataTypeException
1542
-     * @throws InvalidInterfaceException
1543
-     * @throws ReflectionException
1544
-     */
1545
-    private function _generate_publish_box_extra_content()
1546
-    {
1547
-        // load formatter helper
1548
-        // args for getting related registrations
1549
-        $approved_query_args        = [
1550
-            [
1551
-                'REG_deleted' => 0,
1552
-                'STS_ID'      => EEM_Registration::status_id_approved,
1553
-            ],
1554
-        ];
1555
-        $not_approved_query_args    = [
1556
-            [
1557
-                'REG_deleted' => 0,
1558
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1559
-            ],
1560
-        ];
1561
-        $pending_payment_query_args = [
1562
-            [
1563
-                'REG_deleted' => 0,
1564
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1565
-            ],
1566
-        ];
1567
-        // publish box
1568
-        $publish_box_extra_args = [
1569
-            'view_approved_reg_url'        => add_query_arg(
1570
-                [
1571
-                    'action'      => 'default',
1572
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1573
-                    '_reg_status' => EEM_Registration::status_id_approved,
1574
-                ],
1575
-                REG_ADMIN_URL
1576
-            ),
1577
-            'view_not_approved_reg_url'    => add_query_arg(
1578
-                [
1579
-                    'action'      => 'default',
1580
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1581
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1582
-                ],
1583
-                REG_ADMIN_URL
1584
-            ),
1585
-            'view_pending_payment_reg_url' => add_query_arg(
1586
-                [
1587
-                    'action'      => 'default',
1588
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1589
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1590
-                ],
1591
-                REG_ADMIN_URL
1592
-            ),
1593
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1594
-                'Registration',
1595
-                $approved_query_args
1596
-            ),
1597
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1598
-                'Registration',
1599
-                $not_approved_query_args
1600
-            ),
1601
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1602
-                'Registration',
1603
-                $pending_payment_query_args
1604
-            ),
1605
-            'misc_pub_section_class'       => apply_filters(
1606
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1607
-                'misc-pub-section'
1608
-            ),
1609
-        ];
1610
-        ob_start();
1611
-        do_action(
1612
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1613
-            $this->_cpt_model_obj
1614
-        );
1615
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1616
-        // load template
1617
-        EEH_Template::display_template(
1618
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1619
-            $publish_box_extra_args
1620
-        );
1621
-    }
1622
-
1623
-
1624
-    /**
1625
-     * @return EE_Event
1626
-     */
1627
-    public function get_event_object()
1628
-    {
1629
-        return $this->_cpt_model_obj;
1630
-    }
1631
-
1632
-
1633
-
1634
-
1635
-    /** METABOXES * */
1636
-    /**
1637
-     * _register_event_editor_meta_boxes
1638
-     * add all metaboxes related to the event_editor
1639
-     *
1640
-     * @return void
1641
-     * @throws EE_Error
1642
-     * @throws InvalidArgumentException
1643
-     * @throws InvalidDataTypeException
1644
-     * @throws InvalidInterfaceException
1645
-     * @throws ReflectionException
1646
-     */
1647
-    protected function _register_event_editor_meta_boxes()
1648
-    {
1649
-        $this->verify_cpt_object();
1650
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1651
-        /** @var FeatureFlags $flags */
1652
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1653
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1654
-        if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1655
-            add_meta_box(
1656
-                'espresso_event_editor_event_options',
1657
-                esc_html__('Event Registration Options', 'event_espresso'),
1658
-                [$this, 'registration_options_meta_box'],
1659
-                $this->page_slug,
1660
-                'side'
1661
-            );
1662
-        }
1663
-        if (! $use_advanced_editor) {
1664
-            add_meta_box(
1665
-                'espresso_event_editor_tickets',
1666
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1667
-                [$this, 'ticket_metabox'],
1668
-                $this->page_slug,
1669
-                'normal',
1670
-                'high'
1671
-            );
1672
-        } else {
1673
-            if ($flags->featureAllowed('use_reg_options_meta_box')) {
1674
-                add_action(
1675
-                    'add_meta_boxes_espresso_events',
1676
-                    function () {
1677
-                        global $current_screen;
1678
-                        remove_meta_box('authordiv', $current_screen, 'normal');
1679
-                    },
1680
-                    99
1681
-                );
1682
-            }
1683
-        }
1684
-        // NOTE: if you're looking for other metaboxes in here,
1685
-        // where a metabox has a related management page in the admin
1686
-        // you will find it setup in the related management page's "_Hooks" file.
1687
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1688
-    }
1689
-
1690
-
1691
-    /**
1692
-     * @throws DomainException
1693
-     * @throws EE_Error
1694
-     * @throws InvalidArgumentException
1695
-     * @throws InvalidDataTypeException
1696
-     * @throws InvalidInterfaceException
1697
-     * @throws ReflectionException
1698
-     */
1699
-    public function ticket_metabox()
1700
-    {
1701
-        $existing_datetime_ids = $existing_ticket_ids = [];
1702
-        // defaults for template args
1703
-        $template_args = [
1704
-            'existing_datetime_ids'    => '',
1705
-            'event_datetime_help_link' => '',
1706
-            'ticket_options_help_link' => '',
1707
-            'time'                     => null,
1708
-            'ticket_rows'              => '',
1709
-            'existing_ticket_ids'      => '',
1710
-            'total_ticket_rows'        => 1,
1711
-            'ticket_js_structure'      => '',
1712
-            'trash_icon'               => 'ee-lock-icon',
1713
-            'disabled'                 => '',
1714
-        ];
1715
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1716
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1717
-        /**
1718
-         * 1. Start with retrieving Datetimes
1719
-         * 2. Fore each datetime get related tickets
1720
-         * 3. For each ticket get related prices
1721
-         */
1722
-        /** @var EEM_Datetime $datetime_model */
1723
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1724
-        /** @var EEM_Ticket $datetime_model */
1725
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1726
-        $times        = $datetime_model->get_all_event_dates($event_id);
1727
-        /** @type EE_Datetime $first_datetime */
1728
-        $first_datetime = reset($times);
1729
-        // do we get related tickets?
1730
-        if (
1731
-            $first_datetime instanceof EE_Datetime
1732
-            && $first_datetime->ID() !== 0
1733
-        ) {
1734
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1735
-            $template_args['time']   = $first_datetime;
1736
-            $related_tickets         = $first_datetime->tickets(
1737
-                [
1738
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1739
-                    'default_where_conditions' => 'none',
1740
-                ]
1741
-            );
1742
-            if (! empty($related_tickets)) {
1743
-                $template_args['total_ticket_rows'] = count($related_tickets);
1744
-                $row                                = 0;
1745
-                foreach ($related_tickets as $ticket) {
1746
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1747
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1748
-                    $row++;
1749
-                }
1750
-            } else {
1751
-                $template_args['total_ticket_rows'] = 1;
1752
-                /** @type EE_Ticket $ticket */
1753
-                $ticket                       = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1754
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1755
-            }
1756
-        } else {
1757
-            $template_args['time'] = $times[0];
1758
-            /** @type EE_Ticket[] $tickets */
1759
-            $tickets                      = $ticket_model->get_all_default_tickets();
1760
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1761
-            // NOTE: we're just sending the first default row
1762
-            // (decaf can't manage default tickets so this should be sufficient);
1763
-        }
1764
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1765
-            'event_editor_event_datetimes_help_tab'
1766
-        );
1767
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1768
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1769
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1770
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1771
-            $ticket_model->create_default_object(),
1772
-            true
1773
-        );
1774
-        $template                                  = apply_filters(
1775
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1776
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1777
-        );
1778
-        EEH_Template::display_template($template, $template_args);
1779
-    }
1780
-
1781
-
1782
-    /**
1783
-     * Setup an individual ticket form for the decaf event editor page
1784
-     *
1785
-     * @access private
1786
-     * @param EE_Ticket $ticket   the ticket object
1787
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1788
-     * @param int       $row
1789
-     * @return string generated html for the ticket row.
1790
-     * @throws DomainException
1791
-     * @throws EE_Error
1792
-     * @throws InvalidArgumentException
1793
-     * @throws InvalidDataTypeException
1794
-     * @throws InvalidInterfaceException
1795
-     * @throws ReflectionException
1796
-     */
1797
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1798
-    {
1799
-        $template_args = [
1800
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1801
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1802
-                : '',
1803
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1804
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1805
-            'TKT_name'            => $ticket->get('TKT_name'),
1806
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1807
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1808
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1809
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1810
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1811
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1812
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1813
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1814
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1815
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1816
-                : ' disabled=disabled',
1817
-        ];
1818
-        $price         = $ticket->ID() !== 0
1819
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1820
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1821
-        $price_args    = [
1822
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1823
-            'PRC_amount'            => $price->get('PRC_amount'),
1824
-            'PRT_ID'                => $price->get('PRT_ID'),
1825
-            'PRC_ID'                => $price->get('PRC_ID'),
1826
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1827
-        ];
1828
-        // make sure we have default start and end dates if skeleton
1829
-        // handle rows that should NOT be empty
1830
-        if (empty($template_args['TKT_start_date'])) {
1831
-            // if empty then the start date will be now.
1832
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1833
-        }
1834
-        if (empty($template_args['TKT_end_date'])) {
1835
-            // get the earliest datetime (if present);
1836
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1837
-                ? $this->_cpt_model_obj->get_first_related(
1838
-                    'Datetime',
1839
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1840
-                )
1841
-                : null;
1842
-            if (! empty($earliest_dtt)) {
1843
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1844
-            } else {
1845
-                $template_args['TKT_end_date'] = date(
1846
-                    'Y-m-d h:i a',
1847
-                    mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1848
-                );
1849
-            }
1850
-        }
1851
-        $template_args = array_merge($template_args, $price_args);
1852
-        $template      = apply_filters(
1853
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1854
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1855
-            $ticket
1856
-        );
1857
-        return EEH_Template::display_template($template, $template_args, true);
1858
-    }
1859
-
1860
-
1861
-    /**
1862
-     * @throws DomainException
1863
-     * @throws EE_Error
1864
-     */
1865
-    public function registration_options_meta_box()
1866
-    {
1867
-        $yes_no_values             = [
1868
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1869
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1870
-        ];
1871
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1872
-            [
1873
-                EEM_Registration::status_id_cancelled,
1874
-                EEM_Registration::status_id_declined,
1875
-                EEM_Registration::status_id_incomplete,
1876
-            ],
1877
-            true
1878
-        );
1879
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1880
-        $template_args['_event']                          = $this->_cpt_model_obj;
1881
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1882
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1883
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1884
-            'default_reg_status',
1885
-            $default_reg_status_values,
1886
-            $this->_cpt_model_obj->default_registration_status()
1887
-        );
1888
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1889
-            'display_desc',
1890
-            $yes_no_values,
1891
-            $this->_cpt_model_obj->display_description()
1892
-        );
1893
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1894
-            'display_ticket_selector',
1895
-            $yes_no_values,
1896
-            $this->_cpt_model_obj->display_ticket_selector(),
1897
-            '',
1898
-            '',
1899
-            false
1900
-        );
1901
-        $template_args['additional_registration_options'] = apply_filters(
1902
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1903
-            '',
1904
-            $template_args,
1905
-            $yes_no_values,
1906
-            $default_reg_status_values
1907
-        );
1908
-        EEH_Template::display_template(
1909
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1910
-            $template_args
1911
-        );
1912
-    }
1913
-
1914
-
1915
-    /**
1916
-     * _get_events()
1917
-     * This method simply returns all the events (for the given _view and paging)
1918
-     *
1919
-     * @access public
1920
-     * @param int  $per_page     count of items per page (20 default);
1921
-     * @param int  $current_page what is the current page being viewed.
1922
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1923
-     *                           If FALSE then we return an array of event objects
1924
-     *                           that match the given _view and paging parameters.
1925
-     * @return array|int an array of event objects.
1926
-     * @throws EE_Error
1927
-     * @throws InvalidArgumentException
1928
-     * @throws InvalidDataTypeException
1929
-     * @throws InvalidInterfaceException
1930
-     * @throws ReflectionException
1931
-     * @throws Exception
1932
-     * @throws Exception
1933
-     * @throws Exception
1934
-     */
1935
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1936
-    {
1937
-        $EEME    = $this->_event_model();
1938
-        $offset  = ($current_page - 1) * $per_page;
1939
-        $limit   = $count ? null : $offset . ',' . $per_page;
1940
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1941
-        $order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1942
-        $month_r = '';
1943
-        $year_r  = '';
1944
-        if (isset($this->_req_data['month_range'])) {
1945
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1946
-            // simulate the FIRST day of the month, that fixes issues for months like February
1947
-            // where PHP doesn't know what to assume for date.
1948
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1949
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1950
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1951
-        }
1952
-        $where  = [];
1953
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1954
-        // determine what post_status our condition will have for the query.
1955
-        switch ($status) {
1956
-            case 'month':
1957
-            case 'today':
1958
-            case null:
1959
-            case 'all':
1960
-                break;
1961
-            case 'draft':
1962
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1963
-                break;
1964
-            default:
1965
-                $where['status'] = $status;
1966
-        }
1967
-        // categories?
1968
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1969
-            ? $this->_req_data['EVT_CAT'] : null;
1970
-        if (! empty($category)) {
1971
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1972
-            $where['Term_Taxonomy.term_id']  = $category;
1973
-        }
1974
-        // date where conditions
1975
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1976
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1977
-            $DateTime = new DateTime(
1978
-                $year_r . '-' . $month_r . '-01 00:00:00',
1979
-                new DateTimeZone('UTC')
1980
-            );
1981
-            $start    = $DateTime->getTimestamp();
1982
-            // set the datetime to be the end of the month
1983
-            $DateTime->setDate(
1984
-                $year_r,
1985
-                $month_r,
1986
-                $DateTime->format('t')
1987
-            )->setTime(23, 59, 59);
1988
-            $end                             = $DateTime->getTimestamp();
1989
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1990
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1991
-            $DateTime                        =
1992
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1993
-            $start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1994
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1995
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1996
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1997
-            $now                             = date('Y-m-01');
1998
-            $DateTime                        =
1999
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
2000
-            $start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
2001
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
2002
-                                                        ->setTime(23, 59, 59)
2003
-                                                        ->format(implode(' ', $start_formats));
2004
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2005
-        }
2006
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2007
-            $where['EVT_wp_user'] = get_current_user_id();
2008
-        } elseif (
2009
-            ! isset($where['status'])
2010
-            && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
2011
-        ) {
2012
-            $where['OR'] = [
2013
-                'status*restrict_private' => ['!=', 'private'],
2014
-                'AND'                     => [
2015
-                    'status*inclusive' => ['=', 'private'],
2016
-                    'EVT_wp_user'      => get_current_user_id(),
2017
-                ],
2018
-            ];
2019
-        }
2020
-
2021
-        if (
2022
-            isset($this->_req_data['EVT_wp_user'])
2023
-            && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
2024
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2025
-        ) {
2026
-            $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
2027
-        }
2028
-        // search query handling
2029
-        if (isset($this->_req_data['s'])) {
2030
-            $search_string = '%' . $this->_req_data['s'] . '%';
2031
-            $where['OR']   = [
2032
-                'EVT_name'       => ['LIKE', $search_string],
2033
-                'EVT_desc'       => ['LIKE', $search_string],
2034
-                'EVT_short_desc' => ['LIKE', $search_string],
2035
-            ];
2036
-        }
2037
-        // filter events by venue.
2038
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2039
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2040
-        }
2041
-        $where        = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2042
-        $query_params = apply_filters(
2043
-            'FHEE__Events_Admin_Page__get_events__query_params',
2044
-            [
2045
-                $where,
2046
-                'limit'    => $limit,
2047
-                'order_by' => $orderby,
2048
-                'order'    => $order,
2049
-                'group_by' => 'EVT_ID',
2050
-            ],
2051
-            $this->_req_data
2052
-        );
2053
-
2054
-        // let's first check if we have special requests coming in.
2055
-        if (isset($this->_req_data['active_status'])) {
2056
-            switch ($this->_req_data['active_status']) {
2057
-                case 'upcoming':
2058
-                    return $EEME->get_upcoming_events($query_params, $count);
2059
-                case 'expired':
2060
-                    return $EEME->get_expired_events($query_params, $count);
2061
-                case 'active':
2062
-                    return $EEME->get_active_events($query_params, $count);
2063
-                case 'inactive':
2064
-                    return $EEME->get_inactive_events($query_params, $count);
2065
-            }
2066
-        }
2067
-
2068
-        return $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params);
2069
-    }
2070
-
2071
-
2072
-    /**
2073
-     * handling for WordPress CPT actions (trash, restore, delete)
2074
-     *
2075
-     * @param string $post_id
2076
-     * @throws EE_Error
2077
-     * @throws InvalidArgumentException
2078
-     * @throws InvalidDataTypeException
2079
-     * @throws InvalidInterfaceException
2080
-     * @throws ReflectionException
2081
-     */
2082
-    public function trash_cpt_item($post_id)
2083
-    {
2084
-        $this->_req_data['EVT_ID'] = $post_id;
2085
-        $this->_trash_or_restore_event('trash', false);
2086
-    }
2087
-
2088
-
2089
-    /**
2090
-     * @param string $post_id
2091
-     * @throws EE_Error
2092
-     * @throws InvalidArgumentException
2093
-     * @throws InvalidDataTypeException
2094
-     * @throws InvalidInterfaceException
2095
-     * @throws ReflectionException
2096
-     */
2097
-    public function restore_cpt_item($post_id)
2098
-    {
2099
-        $this->_req_data['EVT_ID'] = $post_id;
2100
-        $this->_trash_or_restore_event('draft', false);
2101
-    }
2102
-
2103
-
2104
-    /**
2105
-     * @param string $post_id
2106
-     * @throws EE_Error
2107
-     * @throws InvalidArgumentException
2108
-     * @throws InvalidDataTypeException
2109
-     * @throws InvalidInterfaceException
2110
-     * @throws ReflectionException
2111
-     */
2112
-    public function delete_cpt_item($post_id)
2113
-    {
2114
-        throw new EE_Error(
2115
-            esc_html__(
2116
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2117
-                'event_espresso'
2118
-            )
2119
-        );
2120
-        $this->_req_data['EVT_ID'] = $post_id;
2121
-        $this->_delete_event();
2122
-    }
2123
-
2124
-
2125
-    /**
2126
-     * _trash_or_restore_event
2127
-     *
2128
-     * @access protected
2129
-     * @param string $event_status
2130
-     * @param bool   $redirect_after
2131
-     * @throws EE_Error
2132
-     * @throws InvalidArgumentException
2133
-     * @throws InvalidDataTypeException
2134
-     * @throws InvalidInterfaceException
2135
-     * @throws ReflectionException
2136
-     */
2137
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2138
-    {
2139
-        // determine the event id and set to array.
2140
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2141
-        // loop thru events
2142
-        if ($EVT_ID) {
2143
-            // clean status
2144
-            $event_status = sanitize_key($event_status);
2145
-            // grab status
2146
-            if (! empty($event_status)) {
2147
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2148
-            } else {
2149
-                $success = false;
2150
-                $msg     = esc_html__(
2151
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2152
-                    'event_espresso'
2153
-                );
2154
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2155
-            }
2156
-        } else {
2157
-            $success = false;
2158
-            $msg     = esc_html__(
2159
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2160
-                'event_espresso'
2161
-            );
2162
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2163
-        }
2164
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2165
-        if ($redirect_after) {
2166
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2167
-        }
2168
-    }
2169
-
2170
-
2171
-    /**
2172
-     * _trash_or_restore_events
2173
-     *
2174
-     * @access protected
2175
-     * @param string $event_status
2176
-     * @return void
2177
-     * @throws EE_Error
2178
-     * @throws InvalidArgumentException
2179
-     * @throws InvalidDataTypeException
2180
-     * @throws InvalidInterfaceException
2181
-     * @throws ReflectionException
2182
-     */
2183
-    protected function _trash_or_restore_events($event_status = 'trash')
2184
-    {
2185
-        // clean status
2186
-        $event_status = sanitize_key($event_status);
2187
-        // grab status
2188
-        if (! empty($event_status)) {
2189
-            $success = true;
2190
-            // determine the event id and set to array.
2191
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2192
-            // loop thru events
2193
-            foreach ($EVT_IDs as $EVT_ID) {
2194
-                if ($EVT_ID = absint($EVT_ID)) {
2195
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2196
-                    $success = $results !== false ? $success : false;
2197
-                } else {
2198
-                    $msg = sprintf(
2199
-                        esc_html__(
2200
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2201
-                            'event_espresso'
2202
-                        ),
2203
-                        $EVT_ID
2204
-                    );
2205
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2206
-                    $success = false;
2207
-                }
2208
-            }
2209
-        } else {
2210
-            $success = false;
2211
-            $msg     = esc_html__(
2212
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2213
-                'event_espresso'
2214
-            );
2215
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2216
-        }
2217
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2218
-        $success = $success ? 2 : false;
2219
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2220
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2221
-    }
2222
-
2223
-
2224
-    /**
2225
-     * _trash_or_restore_events
2226
-     *
2227
-     * @access  private
2228
-     * @param int    $EVT_ID
2229
-     * @param string $event_status
2230
-     * @return bool
2231
-     * @throws EE_Error
2232
-     * @throws InvalidArgumentException
2233
-     * @throws InvalidDataTypeException
2234
-     * @throws InvalidInterfaceException
2235
-     * @throws ReflectionException
2236
-     */
2237
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2238
-    {
2239
-        // grab event id
2240
-        if (! $EVT_ID) {
2241
-            $msg = esc_html__(
2242
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2243
-                'event_espresso'
2244
-            );
2245
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2246
-            return false;
2247
-        }
2248
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2249
-        // clean status
2250
-        $event_status = sanitize_key($event_status);
2251
-        // grab status
2252
-        if (empty($event_status)) {
2253
-            $msg = esc_html__(
2254
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2255
-                'event_espresso'
2256
-            );
2257
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2258
-            return false;
2259
-        }
2260
-        // was event trashed or restored ?
2261
-        switch ($event_status) {
2262
-            case 'draft':
2263
-                $action = 'restored from the trash';
2264
-                $hook   = 'AHEE_event_restored_from_trash';
2265
-                break;
2266
-            case 'trash':
2267
-                $action = 'moved to the trash';
2268
-                $hook   = 'AHEE_event_moved_to_trash';
2269
-                break;
2270
-            default:
2271
-                $action = 'updated';
2272
-                $hook   = false;
2273
-        }
2274
-        // use class to change status
2275
-        $this->_cpt_model_obj->set_status($event_status);
2276
-        $success = $this->_cpt_model_obj->save();
2277
-        if ($success === false) {
2278
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2279
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2280
-            return false;
2281
-        }
2282
-        if ($hook) {
2283
-            do_action($hook);
2284
-        }
2285
-        return true;
2286
-    }
2287
-
2288
-
2289
-    /**
2290
-     * @throws InvalidArgumentException
2291
-     * @throws InvalidDataTypeException
2292
-     * @throws InvalidInterfaceException
2293
-     */
2294
-    protected function _delete_event()
2295
-    {
2296
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []);
2297
-    }
2298
-
2299
-
2300
-    /**
2301
-     * Gets the tree traversal batch persister.
2302
-     *
2303
-     * @return NodeGroupDao
2304
-     * @throws InvalidArgumentException
2305
-     * @throws InvalidDataTypeException
2306
-     * @throws InvalidInterfaceException
2307
-     * @since 4.10.12.p
2308
-     */
2309
-    protected function getModelObjNodeGroupPersister()
2310
-    {
2311
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2312
-            $this->model_obj_node_group_persister =
2313
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2314
-        }
2315
-        return $this->model_obj_node_group_persister;
2316
-    }
2317
-
2318
-
2319
-    /**
2320
-     * @return void
2321
-     * @throws InvalidArgumentException
2322
-     * @throws InvalidDataTypeException
2323
-     * @throws InvalidInterfaceException
2324
-     */
2325
-    protected function _delete_events()
2326
-    {
2327
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []);
2328
-    }
2329
-
2330
-
2331
-    protected function generateDeletionPreview($event_ids)
2332
-    {
2333
-        $event_ids = (array) $event_ids;
2334
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2335
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2336
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2337
-            [
2338
-                'action'            => 'preview_deletion',
2339
-                'deletion_job_code' => $deletion_job_code,
2340
-            ],
2341
-            $this->_admin_base_url
2342
-        );
2343
-        $event_ids         = array_map(
2344
-            'intval',
2345
-            $event_ids
2346
-        );
2347
-
2348
-        EEH_URL::safeRedirectAndExit(
2349
-            EE_Admin_Page::add_query_args_and_nonce(
2350
-                [
2351
-                    'page'              => 'espresso_batch',
2352
-                    'batch'             => EED_Batch::batch_job,
2353
-                    'EVT_IDs'           => $event_ids,
2354
-                    'deletion_job_code' => $deletion_job_code,
2355
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2356
-                    'return_url'        => urlencode($return_url),
2357
-                ],
2358
-                admin_url()
2359
-            )
2360
-        );
2361
-    }
2362
-
2363
-
2364
-    /**
2365
-     * Checks for a POST submission
2366
-     *
2367
-     * @since 4.10.12.p
2368
-     */
2369
-    protected function confirmDeletion()
2370
-    {
2371
-        $deletion_redirect_logic =
2372
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2373
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2374
-    }
2375
-
2376
-
2377
-    /**
2378
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2379
-     *
2380
-     * @throws EE_Error
2381
-     * @since 4.10.12.p
2382
-     */
2383
-    protected function previewDeletion()
2384
-    {
2385
-        $preview_deletion_logic =
2386
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2387
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2388
-        $this->display_admin_page_with_no_sidebar();
2389
-    }
2390
-
2391
-
2392
-    /**
2393
-     * get total number of events
2394
-     *
2395
-     * @access public
2396
-     * @return int
2397
-     * @throws EE_Error
2398
-     * @throws InvalidArgumentException
2399
-     * @throws InvalidDataTypeException
2400
-     * @throws InvalidInterfaceException
2401
-     */
2402
-    public function total_events()
2403
-    {
2404
-        return EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2405
-    }
2406
-
2407
-
2408
-    /**
2409
-     * get total number of draft events
2410
-     *
2411
-     * @access public
2412
-     * @return int
2413
-     * @throws EE_Error
2414
-     * @throws InvalidArgumentException
2415
-     * @throws InvalidDataTypeException
2416
-     * @throws InvalidInterfaceException
2417
-     */
2418
-    public function total_events_draft()
2419
-    {
2420
-        $where = [
2421
-            'status' => ['IN', ['draft', 'auto-draft']],
2422
-        ];
2423
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2424
-    }
2425
-
2426
-
2427
-    /**
2428
-     * get total number of trashed events
2429
-     *
2430
-     * @access public
2431
-     * @return int
2432
-     * @throws EE_Error
2433
-     * @throws InvalidArgumentException
2434
-     * @throws InvalidDataTypeException
2435
-     * @throws InvalidInterfaceException
2436
-     */
2437
-    public function total_trashed_events()
2438
-    {
2439
-        $where = [
2440
-            'status' => 'trash',
2441
-        ];
2442
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2443
-    }
2444
-
2445
-
2446
-    /**
2447
-     *    _default_event_settings
2448
-     *    This generates the Default Settings Tab
2449
-     *
2450
-     * @return void
2451
-     * @throws DomainException
2452
-     * @throws EE_Error
2453
-     * @throws InvalidArgumentException
2454
-     * @throws InvalidDataTypeException
2455
-     * @throws InvalidInterfaceException
2456
-     */
2457
-    protected function _default_event_settings()
2458
-    {
2459
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2460
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2461
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2462
-        $this->display_admin_page_with_sidebar();
2463
-    }
2464
-
2465
-
2466
-    /**
2467
-     * Return the form for event settings.
2468
-     *
2469
-     * @return EE_Form_Section_Proper
2470
-     * @throws EE_Error
2471
-     */
2472
-    protected function _default_event_settings_form()
2473
-    {
2474
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2475
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2476
-        // exclude
2477
-            [
2478
-                EEM_Registration::status_id_cancelled,
2479
-                EEM_Registration::status_id_declined,
2480
-                EEM_Registration::status_id_incomplete,
2481
-                EEM_Registration::status_id_wait_list,
2482
-            ],
2483
-            true
2484
-        );
2485
-        return new EE_Form_Section_Proper(
2486
-            [
2487
-                'name'            => 'update_default_event_settings',
2488
-                'html_id'         => 'update_default_event_settings',
2489
-                'html_class'      => 'form-table',
2490
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2491
-                'subsections'     => apply_filters(
2492
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2493
-                    [
2494
-                        'default_reg_status'  => new EE_Select_Input(
2495
-                            $registration_stati_for_selection,
2496
-                            [
2497
-                                'default'         => isset($registration_config->default_STS_ID)
2498
-                                                     && array_key_exists(
2499
-                                                         $registration_config->default_STS_ID,
2500
-                                                         $registration_stati_for_selection
2501
-                                                     )
2502
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2503
-                                    : EEM_Registration::status_id_pending_payment,
2504
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2505
-                                                     . EEH_Template::get_help_tab_link(
2506
-                                                         'default_settings_status_help_tab'
2507
-                                                     ),
2508
-                                'html_help_text'  => esc_html__(
2509
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2510
-                                    'event_espresso'
2511
-                                ),
2512
-                            ]
2513
-                        ),
2514
-                        'default_max_tickets' => new EE_Integer_Input(
2515
-                            [
2516
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2517
-                                    ? $registration_config->default_maximum_number_of_tickets
2518
-                                    : EEM_Event::get_default_additional_limit(),
2519
-                                'html_label_text' => esc_html__(
2520
-                                    'Default Maximum Tickets Allowed Per Order:',
2521
-                                    'event_espresso'
2522
-                                )
2523
-                                . EEH_Template::get_help_tab_link(
2524
-                                    'default_maximum_tickets_help_tab"'
2525
-                                ),
2526
-                                'html_help_text'  => esc_html__(
2527
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2528
-                                    'event_espresso'
2529
-                                ),
2530
-                            ]
2531
-                        ),
2532
-                    ]
2533
-                ),
2534
-            ]
2535
-        );
2536
-    }
2537
-
2538
-
2539
-    /**
2540
-     * @return void
2541
-     * @throws EE_Error
2542
-     * @throws InvalidArgumentException
2543
-     * @throws InvalidDataTypeException
2544
-     * @throws InvalidInterfaceException
2545
-     */
2546
-    protected function _update_default_event_settings()
2547
-    {
2548
-        $form = $this->_default_event_settings_form();
2549
-        if ($form->was_submitted()) {
2550
-            $form->receive_form_submission();
2551
-            if ($form->is_valid()) {
2552
-                $registration_config = EE_Registry::instance()->CFG->registration;
2553
-                $valid_data          = $form->valid_data();
2554
-                if (isset($valid_data['default_reg_status'])) {
2555
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2556
-                }
2557
-                if (isset($valid_data['default_max_tickets'])) {
2558
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2559
-                }
2560
-                do_action(
2561
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2562
-                    $valid_data,
2563
-                    EE_Registry::instance()->CFG,
2564
-                    $this
2565
-                );
2566
-                // update because data was valid!
2567
-                EE_Registry::instance()->CFG->update_espresso_config();
2568
-                EE_Error::overwrite_success();
2569
-                EE_Error::add_success(
2570
-                    __('Default Event Settings were updated', 'event_espresso')
2571
-                );
2572
-            }
2573
-        }
2574
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2575
-    }
2576
-
2577
-
2578
-    /*************        Templates        *************
2579
-     *
2580
-     * @throws EE_Error
2581
-     */
2582
-    protected function _template_settings()
2583
-    {
2584
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2585
-        $this->_template_args['preview_img']  = '<img src="'
2586
-                                                . EVENTS_ASSETS_URL
2587
-                                                . '/images/'
2588
-                                                . 'caffeinated_template_features.jpg" alt="'
2589
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2590
-                                                . '" />';
2591
-        $this->_template_args['preview_text'] = '<strong>'
2592
-                                                . esc_html__(
2593
-                                                    'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2594
-                                                    'event_espresso'
2595
-                                                ) . '</strong>';
2596
-        $this->display_admin_caf_preview_page('template_settings_tab');
2597
-    }
2598
-
2599
-
2600
-    /** Event Category Stuff **/
2601
-    /**
2602
-     * set the _category property with the category object for the loaded page.
2603
-     *
2604
-     * @access private
2605
-     * @return void
2606
-     */
2607
-    private function _set_category_object()
2608
-    {
2609
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2610
-            return;
2611
-        } //already have the category object so get out.
2612
-        // set default category object
2613
-        $this->_set_empty_category_object();
2614
-        // only set if we've got an id
2615
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2616
-            return;
2617
-        }
2618
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2619
-        $term        = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2620
-        if (! empty($term)) {
2621
-            $this->_category->category_name       = $term->name;
2622
-            $this->_category->category_identifier = $term->slug;
2623
-            $this->_category->category_desc       = $term->description;
2624
-            $this->_category->id                  = $term->term_id;
2625
-            $this->_category->parent              = $term->parent;
2626
-        }
2627
-    }
2628
-
2629
-
2630
-    /**
2631
-     * Clears out category properties.
2632
-     */
2633
-    private function _set_empty_category_object()
2634
-    {
2635
-        $this->_category                = new stdClass();
2636
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2637
-        $this->_category->id            = $this->_category->parent = 0;
2638
-    }
2639
-
2640
-
2641
-    /**
2642
-     * @throws DomainException
2643
-     * @throws EE_Error
2644
-     * @throws InvalidArgumentException
2645
-     * @throws InvalidDataTypeException
2646
-     * @throws InvalidInterfaceException
2647
-     */
2648
-    protected function _category_list_table()
2649
-    {
2650
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2651
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2652
-        $this->_admin_page_title .= ' ';
2653
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2654
-            'add_category',
2655
-            'add_category',
2656
-            [],
2657
-            'add-new-h2'
2658
-        );
2659
-        $this->display_admin_list_table_page_with_sidebar();
2660
-    }
2661
-
2662
-
2663
-    /**
2664
-     * Output category details view.
2665
-     *
2666
-     * @param string $view
2667
-     * @throws DomainException
2668
-     * @throws EE_Error
2669
-     * @throws InvalidArgumentException
2670
-     * @throws InvalidDataTypeException
2671
-     * @throws InvalidInterfaceException
2672
-     */
2673
-    protected function _category_details($view)
2674
-    {
2675
-        // load formatter helper
2676
-        // load field generator helper
2677
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2678
-        $this->_set_add_edit_form_tags($route);
2679
-        $this->_set_category_object();
2680
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2681
-        $delete_action = 'delete_category';
2682
-        // custom redirect
2683
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2684
-            ['action' => 'category_list'],
2685
-            $this->_admin_base_url
2686
-        );
2687
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2688
-        // take care of contents
2689
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2690
-        $this->display_admin_page_with_sidebar();
2691
-    }
2692
-
2693
-
2694
-    /**
2695
-     * Output category details content.
2696
-     *
2697
-     * @throws DomainException
2698
-     */
2699
-    protected function _category_details_content()
2700
-    {
2701
-        $editor_args['category_desc'] = [
2702
-            'type'          => 'wp_editor',
2703
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2704
-            'class'         => 'my_editor_custom',
2705
-            'wpeditor_args' => ['media_buttons' => false],
2706
-        ];
2707
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2708
-        $all_terms                    = get_terms(
2709
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2710
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2711
-        );
2712
-        // setup category select for term parents.
2713
-        $category_select_values[] = [
2714
-            'text' => esc_html__('No Parent', 'event_espresso'),
2715
-            'id'   => 0,
2716
-        ];
2717
-        foreach ($all_terms as $term) {
2718
-            $category_select_values[] = [
2719
-                'text' => $term->name,
2720
-                'id'   => $term->term_id,
2721
-            ];
2722
-        }
2723
-        $category_select = EEH_Form_Fields::select_input(
2724
-            'category_parent',
2725
-            $category_select_values,
2726
-            $this->_category->parent
2727
-        );
2728
-        $template_args   = [
2729
-            'category'                 => $this->_category,
2730
-            'category_select'          => $category_select,
2731
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2732
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2733
-            'disable'                  => '',
2734
-            'disabled_message'         => false,
2735
-        ];
2736
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2737
-        return EEH_Template::display_template($template, $template_args, true);
2738
-    }
2739
-
2740
-
2741
-    /**
2742
-     * Handles deleting categories.
2743
-     *
2744
-     * @throws EE_Error
2745
-     */
2746
-    protected function _delete_categories()
2747
-    {
2748
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2749
-            : (array) $this->_req_data['category_id'];
2750
-        foreach ($cat_ids as $cat_id) {
2751
-            $this->_delete_category($cat_id);
2752
-        }
2753
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2754
-        $query_args = [
2755
-            'action' => 'category_list',
2756
-        ];
2757
-        $this->_redirect_after_action(0, '', '', $query_args);
2758
-    }
2759
-
2760
-
2761
-    /**
2762
-     * Handles deleting specific category.
2763
-     *
2764
-     * @param int $cat_id
2765
-     */
2766
-    protected function _delete_category($cat_id)
2767
-    {
2768
-        $cat_id = absint($cat_id);
2769
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2770
-    }
2771
-
2772
-
2773
-    /**
2774
-     * Handles triggering the update or insertion of a new category.
2775
-     *
2776
-     * @param bool $new_category true means we're triggering the insert of a new category.
2777
-     * @throws EE_Error
2778
-     * @throws InvalidArgumentException
2779
-     * @throws InvalidDataTypeException
2780
-     * @throws InvalidInterfaceException
2781
-     */
2782
-    protected function _insert_or_update_category($new_category)
2783
-    {
2784
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2785
-        $success = 0; // we already have a success message so lets not send another.
2786
-        if ($cat_id) {
2787
-            $query_args = [
2788
-                'action'     => 'edit_category',
2789
-                'EVT_CAT_ID' => $cat_id,
2790
-            ];
2791
-        } else {
2792
-            $query_args = ['action' => 'add_category'];
2793
-        }
2794
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2795
-    }
2796
-
2797
-
2798
-    /**
2799
-     * Inserts or updates category
2800
-     *
2801
-     * @param bool $update (true indicates we're updating a category).
2802
-     * @return bool|mixed|string
2803
-     */
2804
-    private function _insert_category($update = false)
2805
-    {
2806
-        $cat_id          = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2807
-        $category_name   = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2808
-        $category_desc   = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2809
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2810
-        if (empty($category_name)) {
2811
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2812
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2813
-            return false;
2814
-        }
2815
-        $term_args = [
2816
-            'name'        => $category_name,
2817
-            'description' => $category_desc,
2818
-            'parent'      => $category_parent,
2819
-        ];
2820
-        // was the category_identifier input disabled?
2821
-        if (isset($this->_req_data['category_identifier'])) {
2822
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2823
-        }
2824
-        $insert_ids = $update
2825
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2826
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2827
-        if (! is_array($insert_ids)) {
2828
-            $msg = esc_html__(
2829
-                'An error occurred and the category has not been saved to the database.',
2830
-                'event_espresso'
2831
-            );
2832
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2833
-        } else {
2834
-            $cat_id = $insert_ids['term_id'];
2835
-            $msg    = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2836
-            EE_Error::add_success($msg);
2837
-        }
2838
-        return $cat_id;
2839
-    }
2840
-
2841
-
2842
-    /**
2843
-     * Gets categories or count of categories matching the arguments in the request.
2844
-     *
2845
-     * @param int  $per_page
2846
-     * @param int  $current_page
2847
-     * @param bool $count
2848
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2849
-     * @throws EE_Error
2850
-     * @throws InvalidArgumentException
2851
-     * @throws InvalidDataTypeException
2852
-     * @throws InvalidInterfaceException
2853
-     */
2854
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2855
-    {
2856
-        // testing term stuff
2857
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2858
-        $order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2859
-        $limit   = ($current_page - 1) * $per_page;
2860
-        $where   = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2861
-        if (isset($this->_req_data['s'])) {
2862
-            $sstr        = '%' . $this->_req_data['s'] . '%';
2863
-            $where['OR'] = [
2864
-                'Term.name'   => ['LIKE', $sstr],
2865
-                'description' => ['LIKE', $sstr],
2866
-            ];
2867
-        }
2868
-        $query_params = [
2869
-            $where,
2870
-            'order_by'   => [$orderby => $order],
2871
-            'limit'      => $limit . ',' . $per_page,
2872
-            'force_join' => ['Term'],
2873
-        ];
2874
-        return $count
2875
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2876
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2877
-    }
2878
-
2879
-    /* end category stuff */
2880
-
2881
-
2882
-    /**************/
2883
-
2884
-
2885
-    /**
2886
-     * Callback for the `ee_save_timezone_setting` ajax action.
20
+	/**
21
+	 * This will hold the event object for event_details screen.
22
+	 *
23
+	 * @access protected
24
+	 * @var EE_Event $_event
25
+	 */
26
+	protected $_event;
27
+
28
+
29
+	/**
30
+	 * This will hold the category object for category_details screen.
31
+	 *
32
+	 * @var stdClass $_category
33
+	 */
34
+	protected $_category;
35
+
36
+
37
+	/**
38
+	 * This will hold the event model instance
39
+	 *
40
+	 * @var EEM_Event $_event_model
41
+	 */
42
+	protected $_event_model;
43
+
44
+
45
+	/**
46
+	 * @var EE_Event
47
+	 */
48
+	protected $_cpt_model_obj = false;
49
+
50
+
51
+	/**
52
+	 * @var NodeGroupDao
53
+	 */
54
+	protected $model_obj_node_group_persister;
55
+
56
+
57
+	/**
58
+	 * Initialize page props for this admin page group.
59
+	 */
60
+	protected function _init_page_props()
61
+	{
62
+		$this->page_slug        = EVENTS_PG_SLUG;
63
+		$this->page_label       = EVENTS_LABEL;
64
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
65
+		$this->_admin_base_path = EVENTS_ADMIN;
66
+		$this->_cpt_model_names = [
67
+			'create_new' => 'EEM_Event',
68
+			'edit'       => 'EEM_Event',
69
+		];
70
+		$this->_cpt_edit_routes = [
71
+			'espresso_events' => 'edit',
72
+		];
73
+		add_action(
74
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
75
+			[$this, 'verify_event_edit'],
76
+			10,
77
+			2
78
+		);
79
+	}
80
+
81
+
82
+	/**
83
+	 * Sets the ajax hooks used for this admin page group.
84
+	 */
85
+	protected function _ajax_hooks()
86
+	{
87
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
88
+	}
89
+
90
+
91
+	/**
92
+	 * Sets the page properties for this admin page group.
93
+	 */
94
+	protected function _define_page_props()
95
+	{
96
+		$this->_admin_page_title = EVENTS_LABEL;
97
+		$this->_labels           = [
98
+			'buttons'      => [
99
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
100
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
101
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
102
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
103
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
104
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
105
+			],
106
+			'editor_title' => [
107
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
108
+			],
109
+			'publishbox'   => [
110
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
111
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
112
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
113
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
114
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
115
+			],
116
+		];
117
+	}
118
+
119
+
120
+	/**
121
+	 * Sets the page routes property for this admin page group.
122
+	 */
123
+	protected function _set_page_routes()
124
+	{
125
+		// load formatter helper
126
+		// load field generator helper
127
+		// is there a evt_id in the request?
128
+		$evt_id             = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
129
+			? $this->_req_data['EVT_ID']
130
+			: 0;
131
+		$evt_id             = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
132
+		$this->_page_routes = [
133
+			'default'                       => [
134
+				'func'       => '_events_overview_list_table',
135
+				'capability' => 'ee_read_events',
136
+			],
137
+			'create_new'                    => [
138
+				'func'       => '_create_new_cpt_item',
139
+				'capability' => 'ee_edit_events',
140
+			],
141
+			'edit'                          => [
142
+				'func'       => '_edit_cpt_item',
143
+				'capability' => 'ee_edit_event',
144
+				'obj_id'     => $evt_id,
145
+			],
146
+			'copy_event'                    => [
147
+				'func'       => '_copy_events',
148
+				'capability' => 'ee_edit_event',
149
+				'obj_id'     => $evt_id,
150
+				'noheader'   => true,
151
+			],
152
+			'trash_event'                   => [
153
+				'func'       => '_trash_or_restore_event',
154
+				'args'       => ['event_status' => 'trash'],
155
+				'capability' => 'ee_delete_event',
156
+				'obj_id'     => $evt_id,
157
+				'noheader'   => true,
158
+			],
159
+			'trash_events'                  => [
160
+				'func'       => '_trash_or_restore_events',
161
+				'args'       => ['event_status' => 'trash'],
162
+				'capability' => 'ee_delete_events',
163
+				'noheader'   => true,
164
+			],
165
+			'restore_event'                 => [
166
+				'func'       => '_trash_or_restore_event',
167
+				'args'       => ['event_status' => 'draft'],
168
+				'capability' => 'ee_delete_event',
169
+				'obj_id'     => $evt_id,
170
+				'noheader'   => true,
171
+			],
172
+			'restore_events'                => [
173
+				'func'       => '_trash_or_restore_events',
174
+				'args'       => ['event_status' => 'draft'],
175
+				'capability' => 'ee_delete_events',
176
+				'noheader'   => true,
177
+			],
178
+			'delete_event'                  => [
179
+				'func'       => '_delete_event',
180
+				'capability' => 'ee_delete_event',
181
+				'obj_id'     => $evt_id,
182
+				'noheader'   => true,
183
+			],
184
+			'delete_events'                 => [
185
+				'func'       => '_delete_events',
186
+				'capability' => 'ee_delete_events',
187
+				'noheader'   => true,
188
+			],
189
+			'view_report'                   => [
190
+				'func'       => '_view_report',
191
+				'capability' => 'ee_edit_events',
192
+			],
193
+			'default_event_settings'        => [
194
+				'func'       => '_default_event_settings',
195
+				'capability' => 'manage_options',
196
+			],
197
+			'update_default_event_settings' => [
198
+				'func'       => '_update_default_event_settings',
199
+				'capability' => 'manage_options',
200
+				'noheader'   => true,
201
+			],
202
+			'template_settings'             => [
203
+				'func'       => '_template_settings',
204
+				'capability' => 'manage_options',
205
+			],
206
+			// event category tab related
207
+			'add_category'                  => [
208
+				'func'       => '_category_details',
209
+				'capability' => 'ee_edit_event_category',
210
+				'args'       => ['add'],
211
+			],
212
+			'edit_category'                 => [
213
+				'func'       => '_category_details',
214
+				'capability' => 'ee_edit_event_category',
215
+				'args'       => ['edit'],
216
+			],
217
+			'delete_categories'             => [
218
+				'func'       => '_delete_categories',
219
+				'capability' => 'ee_delete_event_category',
220
+				'noheader'   => true,
221
+			],
222
+			'delete_category'               => [
223
+				'func'       => '_delete_categories',
224
+				'capability' => 'ee_delete_event_category',
225
+				'noheader'   => true,
226
+			],
227
+			'insert_category'               => [
228
+				'func'       => '_insert_or_update_category',
229
+				'args'       => ['new_category' => true],
230
+				'capability' => 'ee_edit_event_category',
231
+				'noheader'   => true,
232
+			],
233
+			'update_category'               => [
234
+				'func'       => '_insert_or_update_category',
235
+				'args'       => ['new_category' => false],
236
+				'capability' => 'ee_edit_event_category',
237
+				'noheader'   => true,
238
+			],
239
+			'category_list'                 => [
240
+				'func'       => '_category_list_table',
241
+				'capability' => 'ee_manage_event_categories',
242
+			],
243
+			'preview_deletion'              => [
244
+				'func'       => 'previewDeletion',
245
+				'capability' => 'ee_delete_events',
246
+			],
247
+			'confirm_deletion'              => [
248
+				'func'       => 'confirmDeletion',
249
+				'capability' => 'ee_delete_events',
250
+				'noheader'   => true,
251
+			],
252
+		];
253
+	}
254
+
255
+
256
+	/**
257
+	 * Set the _page_config property for this admin page group.
258
+	 */
259
+	protected function _set_page_config()
260
+	{
261
+		$this->_page_config = [
262
+			'default'                => [
263
+				'nav'           => [
264
+					'label' => esc_html__('Overview', 'event_espresso'),
265
+					'order' => 10,
266
+				],
267
+				'list_table'    => 'Events_Admin_List_Table',
268
+				'help_tabs'     => [
269
+					'events_overview_help_tab'                       => [
270
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
271
+						'filename' => 'events_overview',
272
+					],
273
+					'events_overview_table_column_headings_help_tab' => [
274
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
275
+						'filename' => 'events_overview_table_column_headings',
276
+					],
277
+					'events_overview_filters_help_tab'               => [
278
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
279
+						'filename' => 'events_overview_filters',
280
+					],
281
+					'events_overview_view_help_tab'                  => [
282
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
283
+						'filename' => 'events_overview_views',
284
+					],
285
+					'events_overview_other_help_tab'                 => [
286
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
287
+						'filename' => 'events_overview_other',
288
+					],
289
+				],
290
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
291
+				// 'help_tour'     => [
292
+				//     'Event_Overview_Help_Tour',
293
+				//     // 'New_Features_Test_Help_Tour' for testing multiple help tour
294
+				// ],
295
+				'require_nonce' => false,
296
+				'qtips'         => ['EE_Event_List_Table_Tips'],
297
+			],
298
+			'create_new'             => [
299
+				'nav'           => [
300
+					'label'      => esc_html__('Add Event', 'event_espresso'),
301
+					'order'      => 5,
302
+					'persistent' => false,
303
+				],
304
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
305
+				'help_tabs'     => [
306
+					'event_editor_help_tab'                            => [
307
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
308
+						'filename' => 'event_editor',
309
+					],
310
+					'event_editor_title_richtexteditor_help_tab'       => [
311
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
312
+						'filename' => 'event_editor_title_richtexteditor',
313
+					],
314
+					'event_editor_venue_details_help_tab'              => [
315
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
316
+						'filename' => 'event_editor_venue_details',
317
+					],
318
+					'event_editor_event_datetimes_help_tab'            => [
319
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
320
+						'filename' => 'event_editor_event_datetimes',
321
+					],
322
+					'event_editor_event_tickets_help_tab'              => [
323
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
324
+						'filename' => 'event_editor_event_tickets',
325
+					],
326
+					'event_editor_event_registration_options_help_tab' => [
327
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
328
+						'filename' => 'event_editor_event_registration_options',
329
+					],
330
+					'event_editor_tags_categories_help_tab'            => [
331
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
332
+						'filename' => 'event_editor_tags_categories',
333
+					],
334
+					'event_editor_questions_registrants_help_tab'      => [
335
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
336
+						'filename' => 'event_editor_questions_registrants',
337
+					],
338
+					'event_editor_save_new_event_help_tab'             => [
339
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
340
+						'filename' => 'event_editor_save_new_event',
341
+					],
342
+					'event_editor_other_help_tab'                      => [
343
+						'title'    => esc_html__('Event Other', 'event_espresso'),
344
+						'filename' => 'event_editor_other',
345
+					],
346
+				],
347
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
348
+				// 'help_tour'     => [
349
+				//     'Event_Editor_Help_Tour',
350
+				// ],
351
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
352
+				'require_nonce' => false,
353
+			],
354
+			'edit'                   => [
355
+				'nav'           => [
356
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
357
+					'order'      => 5,
358
+					'persistent' => false,
359
+					'url'        => isset($this->_req_data['post'])
360
+						? EE_Admin_Page::add_query_args_and_nonce(
361
+							['post' => $this->_req_data['post'], 'action' => 'edit'],
362
+							$this->_current_page_view_url
363
+						)
364
+						: $this->_admin_base_url,
365
+				],
366
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
367
+				'help_tabs'     => [
368
+					'event_editor_help_tab'                            => [
369
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
370
+						'filename' => 'event_editor',
371
+					],
372
+					'event_editor_title_richtexteditor_help_tab'       => [
373
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
374
+						'filename' => 'event_editor_title_richtexteditor',
375
+					],
376
+					'event_editor_venue_details_help_tab'              => [
377
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
378
+						'filename' => 'event_editor_venue_details',
379
+					],
380
+					'event_editor_event_datetimes_help_tab'            => [
381
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
382
+						'filename' => 'event_editor_event_datetimes',
383
+					],
384
+					'event_editor_event_tickets_help_tab'              => [
385
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
386
+						'filename' => 'event_editor_event_tickets',
387
+					],
388
+					'event_editor_event_registration_options_help_tab' => [
389
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
390
+						'filename' => 'event_editor_event_registration_options',
391
+					],
392
+					'event_editor_tags_categories_help_tab'            => [
393
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
394
+						'filename' => 'event_editor_tags_categories',
395
+					],
396
+					'event_editor_questions_registrants_help_tab'      => [
397
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
398
+						'filename' => 'event_editor_questions_registrants',
399
+					],
400
+					'event_editor_save_new_event_help_tab'             => [
401
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
402
+						'filename' => 'event_editor_save_new_event',
403
+					],
404
+					'event_editor_other_help_tab'                      => [
405
+						'title'    => esc_html__('Event Other', 'event_espresso'),
406
+						'filename' => 'event_editor_other',
407
+					],
408
+				],
409
+				'require_nonce' => false,
410
+			],
411
+			'default_event_settings' => [
412
+				'nav'           => [
413
+					'label' => esc_html__('Default Settings', 'event_espresso'),
414
+					'order' => 40,
415
+				],
416
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
417
+				'labels'        => [
418
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
419
+				],
420
+				'help_tabs'     => [
421
+					'default_settings_help_tab'        => [
422
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
423
+						'filename' => 'events_default_settings',
424
+					],
425
+					'default_settings_status_help_tab' => [
426
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
427
+						'filename' => 'events_default_settings_status',
428
+					],
429
+					'default_maximum_tickets_help_tab' => [
430
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
431
+						'filename' => 'events_default_settings_max_tickets',
432
+					],
433
+				],
434
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
435
+				// 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
436
+				'require_nonce' => false,
437
+			],
438
+			// template settings
439
+			'template_settings'      => [
440
+				'nav'           => [
441
+					'label' => esc_html__('Templates', 'event_espresso'),
442
+					'order' => 30,
443
+				],
444
+				'metaboxes'     => $this->_default_espresso_metaboxes,
445
+				'help_tabs'     => [
446
+					'general_settings_templates_help_tab' => [
447
+						'title'    => esc_html__('Templates', 'event_espresso'),
448
+						'filename' => 'general_settings_templates',
449
+					],
450
+				],
451
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
452
+				// 'help_tour'     => ['Templates_Help_Tour'],
453
+				'require_nonce' => false,
454
+			],
455
+			// event category stuff
456
+			'add_category'           => [
457
+				'nav'           => [
458
+					'label'      => esc_html__('Add Category', 'event_espresso'),
459
+					'order'      => 15,
460
+					'persistent' => false,
461
+				],
462
+				'help_tabs'     => [
463
+					'add_category_help_tab' => [
464
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
465
+						'filename' => 'events_add_category',
466
+					],
467
+				],
468
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
469
+				// 'help_tour'     => ['Event_Add_Category_Help_Tour'],
470
+				'metaboxes'     => ['_publish_post_box'],
471
+				'require_nonce' => false,
472
+			],
473
+			'edit_category'          => [
474
+				'nav'           => [
475
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
476
+					'order'      => 15,
477
+					'persistent' => false,
478
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
479
+						? add_query_arg(
480
+							['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']],
481
+							$this->_current_page_view_url
482
+						)
483
+						: $this->_admin_base_url,
484
+				],
485
+				'help_tabs'     => [
486
+					'edit_category_help_tab' => [
487
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
488
+						'filename' => 'events_edit_category',
489
+					],
490
+				],
491
+				/*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
492
+				'metaboxes'     => ['_publish_post_box'],
493
+				'require_nonce' => false,
494
+			],
495
+			'category_list'          => [
496
+				'nav'           => [
497
+					'label' => esc_html__('Categories', 'event_espresso'),
498
+					'order' => 20,
499
+				],
500
+				'list_table'    => 'Event_Categories_Admin_List_Table',
501
+				'help_tabs'     => [
502
+					'events_categories_help_tab'                       => [
503
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
504
+						'filename' => 'events_categories',
505
+					],
506
+					'events_categories_table_column_headings_help_tab' => [
507
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
508
+						'filename' => 'events_categories_table_column_headings',
509
+					],
510
+					'events_categories_view_help_tab'                  => [
511
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
512
+						'filename' => 'events_categories_views',
513
+					],
514
+					'events_categories_other_help_tab'                 => [
515
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
516
+						'filename' => 'events_categories_other',
517
+					],
518
+				],
519
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
520
+				// 'help_tour'     => [
521
+				//     'Event_Categories_Help_Tour',
522
+				// ],
523
+				'metaboxes'     => $this->_default_espresso_metaboxes,
524
+				'require_nonce' => false,
525
+			],
526
+			'preview_deletion'       => [
527
+				'nav'           => [
528
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
529
+					'order'      => 15,
530
+					'persistent' => false,
531
+					'url'        => '',
532
+				],
533
+				'require_nonce' => false,
534
+			],
535
+		];
536
+		// only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
537
+		$domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
538
+		if (! $domain->isCaffeinated()) {
539
+			$this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
540
+			$this->_page_config['edit']['qtips']       = ['EE_Event_Editor_Decaf_Tips'];
541
+		}
542
+	}
543
+
544
+
545
+	/**
546
+	 * Used to register any global screen options if necessary for every route in this admin page group.
547
+	 */
548
+	protected function _add_screen_options()
549
+	{
550
+	}
551
+
552
+
553
+	/**
554
+	 * Implementing the screen options for the 'default' route.
555
+	 *
556
+	 * @throws InvalidArgumentException
557
+	 * @throws InvalidDataTypeException
558
+	 * @throws InvalidInterfaceException
559
+	 */
560
+	protected function _add_screen_options_default()
561
+	{
562
+		$this->_per_page_screen_option();
563
+	}
564
+
565
+
566
+	/**
567
+	 * Implementing screen options for the category list route.
568
+	 *
569
+	 * @throws InvalidArgumentException
570
+	 * @throws InvalidDataTypeException
571
+	 * @throws InvalidInterfaceException
572
+	 */
573
+	protected function _add_screen_options_category_list()
574
+	{
575
+		$page_title              = $this->_admin_page_title;
576
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
577
+		$this->_per_page_screen_option();
578
+		$this->_admin_page_title = $page_title;
579
+	}
580
+
581
+
582
+	/**
583
+	 * Used to register any global feature pointers for the admin page group.
584
+	 */
585
+	protected function _add_feature_pointers()
586
+	{
587
+	}
588
+
589
+
590
+	/**
591
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
592
+	 */
593
+	public function load_scripts_styles()
594
+	{
595
+		wp_register_style(
596
+			'events-admin-css',
597
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
598
+			[],
599
+			EVENT_ESPRESSO_VERSION
600
+		);
601
+		wp_register_style(
602
+			'ee-cat-admin',
603
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
604
+			[],
605
+			EVENT_ESPRESSO_VERSION
606
+		);
607
+		wp_enqueue_style('events-admin-css');
608
+		wp_enqueue_style('ee-cat-admin');
609
+		// scripts
610
+		wp_register_script(
611
+			'event_editor_js',
612
+			EVENTS_ASSETS_URL . 'event_editor.js',
613
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
614
+			EVENT_ESPRESSO_VERSION,
615
+			true
616
+		);
617
+	}
618
+
619
+
620
+	/**
621
+	 * Enqueuing scripts and styles specific to this view
622
+	 */
623
+	public function load_scripts_styles_create_new()
624
+	{
625
+		$this->load_scripts_styles_edit();
626
+	}
627
+
628
+
629
+	/**
630
+	 * Enqueuing scripts and styles specific to this view
631
+	 */
632
+	public function load_scripts_styles_edit()
633
+	{
634
+		// styles
635
+		wp_enqueue_style('espresso-ui-theme');
636
+		wp_register_style(
637
+			'event-editor-css',
638
+			EVENTS_ASSETS_URL . 'event-editor.css',
639
+			['ee-admin-css'],
640
+			EVENT_ESPRESSO_VERSION
641
+		);
642
+		wp_enqueue_style('event-editor-css');
643
+		// scripts
644
+		if (! $this->admin_config->useAdvancedEditor()) {
645
+			wp_register_script(
646
+				'event-datetime-metabox',
647
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
648
+				['event_editor_js', 'ee-datepicker'],
649
+				EVENT_ESPRESSO_VERSION
650
+			);
651
+			wp_enqueue_script('event-datetime-metabox');
652
+		}
653
+	}
654
+
655
+
656
+	/**
657
+	 * Populating the _views property for the category list table view.
658
+	 */
659
+	protected function _set_list_table_views_category_list()
660
+	{
661
+		$this->_views = [
662
+			'all' => [
663
+				'slug'        => 'all',
664
+				'label'       => esc_html__('All', 'event_espresso'),
665
+				'count'       => 0,
666
+				'bulk_action' => [
667
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
668
+				],
669
+			],
670
+		];
671
+	}
672
+
673
+
674
+	/**
675
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
676
+	 */
677
+	public function admin_init()
678
+	{
679
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
680
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
681
+			'event_espresso'
682
+		);
683
+	}
684
+
685
+
686
+	/**
687
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
688
+	 * group.
689
+	 */
690
+	public function admin_notices()
691
+	{
692
+	}
693
+
694
+
695
+	/**
696
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
697
+	 * this admin page group.
698
+	 */
699
+	public function admin_footer_scripts()
700
+	{
701
+	}
702
+
703
+
704
+	/**
705
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
706
+	 * warning (via EE_Error::add_error());
707
+	 *
708
+	 * @param EE_Event $event Event object
709
+	 * @param string   $req_type
710
+	 * @return void
711
+	 * @throws EE_Error
712
+	 * @access public
713
+	 */
714
+	public function verify_event_edit($event = null, $req_type = '')
715
+	{
716
+		// don't need to do this when processing
717
+		if (! empty($req_type)) {
718
+			return;
719
+		}
720
+		// no event?
721
+		if (! $event instanceof EE_Event) {
722
+			$event = $this->_cpt_model_obj;
723
+		}
724
+		// STILL no event?
725
+		if (! $event instanceof EE_Event) {
726
+			return;
727
+		}
728
+		$orig_status = $event->status();
729
+		// first check if event is active.
730
+		if (
731
+			$orig_status === EEM_Event::cancelled
732
+			|| $orig_status === EEM_Event::postponed
733
+			|| $event->is_expired()
734
+			|| $event->is_inactive()
735
+		) {
736
+			return;
737
+		}
738
+		// made it here so it IS active... next check that any of the tickets are sold.
739
+		if ($event->is_sold_out(true)) {
740
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
741
+				EE_Error::add_attention(
742
+					sprintf(
743
+						esc_html__(
744
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
745
+							'event_espresso'
746
+						),
747
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
748
+					)
749
+				);
750
+			}
751
+			return;
752
+		}
753
+		if ($orig_status === EEM_Event::sold_out) {
754
+			EE_Error::add_attention(
755
+				sprintf(
756
+					esc_html__(
757
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
758
+						'event_espresso'
759
+					),
760
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
761
+				)
762
+			);
763
+		}
764
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
765
+		if (! $event->tickets_on_sale()) {
766
+			return;
767
+		}
768
+		// made it here so show warning
769
+		$this->_edit_event_warning();
770
+	}
771
+
772
+
773
+	/**
774
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
775
+	 * When needed, hook this into a EE_Error::add_error() notice.
776
+	 *
777
+	 * @access protected
778
+	 * @return void
779
+	 */
780
+	protected function _edit_event_warning()
781
+	{
782
+		// we don't want to add warnings during these requests
783
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
784
+			return;
785
+		}
786
+		EE_Error::add_attention(
787
+			sprintf(
788
+				esc_html__(
789
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
790
+					'event_espresso'
791
+				),
792
+				'<a class="espresso-help-tab-lnk">',
793
+				'</a>'
794
+			)
795
+		);
796
+	}
797
+
798
+
799
+	/**
800
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
801
+	 * Otherwise, do the normal logic
802
+	 *
803
+	 * @return void
804
+	 * @throws EE_Error
805
+	 * @throws InvalidArgumentException
806
+	 * @throws InvalidDataTypeException
807
+	 * @throws InvalidInterfaceException
808
+	 */
809
+	protected function _create_new_cpt_item()
810
+	{
811
+		$has_timezone_string = get_option('timezone_string');
812
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
813
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
814
+			EE_Error::add_attention(
815
+				sprintf(
816
+					__(
817
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
818
+						'event_espresso'
819
+					),
820
+					'<br>',
821
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
822
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
823
+					. '</select>',
824
+					'<button class="button button-secondary timezone-submit">',
825
+					'</button><span class="spinner"></span>'
826
+				),
827
+				__FILE__,
828
+				__FUNCTION__,
829
+				__LINE__
830
+			);
831
+		}
832
+		parent::_create_new_cpt_item();
833
+	}
834
+
835
+
836
+	/**
837
+	 * Sets the _views property for the default route in this admin page group.
838
+	 */
839
+	protected function _set_list_table_views_default()
840
+	{
841
+		$this->_views = [
842
+			'all'   => [
843
+				'slug'        => 'all',
844
+				'label'       => esc_html__('View All Events', 'event_espresso'),
845
+				'count'       => 0,
846
+				'bulk_action' => [
847
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
848
+				],
849
+			],
850
+			'draft' => [
851
+				'slug'        => 'draft',
852
+				'label'       => esc_html__('Draft', 'event_espresso'),
853
+				'count'       => 0,
854
+				'bulk_action' => [
855
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
856
+				],
857
+			],
858
+		];
859
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
860
+			$this->_views['trash'] = [
861
+				'slug'        => 'trash',
862
+				'label'       => esc_html__('Trash', 'event_espresso'),
863
+				'count'       => 0,
864
+				'bulk_action' => [
865
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
866
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
867
+				],
868
+			];
869
+		}
870
+	}
871
+
872
+
873
+	/**
874
+	 * Provides the legend item array for the default list table view.
875
+	 *
876
+	 * @return array
877
+	 */
878
+	protected function _event_legend_items()
879
+	{
880
+		$items    = [
881
+			'view_details'   => [
882
+				'class' => 'dashicons dashicons-search',
883
+				'desc'  => esc_html__('View Event', 'event_espresso'),
884
+			],
885
+			'edit_event'     => [
886
+				'class' => 'ee-icon ee-icon-calendar-edit',
887
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
888
+			],
889
+			'view_attendees' => [
890
+				'class' => 'dashicons dashicons-groups',
891
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
892
+			],
893
+		];
894
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
895
+		$statuses = [
896
+			'sold_out_status'  => [
897
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
898
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
899
+			],
900
+			'active_status'    => [
901
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
902
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
903
+			],
904
+			'upcoming_status'  => [
905
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
906
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
907
+			],
908
+			'postponed_status' => [
909
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
910
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
911
+			],
912
+			'cancelled_status' => [
913
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
914
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
915
+			],
916
+			'expired_status'   => [
917
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
918
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
919
+			],
920
+			'inactive_status'  => [
921
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
922
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
923
+			],
924
+		];
925
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
926
+		return array_merge($items, $statuses);
927
+	}
928
+
929
+
930
+	/**
931
+	 * @return EEM_Event
932
+	 * @throws EE_Error
933
+	 * @throws InvalidArgumentException
934
+	 * @throws InvalidDataTypeException
935
+	 * @throws InvalidInterfaceException
936
+	 * @throws ReflectionException
937
+	 */
938
+	private function _event_model()
939
+	{
940
+		if (! $this->_event_model instanceof EEM_Event) {
941
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
942
+		}
943
+		return $this->_event_model;
944
+	}
945
+
946
+
947
+	/**
948
+	 * Adds extra buttons to the WP CPT permalink field row.
949
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
950
+	 *
951
+	 * @param string $return    the current html
952
+	 * @param int    $id        the post id for the page
953
+	 * @param string $new_title What the title is
954
+	 * @param string $new_slug  what the slug is
955
+	 * @return string            The new html string for the permalink area
956
+	 */
957
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
958
+	{
959
+		// make sure this is only when editing
960
+		if (! empty($id)) {
961
+			$post   = get_post($id);
962
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
963
+					   . esc_html__('Shortcode', 'event_espresso')
964
+					   . '</a> ';
965
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
966
+					   . $post->ID
967
+					   . ']">';
968
+		}
969
+		return $return;
970
+	}
971
+
972
+
973
+	/**
974
+	 * _events_overview_list_table
975
+	 * This contains the logic for showing the events_overview list
976
+	 *
977
+	 * @access protected
978
+	 * @return void
979
+	 * @throws DomainException
980
+	 * @throws EE_Error
981
+	 * @throws InvalidArgumentException
982
+	 * @throws InvalidDataTypeException
983
+	 * @throws InvalidInterfaceException
984
+	 */
985
+	protected function _events_overview_list_table()
986
+	{
987
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
988
+		$after_list_table                           = [];
989
+		$after_list_table['view_event_list_button'] = EEH_HTML::br();
990
+		$after_list_table['view_event_list_button'] .= EEH_Template::get_button_or_link(
991
+			get_post_type_archive_link('espresso_events'),
992
+			esc_html__('View Event Archive Page', 'event_espresso'),
993
+			'button'
994
+		);
995
+		$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
996
+		$this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
997
+			'create_new',
998
+			'add',
999
+			[],
1000
+			'add-new-h2'
1001
+		);
1002
+		$this->_template_args['after_list_table']   = array_merge(
1003
+			(array) $this->_template_args['after_list_table'],
1004
+			$after_list_table
1005
+		);
1006
+		$this->display_admin_list_table_page_with_no_sidebar();
1007
+	}
1008
+
1009
+
1010
+	/**
1011
+	 * this allows for extra misc actions in the default WP publish box
1012
+	 *
1013
+	 * @return void
1014
+	 * @throws DomainException
1015
+	 * @throws EE_Error
1016
+	 * @throws InvalidArgumentException
1017
+	 * @throws InvalidDataTypeException
1018
+	 * @throws InvalidInterfaceException
1019
+	 * @throws ReflectionException
1020
+	 */
1021
+	public function extra_misc_actions_publish_box()
1022
+	{
1023
+		$this->_generate_publish_box_extra_content();
1024
+	}
1025
+
1026
+
1027
+	/**
1028
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1029
+	 * saved.
1030
+	 * Typically you would use this to save any additional data.
1031
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1032
+	 * ALSO very important.  When a post transitions from scheduled to published,
1033
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1034
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1035
+	 *
1036
+	 * @access protected
1037
+	 * @abstract
1038
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1039
+	 * @param object $post    The post object of the cpt that was saved.
1040
+	 * @return void
1041
+	 * @throws EE_Error
1042
+	 * @throws InvalidArgumentException
1043
+	 * @throws InvalidDataTypeException
1044
+	 * @throws InvalidInterfaceException
1045
+	 * @throws ReflectionException
1046
+	 */
1047
+	protected function _insert_update_cpt_item($post_id, $post)
1048
+	{
1049
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1050
+			// get out we're not processing an event save.
1051
+			return;
1052
+		}
1053
+		$event_values = [
1054
+			'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1055
+			'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1056
+			'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1057
+				? sanitize_text_field($this->_req_data['timezone_string'])
1058
+				: null,
1059
+		];
1060
+		/** @var FeatureFlags $flags */
1061
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1062
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1063
+		if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1064
+			$event_values['EVT_display_ticket_selector']     =
1065
+				! empty($this->_req_data['display_ticket_selector'])
1066
+					? 1
1067
+					: 0;
1068
+			$event_values['EVT_additional_limit']            = min(
1069
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1070
+				! empty($this->_req_data['additional_limit'])
1071
+					? absint($this->_req_data['additional_limit'])
1072
+					: null
1073
+			);
1074
+			$event_values['EVT_default_registration_status'] =
1075
+				! empty($this->_req_data['EVT_default_registration_status'])
1076
+					? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1077
+					: EE_Registry::instance()->CFG->registration->default_STS_ID;
1078
+			$event_values['EVT_external_URL']                = ! empty($this->_req_data['externalURL'])
1079
+				? esc_url_raw($this->_req_data['externalURL'])
1080
+				: null;
1081
+			$event_values['EVT_phone']                       = ! empty($this->_req_data['event_phone'])
1082
+				? sanitize_text_field($this->_req_data['event_phone'])
1083
+				: null;
1084
+		}
1085
+		// update event
1086
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1087
+		// get event_object for other metaboxes...
1088
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1089
+		// i have to setup where conditions to override the filters in the model that filter out autodraft
1090
+		// and inherit statuses so we GET the inherit id!
1091
+		$get_one_where = [
1092
+			$this->_event_model()->primary_key_name() => $post_id,
1093
+			'OR'                                      => [
1094
+				'status'   => $post->post_status,
1095
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1096
+				// but the returned object here has a status of "publish", so use the original post status as well
1097
+				'status*1' => $this->_req_data['original_post_status'],
1098
+			],
1099
+		];
1100
+		$event         = $this->_event_model()->get_one([$get_one_where]);
1101
+		// the following are default callbacks for event attachment updates
1102
+		// that can be overridden by caffeinated functionality and/or addons.
1103
+		$event_update_callbacks = apply_filters(
1104
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1105
+			[
1106
+				[$this, '_default_venue_update'],
1107
+				[$this, '_default_tickets_update'],
1108
+			]
1109
+		);
1110
+		$att_success            = true;
1111
+		foreach ($event_update_callbacks as $e_callback) {
1112
+			$_success = is_callable($e_callback)
1113
+				? $e_callback($event, $this->_req_data)
1114
+				: false;
1115
+			// if ANY of these updates fail then we want the appropriate global error message
1116
+			$att_success = ! $att_success ? $att_success : $_success;
1117
+		}
1118
+		// any errors?
1119
+		if ($success && false === $att_success) {
1120
+			EE_Error::add_error(
1121
+				esc_html__(
1122
+					'Event Details saved successfully but something went wrong with saving attachments.',
1123
+					'event_espresso'
1124
+				),
1125
+				__FILE__,
1126
+				__FUNCTION__,
1127
+				__LINE__
1128
+			);
1129
+		} elseif ($success === false) {
1130
+			EE_Error::add_error(
1131
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1132
+				__FILE__,
1133
+				__FUNCTION__,
1134
+				__LINE__
1135
+			);
1136
+		}
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * @param int $post_id
1142
+	 * @param int $revision_id
1143
+	 * @throws EE_Error
1144
+	 * @throws InvalidArgumentException
1145
+	 * @throws InvalidDataTypeException
1146
+	 * @throws InvalidInterfaceException
1147
+	 * @throws ReflectionException
1148
+	 * @see parent::restore_item()
1149
+	 */
1150
+	protected function _restore_cpt_item($post_id, $revision_id)
1151
+	{
1152
+		// copy existing event meta to new post
1153
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1154
+		if ($post_evt instanceof EE_Event) {
1155
+			// meta revision restore
1156
+			$post_evt->restore_revision($revision_id);
1157
+			// related objs restore
1158
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1159
+		}
1160
+	}
1161
+
1162
+
1163
+	/**
1164
+	 * Attach the venue to the Event
1165
+	 *
1166
+	 * @param EE_Event $evtobj Event Object to add the venue to
1167
+	 * @param array    $data   The request data from the form
1168
+	 * @return bool           Success or fail.
1169
+	 * @throws EE_Error
1170
+	 * @throws InvalidArgumentException
1171
+	 * @throws InvalidDataTypeException
1172
+	 * @throws InvalidInterfaceException
1173
+	 * @throws ReflectionException
1174
+	 */
1175
+	protected function _default_venue_update(EE_Event $evtobj, $data)
1176
+	{
1177
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1178
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1179
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1180
+		// very important.  If we don't have a venue name...
1181
+		// then we'll get out because not necessary to create empty venue
1182
+		if (empty($data['venue_title'])) {
1183
+			return false;
1184
+		}
1185
+		$venue_array = [
1186
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1187
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1188
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1189
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1190
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1191
+				: null,
1192
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1193
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1194
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1195
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1196
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1197
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1198
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1199
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1200
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1201
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1202
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1203
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1204
+			'status'              => 'publish',
1205
+		];
1206
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1207
+		if (! empty($venue_id)) {
1208
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1209
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1210
+			// we've gotta make sure that the venue is always attached to a revision..
1211
+			// add_relation_to should take care of making sure that the relation is already present.
1212
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1213
+			return $rows_affected > 0;
1214
+		}
1215
+		// we insert the venue
1216
+		$venue_id = $venue_model->insert($venue_array);
1217
+		$evtobj->_add_relation_to($venue_id, 'Venue');
1218
+		return ! empty($venue_id);
1219
+		// when we have the ancestor come in it's already been handled by the revision save.
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1225
+	 *
1226
+	 * @param EE_Event $evtobj The Event object we're attaching data to
1227
+	 * @param array    $data   The request data from the form
1228
+	 * @return array
1229
+	 * @throws EE_Error
1230
+	 * @throws InvalidArgumentException
1231
+	 * @throws InvalidDataTypeException
1232
+	 * @throws InvalidInterfaceException
1233
+	 * @throws ReflectionException
1234
+	 * @throws Exception
1235
+	 */
1236
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1237
+	{
1238
+		if ($this->admin_config->useAdvancedEditor()) {
1239
+			return [];
1240
+		}
1241
+		$success               = true;
1242
+		$saved_dtt             = null;
1243
+		$saved_tickets         = [];
1244
+		$incoming_date_formats = ['Y-m-d', 'h:i a'];
1245
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1246
+			// trim all values to ensure any excess whitespace is removed.
1247
+			$dtt                = array_map('trim', $dtt);
1248
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1249
+				: $dtt['DTT_EVT_start'];
1250
+			$datetime_values    = [
1251
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1252
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1253
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1254
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1255
+				'DTT_order'     => $row,
1256
+			];
1257
+			// if we have an id then let's get existing object first and then set the new values.
1258
+			//  Otherwise we instantiate a new object for save.
1259
+			if (! empty($dtt['DTT_ID'])) {
1260
+				$DTM = EE_Registry::instance()
1261
+								  ->load_model('Datetime', [$evtobj->get_timezone()])
1262
+								  ->get_one_by_ID($dtt['DTT_ID']);
1263
+				$DTM->set_date_format($incoming_date_formats[0]);
1264
+				$DTM->set_time_format($incoming_date_formats[1]);
1265
+				foreach ($datetime_values as $field => $value) {
1266
+					$DTM->set($field, $value);
1267
+				}
1268
+				// make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it.
1269
+				// We need to do this so we dont' TRASH the parent DTT.
1270
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1271
+			} else {
1272
+				$DTM = EE_Registry::instance()->load_class(
1273
+					'Datetime',
1274
+					[$datetime_values, $evtobj->get_timezone(), $incoming_date_formats],
1275
+					false,
1276
+					false
1277
+				);
1278
+				foreach ($datetime_values as $field => $value) {
1279
+					$DTM->set($field, $value);
1280
+				}
1281
+			}
1282
+			$DTM->save();
1283
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1284
+			// load DTT helper
1285
+			// before going any further make sure our dates are setup correctly
1286
+			// so that the end date is always equal or greater than the start date.
1287
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1288
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1289
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1290
+				$DTT->save();
1291
+			}
1292
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array
1293
+			//  because it is possible there was a new one created for the autosave.
1294
+			$saved_dtt = $DTT;
1295
+			$success   = ! $success ? $success : $DTT;
1296
+			// if ANY of these updates fail then we want the appropriate global error message.
1297
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1298
+		}
1299
+		// no dtts get deleted so we don't do any of that logic here.
1300
+		// update tickets next
1301
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1302
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1303
+			$incoming_date_formats = ['Y-m-d', 'h:i a'];
1304
+			$update_prices         = false;
1305
+			$ticket_price          = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1306
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1307
+				: 0;
1308
+			// trim inputs to ensure any excess whitespace is removed.
1309
+			$tkt = array_map('trim', $tkt);
1310
+			if (empty($tkt['TKT_start_date'])) {
1311
+				// let's use now in the set timezone.
1312
+				$now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1313
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1314
+			}
1315
+			if (empty($tkt['TKT_end_date'])) {
1316
+				// use the start date of the first datetime
1317
+				$dtt                 = $evtobj->first_datetime();
1318
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1319
+					$incoming_date_formats[0],
1320
+					$incoming_date_formats[1]
1321
+				);
1322
+			}
1323
+			$TKT_values = [
1324
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1325
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1326
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1327
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1328
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1329
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1330
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1331
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1332
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1333
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1334
+				'TKT_row'         => $row,
1335
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1336
+				'TKT_price'       => $ticket_price,
1337
+			];
1338
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
1339
+			// which means in turn that the prices will become new prices as well.
1340
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1341
+				$TKT_values['TKT_ID']         = 0;
1342
+				$TKT_values['TKT_is_default'] = 0;
1343
+				$TKT_values['TKT_price']      = $ticket_price;
1344
+				$update_prices                = true;
1345
+			}
1346
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1347
+			// we actually do our saves a head of doing any add_relations to because its entirely possible
1348
+			// that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1349
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
1350
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1351
+			if (! empty($tkt['TKT_ID'])) {
1352
+				$TKT = EE_Registry::instance()
1353
+								  ->load_model('Ticket', [$evtobj->get_timezone()])
1354
+								  ->get_one_by_ID($tkt['TKT_ID']);
1355
+				if ($TKT instanceof EE_Ticket) {
1356
+					$ticket_sold = $TKT->count_related(
1357
+						'Registration',
1358
+						[
1359
+							[
1360
+								'STS_ID' => [
1361
+									'NOT IN',
1362
+									[EEM_Registration::status_id_incomplete],
1363
+								],
1364
+							],
1365
+						]
1366
+					) > 0;
1367
+					// let's just check the total price for the existing ticket and determine if it matches the new
1368
+					// total price.  if they are different then we create a new ticket (if tickets sold)
1369
+					// if they aren't different then we go ahead and modify existing ticket.
1370
+					$create_new_TKT = $ticket_sold
1371
+									  && ! $TKT->deleted()
1372
+									  && EEH_Money::compare_floats(
1373
+										  $ticket_price,
1374
+										  $TKT->get('TKT_price'),
1375
+										  '!=='
1376
+									  );
1377
+					$TKT->set_date_format($incoming_date_formats[0]);
1378
+					$TKT->set_time_format($incoming_date_formats[1]);
1379
+					// set new values
1380
+					foreach ($TKT_values as $field => $value) {
1381
+						if ($field === 'TKT_qty') {
1382
+							$TKT->set_qty($value);
1383
+						} else {
1384
+							$TKT->set($field, $value);
1385
+						}
1386
+					}
1387
+					// if $create_new_TKT is false then we can safely update the existing ticket.
1388
+					//  Otherwise we have to create a new ticket.
1389
+					if ($create_new_TKT) {
1390
+						// archive the old ticket first
1391
+						$TKT->set('TKT_deleted', 1);
1392
+						$TKT->save();
1393
+						// make sure this ticket is still recorded in our saved_tkts
1394
+						// so we don't run it through the regular trash routine.
1395
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1396
+						// create new ticket that's a copy of the existing except a new id of course
1397
+						// (and not archived) AND has the new TKT_price associated with it.
1398
+						$TKT = clone $TKT;
1399
+						$TKT->set('TKT_ID', 0);
1400
+						$TKT->set('TKT_deleted', 0);
1401
+						$TKT->set('TKT_price', $ticket_price);
1402
+						$TKT->set('TKT_sold', 0);
1403
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1404
+						$update_prices = true;
1405
+					}
1406
+					// make sure price is set if it hasn't been already
1407
+					$TKT->set('TKT_price', $ticket_price);
1408
+				}
1409
+			} else {
1410
+				// no TKT_id so a new TKT
1411
+				$TKT_values['TKT_price'] = $ticket_price;
1412
+				$TKT                     = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1413
+				if ($TKT instanceof EE_Ticket) {
1414
+					// need to reset values to properly account for the date formats
1415
+					$TKT->set_date_format($incoming_date_formats[0]);
1416
+					$TKT->set_time_format($incoming_date_formats[1]);
1417
+					$TKT->set_timezone($evtobj->get_timezone());
1418
+					// set new values
1419
+					foreach ($TKT_values as $field => $value) {
1420
+						if ($field === 'TKT_qty') {
1421
+							$TKT->set_qty($value);
1422
+						} else {
1423
+							$TKT->set($field, $value);
1424
+						}
1425
+					}
1426
+					$update_prices = true;
1427
+				}
1428
+			}
1429
+			// cap ticket qty by datetime reg limits
1430
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1431
+			// update ticket.
1432
+			$TKT->save();
1433
+			// before going any further make sure our dates are setup correctly
1434
+			// so that the end date is always equal or greater than the start date.
1435
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1436
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1437
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1438
+				$TKT->save();
1439
+			}
1440
+			// initially let's add the ticket to the dtt
1441
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1442
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1443
+			// add prices to ticket
1444
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1445
+		}
1446
+		// however now we need to handle permanently deleting tickets via the ui.
1447
+		//  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1448
+		//  However, it does allow for deleting tickets that have no tickets sold,
1449
+		// in which case we want to get rid of permanently because there is no need to save in db.
1450
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1451
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1452
+		foreach ($tickets_removed as $id) {
1453
+			$id = absint($id);
1454
+			// get the ticket for this id
1455
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1456
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1457
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
1458
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1459
+			foreach ($dtts as $dtt) {
1460
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1461
+			}
1462
+			// need to do the same for prices (except these prices can also be deleted because again,
1463
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1464
+			$tkt_to_remove->delete_related_permanently('Price');
1465
+			// finally let's delete this ticket
1466
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1467
+			$tkt_to_remove->delete_permanently();
1468
+		}
1469
+		return [$saved_dtt, $saved_tickets];
1470
+	}
1471
+
1472
+
1473
+	/**
1474
+	 * This attaches a list of given prices to a ticket.
1475
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1476
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1477
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1478
+	 *
1479
+	 * @access  private
1480
+	 * @param array     $prices     Array of prices from the form.
1481
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1482
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1483
+	 * @return  void
1484
+	 * @throws EE_Error
1485
+	 * @throws InvalidArgumentException
1486
+	 * @throws InvalidDataTypeException
1487
+	 * @throws InvalidInterfaceException
1488
+	 * @throws ReflectionException
1489
+	 */
1490
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1491
+	{
1492
+		foreach ($prices as $row => $prc) {
1493
+			$PRC_values = [
1494
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1495
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1496
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1497
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1498
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1499
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1500
+				'PRC_order'      => $row,
1501
+			];
1502
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1503
+				$PRC_values['PRC_ID'] = 0;
1504
+				$PRC                  = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1505
+			} else {
1506
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1507
+				// update this price with new values
1508
+				foreach ($PRC_values as $field => $newprc) {
1509
+					$PRC->set($field, $newprc);
1510
+				}
1511
+				$PRC->save();
1512
+			}
1513
+			$ticket->_add_relation_to($PRC, 'Price');
1514
+		}
1515
+	}
1516
+
1517
+
1518
+	/**
1519
+	 * Add in our autosave ajax handlers
1520
+	 *
1521
+	 */
1522
+	protected function _ee_autosave_create_new()
1523
+	{
1524
+	}
1525
+
1526
+
1527
+	/**
1528
+	 * More autosave handlers.
1529
+	 */
1530
+	protected function _ee_autosave_edit()
1531
+	{
1532
+	}
1533
+
1534
+
1535
+	/**
1536
+	 *    _generate_publish_box_extra_content
1537
+	 *
1538
+	 * @throws DomainException
1539
+	 * @throws EE_Error
1540
+	 * @throws InvalidArgumentException
1541
+	 * @throws InvalidDataTypeException
1542
+	 * @throws InvalidInterfaceException
1543
+	 * @throws ReflectionException
1544
+	 */
1545
+	private function _generate_publish_box_extra_content()
1546
+	{
1547
+		// load formatter helper
1548
+		// args for getting related registrations
1549
+		$approved_query_args        = [
1550
+			[
1551
+				'REG_deleted' => 0,
1552
+				'STS_ID'      => EEM_Registration::status_id_approved,
1553
+			],
1554
+		];
1555
+		$not_approved_query_args    = [
1556
+			[
1557
+				'REG_deleted' => 0,
1558
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1559
+			],
1560
+		];
1561
+		$pending_payment_query_args = [
1562
+			[
1563
+				'REG_deleted' => 0,
1564
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1565
+			],
1566
+		];
1567
+		// publish box
1568
+		$publish_box_extra_args = [
1569
+			'view_approved_reg_url'        => add_query_arg(
1570
+				[
1571
+					'action'      => 'default',
1572
+					'event_id'    => $this->_cpt_model_obj->ID(),
1573
+					'_reg_status' => EEM_Registration::status_id_approved,
1574
+				],
1575
+				REG_ADMIN_URL
1576
+			),
1577
+			'view_not_approved_reg_url'    => add_query_arg(
1578
+				[
1579
+					'action'      => 'default',
1580
+					'event_id'    => $this->_cpt_model_obj->ID(),
1581
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1582
+				],
1583
+				REG_ADMIN_URL
1584
+			),
1585
+			'view_pending_payment_reg_url' => add_query_arg(
1586
+				[
1587
+					'action'      => 'default',
1588
+					'event_id'    => $this->_cpt_model_obj->ID(),
1589
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1590
+				],
1591
+				REG_ADMIN_URL
1592
+			),
1593
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1594
+				'Registration',
1595
+				$approved_query_args
1596
+			),
1597
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1598
+				'Registration',
1599
+				$not_approved_query_args
1600
+			),
1601
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1602
+				'Registration',
1603
+				$pending_payment_query_args
1604
+			),
1605
+			'misc_pub_section_class'       => apply_filters(
1606
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1607
+				'misc-pub-section'
1608
+			),
1609
+		];
1610
+		ob_start();
1611
+		do_action(
1612
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1613
+			$this->_cpt_model_obj
1614
+		);
1615
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1616
+		// load template
1617
+		EEH_Template::display_template(
1618
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1619
+			$publish_box_extra_args
1620
+		);
1621
+	}
1622
+
1623
+
1624
+	/**
1625
+	 * @return EE_Event
1626
+	 */
1627
+	public function get_event_object()
1628
+	{
1629
+		return $this->_cpt_model_obj;
1630
+	}
1631
+
1632
+
1633
+
1634
+
1635
+	/** METABOXES * */
1636
+	/**
1637
+	 * _register_event_editor_meta_boxes
1638
+	 * add all metaboxes related to the event_editor
1639
+	 *
1640
+	 * @return void
1641
+	 * @throws EE_Error
1642
+	 * @throws InvalidArgumentException
1643
+	 * @throws InvalidDataTypeException
1644
+	 * @throws InvalidInterfaceException
1645
+	 * @throws ReflectionException
1646
+	 */
1647
+	protected function _register_event_editor_meta_boxes()
1648
+	{
1649
+		$this->verify_cpt_object();
1650
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1651
+		/** @var FeatureFlags $flags */
1652
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1653
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1654
+		if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1655
+			add_meta_box(
1656
+				'espresso_event_editor_event_options',
1657
+				esc_html__('Event Registration Options', 'event_espresso'),
1658
+				[$this, 'registration_options_meta_box'],
1659
+				$this->page_slug,
1660
+				'side'
1661
+			);
1662
+		}
1663
+		if (! $use_advanced_editor) {
1664
+			add_meta_box(
1665
+				'espresso_event_editor_tickets',
1666
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1667
+				[$this, 'ticket_metabox'],
1668
+				$this->page_slug,
1669
+				'normal',
1670
+				'high'
1671
+			);
1672
+		} else {
1673
+			if ($flags->featureAllowed('use_reg_options_meta_box')) {
1674
+				add_action(
1675
+					'add_meta_boxes_espresso_events',
1676
+					function () {
1677
+						global $current_screen;
1678
+						remove_meta_box('authordiv', $current_screen, 'normal');
1679
+					},
1680
+					99
1681
+				);
1682
+			}
1683
+		}
1684
+		// NOTE: if you're looking for other metaboxes in here,
1685
+		// where a metabox has a related management page in the admin
1686
+		// you will find it setup in the related management page's "_Hooks" file.
1687
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1688
+	}
1689
+
1690
+
1691
+	/**
1692
+	 * @throws DomainException
1693
+	 * @throws EE_Error
1694
+	 * @throws InvalidArgumentException
1695
+	 * @throws InvalidDataTypeException
1696
+	 * @throws InvalidInterfaceException
1697
+	 * @throws ReflectionException
1698
+	 */
1699
+	public function ticket_metabox()
1700
+	{
1701
+		$existing_datetime_ids = $existing_ticket_ids = [];
1702
+		// defaults for template args
1703
+		$template_args = [
1704
+			'existing_datetime_ids'    => '',
1705
+			'event_datetime_help_link' => '',
1706
+			'ticket_options_help_link' => '',
1707
+			'time'                     => null,
1708
+			'ticket_rows'              => '',
1709
+			'existing_ticket_ids'      => '',
1710
+			'total_ticket_rows'        => 1,
1711
+			'ticket_js_structure'      => '',
1712
+			'trash_icon'               => 'ee-lock-icon',
1713
+			'disabled'                 => '',
1714
+		];
1715
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1716
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1717
+		/**
1718
+		 * 1. Start with retrieving Datetimes
1719
+		 * 2. Fore each datetime get related tickets
1720
+		 * 3. For each ticket get related prices
1721
+		 */
1722
+		/** @var EEM_Datetime $datetime_model */
1723
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1724
+		/** @var EEM_Ticket $datetime_model */
1725
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1726
+		$times        = $datetime_model->get_all_event_dates($event_id);
1727
+		/** @type EE_Datetime $first_datetime */
1728
+		$first_datetime = reset($times);
1729
+		// do we get related tickets?
1730
+		if (
1731
+			$first_datetime instanceof EE_Datetime
1732
+			&& $first_datetime->ID() !== 0
1733
+		) {
1734
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1735
+			$template_args['time']   = $first_datetime;
1736
+			$related_tickets         = $first_datetime->tickets(
1737
+				[
1738
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1739
+					'default_where_conditions' => 'none',
1740
+				]
1741
+			);
1742
+			if (! empty($related_tickets)) {
1743
+				$template_args['total_ticket_rows'] = count($related_tickets);
1744
+				$row                                = 0;
1745
+				foreach ($related_tickets as $ticket) {
1746
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1747
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1748
+					$row++;
1749
+				}
1750
+			} else {
1751
+				$template_args['total_ticket_rows'] = 1;
1752
+				/** @type EE_Ticket $ticket */
1753
+				$ticket                       = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1754
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1755
+			}
1756
+		} else {
1757
+			$template_args['time'] = $times[0];
1758
+			/** @type EE_Ticket[] $tickets */
1759
+			$tickets                      = $ticket_model->get_all_default_tickets();
1760
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1761
+			// NOTE: we're just sending the first default row
1762
+			// (decaf can't manage default tickets so this should be sufficient);
1763
+		}
1764
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1765
+			'event_editor_event_datetimes_help_tab'
1766
+		);
1767
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1768
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1769
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1770
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1771
+			$ticket_model->create_default_object(),
1772
+			true
1773
+		);
1774
+		$template                                  = apply_filters(
1775
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1776
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1777
+		);
1778
+		EEH_Template::display_template($template, $template_args);
1779
+	}
1780
+
1781
+
1782
+	/**
1783
+	 * Setup an individual ticket form for the decaf event editor page
1784
+	 *
1785
+	 * @access private
1786
+	 * @param EE_Ticket $ticket   the ticket object
1787
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1788
+	 * @param int       $row
1789
+	 * @return string generated html for the ticket row.
1790
+	 * @throws DomainException
1791
+	 * @throws EE_Error
1792
+	 * @throws InvalidArgumentException
1793
+	 * @throws InvalidDataTypeException
1794
+	 * @throws InvalidInterfaceException
1795
+	 * @throws ReflectionException
1796
+	 */
1797
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1798
+	{
1799
+		$template_args = [
1800
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1801
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1802
+				: '',
1803
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1804
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1805
+			'TKT_name'            => $ticket->get('TKT_name'),
1806
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1807
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1808
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1809
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1810
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1811
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1812
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1813
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1814
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1815
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1816
+				: ' disabled=disabled',
1817
+		];
1818
+		$price         = $ticket->ID() !== 0
1819
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1820
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1821
+		$price_args    = [
1822
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1823
+			'PRC_amount'            => $price->get('PRC_amount'),
1824
+			'PRT_ID'                => $price->get('PRT_ID'),
1825
+			'PRC_ID'                => $price->get('PRC_ID'),
1826
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1827
+		];
1828
+		// make sure we have default start and end dates if skeleton
1829
+		// handle rows that should NOT be empty
1830
+		if (empty($template_args['TKT_start_date'])) {
1831
+			// if empty then the start date will be now.
1832
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1833
+		}
1834
+		if (empty($template_args['TKT_end_date'])) {
1835
+			// get the earliest datetime (if present);
1836
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1837
+				? $this->_cpt_model_obj->get_first_related(
1838
+					'Datetime',
1839
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1840
+				)
1841
+				: null;
1842
+			if (! empty($earliest_dtt)) {
1843
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1844
+			} else {
1845
+				$template_args['TKT_end_date'] = date(
1846
+					'Y-m-d h:i a',
1847
+					mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1848
+				);
1849
+			}
1850
+		}
1851
+		$template_args = array_merge($template_args, $price_args);
1852
+		$template      = apply_filters(
1853
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1854
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1855
+			$ticket
1856
+		);
1857
+		return EEH_Template::display_template($template, $template_args, true);
1858
+	}
1859
+
1860
+
1861
+	/**
1862
+	 * @throws DomainException
1863
+	 * @throws EE_Error
1864
+	 */
1865
+	public function registration_options_meta_box()
1866
+	{
1867
+		$yes_no_values             = [
1868
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1869
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1870
+		];
1871
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1872
+			[
1873
+				EEM_Registration::status_id_cancelled,
1874
+				EEM_Registration::status_id_declined,
1875
+				EEM_Registration::status_id_incomplete,
1876
+			],
1877
+			true
1878
+		);
1879
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1880
+		$template_args['_event']                          = $this->_cpt_model_obj;
1881
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1882
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1883
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1884
+			'default_reg_status',
1885
+			$default_reg_status_values,
1886
+			$this->_cpt_model_obj->default_registration_status()
1887
+		);
1888
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1889
+			'display_desc',
1890
+			$yes_no_values,
1891
+			$this->_cpt_model_obj->display_description()
1892
+		);
1893
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1894
+			'display_ticket_selector',
1895
+			$yes_no_values,
1896
+			$this->_cpt_model_obj->display_ticket_selector(),
1897
+			'',
1898
+			'',
1899
+			false
1900
+		);
1901
+		$template_args['additional_registration_options'] = apply_filters(
1902
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1903
+			'',
1904
+			$template_args,
1905
+			$yes_no_values,
1906
+			$default_reg_status_values
1907
+		);
1908
+		EEH_Template::display_template(
1909
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1910
+			$template_args
1911
+		);
1912
+	}
1913
+
1914
+
1915
+	/**
1916
+	 * _get_events()
1917
+	 * This method simply returns all the events (for the given _view and paging)
1918
+	 *
1919
+	 * @access public
1920
+	 * @param int  $per_page     count of items per page (20 default);
1921
+	 * @param int  $current_page what is the current page being viewed.
1922
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1923
+	 *                           If FALSE then we return an array of event objects
1924
+	 *                           that match the given _view and paging parameters.
1925
+	 * @return array|int an array of event objects.
1926
+	 * @throws EE_Error
1927
+	 * @throws InvalidArgumentException
1928
+	 * @throws InvalidDataTypeException
1929
+	 * @throws InvalidInterfaceException
1930
+	 * @throws ReflectionException
1931
+	 * @throws Exception
1932
+	 * @throws Exception
1933
+	 * @throws Exception
1934
+	 */
1935
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1936
+	{
1937
+		$EEME    = $this->_event_model();
1938
+		$offset  = ($current_page - 1) * $per_page;
1939
+		$limit   = $count ? null : $offset . ',' . $per_page;
1940
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1941
+		$order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1942
+		$month_r = '';
1943
+		$year_r  = '';
1944
+		if (isset($this->_req_data['month_range'])) {
1945
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1946
+			// simulate the FIRST day of the month, that fixes issues for months like February
1947
+			// where PHP doesn't know what to assume for date.
1948
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1949
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1950
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1951
+		}
1952
+		$where  = [];
1953
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1954
+		// determine what post_status our condition will have for the query.
1955
+		switch ($status) {
1956
+			case 'month':
1957
+			case 'today':
1958
+			case null:
1959
+			case 'all':
1960
+				break;
1961
+			case 'draft':
1962
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1963
+				break;
1964
+			default:
1965
+				$where['status'] = $status;
1966
+		}
1967
+		// categories?
1968
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1969
+			? $this->_req_data['EVT_CAT'] : null;
1970
+		if (! empty($category)) {
1971
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1972
+			$where['Term_Taxonomy.term_id']  = $category;
1973
+		}
1974
+		// date where conditions
1975
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1976
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1977
+			$DateTime = new DateTime(
1978
+				$year_r . '-' . $month_r . '-01 00:00:00',
1979
+				new DateTimeZone('UTC')
1980
+			);
1981
+			$start    = $DateTime->getTimestamp();
1982
+			// set the datetime to be the end of the month
1983
+			$DateTime->setDate(
1984
+				$year_r,
1985
+				$month_r,
1986
+				$DateTime->format('t')
1987
+			)->setTime(23, 59, 59);
1988
+			$end                             = $DateTime->getTimestamp();
1989
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1990
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1991
+			$DateTime                        =
1992
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1993
+			$start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1994
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1995
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1996
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1997
+			$now                             = date('Y-m-01');
1998
+			$DateTime                        =
1999
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
2000
+			$start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
2001
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
2002
+														->setTime(23, 59, 59)
2003
+														->format(implode(' ', $start_formats));
2004
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2005
+		}
2006
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2007
+			$where['EVT_wp_user'] = get_current_user_id();
2008
+		} elseif (
2009
+			! isset($where['status'])
2010
+			&& ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
2011
+		) {
2012
+			$where['OR'] = [
2013
+				'status*restrict_private' => ['!=', 'private'],
2014
+				'AND'                     => [
2015
+					'status*inclusive' => ['=', 'private'],
2016
+					'EVT_wp_user'      => get_current_user_id(),
2017
+				],
2018
+			];
2019
+		}
2020
+
2021
+		if (
2022
+			isset($this->_req_data['EVT_wp_user'])
2023
+			&& (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
2024
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2025
+		) {
2026
+			$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
2027
+		}
2028
+		// search query handling
2029
+		if (isset($this->_req_data['s'])) {
2030
+			$search_string = '%' . $this->_req_data['s'] . '%';
2031
+			$where['OR']   = [
2032
+				'EVT_name'       => ['LIKE', $search_string],
2033
+				'EVT_desc'       => ['LIKE', $search_string],
2034
+				'EVT_short_desc' => ['LIKE', $search_string],
2035
+			];
2036
+		}
2037
+		// filter events by venue.
2038
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2039
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2040
+		}
2041
+		$where        = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2042
+		$query_params = apply_filters(
2043
+			'FHEE__Events_Admin_Page__get_events__query_params',
2044
+			[
2045
+				$where,
2046
+				'limit'    => $limit,
2047
+				'order_by' => $orderby,
2048
+				'order'    => $order,
2049
+				'group_by' => 'EVT_ID',
2050
+			],
2051
+			$this->_req_data
2052
+		);
2053
+
2054
+		// let's first check if we have special requests coming in.
2055
+		if (isset($this->_req_data['active_status'])) {
2056
+			switch ($this->_req_data['active_status']) {
2057
+				case 'upcoming':
2058
+					return $EEME->get_upcoming_events($query_params, $count);
2059
+				case 'expired':
2060
+					return $EEME->get_expired_events($query_params, $count);
2061
+				case 'active':
2062
+					return $EEME->get_active_events($query_params, $count);
2063
+				case 'inactive':
2064
+					return $EEME->get_inactive_events($query_params, $count);
2065
+			}
2066
+		}
2067
+
2068
+		return $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params);
2069
+	}
2070
+
2071
+
2072
+	/**
2073
+	 * handling for WordPress CPT actions (trash, restore, delete)
2074
+	 *
2075
+	 * @param string $post_id
2076
+	 * @throws EE_Error
2077
+	 * @throws InvalidArgumentException
2078
+	 * @throws InvalidDataTypeException
2079
+	 * @throws InvalidInterfaceException
2080
+	 * @throws ReflectionException
2081
+	 */
2082
+	public function trash_cpt_item($post_id)
2083
+	{
2084
+		$this->_req_data['EVT_ID'] = $post_id;
2085
+		$this->_trash_or_restore_event('trash', false);
2086
+	}
2087
+
2088
+
2089
+	/**
2090
+	 * @param string $post_id
2091
+	 * @throws EE_Error
2092
+	 * @throws InvalidArgumentException
2093
+	 * @throws InvalidDataTypeException
2094
+	 * @throws InvalidInterfaceException
2095
+	 * @throws ReflectionException
2096
+	 */
2097
+	public function restore_cpt_item($post_id)
2098
+	{
2099
+		$this->_req_data['EVT_ID'] = $post_id;
2100
+		$this->_trash_or_restore_event('draft', false);
2101
+	}
2102
+
2103
+
2104
+	/**
2105
+	 * @param string $post_id
2106
+	 * @throws EE_Error
2107
+	 * @throws InvalidArgumentException
2108
+	 * @throws InvalidDataTypeException
2109
+	 * @throws InvalidInterfaceException
2110
+	 * @throws ReflectionException
2111
+	 */
2112
+	public function delete_cpt_item($post_id)
2113
+	{
2114
+		throw new EE_Error(
2115
+			esc_html__(
2116
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2117
+				'event_espresso'
2118
+			)
2119
+		);
2120
+		$this->_req_data['EVT_ID'] = $post_id;
2121
+		$this->_delete_event();
2122
+	}
2123
+
2124
+
2125
+	/**
2126
+	 * _trash_or_restore_event
2127
+	 *
2128
+	 * @access protected
2129
+	 * @param string $event_status
2130
+	 * @param bool   $redirect_after
2131
+	 * @throws EE_Error
2132
+	 * @throws InvalidArgumentException
2133
+	 * @throws InvalidDataTypeException
2134
+	 * @throws InvalidInterfaceException
2135
+	 * @throws ReflectionException
2136
+	 */
2137
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2138
+	{
2139
+		// determine the event id and set to array.
2140
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2141
+		// loop thru events
2142
+		if ($EVT_ID) {
2143
+			// clean status
2144
+			$event_status = sanitize_key($event_status);
2145
+			// grab status
2146
+			if (! empty($event_status)) {
2147
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2148
+			} else {
2149
+				$success = false;
2150
+				$msg     = esc_html__(
2151
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2152
+					'event_espresso'
2153
+				);
2154
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2155
+			}
2156
+		} else {
2157
+			$success = false;
2158
+			$msg     = esc_html__(
2159
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2160
+				'event_espresso'
2161
+			);
2162
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2163
+		}
2164
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2165
+		if ($redirect_after) {
2166
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2167
+		}
2168
+	}
2169
+
2170
+
2171
+	/**
2172
+	 * _trash_or_restore_events
2173
+	 *
2174
+	 * @access protected
2175
+	 * @param string $event_status
2176
+	 * @return void
2177
+	 * @throws EE_Error
2178
+	 * @throws InvalidArgumentException
2179
+	 * @throws InvalidDataTypeException
2180
+	 * @throws InvalidInterfaceException
2181
+	 * @throws ReflectionException
2182
+	 */
2183
+	protected function _trash_or_restore_events($event_status = 'trash')
2184
+	{
2185
+		// clean status
2186
+		$event_status = sanitize_key($event_status);
2187
+		// grab status
2188
+		if (! empty($event_status)) {
2189
+			$success = true;
2190
+			// determine the event id and set to array.
2191
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2192
+			// loop thru events
2193
+			foreach ($EVT_IDs as $EVT_ID) {
2194
+				if ($EVT_ID = absint($EVT_ID)) {
2195
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2196
+					$success = $results !== false ? $success : false;
2197
+				} else {
2198
+					$msg = sprintf(
2199
+						esc_html__(
2200
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2201
+							'event_espresso'
2202
+						),
2203
+						$EVT_ID
2204
+					);
2205
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2206
+					$success = false;
2207
+				}
2208
+			}
2209
+		} else {
2210
+			$success = false;
2211
+			$msg     = esc_html__(
2212
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2213
+				'event_espresso'
2214
+			);
2215
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2216
+		}
2217
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2218
+		$success = $success ? 2 : false;
2219
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2220
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2221
+	}
2222
+
2223
+
2224
+	/**
2225
+	 * _trash_or_restore_events
2226
+	 *
2227
+	 * @access  private
2228
+	 * @param int    $EVT_ID
2229
+	 * @param string $event_status
2230
+	 * @return bool
2231
+	 * @throws EE_Error
2232
+	 * @throws InvalidArgumentException
2233
+	 * @throws InvalidDataTypeException
2234
+	 * @throws InvalidInterfaceException
2235
+	 * @throws ReflectionException
2236
+	 */
2237
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2238
+	{
2239
+		// grab event id
2240
+		if (! $EVT_ID) {
2241
+			$msg = esc_html__(
2242
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2243
+				'event_espresso'
2244
+			);
2245
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2246
+			return false;
2247
+		}
2248
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2249
+		// clean status
2250
+		$event_status = sanitize_key($event_status);
2251
+		// grab status
2252
+		if (empty($event_status)) {
2253
+			$msg = esc_html__(
2254
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2255
+				'event_espresso'
2256
+			);
2257
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2258
+			return false;
2259
+		}
2260
+		// was event trashed or restored ?
2261
+		switch ($event_status) {
2262
+			case 'draft':
2263
+				$action = 'restored from the trash';
2264
+				$hook   = 'AHEE_event_restored_from_trash';
2265
+				break;
2266
+			case 'trash':
2267
+				$action = 'moved to the trash';
2268
+				$hook   = 'AHEE_event_moved_to_trash';
2269
+				break;
2270
+			default:
2271
+				$action = 'updated';
2272
+				$hook   = false;
2273
+		}
2274
+		// use class to change status
2275
+		$this->_cpt_model_obj->set_status($event_status);
2276
+		$success = $this->_cpt_model_obj->save();
2277
+		if ($success === false) {
2278
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2279
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2280
+			return false;
2281
+		}
2282
+		if ($hook) {
2283
+			do_action($hook);
2284
+		}
2285
+		return true;
2286
+	}
2287
+
2288
+
2289
+	/**
2290
+	 * @throws InvalidArgumentException
2291
+	 * @throws InvalidDataTypeException
2292
+	 * @throws InvalidInterfaceException
2293
+	 */
2294
+	protected function _delete_event()
2295
+	{
2296
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []);
2297
+	}
2298
+
2299
+
2300
+	/**
2301
+	 * Gets the tree traversal batch persister.
2302
+	 *
2303
+	 * @return NodeGroupDao
2304
+	 * @throws InvalidArgumentException
2305
+	 * @throws InvalidDataTypeException
2306
+	 * @throws InvalidInterfaceException
2307
+	 * @since 4.10.12.p
2308
+	 */
2309
+	protected function getModelObjNodeGroupPersister()
2310
+	{
2311
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2312
+			$this->model_obj_node_group_persister =
2313
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2314
+		}
2315
+		return $this->model_obj_node_group_persister;
2316
+	}
2317
+
2318
+
2319
+	/**
2320
+	 * @return void
2321
+	 * @throws InvalidArgumentException
2322
+	 * @throws InvalidDataTypeException
2323
+	 * @throws InvalidInterfaceException
2324
+	 */
2325
+	protected function _delete_events()
2326
+	{
2327
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []);
2328
+	}
2329
+
2330
+
2331
+	protected function generateDeletionPreview($event_ids)
2332
+	{
2333
+		$event_ids = (array) $event_ids;
2334
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2335
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2336
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2337
+			[
2338
+				'action'            => 'preview_deletion',
2339
+				'deletion_job_code' => $deletion_job_code,
2340
+			],
2341
+			$this->_admin_base_url
2342
+		);
2343
+		$event_ids         = array_map(
2344
+			'intval',
2345
+			$event_ids
2346
+		);
2347
+
2348
+		EEH_URL::safeRedirectAndExit(
2349
+			EE_Admin_Page::add_query_args_and_nonce(
2350
+				[
2351
+					'page'              => 'espresso_batch',
2352
+					'batch'             => EED_Batch::batch_job,
2353
+					'EVT_IDs'           => $event_ids,
2354
+					'deletion_job_code' => $deletion_job_code,
2355
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2356
+					'return_url'        => urlencode($return_url),
2357
+				],
2358
+				admin_url()
2359
+			)
2360
+		);
2361
+	}
2362
+
2363
+
2364
+	/**
2365
+	 * Checks for a POST submission
2366
+	 *
2367
+	 * @since 4.10.12.p
2368
+	 */
2369
+	protected function confirmDeletion()
2370
+	{
2371
+		$deletion_redirect_logic =
2372
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2373
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2374
+	}
2375
+
2376
+
2377
+	/**
2378
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2379
+	 *
2380
+	 * @throws EE_Error
2381
+	 * @since 4.10.12.p
2382
+	 */
2383
+	protected function previewDeletion()
2384
+	{
2385
+		$preview_deletion_logic =
2386
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2387
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2388
+		$this->display_admin_page_with_no_sidebar();
2389
+	}
2390
+
2391
+
2392
+	/**
2393
+	 * get total number of events
2394
+	 *
2395
+	 * @access public
2396
+	 * @return int
2397
+	 * @throws EE_Error
2398
+	 * @throws InvalidArgumentException
2399
+	 * @throws InvalidDataTypeException
2400
+	 * @throws InvalidInterfaceException
2401
+	 */
2402
+	public function total_events()
2403
+	{
2404
+		return EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2405
+	}
2406
+
2407
+
2408
+	/**
2409
+	 * get total number of draft events
2410
+	 *
2411
+	 * @access public
2412
+	 * @return int
2413
+	 * @throws EE_Error
2414
+	 * @throws InvalidArgumentException
2415
+	 * @throws InvalidDataTypeException
2416
+	 * @throws InvalidInterfaceException
2417
+	 */
2418
+	public function total_events_draft()
2419
+	{
2420
+		$where = [
2421
+			'status' => ['IN', ['draft', 'auto-draft']],
2422
+		];
2423
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2424
+	}
2425
+
2426
+
2427
+	/**
2428
+	 * get total number of trashed events
2429
+	 *
2430
+	 * @access public
2431
+	 * @return int
2432
+	 * @throws EE_Error
2433
+	 * @throws InvalidArgumentException
2434
+	 * @throws InvalidDataTypeException
2435
+	 * @throws InvalidInterfaceException
2436
+	 */
2437
+	public function total_trashed_events()
2438
+	{
2439
+		$where = [
2440
+			'status' => 'trash',
2441
+		];
2442
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2443
+	}
2444
+
2445
+
2446
+	/**
2447
+	 *    _default_event_settings
2448
+	 *    This generates the Default Settings Tab
2449
+	 *
2450
+	 * @return void
2451
+	 * @throws DomainException
2452
+	 * @throws EE_Error
2453
+	 * @throws InvalidArgumentException
2454
+	 * @throws InvalidDataTypeException
2455
+	 * @throws InvalidInterfaceException
2456
+	 */
2457
+	protected function _default_event_settings()
2458
+	{
2459
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2460
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2461
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2462
+		$this->display_admin_page_with_sidebar();
2463
+	}
2464
+
2465
+
2466
+	/**
2467
+	 * Return the form for event settings.
2468
+	 *
2469
+	 * @return EE_Form_Section_Proper
2470
+	 * @throws EE_Error
2471
+	 */
2472
+	protected function _default_event_settings_form()
2473
+	{
2474
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2475
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2476
+		// exclude
2477
+			[
2478
+				EEM_Registration::status_id_cancelled,
2479
+				EEM_Registration::status_id_declined,
2480
+				EEM_Registration::status_id_incomplete,
2481
+				EEM_Registration::status_id_wait_list,
2482
+			],
2483
+			true
2484
+		);
2485
+		return new EE_Form_Section_Proper(
2486
+			[
2487
+				'name'            => 'update_default_event_settings',
2488
+				'html_id'         => 'update_default_event_settings',
2489
+				'html_class'      => 'form-table',
2490
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2491
+				'subsections'     => apply_filters(
2492
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2493
+					[
2494
+						'default_reg_status'  => new EE_Select_Input(
2495
+							$registration_stati_for_selection,
2496
+							[
2497
+								'default'         => isset($registration_config->default_STS_ID)
2498
+													 && array_key_exists(
2499
+														 $registration_config->default_STS_ID,
2500
+														 $registration_stati_for_selection
2501
+													 )
2502
+									? sanitize_text_field($registration_config->default_STS_ID)
2503
+									: EEM_Registration::status_id_pending_payment,
2504
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2505
+													 . EEH_Template::get_help_tab_link(
2506
+														 'default_settings_status_help_tab'
2507
+													 ),
2508
+								'html_help_text'  => esc_html__(
2509
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2510
+									'event_espresso'
2511
+								),
2512
+							]
2513
+						),
2514
+						'default_max_tickets' => new EE_Integer_Input(
2515
+							[
2516
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2517
+									? $registration_config->default_maximum_number_of_tickets
2518
+									: EEM_Event::get_default_additional_limit(),
2519
+								'html_label_text' => esc_html__(
2520
+									'Default Maximum Tickets Allowed Per Order:',
2521
+									'event_espresso'
2522
+								)
2523
+								. EEH_Template::get_help_tab_link(
2524
+									'default_maximum_tickets_help_tab"'
2525
+								),
2526
+								'html_help_text'  => esc_html__(
2527
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2528
+									'event_espresso'
2529
+								),
2530
+							]
2531
+						),
2532
+					]
2533
+				),
2534
+			]
2535
+		);
2536
+	}
2537
+
2538
+
2539
+	/**
2540
+	 * @return void
2541
+	 * @throws EE_Error
2542
+	 * @throws InvalidArgumentException
2543
+	 * @throws InvalidDataTypeException
2544
+	 * @throws InvalidInterfaceException
2545
+	 */
2546
+	protected function _update_default_event_settings()
2547
+	{
2548
+		$form = $this->_default_event_settings_form();
2549
+		if ($form->was_submitted()) {
2550
+			$form->receive_form_submission();
2551
+			if ($form->is_valid()) {
2552
+				$registration_config = EE_Registry::instance()->CFG->registration;
2553
+				$valid_data          = $form->valid_data();
2554
+				if (isset($valid_data['default_reg_status'])) {
2555
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2556
+				}
2557
+				if (isset($valid_data['default_max_tickets'])) {
2558
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2559
+				}
2560
+				do_action(
2561
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2562
+					$valid_data,
2563
+					EE_Registry::instance()->CFG,
2564
+					$this
2565
+				);
2566
+				// update because data was valid!
2567
+				EE_Registry::instance()->CFG->update_espresso_config();
2568
+				EE_Error::overwrite_success();
2569
+				EE_Error::add_success(
2570
+					__('Default Event Settings were updated', 'event_espresso')
2571
+				);
2572
+			}
2573
+		}
2574
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2575
+	}
2576
+
2577
+
2578
+	/*************        Templates        *************
2887 2579
      *
2888 2580
      * @throws EE_Error
2889
-     * @throws InvalidArgumentException
2890
-     * @throws InvalidDataTypeException
2891
-     * @throws InvalidInterfaceException
2892 2581
      */
2893
-    public function save_timezonestring_setting()
2894
-    {
2895
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2896
-            ? $this->_req_data['timezone_selected']
2897
-            : '';
2898
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2899
-            EE_Error::add_error(
2900
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2901
-                __FILE__,
2902
-                __FUNCTION__,
2903
-                __LINE__
2904
-            );
2905
-            $this->_template_args['error'] = true;
2906
-            $this->_return_json();
2907
-        }
2908
-
2909
-        update_option('timezone_string', $timezone_string);
2910
-        EE_Error::add_success(
2911
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2912
-        );
2913
-        $this->_template_args['success'] = true;
2914
-        $this->_return_json(true, ['action' => 'create_new']);
2915
-    }
2582
+	protected function _template_settings()
2583
+	{
2584
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2585
+		$this->_template_args['preview_img']  = '<img src="'
2586
+												. EVENTS_ASSETS_URL
2587
+												. '/images/'
2588
+												. 'caffeinated_template_features.jpg" alt="'
2589
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2590
+												. '" />';
2591
+		$this->_template_args['preview_text'] = '<strong>'
2592
+												. esc_html__(
2593
+													'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2594
+													'event_espresso'
2595
+												) . '</strong>';
2596
+		$this->display_admin_caf_preview_page('template_settings_tab');
2597
+	}
2598
+
2599
+
2600
+	/** Event Category Stuff **/
2601
+	/**
2602
+	 * set the _category property with the category object for the loaded page.
2603
+	 *
2604
+	 * @access private
2605
+	 * @return void
2606
+	 */
2607
+	private function _set_category_object()
2608
+	{
2609
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2610
+			return;
2611
+		} //already have the category object so get out.
2612
+		// set default category object
2613
+		$this->_set_empty_category_object();
2614
+		// only set if we've got an id
2615
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2616
+			return;
2617
+		}
2618
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2619
+		$term        = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2620
+		if (! empty($term)) {
2621
+			$this->_category->category_name       = $term->name;
2622
+			$this->_category->category_identifier = $term->slug;
2623
+			$this->_category->category_desc       = $term->description;
2624
+			$this->_category->id                  = $term->term_id;
2625
+			$this->_category->parent              = $term->parent;
2626
+		}
2627
+	}
2628
+
2629
+
2630
+	/**
2631
+	 * Clears out category properties.
2632
+	 */
2633
+	private function _set_empty_category_object()
2634
+	{
2635
+		$this->_category                = new stdClass();
2636
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2637
+		$this->_category->id            = $this->_category->parent = 0;
2638
+	}
2639
+
2640
+
2641
+	/**
2642
+	 * @throws DomainException
2643
+	 * @throws EE_Error
2644
+	 * @throws InvalidArgumentException
2645
+	 * @throws InvalidDataTypeException
2646
+	 * @throws InvalidInterfaceException
2647
+	 */
2648
+	protected function _category_list_table()
2649
+	{
2650
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2651
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2652
+		$this->_admin_page_title .= ' ';
2653
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2654
+			'add_category',
2655
+			'add_category',
2656
+			[],
2657
+			'add-new-h2'
2658
+		);
2659
+		$this->display_admin_list_table_page_with_sidebar();
2660
+	}
2661
+
2662
+
2663
+	/**
2664
+	 * Output category details view.
2665
+	 *
2666
+	 * @param string $view
2667
+	 * @throws DomainException
2668
+	 * @throws EE_Error
2669
+	 * @throws InvalidArgumentException
2670
+	 * @throws InvalidDataTypeException
2671
+	 * @throws InvalidInterfaceException
2672
+	 */
2673
+	protected function _category_details($view)
2674
+	{
2675
+		// load formatter helper
2676
+		// load field generator helper
2677
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2678
+		$this->_set_add_edit_form_tags($route);
2679
+		$this->_set_category_object();
2680
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2681
+		$delete_action = 'delete_category';
2682
+		// custom redirect
2683
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2684
+			['action' => 'category_list'],
2685
+			$this->_admin_base_url
2686
+		);
2687
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2688
+		// take care of contents
2689
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2690
+		$this->display_admin_page_with_sidebar();
2691
+	}
2692
+
2693
+
2694
+	/**
2695
+	 * Output category details content.
2696
+	 *
2697
+	 * @throws DomainException
2698
+	 */
2699
+	protected function _category_details_content()
2700
+	{
2701
+		$editor_args['category_desc'] = [
2702
+			'type'          => 'wp_editor',
2703
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2704
+			'class'         => 'my_editor_custom',
2705
+			'wpeditor_args' => ['media_buttons' => false],
2706
+		];
2707
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2708
+		$all_terms                    = get_terms(
2709
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2710
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2711
+		);
2712
+		// setup category select for term parents.
2713
+		$category_select_values[] = [
2714
+			'text' => esc_html__('No Parent', 'event_espresso'),
2715
+			'id'   => 0,
2716
+		];
2717
+		foreach ($all_terms as $term) {
2718
+			$category_select_values[] = [
2719
+				'text' => $term->name,
2720
+				'id'   => $term->term_id,
2721
+			];
2722
+		}
2723
+		$category_select = EEH_Form_Fields::select_input(
2724
+			'category_parent',
2725
+			$category_select_values,
2726
+			$this->_category->parent
2727
+		);
2728
+		$template_args   = [
2729
+			'category'                 => $this->_category,
2730
+			'category_select'          => $category_select,
2731
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2732
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2733
+			'disable'                  => '',
2734
+			'disabled_message'         => false,
2735
+		];
2736
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2737
+		return EEH_Template::display_template($template, $template_args, true);
2738
+	}
2739
+
2740
+
2741
+	/**
2742
+	 * Handles deleting categories.
2743
+	 *
2744
+	 * @throws EE_Error
2745
+	 */
2746
+	protected function _delete_categories()
2747
+	{
2748
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2749
+			: (array) $this->_req_data['category_id'];
2750
+		foreach ($cat_ids as $cat_id) {
2751
+			$this->_delete_category($cat_id);
2752
+		}
2753
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2754
+		$query_args = [
2755
+			'action' => 'category_list',
2756
+		];
2757
+		$this->_redirect_after_action(0, '', '', $query_args);
2758
+	}
2759
+
2760
+
2761
+	/**
2762
+	 * Handles deleting specific category.
2763
+	 *
2764
+	 * @param int $cat_id
2765
+	 */
2766
+	protected function _delete_category($cat_id)
2767
+	{
2768
+		$cat_id = absint($cat_id);
2769
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2770
+	}
2771
+
2772
+
2773
+	/**
2774
+	 * Handles triggering the update or insertion of a new category.
2775
+	 *
2776
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2777
+	 * @throws EE_Error
2778
+	 * @throws InvalidArgumentException
2779
+	 * @throws InvalidDataTypeException
2780
+	 * @throws InvalidInterfaceException
2781
+	 */
2782
+	protected function _insert_or_update_category($new_category)
2783
+	{
2784
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2785
+		$success = 0; // we already have a success message so lets not send another.
2786
+		if ($cat_id) {
2787
+			$query_args = [
2788
+				'action'     => 'edit_category',
2789
+				'EVT_CAT_ID' => $cat_id,
2790
+			];
2791
+		} else {
2792
+			$query_args = ['action' => 'add_category'];
2793
+		}
2794
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2795
+	}
2796
+
2797
+
2798
+	/**
2799
+	 * Inserts or updates category
2800
+	 *
2801
+	 * @param bool $update (true indicates we're updating a category).
2802
+	 * @return bool|mixed|string
2803
+	 */
2804
+	private function _insert_category($update = false)
2805
+	{
2806
+		$cat_id          = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2807
+		$category_name   = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2808
+		$category_desc   = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2809
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2810
+		if (empty($category_name)) {
2811
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2812
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2813
+			return false;
2814
+		}
2815
+		$term_args = [
2816
+			'name'        => $category_name,
2817
+			'description' => $category_desc,
2818
+			'parent'      => $category_parent,
2819
+		];
2820
+		// was the category_identifier input disabled?
2821
+		if (isset($this->_req_data['category_identifier'])) {
2822
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2823
+		}
2824
+		$insert_ids = $update
2825
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2826
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2827
+		if (! is_array($insert_ids)) {
2828
+			$msg = esc_html__(
2829
+				'An error occurred and the category has not been saved to the database.',
2830
+				'event_espresso'
2831
+			);
2832
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2833
+		} else {
2834
+			$cat_id = $insert_ids['term_id'];
2835
+			$msg    = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2836
+			EE_Error::add_success($msg);
2837
+		}
2838
+		return $cat_id;
2839
+	}
2840
+
2841
+
2842
+	/**
2843
+	 * Gets categories or count of categories matching the arguments in the request.
2844
+	 *
2845
+	 * @param int  $per_page
2846
+	 * @param int  $current_page
2847
+	 * @param bool $count
2848
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2849
+	 * @throws EE_Error
2850
+	 * @throws InvalidArgumentException
2851
+	 * @throws InvalidDataTypeException
2852
+	 * @throws InvalidInterfaceException
2853
+	 */
2854
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2855
+	{
2856
+		// testing term stuff
2857
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2858
+		$order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2859
+		$limit   = ($current_page - 1) * $per_page;
2860
+		$where   = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2861
+		if (isset($this->_req_data['s'])) {
2862
+			$sstr        = '%' . $this->_req_data['s'] . '%';
2863
+			$where['OR'] = [
2864
+				'Term.name'   => ['LIKE', $sstr],
2865
+				'description' => ['LIKE', $sstr],
2866
+			];
2867
+		}
2868
+		$query_params = [
2869
+			$where,
2870
+			'order_by'   => [$orderby => $order],
2871
+			'limit'      => $limit . ',' . $per_page,
2872
+			'force_join' => ['Term'],
2873
+		];
2874
+		return $count
2875
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2876
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2877
+	}
2878
+
2879
+	/* end category stuff */
2880
+
2881
+
2882
+	/**************/
2883
+
2884
+
2885
+	/**
2886
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2887
+	 *
2888
+	 * @throws EE_Error
2889
+	 * @throws InvalidArgumentException
2890
+	 * @throws InvalidDataTypeException
2891
+	 * @throws InvalidInterfaceException
2892
+	 */
2893
+	public function save_timezonestring_setting()
2894
+	{
2895
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2896
+			? $this->_req_data['timezone_selected']
2897
+			: '';
2898
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2899
+			EE_Error::add_error(
2900
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2901
+				__FILE__,
2902
+				__FUNCTION__,
2903
+				__LINE__
2904
+			);
2905
+			$this->_template_args['error'] = true;
2906
+			$this->_return_json();
2907
+		}
2908
+
2909
+		update_option('timezone_string', $timezone_string);
2910
+		EE_Error::add_success(
2911
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2912
+		);
2913
+		$this->_template_args['success'] = true;
2914
+		$this->_return_json(true, ['action' => 'create_new']);
2915
+	}
2916 2916
 }
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
         ];
536 536
         // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
537 537
         $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
538
-        if (! $domain->isCaffeinated()) {
538
+        if ( ! $domain->isCaffeinated()) {
539 539
             $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
540 540
             $this->_page_config['edit']['qtips']       = ['EE_Event_Editor_Decaf_Tips'];
541 541
         }
@@ -594,13 +594,13 @@  discard block
 block discarded – undo
594 594
     {
595 595
         wp_register_style(
596 596
             'events-admin-css',
597
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
597
+            EVENTS_ASSETS_URL.'events-admin-page.css',
598 598
             [],
599 599
             EVENT_ESPRESSO_VERSION
600 600
         );
601 601
         wp_register_style(
602 602
             'ee-cat-admin',
603
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
603
+            EVENTS_ASSETS_URL.'ee-cat-admin.css',
604 604
             [],
605 605
             EVENT_ESPRESSO_VERSION
606 606
         );
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
         // scripts
610 610
         wp_register_script(
611 611
             'event_editor_js',
612
-            EVENTS_ASSETS_URL . 'event_editor.js',
612
+            EVENTS_ASSETS_URL.'event_editor.js',
613 613
             ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
614 614
             EVENT_ESPRESSO_VERSION,
615 615
             true
@@ -635,16 +635,16 @@  discard block
 block discarded – undo
635 635
         wp_enqueue_style('espresso-ui-theme');
636 636
         wp_register_style(
637 637
             'event-editor-css',
638
-            EVENTS_ASSETS_URL . 'event-editor.css',
638
+            EVENTS_ASSETS_URL.'event-editor.css',
639 639
             ['ee-admin-css'],
640 640
             EVENT_ESPRESSO_VERSION
641 641
         );
642 642
         wp_enqueue_style('event-editor-css');
643 643
         // scripts
644
-        if (! $this->admin_config->useAdvancedEditor()) {
644
+        if ( ! $this->admin_config->useAdvancedEditor()) {
645 645
             wp_register_script(
646 646
                 'event-datetime-metabox',
647
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
647
+                EVENTS_ASSETS_URL.'event-datetime-metabox.js',
648 648
                 ['event_editor_js', 'ee-datepicker'],
649 649
                 EVENT_ESPRESSO_VERSION
650 650
             );
@@ -714,15 +714,15 @@  discard block
 block discarded – undo
714 714
     public function verify_event_edit($event = null, $req_type = '')
715 715
     {
716 716
         // don't need to do this when processing
717
-        if (! empty($req_type)) {
717
+        if ( ! empty($req_type)) {
718 718
             return;
719 719
         }
720 720
         // no event?
721
-        if (! $event instanceof EE_Event) {
721
+        if ( ! $event instanceof EE_Event) {
722 722
             $event = $this->_cpt_model_obj;
723 723
         }
724 724
         // STILL no event?
725
-        if (! $event instanceof EE_Event) {
725
+        if ( ! $event instanceof EE_Event) {
726 726
             return;
727 727
         }
728 728
         $orig_status = $event->status();
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
             );
763 763
         }
764 764
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
765
-        if (! $event->tickets_on_sale()) {
765
+        if ( ! $event->tickets_on_sale()) {
766 766
             return;
767 767
         }
768 768
         // made it here so show warning
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
     {
811 811
         $has_timezone_string = get_option('timezone_string');
812 812
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
813
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
813
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
814 814
             EE_Error::add_attention(
815 815
                 sprintf(
816 816
                     __(
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
      */
878 878
     protected function _event_legend_items()
879 879
     {
880
-        $items    = [
880
+        $items = [
881 881
             'view_details'   => [
882 882
                 'class' => 'dashicons dashicons-search',
883 883
                 'desc'  => esc_html__('View Event', 'event_espresso'),
@@ -894,31 +894,31 @@  discard block
 block discarded – undo
894 894
         $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
895 895
         $statuses = [
896 896
             'sold_out_status'  => [
897
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
897
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
898 898
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
899 899
             ],
900 900
             'active_status'    => [
901
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
901
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
902 902
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
903 903
             ],
904 904
             'upcoming_status'  => [
905
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
905
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
906 906
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
907 907
             ],
908 908
             'postponed_status' => [
909
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
909
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
910 910
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
911 911
             ],
912 912
             'cancelled_status' => [
913
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
913
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
914 914
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
915 915
             ],
916 916
             'expired_status'   => [
917
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
917
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
918 918
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
919 919
             ],
920 920
             'inactive_status'  => [
921
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
921
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
922 922
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
923 923
             ],
924 924
         ];
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
      */
938 938
     private function _event_model()
939 939
     {
940
-        if (! $this->_event_model instanceof EEM_Event) {
940
+        if ( ! $this->_event_model instanceof EEM_Event) {
941 941
             $this->_event_model = EE_Registry::instance()->load_model('Event');
942 942
         }
943 943
         return $this->_event_model;
@@ -957,8 +957,8 @@  discard block
 block discarded – undo
957 957
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
958 958
     {
959 959
         // make sure this is only when editing
960
-        if (! empty($id)) {
961
-            $post   = get_post($id);
960
+        if ( ! empty($id)) {
961
+            $post = get_post($id);
962 962
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
963 963
                        . esc_html__('Shortcode', 'event_espresso')
964 964
                        . '</a> ';
@@ -993,13 +993,13 @@  discard block
 block discarded – undo
993 993
             'button'
994 994
         );
995 995
         $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
996
-        $this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
996
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
997 997
             'create_new',
998 998
             'add',
999 999
             [],
1000 1000
             'add-new-h2'
1001 1001
         );
1002
-        $this->_template_args['after_list_table']   = array_merge(
1002
+        $this->_template_args['after_list_table'] = array_merge(
1003 1003
             (array) $this->_template_args['after_list_table'],
1004 1004
             $after_list_table
1005 1005
         );
@@ -1060,12 +1060,12 @@  discard block
 block discarded – undo
1060 1060
         /** @var FeatureFlags $flags */
1061 1061
         $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1062 1062
         // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1063
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1064
-            $event_values['EVT_display_ticket_selector']     =
1063
+        if ( ! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1064
+            $event_values['EVT_display_ticket_selector'] =
1065 1065
                 ! empty($this->_req_data['display_ticket_selector'])
1066 1066
                     ? 1
1067 1067
                     : 0;
1068
-            $event_values['EVT_additional_limit']            = min(
1068
+            $event_values['EVT_additional_limit'] = min(
1069 1069
                 apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1070 1070
                 ! empty($this->_req_data['additional_limit'])
1071 1071
                     ? absint($this->_req_data['additional_limit'])
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
                 'status*1' => $this->_req_data['original_post_status'],
1098 1098
             ],
1099 1099
         ];
1100
-        $event         = $this->_event_model()->get_one([$get_one_where]);
1100
+        $event = $this->_event_model()->get_one([$get_one_where]);
1101 1101
         // the following are default callbacks for event attachment updates
1102 1102
         // that can be overridden by caffeinated functionality and/or addons.
1103 1103
         $event_update_callbacks = apply_filters(
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
                 [$this, '_default_tickets_update'],
1108 1108
             ]
1109 1109
         );
1110
-        $att_success            = true;
1110
+        $att_success = true;
1111 1111
         foreach ($event_update_callbacks as $e_callback) {
1112 1112
             $_success = is_callable($e_callback)
1113 1113
                 ? $e_callback($event, $this->_req_data)
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
      */
1175 1175
     protected function _default_venue_update(EE_Event $evtobj, $data)
1176 1176
     {
1177
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1177
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1178 1178
         $venue_model = EE_Registry::instance()->load_model('Venue');
1179 1179
         $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1180 1180
         // very important.  If we don't have a venue name...
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
1204 1204
             'status'              => 'publish',
1205 1205
         ];
1206 1206
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1207
-        if (! empty($venue_id)) {
1207
+        if ( ! empty($venue_id)) {
1208 1208
             $update_where  = [$venue_model->primary_key_name() => $venue_id];
1209 1209
             $rows_affected = $venue_model->update($venue_array, [$update_where]);
1210 1210
             // we've gotta make sure that the venue is always attached to a revision..
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
             ];
1257 1257
             // if we have an id then let's get existing object first and then set the new values.
1258 1258
             //  Otherwise we instantiate a new object for save.
1259
-            if (! empty($dtt['DTT_ID'])) {
1259
+            if ( ! empty($dtt['DTT_ID'])) {
1260 1260
                 $DTM = EE_Registry::instance()
1261 1261
                                   ->load_model('Datetime', [$evtobj->get_timezone()])
1262 1262
                                   ->get_one_by_ID($dtt['DTT_ID']);
@@ -1267,7 +1267,7 @@  discard block
 block discarded – undo
1267 1267
                 }
1268 1268
                 // make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it.
1269 1269
                 // We need to do this so we dont' TRASH the parent DTT.
1270
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1270
+                $saved_dtts[$DTM->ID()] = $DTM;
1271 1271
             } else {
1272 1272
                 $DTM = EE_Registry::instance()->load_class(
1273 1273
                     'Datetime',
@@ -1302,15 +1302,15 @@  discard block
 block discarded – undo
1302 1302
         foreach ($data['edit_tickets'] as $row => $tkt) {
1303 1303
             $incoming_date_formats = ['Y-m-d', 'h:i a'];
1304 1304
             $update_prices         = false;
1305
-            $ticket_price          = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1306
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1305
+            $ticket_price          = isset($data['edit_prices'][$row][1]['PRC_amount'])
1306
+                ? $data['edit_prices'][$row][1]['PRC_amount']
1307 1307
                 : 0;
1308 1308
             // trim inputs to ensure any excess whitespace is removed.
1309 1309
             $tkt = array_map('trim', $tkt);
1310 1310
             if (empty($tkt['TKT_start_date'])) {
1311 1311
                 // let's use now in the set timezone.
1312 1312
                 $now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1313
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1313
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1314 1314
             }
1315 1315
             if (empty($tkt['TKT_end_date'])) {
1316 1316
                 // use the start date of the first datetime
@@ -1348,7 +1348,7 @@  discard block
 block discarded – undo
1348 1348
             // that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1349 1349
             // keep in mind that if the TKT has been sold (and we have changed pricing information),
1350 1350
             // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1351
-            if (! empty($tkt['TKT_ID'])) {
1351
+            if ( ! empty($tkt['TKT_ID'])) {
1352 1352
                 $TKT = EE_Registry::instance()
1353 1353
                                   ->load_model('Ticket', [$evtobj->get_timezone()])
1354 1354
                                   ->get_one_by_ID($tkt['TKT_ID']);
@@ -1392,7 +1392,7 @@  discard block
 block discarded – undo
1392 1392
                         $TKT->save();
1393 1393
                         // make sure this ticket is still recorded in our saved_tkts
1394 1394
                         // so we don't run it through the regular trash routine.
1395
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1395
+                        $saved_tickets[$TKT->ID()] = $TKT;
1396 1396
                         // create new ticket that's a copy of the existing except a new id of course
1397 1397
                         // (and not archived) AND has the new TKT_price associated with it.
1398 1398
                         $TKT = clone $TKT;
@@ -1439,9 +1439,9 @@  discard block
 block discarded – undo
1439 1439
             }
1440 1440
             // initially let's add the ticket to the dtt
1441 1441
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1442
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1442
+            $saved_tickets[$TKT->ID()] = $TKT;
1443 1443
             // add prices to ticket
1444
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1444
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1445 1445
         }
1446 1446
         // however now we need to handle permanently deleting tickets via the ui.
1447 1447
         //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
@@ -1546,13 +1546,13 @@  discard block
 block discarded – undo
1546 1546
     {
1547 1547
         // load formatter helper
1548 1548
         // args for getting related registrations
1549
-        $approved_query_args        = [
1549
+        $approved_query_args = [
1550 1550
             [
1551 1551
                 'REG_deleted' => 0,
1552 1552
                 'STS_ID'      => EEM_Registration::status_id_approved,
1553 1553
             ],
1554 1554
         ];
1555
-        $not_approved_query_args    = [
1555
+        $not_approved_query_args = [
1556 1556
             [
1557 1557
                 'REG_deleted' => 0,
1558 1558
                 'STS_ID'      => EEM_Registration::status_id_not_approved,
@@ -1615,7 +1615,7 @@  discard block
 block discarded – undo
1615 1615
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1616 1616
         // load template
1617 1617
         EEH_Template::display_template(
1618
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1618
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1619 1619
             $publish_box_extra_args
1620 1620
         );
1621 1621
     }
@@ -1651,7 +1651,7 @@  discard block
 block discarded – undo
1651 1651
         /** @var FeatureFlags $flags */
1652 1652
         $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1653 1653
         // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1654
-        if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1654
+        if ( ! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1655 1655
             add_meta_box(
1656 1656
                 'espresso_event_editor_event_options',
1657 1657
                 esc_html__('Event Registration Options', 'event_espresso'),
@@ -1660,7 +1660,7 @@  discard block
 block discarded – undo
1660 1660
                 'side'
1661 1661
             );
1662 1662
         }
1663
-        if (! $use_advanced_editor) {
1663
+        if ( ! $use_advanced_editor) {
1664 1664
             add_meta_box(
1665 1665
                 'espresso_event_editor_tickets',
1666 1666
                 esc_html__('Event Datetime & Ticket', 'event_espresso'),
@@ -1673,7 +1673,7 @@  discard block
 block discarded – undo
1673 1673
             if ($flags->featureAllowed('use_reg_options_meta_box')) {
1674 1674
                 add_action(
1675 1675
                     'add_meta_boxes_espresso_events',
1676
-                    function () {
1676
+                    function() {
1677 1677
                         global $current_screen;
1678 1678
                         remove_meta_box('authordiv', $current_screen, 'normal');
1679 1679
                     },
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
             'trash_icon'               => 'ee-lock-icon',
1713 1713
             'disabled'                 => '',
1714 1714
         ];
1715
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1715
+        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1716 1716
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1717 1717
         /**
1718 1718
          * 1. Start with retrieving Datetimes
@@ -1739,24 +1739,24 @@  discard block
 block discarded – undo
1739 1739
                     'default_where_conditions' => 'none',
1740 1740
                 ]
1741 1741
             );
1742
-            if (! empty($related_tickets)) {
1742
+            if ( ! empty($related_tickets)) {
1743 1743
                 $template_args['total_ticket_rows'] = count($related_tickets);
1744 1744
                 $row                                = 0;
1745 1745
                 foreach ($related_tickets as $ticket) {
1746
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1746
+                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1747 1747
                     $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1748 1748
                     $row++;
1749 1749
                 }
1750 1750
             } else {
1751 1751
                 $template_args['total_ticket_rows'] = 1;
1752 1752
                 /** @type EE_Ticket $ticket */
1753
-                $ticket                       = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1753
+                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1754 1754
                 $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1755 1755
             }
1756 1756
         } else {
1757 1757
             $template_args['time'] = $times[0];
1758 1758
             /** @type EE_Ticket[] $tickets */
1759
-            $tickets                      = $ticket_model->get_all_default_tickets();
1759
+            $tickets = $ticket_model->get_all_default_tickets();
1760 1760
             $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1761 1761
             // NOTE: we're just sending the first default row
1762 1762
             // (decaf can't manage default tickets so this should be sufficient);
@@ -1771,9 +1771,9 @@  discard block
 block discarded – undo
1771 1771
             $ticket_model->create_default_object(),
1772 1772
             true
1773 1773
         );
1774
-        $template                                  = apply_filters(
1774
+        $template = apply_filters(
1775 1775
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1776
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1776
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1777 1777
         );
1778 1778
         EEH_Template::display_template($template, $template_args);
1779 1779
     }
@@ -1797,7 +1797,7 @@  discard block
 block discarded – undo
1797 1797
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1798 1798
     {
1799 1799
         $template_args = [
1800
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1800
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1801 1801
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1802 1802
                 : '',
1803 1803
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1809,10 +1809,10 @@  discard block
 block discarded – undo
1809 1809
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1810 1810
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1811 1811
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1812
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1813
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1812
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1813
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1814 1814
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1815
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1815
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1816 1816
                 : ' disabled=disabled',
1817 1817
         ];
1818 1818
         $price         = $ticket->ID() !== 0
@@ -1839,7 +1839,7 @@  discard block
 block discarded – undo
1839 1839
                     ['order_by' => ['DTT_EVT_start' => 'ASC']]
1840 1840
                 )
1841 1841
                 : null;
1842
-            if (! empty($earliest_dtt)) {
1842
+            if ( ! empty($earliest_dtt)) {
1843 1843
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1844 1844
             } else {
1845 1845
                 $template_args['TKT_end_date'] = date(
@@ -1851,7 +1851,7 @@  discard block
 block discarded – undo
1851 1851
         $template_args = array_merge($template_args, $price_args);
1852 1852
         $template      = apply_filters(
1853 1853
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1854
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1854
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1855 1855
             $ticket
1856 1856
         );
1857 1857
         return EEH_Template::display_template($template, $template_args, true);
@@ -1864,7 +1864,7 @@  discard block
 block discarded – undo
1864 1864
      */
1865 1865
     public function registration_options_meta_box()
1866 1866
     {
1867
-        $yes_no_values             = [
1867
+        $yes_no_values = [
1868 1868
             ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1869 1869
             ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1870 1870
         ];
@@ -1885,12 +1885,12 @@  discard block
 block discarded – undo
1885 1885
             $default_reg_status_values,
1886 1886
             $this->_cpt_model_obj->default_registration_status()
1887 1887
         );
1888
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1888
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
1889 1889
             'display_desc',
1890 1890
             $yes_no_values,
1891 1891
             $this->_cpt_model_obj->display_description()
1892 1892
         );
1893
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1893
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1894 1894
             'display_ticket_selector',
1895 1895
             $yes_no_values,
1896 1896
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -1906,7 +1906,7 @@  discard block
 block discarded – undo
1906 1906
             $default_reg_status_values
1907 1907
         );
1908 1908
         EEH_Template::display_template(
1909
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1909
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1910 1910
             $template_args
1911 1911
         );
1912 1912
     }
@@ -1936,7 +1936,7 @@  discard block
 block discarded – undo
1936 1936
     {
1937 1937
         $EEME    = $this->_event_model();
1938 1938
         $offset  = ($current_page - 1) * $per_page;
1939
-        $limit   = $count ? null : $offset . ',' . $per_page;
1939
+        $limit   = $count ? null : $offset.','.$per_page;
1940 1940
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1941 1941
         $order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1942 1942
         $month_r = '';
@@ -1967,7 +1967,7 @@  discard block
 block discarded – undo
1967 1967
         // categories?
1968 1968
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1969 1969
             ? $this->_req_data['EVT_CAT'] : null;
1970
-        if (! empty($category)) {
1970
+        if ( ! empty($category)) {
1971 1971
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1972 1972
             $where['Term_Taxonomy.term_id']  = $category;
1973 1973
         }
@@ -1975,10 +1975,10 @@  discard block
 block discarded – undo
1975 1975
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1976 1976
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1977 1977
             $DateTime = new DateTime(
1978
-                $year_r . '-' . $month_r . '-01 00:00:00',
1978
+                $year_r.'-'.$month_r.'-01 00:00:00',
1979 1979
                 new DateTimeZone('UTC')
1980 1980
             );
1981
-            $start    = $DateTime->getTimestamp();
1981
+            $start = $DateTime->getTimestamp();
1982 1982
             // set the datetime to be the end of the month
1983 1983
             $DateTime->setDate(
1984 1984
                 $year_r,
@@ -2003,7 +2003,7 @@  discard block
 block discarded – undo
2003 2003
                                                         ->format(implode(' ', $start_formats));
2004 2004
             $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2005 2005
         }
2006
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2006
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2007 2007
             $where['EVT_wp_user'] = get_current_user_id();
2008 2008
         } elseif (
2009 2009
             ! isset($where['status'])
@@ -2027,7 +2027,7 @@  discard block
 block discarded – undo
2027 2027
         }
2028 2028
         // search query handling
2029 2029
         if (isset($this->_req_data['s'])) {
2030
-            $search_string = '%' . $this->_req_data['s'] . '%';
2030
+            $search_string = '%'.$this->_req_data['s'].'%';
2031 2031
             $where['OR']   = [
2032 2032
                 'EVT_name'       => ['LIKE', $search_string],
2033 2033
                 'EVT_desc'       => ['LIKE', $search_string],
@@ -2143,7 +2143,7 @@  discard block
 block discarded – undo
2143 2143
             // clean status
2144 2144
             $event_status = sanitize_key($event_status);
2145 2145
             // grab status
2146
-            if (! empty($event_status)) {
2146
+            if ( ! empty($event_status)) {
2147 2147
                 $success = $this->_change_event_status($EVT_ID, $event_status);
2148 2148
             } else {
2149 2149
                 $success = false;
@@ -2185,7 +2185,7 @@  discard block
 block discarded – undo
2185 2185
         // clean status
2186 2186
         $event_status = sanitize_key($event_status);
2187 2187
         // grab status
2188
-        if (! empty($event_status)) {
2188
+        if ( ! empty($event_status)) {
2189 2189
             $success = true;
2190 2190
             // determine the event id and set to array.
2191 2191
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
@@ -2237,7 +2237,7 @@  discard block
 block discarded – undo
2237 2237
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2238 2238
     {
2239 2239
         // grab event id
2240
-        if (! $EVT_ID) {
2240
+        if ( ! $EVT_ID) {
2241 2241
             $msg = esc_html__(
2242 2242
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2243 2243
                 'event_espresso'
@@ -2308,7 +2308,7 @@  discard block
 block discarded – undo
2308 2308
      */
2309 2309
     protected function getModelObjNodeGroupPersister()
2310 2310
     {
2311
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2311
+        if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2312 2312
             $this->model_obj_node_group_persister =
2313 2313
                 $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2314 2314
         }
@@ -2340,7 +2340,7 @@  discard block
 block discarded – undo
2340 2340
             ],
2341 2341
             $this->_admin_base_url
2342 2342
         );
2343
-        $event_ids         = array_map(
2343
+        $event_ids = array_map(
2344 2344
             'intval',
2345 2345
             $event_ids
2346 2346
         );
@@ -2592,7 +2592,7 @@  discard block
 block discarded – undo
2592 2592
                                                 . esc_html__(
2593 2593
                                                     'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2594 2594
                                                     'event_espresso'
2595
-                                                ) . '</strong>';
2595
+                                                ).'</strong>';
2596 2596
         $this->display_admin_caf_preview_page('template_settings_tab');
2597 2597
     }
2598 2598
 
@@ -2612,12 +2612,12 @@  discard block
 block discarded – undo
2612 2612
         // set default category object
2613 2613
         $this->_set_empty_category_object();
2614 2614
         // only set if we've got an id
2615
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2615
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2616 2616
             return;
2617 2617
         }
2618 2618
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2619 2619
         $term        = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2620
-        if (! empty($term)) {
2620
+        if ( ! empty($term)) {
2621 2621
             $this->_category->category_name       = $term->name;
2622 2622
             $this->_category->category_identifier = $term->slug;
2623 2623
             $this->_category->category_desc       = $term->description;
@@ -2725,7 +2725,7 @@  discard block
 block discarded – undo
2725 2725
             $category_select_values,
2726 2726
             $this->_category->parent
2727 2727
         );
2728
-        $template_args   = [
2728
+        $template_args = [
2729 2729
             'category'                 => $this->_category,
2730 2730
             'category_select'          => $category_select,
2731 2731
             'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
@@ -2733,7 +2733,7 @@  discard block
 block discarded – undo
2733 2733
             'disable'                  => '',
2734 2734
             'disabled_message'         => false,
2735 2735
         ];
2736
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2736
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2737 2737
         return EEH_Template::display_template($template, $template_args, true);
2738 2738
     }
2739 2739
 
@@ -2824,7 +2824,7 @@  discard block
 block discarded – undo
2824 2824
         $insert_ids = $update
2825 2825
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2826 2826
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2827
-        if (! is_array($insert_ids)) {
2827
+        if ( ! is_array($insert_ids)) {
2828 2828
             $msg = esc_html__(
2829 2829
                 'An error occurred and the category has not been saved to the database.',
2830 2830
                 'event_espresso'
@@ -2859,7 +2859,7 @@  discard block
 block discarded – undo
2859 2859
         $limit   = ($current_page - 1) * $per_page;
2860 2860
         $where   = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2861 2861
         if (isset($this->_req_data['s'])) {
2862
-            $sstr        = '%' . $this->_req_data['s'] . '%';
2862
+            $sstr        = '%'.$this->_req_data['s'].'%';
2863 2863
             $where['OR'] = [
2864 2864
                 'Term.name'   => ['LIKE', $sstr],
2865 2865
                 'description' => ['LIKE', $sstr],
@@ -2868,7 +2868,7 @@  discard block
 block discarded – undo
2868 2868
         $query_params = [
2869 2869
             $where,
2870 2870
             'order_by'   => [$orderby => $order],
2871
-            'limit'      => $limit . ',' . $per_page,
2871
+            'limit'      => $limit.','.$per_page,
2872 2872
             'force_join' => ['Term'],
2873 2873
         ];
2874 2874
         return $count
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Shortcode.lib.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -20,162 +20,162 @@
 block discarded – undo
20 20
 class EE_Register_Shortcode implements EEI_Plugin_API
21 21
 {
22 22
 
23
-    /**
24
-     * Holds values for registered shortcodes
25
-     *
26
-     * @var array
27
-     */
28
-    protected static $_settings = [];
23
+	/**
24
+	 * Holds values for registered shortcodes
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected static $_settings = [];
29 29
 
30 30
 
31
-    /**
32
-     *    Method for registering new EE_Shortcodes
33
-     *
34
-     * @param string $addon_name    a unique identifier for this set of modules Required.
35
-     * @param array  $setup_args    an array of arguments provided for registering shortcodes Required.
36
-     * @type array shortcode_paths  an array of full server paths to folders containing any EES_Shortcodes
37
-     * @type array shortcode_fqcns  an array of fully qualified class names for any new shortcode classes to register.
38
-     *                              Shortcode classes should extend EspressoShortcode
39
-     *                              and be properly namespaced so they are autoloaded.
40
-     * @return bool
41
-     * @throws EE_Error
42
-     * @since    4.3.0
43
-     * @since    4.9.46.rc.025  for the new `shortcode_fqcns` array argument.
44
-     */
45
-    public static function register(string $addon_name = '', array $setup_args = []): bool
46
-    {
47
-        // required fields MUST be present, so let's make sure they are.
48
-        if (
49
-            empty($addon_name)
50
-            || ! is_array($setup_args)
51
-            || (
52
-               empty($setup_args['shortcode_paths']))
53
-               && empty($setup_args['shortcode_fqcns'])
54
-        ) {
55
-            throw new EE_Error(
56
-                esc_html__(
57
-                    'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
58
-                    'event_espresso'
59
-                )
60
-            );
61
-        }
31
+	/**
32
+	 *    Method for registering new EE_Shortcodes
33
+	 *
34
+	 * @param string $addon_name    a unique identifier for this set of modules Required.
35
+	 * @param array  $setup_args    an array of arguments provided for registering shortcodes Required.
36
+	 * @type array shortcode_paths  an array of full server paths to folders containing any EES_Shortcodes
37
+	 * @type array shortcode_fqcns  an array of fully qualified class names for any new shortcode classes to register.
38
+	 *                              Shortcode classes should extend EspressoShortcode
39
+	 *                              and be properly namespaced so they are autoloaded.
40
+	 * @return bool
41
+	 * @throws EE_Error
42
+	 * @since    4.3.0
43
+	 * @since    4.9.46.rc.025  for the new `shortcode_fqcns` array argument.
44
+	 */
45
+	public static function register(string $addon_name = '', array $setup_args = []): bool
46
+	{
47
+		// required fields MUST be present, so let's make sure they are.
48
+		if (
49
+			empty($addon_name)
50
+			|| ! is_array($setup_args)
51
+			|| (
52
+			   empty($setup_args['shortcode_paths']))
53
+			   && empty($setup_args['shortcode_fqcns'])
54
+		) {
55
+			throw new EE_Error(
56
+				esc_html__(
57
+					'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
58
+					'event_espresso'
59
+				)
60
+			);
61
+		}
62 62
 
63
-        // make sure we don't register twice
64
-        if (isset(self::$_settings[ $addon_name ])) {
65
-            return true;
66
-        }
63
+		// make sure we don't register twice
64
+		if (isset(self::$_settings[ $addon_name ])) {
65
+			return true;
66
+		}
67 67
 
68
-        // make sure this was called in the right place!
69
-        if (
70
-            ! did_action('AHEE__EE_System__load_espresso_addons')
71
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
72
-        ) {
73
-            EE_Error::doing_it_wrong(
74
-                __METHOD__,
75
-                esc_html__(
76
-                    'An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
77
-                    'event_espresso'
78
-                ),
79
-                '4.3.0'
80
-            );
81
-        }
82
-        // setup $_settings array from incoming values.
83
-        self::$_settings[ $addon_name ] = [
84
-            // array of full server paths to any EES_Shortcodes used by the shortcode
85
-            'shortcode_paths' => isset($setup_args['shortcode_paths'])
86
-                ? (array) $setup_args['shortcode_paths']
87
-                : [],
88
-            'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
89
-                ? (array) $setup_args['shortcode_fqcns']
90
-                : [],
91
-        ];
92
-        // add to list of shortcodes to be registered
93
-        add_filter(
94
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
95
-            ['EE_Register_Shortcode', 'add_shortcodes']
96
-        );
68
+		// make sure this was called in the right place!
69
+		if (
70
+			! did_action('AHEE__EE_System__load_espresso_addons')
71
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
72
+		) {
73
+			EE_Error::doing_it_wrong(
74
+				__METHOD__,
75
+				esc_html__(
76
+					'An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
77
+					'event_espresso'
78
+				),
79
+				'4.3.0'
80
+			);
81
+		}
82
+		// setup $_settings array from incoming values.
83
+		self::$_settings[ $addon_name ] = [
84
+			// array of full server paths to any EES_Shortcodes used by the shortcode
85
+			'shortcode_paths' => isset($setup_args['shortcode_paths'])
86
+				? (array) $setup_args['shortcode_paths']
87
+				: [],
88
+			'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
89
+				? (array) $setup_args['shortcode_fqcns']
90
+				: [],
91
+		];
92
+		// add to list of shortcodes to be registered
93
+		add_filter(
94
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
95
+			['EE_Register_Shortcode', 'add_shortcodes']
96
+		);
97 97
 
98
-        add_filter(
99
-            'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
100
-            ['EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection']
101
-        );
102
-        return true;
103
-    }
98
+		add_filter(
99
+			'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
100
+			['EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection']
101
+		);
102
+		return true;
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * Filters the list of shortcodes to add ours.
108
-     * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
109
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
110
-     *
111
-     * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
112
-     * @return array
113
-     */
114
-    public static function add_shortcodes(array $shortcodes_to_register): array
115
-    {
116
-        $shortcode_paths = [];
117
-        foreach (self::$_settings as $settings) {
118
-            $shortcode_paths[] = $settings['shortcode_paths'];
119
-        }
120
-        return array_merge($shortcodes_to_register, ...$shortcode_paths);
121
-    }
106
+	/**
107
+	 * Filters the list of shortcodes to add ours.
108
+	 * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
109
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
110
+	 *
111
+	 * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
112
+	 * @return array
113
+	 */
114
+	public static function add_shortcodes(array $shortcodes_to_register): array
115
+	{
116
+		$shortcode_paths = [];
117
+		foreach (self::$_settings as $settings) {
118
+			$shortcode_paths[] = $settings['shortcode_paths'];
119
+		}
120
+		return array_merge($shortcodes_to_register, ...$shortcode_paths);
121
+	}
122 122
 
123 123
 
124
-    /**
125
-     * Hooks into
126
-     * FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection and
127
-     * registers any provided shortcode fully qualified class names.
128
-     *
129
-     * @param CollectionInterface $shortcodes_collection
130
-     * @return CollectionInterface
131
-     * @throws InvalidArgumentException
132
-     * @throws InvalidClassException
133
-     * @throws InvalidDataTypeException
134
-     * @throws InvalidInterfaceException
135
-     */
136
-    public static function instantiateAndAddToShortcodeCollection(
137
-        CollectionInterface $shortcodes_collection
138
-    ): CollectionInterface {
139
-        foreach (self::$_settings as $settings) {
140
-            if (! empty($settings['shortcode_fqcns'])) {
141
-                foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
142
-                    if (! class_exists($shortcode_fqcn)) {
143
-                        throw new InvalidClassException(
144
-                            sprintf(
145
-                                esc_html__(
146
-                                    'Are you sure %s is the right fully qualified class name for the shortcode class?',
147
-                                    'event_espresso'
148
-                                ),
149
-                                $shortcode_fqcn
150
-                            )
151
-                        );
152
-                    }
153
-                    if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
154
-                        // register dependencies
155
-                        EE_Dependency_Map::register_dependencies(
156
-                            $shortcode_fqcn,
157
-                            [
158
-                                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
159
-                            ]
160
-                        );
161
-                    }
162
-                    $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn));
163
-                }
164
-            }
165
-        }
166
-        return $shortcodes_collection;
167
-    }
124
+	/**
125
+	 * Hooks into
126
+	 * FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection and
127
+	 * registers any provided shortcode fully qualified class names.
128
+	 *
129
+	 * @param CollectionInterface $shortcodes_collection
130
+	 * @return CollectionInterface
131
+	 * @throws InvalidArgumentException
132
+	 * @throws InvalidClassException
133
+	 * @throws InvalidDataTypeException
134
+	 * @throws InvalidInterfaceException
135
+	 */
136
+	public static function instantiateAndAddToShortcodeCollection(
137
+		CollectionInterface $shortcodes_collection
138
+	): CollectionInterface {
139
+		foreach (self::$_settings as $settings) {
140
+			if (! empty($settings['shortcode_fqcns'])) {
141
+				foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
142
+					if (! class_exists($shortcode_fqcn)) {
143
+						throw new InvalidClassException(
144
+							sprintf(
145
+								esc_html__(
146
+									'Are you sure %s is the right fully qualified class name for the shortcode class?',
147
+									'event_espresso'
148
+								),
149
+								$shortcode_fqcn
150
+							)
151
+						);
152
+					}
153
+					if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
154
+						// register dependencies
155
+						EE_Dependency_Map::register_dependencies(
156
+							$shortcode_fqcn,
157
+							[
158
+								'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
159
+							]
160
+						);
161
+					}
162
+					$shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn));
163
+				}
164
+			}
165
+		}
166
+		return $shortcodes_collection;
167
+	}
168 168
 
169 169
 
170
-    /**
171
-     * This deregisters a shortcode that was previously registered with a specific $addon_name.
172
-     *
173
-     * @param string $addon_name the name for the shortcode that was previously registered
174
-     * @return void
175
-     * @since    4.3.0
176
-     */
177
-    public static function deregister(string $addon_name = '')
178
-    {
179
-        unset(self::$_settings[ $addon_name ]);
180
-    }
170
+	/**
171
+	 * This deregisters a shortcode that was previously registered with a specific $addon_name.
172
+	 *
173
+	 * @param string $addon_name the name for the shortcode that was previously registered
174
+	 * @return void
175
+	 * @since    4.3.0
176
+	 */
177
+	public static function deregister(string $addon_name = '')
178
+	{
179
+		unset(self::$_settings[ $addon_name ]);
180
+	}
181 181
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Message_Type.lib.php 2 patches
Indentation   +449 added lines, -449 removed lines patch added patch discarded remove patch
@@ -12,479 +12,479 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * Holds values for registered message types
17
-     *
18
-     * @var array
19
-     */
20
-    protected static $_ee_message_type_registry = [];
15
+	/**
16
+	 * Holds values for registered message types
17
+	 *
18
+	 * @var array
19
+	 */
20
+	protected static $_ee_message_type_registry = [];
21 21
 
22 22
 
23
-    /**
24
-     * Method for registering new message types in the EE_messages system.
25
-     * Note:  All message types must have the following files in order to work:
26
-     * Template files for default templates getting setup.
27
-     * See /core/libraries/messages/defaults/default/ for examples
28
-     * (note that template files match a specific naming schema).
29
-     * These templates will need to be registered with the default template pack.
30
-     * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
31
-     *      for examples.  Note for any new message types, there will need to be a validator for each
32
-     *      messenger combo this message type can activate with.
33
-     * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
34
-     *      message type and its properties.
35
-     *
36
-     * @param string $addon_name    Whatever is defined for the $name property of
37
-     *                              the message type you are registering (eg.
38
-     *                              declined_registration). Required.
39
-     * @param array  $setup_args    An array of arguments provided for registering the message type.
40
-     * @throws EE_Error
41
-     *                              }
42
-     * @see      inline docs in the register method for what can be passed in as arguments.
43
-     * @since    4.3.0
44
-     */
45
-    public static function register(string $addon_name = '', array $setup_args = []): bool
46
-    {
47
-        // required fields MUST be present, so let's make sure they are.
48
-        if (
49
-            ! isset($addon_name)
50
-            || ! is_array($setup_args)
51
-            || empty($setup_args['mtfilename'])
52
-            || empty($setup_args['autoloadpaths'])
53
-        ) {
54
-            throw new EE_Error(
55
-                __(
56
-                    'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
57
-                    'event_espresso'
58
-                )
59
-            );
60
-        }
23
+	/**
24
+	 * Method for registering new message types in the EE_messages system.
25
+	 * Note:  All message types must have the following files in order to work:
26
+	 * Template files for default templates getting setup.
27
+	 * See /core/libraries/messages/defaults/default/ for examples
28
+	 * (note that template files match a specific naming schema).
29
+	 * These templates will need to be registered with the default template pack.
30
+	 * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
31
+	 *      for examples.  Note for any new message types, there will need to be a validator for each
32
+	 *      messenger combo this message type can activate with.
33
+	 * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
34
+	 *      message type and its properties.
35
+	 *
36
+	 * @param string $addon_name    Whatever is defined for the $name property of
37
+	 *                              the message type you are registering (eg.
38
+	 *                              declined_registration). Required.
39
+	 * @param array  $setup_args    An array of arguments provided for registering the message type.
40
+	 * @throws EE_Error
41
+	 *                              }
42
+	 * @see      inline docs in the register method for what can be passed in as arguments.
43
+	 * @since    4.3.0
44
+	 */
45
+	public static function register(string $addon_name = '', array $setup_args = []): bool
46
+	{
47
+		// required fields MUST be present, so let's make sure they are.
48
+		if (
49
+			! isset($addon_name)
50
+			|| ! is_array($setup_args)
51
+			|| empty($setup_args['mtfilename'])
52
+			|| empty($setup_args['autoloadpaths'])
53
+		) {
54
+			throw new EE_Error(
55
+				__(
56
+					'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
57
+					'event_espresso'
58
+				)
59
+			);
60
+		}
61 61
 
62
-        // make sure we don't register twice
63
-        if (isset(self::$_ee_message_type_registry[ $addon_name ])) {
64
-            return true;
65
-        }
62
+		// make sure we don't register twice
63
+		if (isset(self::$_ee_message_type_registry[ $addon_name ])) {
64
+			return true;
65
+		}
66 66
 
67
-        // make sure this was called in the right place!
68
-        if (
69
-            ! did_action('EE_Brewing_Regular___messages_caf')
70
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
71
-        ) {
72
-            EE_Error::doing_it_wrong(
73
-                __METHOD__,
74
-                sprintf(
75
-                    __(
76
-                        'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
77
-                        'event_espresso'
78
-                    ),
79
-                    $addon_name
80
-                ),
81
-                '4.3.0'
82
-            );
83
-        }
84
-        // setup $__ee_message_type_registry array from incoming values.
85
-        self::$_ee_message_type_registry[ $addon_name ] = [
86
-            /**
87
-             * The file name for the message type being registered.
88
-             * Required.
89
-             *
90
-             * @type string
91
-             */
92
-            'mtfilename'                                       => (string) $setup_args['mtfilename'],
93
-            /**
94
-             * Autoload paths for classes used by the message type.
95
-             * Required.
96
-             *
97
-             * @type array
98
-             */
99
-            'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
100
-            /**
101
-             * Messengers that the message type should be able to activate with.
102
-             * Use messenger slugs.
103
-             *
104
-             * @type array
105
-             */
106
-            'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
107
-                ? (array) $setup_args['messengers_to_activate_with']
108
-                : [],
109
-            /**
110
-             * Messengers that the message type should validate with.
111
-             * Use messenger slugs.
112
-             *
113
-             * @type array
114
-             */
115
-            'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
116
-                ? (array) $setup_args['messengers_to_validate_with']
117
-                : [],
118
-            /**
119
-             * Whether to force activate this message type the first time it is registered.
120
-             *
121
-             * @type bool   False means its not activated by default and left up to the end user to activate.
122
-             */
123
-            'force_activation'                                 => ! empty($setup_args['force_activation'])
124
-                                                                  && $setup_args['force_activation'],
125
-            /**
126
-             * What messengers this message type supports the default template pack for.
127
-             * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
128
-             * then it is expected that the message type being registered is doing its own custom default template
129
-             * pack/variation registration.
130
-             *
131
-             * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
132
-             * $setup_arguments array as well:
133
-             * - 'base_path_for_default_templates'
134
-             *
135
-             * @type array   Expect an array of messengers this supports default template packs for.
136
-             */
137
-            'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
138
-                ? (array) $setup_args['messengers_supporting_default_template_pack_with']
139
-                : [],
140
-            /**
141
-             * The base path where the default templates for this message type can be found.
142
-             *
143
-             * @type string
144
-             */
145
-            'base_path_for_default_templates'                  => $setup_args['base_path_for_default_templates'] ?? '',
146
-            /**
147
-             * The base path where the default variations for this message type can be found.
148
-             *
149
-             * @type string
150
-             */
151
-            'base_path_for_default_variation'                  => $setup_args['base_path_for_default_variation'] ?? '',
152
-            /**
153
-             * The base url for the default variations for this message type.
154
-             *
155
-             * @type string
156
-             */
157
-            'base_url_for_default_variation'                   => $setup_args['base_url_for_default_variation'] ?? '',
158
-        ];
159
-        // add filters but only if they haven't already been set (these filters only need to be registered ONCE because
160
-        // the callback handles all registered message types.
161
-        if (
162
-            has_filter(
163
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
164
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths']
165
-            ) === false
166
-        ) {
167
-            add_filter(
168
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
169
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
170
-                10
171
-            );
172
-            add_filter(
173
-                'FHEE__EE_messages__get_installed__messagetype_files',
174
-                ['EE_Register_Message_Type', 'register_messagetype_files'],
175
-                10,
176
-                1
177
-            );
178
-            add_filter(
179
-                'FHEE__EE_messenger__get_default_message_types__default_types',
180
-                ['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
181
-                10,
182
-                2
183
-            );
184
-            add_filter(
185
-                'FHEE__EE_messenger__get_valid_message_types__valid_types',
186
-                ['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
187
-                10,
188
-                2
189
-            );
190
-            // actions
191
-            add_action(
192
-                'AHEE__EE_Addon__initialize_default_data__begin',
193
-                ['EE_Register_Message_Type', 'set_defaults']
194
-            );
67
+		// make sure this was called in the right place!
68
+		if (
69
+			! did_action('EE_Brewing_Regular___messages_caf')
70
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
71
+		) {
72
+			EE_Error::doing_it_wrong(
73
+				__METHOD__,
74
+				sprintf(
75
+					__(
76
+						'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
77
+						'event_espresso'
78
+					),
79
+					$addon_name
80
+				),
81
+				'4.3.0'
82
+			);
83
+		}
84
+		// setup $__ee_message_type_registry array from incoming values.
85
+		self::$_ee_message_type_registry[ $addon_name ] = [
86
+			/**
87
+			 * The file name for the message type being registered.
88
+			 * Required.
89
+			 *
90
+			 * @type string
91
+			 */
92
+			'mtfilename'                                       => (string) $setup_args['mtfilename'],
93
+			/**
94
+			 * Autoload paths for classes used by the message type.
95
+			 * Required.
96
+			 *
97
+			 * @type array
98
+			 */
99
+			'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
100
+			/**
101
+			 * Messengers that the message type should be able to activate with.
102
+			 * Use messenger slugs.
103
+			 *
104
+			 * @type array
105
+			 */
106
+			'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
107
+				? (array) $setup_args['messengers_to_activate_with']
108
+				: [],
109
+			/**
110
+			 * Messengers that the message type should validate with.
111
+			 * Use messenger slugs.
112
+			 *
113
+			 * @type array
114
+			 */
115
+			'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
116
+				? (array) $setup_args['messengers_to_validate_with']
117
+				: [],
118
+			/**
119
+			 * Whether to force activate this message type the first time it is registered.
120
+			 *
121
+			 * @type bool   False means its not activated by default and left up to the end user to activate.
122
+			 */
123
+			'force_activation'                                 => ! empty($setup_args['force_activation'])
124
+																  && $setup_args['force_activation'],
125
+			/**
126
+			 * What messengers this message type supports the default template pack for.
127
+			 * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
128
+			 * then it is expected that the message type being registered is doing its own custom default template
129
+			 * pack/variation registration.
130
+			 *
131
+			 * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
132
+			 * $setup_arguments array as well:
133
+			 * - 'base_path_for_default_templates'
134
+			 *
135
+			 * @type array   Expect an array of messengers this supports default template packs for.
136
+			 */
137
+			'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
138
+				? (array) $setup_args['messengers_supporting_default_template_pack_with']
139
+				: [],
140
+			/**
141
+			 * The base path where the default templates for this message type can be found.
142
+			 *
143
+			 * @type string
144
+			 */
145
+			'base_path_for_default_templates'                  => $setup_args['base_path_for_default_templates'] ?? '',
146
+			/**
147
+			 * The base path where the default variations for this message type can be found.
148
+			 *
149
+			 * @type string
150
+			 */
151
+			'base_path_for_default_variation'                  => $setup_args['base_path_for_default_variation'] ?? '',
152
+			/**
153
+			 * The base url for the default variations for this message type.
154
+			 *
155
+			 * @type string
156
+			 */
157
+			'base_url_for_default_variation'                   => $setup_args['base_url_for_default_variation'] ?? '',
158
+		];
159
+		// add filters but only if they haven't already been set (these filters only need to be registered ONCE because
160
+		// the callback handles all registered message types.
161
+		if (
162
+			has_filter(
163
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
164
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths']
165
+			) === false
166
+		) {
167
+			add_filter(
168
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
169
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
170
+				10
171
+			);
172
+			add_filter(
173
+				'FHEE__EE_messages__get_installed__messagetype_files',
174
+				['EE_Register_Message_Type', 'register_messagetype_files'],
175
+				10,
176
+				1
177
+			);
178
+			add_filter(
179
+				'FHEE__EE_messenger__get_default_message_types__default_types',
180
+				['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
181
+				10,
182
+				2
183
+			);
184
+			add_filter(
185
+				'FHEE__EE_messenger__get_valid_message_types__valid_types',
186
+				['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
187
+				10,
188
+				2
189
+			);
190
+			// actions
191
+			add_action(
192
+				'AHEE__EE_Addon__initialize_default_data__begin',
193
+				['EE_Register_Message_Type', 'set_defaults']
194
+			);
195 195
 
196
-            // default template packs and variations related
197
-            add_filter(
198
-                'FHEE__EE_Messages_Template_Pack_Default__get_supports',
199
-                ['EE_Register_Message_Type', 'register_default_template_pack_supports']
200
-            );
201
-            add_filter(
202
-                'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
203
-                ['EE_Register_Message_Type', 'register_base_template_path'],
204
-                10,
205
-                6
206
-            );
207
-            add_filter(
208
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
209
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
210
-                10,
211
-                8
212
-            );
213
-            add_filter(
214
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
215
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
216
-                10,
217
-                8
218
-            );
219
-        }
220
-        return true;
221
-    }
196
+			// default template packs and variations related
197
+			add_filter(
198
+				'FHEE__EE_Messages_Template_Pack_Default__get_supports',
199
+				['EE_Register_Message_Type', 'register_default_template_pack_supports']
200
+			);
201
+			add_filter(
202
+				'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
203
+				['EE_Register_Message_Type', 'register_base_template_path'],
204
+				10,
205
+				6
206
+			);
207
+			add_filter(
208
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
209
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
210
+				10,
211
+				8
212
+			);
213
+			add_filter(
214
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
215
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
216
+				10,
217
+				8
218
+			);
219
+		}
220
+		return true;
221
+	}
222 222
 
223 223
 
224
-    /**
225
-     * This just ensures that when an addon registers a message type that on initial activation/reactivation the
226
-     * defaults the addon sets are taken care of.
227
-     *
228
-     * @throws EE_Error
229
-     * @throws ReflectionException
230
-     */
231
-    public static function set_defaults()
232
-    {
233
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
234
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
224
+	/**
225
+	 * This just ensures that when an addon registers a message type that on initial activation/reactivation the
226
+	 * defaults the addon sets are taken care of.
227
+	 *
228
+	 * @throws EE_Error
229
+	 * @throws ReflectionException
230
+	 */
231
+	public static function set_defaults()
232
+	{
233
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
234
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
235 235
 
236
-        // for any message types with force activation, let's ensure they are activated
237
-        foreach (self::$_ee_message_type_registry as $addon_name => $settings) {
238
-            if ($settings['force_activation']) {
239
-                foreach ($settings['messengers_to_activate_with'] as $messenger) {
240
-                    // DO not force activation if this message type has already been activated in the system
241
-                    if (
242
-                        ! $message_resource_manager->has_message_type_been_activated_for_messenger(
243
-                            $addon_name,
244
-                            $messenger
245
-                        )
246
-                    ) {
247
-                        $message_resource_manager->ensure_message_type_is_active($addon_name, $messenger);
248
-                    }
249
-                }
250
-            }
251
-        }
252
-    }
236
+		// for any message types with force activation, let's ensure they are activated
237
+		foreach (self::$_ee_message_type_registry as $addon_name => $settings) {
238
+			if ($settings['force_activation']) {
239
+				foreach ($settings['messengers_to_activate_with'] as $messenger) {
240
+					// DO not force activation if this message type has already been activated in the system
241
+					if (
242
+						! $message_resource_manager->has_message_type_been_activated_for_messenger(
243
+							$addon_name,
244
+							$messenger
245
+						)
246
+					) {
247
+						$message_resource_manager->ensure_message_type_is_active($addon_name, $messenger);
248
+					}
249
+				}
250
+			}
251
+		}
252
+	}
253 253
 
254 254
 
255
-    /**
256
-     * This deregisters a message type that was previously registered with a specific message_type_name.
257
-     *
258
-     * @param string $addon_name the name for the message type that was previously registered
259
-     * @return void
260
-     * @throws EE_Error
261
-     * @throws ReflectionException
262
-     * @since    4.3.0
263
-     */
264
-    public static function deregister(string $addon_name = '')
265
-    {
266
-        if (! empty(self::$_ee_message_type_registry[ $addon_name ])) {
267
-            // let's make sure that we remove any place this message type was made active
268
-            /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
269
-            $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
270
-            // ensures that if this message type is registered again that it retains its previous active state vs
271
-            // remaining inactive.
272
-            $Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
273
-                $addon_name,
274
-                true
275
-            );
276
-            $Message_Resource_Manager->deactivate_message_type($addon_name, false);
277
-        }
278
-        unset(self::$_ee_message_type_registry[ $addon_name ]);
279
-    }
255
+	/**
256
+	 * This deregisters a message type that was previously registered with a specific message_type_name.
257
+	 *
258
+	 * @param string $addon_name the name for the message type that was previously registered
259
+	 * @return void
260
+	 * @throws EE_Error
261
+	 * @throws ReflectionException
262
+	 * @since    4.3.0
263
+	 */
264
+	public static function deregister(string $addon_name = '')
265
+	{
266
+		if (! empty(self::$_ee_message_type_registry[ $addon_name ])) {
267
+			// let's make sure that we remove any place this message type was made active
268
+			/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
269
+			$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
270
+			// ensures that if this message type is registered again that it retains its previous active state vs
271
+			// remaining inactive.
272
+			$Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
273
+				$addon_name,
274
+				true
275
+			);
276
+			$Message_Resource_Manager->deactivate_message_type($addon_name, false);
277
+		}
278
+		unset(self::$_ee_message_type_registry[ $addon_name ]);
279
+	}
280 280
 
281 281
 
282
-    /**
283
-     * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
284
-     *
285
-     * @param array $messagetype_files The current array of message type file names
286
-     * @return  array                                 Array of message type file names
287
-     * @since   4.3.0
288
-     */
289
-    public static function register_messagetype_files(array $messagetype_files): array
290
-    {
291
-        if (empty(self::$_ee_message_type_registry)) {
292
-            return $messagetype_files;
293
-        }
294
-        foreach (self::$_ee_message_type_registry as $mt_reg) {
295
-            if (empty($mt_reg['mtfilename'])) {
296
-                continue;
297
-            }
298
-            $messagetype_files[] = $mt_reg['mtfilename'];
299
-        }
300
-        return $messagetype_files;
301
-    }
282
+	/**
283
+	 * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
284
+	 *
285
+	 * @param array $messagetype_files The current array of message type file names
286
+	 * @return  array                                 Array of message type file names
287
+	 * @since   4.3.0
288
+	 */
289
+	public static function register_messagetype_files(array $messagetype_files): array
290
+	{
291
+		if (empty(self::$_ee_message_type_registry)) {
292
+			return $messagetype_files;
293
+		}
294
+		foreach (self::$_ee_message_type_registry as $mt_reg) {
295
+			if (empty($mt_reg['mtfilename'])) {
296
+				continue;
297
+			}
298
+			$messagetype_files[] = $mt_reg['mtfilename'];
299
+		}
300
+		return $messagetype_files;
301
+	}
302 302
 
303 303
 
304
-    /**
305
-     * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
306
-     *
307
-     * @param array $paths array of paths to be checked by EE_messages autoloader.
308
-     * @return array
309
-     * @since    4.3.0
310
-     */
311
-    public static function register_msgs_autoload_paths(array $paths): array
312
-    {
313
-        $autoload_paths = [];
314
-        if (! empty(self::$_ee_message_type_registry)) {
315
-            foreach (self::$_ee_message_type_registry as $mt_reg) {
316
-                if (empty($mt_reg['autoloadpaths'])) {
317
-                    continue;
318
-                }
319
-                $autoload_paths[] = $mt_reg['autoloadpaths'];
320
-            }
321
-        }
322
-        return array_merge($paths, ...$autoload_paths);
323
-    }
304
+	/**
305
+	 * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
306
+	 *
307
+	 * @param array $paths array of paths to be checked by EE_messages autoloader.
308
+	 * @return array
309
+	 * @since    4.3.0
310
+	 */
311
+	public static function register_msgs_autoload_paths(array $paths): array
312
+	{
313
+		$autoload_paths = [];
314
+		if (! empty(self::$_ee_message_type_registry)) {
315
+			foreach (self::$_ee_message_type_registry as $mt_reg) {
316
+				if (empty($mt_reg['autoloadpaths'])) {
317
+					continue;
318
+				}
319
+				$autoload_paths[] = $mt_reg['autoloadpaths'];
320
+			}
321
+		}
322
+		return array_merge($paths, ...$autoload_paths);
323
+	}
324 324
 
325 325
 
326
-    /**
327
-     * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
328
-     *
329
-     * @param array        $default_types   array of message types activated with messenger (
330
-     *                                      corresponds to the $name property of message type)
331
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
332
-     * @return array
333
-     * @since  4.3.0
334
-     */
335
-    public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger): array
336
-    {
337
-        if (empty(self::$_ee_message_type_registry)) {
338
-            return $default_types;
339
-        }
340
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
341
-            if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
342
-                continue;
343
-            }
344
-            // loop through each of the messengers and if it matches the loaded class
345
-            // then we add this message type to the
346
-            foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
347
-                if ($messenger->name == $msgr) {
348
-                    $default_types[] = $addon_name;
349
-                }
350
-            }
351
-        }
326
+	/**
327
+	 * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
328
+	 *
329
+	 * @param array        $default_types   array of message types activated with messenger (
330
+	 *                                      corresponds to the $name property of message type)
331
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
332
+	 * @return array
333
+	 * @since  4.3.0
334
+	 */
335
+	public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger): array
336
+	{
337
+		if (empty(self::$_ee_message_type_registry)) {
338
+			return $default_types;
339
+		}
340
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
341
+			if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
342
+				continue;
343
+			}
344
+			// loop through each of the messengers and if it matches the loaded class
345
+			// then we add this message type to the
346
+			foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
347
+				if ($messenger->name == $msgr) {
348
+					$default_types[] = $addon_name;
349
+				}
350
+			}
351
+		}
352 352
 
353
-        return $default_types;
354
-    }
353
+		return $default_types;
354
+	}
355 355
 
356 356
 
357
-    /**
358
-     * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
359
-     *
360
-     * @param array        $valid_types     array of message types valid with messenger (
361
-     *                                      corresponds to the $name property of message type)
362
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
363
-     * @return  array
364
-     * @since   4.3.0
365
-     */
366
-    public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger): array
367
-    {
368
-        if (empty(self::$_ee_message_type_registry)) {
369
-            return $valid_types;
370
-        }
371
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
372
-            if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
373
-                continue;
374
-            }
375
-            // loop through each of the messengers and if it matches the loaded class
376
-            // then we add this message type to the
377
-            foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
378
-                if ($messenger->name == $msgr) {
379
-                    $valid_types[] = $addon_name;
380
-                }
381
-            }
382
-        }
357
+	/**
358
+	 * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
359
+	 *
360
+	 * @param array        $valid_types     array of message types valid with messenger (
361
+	 *                                      corresponds to the $name property of message type)
362
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
363
+	 * @return  array
364
+	 * @since   4.3.0
365
+	 */
366
+	public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger): array
367
+	{
368
+		if (empty(self::$_ee_message_type_registry)) {
369
+			return $valid_types;
370
+		}
371
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
372
+			if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
373
+				continue;
374
+			}
375
+			// loop through each of the messengers and if it matches the loaded class
376
+			// then we add this message type to the
377
+			foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
378
+				if ($messenger->name == $msgr) {
379
+					$valid_types[] = $addon_name;
380
+				}
381
+			}
382
+		}
383 383
 
384
-        return $valid_types;
385
-    }
384
+		return $valid_types;
385
+	}
386 386
 
387 387
 
388
-    /**
389
-     * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
390
-     * supporting the default template pack
391
-     *
392
-     * @param array $supports
393
-     *
394
-     * @return array
395
-     */
396
-    public static function register_default_template_pack_supports(array $supports): array
397
-    {
398
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
399
-            if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
400
-                continue;
401
-            }
402
-            foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
403
-                $supports[ $messenger_slug ][] = $addon_name;
404
-            }
405
-        }
406
-        return $supports;
407
-    }
388
+	/**
389
+	 * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
390
+	 * supporting the default template pack
391
+	 *
392
+	 * @param array $supports
393
+	 *
394
+	 * @return array
395
+	 */
396
+	public static function register_default_template_pack_supports(array $supports): array
397
+	{
398
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
399
+			if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
400
+				continue;
401
+			}
402
+			foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
403
+				$supports[ $messenger_slug ][] = $addon_name;
404
+			}
405
+		}
406
+		return $supports;
407
+	}
408 408
 
409 409
 
410
-    /**
411
-     * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
412
-     *
413
-     * @param string                    $base_path The original base path for message templates
414
-     * @param EE_messenger              $messenger
415
-     * @param EE_message_type           $message_type
416
-     * @param string                    $field     The field requesting a template
417
-     * @param string                    $context   The context requesting a template
418
-     * @param EE_Messages_Template_Pack $template_pack
419
-     *
420
-     * @return string
421
-     */
422
-    public static function register_base_template_path(
423
-        string $base_path,
424
-        EE_messenger $messenger,
425
-        EE_message_type $message_type,
426
-        string $field,
427
-        string $context,
428
-        EE_Messages_Template_Pack $template_pack
429
-    ): string {
430
-        if (
431
-            ! $template_pack instanceof EE_Messages_Template_Pack_Default
432
-            || ! $message_type instanceof EE_message_type
433
-        ) {
434
-            return $base_path;
435
-        }
436
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
437
-            if (
438
-                $message_type->name === $addon_name
439
-                && ! empty($mt_reg['base_path_for_default_templates'])
440
-            ) {
441
-                return $mt_reg['base_path_for_default_templates'];
442
-            }
443
-        }
444
-        return $base_path;
445
-    }
410
+	/**
411
+	 * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
412
+	 *
413
+	 * @param string                    $base_path The original base path for message templates
414
+	 * @param EE_messenger              $messenger
415
+	 * @param EE_message_type           $message_type
416
+	 * @param string                    $field     The field requesting a template
417
+	 * @param string                    $context   The context requesting a template
418
+	 * @param EE_Messages_Template_Pack $template_pack
419
+	 *
420
+	 * @return string
421
+	 */
422
+	public static function register_base_template_path(
423
+		string $base_path,
424
+		EE_messenger $messenger,
425
+		EE_message_type $message_type,
426
+		string $field,
427
+		string $context,
428
+		EE_Messages_Template_Pack $template_pack
429
+	): string {
430
+		if (
431
+			! $template_pack instanceof EE_Messages_Template_Pack_Default
432
+			|| ! $message_type instanceof EE_message_type
433
+		) {
434
+			return $base_path;
435
+		}
436
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
437
+			if (
438
+				$message_type->name === $addon_name
439
+				&& ! empty($mt_reg['base_path_for_default_templates'])
440
+			) {
441
+				return $mt_reg['base_path_for_default_templates'];
442
+			}
443
+		}
444
+		return $base_path;
445
+	}
446 446
 
447 447
 
448
-    /**
449
-     * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
450
-     * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
451
-     *
452
-     * @param string                    $base_path_or_url  The original incoming base url or path
453
-     * @param string                    $messenger_slug    The slug of the messenger the template is being generated
454
-     *                                                     for.
455
-     * @param string                    $message_type_slug The slug of the message type the template is being generated
456
-     *                                                     for.
457
-     * @param string                    $type              The "type" of css being requested.
458
-     * @param string                    $variation         The variation being requested.
459
-     * @param bool                      $url               whether a url or path is being requested.
460
-     * @param string                    $file_extension    What file extension is expected for the variation file.
461
-     * @param EE_Messages_Template_Pack $template_pack
462
-     *
463
-     * @return string
464
-     */
465
-    public static function register_variation_base_path_or_url(
466
-        string $base_path_or_url,
467
-        string $messenger_slug,
468
-        string $message_type_slug,
469
-        string $type,
470
-        string $variation,
471
-        bool $url,
472
-        string $file_extension,
473
-        EE_Messages_Template_Pack $template_pack
474
-    ): string {
475
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
476
-            return $base_path_or_url;
477
-        }
478
-        foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
479
-            if ($addon_name === $message_type_slug) {
480
-                if ($url && ! empty($mt_reg['base_url_for_default_variation'])) {
481
-                    return $mt_reg['base_url_for_default_variation'];
482
-                }
483
-                if (! $url && ! empty($mt_reg['base_path_for_default_variation'])) {
484
-                    return $mt_reg['base_path_for_default_variation'];
485
-                }
486
-            }
487
-        }
488
-        return $base_path_or_url;
489
-    }
448
+	/**
449
+	 * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
450
+	 * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
451
+	 *
452
+	 * @param string                    $base_path_or_url  The original incoming base url or path
453
+	 * @param string                    $messenger_slug    The slug of the messenger the template is being generated
454
+	 *                                                     for.
455
+	 * @param string                    $message_type_slug The slug of the message type the template is being generated
456
+	 *                                                     for.
457
+	 * @param string                    $type              The "type" of css being requested.
458
+	 * @param string                    $variation         The variation being requested.
459
+	 * @param bool                      $url               whether a url or path is being requested.
460
+	 * @param string                    $file_extension    What file extension is expected for the variation file.
461
+	 * @param EE_Messages_Template_Pack $template_pack
462
+	 *
463
+	 * @return string
464
+	 */
465
+	public static function register_variation_base_path_or_url(
466
+		string $base_path_or_url,
467
+		string $messenger_slug,
468
+		string $message_type_slug,
469
+		string $type,
470
+		string $variation,
471
+		bool $url,
472
+		string $file_extension,
473
+		EE_Messages_Template_Pack $template_pack
474
+	): string {
475
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
476
+			return $base_path_or_url;
477
+		}
478
+		foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
479
+			if ($addon_name === $message_type_slug) {
480
+				if ($url && ! empty($mt_reg['base_url_for_default_variation'])) {
481
+					return $mt_reg['base_url_for_default_variation'];
482
+				}
483
+				if (! $url && ! empty($mt_reg['base_path_for_default_variation'])) {
484
+					return $mt_reg['base_path_for_default_variation'];
485
+				}
486
+			}
487
+		}
488
+		return $base_path_or_url;
489
+	}
490 490
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         }
61 61
 
62 62
         // make sure we don't register twice
63
-        if (isset(self::$_ee_message_type_registry[ $addon_name ])) {
63
+        if (isset(self::$_ee_message_type_registry[$addon_name])) {
64 64
             return true;
65 65
         }
66 66
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             );
83 83
         }
84 84
         // setup $__ee_message_type_registry array from incoming values.
85
-        self::$_ee_message_type_registry[ $addon_name ] = [
85
+        self::$_ee_message_type_registry[$addon_name] = [
86 86
             /**
87 87
              * The file name for the message type being registered.
88 88
              * Required.
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      */
264 264
     public static function deregister(string $addon_name = '')
265 265
     {
266
-        if (! empty(self::$_ee_message_type_registry[ $addon_name ])) {
266
+        if ( ! empty(self::$_ee_message_type_registry[$addon_name])) {
267 267
             // let's make sure that we remove any place this message type was made active
268 268
             /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
269 269
             $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
             );
276 276
             $Message_Resource_Manager->deactivate_message_type($addon_name, false);
277 277
         }
278
-        unset(self::$_ee_message_type_registry[ $addon_name ]);
278
+        unset(self::$_ee_message_type_registry[$addon_name]);
279 279
     }
280 280
 
281 281
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     public static function register_msgs_autoload_paths(array $paths): array
312 312
     {
313 313
         $autoload_paths = [];
314
-        if (! empty(self::$_ee_message_type_registry)) {
314
+        if ( ! empty(self::$_ee_message_type_registry)) {
315 315
             foreach (self::$_ee_message_type_registry as $mt_reg) {
316 316
                 if (empty($mt_reg['autoloadpaths'])) {
317 317
                     continue;
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
                 continue;
401 401
             }
402 402
             foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
403
-                $supports[ $messenger_slug ][] = $addon_name;
403
+                $supports[$messenger_slug][] = $addon_name;
404 404
             }
405 405
         }
406 406
         return $supports;
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
         string $file_extension,
473 473
         EE_Messages_Template_Pack $template_pack
474 474
     ): string {
475
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
475
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
476 476
             return $base_path_or_url;
477 477
         }
478 478
         foreach (self::$_ee_message_type_registry as $addon_name => $mt_reg) {
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
                 if ($url && ! empty($mt_reg['base_url_for_default_variation'])) {
481 481
                     return $mt_reg['base_url_for_default_variation'];
482 482
                 }
483
-                if (! $url && ! empty($mt_reg['base_path_for_default_variation'])) {
483
+                if ( ! $url && ! empty($mt_reg['base_path_for_default_variation'])) {
484 484
                     return $mt_reg['base_path_for_default_variation'];
485 485
                 }
486 486
             }
Please login to merge, or discard this patch.