Completed
Branch FET/Gutenberg/11467/espresso-c... (b0019e)
by
unknown
49:48 queued 35:26
created
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4124 added lines, -4124 removed lines patch added patch discarded remove patch
@@ -21,4209 +21,4209 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    //set in _init_page_props()
25
-    public $page_slug;
24
+	//set in _init_page_props()
25
+	public $page_slug;
26 26
 
27
-    public $page_label;
27
+	public $page_label;
28 28
 
29
-    public $page_folder;
29
+	public $page_folder;
30 30
 
31
-    //set in define_page_props()
32
-    protected $_admin_base_url;
31
+	//set in define_page_props()
32
+	protected $_admin_base_url;
33 33
 
34
-    protected $_admin_base_path;
34
+	protected $_admin_base_path;
35 35
 
36
-    protected $_admin_page_title;
36
+	protected $_admin_page_title;
37 37
 
38
-    protected $_labels;
38
+	protected $_labels;
39 39
 
40 40
 
41
-    //set early within EE_Admin_Init
42
-    protected $_wp_page_slug;
41
+	//set early within EE_Admin_Init
42
+	protected $_wp_page_slug;
43 43
 
44
-    //navtabs
45
-    protected $_nav_tabs;
44
+	//navtabs
45
+	protected $_nav_tabs;
46 46
 
47
-    protected $_default_nav_tab_name;
47
+	protected $_default_nav_tab_name;
48 48
 
49
-    /**
50
-     * @var array $_help_tour
51
-     */
52
-    protected $_help_tour = array();
49
+	/**
50
+	 * @var array $_help_tour
51
+	 */
52
+	protected $_help_tour = array();
53 53
 
54 54
 
55
-    //template variables (used by templates)
56
-    protected $_template_path;
55
+	//template variables (used by templates)
56
+	protected $_template_path;
57 57
 
58
-    protected $_column_template_path;
58
+	protected $_column_template_path;
59 59
 
60
-    /**
61
-     * @var array $_template_args
62
-     */
63
-    protected $_template_args = array();
60
+	/**
61
+	 * @var array $_template_args
62
+	 */
63
+	protected $_template_args = array();
64 64
 
65
-    /**
66
-     * this will hold the list table object for a given view.
67
-     *
68
-     * @var EE_Admin_List_Table $_list_table_object
69
-     */
70
-    protected $_list_table_object;
65
+	/**
66
+	 * this will hold the list table object for a given view.
67
+	 *
68
+	 * @var EE_Admin_List_Table $_list_table_object
69
+	 */
70
+	protected $_list_table_object;
71 71
 
72
-    //bools
73
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
72
+	//bools
73
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
74 74
 
75
-    protected $_routing;
75
+	protected $_routing;
76 76
 
77
-    //list table args
78
-    protected $_view;
77
+	//list table args
78
+	protected $_view;
79 79
 
80
-    protected $_views;
80
+	protected $_views;
81 81
 
82 82
 
83
-    //action => method pairs used for routing incoming requests
84
-    protected $_page_routes;
83
+	//action => method pairs used for routing incoming requests
84
+	protected $_page_routes;
85 85
 
86
-    /**
87
-     * @var array $_page_config
88
-     */
89
-    protected $_page_config;
86
+	/**
87
+	 * @var array $_page_config
88
+	 */
89
+	protected $_page_config;
90 90
 
91
-    /**
92
-     * the current page route and route config
93
-     *
94
-     * @var string $_route
95
-     */
96
-    protected $_route;
91
+	/**
92
+	 * the current page route and route config
93
+	 *
94
+	 * @var string $_route
95
+	 */
96
+	protected $_route;
97 97
 
98
-    /**
99
-     * @var string $_cpt_route
100
-     */
101
-    protected $_cpt_route;
98
+	/**
99
+	 * @var string $_cpt_route
100
+	 */
101
+	protected $_cpt_route;
102 102
 
103
-    /**
104
-     * @var array $_route_config
105
-     */
106
-    protected $_route_config;
103
+	/**
104
+	 * @var array $_route_config
105
+	 */
106
+	protected $_route_config;
107 107
 
108
-    /**
109
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
110
-     * actions.
111
-     *
112
-     * @since 4.6.x
113
-     * @var array.
114
-     */
115
-    protected $_default_route_query_args;
116
-
117
-    //set via request page and action args.
118
-    protected $_current_page;
108
+	/**
109
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
110
+	 * actions.
111
+	 *
112
+	 * @since 4.6.x
113
+	 * @var array.
114
+	 */
115
+	protected $_default_route_query_args;
116
+
117
+	//set via request page and action args.
118
+	protected $_current_page;
119 119
 
120
-    protected $_current_view;
120
+	protected $_current_view;
121 121
 
122
-    protected $_current_page_view_url;
122
+	protected $_current_page_view_url;
123 123
 
124
-    //sanitized request action (and nonce)
124
+	//sanitized request action (and nonce)
125 125
 
126
-    /**
127
-     * @var string $_req_action
128
-     */
129
-    protected $_req_action;
130
-
131
-    /**
132
-     * @var string $_req_nonce
133
-     */
134
-    protected $_req_nonce;
135
-
136
-    //search related
137
-    protected $_search_btn_label;
138
-
139
-    protected $_search_box_callback;
140
-
141
-    /**
142
-     * WP Current Screen object
143
-     *
144
-     * @var WP_Screen
145
-     */
146
-    protected $_current_screen;
147
-
148
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
149
-    protected $_hook_obj;
150
-
151
-    //for holding incoming request data
152
-    protected $_req_data;
153
-
154
-    // yes / no array for admin form fields
155
-    protected $_yes_no_values = array();
156
-
157
-    //some default things shared by all child classes
158
-    protected $_default_espresso_metaboxes;
159
-
160
-    /**
161
-     *    EE_Registry Object
162
-     *
163
-     * @var    EE_Registry
164
-     */
165
-    protected $EE = null;
166
-
167
-
168
-
169
-    /**
170
-     * This is just a property that flags whether the given route is a caffeinated route or not.
171
-     *
172
-     * @var boolean
173
-     */
174
-    protected $_is_caf = false;
175
-
176
-
177
-
178
-    /**
179
-     * @Constructor
180
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
181
-     * @throws EE_Error
182
-     * @throws InvalidArgumentException
183
-     * @throws ReflectionException
184
-     * @throws InvalidDataTypeException
185
-     * @throws InvalidInterfaceException
186
-     */
187
-    public function __construct($routing = true)
188
-    {
189
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
190
-            $this->_is_caf = true;
191
-        }
192
-        $this->_yes_no_values = array(
193
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
194
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
195
-        );
196
-        //set the _req_data property.
197
-        $this->_req_data = array_merge($_GET, $_POST);
198
-        //routing enabled?
199
-        $this->_routing = $routing;
200
-        //set initial page props (child method)
201
-        $this->_init_page_props();
202
-        //set global defaults
203
-        $this->_set_defaults();
204
-        //set early because incoming requests could be ajax related and we need to register those hooks.
205
-        $this->_global_ajax_hooks();
206
-        $this->_ajax_hooks();
207
-        //other_page_hooks have to be early too.
208
-        $this->_do_other_page_hooks();
209
-        //This just allows us to have extending classes do something specific
210
-        // before the parent constructor runs _page_setup().
211
-        if (method_exists($this, '_before_page_setup')) {
212
-            $this->_before_page_setup();
213
-        }
214
-        //set up page dependencies
215
-        $this->_page_setup();
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * _init_page_props
222
-     * Child classes use to set at least the following properties:
223
-     * $page_slug.
224
-     * $page_label.
225
-     *
226
-     * @abstract
227
-     * @return void
228
-     */
229
-    abstract protected function _init_page_props();
230
-
231
-
232
-
233
-    /**
234
-     * _ajax_hooks
235
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
236
-     * Note: within the ajax callback methods.
237
-     *
238
-     * @abstract
239
-     * @return void
240
-     */
241
-    abstract protected function _ajax_hooks();
242
-
243
-
244
-
245
-    /**
246
-     * _define_page_props
247
-     * child classes define page properties in here.  Must include at least:
248
-     * $_admin_base_url = base_url for all admin pages
249
-     * $_admin_page_title = default admin_page_title for admin pages
250
-     * $_labels = array of default labels for various automatically generated elements:
251
-     *    array(
252
-     *        'buttons' => array(
253
-     *            'add' => esc_html__('label for add new button'),
254
-     *            'edit' => esc_html__('label for edit button'),
255
-     *            'delete' => esc_html__('label for delete button')
256
-     *            )
257
-     *        )
258
-     *
259
-     * @abstract
260
-     * @return void
261
-     */
262
-    abstract protected function _define_page_props();
263
-
264
-
265
-
266
-    /**
267
-     * _set_page_routes
268
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
269
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
270
-     * have a 'default' route. Here's the format
271
-     * $this->_page_routes = array(
272
-     *        'default' => array(
273
-     *            'func' => '_default_method_handling_route',
274
-     *            'args' => array('array','of','args'),
275
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
276
-     *            ajax request, backend processing)
277
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
278
-     *            headers route after.  The string you enter here should match the defined route reference for a
279
-     *            headers sent route.
280
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
281
-     *            this route.
282
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
283
-     *            checks).
284
-     *        ),
285
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
286
-     *        handling method.
287
-     *        )
288
-     * )
289
-     *
290
-     * @abstract
291
-     * @return void
292
-     */
293
-    abstract protected function _set_page_routes();
294
-
295
-
296
-
297
-    /**
298
-     * _set_page_config
299
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
300
-     * array corresponds to the page_route for the loaded page. Format:
301
-     * $this->_page_config = array(
302
-     *        'default' => array(
303
-     *            'labels' => array(
304
-     *                'buttons' => array(
305
-     *                    'add' => esc_html__('label for adding item'),
306
-     *                    'edit' => esc_html__('label for editing item'),
307
-     *                    'delete' => esc_html__('label for deleting item')
308
-     *                ),
309
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
310
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
311
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
312
-     *            _define_page_props() method
313
-     *            'nav' => array(
314
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
315
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
316
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
317
-     *                'order' => 10, //required to indicate tab position.
318
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
319
-     *                displayed then add this parameter.
320
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
321
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
322
-     *            metaboxes set for eventespresso admin pages.
323
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
324
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
325
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
326
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
327
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
328
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
329
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
330
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
331
-     *            want to display.
332
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
333
-     *                'tab_id' => array(
334
-     *                    'title' => 'tab_title',
335
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
336
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
337
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
338
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
339
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
340
-     *                    attempt to use the callback which should match the name of a method in the class
341
-     *                    ),
342
-     *                'tab2_id' => array(
343
-     *                    'title' => 'tab2 title',
344
-     *                    'filename' => 'file_name_2'
345
-     *                    'callback' => 'callback_method_for_content',
346
-     *                 ),
347
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
348
-     *            help tab area on an admin page. @link
349
-     *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
350
-     *            'help_tour' => array(
351
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
352
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
353
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
354
-     *            ),
355
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
356
-     *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
357
-     *            just set
358
-     *            'require_nonce' to FALSE
359
-     *            )
360
-     * )
361
-     *
362
-     * @abstract
363
-     * @return void
364
-     */
365
-    abstract protected function _set_page_config();
366
-
367
-
368
-
369
-
370
-
371
-    /** end sample help_tour methods **/
372
-    /**
373
-     * _add_screen_options
374
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
375
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
376
-     * to a particular view.
377
-     *
378
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
379
-     *         see also WP_Screen object documents...
380
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
381
-     * @abstract
382
-     * @return void
383
-     */
384
-    abstract protected function _add_screen_options();
385
-
386
-
387
-
388
-    /**
389
-     * _add_feature_pointers
390
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
391
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
392
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
393
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
394
-     * extended) also see:
395
-     *
396
-     * @link   http://eamann.com/tech/wordpress-portland/
397
-     * @abstract
398
-     * @return void
399
-     */
400
-    abstract protected function _add_feature_pointers();
401
-
402
-
403
-
404
-    /**
405
-     * load_scripts_styles
406
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
407
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
408
-     * scripts/styles per view by putting them in a dynamic function in this format
409
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
410
-     *
411
-     * @abstract
412
-     * @return void
413
-     */
414
-    abstract public function load_scripts_styles();
415
-
416
-
417
-
418
-    /**
419
-     * admin_init
420
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
421
-     * all pages/views loaded by child class.
422
-     *
423
-     * @abstract
424
-     * @return void
425
-     */
426
-    abstract public function admin_init();
427
-
428
-
429
-
430
-    /**
431
-     * admin_notices
432
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
433
-     * all pages/views loaded by child class.
434
-     *
435
-     * @abstract
436
-     * @return void
437
-     */
438
-    abstract public function admin_notices();
439
-
440
-
441
-
442
-    /**
443
-     * admin_footer_scripts
444
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
445
-     * will apply to all pages/views loaded by child class.
446
-     *
447
-     * @return void
448
-     */
449
-    abstract public function admin_footer_scripts();
450
-
451
-
452
-
453
-    /**
454
-     * admin_footer
455
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
456
-     * apply to all pages/views loaded by child class.
457
-     *
458
-     * @return void
459
-     */
460
-    public function admin_footer()
461
-    {
462
-    }
463
-
464
-
465
-
466
-    /**
467
-     * _global_ajax_hooks
468
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
469
-     * Note: within the ajax callback methods.
470
-     *
471
-     * @abstract
472
-     * @return void
473
-     */
474
-    protected function _global_ajax_hooks()
475
-    {
476
-        //for lazy loading of metabox content
477
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
478
-    }
479
-
480
-
481
-
482
-    public function ajax_metabox_content()
483
-    {
484
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
485
-        $url       = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
486
-        self::cached_rss_display($contentid, $url);
487
-        wp_die();
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     * _page_setup
494
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
495
-     * doesn't match the object.
496
-     *
497
-     * @final
498
-     * @return void
499
-     * @throws EE_Error
500
-     * @throws InvalidArgumentException
501
-     * @throws ReflectionException
502
-     * @throws InvalidDataTypeException
503
-     * @throws InvalidInterfaceException
504
-     */
505
-    final protected function _page_setup()
506
-    {
507
-        //requires?
508
-        //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
509
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
510
-        //next verify if we need to load anything...
511
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
512
-        $this->page_folder   = strtolower(
513
-            str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
514
-        );
515
-        global $ee_menu_slugs;
516
-        $ee_menu_slugs = (array)$ee_menu_slugs;
517
-        if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) {
518
-            return;
519
-        }
520
-        // 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
521
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
522
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
523
-                ? $this->_req_data['action2']
524
-                : $this->_req_data['action'];
525
-        }
526
-        // then set blank or -1 action values to 'default'
527
-        $this->_req_action = isset($this->_req_data['action'])
528
-                             && ! empty($this->_req_data['action'])
529
-                             && $this->_req_data['action'] !== '-1'
530
-            ? sanitize_key($this->_req_data['action'])
531
-            : 'default';
532
-        // if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
533
-        //  This covers cases where we're coming in from a list table that isn't on the default route.
534
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
535
-            ? $this->_req_data['route'] : $this->_req_action;
536
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
537
-        $this->_req_action   = defined('DOING_AJAX') && isset($this->_req_data['route'])
538
-            ? $this->_req_data['route']
539
-            : $this->_req_action;
540
-        $this->_current_view = $this->_req_action;
541
-        $this->_req_nonce    = $this->_req_action . '_nonce';
542
-        $this->_define_page_props();
543
-        $this->_current_page_view_url = add_query_arg(
544
-            array('page' => $this->_current_page, 'action' => $this->_current_view),
545
-            $this->_admin_base_url
546
-        );
547
-        //default things
548
-        $this->_default_espresso_metaboxes = array(
549
-            '_espresso_news_post_box',
550
-            '_espresso_links_post_box',
551
-            '_espresso_ratings_request',
552
-            '_espresso_sponsors_post_box',
553
-        );
554
-        //set page configs
555
-        $this->_set_page_routes();
556
-        $this->_set_page_config();
557
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
558
-        if (isset($this->_req_data['wp_referer'])) {
559
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
560
-        }
561
-        //for caffeinated and other extended functionality.
562
-        //  If there is a _extend_page_config method
563
-        // then let's run that to modify the all the various page configuration arrays
564
-        if (method_exists($this, '_extend_page_config')) {
565
-            $this->_extend_page_config();
566
-        }
567
-        //for CPT and other extended functionality.
568
-        // If there is an _extend_page_config_for_cpt
569
-        // then let's run that to modify all the various page configuration arrays.
570
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
571
-            $this->_extend_page_config_for_cpt();
572
-        }
573
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
574
-        $this->_page_routes = apply_filters(
575
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
576
-            $this->_page_routes,
577
-            $this
578
-        );
579
-        $this->_page_config = apply_filters(
580
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
581
-            $this->_page_config,
582
-            $this
583
-        );
584
-        //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
585
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
586
-        if (
587
-            method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)
588
-        ) {
589
-            add_action(
590
-                'AHEE__EE_Admin_Page__route_admin_request',
591
-                array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
592
-                10,
593
-                2
594
-            );
595
-        }
596
-        //next route only if routing enabled
597
-        if ($this->_routing && ! defined('DOING_AJAX')) {
598
-            $this->_verify_routes();
599
-            //next let's just check user_access and kill if no access
600
-            $this->check_user_access();
601
-            if ($this->_is_UI_request) {
602
-                //admin_init stuff - global, all views for this page class, specific view
603
-                add_action('admin_init', array($this, 'admin_init'), 10);
604
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
605
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
606
-                }
607
-            } else {
608
-                //hijack regular WP loading and route admin request immediately
609
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
610
-                $this->route_admin_request();
611
-            }
612
-        }
613
-    }
614
-
615
-
616
-
617
-    /**
618
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
619
-     *
620
-     * @return void
621
-     * @throws ReflectionException
622
-     * @throws EE_Error
623
-     */
624
-    private function _do_other_page_hooks()
625
-    {
626
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
627
-        foreach ($registered_pages as $page) {
628
-            //now let's setup the file name and class that should be present
629
-            $classname = str_replace('.class.php', '', $page);
630
-            //autoloaders should take care of loading file
631
-            if (! class_exists($classname)) {
632
-                $error_msg[] = sprintf(
633
-                    esc_html__(
634
-                        'Something went wrong with loading the %s admin hooks page.',
635
-                        'event_espresso'
636
-                    ),
637
-                    $page
638
-                );
639
-                $error_msg[] = $error_msg[0]
640
-                               . "\r\n"
641
-                               . sprintf(
642
-                                   esc_html__(
643
-                                       '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',
644
-                                       'event_espresso'
645
-                                   ),
646
-                                   $page,
647
-                                   '<br />',
648
-                                   '<strong>' . $classname . '</strong>'
649
-                               );
650
-                throw new EE_Error(implode('||', $error_msg));
651
-            }
652
-            $a = new ReflectionClass($classname);
653
-            //notice we are passing the instance of this class to the hook object.
654
-            $hookobj[] = $a->newInstance($this);
655
-        }
656
-    }
657
-
658
-
659
-
660
-    public function load_page_dependencies()
661
-    {
662
-        try {
663
-            $this->_load_page_dependencies();
664
-        } catch (EE_Error $e) {
665
-            $e->get_error();
666
-        }
667
-    }
668
-
669
-
670
-
671
-    /**
672
-     * load_page_dependencies
673
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
674
-     *
675
-     * @return void
676
-     * @throws DomainException
677
-     * @throws EE_Error
678
-     * @throws InvalidArgumentException
679
-     * @throws InvalidDataTypeException
680
-     * @throws InvalidInterfaceException
681
-     * @throws ReflectionException
682
-     */
683
-    protected function _load_page_dependencies()
684
-    {
685
-        //let's set the current_screen and screen options to override what WP set
686
-        $this->_current_screen = get_current_screen();
687
-        //load admin_notices - global, page class, and view specific
688
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
689
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
690
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
691
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
692
-        }
693
-        //load network admin_notices - global, page class, and view specific
694
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
695
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
696
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
697
-        }
698
-        //this will save any per_page screen options if they are present
699
-        $this->_set_per_page_screen_options();
700
-        //setup list table properties
701
-        $this->_set_list_table();
702
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
703
-        // However in some cases the metaboxes will need to be added within a route handling callback.
704
-        $this->_add_registered_meta_boxes();
705
-        $this->_add_screen_columns();
706
-        //add screen options - global, page child class, and view specific
707
-        $this->_add_global_screen_options();
708
-        $this->_add_screen_options();
709
-        $add_screen_options  = "_add_screen_options_{$this->_current_view}";
710
-        if (method_exists($this, $add_screen_options )) {
711
-            $this->{$add_screen_options}();
712
-        }
713
-        //add help tab(s) and tours- set via page_config and qtips.
714
-        $this->_add_help_tour();
715
-        $this->_add_help_tabs();
716
-        $this->_add_qtips();
717
-        //add feature_pointers - global, page child class, and view specific
718
-        $this->_add_feature_pointers();
719
-        $this->_add_global_feature_pointers();
720
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
721
-        if (method_exists($this, $add_feature_pointer )) {
722
-            $this->{$add_feature_pointer}();
723
-        }
724
-        //enqueue scripts/styles - global, page class, and view specific
725
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
726
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
727
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
728
-            add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
729
-        }
730
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
731
-        // admin_print_footer_scripts - global, page child class, and view specific.
732
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
733
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
734
-        // is a good use case. Notice the late priority we're giving these
735
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
736
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
737
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
738
-            add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
739
-        }
740
-        //admin footer scripts
741
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
742
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
743
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
744
-            add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
745
-        }
746
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
747
-        //targeted hook
748
-        do_action(
749
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
750
-
751
-        );
752
-    }
753
-
754
-
755
-
756
-    /**
757
-     * _set_defaults
758
-     * This sets some global defaults for class properties.
759
-     */
760
-    private function _set_defaults()
761
-    {
762
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
763
-        $this->_event = $this->_template_path = $this->_column_template_path = null;
764
-        $this->_nav_tabs = $this->_views = $this->_page_routes = array();
765
-        $this->_page_config = $this->_default_route_query_args = array();
766
-        $this->_default_nav_tab_name = 'overview';
767
-        //init template args
768
-        $this->_template_args = array(
769
-            'admin_page_header'  => '',
770
-            'admin_page_content' => '',
771
-            'post_body_content'  => '',
772
-            'before_list_table'  => '',
773
-            'after_list_table'   => '',
774
-        );
775
-    }
776
-
777
-
778
-
779
-    /**
780
-     * route_admin_request
781
-     *
782
-     * @see    _route_admin_request()
783
-     * @return exception|void error
784
-     * @throws InvalidArgumentException
785
-     * @throws InvalidInterfaceException
786
-     * @throws InvalidDataTypeException
787
-     * @throws EE_Error
788
-     * @throws ReflectionException
789
-     */
790
-    public function route_admin_request()
791
-    {
792
-        try {
793
-            $this->_route_admin_request();
794
-        } catch (EE_Error $e) {
795
-            $e->get_error();
796
-        }
797
-    }
798
-
799
-
800
-
801
-    public function set_wp_page_slug($wp_page_slug)
802
-    {
803
-        $this->_wp_page_slug = $wp_page_slug;
804
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
805
-        if (is_network_admin()) {
806
-            $this->_wp_page_slug .= '-network';
807
-        }
808
-    }
809
-
810
-
811
-
812
-    /**
813
-     * _verify_routes
814
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
815
-     * we know if we need to drop out.
816
-     *
817
-     * @return bool
818
-     * @throws EE_Error
819
-     */
820
-    protected function _verify_routes()
821
-    {
822
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
823
-        if (! $this->_current_page && ! defined('DOING_AJAX')) {
824
-            return false;
825
-        }
826
-        $this->_route = false;
827
-        // check that the page_routes array is not empty
828
-        if (empty($this->_page_routes)) {
829
-            // user error msg
830
-            $error_msg = sprintf(
831
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
832
-                $this->_admin_page_title
833
-            );
834
-            // developer error msg
835
-            $error_msg .= '||' . $error_msg . esc_html__(
836
-                ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
837
-                'event_espresso'
838
-            );
839
-            throw new EE_Error($error_msg);
840
-        }
841
-        // and that the requested page route exists
842
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
843
-            $this->_route        = $this->_page_routes[$this->_req_action];
844
-            $this->_route_config = isset($this->_page_config[$this->_req_action])
845
-                ? $this->_page_config[$this->_req_action] : array();
846
-        } else {
847
-            // user error msg
848
-            $error_msg = sprintf(
849
-                esc_html__(
850
-                        'The requested page route does not exist for the %s admin page.',
851
-                        'event_espresso'
852
-                ),
853
-                $this->_admin_page_title
854
-            );
855
-            // developer error msg
856
-            $error_msg .= '||' . $error_msg . sprintf(
857
-                    esc_html__(
858
-                        ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
859
-                        'event_espresso'
860
-                    ),
861
-                    $this->_req_action
862
-                );
863
-            throw new EE_Error($error_msg);
864
-        }
865
-        // and that a default route exists
866
-        if (! array_key_exists('default', $this->_page_routes)) {
867
-            // user error msg
868
-            $error_msg = sprintf(
869
-                esc_html__(
870
-                        'A default page route has not been set for the % admin page.',
871
-                        'event_espresso'
872
-                ),
873
-                $this->_admin_page_title
874
-            );
875
-            // developer error msg
876
-            $error_msg .= '||' . $error_msg . esc_html__(
877
-                ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
878
-                'event_espresso'
879
-            );
880
-            throw new EE_Error($error_msg);
881
-        }
882
-        //first lets' catch if the UI request has EVER been set.
883
-        if ($this->_is_UI_request === null) {
884
-            //lets set if this is a UI request or not.
885
-            $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
886
-            //wait a minute... we might have a noheader in the route array
887
-            $this->_is_UI_request = is_array($this->_route)
888
-                                    && isset($this->_route['noheader'])
889
-                                    && $this->_route['noheader'] ? false : $this->_is_UI_request;
890
-        }
891
-        $this->_set_current_labels();
892
-        return true;
893
-    }
894
-
895
-
896
-
897
-    /**
898
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
899
-     *
900
-     * @param  string $route the route name we're verifying
901
-     * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
902
-     * @throws EE_Error
903
-     */
904
-    protected function _verify_route($route)
905
-    {
906
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
907
-            return true;
908
-        }
909
-        // user error msg
910
-        $error_msg = sprintf(
911
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
912
-            $this->_admin_page_title
913
-        );
914
-        // developer error msg
915
-        $error_msg .= '||' . $error_msg . sprintf(
916
-                esc_html__(
917
-                    ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
918
-                    'event_espresso'
919
-                ),
920
-                $route
921
-            );
922
-        throw new EE_Error($error_msg);
923
-    }
924
-
925
-
926
-
927
-    /**
928
-     * perform nonce verification
929
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
930
-     * using this method (and save retyping!)
931
-     *
932
-     * @param  string $nonce     The nonce sent
933
-     * @param  string $nonce_ref The nonce reference string (name0)
934
-     * @return void
935
-     * @throws EE_Error
936
-     */
937
-    protected function _verify_nonce($nonce, $nonce_ref)
938
-    {
939
-        // verify nonce against expected value
940
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
941
-            // these are not the droids you are looking for !!!
942
-            $msg = sprintf(
943
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
944
-                '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
945
-                '</a>'
946
-            );
947
-            if (WP_DEBUG) {
948
-                $msg .= "\n  " . sprintf(
949
-                        esc_html__(
950
-                            'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
951
-                            'event_espresso'
952
-                        ),
953
-                        __CLASS__
954
-                    );
955
-            }
956
-            if (! defined('DOING_AJAX')) {
957
-                wp_die($msg);
958
-            } else {
959
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
960
-                $this->_return_json();
961
-            }
962
-        }
963
-    }
964
-
965
-
966
-
967
-    /**
968
-     * _route_admin_request()
969
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
970
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
971
-     * in the page routes and then will try to load the corresponding method.
972
-     *
973
-     * @return void
974
-     * @throws EE_Error
975
-     * @throws InvalidArgumentException
976
-     * @throws InvalidDataTypeException
977
-     * @throws InvalidInterfaceException
978
-     * @throws ReflectionException
979
-     */
980
-    protected function _route_admin_request()
981
-    {
982
-        if (! $this->_is_UI_request) {
983
-            $this->_verify_routes();
984
-        }
985
-        $nonce_check = isset($this->_route_config['require_nonce'])
986
-            ? $this->_route_config['require_nonce']
987
-            : true;
988
-        if ($this->_req_action !== 'default' && $nonce_check) {
989
-            // set nonce from post data
990
-            $nonce = isset($this->_req_data[$this->_req_nonce])
991
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
992
-                : '';
993
-            $this->_verify_nonce($nonce, $this->_req_nonce);
994
-        }
995
-        //set the nav_tabs array but ONLY if this is  UI_request
996
-        if ($this->_is_UI_request) {
997
-            $this->_set_nav_tabs();
998
-        }
999
-        // grab callback function
1000
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
1001
-        // check if callback has args
1002
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1003
-        $error_msg = '';
1004
-        // action right before calling route
1005
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1006
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1007
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1008
-        }
1009
-        // right before calling the route, let's remove _wp_http_referer from the
1010
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1011
-        $_SERVER['REQUEST_URI'] = remove_query_arg(
1012
-                '_wp_http_referer',
1013
-                wp_unslash($_SERVER['REQUEST_URI'])
1014
-        );
1015
-        if (! empty($func)) {
1016
-            if (is_array($func)) {
1017
-                list($class, $method) = $func;
1018
-            } elseif (strpos($func, '::') !== false) {
1019
-                list($class, $method) = explode('::', $func);
1020
-            } else {
1021
-                $class  = $this;
1022
-                $method = $func;
1023
-            }
1024
-            if (! (is_object($class) && $class === $this)) {
1025
-                // send along this admin page object for access by addons.
1026
-                $args['admin_page_object'] = $this;
1027
-            }
1028
-            if (
1029
-                //is it a method on a class that doesn't work?
1030
-                (
1031
-                    (
1032
-                        method_exists($class, $method)
1033
-                        && call_user_func_array(array($class, $method), $args) === false
1034
-                    )
1035
-                    && (
1036
-                        //is it a standalone function that doesn't work?
1037
-                        function_exists($method)
1038
-                        && call_user_func_array(
1039
-                            $func,
1040
-                            array_merge(array('admin_page_object' => $this), $args)
1041
-                           ) === false
1042
-                    )
1043
-                )
1044
-                || (
1045
-                    //is it neither a class method NOR a standalone function?
1046
-                    ! method_exists($class, $method)
1047
-                    && ! function_exists($method)
1048
-                )
1049
-            ) {
1050
-                // user error msg
1051
-                $error_msg = esc_html__(
1052
-                    'An error occurred. The  requested page route could not be found.',
1053
-                    'event_espresso'
1054
-                );
1055
-                // developer error msg
1056
-                $error_msg .= '||';
1057
-                $error_msg .= sprintf(
1058
-                    esc_html__(
1059
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1060
-                        'event_espresso'
1061
-                    ),
1062
-                    $method
1063
-                );
1064
-            }
1065
-            if (! empty($error_msg)) {
1066
-                throw new EE_Error($error_msg);
1067
-            }
1068
-        }
1069
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1070
-        // then we need to reset the routing properties to the new route.
1071
-        //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.
1072
-        if ($this->_is_UI_request === false
1073
-            && is_array($this->_route)
1074
-            && ! empty($this->_route['headers_sent_route'])
1075
-        ) {
1076
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1077
-        }
1078
-    }
1079
-
1080
-
1081
-
1082
-    /**
1083
-     * This method just allows the resetting of page properties in the case where a no headers
1084
-     * route redirects to a headers route in its route config.
1085
-     *
1086
-     * @since   4.3.0
1087
-     * @param  string $new_route New (non header) route to redirect to.
1088
-     * @return   void
1089
-     * @throws ReflectionException
1090
-     * @throws InvalidArgumentException
1091
-     * @throws InvalidInterfaceException
1092
-     * @throws InvalidDataTypeException
1093
-     * @throws EE_Error
1094
-     */
1095
-    protected function _reset_routing_properties($new_route)
1096
-    {
1097
-        $this->_is_UI_request = true;
1098
-        //now we set the current route to whatever the headers_sent_route is set at
1099
-        $this->_req_data['action'] = $new_route;
1100
-        //rerun page setup
1101
-        $this->_page_setup();
1102
-    }
1103
-
1104
-
1105
-
1106
-    /**
1107
-     * _add_query_arg
1108
-     * adds nonce to array of arguments then calls WP add_query_arg function
1109
-     *(internally just uses EEH_URL's function with the same name)
1110
-     *
1111
-     * @param array  $args
1112
-     * @param string $url
1113
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1114
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1115
-     *                                        Example usage: If the current page is:
1116
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1117
-     *                                        &action=default&event_id=20&month_range=March%202015
1118
-     *                                        &_wpnonce=5467821
1119
-     *                                        and you call:
1120
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1121
-     *                                        array(
1122
-     *                                        'action' => 'resend_something',
1123
-     *                                        'page=>espresso_registrations'
1124
-     *                                        ),
1125
-     *                                        $some_url,
1126
-     *                                        true
1127
-     *                                        );
1128
-     *                                        It will produce a url in this structure:
1129
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1130
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1131
-     *                                        month_range]=March%202015
1132
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1133
-     * @return string
1134
-     */
1135
-    public static function add_query_args_and_nonce(
1136
-        $args = array(),
1137
-        $url = false,
1138
-        $sticky = false,
1139
-        $exclude_nonce = false
1140
-    ) {
1141
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
1142
-        if ($sticky) {
1143
-            $request = $_REQUEST;
1144
-            unset($request['_wp_http_referer']);
1145
-            unset($request['wp_referer']);
1146
-            foreach ($request as $key => $value) {
1147
-                //do not add nonces
1148
-                if (strpos($key, 'nonce') !== false) {
1149
-                    continue;
1150
-                }
1151
-                $args['wp_referer[' . $key . ']'] = $value;
1152
-            }
1153
-        }
1154
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1155
-    }
1156
-
1157
-
1158
-
1159
-    /**
1160
-     * This returns a generated link that will load the related help tab.
1161
-     *
1162
-     * @param  string $help_tab_id the id for the connected help tab
1163
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1164
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1165
-     * @uses EEH_Template::get_help_tab_link()
1166
-     * @return string              generated link
1167
-     */
1168
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1169
-    {
1170
-        return EEH_Template::get_help_tab_link(
1171
-            $help_tab_id,
1172
-            $this->page_slug,
1173
-            $this->_req_action,
1174
-            $icon_style,
1175
-            $help_text
1176
-        );
1177
-    }
1178
-
1179
-
1180
-
1181
-    /**
1182
-     * _add_help_tabs
1183
-     * Note child classes define their help tabs within the page_config array.
1184
-     *
1185
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1186
-     * @return void
1187
-     * @throws DomainException
1188
-     * @throws EE_Error
1189
-     */
1190
-    protected function _add_help_tabs()
1191
-    {
1192
-        $tour_buttons = '';
1193
-        if (isset($this->_page_config[$this->_req_action])) {
1194
-            $config = $this->_page_config[$this->_req_action];
1195
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1196
-            if (isset($this->_help_tour[$this->_req_action])) {
1197
-                $tb           = array();
1198
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1199
-                foreach ($this->_help_tour['tours'] as $tour) {
1200
-                    //if this is the end tour then we don't need to setup a button
1201
-                    if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1202
-                        continue;
1203
-                    }
1204
-                    $tb[] = '<button id="trigger-tour-'
1205
-                            . $tour->get_slug()
1206
-                            . '" class="button-primary trigger-ee-help-tour">'
1207
-                            . $tour->get_label()
1208
-                            . '</button>';
1209
-                }
1210
-                $tour_buttons .= implode('<br />', $tb);
1211
-                $tour_buttons .= '</div></div>';
1212
-            }
1213
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1214
-            if (is_array($config) && isset($config['help_sidebar'])) {
1215
-                //check that the callback given is valid
1216
-                if (! method_exists($this, $config['help_sidebar'])) {
1217
-                    throw new EE_Error(
1218
-                        sprintf(
1219
-                            esc_html__(
1220
-                                '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',
1221
-                                'event_espresso'
1222
-                            ),
1223
-                            $config['help_sidebar'],
1224
-                            get_class($this)
1225
-                        )
1226
-                    );
1227
-                }
1228
-                $content = apply_filters(
1229
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1230
-                    $this->{$config['help_sidebar']}()
1231
-                );
1232
-                $content .= $tour_buttons; //add help tour buttons.
1233
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1234
-                $this->_current_screen->set_help_sidebar($content);
1235
-            }
1236
-            //if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1237
-            if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1238
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1239
-            }
1240
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1241
-            if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1242
-                $_ht['id']      = $this->page_slug;
1243
-                $_ht['title']   = esc_html__('Help Tours', 'event_espresso');
1244
-                $_ht['content'] = '<p>' . esc_html__(
1245
-                        'The buttons to the right allow you to start/restart any help tours available for this page',
1246
-                        'event_espresso'
1247
-                    ) . '</p>';
1248
-                $this->_current_screen->add_help_tab($_ht);
1249
-            }
1250
-            if (! isset($config['help_tabs'])) {
1251
-                return;
1252
-            } //no help tabs for this route
1253
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1254
-                //we're here so there ARE help tabs!
1255
-                //make sure we've got what we need
1256
-                if (! isset($cfg['title'])) {
1257
-                    throw new EE_Error(
1258
-                        esc_html__(
1259
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1260
-                            'event_espresso'
1261
-                        )
1262
-                    );
1263
-                }
1264
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1265
-                    throw new EE_Error(
1266
-                        esc_html__(
1267
-                            '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',
1268
-                            'event_espresso'
1269
-                        )
1270
-                    );
1271
-                }
1272
-                //first priority goes to content.
1273
-                if (! empty($cfg['content'])) {
1274
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1275
-                    //second priority goes to filename
1276
-                } elseif (! empty($cfg['filename'])) {
1277
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1278
-                    //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)
1279
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1280
-                                                             . basename($this->_get_dir())
1281
-                                                             . '/help_tabs/'
1282
-                                                             . $cfg['filename']
1283
-                                                             . '.help_tab.php' : $file_path;
1284
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1285
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1286
-                        EE_Error::add_error(
1287
-                            sprintf(
1288
-                                esc_html__(
1289
-                                    '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',
1290
-                                    'event_espresso'
1291
-                                ),
1292
-                                $tab_id,
1293
-                                key($config),
1294
-                                $file_path
1295
-                            ),
1296
-                            __FILE__,
1297
-                            __FUNCTION__,
1298
-                            __LINE__
1299
-                        );
1300
-                        return;
1301
-                    }
1302
-                    $template_args['admin_page_obj'] = $this;
1303
-                    $content = EEH_Template::display_template(
1304
-                        $file_path,
1305
-                        $template_args,
1306
-                        true
1307
-                    );
1308
-                } else {
1309
-                    $content = '';
1310
-                }
1311
-                //check if callback is valid
1312
-                if (
1313
-                    empty($content) && (
1314
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1315
-                    )
1316
-                ) {
1317
-                    EE_Error::add_error(
1318
-                        sprintf(
1319
-                            esc_html__(
1320
-                                '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.',
1321
-                                'event_espresso'
1322
-                            ),
1323
-                            $cfg['title']
1324
-                        ),
1325
-                        __FILE__,
1326
-                        __FUNCTION__,
1327
-                        __LINE__
1328
-                    );
1329
-                    return;
1330
-                }
1331
-                //setup config array for help tab method
1332
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1333
-                $_ht = array(
1334
-                    'id'       => $id,
1335
-                    'title'    => $cfg['title'],
1336
-                    'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1337
-                    'content'  => $content,
1338
-                );
1339
-                $this->_current_screen->add_help_tab($_ht);
1340
-            }
1341
-        }
1342
-    }
1343
-
1344
-
1345
-
1346
-    /**
1347
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1348
-     * an array with properties for setting up usage of the joyride plugin
1349
-     *
1350
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1351
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1352
-     *         _set_page_config() comments
1353
-     * @return void
1354
-     * @throws EE_Error
1355
-     * @throws InvalidArgumentException
1356
-     * @throws InvalidDataTypeException
1357
-     * @throws InvalidInterfaceException
1358
-     */
1359
-    protected function _add_help_tour()
1360
-    {
1361
-        $tours            = array();
1362
-        $this->_help_tour = array();
1363
-        //exit early if help tours are turned off globally
1364
-        if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1365
-            || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1366
-        ) {
1367
-            return;
1368
-        }
1369
-        //loop through _page_config to find any help_tour defined
1370
-        foreach ($this->_page_config as $route => $config) {
1371
-            //we're only going to set things up for this route
1372
-            if ($route !== $this->_req_action) {
1373
-                continue;
1374
-            }
1375
-            if (isset($config['help_tour'])) {
1376
-                foreach ($config['help_tour'] as $tour) {
1377
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1378
-                    // let's see if we can get that file...
1379
-                    // if not its possible this is a decaf route not set in caffeinated
1380
-                    // so lets try and get the caffeinated equivalent
1381
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1382
-                                                             . basename($this->_get_dir())
1383
-                                                             . '/help_tours/'
1384
-                                                             . $tour
1385
-                                                             . '.class.php' : $file_path;
1386
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1387
-                    if (! is_readable($file_path)) {
1388
-                        EE_Error::add_error(
1389
-                            sprintf(
1390
-                                esc_html__(
1391
-                                    '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',
1392
-                                    'event_espresso'
1393
-                                ),
1394
-                                $file_path,
1395
-                                $tour
1396
-                            ),
1397
-                            __FILE__,
1398
-                            __FUNCTION__,
1399
-                            __LINE__
1400
-                        );
1401
-                        return;
1402
-                    }
1403
-                    require_once $file_path;
1404
-                    if (! class_exists($tour)) {
1405
-                        $error_msg[] = sprintf(
1406
-                            esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1407
-                            $tour
1408
-                        );
1409
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(
1410
-                                esc_html__(
1411
-                                    '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.',
1412
-                                    'event_espresso'
1413
-                                ),
1414
-                                $tour,
1415
-                                '<br />',
1416
-                                $tour,
1417
-                                $this->_req_action,
1418
-                                get_class($this)
1419
-                            );
1420
-                        throw new EE_Error(implode('||', $error_msg));
1421
-                    }
1422
-                    $tour_obj                   = new $tour($this->_is_caf);
1423
-                    $tours[]                    = $tour_obj;
1424
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1425
-                }
1426
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1427
-                $end_stop_tour              = new EE_Help_Tour_final_stop($this->_is_caf);
1428
-                $tours[]                    = $end_stop_tour;
1429
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1430
-            }
1431
-        }
1432
-        if (! empty($tours)) {
1433
-            $this->_help_tour['tours'] = $tours;
1434
-        }
1435
-        // that's it!  Now that the $_help_tours property is set (or not)
1436
-        // the scripts and html should be taken care of automatically.
1437
-    }
1438
-
1439
-
1440
-
1441
-    /**
1442
-     * This simply sets up any qtips that have been defined in the page config
1443
-     *
1444
-     * @return void
1445
-     */
1446
-    protected function _add_qtips()
1447
-    {
1448
-        if (isset($this->_route_config['qtips'])) {
1449
-            $qtips = (array)$this->_route_config['qtips'];
1450
-            //load qtip loader
1451
-            $path = array(
1452
-                $this->_get_dir() . '/qtips/',
1453
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1454
-            );
1455
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1456
-        }
1457
-    }
1458
-
1459
-
1460
-
1461
-    /**
1462
-     * _set_nav_tabs
1463
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1464
-     * wish to add additional tabs or modify accordingly.
1465
-     *
1466
-     * @return void
1467
-     * @throws InvalidArgumentException
1468
-     * @throws InvalidInterfaceException
1469
-     * @throws InvalidDataTypeException
1470
-     */
1471
-    protected function _set_nav_tabs()
1472
-    {
1473
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1474
-        $i = 0;
1475
-        foreach ($this->_page_config as $slug => $config) {
1476
-            if (
1477
-                ! is_array($config)
1478
-                || (
1479
-                    is_array($config)
1480
-                    && (
1481
-                        (isset($config['nav']) && ! $config['nav'])
1482
-                        || ! isset($config['nav'])
1483
-                    )
1484
-                )
1485
-            ) {
1486
-                continue;
1487
-            }
1488
-            //no nav tab for this config
1489
-            //check for persistent flag
1490
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1491
-                // nav tab is only to appear when route requested.
1492
-                continue;
1493
-            }
1494
-            if (! $this->check_user_access($slug, true)) {
1495
-                // no nav tab because current user does not have access.
1496
-                continue;
1497
-            }
1498
-            $css_class              = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1499
-            $this->_nav_tabs[$slug] = array(
1500
-                'url'       => isset($config['nav']['url'])
1501
-                    ? $config['nav']['url']
1502
-                    : self::add_query_args_and_nonce(
1503
-                        array('action' => $slug),
1504
-                        $this->_admin_base_url
1505
-                    ),
1506
-                'link_text' => isset($config['nav']['label'])
1507
-                    ? $config['nav']['label']
1508
-                    : ucwords(
1509
-                        str_replace('_', ' ', $slug)
1510
-                    ),
1511
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1512
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1513
-            );
1514
-            $i++;
1515
-        }
1516
-        //if $this->_nav_tabs is empty then lets set the default
1517
-        if (empty($this->_nav_tabs)) {
1518
-            $this->_nav_tabs[$this->_default_nav_tab_name] = array(
1519
-                'url'       => $this->_admin_base_url,
1520
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1521
-                'css_class' => 'nav-tab-active',
1522
-                'order'     => 10,
1523
-            );
1524
-        }
1525
-        //now let's sort the tabs according to order
1526
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1527
-    }
1528
-
1529
-
1530
-
1531
-    /**
1532
-     * _set_current_labels
1533
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1534
-     * property array
1535
-     *
1536
-     * @return void
1537
-     */
1538
-    private function _set_current_labels()
1539
-    {
1540
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1541
-            foreach ($this->_route_config['labels'] as $label => $text) {
1542
-                if (is_array($text)) {
1543
-                    foreach ($text as $sublabel => $subtext) {
1544
-                        $this->_labels[$label][$sublabel] = $subtext;
1545
-                    }
1546
-                } else {
1547
-                    $this->_labels[$label] = $text;
1548
-                }
1549
-            }
1550
-        }
1551
-    }
1552
-
1553
-
1554
-
1555
-    /**
1556
-     *        verifies user access for this admin page
1557
-     *
1558
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1559
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1560
-     *                               return false if verify fail.
1561
-     * @return bool
1562
-     * @throws InvalidArgumentException
1563
-     * @throws InvalidDataTypeException
1564
-     * @throws InvalidInterfaceException
1565
-     */
1566
-    public function check_user_access($route_to_check = '', $verify_only = false)
1567
-    {
1568
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1569
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1570
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1571
-                          && is_array(
1572
-                              $this->_page_routes[$route_to_check]
1573
-                          )
1574
-                          && ! empty($this->_page_routes[$route_to_check]['capability'])
1575
-            ? $this->_page_routes[$route_to_check]['capability'] : null;
1576
-        if (empty($capability) && empty($route_to_check)) {
1577
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1578
-                : $this->_route['capability'];
1579
-        } else {
1580
-            $capability = empty($capability) ? 'manage_options' : $capability;
1581
-        }
1582
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1583
-        if (
1584
-            ! defined('DOING_AJAX')
1585
-            && (
1586
-                ! function_exists('is_admin')
1587
-                || ! EE_Registry::instance()->CAP->current_user_can(
1588
-                    $capability,
1589
-                    $this->page_slug
1590
-                    . '_'
1591
-                    . $route_to_check,
1592
-                    $id
1593
-                )
1594
-            )
1595
-        ) {
1596
-            if ($verify_only) {
1597
-                return false;
1598
-            }
1599
-            if (is_user_logged_in()) {
1600
-                wp_die(__('You do not have access to this route.', 'event_espresso'));
1601
-            } else {
1602
-                return false;
1603
-            }
1604
-        }
1605
-        return true;
1606
-    }
1607
-
1608
-
1609
-
1610
-    /**
1611
-     * admin_init_global
1612
-     * This runs all the code that we want executed within the WP admin_init hook.
1613
-     * This method executes for ALL EE Admin pages.
1614
-     *
1615
-     * @return void
1616
-     */
1617
-    public function admin_init_global()
1618
-    {
1619
-    }
1620
-
1621
-
1622
-
1623
-    /**
1624
-     * wp_loaded_global
1625
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1626
-     * EE_Admin page and will execute on every EE Admin Page load
1627
-     *
1628
-     * @return void
1629
-     */
1630
-    public function wp_loaded()
1631
-    {
1632
-    }
1633
-
1634
-
1635
-
1636
-    /**
1637
-     * admin_notices
1638
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1639
-     * ALL EE_Admin pages.
1640
-     *
1641
-     * @return void
1642
-     */
1643
-    public function admin_notices_global()
1644
-    {
1645
-        $this->_display_no_javascript_warning();
1646
-        $this->_display_espresso_notices();
1647
-    }
1648
-
1649
-
1650
-
1651
-    public function network_admin_notices_global()
1652
-    {
1653
-        $this->_display_no_javascript_warning();
1654
-        $this->_display_espresso_notices();
1655
-    }
1656
-
1657
-
1658
-
1659
-    /**
1660
-     * admin_footer_scripts_global
1661
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1662
-     * will apply on ALL EE_Admin pages.
1663
-     *
1664
-     * @return void
1665
-     */
1666
-    public function admin_footer_scripts_global()
1667
-    {
1668
-        $this->_add_admin_page_ajax_loading_img();
1669
-        $this->_add_admin_page_overlay();
1670
-        //if metaboxes are present we need to add the nonce field
1671
-        if (
1672
-             isset($this->_route_config['metaboxes'])
1673
-             || isset($this->_route_config['list_table'])
1674
-             || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1675
-        ) {
1676
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1677
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1678
-        }
1679
-    }
1680
-
1681
-
1682
-
1683
-    /**
1684
-     * admin_footer_global
1685
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1686
-     * ALL EE_Admin Pages.
1687
-     *
1688
-     * @return void
1689
-     * @throws EE_Error
1690
-     */
1691
-    public function admin_footer_global()
1692
-    {
1693
-        //dialog container for dialog helper
1694
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1695
-        $d_cont .= '<div class="ee-notices"></div>';
1696
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1697
-        $d_cont .= '</div>';
1698
-        echo $d_cont;
1699
-        //help tour stuff?
1700
-        if (isset($this->_help_tour[$this->_req_action])) {
1701
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1702
-        }
1703
-        //current set timezone for timezone js
1704
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1705
-    }
1706
-
1707
-
1708
-
1709
-    /**
1710
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1711
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1712
-     * help popups then in your templates or your content you set "triggers" for the content using the
1713
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1714
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1715
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1716
-     * for the
1717
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1718
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1719
-     *    'help_trigger_id' => array(
1720
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1721
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1722
-     *    )
1723
-     * );
1724
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1725
-     *
1726
-     * @param array $help_array
1727
-     * @param bool  $display
1728
-     * @return string content
1729
-     * @throws DomainException
1730
-     * @throws EE_Error
1731
-     */
1732
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1733
-    {
1734
-        $content       = '';
1735
-        $help_array    = empty($help_array) ? $this->_get_help_content() : $help_array;
1736
-        //loop through the array and setup content
1737
-        foreach ($help_array as $trigger => $help) {
1738
-            //make sure the array is setup properly
1739
-            if (! isset($help['title']) || ! isset($help['content'])) {
1740
-                throw new EE_Error(
1741
-                    esc_html__(
1742
-                        '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',
1743
-                        'event_espresso'
1744
-                    )
1745
-                );
1746
-            }
1747
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1748
-            $template_args = array(
1749
-                'help_popup_id'      => $trigger,
1750
-                'help_popup_title'   => $help['title'],
1751
-                'help_popup_content' => $help['content'],
1752
-            );
1753
-            $content       .= EEH_Template::display_template(
1754
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1755
-                $template_args,
1756
-                true
1757
-            );
1758
-        }
1759
-        if ($display) {
1760
-            echo $content;
1761
-            return '';
1762
-        }
1763
-        return $content;
1764
-    }
1765
-
1766
-
1767
-
1768
-    /**
1769
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1770
-     *
1771
-     * @return array properly formatted array for help popup content
1772
-     * @throws EE_Error
1773
-     */
1774
-    private function _get_help_content()
1775
-    {
1776
-        //what is the method we're looking for?
1777
-        $method_name = '_help_popup_content_' . $this->_req_action;
1778
-        //if method doesn't exist let's get out.
1779
-        if (! method_exists($this, $method_name)) {
1780
-            return array();
1781
-        }
1782
-        //k we're good to go let's retrieve the help array
1783
-        $help_array = call_user_func(array($this, $method_name));
1784
-        //make sure we've got an array!
1785
-        if (! is_array($help_array)) {
1786
-            throw new EE_Error(
1787
-                esc_html__(
1788
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1789
-                    'event_espresso'
1790
-                )
1791
-            );
1792
-        }
1793
-        return $help_array;
1794
-    }
1795
-
1796
-
1797
-
1798
-    /**
1799
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1800
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1801
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1802
-     *
1803
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1804
-     * @param boolean $display    if false then we return the trigger string
1805
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1806
-     * @return string
1807
-     * @throws DomainException
1808
-     * @throws EE_Error
1809
-     */
1810
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1811
-    {
1812
-        if (defined('DOING_AJAX')) {
1813
-            return '';
1814
-        }
1815
-        //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
1816
-        $help_array   = $this->_get_help_content();
1817
-        $help_content = '';
1818
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1819
-            $help_array[$trigger_id] = array(
1820
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1821
-                'content' => esc_html__(
1822
-                    '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.)',
1823
-                    'event_espresso'
1824
-                ),
1825
-            );
1826
-            $help_content            = $this->_set_help_popup_content($help_array, false);
1827
-        }
1828
-        //let's setup the trigger
1829
-        $content = '<a class="ee-dialog" href="?height='
1830
-                   . $dimensions[0]
1831
-                   . '&width='
1832
-                   . $dimensions[1]
1833
-                   . '&inlineId='
1834
-                   . $trigger_id
1835
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1836
-        $content .= $help_content;
1837
-        if ($display) {
1838
-            echo $content;
1839
-            return  '';
1840
-        }
1841
-        return $content;
1842
-    }
1843
-
1844
-
1845
-
1846
-    /**
1847
-     * _add_global_screen_options
1848
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1849
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1850
-     *
1851
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1852
-     *         see also WP_Screen object documents...
1853
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1854
-     * @abstract
1855
-     * @return void
1856
-     */
1857
-    private function _add_global_screen_options()
1858
-    {
1859
-    }
1860
-
1861
-
1862
-
1863
-    /**
1864
-     * _add_global_feature_pointers
1865
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1866
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1867
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1868
-     *
1869
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1870
-     *         extended) also see:
1871
-     * @link   http://eamann.com/tech/wordpress-portland/
1872
-     * @abstract
1873
-     * @return void
1874
-     */
1875
-    private function _add_global_feature_pointers()
1876
-    {
1877
-    }
1878
-
1879
-
1880
-
1881
-    /**
1882
-     * load_global_scripts_styles
1883
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1884
-     *
1885
-     * @return void
1886
-     * @throws EE_Error
1887
-     */
1888
-    public function load_global_scripts_styles()
1889
-    {
1890
-        /** STYLES **/
1891
-        // add debugging styles
1892
-        if (WP_DEBUG) {
1893
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1894
-        }
1895
-        // register all styles
1896
-        wp_register_style(
1897
-            'espresso-ui-theme',
1898
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1899
-            array(),
1900
-            EVENT_ESPRESSO_VERSION
1901
-        );
1902
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1903
-        //helpers styles
1904
-        wp_register_style(
1905
-            'ee-text-links',
1906
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1907
-            array(),
1908
-            EVENT_ESPRESSO_VERSION
1909
-        );
1910
-        /** SCRIPTS **/
1911
-        //register all scripts
1912
-        wp_register_script(
1913
-            'ee-dialog',
1914
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1915
-            array('jquery', 'jquery-ui-draggable'),
1916
-            EVENT_ESPRESSO_VERSION,
1917
-            true
1918
-        );
1919
-        wp_register_script(
1920
-            'ee_admin_js',
1921
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1922
-            array('espresso_core', 'ee-parse-uri', 'ee-dialog'),
1923
-            EVENT_ESPRESSO_VERSION,
1924
-            true
1925
-        );
1926
-        wp_register_script(
1927
-            'jquery-ui-timepicker-addon',
1928
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1929
-            array('jquery-ui-datepicker', 'jquery-ui-slider'),
1930
-            EVENT_ESPRESSO_VERSION,
1931
-            true
1932
-        );
1933
-        add_filter('FHEE_load_joyride', '__return_true');
1934
-        //script for sorting tables
1935
-        wp_register_script(
1936
-            'espresso_ajax_table_sorting',
1937
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1938
-            array('ee_admin_js', 'jquery-ui-sortable'),
1939
-            EVENT_ESPRESSO_VERSION,
1940
-            true
1941
-        );
1942
-        //script for parsing uri's
1943
-        wp_register_script(
1944
-            'ee-parse-uri',
1945
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1946
-            array(),
1947
-            EVENT_ESPRESSO_VERSION,
1948
-            true
1949
-        );
1950
-        //and parsing associative serialized form elements
1951
-        wp_register_script(
1952
-            'ee-serialize-full-array',
1953
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1954
-            array('jquery'),
1955
-            EVENT_ESPRESSO_VERSION,
1956
-            true
1957
-        );
1958
-        //helpers scripts
1959
-        wp_register_script(
1960
-            'ee-text-links',
1961
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1962
-            array('jquery'),
1963
-            EVENT_ESPRESSO_VERSION,
1964
-            true
1965
-        );
1966
-        wp_register_script(
1967
-            'ee-moment-core',
1968
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1969
-            array(),
1970
-            EVENT_ESPRESSO_VERSION,
1971
-            true
1972
-        );
1973
-        wp_register_script(
1974
-            'ee-moment',
1975
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1976
-            array('ee-moment-core'),
1977
-            EVENT_ESPRESSO_VERSION,
1978
-            true
1979
-        );
1980
-        wp_register_script(
1981
-            'ee-datepicker',
1982
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1983
-            array('jquery-ui-timepicker-addon', 'ee-moment'),
1984
-            EVENT_ESPRESSO_VERSION,
1985
-            true
1986
-        );
1987
-        //google charts
1988
-        wp_register_script(
1989
-            'google-charts',
1990
-            'https://www.gstatic.com/charts/loader.js',
1991
-            array(),
1992
-            EVENT_ESPRESSO_VERSION,
1993
-            false
1994
-        );
1995
-        // ENQUEUE ALL BASICS BY DEFAULT
1996
-        wp_enqueue_style('ee-admin-css');
1997
-        wp_enqueue_script('ee_admin_js');
1998
-        wp_enqueue_script('ee-accounting');
1999
-        wp_enqueue_script('jquery-validate');
2000
-        //taking care of metaboxes
2001
-        if (
2002
-            empty($this->_cpt_route)
2003
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
2004
-        ) {
2005
-            wp_enqueue_script('dashboard');
2006
-        }
2007
-        // LOCALIZED DATA
2008
-        //localize script for ajax lazy loading
2009
-        $lazy_loader_container_ids = apply_filters(
2010
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
2011
-            array('espresso_news_post_box_content')
2012
-        );
2013
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
2014
-        /**
2015
-         * help tour stuff
2016
-         */
2017
-        if (! empty($this->_help_tour)) {
2018
-            //register the js for kicking things off
2019
-            wp_enqueue_script(
2020
-                'ee-help-tour',
2021
-                EE_ADMIN_URL . 'assets/ee-help-tour.js',
2022
-                array('jquery-joyride'),
2023
-                EVENT_ESPRESSO_VERSION,
2024
-                true
2025
-            );
2026
-            $tours = array();
2027
-            //setup tours for the js tour object
2028
-            foreach ($this->_help_tour['tours'] as $tour) {
2029
-                if ($tour instanceof EE_Help_Tour) {
2030
-                    $tours[] = array(
2031
-                        'id'      => $tour->get_slug(),
2032
-                        'options' => $tour->get_options(),
2033
-                    );
2034
-                }
2035
-            }
2036
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2037
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2038
-        }
2039
-    }
2040
-
2041
-
2042
-
2043
-    /**
2044
-     *        admin_footer_scripts_eei18n_js_strings
2045
-     *
2046
-     * @return        void
2047
-     */
2048
-    public function admin_footer_scripts_eei18n_js_strings()
2049
-    {
2050
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
2051
-        EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2052
-            '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!!!',
2053
-            'event_espresso'
2054
-        );
2055
-        EE_Registry::$i18n_js_strings['January']        = esc_html__('January', 'event_espresso');
2056
-        EE_Registry::$i18n_js_strings['February']       = esc_html__('February', 'event_espresso');
2057
-        EE_Registry::$i18n_js_strings['March']          = esc_html__('March', 'event_espresso');
2058
-        EE_Registry::$i18n_js_strings['April']          = esc_html__('April', 'event_espresso');
2059
-        EE_Registry::$i18n_js_strings['May']            = esc_html__('May', 'event_espresso');
2060
-        EE_Registry::$i18n_js_strings['June']           = esc_html__('June', 'event_espresso');
2061
-        EE_Registry::$i18n_js_strings['July']           = esc_html__('July', 'event_espresso');
2062
-        EE_Registry::$i18n_js_strings['August']         = esc_html__('August', 'event_espresso');
2063
-        EE_Registry::$i18n_js_strings['September']      = esc_html__('September', 'event_espresso');
2064
-        EE_Registry::$i18n_js_strings['October']        = esc_html__('October', 'event_espresso');
2065
-        EE_Registry::$i18n_js_strings['November']       = esc_html__('November', 'event_espresso');
2066
-        EE_Registry::$i18n_js_strings['December']       = esc_html__('December', 'event_espresso');
2067
-        EE_Registry::$i18n_js_strings['Jan']            = esc_html__('Jan', 'event_espresso');
2068
-        EE_Registry::$i18n_js_strings['Feb']            = esc_html__('Feb', 'event_espresso');
2069
-        EE_Registry::$i18n_js_strings['Mar']            = esc_html__('Mar', 'event_espresso');
2070
-        EE_Registry::$i18n_js_strings['Apr']            = esc_html__('Apr', 'event_espresso');
2071
-        EE_Registry::$i18n_js_strings['May']            = esc_html__('May', 'event_espresso');
2072
-        EE_Registry::$i18n_js_strings['Jun']            = esc_html__('Jun', 'event_espresso');
2073
-        EE_Registry::$i18n_js_strings['Jul']            = esc_html__('Jul', 'event_espresso');
2074
-        EE_Registry::$i18n_js_strings['Aug']            = esc_html__('Aug', 'event_espresso');
2075
-        EE_Registry::$i18n_js_strings['Sep']            = esc_html__('Sep', 'event_espresso');
2076
-        EE_Registry::$i18n_js_strings['Oct']            = esc_html__('Oct', 'event_espresso');
2077
-        EE_Registry::$i18n_js_strings['Nov']            = esc_html__('Nov', 'event_espresso');
2078
-        EE_Registry::$i18n_js_strings['Dec']            = esc_html__('Dec', 'event_espresso');
2079
-        EE_Registry::$i18n_js_strings['Sunday']         = esc_html__('Sunday', 'event_espresso');
2080
-        EE_Registry::$i18n_js_strings['Monday']         = esc_html__('Monday', 'event_espresso');
2081
-        EE_Registry::$i18n_js_strings['Tuesday']        = esc_html__('Tuesday', 'event_espresso');
2082
-        EE_Registry::$i18n_js_strings['Wednesday']      = esc_html__('Wednesday', 'event_espresso');
2083
-        EE_Registry::$i18n_js_strings['Thursday']       = esc_html__('Thursday', 'event_espresso');
2084
-        EE_Registry::$i18n_js_strings['Friday']         = esc_html__('Friday', 'event_espresso');
2085
-        EE_Registry::$i18n_js_strings['Saturday']       = esc_html__('Saturday', 'event_espresso');
2086
-        EE_Registry::$i18n_js_strings['Sun']            = esc_html__('Sun', 'event_espresso');
2087
-        EE_Registry::$i18n_js_strings['Mon']            = esc_html__('Mon', 'event_espresso');
2088
-        EE_Registry::$i18n_js_strings['Tue']            = esc_html__('Tue', 'event_espresso');
2089
-        EE_Registry::$i18n_js_strings['Wed']            = esc_html__('Wed', 'event_espresso');
2090
-        EE_Registry::$i18n_js_strings['Thu']            = esc_html__('Thu', 'event_espresso');
2091
-        EE_Registry::$i18n_js_strings['Fri']            = esc_html__('Fri', 'event_espresso');
2092
-        EE_Registry::$i18n_js_strings['Sat']            = esc_html__('Sat', 'event_espresso');
2093
-    }
2094
-
2095
-
2096
-
2097
-    /**
2098
-     *        load enhanced xdebug styles for ppl with failing eyesight
2099
-     *
2100
-     * @return        void
2101
-     */
2102
-    public function add_xdebug_style()
2103
-    {
2104
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2105
-    }
2106
-
2107
-
2108
-    /************************/
2109
-    /** LIST TABLE METHODS **/
2110
-    /************************/
2111
-    /**
2112
-     * this sets up the list table if the current view requires it.
2113
-     *
2114
-     * @return void
2115
-     * @throws EE_Error
2116
-     */
2117
-    protected function _set_list_table()
2118
-    {
2119
-        //first is this a list_table view?
2120
-        if (! isset($this->_route_config['list_table'])) {
2121
-            return;
2122
-        } //not a list_table view so get out.
2123
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2124
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2125
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2126
-            //user error msg
2127
-            $error_msg = esc_html__(
2128
-                'An error occurred. The requested list table views could not be found.',
2129
-                'event_espresso'
2130
-            );
2131
-            //developer error msg
2132
-            $error_msg .= '||' . sprintf(
2133
-                    esc_html__(
2134
-                        '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.',
2135
-                        'event_espresso'
2136
-                    ),
2137
-                    $this->_req_action,
2138
-                    $list_table_view
2139
-                );
2140
-            throw new EE_Error($error_msg);
2141
-        }
2142
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2143
-        $this->_views = apply_filters(
2144
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2145
-            $this->_views
2146
-        );
2147
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2148
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2149
-        $this->_set_list_table_view();
2150
-        $this->_set_list_table_object();
2151
-    }
2152
-
2153
-
2154
-
2155
-    /**
2156
-     * set current view for List Table
2157
-     *
2158
-     * @return void
2159
-     */
2160
-    protected function _set_list_table_view()
2161
-    {
2162
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2163
-        // looking at active items or dumpster diving ?
2164
-        if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2165
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2166
-        } else {
2167
-            $this->_view = sanitize_key($this->_req_data['status']);
2168
-        }
2169
-    }
2170
-
2171
-
2172
-    /**
2173
-     * _set_list_table_object
2174
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2175
-     *
2176
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2177
-     * @throws \InvalidArgumentException
2178
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2179
-     * @throws EE_Error
2180
-     * @throws InvalidInterfaceException
2181
-     */
2182
-    protected function _set_list_table_object()
2183
-    {
2184
-        if (isset($this->_route_config['list_table'])) {
2185
-            if (! class_exists($this->_route_config['list_table'])) {
2186
-                throw new EE_Error(
2187
-                    sprintf(
2188
-                        esc_html__(
2189
-                            '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.',
2190
-                            'event_espresso'
2191
-                        ),
2192
-                        $this->_route_config['list_table'],
2193
-                        get_class($this)
2194
-                    )
2195
-                );
2196
-            }
2197
-            $this->_list_table_object = LoaderFactory::getLoader()->getShared(
2198
-                $this->_route_config['list_table'],
2199
-                array($this)
2200
-            );
2201
-        }
2202
-    }
2203
-
2204
-
2205
-
2206
-    /**
2207
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2208
-     *
2209
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2210
-     *                                                    urls.  The array should be indexed by the view it is being
2211
-     *                                                    added to.
2212
-     * @return array
2213
-     */
2214
-    public function get_list_table_view_RLs($extra_query_args = array())
2215
-    {
2216
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2217
-        if (empty($this->_views)) {
2218
-            $this->_views = array();
2219
-        }
2220
-        // cycle thru views
2221
-        foreach ($this->_views as $key => $view) {
2222
-            $query_args = array();
2223
-            // check for current view
2224
-            $this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2225
-            $query_args['action']                      = $this->_req_action;
2226
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2227
-            $query_args['status']                      = $view['slug'];
2228
-            //merge any other arguments sent in.
2229
-            if (isset($extra_query_args[$view['slug']])) {
2230
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
2231
-            }
2232
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2233
-        }
2234
-        return $this->_views;
2235
-    }
2236
-
2237
-
2238
-
2239
-    /**
2240
-     * _entries_per_page_dropdown
2241
-     * generates a drop down box for selecting the number of visible rows in an admin page list table
2242
-     *
2243
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2244
-     *         WP does it.
2245
-     * @param int $max_entries total number of rows in the table
2246
-     * @return string
2247
-     */
2248
-    protected function _entries_per_page_dropdown($max_entries = 0)
2249
-    {
2250
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2251
-        $values   = array(10, 25, 50, 100);
2252
-        $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2253
-        if ($max_entries) {
2254
-            $values[] = $max_entries;
2255
-            sort($values);
2256
-        }
2257
-        $entries_per_page_dropdown = '
126
+	/**
127
+	 * @var string $_req_action
128
+	 */
129
+	protected $_req_action;
130
+
131
+	/**
132
+	 * @var string $_req_nonce
133
+	 */
134
+	protected $_req_nonce;
135
+
136
+	//search related
137
+	protected $_search_btn_label;
138
+
139
+	protected $_search_box_callback;
140
+
141
+	/**
142
+	 * WP Current Screen object
143
+	 *
144
+	 * @var WP_Screen
145
+	 */
146
+	protected $_current_screen;
147
+
148
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
149
+	protected $_hook_obj;
150
+
151
+	//for holding incoming request data
152
+	protected $_req_data;
153
+
154
+	// yes / no array for admin form fields
155
+	protected $_yes_no_values = array();
156
+
157
+	//some default things shared by all child classes
158
+	protected $_default_espresso_metaboxes;
159
+
160
+	/**
161
+	 *    EE_Registry Object
162
+	 *
163
+	 * @var    EE_Registry
164
+	 */
165
+	protected $EE = null;
166
+
167
+
168
+
169
+	/**
170
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
171
+	 *
172
+	 * @var boolean
173
+	 */
174
+	protected $_is_caf = false;
175
+
176
+
177
+
178
+	/**
179
+	 * @Constructor
180
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
181
+	 * @throws EE_Error
182
+	 * @throws InvalidArgumentException
183
+	 * @throws ReflectionException
184
+	 * @throws InvalidDataTypeException
185
+	 * @throws InvalidInterfaceException
186
+	 */
187
+	public function __construct($routing = true)
188
+	{
189
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
190
+			$this->_is_caf = true;
191
+		}
192
+		$this->_yes_no_values = array(
193
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
194
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
195
+		);
196
+		//set the _req_data property.
197
+		$this->_req_data = array_merge($_GET, $_POST);
198
+		//routing enabled?
199
+		$this->_routing = $routing;
200
+		//set initial page props (child method)
201
+		$this->_init_page_props();
202
+		//set global defaults
203
+		$this->_set_defaults();
204
+		//set early because incoming requests could be ajax related and we need to register those hooks.
205
+		$this->_global_ajax_hooks();
206
+		$this->_ajax_hooks();
207
+		//other_page_hooks have to be early too.
208
+		$this->_do_other_page_hooks();
209
+		//This just allows us to have extending classes do something specific
210
+		// before the parent constructor runs _page_setup().
211
+		if (method_exists($this, '_before_page_setup')) {
212
+			$this->_before_page_setup();
213
+		}
214
+		//set up page dependencies
215
+		$this->_page_setup();
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * _init_page_props
222
+	 * Child classes use to set at least the following properties:
223
+	 * $page_slug.
224
+	 * $page_label.
225
+	 *
226
+	 * @abstract
227
+	 * @return void
228
+	 */
229
+	abstract protected function _init_page_props();
230
+
231
+
232
+
233
+	/**
234
+	 * _ajax_hooks
235
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
236
+	 * Note: within the ajax callback methods.
237
+	 *
238
+	 * @abstract
239
+	 * @return void
240
+	 */
241
+	abstract protected function _ajax_hooks();
242
+
243
+
244
+
245
+	/**
246
+	 * _define_page_props
247
+	 * child classes define page properties in here.  Must include at least:
248
+	 * $_admin_base_url = base_url for all admin pages
249
+	 * $_admin_page_title = default admin_page_title for admin pages
250
+	 * $_labels = array of default labels for various automatically generated elements:
251
+	 *    array(
252
+	 *        'buttons' => array(
253
+	 *            'add' => esc_html__('label for add new button'),
254
+	 *            'edit' => esc_html__('label for edit button'),
255
+	 *            'delete' => esc_html__('label for delete button')
256
+	 *            )
257
+	 *        )
258
+	 *
259
+	 * @abstract
260
+	 * @return void
261
+	 */
262
+	abstract protected function _define_page_props();
263
+
264
+
265
+
266
+	/**
267
+	 * _set_page_routes
268
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
269
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
270
+	 * have a 'default' route. Here's the format
271
+	 * $this->_page_routes = array(
272
+	 *        'default' => array(
273
+	 *            'func' => '_default_method_handling_route',
274
+	 *            'args' => array('array','of','args'),
275
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
276
+	 *            ajax request, backend processing)
277
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
278
+	 *            headers route after.  The string you enter here should match the defined route reference for a
279
+	 *            headers sent route.
280
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
281
+	 *            this route.
282
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
283
+	 *            checks).
284
+	 *        ),
285
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
286
+	 *        handling method.
287
+	 *        )
288
+	 * )
289
+	 *
290
+	 * @abstract
291
+	 * @return void
292
+	 */
293
+	abstract protected function _set_page_routes();
294
+
295
+
296
+
297
+	/**
298
+	 * _set_page_config
299
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
300
+	 * array corresponds to the page_route for the loaded page. Format:
301
+	 * $this->_page_config = array(
302
+	 *        'default' => array(
303
+	 *            'labels' => array(
304
+	 *                'buttons' => array(
305
+	 *                    'add' => esc_html__('label for adding item'),
306
+	 *                    'edit' => esc_html__('label for editing item'),
307
+	 *                    'delete' => esc_html__('label for deleting item')
308
+	 *                ),
309
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
310
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
311
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
312
+	 *            _define_page_props() method
313
+	 *            'nav' => array(
314
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
315
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
316
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
317
+	 *                'order' => 10, //required to indicate tab position.
318
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
319
+	 *                displayed then add this parameter.
320
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
321
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
322
+	 *            metaboxes set for eventespresso admin pages.
323
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
324
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
325
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
326
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
327
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
328
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
329
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
330
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
331
+	 *            want to display.
332
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
333
+	 *                'tab_id' => array(
334
+	 *                    'title' => 'tab_title',
335
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
336
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
337
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
338
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
339
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
340
+	 *                    attempt to use the callback which should match the name of a method in the class
341
+	 *                    ),
342
+	 *                'tab2_id' => array(
343
+	 *                    'title' => 'tab2 title',
344
+	 *                    'filename' => 'file_name_2'
345
+	 *                    'callback' => 'callback_method_for_content',
346
+	 *                 ),
347
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
348
+	 *            help tab area on an admin page. @link
349
+	 *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
350
+	 *            'help_tour' => array(
351
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
352
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
353
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
354
+	 *            ),
355
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
356
+	 *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
357
+	 *            just set
358
+	 *            'require_nonce' to FALSE
359
+	 *            )
360
+	 * )
361
+	 *
362
+	 * @abstract
363
+	 * @return void
364
+	 */
365
+	abstract protected function _set_page_config();
366
+
367
+
368
+
369
+
370
+
371
+	/** end sample help_tour methods **/
372
+	/**
373
+	 * _add_screen_options
374
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
375
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
376
+	 * to a particular view.
377
+	 *
378
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
379
+	 *         see also WP_Screen object documents...
380
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
381
+	 * @abstract
382
+	 * @return void
383
+	 */
384
+	abstract protected function _add_screen_options();
385
+
386
+
387
+
388
+	/**
389
+	 * _add_feature_pointers
390
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
391
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
392
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
393
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
394
+	 * extended) also see:
395
+	 *
396
+	 * @link   http://eamann.com/tech/wordpress-portland/
397
+	 * @abstract
398
+	 * @return void
399
+	 */
400
+	abstract protected function _add_feature_pointers();
401
+
402
+
403
+
404
+	/**
405
+	 * load_scripts_styles
406
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
407
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
408
+	 * scripts/styles per view by putting them in a dynamic function in this format
409
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
410
+	 *
411
+	 * @abstract
412
+	 * @return void
413
+	 */
414
+	abstract public function load_scripts_styles();
415
+
416
+
417
+
418
+	/**
419
+	 * admin_init
420
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
421
+	 * all pages/views loaded by child class.
422
+	 *
423
+	 * @abstract
424
+	 * @return void
425
+	 */
426
+	abstract public function admin_init();
427
+
428
+
429
+
430
+	/**
431
+	 * admin_notices
432
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
433
+	 * all pages/views loaded by child class.
434
+	 *
435
+	 * @abstract
436
+	 * @return void
437
+	 */
438
+	abstract public function admin_notices();
439
+
440
+
441
+
442
+	/**
443
+	 * admin_footer_scripts
444
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
445
+	 * will apply to all pages/views loaded by child class.
446
+	 *
447
+	 * @return void
448
+	 */
449
+	abstract public function admin_footer_scripts();
450
+
451
+
452
+
453
+	/**
454
+	 * admin_footer
455
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
456
+	 * apply to all pages/views loaded by child class.
457
+	 *
458
+	 * @return void
459
+	 */
460
+	public function admin_footer()
461
+	{
462
+	}
463
+
464
+
465
+
466
+	/**
467
+	 * _global_ajax_hooks
468
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
469
+	 * Note: within the ajax callback methods.
470
+	 *
471
+	 * @abstract
472
+	 * @return void
473
+	 */
474
+	protected function _global_ajax_hooks()
475
+	{
476
+		//for lazy loading of metabox content
477
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
478
+	}
479
+
480
+
481
+
482
+	public function ajax_metabox_content()
483
+	{
484
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
485
+		$url       = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
486
+		self::cached_rss_display($contentid, $url);
487
+		wp_die();
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 * _page_setup
494
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
495
+	 * doesn't match the object.
496
+	 *
497
+	 * @final
498
+	 * @return void
499
+	 * @throws EE_Error
500
+	 * @throws InvalidArgumentException
501
+	 * @throws ReflectionException
502
+	 * @throws InvalidDataTypeException
503
+	 * @throws InvalidInterfaceException
504
+	 */
505
+	final protected function _page_setup()
506
+	{
507
+		//requires?
508
+		//admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
509
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
510
+		//next verify if we need to load anything...
511
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
512
+		$this->page_folder   = strtolower(
513
+			str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
514
+		);
515
+		global $ee_menu_slugs;
516
+		$ee_menu_slugs = (array)$ee_menu_slugs;
517
+		if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) {
518
+			return;
519
+		}
520
+		// 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
521
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
522
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
523
+				? $this->_req_data['action2']
524
+				: $this->_req_data['action'];
525
+		}
526
+		// then set blank or -1 action values to 'default'
527
+		$this->_req_action = isset($this->_req_data['action'])
528
+							 && ! empty($this->_req_data['action'])
529
+							 && $this->_req_data['action'] !== '-1'
530
+			? sanitize_key($this->_req_data['action'])
531
+			: 'default';
532
+		// if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
533
+		//  This covers cases where we're coming in from a list table that isn't on the default route.
534
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
535
+			? $this->_req_data['route'] : $this->_req_action;
536
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
537
+		$this->_req_action   = defined('DOING_AJAX') && isset($this->_req_data['route'])
538
+			? $this->_req_data['route']
539
+			: $this->_req_action;
540
+		$this->_current_view = $this->_req_action;
541
+		$this->_req_nonce    = $this->_req_action . '_nonce';
542
+		$this->_define_page_props();
543
+		$this->_current_page_view_url = add_query_arg(
544
+			array('page' => $this->_current_page, 'action' => $this->_current_view),
545
+			$this->_admin_base_url
546
+		);
547
+		//default things
548
+		$this->_default_espresso_metaboxes = array(
549
+			'_espresso_news_post_box',
550
+			'_espresso_links_post_box',
551
+			'_espresso_ratings_request',
552
+			'_espresso_sponsors_post_box',
553
+		);
554
+		//set page configs
555
+		$this->_set_page_routes();
556
+		$this->_set_page_config();
557
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
558
+		if (isset($this->_req_data['wp_referer'])) {
559
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
560
+		}
561
+		//for caffeinated and other extended functionality.
562
+		//  If there is a _extend_page_config method
563
+		// then let's run that to modify the all the various page configuration arrays
564
+		if (method_exists($this, '_extend_page_config')) {
565
+			$this->_extend_page_config();
566
+		}
567
+		//for CPT and other extended functionality.
568
+		// If there is an _extend_page_config_for_cpt
569
+		// then let's run that to modify all the various page configuration arrays.
570
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
571
+			$this->_extend_page_config_for_cpt();
572
+		}
573
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
574
+		$this->_page_routes = apply_filters(
575
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
576
+			$this->_page_routes,
577
+			$this
578
+		);
579
+		$this->_page_config = apply_filters(
580
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
581
+			$this->_page_config,
582
+			$this
583
+		);
584
+		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
585
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
586
+		if (
587
+			method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)
588
+		) {
589
+			add_action(
590
+				'AHEE__EE_Admin_Page__route_admin_request',
591
+				array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
592
+				10,
593
+				2
594
+			);
595
+		}
596
+		//next route only if routing enabled
597
+		if ($this->_routing && ! defined('DOING_AJAX')) {
598
+			$this->_verify_routes();
599
+			//next let's just check user_access and kill if no access
600
+			$this->check_user_access();
601
+			if ($this->_is_UI_request) {
602
+				//admin_init stuff - global, all views for this page class, specific view
603
+				add_action('admin_init', array($this, 'admin_init'), 10);
604
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
605
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
606
+				}
607
+			} else {
608
+				//hijack regular WP loading and route admin request immediately
609
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
610
+				$this->route_admin_request();
611
+			}
612
+		}
613
+	}
614
+
615
+
616
+
617
+	/**
618
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
619
+	 *
620
+	 * @return void
621
+	 * @throws ReflectionException
622
+	 * @throws EE_Error
623
+	 */
624
+	private function _do_other_page_hooks()
625
+	{
626
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
627
+		foreach ($registered_pages as $page) {
628
+			//now let's setup the file name and class that should be present
629
+			$classname = str_replace('.class.php', '', $page);
630
+			//autoloaders should take care of loading file
631
+			if (! class_exists($classname)) {
632
+				$error_msg[] = sprintf(
633
+					esc_html__(
634
+						'Something went wrong with loading the %s admin hooks page.',
635
+						'event_espresso'
636
+					),
637
+					$page
638
+				);
639
+				$error_msg[] = $error_msg[0]
640
+							   . "\r\n"
641
+							   . sprintf(
642
+								   esc_html__(
643
+									   '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',
644
+									   'event_espresso'
645
+								   ),
646
+								   $page,
647
+								   '<br />',
648
+								   '<strong>' . $classname . '</strong>'
649
+							   );
650
+				throw new EE_Error(implode('||', $error_msg));
651
+			}
652
+			$a = new ReflectionClass($classname);
653
+			//notice we are passing the instance of this class to the hook object.
654
+			$hookobj[] = $a->newInstance($this);
655
+		}
656
+	}
657
+
658
+
659
+
660
+	public function load_page_dependencies()
661
+	{
662
+		try {
663
+			$this->_load_page_dependencies();
664
+		} catch (EE_Error $e) {
665
+			$e->get_error();
666
+		}
667
+	}
668
+
669
+
670
+
671
+	/**
672
+	 * load_page_dependencies
673
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
674
+	 *
675
+	 * @return void
676
+	 * @throws DomainException
677
+	 * @throws EE_Error
678
+	 * @throws InvalidArgumentException
679
+	 * @throws InvalidDataTypeException
680
+	 * @throws InvalidInterfaceException
681
+	 * @throws ReflectionException
682
+	 */
683
+	protected function _load_page_dependencies()
684
+	{
685
+		//let's set the current_screen and screen options to override what WP set
686
+		$this->_current_screen = get_current_screen();
687
+		//load admin_notices - global, page class, and view specific
688
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
689
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
690
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
691
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
692
+		}
693
+		//load network admin_notices - global, page class, and view specific
694
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
695
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
696
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
697
+		}
698
+		//this will save any per_page screen options if they are present
699
+		$this->_set_per_page_screen_options();
700
+		//setup list table properties
701
+		$this->_set_list_table();
702
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
703
+		// However in some cases the metaboxes will need to be added within a route handling callback.
704
+		$this->_add_registered_meta_boxes();
705
+		$this->_add_screen_columns();
706
+		//add screen options - global, page child class, and view specific
707
+		$this->_add_global_screen_options();
708
+		$this->_add_screen_options();
709
+		$add_screen_options  = "_add_screen_options_{$this->_current_view}";
710
+		if (method_exists($this, $add_screen_options )) {
711
+			$this->{$add_screen_options}();
712
+		}
713
+		//add help tab(s) and tours- set via page_config and qtips.
714
+		$this->_add_help_tour();
715
+		$this->_add_help_tabs();
716
+		$this->_add_qtips();
717
+		//add feature_pointers - global, page child class, and view specific
718
+		$this->_add_feature_pointers();
719
+		$this->_add_global_feature_pointers();
720
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
721
+		if (method_exists($this, $add_feature_pointer )) {
722
+			$this->{$add_feature_pointer}();
723
+		}
724
+		//enqueue scripts/styles - global, page class, and view specific
725
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
726
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
727
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
728
+			add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
729
+		}
730
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
731
+		// admin_print_footer_scripts - global, page child class, and view specific.
732
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
733
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
734
+		// is a good use case. Notice the late priority we're giving these
735
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
736
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
737
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
738
+			add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
739
+		}
740
+		//admin footer scripts
741
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
742
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
743
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
744
+			add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
745
+		}
746
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
747
+		//targeted hook
748
+		do_action(
749
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
750
+
751
+		);
752
+	}
753
+
754
+
755
+
756
+	/**
757
+	 * _set_defaults
758
+	 * This sets some global defaults for class properties.
759
+	 */
760
+	private function _set_defaults()
761
+	{
762
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
763
+		$this->_event = $this->_template_path = $this->_column_template_path = null;
764
+		$this->_nav_tabs = $this->_views = $this->_page_routes = array();
765
+		$this->_page_config = $this->_default_route_query_args = array();
766
+		$this->_default_nav_tab_name = 'overview';
767
+		//init template args
768
+		$this->_template_args = array(
769
+			'admin_page_header'  => '',
770
+			'admin_page_content' => '',
771
+			'post_body_content'  => '',
772
+			'before_list_table'  => '',
773
+			'after_list_table'   => '',
774
+		);
775
+	}
776
+
777
+
778
+
779
+	/**
780
+	 * route_admin_request
781
+	 *
782
+	 * @see    _route_admin_request()
783
+	 * @return exception|void error
784
+	 * @throws InvalidArgumentException
785
+	 * @throws InvalidInterfaceException
786
+	 * @throws InvalidDataTypeException
787
+	 * @throws EE_Error
788
+	 * @throws ReflectionException
789
+	 */
790
+	public function route_admin_request()
791
+	{
792
+		try {
793
+			$this->_route_admin_request();
794
+		} catch (EE_Error $e) {
795
+			$e->get_error();
796
+		}
797
+	}
798
+
799
+
800
+
801
+	public function set_wp_page_slug($wp_page_slug)
802
+	{
803
+		$this->_wp_page_slug = $wp_page_slug;
804
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
805
+		if (is_network_admin()) {
806
+			$this->_wp_page_slug .= '-network';
807
+		}
808
+	}
809
+
810
+
811
+
812
+	/**
813
+	 * _verify_routes
814
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
815
+	 * we know if we need to drop out.
816
+	 *
817
+	 * @return bool
818
+	 * @throws EE_Error
819
+	 */
820
+	protected function _verify_routes()
821
+	{
822
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
823
+		if (! $this->_current_page && ! defined('DOING_AJAX')) {
824
+			return false;
825
+		}
826
+		$this->_route = false;
827
+		// check that the page_routes array is not empty
828
+		if (empty($this->_page_routes)) {
829
+			// user error msg
830
+			$error_msg = sprintf(
831
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
832
+				$this->_admin_page_title
833
+			);
834
+			// developer error msg
835
+			$error_msg .= '||' . $error_msg . esc_html__(
836
+				' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
837
+				'event_espresso'
838
+			);
839
+			throw new EE_Error($error_msg);
840
+		}
841
+		// and that the requested page route exists
842
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
843
+			$this->_route        = $this->_page_routes[$this->_req_action];
844
+			$this->_route_config = isset($this->_page_config[$this->_req_action])
845
+				? $this->_page_config[$this->_req_action] : array();
846
+		} else {
847
+			// user error msg
848
+			$error_msg = sprintf(
849
+				esc_html__(
850
+						'The requested page route does not exist for the %s admin page.',
851
+						'event_espresso'
852
+				),
853
+				$this->_admin_page_title
854
+			);
855
+			// developer error msg
856
+			$error_msg .= '||' . $error_msg . sprintf(
857
+					esc_html__(
858
+						' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
859
+						'event_espresso'
860
+					),
861
+					$this->_req_action
862
+				);
863
+			throw new EE_Error($error_msg);
864
+		}
865
+		// and that a default route exists
866
+		if (! array_key_exists('default', $this->_page_routes)) {
867
+			// user error msg
868
+			$error_msg = sprintf(
869
+				esc_html__(
870
+						'A default page route has not been set for the % admin page.',
871
+						'event_espresso'
872
+				),
873
+				$this->_admin_page_title
874
+			);
875
+			// developer error msg
876
+			$error_msg .= '||' . $error_msg . esc_html__(
877
+				' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
878
+				'event_espresso'
879
+			);
880
+			throw new EE_Error($error_msg);
881
+		}
882
+		//first lets' catch if the UI request has EVER been set.
883
+		if ($this->_is_UI_request === null) {
884
+			//lets set if this is a UI request or not.
885
+			$this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
886
+			//wait a minute... we might have a noheader in the route array
887
+			$this->_is_UI_request = is_array($this->_route)
888
+									&& isset($this->_route['noheader'])
889
+									&& $this->_route['noheader'] ? false : $this->_is_UI_request;
890
+		}
891
+		$this->_set_current_labels();
892
+		return true;
893
+	}
894
+
895
+
896
+
897
+	/**
898
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
899
+	 *
900
+	 * @param  string $route the route name we're verifying
901
+	 * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
902
+	 * @throws EE_Error
903
+	 */
904
+	protected function _verify_route($route)
905
+	{
906
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
907
+			return true;
908
+		}
909
+		// user error msg
910
+		$error_msg = sprintf(
911
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
912
+			$this->_admin_page_title
913
+		);
914
+		// developer error msg
915
+		$error_msg .= '||' . $error_msg . sprintf(
916
+				esc_html__(
917
+					' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
918
+					'event_espresso'
919
+				),
920
+				$route
921
+			);
922
+		throw new EE_Error($error_msg);
923
+	}
924
+
925
+
926
+
927
+	/**
928
+	 * perform nonce verification
929
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
930
+	 * using this method (and save retyping!)
931
+	 *
932
+	 * @param  string $nonce     The nonce sent
933
+	 * @param  string $nonce_ref The nonce reference string (name0)
934
+	 * @return void
935
+	 * @throws EE_Error
936
+	 */
937
+	protected function _verify_nonce($nonce, $nonce_ref)
938
+	{
939
+		// verify nonce against expected value
940
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
941
+			// these are not the droids you are looking for !!!
942
+			$msg = sprintf(
943
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
944
+				'<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
945
+				'</a>'
946
+			);
947
+			if (WP_DEBUG) {
948
+				$msg .= "\n  " . sprintf(
949
+						esc_html__(
950
+							'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
951
+							'event_espresso'
952
+						),
953
+						__CLASS__
954
+					);
955
+			}
956
+			if (! defined('DOING_AJAX')) {
957
+				wp_die($msg);
958
+			} else {
959
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
960
+				$this->_return_json();
961
+			}
962
+		}
963
+	}
964
+
965
+
966
+
967
+	/**
968
+	 * _route_admin_request()
969
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
970
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
971
+	 * in the page routes and then will try to load the corresponding method.
972
+	 *
973
+	 * @return void
974
+	 * @throws EE_Error
975
+	 * @throws InvalidArgumentException
976
+	 * @throws InvalidDataTypeException
977
+	 * @throws InvalidInterfaceException
978
+	 * @throws ReflectionException
979
+	 */
980
+	protected function _route_admin_request()
981
+	{
982
+		if (! $this->_is_UI_request) {
983
+			$this->_verify_routes();
984
+		}
985
+		$nonce_check = isset($this->_route_config['require_nonce'])
986
+			? $this->_route_config['require_nonce']
987
+			: true;
988
+		if ($this->_req_action !== 'default' && $nonce_check) {
989
+			// set nonce from post data
990
+			$nonce = isset($this->_req_data[$this->_req_nonce])
991
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
992
+				: '';
993
+			$this->_verify_nonce($nonce, $this->_req_nonce);
994
+		}
995
+		//set the nav_tabs array but ONLY if this is  UI_request
996
+		if ($this->_is_UI_request) {
997
+			$this->_set_nav_tabs();
998
+		}
999
+		// grab callback function
1000
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
1001
+		// check if callback has args
1002
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1003
+		$error_msg = '';
1004
+		// action right before calling route
1005
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1006
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1007
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1008
+		}
1009
+		// right before calling the route, let's remove _wp_http_referer from the
1010
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1011
+		$_SERVER['REQUEST_URI'] = remove_query_arg(
1012
+				'_wp_http_referer',
1013
+				wp_unslash($_SERVER['REQUEST_URI'])
1014
+		);
1015
+		if (! empty($func)) {
1016
+			if (is_array($func)) {
1017
+				list($class, $method) = $func;
1018
+			} elseif (strpos($func, '::') !== false) {
1019
+				list($class, $method) = explode('::', $func);
1020
+			} else {
1021
+				$class  = $this;
1022
+				$method = $func;
1023
+			}
1024
+			if (! (is_object($class) && $class === $this)) {
1025
+				// send along this admin page object for access by addons.
1026
+				$args['admin_page_object'] = $this;
1027
+			}
1028
+			if (
1029
+				//is it a method on a class that doesn't work?
1030
+				(
1031
+					(
1032
+						method_exists($class, $method)
1033
+						&& call_user_func_array(array($class, $method), $args) === false
1034
+					)
1035
+					&& (
1036
+						//is it a standalone function that doesn't work?
1037
+						function_exists($method)
1038
+						&& call_user_func_array(
1039
+							$func,
1040
+							array_merge(array('admin_page_object' => $this), $args)
1041
+						   ) === false
1042
+					)
1043
+				)
1044
+				|| (
1045
+					//is it neither a class method NOR a standalone function?
1046
+					! method_exists($class, $method)
1047
+					&& ! function_exists($method)
1048
+				)
1049
+			) {
1050
+				// user error msg
1051
+				$error_msg = esc_html__(
1052
+					'An error occurred. The  requested page route could not be found.',
1053
+					'event_espresso'
1054
+				);
1055
+				// developer error msg
1056
+				$error_msg .= '||';
1057
+				$error_msg .= sprintf(
1058
+					esc_html__(
1059
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1060
+						'event_espresso'
1061
+					),
1062
+					$method
1063
+				);
1064
+			}
1065
+			if (! empty($error_msg)) {
1066
+				throw new EE_Error($error_msg);
1067
+			}
1068
+		}
1069
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1070
+		// then we need to reset the routing properties to the new route.
1071
+		//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.
1072
+		if ($this->_is_UI_request === false
1073
+			&& is_array($this->_route)
1074
+			&& ! empty($this->_route['headers_sent_route'])
1075
+		) {
1076
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1077
+		}
1078
+	}
1079
+
1080
+
1081
+
1082
+	/**
1083
+	 * This method just allows the resetting of page properties in the case where a no headers
1084
+	 * route redirects to a headers route in its route config.
1085
+	 *
1086
+	 * @since   4.3.0
1087
+	 * @param  string $new_route New (non header) route to redirect to.
1088
+	 * @return   void
1089
+	 * @throws ReflectionException
1090
+	 * @throws InvalidArgumentException
1091
+	 * @throws InvalidInterfaceException
1092
+	 * @throws InvalidDataTypeException
1093
+	 * @throws EE_Error
1094
+	 */
1095
+	protected function _reset_routing_properties($new_route)
1096
+	{
1097
+		$this->_is_UI_request = true;
1098
+		//now we set the current route to whatever the headers_sent_route is set at
1099
+		$this->_req_data['action'] = $new_route;
1100
+		//rerun page setup
1101
+		$this->_page_setup();
1102
+	}
1103
+
1104
+
1105
+
1106
+	/**
1107
+	 * _add_query_arg
1108
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1109
+	 *(internally just uses EEH_URL's function with the same name)
1110
+	 *
1111
+	 * @param array  $args
1112
+	 * @param string $url
1113
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1114
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1115
+	 *                                        Example usage: If the current page is:
1116
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1117
+	 *                                        &action=default&event_id=20&month_range=March%202015
1118
+	 *                                        &_wpnonce=5467821
1119
+	 *                                        and you call:
1120
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1121
+	 *                                        array(
1122
+	 *                                        'action' => 'resend_something',
1123
+	 *                                        'page=>espresso_registrations'
1124
+	 *                                        ),
1125
+	 *                                        $some_url,
1126
+	 *                                        true
1127
+	 *                                        );
1128
+	 *                                        It will produce a url in this structure:
1129
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1130
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1131
+	 *                                        month_range]=March%202015
1132
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1133
+	 * @return string
1134
+	 */
1135
+	public static function add_query_args_and_nonce(
1136
+		$args = array(),
1137
+		$url = false,
1138
+		$sticky = false,
1139
+		$exclude_nonce = false
1140
+	) {
1141
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
1142
+		if ($sticky) {
1143
+			$request = $_REQUEST;
1144
+			unset($request['_wp_http_referer']);
1145
+			unset($request['wp_referer']);
1146
+			foreach ($request as $key => $value) {
1147
+				//do not add nonces
1148
+				if (strpos($key, 'nonce') !== false) {
1149
+					continue;
1150
+				}
1151
+				$args['wp_referer[' . $key . ']'] = $value;
1152
+			}
1153
+		}
1154
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1155
+	}
1156
+
1157
+
1158
+
1159
+	/**
1160
+	 * This returns a generated link that will load the related help tab.
1161
+	 *
1162
+	 * @param  string $help_tab_id the id for the connected help tab
1163
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1164
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1165
+	 * @uses EEH_Template::get_help_tab_link()
1166
+	 * @return string              generated link
1167
+	 */
1168
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1169
+	{
1170
+		return EEH_Template::get_help_tab_link(
1171
+			$help_tab_id,
1172
+			$this->page_slug,
1173
+			$this->_req_action,
1174
+			$icon_style,
1175
+			$help_text
1176
+		);
1177
+	}
1178
+
1179
+
1180
+
1181
+	/**
1182
+	 * _add_help_tabs
1183
+	 * Note child classes define their help tabs within the page_config array.
1184
+	 *
1185
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1186
+	 * @return void
1187
+	 * @throws DomainException
1188
+	 * @throws EE_Error
1189
+	 */
1190
+	protected function _add_help_tabs()
1191
+	{
1192
+		$tour_buttons = '';
1193
+		if (isset($this->_page_config[$this->_req_action])) {
1194
+			$config = $this->_page_config[$this->_req_action];
1195
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1196
+			if (isset($this->_help_tour[$this->_req_action])) {
1197
+				$tb           = array();
1198
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1199
+				foreach ($this->_help_tour['tours'] as $tour) {
1200
+					//if this is the end tour then we don't need to setup a button
1201
+					if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1202
+						continue;
1203
+					}
1204
+					$tb[] = '<button id="trigger-tour-'
1205
+							. $tour->get_slug()
1206
+							. '" class="button-primary trigger-ee-help-tour">'
1207
+							. $tour->get_label()
1208
+							. '</button>';
1209
+				}
1210
+				$tour_buttons .= implode('<br />', $tb);
1211
+				$tour_buttons .= '</div></div>';
1212
+			}
1213
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1214
+			if (is_array($config) && isset($config['help_sidebar'])) {
1215
+				//check that the callback given is valid
1216
+				if (! method_exists($this, $config['help_sidebar'])) {
1217
+					throw new EE_Error(
1218
+						sprintf(
1219
+							esc_html__(
1220
+								'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',
1221
+								'event_espresso'
1222
+							),
1223
+							$config['help_sidebar'],
1224
+							get_class($this)
1225
+						)
1226
+					);
1227
+				}
1228
+				$content = apply_filters(
1229
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1230
+					$this->{$config['help_sidebar']}()
1231
+				);
1232
+				$content .= $tour_buttons; //add help tour buttons.
1233
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1234
+				$this->_current_screen->set_help_sidebar($content);
1235
+			}
1236
+			//if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1237
+			if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1238
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1239
+			}
1240
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1241
+			if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1242
+				$_ht['id']      = $this->page_slug;
1243
+				$_ht['title']   = esc_html__('Help Tours', 'event_espresso');
1244
+				$_ht['content'] = '<p>' . esc_html__(
1245
+						'The buttons to the right allow you to start/restart any help tours available for this page',
1246
+						'event_espresso'
1247
+					) . '</p>';
1248
+				$this->_current_screen->add_help_tab($_ht);
1249
+			}
1250
+			if (! isset($config['help_tabs'])) {
1251
+				return;
1252
+			} //no help tabs for this route
1253
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1254
+				//we're here so there ARE help tabs!
1255
+				//make sure we've got what we need
1256
+				if (! isset($cfg['title'])) {
1257
+					throw new EE_Error(
1258
+						esc_html__(
1259
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1260
+							'event_espresso'
1261
+						)
1262
+					);
1263
+				}
1264
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1265
+					throw new EE_Error(
1266
+						esc_html__(
1267
+							'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',
1268
+							'event_espresso'
1269
+						)
1270
+					);
1271
+				}
1272
+				//first priority goes to content.
1273
+				if (! empty($cfg['content'])) {
1274
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1275
+					//second priority goes to filename
1276
+				} elseif (! empty($cfg['filename'])) {
1277
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1278
+					//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)
1279
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1280
+															 . basename($this->_get_dir())
1281
+															 . '/help_tabs/'
1282
+															 . $cfg['filename']
1283
+															 . '.help_tab.php' : $file_path;
1284
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1285
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1286
+						EE_Error::add_error(
1287
+							sprintf(
1288
+								esc_html__(
1289
+									'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',
1290
+									'event_espresso'
1291
+								),
1292
+								$tab_id,
1293
+								key($config),
1294
+								$file_path
1295
+							),
1296
+							__FILE__,
1297
+							__FUNCTION__,
1298
+							__LINE__
1299
+						);
1300
+						return;
1301
+					}
1302
+					$template_args['admin_page_obj'] = $this;
1303
+					$content = EEH_Template::display_template(
1304
+						$file_path,
1305
+						$template_args,
1306
+						true
1307
+					);
1308
+				} else {
1309
+					$content = '';
1310
+				}
1311
+				//check if callback is valid
1312
+				if (
1313
+					empty($content) && (
1314
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1315
+					)
1316
+				) {
1317
+					EE_Error::add_error(
1318
+						sprintf(
1319
+							esc_html__(
1320
+								'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.',
1321
+								'event_espresso'
1322
+							),
1323
+							$cfg['title']
1324
+						),
1325
+						__FILE__,
1326
+						__FUNCTION__,
1327
+						__LINE__
1328
+					);
1329
+					return;
1330
+				}
1331
+				//setup config array for help tab method
1332
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1333
+				$_ht = array(
1334
+					'id'       => $id,
1335
+					'title'    => $cfg['title'],
1336
+					'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1337
+					'content'  => $content,
1338
+				);
1339
+				$this->_current_screen->add_help_tab($_ht);
1340
+			}
1341
+		}
1342
+	}
1343
+
1344
+
1345
+
1346
+	/**
1347
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1348
+	 * an array with properties for setting up usage of the joyride plugin
1349
+	 *
1350
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1351
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1352
+	 *         _set_page_config() comments
1353
+	 * @return void
1354
+	 * @throws EE_Error
1355
+	 * @throws InvalidArgumentException
1356
+	 * @throws InvalidDataTypeException
1357
+	 * @throws InvalidInterfaceException
1358
+	 */
1359
+	protected function _add_help_tour()
1360
+	{
1361
+		$tours            = array();
1362
+		$this->_help_tour = array();
1363
+		//exit early if help tours are turned off globally
1364
+		if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1365
+			|| ! EE_Registry::instance()->CFG->admin->help_tour_activation
1366
+		) {
1367
+			return;
1368
+		}
1369
+		//loop through _page_config to find any help_tour defined
1370
+		foreach ($this->_page_config as $route => $config) {
1371
+			//we're only going to set things up for this route
1372
+			if ($route !== $this->_req_action) {
1373
+				continue;
1374
+			}
1375
+			if (isset($config['help_tour'])) {
1376
+				foreach ($config['help_tour'] as $tour) {
1377
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1378
+					// let's see if we can get that file...
1379
+					// if not its possible this is a decaf route not set in caffeinated
1380
+					// so lets try and get the caffeinated equivalent
1381
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1382
+															 . basename($this->_get_dir())
1383
+															 . '/help_tours/'
1384
+															 . $tour
1385
+															 . '.class.php' : $file_path;
1386
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1387
+					if (! is_readable($file_path)) {
1388
+						EE_Error::add_error(
1389
+							sprintf(
1390
+								esc_html__(
1391
+									'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',
1392
+									'event_espresso'
1393
+								),
1394
+								$file_path,
1395
+								$tour
1396
+							),
1397
+							__FILE__,
1398
+							__FUNCTION__,
1399
+							__LINE__
1400
+						);
1401
+						return;
1402
+					}
1403
+					require_once $file_path;
1404
+					if (! class_exists($tour)) {
1405
+						$error_msg[] = sprintf(
1406
+							esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1407
+							$tour
1408
+						);
1409
+						$error_msg[] = $error_msg[0] . "\r\n" . sprintf(
1410
+								esc_html__(
1411
+									'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.',
1412
+									'event_espresso'
1413
+								),
1414
+								$tour,
1415
+								'<br />',
1416
+								$tour,
1417
+								$this->_req_action,
1418
+								get_class($this)
1419
+							);
1420
+						throw new EE_Error(implode('||', $error_msg));
1421
+					}
1422
+					$tour_obj                   = new $tour($this->_is_caf);
1423
+					$tours[]                    = $tour_obj;
1424
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1425
+				}
1426
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1427
+				$end_stop_tour              = new EE_Help_Tour_final_stop($this->_is_caf);
1428
+				$tours[]                    = $end_stop_tour;
1429
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1430
+			}
1431
+		}
1432
+		if (! empty($tours)) {
1433
+			$this->_help_tour['tours'] = $tours;
1434
+		}
1435
+		// that's it!  Now that the $_help_tours property is set (or not)
1436
+		// the scripts and html should be taken care of automatically.
1437
+	}
1438
+
1439
+
1440
+
1441
+	/**
1442
+	 * This simply sets up any qtips that have been defined in the page config
1443
+	 *
1444
+	 * @return void
1445
+	 */
1446
+	protected function _add_qtips()
1447
+	{
1448
+		if (isset($this->_route_config['qtips'])) {
1449
+			$qtips = (array)$this->_route_config['qtips'];
1450
+			//load qtip loader
1451
+			$path = array(
1452
+				$this->_get_dir() . '/qtips/',
1453
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1454
+			);
1455
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1456
+		}
1457
+	}
1458
+
1459
+
1460
+
1461
+	/**
1462
+	 * _set_nav_tabs
1463
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1464
+	 * wish to add additional tabs or modify accordingly.
1465
+	 *
1466
+	 * @return void
1467
+	 * @throws InvalidArgumentException
1468
+	 * @throws InvalidInterfaceException
1469
+	 * @throws InvalidDataTypeException
1470
+	 */
1471
+	protected function _set_nav_tabs()
1472
+	{
1473
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1474
+		$i = 0;
1475
+		foreach ($this->_page_config as $slug => $config) {
1476
+			if (
1477
+				! is_array($config)
1478
+				|| (
1479
+					is_array($config)
1480
+					&& (
1481
+						(isset($config['nav']) && ! $config['nav'])
1482
+						|| ! isset($config['nav'])
1483
+					)
1484
+				)
1485
+			) {
1486
+				continue;
1487
+			}
1488
+			//no nav tab for this config
1489
+			//check for persistent flag
1490
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1491
+				// nav tab is only to appear when route requested.
1492
+				continue;
1493
+			}
1494
+			if (! $this->check_user_access($slug, true)) {
1495
+				// no nav tab because current user does not have access.
1496
+				continue;
1497
+			}
1498
+			$css_class              = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1499
+			$this->_nav_tabs[$slug] = array(
1500
+				'url'       => isset($config['nav']['url'])
1501
+					? $config['nav']['url']
1502
+					: self::add_query_args_and_nonce(
1503
+						array('action' => $slug),
1504
+						$this->_admin_base_url
1505
+					),
1506
+				'link_text' => isset($config['nav']['label'])
1507
+					? $config['nav']['label']
1508
+					: ucwords(
1509
+						str_replace('_', ' ', $slug)
1510
+					),
1511
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1512
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1513
+			);
1514
+			$i++;
1515
+		}
1516
+		//if $this->_nav_tabs is empty then lets set the default
1517
+		if (empty($this->_nav_tabs)) {
1518
+			$this->_nav_tabs[$this->_default_nav_tab_name] = array(
1519
+				'url'       => $this->_admin_base_url,
1520
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1521
+				'css_class' => 'nav-tab-active',
1522
+				'order'     => 10,
1523
+			);
1524
+		}
1525
+		//now let's sort the tabs according to order
1526
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1527
+	}
1528
+
1529
+
1530
+
1531
+	/**
1532
+	 * _set_current_labels
1533
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1534
+	 * property array
1535
+	 *
1536
+	 * @return void
1537
+	 */
1538
+	private function _set_current_labels()
1539
+	{
1540
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1541
+			foreach ($this->_route_config['labels'] as $label => $text) {
1542
+				if (is_array($text)) {
1543
+					foreach ($text as $sublabel => $subtext) {
1544
+						$this->_labels[$label][$sublabel] = $subtext;
1545
+					}
1546
+				} else {
1547
+					$this->_labels[$label] = $text;
1548
+				}
1549
+			}
1550
+		}
1551
+	}
1552
+
1553
+
1554
+
1555
+	/**
1556
+	 *        verifies user access for this admin page
1557
+	 *
1558
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1559
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1560
+	 *                               return false if verify fail.
1561
+	 * @return bool
1562
+	 * @throws InvalidArgumentException
1563
+	 * @throws InvalidDataTypeException
1564
+	 * @throws InvalidInterfaceException
1565
+	 */
1566
+	public function check_user_access($route_to_check = '', $verify_only = false)
1567
+	{
1568
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1569
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1570
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1571
+						  && is_array(
1572
+							  $this->_page_routes[$route_to_check]
1573
+						  )
1574
+						  && ! empty($this->_page_routes[$route_to_check]['capability'])
1575
+			? $this->_page_routes[$route_to_check]['capability'] : null;
1576
+		if (empty($capability) && empty($route_to_check)) {
1577
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1578
+				: $this->_route['capability'];
1579
+		} else {
1580
+			$capability = empty($capability) ? 'manage_options' : $capability;
1581
+		}
1582
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1583
+		if (
1584
+			! defined('DOING_AJAX')
1585
+			&& (
1586
+				! function_exists('is_admin')
1587
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1588
+					$capability,
1589
+					$this->page_slug
1590
+					. '_'
1591
+					. $route_to_check,
1592
+					$id
1593
+				)
1594
+			)
1595
+		) {
1596
+			if ($verify_only) {
1597
+				return false;
1598
+			}
1599
+			if (is_user_logged_in()) {
1600
+				wp_die(__('You do not have access to this route.', 'event_espresso'));
1601
+			} else {
1602
+				return false;
1603
+			}
1604
+		}
1605
+		return true;
1606
+	}
1607
+
1608
+
1609
+
1610
+	/**
1611
+	 * admin_init_global
1612
+	 * This runs all the code that we want executed within the WP admin_init hook.
1613
+	 * This method executes for ALL EE Admin pages.
1614
+	 *
1615
+	 * @return void
1616
+	 */
1617
+	public function admin_init_global()
1618
+	{
1619
+	}
1620
+
1621
+
1622
+
1623
+	/**
1624
+	 * wp_loaded_global
1625
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1626
+	 * EE_Admin page and will execute on every EE Admin Page load
1627
+	 *
1628
+	 * @return void
1629
+	 */
1630
+	public function wp_loaded()
1631
+	{
1632
+	}
1633
+
1634
+
1635
+
1636
+	/**
1637
+	 * admin_notices
1638
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1639
+	 * ALL EE_Admin pages.
1640
+	 *
1641
+	 * @return void
1642
+	 */
1643
+	public function admin_notices_global()
1644
+	{
1645
+		$this->_display_no_javascript_warning();
1646
+		$this->_display_espresso_notices();
1647
+	}
1648
+
1649
+
1650
+
1651
+	public function network_admin_notices_global()
1652
+	{
1653
+		$this->_display_no_javascript_warning();
1654
+		$this->_display_espresso_notices();
1655
+	}
1656
+
1657
+
1658
+
1659
+	/**
1660
+	 * admin_footer_scripts_global
1661
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1662
+	 * will apply on ALL EE_Admin pages.
1663
+	 *
1664
+	 * @return void
1665
+	 */
1666
+	public function admin_footer_scripts_global()
1667
+	{
1668
+		$this->_add_admin_page_ajax_loading_img();
1669
+		$this->_add_admin_page_overlay();
1670
+		//if metaboxes are present we need to add the nonce field
1671
+		if (
1672
+			 isset($this->_route_config['metaboxes'])
1673
+			 || isset($this->_route_config['list_table'])
1674
+			 || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1675
+		) {
1676
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1677
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1678
+		}
1679
+	}
1680
+
1681
+
1682
+
1683
+	/**
1684
+	 * admin_footer_global
1685
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1686
+	 * ALL EE_Admin Pages.
1687
+	 *
1688
+	 * @return void
1689
+	 * @throws EE_Error
1690
+	 */
1691
+	public function admin_footer_global()
1692
+	{
1693
+		//dialog container for dialog helper
1694
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1695
+		$d_cont .= '<div class="ee-notices"></div>';
1696
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1697
+		$d_cont .= '</div>';
1698
+		echo $d_cont;
1699
+		//help tour stuff?
1700
+		if (isset($this->_help_tour[$this->_req_action])) {
1701
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1702
+		}
1703
+		//current set timezone for timezone js
1704
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1705
+	}
1706
+
1707
+
1708
+
1709
+	/**
1710
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1711
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1712
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1713
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1714
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1715
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1716
+	 * for the
1717
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1718
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1719
+	 *    'help_trigger_id' => array(
1720
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1721
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1722
+	 *    )
1723
+	 * );
1724
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1725
+	 *
1726
+	 * @param array $help_array
1727
+	 * @param bool  $display
1728
+	 * @return string content
1729
+	 * @throws DomainException
1730
+	 * @throws EE_Error
1731
+	 */
1732
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1733
+	{
1734
+		$content       = '';
1735
+		$help_array    = empty($help_array) ? $this->_get_help_content() : $help_array;
1736
+		//loop through the array and setup content
1737
+		foreach ($help_array as $trigger => $help) {
1738
+			//make sure the array is setup properly
1739
+			if (! isset($help['title']) || ! isset($help['content'])) {
1740
+				throw new EE_Error(
1741
+					esc_html__(
1742
+						'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',
1743
+						'event_espresso'
1744
+					)
1745
+				);
1746
+			}
1747
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1748
+			$template_args = array(
1749
+				'help_popup_id'      => $trigger,
1750
+				'help_popup_title'   => $help['title'],
1751
+				'help_popup_content' => $help['content'],
1752
+			);
1753
+			$content       .= EEH_Template::display_template(
1754
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1755
+				$template_args,
1756
+				true
1757
+			);
1758
+		}
1759
+		if ($display) {
1760
+			echo $content;
1761
+			return '';
1762
+		}
1763
+		return $content;
1764
+	}
1765
+
1766
+
1767
+
1768
+	/**
1769
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1770
+	 *
1771
+	 * @return array properly formatted array for help popup content
1772
+	 * @throws EE_Error
1773
+	 */
1774
+	private function _get_help_content()
1775
+	{
1776
+		//what is the method we're looking for?
1777
+		$method_name = '_help_popup_content_' . $this->_req_action;
1778
+		//if method doesn't exist let's get out.
1779
+		if (! method_exists($this, $method_name)) {
1780
+			return array();
1781
+		}
1782
+		//k we're good to go let's retrieve the help array
1783
+		$help_array = call_user_func(array($this, $method_name));
1784
+		//make sure we've got an array!
1785
+		if (! is_array($help_array)) {
1786
+			throw new EE_Error(
1787
+				esc_html__(
1788
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1789
+					'event_espresso'
1790
+				)
1791
+			);
1792
+		}
1793
+		return $help_array;
1794
+	}
1795
+
1796
+
1797
+
1798
+	/**
1799
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1800
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1801
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1802
+	 *
1803
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1804
+	 * @param boolean $display    if false then we return the trigger string
1805
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1806
+	 * @return string
1807
+	 * @throws DomainException
1808
+	 * @throws EE_Error
1809
+	 */
1810
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1811
+	{
1812
+		if (defined('DOING_AJAX')) {
1813
+			return '';
1814
+		}
1815
+		//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
1816
+		$help_array   = $this->_get_help_content();
1817
+		$help_content = '';
1818
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1819
+			$help_array[$trigger_id] = array(
1820
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1821
+				'content' => esc_html__(
1822
+					'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.)',
1823
+					'event_espresso'
1824
+				),
1825
+			);
1826
+			$help_content            = $this->_set_help_popup_content($help_array, false);
1827
+		}
1828
+		//let's setup the trigger
1829
+		$content = '<a class="ee-dialog" href="?height='
1830
+				   . $dimensions[0]
1831
+				   . '&width='
1832
+				   . $dimensions[1]
1833
+				   . '&inlineId='
1834
+				   . $trigger_id
1835
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1836
+		$content .= $help_content;
1837
+		if ($display) {
1838
+			echo $content;
1839
+			return  '';
1840
+		}
1841
+		return $content;
1842
+	}
1843
+
1844
+
1845
+
1846
+	/**
1847
+	 * _add_global_screen_options
1848
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1849
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1850
+	 *
1851
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1852
+	 *         see also WP_Screen object documents...
1853
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1854
+	 * @abstract
1855
+	 * @return void
1856
+	 */
1857
+	private function _add_global_screen_options()
1858
+	{
1859
+	}
1860
+
1861
+
1862
+
1863
+	/**
1864
+	 * _add_global_feature_pointers
1865
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1866
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1867
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1868
+	 *
1869
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1870
+	 *         extended) also see:
1871
+	 * @link   http://eamann.com/tech/wordpress-portland/
1872
+	 * @abstract
1873
+	 * @return void
1874
+	 */
1875
+	private function _add_global_feature_pointers()
1876
+	{
1877
+	}
1878
+
1879
+
1880
+
1881
+	/**
1882
+	 * load_global_scripts_styles
1883
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1884
+	 *
1885
+	 * @return void
1886
+	 * @throws EE_Error
1887
+	 */
1888
+	public function load_global_scripts_styles()
1889
+	{
1890
+		/** STYLES **/
1891
+		// add debugging styles
1892
+		if (WP_DEBUG) {
1893
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1894
+		}
1895
+		// register all styles
1896
+		wp_register_style(
1897
+			'espresso-ui-theme',
1898
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1899
+			array(),
1900
+			EVENT_ESPRESSO_VERSION
1901
+		);
1902
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1903
+		//helpers styles
1904
+		wp_register_style(
1905
+			'ee-text-links',
1906
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1907
+			array(),
1908
+			EVENT_ESPRESSO_VERSION
1909
+		);
1910
+		/** SCRIPTS **/
1911
+		//register all scripts
1912
+		wp_register_script(
1913
+			'ee-dialog',
1914
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1915
+			array('jquery', 'jquery-ui-draggable'),
1916
+			EVENT_ESPRESSO_VERSION,
1917
+			true
1918
+		);
1919
+		wp_register_script(
1920
+			'ee_admin_js',
1921
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1922
+			array('espresso_core', 'ee-parse-uri', 'ee-dialog'),
1923
+			EVENT_ESPRESSO_VERSION,
1924
+			true
1925
+		);
1926
+		wp_register_script(
1927
+			'jquery-ui-timepicker-addon',
1928
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1929
+			array('jquery-ui-datepicker', 'jquery-ui-slider'),
1930
+			EVENT_ESPRESSO_VERSION,
1931
+			true
1932
+		);
1933
+		add_filter('FHEE_load_joyride', '__return_true');
1934
+		//script for sorting tables
1935
+		wp_register_script(
1936
+			'espresso_ajax_table_sorting',
1937
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1938
+			array('ee_admin_js', 'jquery-ui-sortable'),
1939
+			EVENT_ESPRESSO_VERSION,
1940
+			true
1941
+		);
1942
+		//script for parsing uri's
1943
+		wp_register_script(
1944
+			'ee-parse-uri',
1945
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1946
+			array(),
1947
+			EVENT_ESPRESSO_VERSION,
1948
+			true
1949
+		);
1950
+		//and parsing associative serialized form elements
1951
+		wp_register_script(
1952
+			'ee-serialize-full-array',
1953
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1954
+			array('jquery'),
1955
+			EVENT_ESPRESSO_VERSION,
1956
+			true
1957
+		);
1958
+		//helpers scripts
1959
+		wp_register_script(
1960
+			'ee-text-links',
1961
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1962
+			array('jquery'),
1963
+			EVENT_ESPRESSO_VERSION,
1964
+			true
1965
+		);
1966
+		wp_register_script(
1967
+			'ee-moment-core',
1968
+			EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1969
+			array(),
1970
+			EVENT_ESPRESSO_VERSION,
1971
+			true
1972
+		);
1973
+		wp_register_script(
1974
+			'ee-moment',
1975
+			EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1976
+			array('ee-moment-core'),
1977
+			EVENT_ESPRESSO_VERSION,
1978
+			true
1979
+		);
1980
+		wp_register_script(
1981
+			'ee-datepicker',
1982
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1983
+			array('jquery-ui-timepicker-addon', 'ee-moment'),
1984
+			EVENT_ESPRESSO_VERSION,
1985
+			true
1986
+		);
1987
+		//google charts
1988
+		wp_register_script(
1989
+			'google-charts',
1990
+			'https://www.gstatic.com/charts/loader.js',
1991
+			array(),
1992
+			EVENT_ESPRESSO_VERSION,
1993
+			false
1994
+		);
1995
+		// ENQUEUE ALL BASICS BY DEFAULT
1996
+		wp_enqueue_style('ee-admin-css');
1997
+		wp_enqueue_script('ee_admin_js');
1998
+		wp_enqueue_script('ee-accounting');
1999
+		wp_enqueue_script('jquery-validate');
2000
+		//taking care of metaboxes
2001
+		if (
2002
+			empty($this->_cpt_route)
2003
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
2004
+		) {
2005
+			wp_enqueue_script('dashboard');
2006
+		}
2007
+		// LOCALIZED DATA
2008
+		//localize script for ajax lazy loading
2009
+		$lazy_loader_container_ids = apply_filters(
2010
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
2011
+			array('espresso_news_post_box_content')
2012
+		);
2013
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
2014
+		/**
2015
+		 * help tour stuff
2016
+		 */
2017
+		if (! empty($this->_help_tour)) {
2018
+			//register the js for kicking things off
2019
+			wp_enqueue_script(
2020
+				'ee-help-tour',
2021
+				EE_ADMIN_URL . 'assets/ee-help-tour.js',
2022
+				array('jquery-joyride'),
2023
+				EVENT_ESPRESSO_VERSION,
2024
+				true
2025
+			);
2026
+			$tours = array();
2027
+			//setup tours for the js tour object
2028
+			foreach ($this->_help_tour['tours'] as $tour) {
2029
+				if ($tour instanceof EE_Help_Tour) {
2030
+					$tours[] = array(
2031
+						'id'      => $tour->get_slug(),
2032
+						'options' => $tour->get_options(),
2033
+					);
2034
+				}
2035
+			}
2036
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2037
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2038
+		}
2039
+	}
2040
+
2041
+
2042
+
2043
+	/**
2044
+	 *        admin_footer_scripts_eei18n_js_strings
2045
+	 *
2046
+	 * @return        void
2047
+	 */
2048
+	public function admin_footer_scripts_eei18n_js_strings()
2049
+	{
2050
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
2051
+		EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2052
+			'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!!!',
2053
+			'event_espresso'
2054
+		);
2055
+		EE_Registry::$i18n_js_strings['January']        = esc_html__('January', 'event_espresso');
2056
+		EE_Registry::$i18n_js_strings['February']       = esc_html__('February', 'event_espresso');
2057
+		EE_Registry::$i18n_js_strings['March']          = esc_html__('March', 'event_espresso');
2058
+		EE_Registry::$i18n_js_strings['April']          = esc_html__('April', 'event_espresso');
2059
+		EE_Registry::$i18n_js_strings['May']            = esc_html__('May', 'event_espresso');
2060
+		EE_Registry::$i18n_js_strings['June']           = esc_html__('June', 'event_espresso');
2061
+		EE_Registry::$i18n_js_strings['July']           = esc_html__('July', 'event_espresso');
2062
+		EE_Registry::$i18n_js_strings['August']         = esc_html__('August', 'event_espresso');
2063
+		EE_Registry::$i18n_js_strings['September']      = esc_html__('September', 'event_espresso');
2064
+		EE_Registry::$i18n_js_strings['October']        = esc_html__('October', 'event_espresso');
2065
+		EE_Registry::$i18n_js_strings['November']       = esc_html__('November', 'event_espresso');
2066
+		EE_Registry::$i18n_js_strings['December']       = esc_html__('December', 'event_espresso');
2067
+		EE_Registry::$i18n_js_strings['Jan']            = esc_html__('Jan', 'event_espresso');
2068
+		EE_Registry::$i18n_js_strings['Feb']            = esc_html__('Feb', 'event_espresso');
2069
+		EE_Registry::$i18n_js_strings['Mar']            = esc_html__('Mar', 'event_espresso');
2070
+		EE_Registry::$i18n_js_strings['Apr']            = esc_html__('Apr', 'event_espresso');
2071
+		EE_Registry::$i18n_js_strings['May']            = esc_html__('May', 'event_espresso');
2072
+		EE_Registry::$i18n_js_strings['Jun']            = esc_html__('Jun', 'event_espresso');
2073
+		EE_Registry::$i18n_js_strings['Jul']            = esc_html__('Jul', 'event_espresso');
2074
+		EE_Registry::$i18n_js_strings['Aug']            = esc_html__('Aug', 'event_espresso');
2075
+		EE_Registry::$i18n_js_strings['Sep']            = esc_html__('Sep', 'event_espresso');
2076
+		EE_Registry::$i18n_js_strings['Oct']            = esc_html__('Oct', 'event_espresso');
2077
+		EE_Registry::$i18n_js_strings['Nov']            = esc_html__('Nov', 'event_espresso');
2078
+		EE_Registry::$i18n_js_strings['Dec']            = esc_html__('Dec', 'event_espresso');
2079
+		EE_Registry::$i18n_js_strings['Sunday']         = esc_html__('Sunday', 'event_espresso');
2080
+		EE_Registry::$i18n_js_strings['Monday']         = esc_html__('Monday', 'event_espresso');
2081
+		EE_Registry::$i18n_js_strings['Tuesday']        = esc_html__('Tuesday', 'event_espresso');
2082
+		EE_Registry::$i18n_js_strings['Wednesday']      = esc_html__('Wednesday', 'event_espresso');
2083
+		EE_Registry::$i18n_js_strings['Thursday']       = esc_html__('Thursday', 'event_espresso');
2084
+		EE_Registry::$i18n_js_strings['Friday']         = esc_html__('Friday', 'event_espresso');
2085
+		EE_Registry::$i18n_js_strings['Saturday']       = esc_html__('Saturday', 'event_espresso');
2086
+		EE_Registry::$i18n_js_strings['Sun']            = esc_html__('Sun', 'event_espresso');
2087
+		EE_Registry::$i18n_js_strings['Mon']            = esc_html__('Mon', 'event_espresso');
2088
+		EE_Registry::$i18n_js_strings['Tue']            = esc_html__('Tue', 'event_espresso');
2089
+		EE_Registry::$i18n_js_strings['Wed']            = esc_html__('Wed', 'event_espresso');
2090
+		EE_Registry::$i18n_js_strings['Thu']            = esc_html__('Thu', 'event_espresso');
2091
+		EE_Registry::$i18n_js_strings['Fri']            = esc_html__('Fri', 'event_espresso');
2092
+		EE_Registry::$i18n_js_strings['Sat']            = esc_html__('Sat', 'event_espresso');
2093
+	}
2094
+
2095
+
2096
+
2097
+	/**
2098
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2099
+	 *
2100
+	 * @return        void
2101
+	 */
2102
+	public function add_xdebug_style()
2103
+	{
2104
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2105
+	}
2106
+
2107
+
2108
+	/************************/
2109
+	/** LIST TABLE METHODS **/
2110
+	/************************/
2111
+	/**
2112
+	 * this sets up the list table if the current view requires it.
2113
+	 *
2114
+	 * @return void
2115
+	 * @throws EE_Error
2116
+	 */
2117
+	protected function _set_list_table()
2118
+	{
2119
+		//first is this a list_table view?
2120
+		if (! isset($this->_route_config['list_table'])) {
2121
+			return;
2122
+		} //not a list_table view so get out.
2123
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2124
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2125
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2126
+			//user error msg
2127
+			$error_msg = esc_html__(
2128
+				'An error occurred. The requested list table views could not be found.',
2129
+				'event_espresso'
2130
+			);
2131
+			//developer error msg
2132
+			$error_msg .= '||' . sprintf(
2133
+					esc_html__(
2134
+						'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.',
2135
+						'event_espresso'
2136
+					),
2137
+					$this->_req_action,
2138
+					$list_table_view
2139
+				);
2140
+			throw new EE_Error($error_msg);
2141
+		}
2142
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2143
+		$this->_views = apply_filters(
2144
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2145
+			$this->_views
2146
+		);
2147
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2148
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2149
+		$this->_set_list_table_view();
2150
+		$this->_set_list_table_object();
2151
+	}
2152
+
2153
+
2154
+
2155
+	/**
2156
+	 * set current view for List Table
2157
+	 *
2158
+	 * @return void
2159
+	 */
2160
+	protected function _set_list_table_view()
2161
+	{
2162
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2163
+		// looking at active items or dumpster diving ?
2164
+		if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2165
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2166
+		} else {
2167
+			$this->_view = sanitize_key($this->_req_data['status']);
2168
+		}
2169
+	}
2170
+
2171
+
2172
+	/**
2173
+	 * _set_list_table_object
2174
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2175
+	 *
2176
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2177
+	 * @throws \InvalidArgumentException
2178
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2179
+	 * @throws EE_Error
2180
+	 * @throws InvalidInterfaceException
2181
+	 */
2182
+	protected function _set_list_table_object()
2183
+	{
2184
+		if (isset($this->_route_config['list_table'])) {
2185
+			if (! class_exists($this->_route_config['list_table'])) {
2186
+				throw new EE_Error(
2187
+					sprintf(
2188
+						esc_html__(
2189
+							'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.',
2190
+							'event_espresso'
2191
+						),
2192
+						$this->_route_config['list_table'],
2193
+						get_class($this)
2194
+					)
2195
+				);
2196
+			}
2197
+			$this->_list_table_object = LoaderFactory::getLoader()->getShared(
2198
+				$this->_route_config['list_table'],
2199
+				array($this)
2200
+			);
2201
+		}
2202
+	}
2203
+
2204
+
2205
+
2206
+	/**
2207
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2208
+	 *
2209
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2210
+	 *                                                    urls.  The array should be indexed by the view it is being
2211
+	 *                                                    added to.
2212
+	 * @return array
2213
+	 */
2214
+	public function get_list_table_view_RLs($extra_query_args = array())
2215
+	{
2216
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2217
+		if (empty($this->_views)) {
2218
+			$this->_views = array();
2219
+		}
2220
+		// cycle thru views
2221
+		foreach ($this->_views as $key => $view) {
2222
+			$query_args = array();
2223
+			// check for current view
2224
+			$this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2225
+			$query_args['action']                      = $this->_req_action;
2226
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2227
+			$query_args['status']                      = $view['slug'];
2228
+			//merge any other arguments sent in.
2229
+			if (isset($extra_query_args[$view['slug']])) {
2230
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
2231
+			}
2232
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2233
+		}
2234
+		return $this->_views;
2235
+	}
2236
+
2237
+
2238
+
2239
+	/**
2240
+	 * _entries_per_page_dropdown
2241
+	 * generates a drop down box for selecting the number of visible rows in an admin page list table
2242
+	 *
2243
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2244
+	 *         WP does it.
2245
+	 * @param int $max_entries total number of rows in the table
2246
+	 * @return string
2247
+	 */
2248
+	protected function _entries_per_page_dropdown($max_entries = 0)
2249
+	{
2250
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2251
+		$values   = array(10, 25, 50, 100);
2252
+		$per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2253
+		if ($max_entries) {
2254
+			$values[] = $max_entries;
2255
+			sort($values);
2256
+		}
2257
+		$entries_per_page_dropdown = '
2258 2258
 			<div id="entries-per-page-dv" class="alignleft actions">
2259 2259
 				<label class="hide-if-no-js">
2260 2260
 					Show
2261 2261
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2262
-        foreach ($values as $value) {
2263
-            if ($value < $max_entries) {
2264
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2265
-                $entries_per_page_dropdown .= '
2262
+		foreach ($values as $value) {
2263
+			if ($value < $max_entries) {
2264
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2265
+				$entries_per_page_dropdown .= '
2266 2266
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2267
-            }
2268
-        }
2269
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2270
-        $entries_per_page_dropdown .= '
2267
+			}
2268
+		}
2269
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2270
+		$entries_per_page_dropdown .= '
2271 2271
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2272
-        $entries_per_page_dropdown .= '
2272
+		$entries_per_page_dropdown .= '
2273 2273
 					</select>
2274 2274
 					entries
2275 2275
 				</label>
2276 2276
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2277 2277
 			</div>
2278 2278
 		';
2279
-        return $entries_per_page_dropdown;
2280
-    }
2281
-
2282
-
2283
-
2284
-    /**
2285
-     *        _set_search_attributes
2286
-     *
2287
-     * @return        void
2288
-     */
2289
-    public function _set_search_attributes()
2290
-    {
2291
-        $this->_template_args['search']['btn_label'] = sprintf(
2292
-            esc_html__('Search %s', 'event_espresso'),
2293
-            empty($this->_search_btn_label) ? $this->page_label
2294
-                : $this->_search_btn_label
2295
-        );
2296
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2297
-    }
2298
-
2299
-
2300
-
2301
-    /*** END LIST TABLE METHODS **/
2302
-
2303
-
2304
-
2305
-    /**
2306
-     * _add_registered_metaboxes
2307
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2308
-     *
2309
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2310
-     * @return void
2311
-     * @throws EE_Error
2312
-     */
2313
-    private function _add_registered_meta_boxes()
2314
-    {
2315
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2316
-        //we only add meta boxes if the page_route calls for it
2317
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2318
-            && is_array(
2319
-                $this->_route_config['metaboxes']
2320
-            )
2321
-        ) {
2322
-            // this simply loops through the callbacks provided
2323
-            // and checks if there is a corresponding callback registered by the child
2324
-            // if there is then we go ahead and process the metabox loader.
2325
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2326
-                // first check for Closures
2327
-                if ($metabox_callback instanceof Closure) {
2328
-                    $result = $metabox_callback();
2329
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2330
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2331
-                } else {
2332
-                    $result = call_user_func(array($this, &$metabox_callback));
2333
-                }
2334
-                if ($result === false) {
2335
-                    // user error msg
2336
-                    $error_msg = esc_html__(
2337
-                            'An error occurred. The  requested metabox could not be found.',
2338
-                            'event_espresso'
2339
-                    );
2340
-                    // developer error msg
2341
-                    $error_msg .= '||' . sprintf(
2342
-                            esc_html__(
2343
-                                '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.',
2344
-                                'event_espresso'
2345
-                            ),
2346
-                            $metabox_callback
2347
-                        );
2348
-                    throw new EE_Error($error_msg);
2349
-                }
2350
-            }
2351
-        }
2352
-    }
2353
-
2354
-
2355
-
2356
-    /**
2357
-     * _add_screen_columns
2358
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2359
-     * the dynamic column template and we'll setup the column options for the page.
2360
-     *
2361
-     * @return void
2362
-     */
2363
-    private function _add_screen_columns()
2364
-    {
2365
-        if (
2366
-            is_array($this->_route_config)
2367
-            && isset($this->_route_config['columns'])
2368
-            && is_array($this->_route_config['columns'])
2369
-            && count($this->_route_config['columns']) === 2
2370
-        ) {
2371
-            add_screen_option(
2372
-                'layout_columns',
2373
-                array(
2374
-                    'max'     => (int)$this->_route_config['columns'][0],
2375
-                    'default' => (int)$this->_route_config['columns'][1],
2376
-                )
2377
-            );
2378
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2379
-            $screen_id                                           = $this->_current_screen->id;
2380
-            $screen_columns                                      = (int)get_user_option("screen_layout_{$screen_id}");
2381
-            $total_columns                                       = ! empty($screen_columns)
2382
-                ? $screen_columns
2383
-                : $this->_route_config['columns'][1];
2384
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2385
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2386
-            $this->_template_args['screen']                      = $this->_current_screen;
2387
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2388
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2389
-            // finally if we don't have has_metaboxes set in the route config
2390
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2391
-            $this->_route_config['has_metaboxes'] = true;
2392
-        }
2393
-    }
2394
-
2395
-
2396
-
2397
-    /** GLOBALLY AVAILABLE METABOXES **/
2398
-
2399
-
2400
-    /**
2401
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2402
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2403
-     * these get loaded on.
2404
-     */
2405
-    private function _espresso_news_post_box()
2406
-    {
2407
-        $news_box_title = apply_filters(
2408
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2409
-            esc_html__('New @ Event Espresso', 'event_espresso')
2410
-        );
2411
-        add_meta_box(
2412
-            'espresso_news_post_box',
2413
-            $news_box_title,
2414
-            array(
2415
-                $this,
2416
-                'espresso_news_post_box',
2417
-            ),
2418
-            $this->_wp_page_slug,
2419
-            'side'
2420
-        );
2421
-    }
2422
-
2423
-
2424
-
2425
-    /**
2426
-     * Code for setting up espresso ratings request metabox.
2427
-     */
2428
-    protected function _espresso_ratings_request()
2429
-    {
2430
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2431
-            return;
2432
-        }
2433
-        $ratings_box_title = apply_filters(
2434
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2435
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2436
-        );
2437
-        add_meta_box(
2438
-            'espresso_ratings_request',
2439
-            $ratings_box_title,
2440
-            array(
2441
-                $this,
2442
-                'espresso_ratings_request',
2443
-            ),
2444
-            $this->_wp_page_slug,
2445
-            'side'
2446
-        );
2447
-    }
2448
-
2449
-
2450
-
2451
-    /**
2452
-     * Code for setting up espresso ratings request metabox content.
2453
-     *
2454
-     * @throws DomainException
2455
-     */
2456
-    public function espresso_ratings_request()
2457
-    {
2458
-        EEH_Template::display_template(
2459
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2460
-                array()
2461
-        );
2462
-    }
2463
-
2464
-
2465
-
2466
-    public static function cached_rss_display($rss_id, $url)
2467
-    {
2468
-        $loading    = '<p class="widget-loading hide-if-no-js">'
2469
-                      . __('Loading&#8230;')
2470
-                      . '</p><p class="hide-if-js">'
2471
-                      . esc_html__('This widget requires JavaScript.')
2472
-                      . '</p>';
2473
-        $pre        = '<div class="espresso-rss-display">' . "\n\t";
2474
-        $pre        .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2475
-        $post       = '</div>' . "\n";
2476
-        $cache_key  = 'ee_rss_' . md5($rss_id);
2477
-        $output = get_transient($cache_key);
2478
-        if ($output !== false) {
2479
-            echo $pre . $output . $post;
2480
-            return true;
2481
-        }
2482
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2483
-            echo $pre . $loading . $post;
2484
-            return false;
2485
-        }
2486
-        ob_start();
2487
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2488
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2489
-        return true;
2490
-    }
2491
-
2492
-
2493
-
2494
-    public function espresso_news_post_box()
2495
-    {
2496
-        ?>
2279
+		return $entries_per_page_dropdown;
2280
+	}
2281
+
2282
+
2283
+
2284
+	/**
2285
+	 *        _set_search_attributes
2286
+	 *
2287
+	 * @return        void
2288
+	 */
2289
+	public function _set_search_attributes()
2290
+	{
2291
+		$this->_template_args['search']['btn_label'] = sprintf(
2292
+			esc_html__('Search %s', 'event_espresso'),
2293
+			empty($this->_search_btn_label) ? $this->page_label
2294
+				: $this->_search_btn_label
2295
+		);
2296
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2297
+	}
2298
+
2299
+
2300
+
2301
+	/*** END LIST TABLE METHODS **/
2302
+
2303
+
2304
+
2305
+	/**
2306
+	 * _add_registered_metaboxes
2307
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2308
+	 *
2309
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2310
+	 * @return void
2311
+	 * @throws EE_Error
2312
+	 */
2313
+	private function _add_registered_meta_boxes()
2314
+	{
2315
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2316
+		//we only add meta boxes if the page_route calls for it
2317
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2318
+			&& is_array(
2319
+				$this->_route_config['metaboxes']
2320
+			)
2321
+		) {
2322
+			// this simply loops through the callbacks provided
2323
+			// and checks if there is a corresponding callback registered by the child
2324
+			// if there is then we go ahead and process the metabox loader.
2325
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2326
+				// first check for Closures
2327
+				if ($metabox_callback instanceof Closure) {
2328
+					$result = $metabox_callback();
2329
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2330
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2331
+				} else {
2332
+					$result = call_user_func(array($this, &$metabox_callback));
2333
+				}
2334
+				if ($result === false) {
2335
+					// user error msg
2336
+					$error_msg = esc_html__(
2337
+							'An error occurred. The  requested metabox could not be found.',
2338
+							'event_espresso'
2339
+					);
2340
+					// developer error msg
2341
+					$error_msg .= '||' . sprintf(
2342
+							esc_html__(
2343
+								'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.',
2344
+								'event_espresso'
2345
+							),
2346
+							$metabox_callback
2347
+						);
2348
+					throw new EE_Error($error_msg);
2349
+				}
2350
+			}
2351
+		}
2352
+	}
2353
+
2354
+
2355
+
2356
+	/**
2357
+	 * _add_screen_columns
2358
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2359
+	 * the dynamic column template and we'll setup the column options for the page.
2360
+	 *
2361
+	 * @return void
2362
+	 */
2363
+	private function _add_screen_columns()
2364
+	{
2365
+		if (
2366
+			is_array($this->_route_config)
2367
+			&& isset($this->_route_config['columns'])
2368
+			&& is_array($this->_route_config['columns'])
2369
+			&& count($this->_route_config['columns']) === 2
2370
+		) {
2371
+			add_screen_option(
2372
+				'layout_columns',
2373
+				array(
2374
+					'max'     => (int)$this->_route_config['columns'][0],
2375
+					'default' => (int)$this->_route_config['columns'][1],
2376
+				)
2377
+			);
2378
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2379
+			$screen_id                                           = $this->_current_screen->id;
2380
+			$screen_columns                                      = (int)get_user_option("screen_layout_{$screen_id}");
2381
+			$total_columns                                       = ! empty($screen_columns)
2382
+				? $screen_columns
2383
+				: $this->_route_config['columns'][1];
2384
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2385
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2386
+			$this->_template_args['screen']                      = $this->_current_screen;
2387
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2388
+																   . 'admin_details_metabox_column_wrapper.template.php';
2389
+			// finally if we don't have has_metaboxes set in the route config
2390
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2391
+			$this->_route_config['has_metaboxes'] = true;
2392
+		}
2393
+	}
2394
+
2395
+
2396
+
2397
+	/** GLOBALLY AVAILABLE METABOXES **/
2398
+
2399
+
2400
+	/**
2401
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2402
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2403
+	 * these get loaded on.
2404
+	 */
2405
+	private function _espresso_news_post_box()
2406
+	{
2407
+		$news_box_title = apply_filters(
2408
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2409
+			esc_html__('New @ Event Espresso', 'event_espresso')
2410
+		);
2411
+		add_meta_box(
2412
+			'espresso_news_post_box',
2413
+			$news_box_title,
2414
+			array(
2415
+				$this,
2416
+				'espresso_news_post_box',
2417
+			),
2418
+			$this->_wp_page_slug,
2419
+			'side'
2420
+		);
2421
+	}
2422
+
2423
+
2424
+
2425
+	/**
2426
+	 * Code for setting up espresso ratings request metabox.
2427
+	 */
2428
+	protected function _espresso_ratings_request()
2429
+	{
2430
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2431
+			return;
2432
+		}
2433
+		$ratings_box_title = apply_filters(
2434
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2435
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2436
+		);
2437
+		add_meta_box(
2438
+			'espresso_ratings_request',
2439
+			$ratings_box_title,
2440
+			array(
2441
+				$this,
2442
+				'espresso_ratings_request',
2443
+			),
2444
+			$this->_wp_page_slug,
2445
+			'side'
2446
+		);
2447
+	}
2448
+
2449
+
2450
+
2451
+	/**
2452
+	 * Code for setting up espresso ratings request metabox content.
2453
+	 *
2454
+	 * @throws DomainException
2455
+	 */
2456
+	public function espresso_ratings_request()
2457
+	{
2458
+		EEH_Template::display_template(
2459
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2460
+				array()
2461
+		);
2462
+	}
2463
+
2464
+
2465
+
2466
+	public static function cached_rss_display($rss_id, $url)
2467
+	{
2468
+		$loading    = '<p class="widget-loading hide-if-no-js">'
2469
+					  . __('Loading&#8230;')
2470
+					  . '</p><p class="hide-if-js">'
2471
+					  . esc_html__('This widget requires JavaScript.')
2472
+					  . '</p>';
2473
+		$pre        = '<div class="espresso-rss-display">' . "\n\t";
2474
+		$pre        .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2475
+		$post       = '</div>' . "\n";
2476
+		$cache_key  = 'ee_rss_' . md5($rss_id);
2477
+		$output = get_transient($cache_key);
2478
+		if ($output !== false) {
2479
+			echo $pre . $output . $post;
2480
+			return true;
2481
+		}
2482
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2483
+			echo $pre . $loading . $post;
2484
+			return false;
2485
+		}
2486
+		ob_start();
2487
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2488
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2489
+		return true;
2490
+	}
2491
+
2492
+
2493
+
2494
+	public function espresso_news_post_box()
2495
+	{
2496
+		?>
2497 2497
         <div class="padding">
2498 2498
             <div id="espresso_news_post_box_content" class="infolinks">
2499 2499
                 <?php
2500
-                // Get RSS Feed(s)
2501
-                self::cached_rss_display(
2502
-                    'espresso_news_post_box_content',
2503
-                    urlencode(
2504
-                        apply_filters(
2505
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2506
-                            'http://eventespresso.com/feed/'
2507
-                        )
2508
-                    )
2509
-                );
2510
-                ?>
2500
+				// Get RSS Feed(s)
2501
+				self::cached_rss_display(
2502
+					'espresso_news_post_box_content',
2503
+					urlencode(
2504
+						apply_filters(
2505
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2506
+							'http://eventespresso.com/feed/'
2507
+						)
2508
+					)
2509
+				);
2510
+				?>
2511 2511
             </div>
2512 2512
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2513 2513
         </div>
2514 2514
         <?php
2515
-    }
2516
-
2517
-
2518
-
2519
-    private function _espresso_links_post_box()
2520
-    {
2521
-        //Hiding until we actually have content to put in here...
2522
-        //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');
2523
-    }
2524
-
2525
-
2526
-
2527
-    public function espresso_links_post_box()
2528
-    {
2529
-        //Hiding until we actually have content to put in here...
2530
-        // EEH_Template::display_template(
2531
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2532
-        // );
2533
-    }
2534
-
2535
-
2536
-
2537
-    protected function _espresso_sponsors_post_box()
2538
-    {
2539
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2540
-            add_meta_box(
2541
-                'espresso_sponsors_post_box',
2542
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2543
-                array($this, 'espresso_sponsors_post_box'),
2544
-                $this->_wp_page_slug,
2545
-                'side'
2546
-            );
2547
-        }
2548
-    }
2549
-
2550
-
2551
-
2552
-    public function espresso_sponsors_post_box()
2553
-    {
2554
-        EEH_Template::display_template(
2555
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2556
-        );
2557
-    }
2558
-
2559
-
2560
-
2561
-    private function _publish_post_box()
2562
-    {
2563
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2564
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2565
-        // then we'll use that for the metabox label.
2566
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2567
-        if (! empty($this->_labels['publishbox'])) {
2568
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2569
-                : $this->_labels['publishbox'];
2570
-        } else {
2571
-            $box_label = esc_html__('Publish', 'event_espresso');
2572
-        }
2573
-        $box_label = apply_filters(
2574
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2575
-            $box_label,
2576
-            $this->_req_action,
2577
-            $this
2578
-        );
2579
-        add_meta_box(
2580
-            $meta_box_ref,
2581
-            $box_label,
2582
-            array($this, 'editor_overview'),
2583
-            $this->_current_screen->id,
2584
-            'side',
2585
-            'high'
2586
-        );
2587
-    }
2588
-
2589
-
2590
-
2591
-    public function editor_overview()
2592
-    {
2593
-        //if we have extra content set let's add it in if not make sure its empty
2594
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2595
-            ? $this->_template_args['publish_box_extra_content']
2596
-            : '';
2597
-        echo EEH_Template::display_template(
2598
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2599
-            $this->_template_args,
2600
-            true
2601
-        );
2602
-    }
2603
-
2604
-
2605
-    /** end of globally available metaboxes section **/
2606
-
2607
-
2608
-
2609
-    /**
2610
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2611
-     * protected method.
2612
-     *
2613
-     * @see   $this->_set_publish_post_box_vars for param details
2614
-     * @since 4.6.0
2615
-     * @param string $name
2616
-     * @param int    $id
2617
-     * @param bool   $delete
2618
-     * @param string $save_close_redirect_URL
2619
-     * @param bool   $both_btns
2620
-     * @throws EE_Error
2621
-     * @throws InvalidArgumentException
2622
-     * @throws InvalidDataTypeException
2623
-     * @throws InvalidInterfaceException
2624
-     */
2625
-    public function set_publish_post_box_vars(
2626
-        $name = '',
2627
-        $id = 0,
2628
-        $delete = false,
2629
-        $save_close_redirect_URL = '',
2630
-        $both_btns = true
2631
-    ) {
2632
-        $this->_set_publish_post_box_vars(
2633
-            $name,
2634
-            $id,
2635
-            $delete,
2636
-            $save_close_redirect_URL,
2637
-            $both_btns
2638
-        );
2639
-    }
2640
-
2641
-
2642
-
2643
-    /**
2644
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2645
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2646
-     * save, and save and close buttons to work properly, then you will want to include a
2647
-     * values for the name and id arguments.
2648
-     *
2649
-     * @todo  Add in validation for name/id arguments.
2650
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2651
-     * @param    int     $id                      id attached to the item published
2652
-     * @param    string  $delete                  page route callback for the delete action
2653
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2654
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2655
-     *                                            the Save button
2656
-     * @throws EE_Error
2657
-     * @throws InvalidArgumentException
2658
-     * @throws InvalidDataTypeException
2659
-     * @throws InvalidInterfaceException
2660
-     */
2661
-    protected function _set_publish_post_box_vars(
2662
-        $name = '',
2663
-        $id = 0,
2664
-        $delete = '',
2665
-        $save_close_redirect_URL = '',
2666
-        $both_btns = true
2667
-    ) {
2668
-        // if Save & Close, use a custom redirect URL or default to the main page?
2669
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2670
-            ? $save_close_redirect_URL
2671
-            : $this->_admin_base_url;
2672
-        // create the Save & Close and Save buttons
2673
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2674
-        //if we have extra content set let's add it in if not make sure its empty
2675
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2676
-            ? $this->_template_args['publish_box_extra_content']
2677
-            : '';
2678
-        if ($delete && ! empty($id)) {
2679
-            //make sure we have a default if just true is sent.
2680
-            $delete           = ! empty($delete) ? $delete : 'delete';
2681
-            $delete_link_args = array($name => $id);
2682
-            $delete           = $this->get_action_link_or_button(
2683
-                $delete,
2684
-                $delete,
2685
-                $delete_link_args,
2686
-                'submitdelete deletion',
2687
-                '',
2688
-                false
2689
-            );
2690
-        }
2691
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2692
-        if (! empty($name) && ! empty($id)) {
2693
-            $hidden_field_arr[$name] = array(
2694
-                'type'  => 'hidden',
2695
-                'value' => $id,
2696
-            );
2697
-            $hf                      = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2698
-        } else {
2699
-            $hf = '';
2700
-        }
2701
-        // add hidden field
2702
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2703
-            ? $hf[$name]['field']
2704
-            : $hf;
2705
-    }
2706
-
2707
-
2708
-
2709
-    /**
2710
-     * displays an error message to ppl who have javascript disabled
2711
-     *
2712
-     * @return void
2713
-     */
2714
-    private function _display_no_javascript_warning()
2715
-    {
2716
-        ?>
2515
+	}
2516
+
2517
+
2518
+
2519
+	private function _espresso_links_post_box()
2520
+	{
2521
+		//Hiding until we actually have content to put in here...
2522
+		//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');
2523
+	}
2524
+
2525
+
2526
+
2527
+	public function espresso_links_post_box()
2528
+	{
2529
+		//Hiding until we actually have content to put in here...
2530
+		// EEH_Template::display_template(
2531
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2532
+		// );
2533
+	}
2534
+
2535
+
2536
+
2537
+	protected function _espresso_sponsors_post_box()
2538
+	{
2539
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2540
+			add_meta_box(
2541
+				'espresso_sponsors_post_box',
2542
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2543
+				array($this, 'espresso_sponsors_post_box'),
2544
+				$this->_wp_page_slug,
2545
+				'side'
2546
+			);
2547
+		}
2548
+	}
2549
+
2550
+
2551
+
2552
+	public function espresso_sponsors_post_box()
2553
+	{
2554
+		EEH_Template::display_template(
2555
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2556
+		);
2557
+	}
2558
+
2559
+
2560
+
2561
+	private function _publish_post_box()
2562
+	{
2563
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2564
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2565
+		// then we'll use that for the metabox label.
2566
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2567
+		if (! empty($this->_labels['publishbox'])) {
2568
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2569
+				: $this->_labels['publishbox'];
2570
+		} else {
2571
+			$box_label = esc_html__('Publish', 'event_espresso');
2572
+		}
2573
+		$box_label = apply_filters(
2574
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2575
+			$box_label,
2576
+			$this->_req_action,
2577
+			$this
2578
+		);
2579
+		add_meta_box(
2580
+			$meta_box_ref,
2581
+			$box_label,
2582
+			array($this, 'editor_overview'),
2583
+			$this->_current_screen->id,
2584
+			'side',
2585
+			'high'
2586
+		);
2587
+	}
2588
+
2589
+
2590
+
2591
+	public function editor_overview()
2592
+	{
2593
+		//if we have extra content set let's add it in if not make sure its empty
2594
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2595
+			? $this->_template_args['publish_box_extra_content']
2596
+			: '';
2597
+		echo EEH_Template::display_template(
2598
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2599
+			$this->_template_args,
2600
+			true
2601
+		);
2602
+	}
2603
+
2604
+
2605
+	/** end of globally available metaboxes section **/
2606
+
2607
+
2608
+
2609
+	/**
2610
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2611
+	 * protected method.
2612
+	 *
2613
+	 * @see   $this->_set_publish_post_box_vars for param details
2614
+	 * @since 4.6.0
2615
+	 * @param string $name
2616
+	 * @param int    $id
2617
+	 * @param bool   $delete
2618
+	 * @param string $save_close_redirect_URL
2619
+	 * @param bool   $both_btns
2620
+	 * @throws EE_Error
2621
+	 * @throws InvalidArgumentException
2622
+	 * @throws InvalidDataTypeException
2623
+	 * @throws InvalidInterfaceException
2624
+	 */
2625
+	public function set_publish_post_box_vars(
2626
+		$name = '',
2627
+		$id = 0,
2628
+		$delete = false,
2629
+		$save_close_redirect_URL = '',
2630
+		$both_btns = true
2631
+	) {
2632
+		$this->_set_publish_post_box_vars(
2633
+			$name,
2634
+			$id,
2635
+			$delete,
2636
+			$save_close_redirect_URL,
2637
+			$both_btns
2638
+		);
2639
+	}
2640
+
2641
+
2642
+
2643
+	/**
2644
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2645
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2646
+	 * save, and save and close buttons to work properly, then you will want to include a
2647
+	 * values for the name and id arguments.
2648
+	 *
2649
+	 * @todo  Add in validation for name/id arguments.
2650
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2651
+	 * @param    int     $id                      id attached to the item published
2652
+	 * @param    string  $delete                  page route callback for the delete action
2653
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2654
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2655
+	 *                                            the Save button
2656
+	 * @throws EE_Error
2657
+	 * @throws InvalidArgumentException
2658
+	 * @throws InvalidDataTypeException
2659
+	 * @throws InvalidInterfaceException
2660
+	 */
2661
+	protected function _set_publish_post_box_vars(
2662
+		$name = '',
2663
+		$id = 0,
2664
+		$delete = '',
2665
+		$save_close_redirect_URL = '',
2666
+		$both_btns = true
2667
+	) {
2668
+		// if Save & Close, use a custom redirect URL or default to the main page?
2669
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2670
+			? $save_close_redirect_URL
2671
+			: $this->_admin_base_url;
2672
+		// create the Save & Close and Save buttons
2673
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2674
+		//if we have extra content set let's add it in if not make sure its empty
2675
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2676
+			? $this->_template_args['publish_box_extra_content']
2677
+			: '';
2678
+		if ($delete && ! empty($id)) {
2679
+			//make sure we have a default if just true is sent.
2680
+			$delete           = ! empty($delete) ? $delete : 'delete';
2681
+			$delete_link_args = array($name => $id);
2682
+			$delete           = $this->get_action_link_or_button(
2683
+				$delete,
2684
+				$delete,
2685
+				$delete_link_args,
2686
+				'submitdelete deletion',
2687
+				'',
2688
+				false
2689
+			);
2690
+		}
2691
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2692
+		if (! empty($name) && ! empty($id)) {
2693
+			$hidden_field_arr[$name] = array(
2694
+				'type'  => 'hidden',
2695
+				'value' => $id,
2696
+			);
2697
+			$hf                      = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2698
+		} else {
2699
+			$hf = '';
2700
+		}
2701
+		// add hidden field
2702
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2703
+			? $hf[$name]['field']
2704
+			: $hf;
2705
+	}
2706
+
2707
+
2708
+
2709
+	/**
2710
+	 * displays an error message to ppl who have javascript disabled
2711
+	 *
2712
+	 * @return void
2713
+	 */
2714
+	private function _display_no_javascript_warning()
2715
+	{
2716
+		?>
2717 2717
         <noscript>
2718 2718
             <div id="no-js-message" class="error">
2719 2719
                 <p style="font-size:1.3em;">
2720 2720
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2721 2721
                     <?php esc_html_e(
2722
-                        '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.',
2723
-                        'event_espresso'
2724
-                    ); ?>
2722
+						'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.',
2723
+						'event_espresso'
2724
+					); ?>
2725 2725
                 </p>
2726 2726
             </div>
2727 2727
         </noscript>
2728 2728
         <?php
2729
-    }
2729
+	}
2730 2730
 
2731 2731
 
2732 2732
 
2733
-    /**
2734
-     * displays espresso success and/or error notices
2735
-     *
2736
-     * @return void
2737
-     */
2738
-    private function _display_espresso_notices()
2739
-    {
2740
-        $notices = $this->_get_transient(true);
2741
-        echo stripslashes($notices);
2742
-    }
2733
+	/**
2734
+	 * displays espresso success and/or error notices
2735
+	 *
2736
+	 * @return void
2737
+	 */
2738
+	private function _display_espresso_notices()
2739
+	{
2740
+		$notices = $this->_get_transient(true);
2741
+		echo stripslashes($notices);
2742
+	}
2743 2743
 
2744 2744
 
2745 2745
 
2746
-    /**
2747
-     * spinny things pacify the masses
2748
-     *
2749
-     * @return void
2750
-     */
2751
-    protected function _add_admin_page_ajax_loading_img()
2752
-    {
2753
-        ?>
2746
+	/**
2747
+	 * spinny things pacify the masses
2748
+	 *
2749
+	 * @return void
2750
+	 */
2751
+	protected function _add_admin_page_ajax_loading_img()
2752
+	{
2753
+		?>
2754 2754
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2755 2755
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e(
2756
-                    'loading...',
2757
-                    'event_espresso'
2758
-                ); ?></span>
2756
+					'loading...',
2757
+					'event_espresso'
2758
+				); ?></span>
2759 2759
         </div>
2760 2760
         <?php
2761
-    }
2761
+	}
2762 2762
 
2763 2763
 
2764 2764
 
2765
-    /**
2766
-     * add admin page overlay for modal boxes
2767
-     *
2768
-     * @return void
2769
-     */
2770
-    protected function _add_admin_page_overlay()
2771
-    {
2772
-        ?>
2765
+	/**
2766
+	 * add admin page overlay for modal boxes
2767
+	 *
2768
+	 * @return void
2769
+	 */
2770
+	protected function _add_admin_page_overlay()
2771
+	{
2772
+		?>
2773 2773
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2774 2774
         <?php
2775
-    }
2776
-
2777
-
2778
-
2779
-    /**
2780
-     * facade for add_meta_box
2781
-     *
2782
-     * @param string  $action        where the metabox get's displayed
2783
-     * @param string  $title         Title of Metabox (output in metabox header)
2784
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2785
-     *                               instead of the one created in here.
2786
-     * @param array   $callback_args an array of args supplied for the metabox
2787
-     * @param string  $column        what metabox column
2788
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2789
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2790
-     *                               created but just set our own callback for wp's add_meta_box.
2791
-     * @throws \DomainException
2792
-     */
2793
-    public function _add_admin_page_meta_box(
2794
-        $action,
2795
-        $title,
2796
-        $callback,
2797
-        $callback_args,
2798
-        $column = 'normal',
2799
-        $priority = 'high',
2800
-        $create_func = true
2801
-    ) {
2802
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2803
-        //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.
2804
-        if (empty($callback_args) && $create_func) {
2805
-            $callback_args = array(
2806
-                'template_path' => $this->_template_path,
2807
-                'template_args' => $this->_template_args,
2808
-            );
2809
-        }
2810
-        //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)
2811
-        $call_back_func = $create_func
2812
-            ? function ($post, $metabox)
2813
-            {
2814
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2815
-                echo EEH_Template::display_template(
2816
-                    $metabox['args']['template_path'],
2817
-                    $metabox['args']['template_args'],
2818
-                    true
2819
-                );
2820
-            }
2821
-            : $callback;
2822
-        add_meta_box(
2823
-            str_replace('_', '-', $action) . '-mbox',
2824
-            $title,
2825
-            $call_back_func,
2826
-            $this->_wp_page_slug,
2827
-            $column,
2828
-            $priority,
2829
-            $callback_args
2830
-        );
2831
-    }
2832
-
2833
-
2834
-
2835
-    /**
2836
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2837
-     *
2838
-     * @throws DomainException
2839
-     * @throws EE_Error
2840
-     */
2841
-    public function display_admin_page_with_metabox_columns()
2842
-    {
2843
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2844
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2845
-            $this->_column_template_path,
2846
-            $this->_template_args,
2847
-            true
2848
-        );
2849
-        //the final wrapper
2850
-        $this->admin_page_wrapper();
2851
-    }
2852
-
2853
-
2854
-
2855
-    /**
2856
-     * generates  HTML wrapper for an admin details page
2857
-     *
2858
-     * @return void
2859
-     * @throws EE_Error
2860
-     * @throws DomainException
2861
-     */
2862
-    public function display_admin_page_with_sidebar()
2863
-    {
2864
-        $this->_display_admin_page(true);
2865
-    }
2866
-
2867
-
2868
-
2869
-    /**
2870
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2871
-     *
2872
-     * @return void
2873
-     * @throws EE_Error
2874
-     * @throws DomainException
2875
-     */
2876
-    public function display_admin_page_with_no_sidebar()
2877
-    {
2878
-        $this->_display_admin_page();
2879
-    }
2880
-
2881
-
2882
-
2883
-    /**
2884
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2885
-     *
2886
-     * @return void
2887
-     * @throws EE_Error
2888
-     * @throws DomainException
2889
-     */
2890
-    public function display_about_admin_page()
2891
-    {
2892
-        $this->_display_admin_page(false, true);
2893
-    }
2894
-
2895
-
2896
-
2897
-    /**
2898
-     * display_admin_page
2899
-     * contains the code for actually displaying an admin page
2900
-     *
2901
-     * @param  boolean $sidebar true with sidebar, false without
2902
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2903
-     * @return void
2904
-     * @throws DomainException
2905
-     * @throws EE_Error
2906
-     */
2907
-    private function _display_admin_page($sidebar = false, $about = false)
2908
-    {
2909
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2910
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2911
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2912
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2913
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2914
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2915
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2916
-            ? 'poststuff'
2917
-            : 'espresso-default-admin';
2918
-        $template_path                                     = $sidebar
2919
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2920
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2921
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2922
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2923
-        }
2924
-        $template_path                                     = ! empty($this->_column_template_path)
2925
-            ? $this->_column_template_path : $template_path;
2926
-        $this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2927
-            ? $this->_template_args['admin_page_content']
2928
-            : '';
2929
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2930
-            ? $this->_template_args['before_admin_page_content']
2931
-            : '';
2932
-        $this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2933
-            ? $this->_template_args['after_admin_page_content']
2934
-            : '';
2935
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2936
-            $template_path,
2937
-            $this->_template_args,
2938
-            true
2939
-        );
2940
-        // the final template wrapper
2941
-        $this->admin_page_wrapper($about);
2942
-    }
2943
-
2944
-
2945
-
2946
-    /**
2947
-     * This is used to display caf preview pages.
2948
-     *
2949
-     * @since 4.3.2
2950
-     * @param string $utm_campaign_source what is the key used for google analytics link
2951
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2952
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2953
-     * @return void
2954
-     * @throws DomainException
2955
-     * @throws EE_Error
2956
-     * @throws InvalidArgumentException
2957
-     * @throws InvalidDataTypeException
2958
-     * @throws InvalidInterfaceException
2959
-     */
2960
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2961
-    {
2962
-        //let's generate a default preview action button if there isn't one already present.
2963
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2964
-            'Upgrade to Event Espresso 4 Right Now',
2965
-            'event_espresso'
2966
-        );
2967
-        $buy_now_url                                   = add_query_arg(
2968
-            array(
2969
-                'ee_ver'       => 'ee4',
2970
-                'utm_source'   => 'ee4_plugin_admin',
2971
-                'utm_medium'   => 'link',
2972
-                'utm_campaign' => $utm_campaign_source,
2973
-                'utm_content'  => 'buy_now_button',
2974
-            ),
2975
-            'http://eventespresso.com/pricing/'
2976
-        );
2977
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2978
-            ? $this->get_action_link_or_button(
2979
-                '',
2980
-                'buy_now',
2981
-                array(),
2982
-                'button-primary button-large',
2983
-                $buy_now_url,
2984
-                true
2985
-            )
2986
-            : $this->_template_args['preview_action_button'];
2987
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2988
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2989
-            $this->_template_args,
2990
-            true
2991
-        );
2992
-        $this->_display_admin_page($display_sidebar);
2993
-    }
2994
-
2995
-
2996
-
2997
-    /**
2998
-     * display_admin_list_table_page_with_sidebar
2999
-     * generates HTML wrapper for an admin_page with list_table
3000
-     *
3001
-     * @return void
3002
-     * @throws EE_Error
3003
-     * @throws DomainException
3004
-     */
3005
-    public function display_admin_list_table_page_with_sidebar()
3006
-    {
3007
-        $this->_display_admin_list_table_page(true);
3008
-    }
3009
-
3010
-
3011
-
3012
-    /**
3013
-     * display_admin_list_table_page_with_no_sidebar
3014
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
3015
-     *
3016
-     * @return void
3017
-     * @throws EE_Error
3018
-     * @throws DomainException
3019
-     */
3020
-    public function display_admin_list_table_page_with_no_sidebar()
3021
-    {
3022
-        $this->_display_admin_list_table_page();
3023
-    }
3024
-
3025
-
3026
-
3027
-    /**
3028
-     * generates html wrapper for an admin_list_table page
3029
-     *
3030
-     * @param boolean $sidebar whether to display with sidebar or not.
3031
-     * @return void
3032
-     * @throws DomainException
3033
-     * @throws EE_Error
3034
-     */
3035
-    private function _display_admin_list_table_page($sidebar = false)
3036
-    {
3037
-        //setup search attributes
3038
-        $this->_set_search_attributes();
3039
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
3040
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3041
-        $this->_template_args['table_url']        = defined('DOING_AJAX')
3042
-            ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
3043
-            : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
3044
-        $this->_template_args['list_table']       = $this->_list_table_object;
3045
-        $this->_template_args['current_route']    = $this->_req_action;
3046
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3047
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
3048
-        if (! empty($ajax_sorting_callback)) {
3049
-            $sortable_list_table_form_fields = wp_nonce_field(
3050
-                $ajax_sorting_callback . '_nonce',
3051
-                $ajax_sorting_callback . '_nonce',
3052
-                false,
3053
-                false
3054
-            );
3055
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
3056
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
3057
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3058
-                                                . $this->page_slug
3059
-                                                . '" />';
3060
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3061
-                                                . $ajax_sorting_callback
3062
-                                                . '" />';
3063
-        } else {
3064
-            $sortable_list_table_form_fields = '';
3065
-        }
3066
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3067
-        $hidden_form_fields                                      = isset($this->_template_args['list_table_hidden_fields'])
3068
-            ? $this->_template_args['list_table_hidden_fields']
3069
-            : '';
3070
-        $nonce_ref                                               = $this->_req_action . '_nonce';
3071
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
3072
-                                                                    . $nonce_ref
3073
-                                                                    . '" value="'
3074
-                                                                    . wp_create_nonce($nonce_ref)
3075
-                                                                    . '">';
3076
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
3077
-        //display message about search results?
3078
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3079
-            ? '<p class="ee-search-results">' . sprintf(
3080
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3081
-                trim($this->_req_data['s'], '%')
3082
-            ) . '</p>'
3083
-            : '';
3084
-        // filter before_list_table template arg
3085
-        $this->_template_args['before_list_table'] = apply_filters(
3086
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3087
-            $this->_template_args['before_list_table'],
3088
-            $this->page_slug,
3089
-            $this->_req_data,
3090
-            $this->_req_action
3091
-        );
3092
-        // convert to array and filter again
3093
-        // arrays are easier to inject new items in a specific location,
3094
-        // but would not be backwards compatible, so we have to add a new filter
3095
-        $this->_template_args['before_list_table'] = implode(
3096
-            " \n",
3097
-            (array)apply_filters(
3098
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3099
-                (array)$this->_template_args['before_list_table'],
3100
-                $this->page_slug,
3101
-                $this->_req_data,
3102
-                $this->_req_action
3103
-            )
3104
-        );
3105
-        // filter after_list_table template arg
3106
-        $this->_template_args['after_list_table'] = apply_filters(
3107
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3108
-            $this->_template_args['after_list_table'],
3109
-            $this->page_slug,
3110
-            $this->_req_data,
3111
-            $this->_req_action
3112
-        );
3113
-        // convert to array and filter again
3114
-        // arrays are easier to inject new items in a specific location,
3115
-        // but would not be backwards compatible, so we have to add a new filter
3116
-        $this->_template_args['after_list_table']   = implode(
3117
-            " \n",
3118
-            (array)apply_filters(
3119
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3120
-                (array)$this->_template_args['after_list_table'],
3121
-                $this->page_slug,
3122
-                $this->_req_data,
3123
-                $this->_req_action
3124
-            )
3125
-        );
3126
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3127
-            $template_path,
3128
-            $this->_template_args,
3129
-            true
3130
-        );
3131
-        // the final template wrapper
3132
-        if ($sidebar) {
3133
-            $this->display_admin_page_with_sidebar();
3134
-        } else {
3135
-            $this->display_admin_page_with_no_sidebar();
3136
-        }
3137
-    }
3138
-
3139
-
3140
-
3141
-    /**
3142
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3143
-     * html string for the legend.
3144
-     * $items are expected in an array in the following format:
3145
-     * $legend_items = array(
3146
-     *        'item_id' => array(
3147
-     *            'icon' => 'http://url_to_icon_being_described.png',
3148
-     *            'desc' => esc_html__('localized description of item');
3149
-     *        )
3150
-     * );
3151
-     *
3152
-     * @param  array $items see above for format of array
3153
-     * @return string html string of legend
3154
-     * @throws DomainException
3155
-     */
3156
-    protected function _display_legend($items)
3157
-    {
3158
-        $this->_template_args['items'] = apply_filters(
3159
-            'FHEE__EE_Admin_Page___display_legend__items',
3160
-            (array)$items,
3161
-            $this
3162
-        );
3163
-        return EEH_Template::display_template(
3164
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3165
-            $this->_template_args,
3166
-            true
3167
-        );
3168
-    }
3169
-
3170
-
3171
-    /**
3172
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3173
-     * The returned json object is created from an array in the following format:
3174
-     * array(
3175
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3176
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3177
-     *  'notices' => '', // - contains any EE_Error formatted notices
3178
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3179
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3180
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3181
-     *  that might be included in here)
3182
-     * )
3183
-     * The json object is populated by whatever is set in the $_template_args property.
3184
-     *
3185
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3186
-     *                                 instead of displayed.
3187
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3188
-     * @return void
3189
-     * @throws EE_Error
3190
-     */
3191
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
3192
-    {
3193
-        //make sure any EE_Error notices have been handled.
3194
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3195
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3196
-        unset($this->_template_args['data']);
3197
-        $json = array(
3198
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3199
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3200
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3201
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3202
-            'notices'   => EE_Error::get_notices(),
3203
-            'content'   => isset($this->_template_args['admin_page_content'])
3204
-                ? $this->_template_args['admin_page_content'] : '',
3205
-            'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3206
-            'isEEajax'  => true
3207
-            //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3208
-        );
3209
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3210
-        if (null === error_get_last() || ! headers_sent()) {
3211
-            header('Content-Type: application/json; charset=UTF-8');
3212
-        }
3213
-        echo wp_json_encode($json);
3214
-        exit();
3215
-    }
3216
-
3217
-
3218
-
3219
-    /**
3220
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3221
-     *
3222
-     * @return void
3223
-     * @throws EE_Error
3224
-     */
3225
-    public function return_json()
3226
-    {
3227
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3228
-            $this->_return_json();
3229
-        } else {
3230
-            throw new EE_Error(
3231
-                sprintf(
3232
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3233
-                    __FUNCTION__
3234
-                )
3235
-            );
3236
-        }
3237
-    }
3238
-
3239
-
3240
-
3241
-    /**
3242
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3243
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3244
-     *
3245
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3246
-     */
3247
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3248
-    {
3249
-        $this->_hook_obj = $hook_obj;
3250
-    }
3251
-
3252
-
3253
-
3254
-    /**
3255
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3256
-     *
3257
-     * @param  boolean $about whether to use the special about page wrapper or default.
3258
-     * @return void
3259
-     * @throws DomainException
3260
-     * @throws EE_Error
3261
-     */
3262
-    public function admin_page_wrapper($about = false)
3263
-    {
3264
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3265
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3266
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3267
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3268
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3269
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3270
-            isset($this->_template_args['before_admin_page_content'])
3271
-                ? $this->_template_args['before_admin_page_content']
3272
-                : ''
3273
-        );
3274
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3275
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3276
-            isset($this->_template_args['after_admin_page_content'])
3277
-                ? $this->_template_args['after_admin_page_content']
3278
-                : ''
3279
-        );
3280
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3281
-        // load settings page wrapper template
3282
-        $template_path = ! defined('DOING_AJAX')
3283
-            ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3284
-            : EE_ADMIN_TEMPLATE
3285
-              . 'admin_wrapper_ajax.template.php';
3286
-        //about page?
3287
-        $template_path = $about
3288
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3289
-            : $template_path;
3290
-        if (defined('DOING_AJAX')) {
3291
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3292
-                $template_path,
3293
-                $this->_template_args,
3294
-                true
3295
-            );
3296
-            $this->_return_json();
3297
-        } else {
3298
-            EEH_Template::display_template($template_path, $this->_template_args);
3299
-        }
3300
-    }
3301
-
3302
-
3303
-
3304
-    /**
3305
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3306
-     *
3307
-     * @return string html
3308
-     * @throws EE_Error
3309
-     */
3310
-    protected function _get_main_nav_tabs()
3311
-    {
3312
-        // let's generate the html using the EEH_Tabbed_Content helper.
3313
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3314
-        // (rather than setting in the page_routes array)
3315
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3316
-    }
3317
-
3318
-
3319
-
3320
-    /**
3321
-     *        sort nav tabs
3322
-     *
3323
-     * @param $a
3324
-     * @param $b
3325
-     * @return int
3326
-     */
3327
-    private function _sort_nav_tabs($a, $b)
3328
-    {
3329
-        if ($a['order'] === $b['order']) {
3330
-            return 0;
3331
-        }
3332
-        return ($a['order'] < $b['order']) ? -1 : 1;
3333
-    }
3334
-
3335
-
3336
-
3337
-    /**
3338
-     *    generates HTML for the forms used on admin pages
3339
-     *
3340
-     * @param    array $input_vars - array of input field details
3341
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3342
-     *                             use)
3343
-     * @param bool     $id
3344
-     * @return string
3345
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3346
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3347
-     */
3348
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3349
-    {
3350
-        $content = $generator === 'string'
3351
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3352
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3353
-        return $content;
3354
-    }
3355
-
3356
-
3357
-
3358
-    /**
3359
-     * generates the "Save" and "Save & Close" buttons for edit forms
3360
-     *
3361
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3362
-     *                                   Close" button.
3363
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3364
-     *                                   'Save', [1] => 'save & close')
3365
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3366
-     *                                   via the "name" value in the button).  We can also use this to just dump
3367
-     *                                   default actions by submitting some other value.
3368
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3369
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3370
-     *                                   close (normal form handling).
3371
-     */
3372
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3373
-    {
3374
-        //make sure $text and $actions are in an array
3375
-        $text          = (array)$text;
3376
-        $actions       = (array)$actions;
3377
-        $referrer_url  = empty($referrer)
3378
-            ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3379
-              . $_SERVER['REQUEST_URI']
3380
-              . '" />'
3381
-            : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3382
-              . $referrer
3383
-              . '" />';
3384
-        $button_text   = ! empty($text)
3385
-            ? $text
3386
-            : array(
3387
-                esc_html__('Save', 'event_espresso'),
3388
-                esc_html__('Save and Close', 'event_espresso'),
3389
-            );
3390
-        $default_names = array('save', 'save_and_close');
3391
-        //add in a hidden index for the current page (so save and close redirects properly)
3392
-        $this->_template_args['save_buttons'] = $referrer_url;
3393
-        foreach ($button_text as $key => $button) {
3394
-            $ref                                  = $default_names[$key];
3395
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3396
-                                                     . $ref
3397
-                                                     . '" value="'
3398
-                                                     . $button
3399
-                                                     . '" name="'
3400
-                                                     . (! empty($actions) ? $actions[$key] : $ref)
3401
-                                                     . '" id="'
3402
-                                                     . $this->_current_view . '_' . $ref
3403
-                                                     . '" />';
3404
-            if (! $both) {
3405
-                break;
3406
-            }
3407
-        }
3408
-    }
3409
-
3410
-
3411
-
3412
-    /**
3413
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3414
-     *
3415
-     * @see   $this->_set_add_edit_form_tags() for details on params
3416
-     * @since 4.6.0
3417
-     * @param string $route
3418
-     * @param array  $additional_hidden_fields
3419
-     */
3420
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3421
-    {
3422
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3423
-    }
3424
-
3425
-
3426
-
3427
-    /**
3428
-     * set form open and close tags on add/edit pages.
3429
-     *
3430
-     * @param string $route                    the route you want the form to direct to
3431
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3432
-     * @return void
3433
-     */
3434
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3435
-    {
3436
-        if (empty($route)) {
3437
-            $user_msg = esc_html__(
3438
-                'An error occurred. No action was set for this page\'s form.',
3439
-                'event_espresso'
3440
-            );
3441
-            $dev_msg  = $user_msg . "\n" . sprintf(
3442
-                    esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3443
-                    __FUNCTION__,
3444
-                    __CLASS__
3445
-                );
3446
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3447
-        }
3448
-        // open form
3449
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3450
-                                                             . $this->_admin_base_url
3451
-                                                             . '" id="'
3452
-                                                             . $route
3453
-                                                             . '_event_form" >';
3454
-        // add nonce
3455
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3456
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
3457
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3458
-        // add REQUIRED form action
3459
-        $hidden_fields = array(
3460
-            'action' => array('type' => 'hidden', 'value' => $route),
3461
-        );
3462
-        // merge arrays
3463
-        $hidden_fields = is_array($additional_hidden_fields)
3464
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3465
-            : $hidden_fields;
3466
-        // generate form fields
3467
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3468
-        // add fields to form
3469
-        foreach ((array)$form_fields as $field_name => $form_field) {
3470
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3471
-        }
3472
-        // close form
3473
-        $this->_template_args['after_admin_page_content'] = '</form>';
3474
-    }
3475
-
3476
-
3477
-
3478
-    /**
3479
-     * Public Wrapper for _redirect_after_action() method since its
3480
-     * discovered it would be useful for external code to have access.
3481
-     *
3482
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3483
-     * @since 4.5.0
3484
-     * @param bool   $success
3485
-     * @param string $what
3486
-     * @param string $action_desc
3487
-     * @param array  $query_args
3488
-     * @param bool   $override_overwrite
3489
-     * @throws EE_Error
3490
-     */
3491
-    public function redirect_after_action(
3492
-        $success = false,
3493
-        $what = 'item',
3494
-        $action_desc = 'processed',
3495
-        $query_args = array(),
3496
-        $override_overwrite = false
3497
-    ) {
3498
-        $this->_redirect_after_action(
3499
-            $success,
3500
-            $what,
3501
-            $action_desc,
3502
-            $query_args,
3503
-            $override_overwrite
3504
-        );
3505
-    }
3506
-
3507
-
3508
-
3509
-    /**
3510
-     *    _redirect_after_action
3511
-     *
3512
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3513
-     * @param string $what               - what the action was performed on
3514
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3515
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3516
-     *                                   action is completed
3517
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3518
-     *                                   override this so that they show.
3519
-     * @return void
3520
-     * @throws EE_Error
3521
-     */
3522
-    protected function _redirect_after_action(
3523
-        $success = 0,
3524
-        $what = 'item',
3525
-        $action_desc = 'processed',
3526
-        $query_args = array(),
3527
-        $override_overwrite = false
3528
-    ) {
3529
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3530
-        //class name for actions/filters.
3531
-        $classname = get_class($this);
3532
-        // set redirect url.
3533
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3534
-        // otherwise we go with whatever is set as the _admin_base_url
3535
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3536
-        $notices      = EE_Error::get_notices(false);
3537
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3538
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3539
-            EE_Error::overwrite_success();
3540
-        }
3541
-        if (! empty($what) && ! empty($action_desc)  && empty($notices['errors'])) {
3542
-            // how many records affected ? more than one record ? or just one ?
3543
-            if ($success > 1) {
3544
-                // set plural msg
3545
-                EE_Error::add_success(
3546
-                    sprintf(
3547
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3548
-                        $what,
3549
-                        $action_desc
3550
-                    ),
3551
-                    __FILE__,
3552
-                    __FUNCTION__,
3553
-                    __LINE__
3554
-                );
3555
-            } elseif ($success === 1) {
3556
-                // set singular msg
3557
-                EE_Error::add_success(
3558
-                    sprintf(
3559
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3560
-                        $what,
3561
-                        $action_desc
3562
-                    ),
3563
-                    __FILE__,
3564
-                    __FUNCTION__,
3565
-                    __LINE__
3566
-                );
3567
-            }
3568
-        }
3569
-        // check that $query_args isn't something crazy
3570
-        if (! is_array($query_args)) {
3571
-            $query_args = array();
3572
-        }
3573
-        /**
3574
-         * Allow injecting actions before the query_args are modified for possible different
3575
-         * redirections on save and close actions
3576
-         *
3577
-         * @since 4.2.0
3578
-         * @param array $query_args       The original query_args array coming into the
3579
-         *                                method.
3580
-         */
3581
-        do_action(
3582
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3583
-            $query_args
3584
-        );
3585
-        //calculate where we're going (if we have a "save and close" button pushed)
3586
-        if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3587
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3588
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3589
-            // regenerate query args array from referrer URL
3590
-            parse_str($parsed_url['query'], $query_args);
3591
-            // correct page and action will be in the query args now
3592
-            $redirect_url = admin_url('admin.php');
3593
-        }
3594
-        //merge any default query_args set in _default_route_query_args property
3595
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3596
-            $args_to_merge = array();
3597
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3598
-                //is there a wp_referer array in our _default_route_query_args property?
3599
-                if ($query_param === 'wp_referer') {
3600
-                    $query_value = (array)$query_value;
3601
-                    foreach ($query_value as $reference => $value) {
3602
-                        if (strpos($reference, 'nonce') !== false) {
3603
-                            continue;
3604
-                        }
3605
-                        //finally we will override any arguments in the referer with
3606
-                        //what might be set on the _default_route_query_args array.
3607
-                        if (isset($this->_default_route_query_args[$reference])) {
3608
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3609
-                        } else {
3610
-                            $args_to_merge[$reference] = urlencode($value);
3611
-                        }
3612
-                    }
3613
-                    continue;
3614
-                }
3615
-                $args_to_merge[$query_param] = $query_value;
3616
-            }
3617
-            //now let's merge these arguments but override with what was specifically sent in to the
3618
-            //redirect.
3619
-            $query_args = array_merge($args_to_merge, $query_args);
3620
-        }
3621
-        $this->_process_notices($query_args);
3622
-        // generate redirect url
3623
-        // if redirecting to anything other than the main page, add a nonce
3624
-        if (isset($query_args['action'])) {
3625
-            // manually generate wp_nonce and merge that with the query vars
3626
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3627
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3628
-        }
3629
-        // we're adding some hooks and filters in here for processing any things just before redirects
3630
-        // (example: an admin page has done an insert or update and we want to run something after that).
3631
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3632
-        $redirect_url = apply_filters(
3633
-            'FHEE_redirect_' . $classname . $this->_req_action,
3634
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3635
-            $query_args
3636
-        );
3637
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3638
-        if (defined('DOING_AJAX')) {
3639
-            $default_data                    = array(
3640
-                'close'        => true,
3641
-                'redirect_url' => $redirect_url,
3642
-                'where'        => 'main',
3643
-                'what'         => 'append',
3644
-            );
3645
-            $this->_template_args['success'] = $success;
3646
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3647
-                $default_data,
3648
-                $this->_template_args['data']
3649
-            ) : $default_data;
3650
-            $this->_return_json();
3651
-        }
3652
-        wp_safe_redirect($redirect_url);
3653
-        exit();
3654
-    }
3655
-
3656
-
3657
-
3658
-    /**
3659
-     * process any notices before redirecting (or returning ajax request)
3660
-     * This method sets the $this->_template_args['notices'] attribute;
3661
-     *
3662
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
3663
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and
3664
-     *                                  page_routes haven't been defined yet.
3665
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we
3666
-     *                                  still save a transient for the notice.
3667
-     * @return void
3668
-     * @throws EE_Error
3669
-     */
3670
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3671
-    {
3672
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
3673
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3674
-            $notices = EE_Error::get_notices(false);
3675
-            if (empty($this->_template_args['success'])) {
3676
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3677
-            }
3678
-            if (empty($this->_template_args['errors'])) {
3679
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3680
-            }
3681
-            if (empty($this->_template_args['attention'])) {
3682
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3683
-            }
3684
-        }
3685
-        $this->_template_args['notices'] = EE_Error::get_notices();
3686
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3687
-        if (! defined('DOING_AJAX') || $sticky_notices) {
3688
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3689
-            $this->_add_transient(
3690
-                $route,
3691
-                $this->_template_args['notices'],
3692
-                true,
3693
-                $skip_route_verify
3694
-            );
3695
-        }
3696
-    }
3697
-
3698
-
3699
-
3700
-    /**
3701
-     * get_action_link_or_button
3702
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3703
-     *
3704
-     * @param string $action        use this to indicate which action the url is generated with.
3705
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3706
-     *                              property.
3707
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3708
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3709
-     * @param string $base_url      If this is not provided
3710
-     *                              the _admin_base_url will be used as the default for the button base_url.
3711
-     *                              Otherwise this value will be used.
3712
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3713
-     * @return string
3714
-     * @throws InvalidArgumentException
3715
-     * @throws InvalidInterfaceException
3716
-     * @throws InvalidDataTypeException
3717
-     * @throws EE_Error
3718
-     */
3719
-    public function get_action_link_or_button(
3720
-        $action,
3721
-        $type = 'add',
3722
-        $extra_request = array(),
3723
-        $class = 'button-primary',
3724
-        $base_url = '',
3725
-        $exclude_nonce = false
3726
-    ) {
3727
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3728
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3729
-            throw new EE_Error(
3730
-                sprintf(
3731
-                    esc_html__(
3732
-                        'There is no page route for given action for the button.  This action was given: %s',
3733
-                        'event_espresso'
3734
-                    ),
3735
-                    $action
3736
-                )
3737
-            );
3738
-        }
3739
-        if (! isset($this->_labels['buttons'][$type])) {
3740
-            throw new EE_Error(
3741
-                sprintf(
3742
-                    __(
3743
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3744
-                        'event_espresso'
3745
-                    ),
3746
-                    $type
3747
-                )
3748
-            );
3749
-        }
3750
-        //finally check user access for this button.
3751
-        $has_access = $this->check_user_access($action, true);
3752
-        if (! $has_access) {
3753
-            return '';
3754
-        }
3755
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3756
-        $query_args = array(
3757
-            'action' => $action,
3758
-        );
3759
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3760
-        if (! empty($extra_request)) {
3761
-            $query_args = array_merge($extra_request, $query_args);
3762
-        }
3763
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3764
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3765
-    }
3766
-
3767
-
3768
-
3769
-    /**
3770
-     * _per_page_screen_option
3771
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3772
-     *
3773
-     * @return void
3774
-     * @throws InvalidArgumentException
3775
-     * @throws InvalidInterfaceException
3776
-     * @throws InvalidDataTypeException
3777
-     */
3778
-    protected function _per_page_screen_option()
3779
-    {
3780
-        $option = 'per_page';
3781
-        $args   = array(
3782
-            'label'   => esc_html__(
3783
-                    apply_filters(
3784
-                        'FHEE__EE_Admin_Page___per_page_screen_options___label',
3785
-                        $this->_admin_page_title,
3786
-                        $this
3787
-                    )
3788
-            ),
3789
-            'default' => (int) apply_filters(
3790
-                    'FHEE__EE_Admin_Page___per_page_screen_options__default',
3791
-                    10
3792
-            ),
3793
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3794
-        );
3795
-        //ONLY add the screen option if the user has access to it.
3796
-        if ($this->check_user_access($this->_current_view, true)) {
3797
-            add_screen_option($option, $args);
3798
-        }
3799
-    }
3800
-
3801
-
3802
-
3803
-    /**
3804
-     * set_per_page_screen_option
3805
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3806
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3807
-     * admin_menu.
3808
-     *
3809
-     * @return void
3810
-     */
3811
-    private function _set_per_page_screen_options()
3812
-    {
3813
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3814
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3815
-            if (! $user = wp_get_current_user()) {
3816
-                return;
3817
-            }
3818
-            $option = $_POST['wp_screen_options']['option'];
3819
-            $value  = $_POST['wp_screen_options']['value'];
3820
-            if ($option != sanitize_key($option)) {
3821
-                return;
3822
-            }
3823
-            $map_option = $option;
3824
-            $option     = str_replace('-', '_', $option);
3825
-            switch ($map_option) {
3826
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3827
-                    $value = (int)$value;
3828
-                    $max_value = apply_filters(
3829
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3830
-                        999,
3831
-                        $this->_current_page,
3832
-                        $this->_current_view
3833
-                    );
3834
-                    if ($value < 1) {
3835
-                        return;
3836
-                    }
3837
-                    $value = min($value, $max_value);
3838
-                    break;
3839
-                default:
3840
-                    $value = apply_filters(
3841
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3842
-                        false,
3843
-                        $option,
3844
-                        $value
3845
-                    );
3846
-                    if (false === $value) {
3847
-                        return;
3848
-                    }
3849
-                    break;
3850
-            }
3851
-            update_user_meta($user->ID, $option, $value);
3852
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3853
-            exit;
3854
-        }
3855
-    }
3856
-
3857
-
3858
-
3859
-    /**
3860
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3861
-     *
3862
-     * @param array $data array that will be assigned to template args.
3863
-     */
3864
-    public function set_template_args($data)
3865
-    {
3866
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3867
-    }
3868
-
3869
-
3870
-
3871
-    /**
3872
-     * This makes available the WP transient system for temporarily moving data between routes
3873
-     *
3874
-     * @param string $route             the route that should receive the transient
3875
-     * @param array  $data              the data that gets sent
3876
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3877
-     *                                  normal route transient.
3878
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3879
-     *                                  when we are adding a transient before page_routes have been defined.
3880
-     * @return void
3881
-     * @throws EE_Error
3882
-     */
3883
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3884
-    {
3885
-        $user_id = get_current_user_id();
3886
-        if (! $skip_route_verify) {
3887
-            $this->_verify_route($route);
3888
-        }
3889
-        //now let's set the string for what kind of transient we're setting
3890
-        $transient = $notices
3891
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3892
-            : 'rte_tx_' . $route . '_' . $user_id;
3893
-        $data      = $notices ? array('notices' => $data) : $data;
3894
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3895
-        $existing = is_multisite() && is_network_admin()
3896
-            ? get_site_transient($transient)
3897
-            : get_transient($transient);
3898
-        if ($existing) {
3899
-            $data = array_merge((array)$data, (array)$existing);
3900
-        }
3901
-        if (is_multisite() && is_network_admin()) {
3902
-            set_site_transient($transient, $data, 8);
3903
-        } else {
3904
-            set_transient($transient, $data, 8);
3905
-        }
3906
-    }
3907
-
3908
-
3909
-
3910
-    /**
3911
-     * this retrieves the temporary transient that has been set for moving data between routes.
3912
-     *
3913
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3914
-     * @param string $route
3915
-     * @return mixed data
3916
-     */
3917
-    protected function _get_transient($notices = false, $route = '')
3918
-    {
3919
-        $user_id   = get_current_user_id();
3920
-        $route     = ! $route ? $this->_req_action : $route;
3921
-        $transient = $notices
3922
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3923
-            : 'rte_tx_' . $route . '_' . $user_id;
3924
-        $data      = is_multisite() && is_network_admin()
3925
-            ? get_site_transient($transient)
3926
-            : get_transient($transient);
3927
-        //delete transient after retrieval (just in case it hasn't expired);
3928
-        if (is_multisite() && is_network_admin()) {
3929
-            delete_site_transient($transient);
3930
-        } else {
3931
-            delete_transient($transient);
3932
-        }
3933
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3934
-    }
3935
-
3936
-
3937
-
3938
-    /**
3939
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3940
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3941
-     * default route callback on the EE_Admin page you want it run.)
3942
-     *
3943
-     * @return void
3944
-     */
3945
-    protected function _transient_garbage_collection()
3946
-    {
3947
-        global $wpdb;
3948
-        //retrieve all existing transients
3949
-        $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3950
-        if ($results = $wpdb->get_results($query)) {
3951
-            foreach ($results as $result) {
3952
-                $transient = str_replace('_transient_', '', $result->option_name);
3953
-                get_transient($transient);
3954
-                if (is_multisite() && is_network_admin()) {
3955
-                    get_site_transient($transient);
3956
-                }
3957
-            }
3958
-        }
3959
-    }
3960
-
3961
-
3962
-
3963
-    /**
3964
-     * get_view
3965
-     *
3966
-     * @return string content of _view property
3967
-     */
3968
-    public function get_view()
3969
-    {
3970
-        return $this->_view;
3971
-    }
3972
-
3973
-
3974
-
3975
-    /**
3976
-     * getter for the protected $_views property
3977
-     *
3978
-     * @return array
3979
-     */
3980
-    public function get_views()
3981
-    {
3982
-        return $this->_views;
3983
-    }
3984
-
3985
-
3986
-
3987
-    /**
3988
-     * get_current_page
3989
-     *
3990
-     * @return string _current_page property value
3991
-     */
3992
-    public function get_current_page()
3993
-    {
3994
-        return $this->_current_page;
3995
-    }
3996
-
3997
-
3998
-
3999
-    /**
4000
-     * get_current_view
4001
-     *
4002
-     * @return string _current_view property value
4003
-     */
4004
-    public function get_current_view()
4005
-    {
4006
-        return $this->_current_view;
4007
-    }
4008
-
4009
-
4010
-
4011
-    /**
4012
-     * get_current_screen
4013
-     *
4014
-     * @return object The current WP_Screen object
4015
-     */
4016
-    public function get_current_screen()
4017
-    {
4018
-        return $this->_current_screen;
4019
-    }
4020
-
4021
-
4022
-
4023
-    /**
4024
-     * get_current_page_view_url
4025
-     *
4026
-     * @return string This returns the url for the current_page_view.
4027
-     */
4028
-    public function get_current_page_view_url()
4029
-    {
4030
-        return $this->_current_page_view_url;
4031
-    }
4032
-
4033
-
4034
-
4035
-    /**
4036
-     * just returns the _req_data property
4037
-     *
4038
-     * @return array
4039
-     */
4040
-    public function get_request_data()
4041
-    {
4042
-        return $this->_req_data;
4043
-    }
4044
-
4045
-
4046
-
4047
-    /**
4048
-     * returns the _req_data protected property
4049
-     *
4050
-     * @return string
4051
-     */
4052
-    public function get_req_action()
4053
-    {
4054
-        return $this->_req_action;
4055
-    }
4056
-
4057
-
4058
-
4059
-    /**
4060
-     * @return bool  value of $_is_caf property
4061
-     */
4062
-    public function is_caf()
4063
-    {
4064
-        return $this->_is_caf;
4065
-    }
4066
-
4067
-
4068
-
4069
-    /**
4070
-     * @return mixed
4071
-     */
4072
-    public function default_espresso_metaboxes()
4073
-    {
4074
-        return $this->_default_espresso_metaboxes;
4075
-    }
4076
-
4077
-
4078
-
4079
-    /**
4080
-     * @return mixed
4081
-     */
4082
-    public function admin_base_url()
4083
-    {
4084
-        return $this->_admin_base_url;
4085
-    }
2775
+	}
2776
+
2777
+
2778
+
2779
+	/**
2780
+	 * facade for add_meta_box
2781
+	 *
2782
+	 * @param string  $action        where the metabox get's displayed
2783
+	 * @param string  $title         Title of Metabox (output in metabox header)
2784
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2785
+	 *                               instead of the one created in here.
2786
+	 * @param array   $callback_args an array of args supplied for the metabox
2787
+	 * @param string  $column        what metabox column
2788
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2789
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2790
+	 *                               created but just set our own callback for wp's add_meta_box.
2791
+	 * @throws \DomainException
2792
+	 */
2793
+	public function _add_admin_page_meta_box(
2794
+		$action,
2795
+		$title,
2796
+		$callback,
2797
+		$callback_args,
2798
+		$column = 'normal',
2799
+		$priority = 'high',
2800
+		$create_func = true
2801
+	) {
2802
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2803
+		//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.
2804
+		if (empty($callback_args) && $create_func) {
2805
+			$callback_args = array(
2806
+				'template_path' => $this->_template_path,
2807
+				'template_args' => $this->_template_args,
2808
+			);
2809
+		}
2810
+		//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)
2811
+		$call_back_func = $create_func
2812
+			? function ($post, $metabox)
2813
+			{
2814
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2815
+				echo EEH_Template::display_template(
2816
+					$metabox['args']['template_path'],
2817
+					$metabox['args']['template_args'],
2818
+					true
2819
+				);
2820
+			}
2821
+			: $callback;
2822
+		add_meta_box(
2823
+			str_replace('_', '-', $action) . '-mbox',
2824
+			$title,
2825
+			$call_back_func,
2826
+			$this->_wp_page_slug,
2827
+			$column,
2828
+			$priority,
2829
+			$callback_args
2830
+		);
2831
+	}
2832
+
2833
+
2834
+
2835
+	/**
2836
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2837
+	 *
2838
+	 * @throws DomainException
2839
+	 * @throws EE_Error
2840
+	 */
2841
+	public function display_admin_page_with_metabox_columns()
2842
+	{
2843
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2844
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2845
+			$this->_column_template_path,
2846
+			$this->_template_args,
2847
+			true
2848
+		);
2849
+		//the final wrapper
2850
+		$this->admin_page_wrapper();
2851
+	}
2852
+
2853
+
2854
+
2855
+	/**
2856
+	 * generates  HTML wrapper for an admin details page
2857
+	 *
2858
+	 * @return void
2859
+	 * @throws EE_Error
2860
+	 * @throws DomainException
2861
+	 */
2862
+	public function display_admin_page_with_sidebar()
2863
+	{
2864
+		$this->_display_admin_page(true);
2865
+	}
2866
+
2867
+
2868
+
2869
+	/**
2870
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2871
+	 *
2872
+	 * @return void
2873
+	 * @throws EE_Error
2874
+	 * @throws DomainException
2875
+	 */
2876
+	public function display_admin_page_with_no_sidebar()
2877
+	{
2878
+		$this->_display_admin_page();
2879
+	}
2880
+
2881
+
2882
+
2883
+	/**
2884
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2885
+	 *
2886
+	 * @return void
2887
+	 * @throws EE_Error
2888
+	 * @throws DomainException
2889
+	 */
2890
+	public function display_about_admin_page()
2891
+	{
2892
+		$this->_display_admin_page(false, true);
2893
+	}
2894
+
2895
+
2896
+
2897
+	/**
2898
+	 * display_admin_page
2899
+	 * contains the code for actually displaying an admin page
2900
+	 *
2901
+	 * @param  boolean $sidebar true with sidebar, false without
2902
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2903
+	 * @return void
2904
+	 * @throws DomainException
2905
+	 * @throws EE_Error
2906
+	 */
2907
+	private function _display_admin_page($sidebar = false, $about = false)
2908
+	{
2909
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2910
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2911
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2912
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2913
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2914
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2915
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2916
+			? 'poststuff'
2917
+			: 'espresso-default-admin';
2918
+		$template_path                                     = $sidebar
2919
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2920
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2921
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2922
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2923
+		}
2924
+		$template_path                                     = ! empty($this->_column_template_path)
2925
+			? $this->_column_template_path : $template_path;
2926
+		$this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2927
+			? $this->_template_args['admin_page_content']
2928
+			: '';
2929
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2930
+			? $this->_template_args['before_admin_page_content']
2931
+			: '';
2932
+		$this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2933
+			? $this->_template_args['after_admin_page_content']
2934
+			: '';
2935
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2936
+			$template_path,
2937
+			$this->_template_args,
2938
+			true
2939
+		);
2940
+		// the final template wrapper
2941
+		$this->admin_page_wrapper($about);
2942
+	}
2943
+
2944
+
2945
+
2946
+	/**
2947
+	 * This is used to display caf preview pages.
2948
+	 *
2949
+	 * @since 4.3.2
2950
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2951
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2952
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2953
+	 * @return void
2954
+	 * @throws DomainException
2955
+	 * @throws EE_Error
2956
+	 * @throws InvalidArgumentException
2957
+	 * @throws InvalidDataTypeException
2958
+	 * @throws InvalidInterfaceException
2959
+	 */
2960
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2961
+	{
2962
+		//let's generate a default preview action button if there isn't one already present.
2963
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2964
+			'Upgrade to Event Espresso 4 Right Now',
2965
+			'event_espresso'
2966
+		);
2967
+		$buy_now_url                                   = add_query_arg(
2968
+			array(
2969
+				'ee_ver'       => 'ee4',
2970
+				'utm_source'   => 'ee4_plugin_admin',
2971
+				'utm_medium'   => 'link',
2972
+				'utm_campaign' => $utm_campaign_source,
2973
+				'utm_content'  => 'buy_now_button',
2974
+			),
2975
+			'http://eventespresso.com/pricing/'
2976
+		);
2977
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2978
+			? $this->get_action_link_or_button(
2979
+				'',
2980
+				'buy_now',
2981
+				array(),
2982
+				'button-primary button-large',
2983
+				$buy_now_url,
2984
+				true
2985
+			)
2986
+			: $this->_template_args['preview_action_button'];
2987
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2988
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2989
+			$this->_template_args,
2990
+			true
2991
+		);
2992
+		$this->_display_admin_page($display_sidebar);
2993
+	}
2994
+
2995
+
2996
+
2997
+	/**
2998
+	 * display_admin_list_table_page_with_sidebar
2999
+	 * generates HTML wrapper for an admin_page with list_table
3000
+	 *
3001
+	 * @return void
3002
+	 * @throws EE_Error
3003
+	 * @throws DomainException
3004
+	 */
3005
+	public function display_admin_list_table_page_with_sidebar()
3006
+	{
3007
+		$this->_display_admin_list_table_page(true);
3008
+	}
3009
+
3010
+
3011
+
3012
+	/**
3013
+	 * display_admin_list_table_page_with_no_sidebar
3014
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
3015
+	 *
3016
+	 * @return void
3017
+	 * @throws EE_Error
3018
+	 * @throws DomainException
3019
+	 */
3020
+	public function display_admin_list_table_page_with_no_sidebar()
3021
+	{
3022
+		$this->_display_admin_list_table_page();
3023
+	}
3024
+
3025
+
3026
+
3027
+	/**
3028
+	 * generates html wrapper for an admin_list_table page
3029
+	 *
3030
+	 * @param boolean $sidebar whether to display with sidebar or not.
3031
+	 * @return void
3032
+	 * @throws DomainException
3033
+	 * @throws EE_Error
3034
+	 */
3035
+	private function _display_admin_list_table_page($sidebar = false)
3036
+	{
3037
+		//setup search attributes
3038
+		$this->_set_search_attributes();
3039
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
3040
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3041
+		$this->_template_args['table_url']        = defined('DOING_AJAX')
3042
+			? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
3043
+			: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
3044
+		$this->_template_args['list_table']       = $this->_list_table_object;
3045
+		$this->_template_args['current_route']    = $this->_req_action;
3046
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3047
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
3048
+		if (! empty($ajax_sorting_callback)) {
3049
+			$sortable_list_table_form_fields = wp_nonce_field(
3050
+				$ajax_sorting_callback . '_nonce',
3051
+				$ajax_sorting_callback . '_nonce',
3052
+				false,
3053
+				false
3054
+			);
3055
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
3056
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
3057
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3058
+												. $this->page_slug
3059
+												. '" />';
3060
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3061
+												. $ajax_sorting_callback
3062
+												. '" />';
3063
+		} else {
3064
+			$sortable_list_table_form_fields = '';
3065
+		}
3066
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3067
+		$hidden_form_fields                                      = isset($this->_template_args['list_table_hidden_fields'])
3068
+			? $this->_template_args['list_table_hidden_fields']
3069
+			: '';
3070
+		$nonce_ref                                               = $this->_req_action . '_nonce';
3071
+		$hidden_form_fields                                      .= '<input type="hidden" name="'
3072
+																	. $nonce_ref
3073
+																	. '" value="'
3074
+																	. wp_create_nonce($nonce_ref)
3075
+																	. '">';
3076
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
3077
+		//display message about search results?
3078
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3079
+			? '<p class="ee-search-results">' . sprintf(
3080
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3081
+				trim($this->_req_data['s'], '%')
3082
+			) . '</p>'
3083
+			: '';
3084
+		// filter before_list_table template arg
3085
+		$this->_template_args['before_list_table'] = apply_filters(
3086
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3087
+			$this->_template_args['before_list_table'],
3088
+			$this->page_slug,
3089
+			$this->_req_data,
3090
+			$this->_req_action
3091
+		);
3092
+		// convert to array and filter again
3093
+		// arrays are easier to inject new items in a specific location,
3094
+		// but would not be backwards compatible, so we have to add a new filter
3095
+		$this->_template_args['before_list_table'] = implode(
3096
+			" \n",
3097
+			(array)apply_filters(
3098
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3099
+				(array)$this->_template_args['before_list_table'],
3100
+				$this->page_slug,
3101
+				$this->_req_data,
3102
+				$this->_req_action
3103
+			)
3104
+		);
3105
+		// filter after_list_table template arg
3106
+		$this->_template_args['after_list_table'] = apply_filters(
3107
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3108
+			$this->_template_args['after_list_table'],
3109
+			$this->page_slug,
3110
+			$this->_req_data,
3111
+			$this->_req_action
3112
+		);
3113
+		// convert to array and filter again
3114
+		// arrays are easier to inject new items in a specific location,
3115
+		// but would not be backwards compatible, so we have to add a new filter
3116
+		$this->_template_args['after_list_table']   = implode(
3117
+			" \n",
3118
+			(array)apply_filters(
3119
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3120
+				(array)$this->_template_args['after_list_table'],
3121
+				$this->page_slug,
3122
+				$this->_req_data,
3123
+				$this->_req_action
3124
+			)
3125
+		);
3126
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3127
+			$template_path,
3128
+			$this->_template_args,
3129
+			true
3130
+		);
3131
+		// the final template wrapper
3132
+		if ($sidebar) {
3133
+			$this->display_admin_page_with_sidebar();
3134
+		} else {
3135
+			$this->display_admin_page_with_no_sidebar();
3136
+		}
3137
+	}
3138
+
3139
+
3140
+
3141
+	/**
3142
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3143
+	 * html string for the legend.
3144
+	 * $items are expected in an array in the following format:
3145
+	 * $legend_items = array(
3146
+	 *        'item_id' => array(
3147
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3148
+	 *            'desc' => esc_html__('localized description of item');
3149
+	 *        )
3150
+	 * );
3151
+	 *
3152
+	 * @param  array $items see above for format of array
3153
+	 * @return string html string of legend
3154
+	 * @throws DomainException
3155
+	 */
3156
+	protected function _display_legend($items)
3157
+	{
3158
+		$this->_template_args['items'] = apply_filters(
3159
+			'FHEE__EE_Admin_Page___display_legend__items',
3160
+			(array)$items,
3161
+			$this
3162
+		);
3163
+		return EEH_Template::display_template(
3164
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3165
+			$this->_template_args,
3166
+			true
3167
+		);
3168
+	}
3169
+
3170
+
3171
+	/**
3172
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3173
+	 * The returned json object is created from an array in the following format:
3174
+	 * array(
3175
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3176
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3177
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3178
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3179
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3180
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3181
+	 *  that might be included in here)
3182
+	 * )
3183
+	 * The json object is populated by whatever is set in the $_template_args property.
3184
+	 *
3185
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3186
+	 *                                 instead of displayed.
3187
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3188
+	 * @return void
3189
+	 * @throws EE_Error
3190
+	 */
3191
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
3192
+	{
3193
+		//make sure any EE_Error notices have been handled.
3194
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3195
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3196
+		unset($this->_template_args['data']);
3197
+		$json = array(
3198
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3199
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3200
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3201
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3202
+			'notices'   => EE_Error::get_notices(),
3203
+			'content'   => isset($this->_template_args['admin_page_content'])
3204
+				? $this->_template_args['admin_page_content'] : '',
3205
+			'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3206
+			'isEEajax'  => true
3207
+			//special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3208
+		);
3209
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3210
+		if (null === error_get_last() || ! headers_sent()) {
3211
+			header('Content-Type: application/json; charset=UTF-8');
3212
+		}
3213
+		echo wp_json_encode($json);
3214
+		exit();
3215
+	}
3216
+
3217
+
3218
+
3219
+	/**
3220
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3221
+	 *
3222
+	 * @return void
3223
+	 * @throws EE_Error
3224
+	 */
3225
+	public function return_json()
3226
+	{
3227
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3228
+			$this->_return_json();
3229
+		} else {
3230
+			throw new EE_Error(
3231
+				sprintf(
3232
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3233
+					__FUNCTION__
3234
+				)
3235
+			);
3236
+		}
3237
+	}
3238
+
3239
+
3240
+
3241
+	/**
3242
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3243
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3244
+	 *
3245
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3246
+	 */
3247
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3248
+	{
3249
+		$this->_hook_obj = $hook_obj;
3250
+	}
3251
+
3252
+
3253
+
3254
+	/**
3255
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3256
+	 *
3257
+	 * @param  boolean $about whether to use the special about page wrapper or default.
3258
+	 * @return void
3259
+	 * @throws DomainException
3260
+	 * @throws EE_Error
3261
+	 */
3262
+	public function admin_page_wrapper($about = false)
3263
+	{
3264
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3265
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3266
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3267
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3268
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3269
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3270
+			isset($this->_template_args['before_admin_page_content'])
3271
+				? $this->_template_args['before_admin_page_content']
3272
+				: ''
3273
+		);
3274
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3275
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3276
+			isset($this->_template_args['after_admin_page_content'])
3277
+				? $this->_template_args['after_admin_page_content']
3278
+				: ''
3279
+		);
3280
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3281
+		// load settings page wrapper template
3282
+		$template_path = ! defined('DOING_AJAX')
3283
+			? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3284
+			: EE_ADMIN_TEMPLATE
3285
+			  . 'admin_wrapper_ajax.template.php';
3286
+		//about page?
3287
+		$template_path = $about
3288
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3289
+			: $template_path;
3290
+		if (defined('DOING_AJAX')) {
3291
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3292
+				$template_path,
3293
+				$this->_template_args,
3294
+				true
3295
+			);
3296
+			$this->_return_json();
3297
+		} else {
3298
+			EEH_Template::display_template($template_path, $this->_template_args);
3299
+		}
3300
+	}
3301
+
3302
+
3303
+
3304
+	/**
3305
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3306
+	 *
3307
+	 * @return string html
3308
+	 * @throws EE_Error
3309
+	 */
3310
+	protected function _get_main_nav_tabs()
3311
+	{
3312
+		// let's generate the html using the EEH_Tabbed_Content helper.
3313
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3314
+		// (rather than setting in the page_routes array)
3315
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3316
+	}
3317
+
3318
+
3319
+
3320
+	/**
3321
+	 *        sort nav tabs
3322
+	 *
3323
+	 * @param $a
3324
+	 * @param $b
3325
+	 * @return int
3326
+	 */
3327
+	private function _sort_nav_tabs($a, $b)
3328
+	{
3329
+		if ($a['order'] === $b['order']) {
3330
+			return 0;
3331
+		}
3332
+		return ($a['order'] < $b['order']) ? -1 : 1;
3333
+	}
3334
+
3335
+
3336
+
3337
+	/**
3338
+	 *    generates HTML for the forms used on admin pages
3339
+	 *
3340
+	 * @param    array $input_vars - array of input field details
3341
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3342
+	 *                             use)
3343
+	 * @param bool     $id
3344
+	 * @return string
3345
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3346
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3347
+	 */
3348
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3349
+	{
3350
+		$content = $generator === 'string'
3351
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3352
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3353
+		return $content;
3354
+	}
3355
+
3356
+
3357
+
3358
+	/**
3359
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3360
+	 *
3361
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3362
+	 *                                   Close" button.
3363
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3364
+	 *                                   'Save', [1] => 'save & close')
3365
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3366
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3367
+	 *                                   default actions by submitting some other value.
3368
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3369
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3370
+	 *                                   close (normal form handling).
3371
+	 */
3372
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3373
+	{
3374
+		//make sure $text and $actions are in an array
3375
+		$text          = (array)$text;
3376
+		$actions       = (array)$actions;
3377
+		$referrer_url  = empty($referrer)
3378
+			? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3379
+			  . $_SERVER['REQUEST_URI']
3380
+			  . '" />'
3381
+			: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3382
+			  . $referrer
3383
+			  . '" />';
3384
+		$button_text   = ! empty($text)
3385
+			? $text
3386
+			: array(
3387
+				esc_html__('Save', 'event_espresso'),
3388
+				esc_html__('Save and Close', 'event_espresso'),
3389
+			);
3390
+		$default_names = array('save', 'save_and_close');
3391
+		//add in a hidden index for the current page (so save and close redirects properly)
3392
+		$this->_template_args['save_buttons'] = $referrer_url;
3393
+		foreach ($button_text as $key => $button) {
3394
+			$ref                                  = $default_names[$key];
3395
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3396
+													 . $ref
3397
+													 . '" value="'
3398
+													 . $button
3399
+													 . '" name="'
3400
+													 . (! empty($actions) ? $actions[$key] : $ref)
3401
+													 . '" id="'
3402
+													 . $this->_current_view . '_' . $ref
3403
+													 . '" />';
3404
+			if (! $both) {
3405
+				break;
3406
+			}
3407
+		}
3408
+	}
3409
+
3410
+
3411
+
3412
+	/**
3413
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3414
+	 *
3415
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3416
+	 * @since 4.6.0
3417
+	 * @param string $route
3418
+	 * @param array  $additional_hidden_fields
3419
+	 */
3420
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3421
+	{
3422
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3423
+	}
3424
+
3425
+
3426
+
3427
+	/**
3428
+	 * set form open and close tags on add/edit pages.
3429
+	 *
3430
+	 * @param string $route                    the route you want the form to direct to
3431
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3432
+	 * @return void
3433
+	 */
3434
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3435
+	{
3436
+		if (empty($route)) {
3437
+			$user_msg = esc_html__(
3438
+				'An error occurred. No action was set for this page\'s form.',
3439
+				'event_espresso'
3440
+			);
3441
+			$dev_msg  = $user_msg . "\n" . sprintf(
3442
+					esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3443
+					__FUNCTION__,
3444
+					__CLASS__
3445
+				);
3446
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3447
+		}
3448
+		// open form
3449
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3450
+															 . $this->_admin_base_url
3451
+															 . '" id="'
3452
+															 . $route
3453
+															 . '_event_form" >';
3454
+		// add nonce
3455
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3456
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
3457
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3458
+		// add REQUIRED form action
3459
+		$hidden_fields = array(
3460
+			'action' => array('type' => 'hidden', 'value' => $route),
3461
+		);
3462
+		// merge arrays
3463
+		$hidden_fields = is_array($additional_hidden_fields)
3464
+			? array_merge($hidden_fields, $additional_hidden_fields)
3465
+			: $hidden_fields;
3466
+		// generate form fields
3467
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3468
+		// add fields to form
3469
+		foreach ((array)$form_fields as $field_name => $form_field) {
3470
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3471
+		}
3472
+		// close form
3473
+		$this->_template_args['after_admin_page_content'] = '</form>';
3474
+	}
3475
+
3476
+
3477
+
3478
+	/**
3479
+	 * Public Wrapper for _redirect_after_action() method since its
3480
+	 * discovered it would be useful for external code to have access.
3481
+	 *
3482
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3483
+	 * @since 4.5.0
3484
+	 * @param bool   $success
3485
+	 * @param string $what
3486
+	 * @param string $action_desc
3487
+	 * @param array  $query_args
3488
+	 * @param bool   $override_overwrite
3489
+	 * @throws EE_Error
3490
+	 */
3491
+	public function redirect_after_action(
3492
+		$success = false,
3493
+		$what = 'item',
3494
+		$action_desc = 'processed',
3495
+		$query_args = array(),
3496
+		$override_overwrite = false
3497
+	) {
3498
+		$this->_redirect_after_action(
3499
+			$success,
3500
+			$what,
3501
+			$action_desc,
3502
+			$query_args,
3503
+			$override_overwrite
3504
+		);
3505
+	}
3506
+
3507
+
3508
+
3509
+	/**
3510
+	 *    _redirect_after_action
3511
+	 *
3512
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3513
+	 * @param string $what               - what the action was performed on
3514
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3515
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3516
+	 *                                   action is completed
3517
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3518
+	 *                                   override this so that they show.
3519
+	 * @return void
3520
+	 * @throws EE_Error
3521
+	 */
3522
+	protected function _redirect_after_action(
3523
+		$success = 0,
3524
+		$what = 'item',
3525
+		$action_desc = 'processed',
3526
+		$query_args = array(),
3527
+		$override_overwrite = false
3528
+	) {
3529
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3530
+		//class name for actions/filters.
3531
+		$classname = get_class($this);
3532
+		// set redirect url.
3533
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3534
+		// otherwise we go with whatever is set as the _admin_base_url
3535
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3536
+		$notices      = EE_Error::get_notices(false);
3537
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3538
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3539
+			EE_Error::overwrite_success();
3540
+		}
3541
+		if (! empty($what) && ! empty($action_desc)  && empty($notices['errors'])) {
3542
+			// how many records affected ? more than one record ? or just one ?
3543
+			if ($success > 1) {
3544
+				// set plural msg
3545
+				EE_Error::add_success(
3546
+					sprintf(
3547
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3548
+						$what,
3549
+						$action_desc
3550
+					),
3551
+					__FILE__,
3552
+					__FUNCTION__,
3553
+					__LINE__
3554
+				);
3555
+			} elseif ($success === 1) {
3556
+				// set singular msg
3557
+				EE_Error::add_success(
3558
+					sprintf(
3559
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3560
+						$what,
3561
+						$action_desc
3562
+					),
3563
+					__FILE__,
3564
+					__FUNCTION__,
3565
+					__LINE__
3566
+				);
3567
+			}
3568
+		}
3569
+		// check that $query_args isn't something crazy
3570
+		if (! is_array($query_args)) {
3571
+			$query_args = array();
3572
+		}
3573
+		/**
3574
+		 * Allow injecting actions before the query_args are modified for possible different
3575
+		 * redirections on save and close actions
3576
+		 *
3577
+		 * @since 4.2.0
3578
+		 * @param array $query_args       The original query_args array coming into the
3579
+		 *                                method.
3580
+		 */
3581
+		do_action(
3582
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3583
+			$query_args
3584
+		);
3585
+		//calculate where we're going (if we have a "save and close" button pushed)
3586
+		if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3587
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3588
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3589
+			// regenerate query args array from referrer URL
3590
+			parse_str($parsed_url['query'], $query_args);
3591
+			// correct page and action will be in the query args now
3592
+			$redirect_url = admin_url('admin.php');
3593
+		}
3594
+		//merge any default query_args set in _default_route_query_args property
3595
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3596
+			$args_to_merge = array();
3597
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3598
+				//is there a wp_referer array in our _default_route_query_args property?
3599
+				if ($query_param === 'wp_referer') {
3600
+					$query_value = (array)$query_value;
3601
+					foreach ($query_value as $reference => $value) {
3602
+						if (strpos($reference, 'nonce') !== false) {
3603
+							continue;
3604
+						}
3605
+						//finally we will override any arguments in the referer with
3606
+						//what might be set on the _default_route_query_args array.
3607
+						if (isset($this->_default_route_query_args[$reference])) {
3608
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3609
+						} else {
3610
+							$args_to_merge[$reference] = urlencode($value);
3611
+						}
3612
+					}
3613
+					continue;
3614
+				}
3615
+				$args_to_merge[$query_param] = $query_value;
3616
+			}
3617
+			//now let's merge these arguments but override with what was specifically sent in to the
3618
+			//redirect.
3619
+			$query_args = array_merge($args_to_merge, $query_args);
3620
+		}
3621
+		$this->_process_notices($query_args);
3622
+		// generate redirect url
3623
+		// if redirecting to anything other than the main page, add a nonce
3624
+		if (isset($query_args['action'])) {
3625
+			// manually generate wp_nonce and merge that with the query vars
3626
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3627
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3628
+		}
3629
+		// we're adding some hooks and filters in here for processing any things just before redirects
3630
+		// (example: an admin page has done an insert or update and we want to run something after that).
3631
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3632
+		$redirect_url = apply_filters(
3633
+			'FHEE_redirect_' . $classname . $this->_req_action,
3634
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3635
+			$query_args
3636
+		);
3637
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3638
+		if (defined('DOING_AJAX')) {
3639
+			$default_data                    = array(
3640
+				'close'        => true,
3641
+				'redirect_url' => $redirect_url,
3642
+				'where'        => 'main',
3643
+				'what'         => 'append',
3644
+			);
3645
+			$this->_template_args['success'] = $success;
3646
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3647
+				$default_data,
3648
+				$this->_template_args['data']
3649
+			) : $default_data;
3650
+			$this->_return_json();
3651
+		}
3652
+		wp_safe_redirect($redirect_url);
3653
+		exit();
3654
+	}
3655
+
3656
+
3657
+
3658
+	/**
3659
+	 * process any notices before redirecting (or returning ajax request)
3660
+	 * This method sets the $this->_template_args['notices'] attribute;
3661
+	 *
3662
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
3663
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and
3664
+	 *                                  page_routes haven't been defined yet.
3665
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we
3666
+	 *                                  still save a transient for the notice.
3667
+	 * @return void
3668
+	 * @throws EE_Error
3669
+	 */
3670
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3671
+	{
3672
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
3673
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3674
+			$notices = EE_Error::get_notices(false);
3675
+			if (empty($this->_template_args['success'])) {
3676
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3677
+			}
3678
+			if (empty($this->_template_args['errors'])) {
3679
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3680
+			}
3681
+			if (empty($this->_template_args['attention'])) {
3682
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3683
+			}
3684
+		}
3685
+		$this->_template_args['notices'] = EE_Error::get_notices();
3686
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3687
+		if (! defined('DOING_AJAX') || $sticky_notices) {
3688
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3689
+			$this->_add_transient(
3690
+				$route,
3691
+				$this->_template_args['notices'],
3692
+				true,
3693
+				$skip_route_verify
3694
+			);
3695
+		}
3696
+	}
3697
+
3698
+
3699
+
3700
+	/**
3701
+	 * get_action_link_or_button
3702
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3703
+	 *
3704
+	 * @param string $action        use this to indicate which action the url is generated with.
3705
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3706
+	 *                              property.
3707
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3708
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3709
+	 * @param string $base_url      If this is not provided
3710
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3711
+	 *                              Otherwise this value will be used.
3712
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3713
+	 * @return string
3714
+	 * @throws InvalidArgumentException
3715
+	 * @throws InvalidInterfaceException
3716
+	 * @throws InvalidDataTypeException
3717
+	 * @throws EE_Error
3718
+	 */
3719
+	public function get_action_link_or_button(
3720
+		$action,
3721
+		$type = 'add',
3722
+		$extra_request = array(),
3723
+		$class = 'button-primary',
3724
+		$base_url = '',
3725
+		$exclude_nonce = false
3726
+	) {
3727
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3728
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3729
+			throw new EE_Error(
3730
+				sprintf(
3731
+					esc_html__(
3732
+						'There is no page route for given action for the button.  This action was given: %s',
3733
+						'event_espresso'
3734
+					),
3735
+					$action
3736
+				)
3737
+			);
3738
+		}
3739
+		if (! isset($this->_labels['buttons'][$type])) {
3740
+			throw new EE_Error(
3741
+				sprintf(
3742
+					__(
3743
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3744
+						'event_espresso'
3745
+					),
3746
+					$type
3747
+				)
3748
+			);
3749
+		}
3750
+		//finally check user access for this button.
3751
+		$has_access = $this->check_user_access($action, true);
3752
+		if (! $has_access) {
3753
+			return '';
3754
+		}
3755
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3756
+		$query_args = array(
3757
+			'action' => $action,
3758
+		);
3759
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3760
+		if (! empty($extra_request)) {
3761
+			$query_args = array_merge($extra_request, $query_args);
3762
+		}
3763
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3764
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3765
+	}
3766
+
3767
+
3768
+
3769
+	/**
3770
+	 * _per_page_screen_option
3771
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3772
+	 *
3773
+	 * @return void
3774
+	 * @throws InvalidArgumentException
3775
+	 * @throws InvalidInterfaceException
3776
+	 * @throws InvalidDataTypeException
3777
+	 */
3778
+	protected function _per_page_screen_option()
3779
+	{
3780
+		$option = 'per_page';
3781
+		$args   = array(
3782
+			'label'   => esc_html__(
3783
+					apply_filters(
3784
+						'FHEE__EE_Admin_Page___per_page_screen_options___label',
3785
+						$this->_admin_page_title,
3786
+						$this
3787
+					)
3788
+			),
3789
+			'default' => (int) apply_filters(
3790
+					'FHEE__EE_Admin_Page___per_page_screen_options__default',
3791
+					10
3792
+			),
3793
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3794
+		);
3795
+		//ONLY add the screen option if the user has access to it.
3796
+		if ($this->check_user_access($this->_current_view, true)) {
3797
+			add_screen_option($option, $args);
3798
+		}
3799
+	}
3800
+
3801
+
3802
+
3803
+	/**
3804
+	 * set_per_page_screen_option
3805
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3806
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3807
+	 * admin_menu.
3808
+	 *
3809
+	 * @return void
3810
+	 */
3811
+	private function _set_per_page_screen_options()
3812
+	{
3813
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3814
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3815
+			if (! $user = wp_get_current_user()) {
3816
+				return;
3817
+			}
3818
+			$option = $_POST['wp_screen_options']['option'];
3819
+			$value  = $_POST['wp_screen_options']['value'];
3820
+			if ($option != sanitize_key($option)) {
3821
+				return;
3822
+			}
3823
+			$map_option = $option;
3824
+			$option     = str_replace('-', '_', $option);
3825
+			switch ($map_option) {
3826
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3827
+					$value = (int)$value;
3828
+					$max_value = apply_filters(
3829
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3830
+						999,
3831
+						$this->_current_page,
3832
+						$this->_current_view
3833
+					);
3834
+					if ($value < 1) {
3835
+						return;
3836
+					}
3837
+					$value = min($value, $max_value);
3838
+					break;
3839
+				default:
3840
+					$value = apply_filters(
3841
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3842
+						false,
3843
+						$option,
3844
+						$value
3845
+					);
3846
+					if (false === $value) {
3847
+						return;
3848
+					}
3849
+					break;
3850
+			}
3851
+			update_user_meta($user->ID, $option, $value);
3852
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3853
+			exit;
3854
+		}
3855
+	}
3856
+
3857
+
3858
+
3859
+	/**
3860
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3861
+	 *
3862
+	 * @param array $data array that will be assigned to template args.
3863
+	 */
3864
+	public function set_template_args($data)
3865
+	{
3866
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3867
+	}
3868
+
3869
+
3870
+
3871
+	/**
3872
+	 * This makes available the WP transient system for temporarily moving data between routes
3873
+	 *
3874
+	 * @param string $route             the route that should receive the transient
3875
+	 * @param array  $data              the data that gets sent
3876
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3877
+	 *                                  normal route transient.
3878
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3879
+	 *                                  when we are adding a transient before page_routes have been defined.
3880
+	 * @return void
3881
+	 * @throws EE_Error
3882
+	 */
3883
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3884
+	{
3885
+		$user_id = get_current_user_id();
3886
+		if (! $skip_route_verify) {
3887
+			$this->_verify_route($route);
3888
+		}
3889
+		//now let's set the string for what kind of transient we're setting
3890
+		$transient = $notices
3891
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3892
+			: 'rte_tx_' . $route . '_' . $user_id;
3893
+		$data      = $notices ? array('notices' => $data) : $data;
3894
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3895
+		$existing = is_multisite() && is_network_admin()
3896
+			? get_site_transient($transient)
3897
+			: get_transient($transient);
3898
+		if ($existing) {
3899
+			$data = array_merge((array)$data, (array)$existing);
3900
+		}
3901
+		if (is_multisite() && is_network_admin()) {
3902
+			set_site_transient($transient, $data, 8);
3903
+		} else {
3904
+			set_transient($transient, $data, 8);
3905
+		}
3906
+	}
3907
+
3908
+
3909
+
3910
+	/**
3911
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3912
+	 *
3913
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3914
+	 * @param string $route
3915
+	 * @return mixed data
3916
+	 */
3917
+	protected function _get_transient($notices = false, $route = '')
3918
+	{
3919
+		$user_id   = get_current_user_id();
3920
+		$route     = ! $route ? $this->_req_action : $route;
3921
+		$transient = $notices
3922
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3923
+			: 'rte_tx_' . $route . '_' . $user_id;
3924
+		$data      = is_multisite() && is_network_admin()
3925
+			? get_site_transient($transient)
3926
+			: get_transient($transient);
3927
+		//delete transient after retrieval (just in case it hasn't expired);
3928
+		if (is_multisite() && is_network_admin()) {
3929
+			delete_site_transient($transient);
3930
+		} else {
3931
+			delete_transient($transient);
3932
+		}
3933
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3934
+	}
3935
+
3936
+
3937
+
3938
+	/**
3939
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3940
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3941
+	 * default route callback on the EE_Admin page you want it run.)
3942
+	 *
3943
+	 * @return void
3944
+	 */
3945
+	protected function _transient_garbage_collection()
3946
+	{
3947
+		global $wpdb;
3948
+		//retrieve all existing transients
3949
+		$query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3950
+		if ($results = $wpdb->get_results($query)) {
3951
+			foreach ($results as $result) {
3952
+				$transient = str_replace('_transient_', '', $result->option_name);
3953
+				get_transient($transient);
3954
+				if (is_multisite() && is_network_admin()) {
3955
+					get_site_transient($transient);
3956
+				}
3957
+			}
3958
+		}
3959
+	}
3960
+
3961
+
3962
+
3963
+	/**
3964
+	 * get_view
3965
+	 *
3966
+	 * @return string content of _view property
3967
+	 */
3968
+	public function get_view()
3969
+	{
3970
+		return $this->_view;
3971
+	}
3972
+
3973
+
3974
+
3975
+	/**
3976
+	 * getter for the protected $_views property
3977
+	 *
3978
+	 * @return array
3979
+	 */
3980
+	public function get_views()
3981
+	{
3982
+		return $this->_views;
3983
+	}
3984
+
3985
+
3986
+
3987
+	/**
3988
+	 * get_current_page
3989
+	 *
3990
+	 * @return string _current_page property value
3991
+	 */
3992
+	public function get_current_page()
3993
+	{
3994
+		return $this->_current_page;
3995
+	}
3996
+
3997
+
3998
+
3999
+	/**
4000
+	 * get_current_view
4001
+	 *
4002
+	 * @return string _current_view property value
4003
+	 */
4004
+	public function get_current_view()
4005
+	{
4006
+		return $this->_current_view;
4007
+	}
4008
+
4009
+
4010
+
4011
+	/**
4012
+	 * get_current_screen
4013
+	 *
4014
+	 * @return object The current WP_Screen object
4015
+	 */
4016
+	public function get_current_screen()
4017
+	{
4018
+		return $this->_current_screen;
4019
+	}
4020
+
4021
+
4022
+
4023
+	/**
4024
+	 * get_current_page_view_url
4025
+	 *
4026
+	 * @return string This returns the url for the current_page_view.
4027
+	 */
4028
+	public function get_current_page_view_url()
4029
+	{
4030
+		return $this->_current_page_view_url;
4031
+	}
4032
+
4033
+
4034
+
4035
+	/**
4036
+	 * just returns the _req_data property
4037
+	 *
4038
+	 * @return array
4039
+	 */
4040
+	public function get_request_data()
4041
+	{
4042
+		return $this->_req_data;
4043
+	}
4044
+
4045
+
4046
+
4047
+	/**
4048
+	 * returns the _req_data protected property
4049
+	 *
4050
+	 * @return string
4051
+	 */
4052
+	public function get_req_action()
4053
+	{
4054
+		return $this->_req_action;
4055
+	}
4056
+
4057
+
4058
+
4059
+	/**
4060
+	 * @return bool  value of $_is_caf property
4061
+	 */
4062
+	public function is_caf()
4063
+	{
4064
+		return $this->_is_caf;
4065
+	}
4066
+
4067
+
4068
+
4069
+	/**
4070
+	 * @return mixed
4071
+	 */
4072
+	public function default_espresso_metaboxes()
4073
+	{
4074
+		return $this->_default_espresso_metaboxes;
4075
+	}
4076
+
4077
+
4078
+
4079
+	/**
4080
+	 * @return mixed
4081
+	 */
4082
+	public function admin_base_url()
4083
+	{
4084
+		return $this->_admin_base_url;
4085
+	}
4086 4086
 
4087 4087
 
4088 4088
 
4089
-    /**
4090
-     * @return mixed
4091
-     */
4092
-    public function wp_page_slug()
4093
-    {
4094
-        return $this->_wp_page_slug;
4095
-    }
4089
+	/**
4090
+	 * @return mixed
4091
+	 */
4092
+	public function wp_page_slug()
4093
+	{
4094
+		return $this->_wp_page_slug;
4095
+	}
4096 4096
 
4097 4097
 
4098
-
4099
-    /**
4100
-     * updates  espresso configuration settings
4101
-     *
4102
-     * @param string                   $tab
4103
-     * @param EE_Config_Base|EE_Config $config
4104
-     * @param string                   $file file where error occurred
4105
-     * @param string                   $func function  where error occurred
4106
-     * @param string                   $line line no where error occurred
4107
-     * @return boolean
4108
-     */
4109
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4110
-    {
4111
-        //remove any options that are NOT going to be saved with the config settings.
4112
-        if (isset($config->core->ee_ueip_optin)) {
4113
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4114
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4115
-            update_option('ee_ueip_has_notified', true);
4116
-        }
4117
-        // and save it (note we're also doing the network save here)
4118
-        $net_saved    = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4119
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4120
-        if ($config_saved && $net_saved) {
4121
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4122
-            return true;
4123
-        }
4124
-        EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4125
-        return false;
4126
-    }
4127
-
4128
-
4129
-
4130
-    /**
4131
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4132
-     *
4133
-     * @return array
4134
-     */
4135
-    public function get_yes_no_values()
4136
-    {
4137
-        return $this->_yes_no_values;
4138
-    }
4139
-
4140
-
4141
-
4142
-    protected function _get_dir()
4143
-    {
4144
-        $reflector = new ReflectionClass(get_class($this));
4145
-        return dirname($reflector->getFileName());
4146
-    }
4147
-
4148
-
4149
-
4150
-    /**
4151
-     * A helper for getting a "next link".
4152
-     *
4153
-     * @param string $url   The url to link to
4154
-     * @param string $class The class to use.
4155
-     * @return string
4156
-     */
4157
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4158
-    {
4159
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4160
-    }
4161
-
4162
-
4163
-
4164
-    /**
4165
-     * A helper for getting a "previous link".
4166
-     *
4167
-     * @param string $url   The url to link to
4168
-     * @param string $class The class to use.
4169
-     * @return string
4170
-     */
4171
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4172
-    {
4173
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4174
-    }
4175
-
4176
-
4177
-
4178
-
4179
-
4180
-
4181
-
4182
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4183
-
4184
-
4185
-    /**
4186
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4187
-     * 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
4188
-     * _req_data array.
4189
-     *
4190
-     * @return bool success/fail
4191
-     * @throws EE_Error
4192
-     * @throws InvalidArgumentException
4193
-     * @throws ReflectionException
4194
-     * @throws InvalidDataTypeException
4195
-     * @throws InvalidInterfaceException
4196
-     */
4197
-    protected function _process_resend_registration()
4198
-    {
4199
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4200
-        do_action(
4201
-            'AHEE__EE_Admin_Page___process_resend_registration',
4202
-            $this->_template_args['success'],
4203
-            $this->_req_data
4204
-        );
4205
-        return $this->_template_args['success'];
4206
-    }
4207
-
4208
-
4209
-
4210
-    /**
4211
-     * This automatically processes any payment message notifications when manual payment has been applied.
4212
-     *
4213
-     * @param \EE_Payment $payment
4214
-     * @return bool success/fail
4215
-     */
4216
-    protected function _process_payment_notification(EE_Payment $payment)
4217
-    {
4218
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4219
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4220
-        $this->_template_args['success'] = apply_filters(
4221
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4222
-            false,
4223
-            $payment
4224
-        );
4225
-        return $this->_template_args['success'];
4226
-    }
4098
+
4099
+	/**
4100
+	 * updates  espresso configuration settings
4101
+	 *
4102
+	 * @param string                   $tab
4103
+	 * @param EE_Config_Base|EE_Config $config
4104
+	 * @param string                   $file file where error occurred
4105
+	 * @param string                   $func function  where error occurred
4106
+	 * @param string                   $line line no where error occurred
4107
+	 * @return boolean
4108
+	 */
4109
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4110
+	{
4111
+		//remove any options that are NOT going to be saved with the config settings.
4112
+		if (isset($config->core->ee_ueip_optin)) {
4113
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4114
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4115
+			update_option('ee_ueip_has_notified', true);
4116
+		}
4117
+		// and save it (note we're also doing the network save here)
4118
+		$net_saved    = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4119
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4120
+		if ($config_saved && $net_saved) {
4121
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4122
+			return true;
4123
+		}
4124
+		EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4125
+		return false;
4126
+	}
4127
+
4128
+
4129
+
4130
+	/**
4131
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4132
+	 *
4133
+	 * @return array
4134
+	 */
4135
+	public function get_yes_no_values()
4136
+	{
4137
+		return $this->_yes_no_values;
4138
+	}
4139
+
4140
+
4141
+
4142
+	protected function _get_dir()
4143
+	{
4144
+		$reflector = new ReflectionClass(get_class($this));
4145
+		return dirname($reflector->getFileName());
4146
+	}
4147
+
4148
+
4149
+
4150
+	/**
4151
+	 * A helper for getting a "next link".
4152
+	 *
4153
+	 * @param string $url   The url to link to
4154
+	 * @param string $class The class to use.
4155
+	 * @return string
4156
+	 */
4157
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4158
+	{
4159
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4160
+	}
4161
+
4162
+
4163
+
4164
+	/**
4165
+	 * A helper for getting a "previous link".
4166
+	 *
4167
+	 * @param string $url   The url to link to
4168
+	 * @param string $class The class to use.
4169
+	 * @return string
4170
+	 */
4171
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4172
+	{
4173
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4174
+	}
4175
+
4176
+
4177
+
4178
+
4179
+
4180
+
4181
+
4182
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4183
+
4184
+
4185
+	/**
4186
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4187
+	 * 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
4188
+	 * _req_data array.
4189
+	 *
4190
+	 * @return bool success/fail
4191
+	 * @throws EE_Error
4192
+	 * @throws InvalidArgumentException
4193
+	 * @throws ReflectionException
4194
+	 * @throws InvalidDataTypeException
4195
+	 * @throws InvalidInterfaceException
4196
+	 */
4197
+	protected function _process_resend_registration()
4198
+	{
4199
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4200
+		do_action(
4201
+			'AHEE__EE_Admin_Page___process_resend_registration',
4202
+			$this->_template_args['success'],
4203
+			$this->_req_data
4204
+		);
4205
+		return $this->_template_args['success'];
4206
+	}
4207
+
4208
+
4209
+
4210
+	/**
4211
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4212
+	 *
4213
+	 * @param \EE_Payment $payment
4214
+	 * @return bool success/fail
4215
+	 */
4216
+	protected function _process_payment_notification(EE_Payment $payment)
4217
+	{
4218
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4219
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4220
+		$this->_template_args['success'] = apply_filters(
4221
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4222
+			false,
4223
+			$payment
4224
+		);
4225
+		return $this->_template_args['success'];
4226
+	}
4227 4227
 
4228 4228
 
4229 4229
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
         EE_Maintenance_Mode $maintenance_mode = null
149 149
     ) {
150 150
         // check if class object is instantiated
151
-        if (! self::$_instance instanceof EE_System) {
151
+        if ( ! self::$_instance instanceof EE_System) {
152 152
             self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
153 153
         }
154 154
         return self::$_instance;
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
         $this->capabilities = $this->loader->getShared('EE_Capabilities');
268 268
         add_action(
269 269
             'AHEE__EE_Capabilities__init_caps__before_initialization',
270
-            function ()
270
+            function()
271 271
             {
272 272
                 LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
273 273
             }
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     {
312 312
         // set autoloaders for all of the classes implementing EEI_Plugin_API
313 313
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
314
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
314
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
315 315
         $this->loader->getShared('EE_Request_Handler');
316 316
     }
317 317
 
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
         $load_callback,
332 332
         $plugin_file_constant
333 333
     ) {
334
-        if (! defined($version_constant)) {
334
+        if ( ! defined($version_constant)) {
335 335
             return;
336 336
         }
337 337
         $addon_version = constant($version_constant);
338 338
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
339 339
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
340
-            if (! function_exists('deactivate_plugins')) {
341
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
340
+            if ( ! function_exists('deactivate_plugins')) {
341
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
342 342
             }
343 343
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
344 344
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
                     $addon_name,
352 352
                     $min_version_required
353 353
                 ),
354
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
354
+                __FILE__, __FUNCTION__."({$addon_name})", __LINE__
355 355
             );
356 356
             EE_Error::get_notices(false, true);
357 357
         }
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
                 true
402 402
             )
403 403
         ) {
404
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
404
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
405 405
         }
406 406
         do_action('AHEE__EE_System__load_espresso_addons__complete');
407 407
     }
@@ -508,11 +508,11 @@  discard block
 block discarded – undo
508 508
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
509 509
     {
510 510
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
511
-        if (! $espresso_db_update) {
511
+        if ( ! $espresso_db_update) {
512 512
             $espresso_db_update = get_option('espresso_db_update');
513 513
         }
514 514
         // check that option is an array
515
-        if (! is_array($espresso_db_update)) {
515
+        if ( ! is_array($espresso_db_update)) {
516 516
             // if option is FALSE, then it never existed
517 517
             if ($espresso_db_update === false) {
518 518
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -532,10 +532,10 @@  discard block
 block discarded – undo
532 532
                     //so it must be numerically-indexed, where values are versions installed...
533 533
                     //fix it!
534 534
                     $version_string                         = $should_be_array;
535
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
535
+                    $corrected_db_update[$version_string] = array('unknown-date');
536 536
                 } else {
537 537
                     //ok it checks out
538
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
538
+                    $corrected_db_update[$should_be_version_string] = $should_be_array;
539 539
                 }
540 540
             }
541 541
             $espresso_db_update = $corrected_db_update;
@@ -617,13 +617,13 @@  discard block
 block discarded – undo
617 617
      */
618 618
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
619 619
     {
620
-        if (! $version_history) {
620
+        if ( ! $version_history) {
621 621
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
622 622
         }
623 623
         if ($current_version_to_add === null) {
624 624
             $current_version_to_add = espresso_version();
625 625
         }
626
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
626
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
627 627
         // re-save
628 628
         return update_option('espresso_db_update', $version_history);
629 629
     }
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
         if ($activation_history_for_addon) {
717 717
             //it exists, so this isn't a completely new install
718 718
             //check if this version already in that list of previously installed versions
719
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
719
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
720 720
                 //it a version we haven't seen before
721 721
                 if ($version_is_higher === 1) {
722 722
                     $req_type = EE_System::req_type_upgrade;
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
             foreach ($activation_history as $version => $times_activated) {
797 797
                 //check there is a record of when this version was activated. Otherwise,
798 798
                 //mark it as unknown
799
-                if (! $times_activated) {
799
+                if ( ! $times_activated) {
800 800
                     $times_activated = array('unknown-date');
801 801
                 }
802 802
                 if (is_string($times_activated)) {
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
     private function _parse_model_names()
898 898
     {
899 899
         //get all the files in the EE_MODELS folder that end in .model.php
900
-        $models                 = glob(EE_MODELS . '*.model.php');
900
+        $models                 = glob(EE_MODELS.'*.model.php');
901 901
         $model_names            = array();
902 902
         $non_abstract_db_models = array();
903 903
         foreach ($models as $model) {
@@ -906,9 +906,9 @@  discard block
 block discarded – undo
906 906
             $short_name      = str_replace('EEM_', '', $classname);
907 907
             $reflectionClass = new ReflectionClass($classname);
908 908
             if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
909
-                $non_abstract_db_models[ $short_name ] = $classname;
909
+                $non_abstract_db_models[$short_name] = $classname;
910 910
             }
911
-            $model_names[ $short_name ] = $classname;
911
+            $model_names[$short_name] = $classname;
912 912
         }
913 913
         $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
914 914
         $this->registry->non_abstract_db_models = apply_filters(
@@ -943,7 +943,7 @@  discard block
 block discarded – undo
943 943
             )
944 944
         );
945 945
         if ($domain->isCaffeinated()) {
946
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
946
+            require_once EE_CAFF_PATH.'brewing_regular.php';
947 947
         }
948 948
     }
949 949
 
@@ -1008,17 +1008,17 @@  discard block
 block discarded – undo
1008 1008
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1009 1009
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
1010 1010
         );
1011
-        if (! empty($class_names)) {
1011
+        if ( ! empty($class_names)) {
1012 1012
             $msg = __(
1013 1013
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1014 1014
                 'event_espresso'
1015 1015
             );
1016 1016
             $msg .= '<ul>';
1017 1017
             foreach ($class_names as $class_name) {
1018
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
1018
+                $msg .= '<li><b>Event Espresso - '.str_replace(
1019 1019
                         array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1020 1020
                         $class_name
1021
-                    ) . '</b></li>';
1021
+                    ).'</b></li>';
1022 1022
             }
1023 1023
             $msg .= '</ul>';
1024 1024
             $msg .= __(
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
     private function _deactivate_incompatible_addons()
1091 1091
     {
1092 1092
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1093
-        if (! empty($incompatible_addons)) {
1093
+        if ( ! empty($incompatible_addons)) {
1094 1094
             $active_plugins = get_option('active_plugins', array());
1095 1095
             foreach ($active_plugins as $active_plugin) {
1096 1096
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
         do_action('AHEE__EE_System__core_loaded_and_ready');
1182 1182
         // load_espresso_template_tags
1183 1183
         if (
1184
-            is_readable(EE_PUBLIC . 'template_tags.php')
1184
+            is_readable(EE_PUBLIC.'template_tags.php')
1185 1185
             && (
1186 1186
                 $this->request->isFrontend()
1187 1187
                 || $this->request->isAdmin()
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
                 || $this->request->isFeed()
1190 1190
             )
1191 1191
         ) {
1192
-            require_once EE_PUBLIC . 'template_tags.php';
1192
+            require_once EE_PUBLIC.'template_tags.php';
1193 1193
         }
1194 1194
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1195 1195
         if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
@@ -1253,13 +1253,13 @@  discard block
 block discarded – undo
1253 1253
     public static function do_not_cache()
1254 1254
     {
1255 1255
         // set no cache constants
1256
-        if (! defined('DONOTCACHEPAGE')) {
1256
+        if ( ! defined('DONOTCACHEPAGE')) {
1257 1257
             define('DONOTCACHEPAGE', true);
1258 1258
         }
1259
-        if (! defined('DONOTCACHCEOBJECT')) {
1259
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1260 1260
             define('DONOTCACHCEOBJECT', true);
1261 1261
         }
1262
-        if (! defined('DONOTCACHEDB')) {
1262
+        if ( ! defined('DONOTCACHEDB')) {
1263 1263
             define('DONOTCACHEDB', true);
1264 1264
         }
1265 1265
         // add no cache headers
Please login to merge, or discard this patch.
Indentation   +1303 added lines, -1303 removed lines patch added patch discarded remove patch
@@ -32,1309 +32,1309 @@
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
37
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
38
-     */
39
-    const req_type_normal = 0;
40
-
41
-    /**
42
-     * Indicates this is a brand new installation of EE so we should install
43
-     * tables and default data etc
44
-     */
45
-    const req_type_new_activation = 1;
46
-
47
-    /**
48
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
49
-     * and we just exited maintenance mode). We MUST check the database is setup properly
50
-     * and that default data is setup too
51
-     */
52
-    const req_type_reactivation = 2;
53
-
54
-    /**
55
-     * indicates that EE has been upgraded since its previous request.
56
-     * We may have data migration scripts to call and will want to trigger maintenance mode
57
-     */
58
-    const req_type_upgrade = 3;
59
-
60
-    /**
61
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
62
-     */
63
-    const req_type_downgrade = 4;
64
-
65
-    /**
66
-     * @deprecated since version 4.6.0.dev.006
67
-     * Now whenever a new_activation is detected the request type is still just
68
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
69
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
70
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
71
-     * (Specifically, when the migration manager indicates migrations are finished
72
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
73
-     */
74
-    const req_type_activation_but_not_installed = 5;
75
-
76
-    /**
77
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
78
-     */
79
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
80
-
81
-
82
-    /**
83
-     * @var EE_System $_instance
84
-     */
85
-    private static $_instance;
86
-
87
-    /**
88
-     * @var EE_Registry $registry
89
-     */
90
-    private $registry;
91
-
92
-    /**
93
-     * @var LoaderInterface $loader
94
-     */
95
-    private $loader;
96
-
97
-    /**
98
-     * @var EE_Capabilities $capabilities
99
-     */
100
-    private $capabilities;
101
-
102
-    /**
103
-     * @var RequestInterface $request
104
-     */
105
-    private $request;
106
-
107
-    /**
108
-     * @var EE_Maintenance_Mode $maintenance_mode
109
-     */
110
-    private $maintenance_mode;
111
-
112
-    /**
113
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
114
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
115
-     *
116
-     * @var int $_req_type
117
-     */
118
-    private $_req_type;
119
-
120
-    /**
121
-     * Whether or not there was a non-micro version change in EE core version during this request
122
-     *
123
-     * @var boolean $_major_version_change
124
-     */
125
-    private $_major_version_change = false;
126
-
127
-    /**
128
-     * A Context DTO dedicated solely to identifying the current request type.
129
-     *
130
-     * @var RequestTypeContextCheckerInterface $request_type
131
-     */
132
-    private $request_type;
133
-
134
-
135
-
136
-    /**
137
-     * @singleton method used to instantiate class object
138
-     * @param EE_Registry|null         $registry
139
-     * @param LoaderInterface|null     $loader
140
-     * @param RequestInterface|null          $request
141
-     * @param EE_Maintenance_Mode|null $maintenance_mode
142
-     * @return EE_System
143
-     */
144
-    public static function instance(
145
-        EE_Registry $registry = null,
146
-        LoaderInterface $loader = null,
147
-        RequestInterface $request = null,
148
-        EE_Maintenance_Mode $maintenance_mode = null
149
-    ) {
150
-        // check if class object is instantiated
151
-        if (! self::$_instance instanceof EE_System) {
152
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
153
-        }
154
-        return self::$_instance;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * resets the instance and returns it
161
-     *
162
-     * @return EE_System
163
-     */
164
-    public static function reset()
165
-    {
166
-        self::$_instance->_req_type = null;
167
-        //make sure none of the old hooks are left hanging around
168
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
-        //we need to reset the migration manager in order for it to detect DMSs properly
170
-        EE_Data_Migration_Manager::reset();
171
-        self::instance()->detect_activations_or_upgrades();
172
-        self::instance()->perform_activations_upgrades_and_migrations();
173
-        return self::instance();
174
-    }
175
-
176
-
177
-
178
-    /**
179
-     * sets hooks for running rest of system
180
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
181
-     * starting EE Addons from any other point may lead to problems
182
-     *
183
-     * @param EE_Registry         $registry
184
-     * @param LoaderInterface     $loader
185
-     * @param RequestInterface          $request
186
-     * @param EE_Maintenance_Mode $maintenance_mode
187
-     */
188
-    private function __construct(
189
-        EE_Registry $registry,
190
-        LoaderInterface $loader,
191
-        RequestInterface $request,
192
-        EE_Maintenance_Mode $maintenance_mode
193
-    ) {
194
-        $this->registry         = $registry;
195
-        $this->loader           = $loader;
196
-        $this->request          = $request;
197
-        $this->maintenance_mode = $maintenance_mode;
198
-        do_action('AHEE__EE_System__construct__begin', $this);
199
-        add_action(
200
-            'AHEE__EE_Bootstrap__load_espresso_addons',
201
-            array($this, 'loadCapabilities'),
202
-            5
203
-        );
204
-        add_action(
205
-            'AHEE__EE_Bootstrap__load_espresso_addons',
206
-            array($this, 'loadCommandBus'),
207
-            7
208
-        );
209
-        add_action(
210
-            'AHEE__EE_Bootstrap__load_espresso_addons',
211
-            array($this, 'loadPluginApi'),
212
-            9
213
-        );
214
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
215
-        add_action(
216
-            'AHEE__EE_Bootstrap__load_espresso_addons',
217
-            array($this, 'load_espresso_addons')
218
-        );
219
-        // when an ee addon is activated, we want to call the core hook(s) again
220
-        // because the newly-activated addon didn't get a chance to run at all
221
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
222
-        // detect whether install or upgrade
223
-        add_action(
224
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
225
-            array($this, 'detect_activations_or_upgrades'),
226
-            3
227
-        );
228
-        // load EE_Config, EE_Textdomain, etc
229
-        add_action(
230
-            'AHEE__EE_Bootstrap__load_core_configuration',
231
-            array($this, 'load_core_configuration'),
232
-            5
233
-        );
234
-        // load EE_Config, EE_Textdomain, etc
235
-        add_action(
236
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
237
-            array($this, 'register_shortcodes_modules_and_widgets'),
238
-            7
239
-        );
240
-        // you wanna get going? I wanna get going... let's get going!
241
-        add_action(
242
-            'AHEE__EE_Bootstrap__brew_espresso',
243
-            array($this, 'brew_espresso'),
244
-            9
245
-        );
246
-        //other housekeeping
247
-        //exclude EE critical pages from wp_list_pages
248
-        add_filter(
249
-            'wp_list_pages_excludes',
250
-            array($this, 'remove_pages_from_wp_list_pages'),
251
-            10
252
-        );
253
-        // ALL EE Addons should use the following hook point to attach their initial setup too
254
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
255
-        do_action('AHEE__EE_System__construct__complete', $this);
256
-    }
257
-
258
-
259
-    /**
260
-     * load and setup EE_Capabilities
261
-     *
262
-     * @return void
263
-     * @throws EE_Error
264
-     */
265
-    public function loadCapabilities()
266
-    {
267
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
268
-        add_action(
269
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
270
-            function ()
271
-            {
272
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
273
-            }
274
-        );
275
-    }
276
-
277
-
278
-
279
-    /**
280
-     * create and cache the CommandBus, and also add middleware
281
-     * The CapChecker middleware requires the use of EE_Capabilities
282
-     * which is why we need to load the CommandBus after Caps are set up
283
-     *
284
-     * @return void
285
-     * @throws EE_Error
286
-     */
287
-    public function loadCommandBus()
288
-    {
289
-        $this->loader->getShared(
290
-            'CommandBusInterface',
291
-            array(
292
-                null,
293
-                apply_filters(
294
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
-                    array(
296
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
-                    )
299
-                ),
300
-            )
301
-        );
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @return void
308
-     * @throws EE_Error
309
-     */
310
-    public function loadPluginApi()
311
-    {
312
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
313
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
314
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
315
-        $this->loader->getShared('EE_Request_Handler');
316
-    }
317
-
318
-
319
-    /**
320
-     * @param string $addon_name
321
-     * @param string $version_constant
322
-     * @param string $min_version_required
323
-     * @param string $load_callback
324
-     * @param string $plugin_file_constant
325
-     * @return void
326
-     */
327
-    private function deactivateIncompatibleAddon(
328
-        $addon_name,
329
-        $version_constant,
330
-        $min_version_required,
331
-        $load_callback,
332
-        $plugin_file_constant
333
-    ) {
334
-        if (! defined($version_constant)) {
335
-            return;
336
-        }
337
-        $addon_version = constant($version_constant);
338
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
339
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
340
-            if (! function_exists('deactivate_plugins')) {
341
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
342
-            }
343
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
344
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
345
-            EE_Error::add_error(
346
-                sprintf(
347
-                    esc_html__(
348
-                        '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.',
349
-                        'event_espresso'
350
-                    ),
351
-                    $addon_name,
352
-                    $min_version_required
353
-                ),
354
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
355
-            );
356
-            EE_Error::get_notices(false, true);
357
-        }
358
-    }
359
-
360
-
361
-    /**
362
-     * load_espresso_addons
363
-     * allow addons to load first so that they can set hooks for running DMS's, etc
364
-     * this is hooked into both:
365
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
366
-     *        which runs during the WP 'plugins_loaded' action at priority 5
367
-     *    and the WP 'activate_plugin' hook point
368
-     *
369
-     * @access public
370
-     * @return void
371
-     */
372
-    public function load_espresso_addons()
373
-    {
374
-        $this->deactivateIncompatibleAddon(
375
-            'Wait Lists',
376
-            'EE_WAIT_LISTS_VERSION',
377
-            '1.0.0.beta.074',
378
-            'load_espresso_wait_lists',
379
-            'EE_WAIT_LISTS_PLUGIN_FILE'
380
-        );
381
-        $this->deactivateIncompatibleAddon(
382
-            'Automated Upcoming Event Notifications',
383
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
384
-            '1.0.0.beta.091',
385
-            'load_espresso_automated_upcoming_event_notification',
386
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
387
-        );
388
-        do_action('AHEE__EE_System__load_espresso_addons');
389
-        //if the WP API basic auth plugin isn't already loaded, load it now.
390
-        //We want it for mobile apps. Just include the entire plugin
391
-        //also, don't load the basic auth when a plugin is getting activated, because
392
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
393
-        //and causes a fatal error
394
-        if (
395
-            $this->request->getRequestParam('activate') !== 'true'
396
-            && ! function_exists('json_basic_auth_handler')
397
-            && ! function_exists('json_basic_auth_error')
398
-            && ! in_array(
399
-                $this->request->getRequestParam('action'),
400
-                array('activate', 'activate-selected'),
401
-                true
402
-            )
403
-        ) {
404
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
405
-        }
406
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * detect_activations_or_upgrades
413
-     * Checks for activation or upgrade of core first;
414
-     * then also checks if any registered addons have been activated or upgraded
415
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
-     * which runs during the WP 'plugins_loaded' action at priority 3
417
-     *
418
-     * @access public
419
-     * @return void
420
-     */
421
-    public function detect_activations_or_upgrades()
422
-    {
423
-        //first off: let's make sure to handle core
424
-        $this->detect_if_activation_or_upgrade();
425
-        foreach ($this->registry->addons as $addon) {
426
-            if ($addon instanceof EE_Addon) {
427
-                //detect teh request type for that addon
428
-                $addon->detect_activation_or_upgrade();
429
-            }
430
-        }
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * detect_if_activation_or_upgrade
437
-     * Takes care of detecting whether this is a brand new install or code upgrade,
438
-     * and either setting up the DB or setting up maintenance mode etc.
439
-     *
440
-     * @access public
441
-     * @return void
442
-     */
443
-    public function detect_if_activation_or_upgrade()
444
-    {
445
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
446
-        // check if db has been updated, or if its a brand-new installation
447
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
448
-        $request_type       = $this->detect_req_type($espresso_db_update);
449
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
450
-        switch ($request_type) {
451
-            case EE_System::req_type_new_activation:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
453
-                $this->_handle_core_version_change($espresso_db_update);
454
-                break;
455
-            case EE_System::req_type_reactivation:
456
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
457
-                $this->_handle_core_version_change($espresso_db_update);
458
-                break;
459
-            case EE_System::req_type_upgrade:
460
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
461
-                //migrations may be required now that we've upgraded
462
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
463
-                $this->_handle_core_version_change($espresso_db_update);
464
-                //				echo "done upgrade";die;
465
-                break;
466
-            case EE_System::req_type_downgrade:
467
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
468
-                //its possible migrations are no longer required
469
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
470
-                $this->_handle_core_version_change($espresso_db_update);
471
-                break;
472
-            case EE_System::req_type_normal:
473
-            default:
474
-                break;
475
-        }
476
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     * Updates the list of installed versions and sets hooks for
483
-     * initializing the database later during the request
484
-     *
485
-     * @param array $espresso_db_update
486
-     */
487
-    private function _handle_core_version_change($espresso_db_update)
488
-    {
489
-        $this->update_list_of_installed_versions($espresso_db_update);
490
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
491
-        add_action(
492
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
493
-            array($this, 'initialize_db_if_no_migrations_required')
494
-        );
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
501
-     * information about what versions of EE have been installed and activated,
502
-     * NOT necessarily the state of the database
503
-     *
504
-     * @param mixed $espresso_db_update           the value of the WordPress option.
505
-     *                                            If not supplied, fetches it from the options table
506
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
507
-     */
508
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
509
-    {
510
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
511
-        if (! $espresso_db_update) {
512
-            $espresso_db_update = get_option('espresso_db_update');
513
-        }
514
-        // check that option is an array
515
-        if (! is_array($espresso_db_update)) {
516
-            // if option is FALSE, then it never existed
517
-            if ($espresso_db_update === false) {
518
-                // make $espresso_db_update an array and save option with autoload OFF
519
-                $espresso_db_update = array();
520
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
521
-            } else {
522
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
523
-                $espresso_db_update = array($espresso_db_update => array());
524
-                update_option('espresso_db_update', $espresso_db_update);
525
-            }
526
-        } else {
527
-            $corrected_db_update = array();
528
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
529
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
530
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
531
-                    //the key is an int, and the value IS NOT an array
532
-                    //so it must be numerically-indexed, where values are versions installed...
533
-                    //fix it!
534
-                    $version_string                         = $should_be_array;
535
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
536
-                } else {
537
-                    //ok it checks out
538
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
539
-                }
540
-            }
541
-            $espresso_db_update = $corrected_db_update;
542
-            update_option('espresso_db_update', $espresso_db_update);
543
-        }
544
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
545
-        return $espresso_db_update;
546
-    }
547
-
548
-
549
-
550
-    /**
551
-     * Does the traditional work of setting up the plugin's database and adding default data.
552
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
553
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
554
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
555
-     * so that it will be done when migrations are finished
556
-     *
557
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
558
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
559
-     *                                       This is a resource-intensive job
560
-     *                                       so we prefer to only do it when necessary
561
-     * @return void
562
-     * @throws EE_Error
563
-     */
564
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
565
-    {
566
-        $request_type = $this->detect_req_type();
567
-        //only initialize system if we're not in maintenance mode.
568
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
569
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
570
-            $rewrite_rules = $this->loader->getShared(
571
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
572
-            );
573
-            $rewrite_rules->flush();
574
-            if ($verify_schema) {
575
-                EEH_Activation::initialize_db_and_folders();
576
-            }
577
-            EEH_Activation::initialize_db_content();
578
-            EEH_Activation::system_initialization();
579
-            if ($initialize_addons_too) {
580
-                $this->initialize_addons();
581
-            }
582
-        } else {
583
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
584
-        }
585
-        if ($request_type === EE_System::req_type_new_activation
586
-            || $request_type === EE_System::req_type_reactivation
587
-            || (
588
-                $request_type === EE_System::req_type_upgrade
589
-                && $this->is_major_version_change()
590
-            )
591
-        ) {
592
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
593
-        }
594
-    }
595
-
596
-
597
-
598
-    /**
599
-     * Initializes the db for all registered addons
600
-     *
601
-     * @throws EE_Error
602
-     */
603
-    public function initialize_addons()
604
-    {
605
-        //foreach registered addon, make sure its db is up-to-date too
606
-        foreach ($this->registry->addons as $addon) {
607
-            if ($addon instanceof EE_Addon) {
608
-                $addon->initialize_db_if_no_migrations_required();
609
-            }
610
-        }
611
-    }
612
-
613
-
614
-
615
-    /**
616
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
617
-     *
618
-     * @param    array  $version_history
619
-     * @param    string $current_version_to_add version to be added to the version history
620
-     * @return    boolean success as to whether or not this option was changed
621
-     */
622
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
623
-    {
624
-        if (! $version_history) {
625
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
626
-        }
627
-        if ($current_version_to_add === null) {
628
-            $current_version_to_add = espresso_version();
629
-        }
630
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
631
-        // re-save
632
-        return update_option('espresso_db_update', $version_history);
633
-    }
634
-
635
-
636
-
637
-    /**
638
-     * Detects if the current version indicated in the has existed in the list of
639
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
640
-     *
641
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
642
-     *                                  If not supplied, fetches it from the options table.
643
-     *                                  Also, caches its result so later parts of the code can also know whether
644
-     *                                  there's been an update or not. This way we can add the current version to
645
-     *                                  espresso_db_update, but still know if this is a new install or not
646
-     * @return int one of the constants on EE_System::req_type_
647
-     */
648
-    public function detect_req_type($espresso_db_update = null)
649
-    {
650
-        if ($this->_req_type === null) {
651
-            $espresso_db_update          = ! empty($espresso_db_update)
652
-                ? $espresso_db_update
653
-                : $this->fix_espresso_db_upgrade_option();
654
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
655
-                $espresso_db_update,
656
-                'ee_espresso_activation', espresso_version()
657
-            );
658
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
659
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
660
-        }
661
-        return $this->_req_type;
662
-    }
663
-
664
-
665
-
666
-    /**
667
-     * Returns whether or not there was a non-micro version change (ie, change in either
668
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
669
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
670
-     *
671
-     * @param $activation_history
672
-     * @return bool
673
-     */
674
-    private function _detect_major_version_change($activation_history)
675
-    {
676
-        $previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
677
-        $previous_version_parts = explode('.', $previous_version);
678
-        $current_version_parts  = explode('.', espresso_version());
679
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
680
-               && ($previous_version_parts[0] !== $current_version_parts[0]
681
-                   || $previous_version_parts[1] !== $current_version_parts[1]
682
-               );
683
-    }
684
-
685
-
686
-
687
-    /**
688
-     * Returns true if either the major or minor version of EE changed during this request.
689
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
690
-     *
691
-     * @return bool
692
-     */
693
-    public function is_major_version_change()
694
-    {
695
-        return $this->_major_version_change;
696
-    }
697
-
698
-
699
-
700
-    /**
701
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
702
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
703
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
704
-     * just activated to (for core that will always be espresso_version())
705
-     *
706
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
707
-     *                                                 ee plugin. for core that's 'espresso_db_update'
708
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
709
-     *                                                 indicate that this plugin was just activated
710
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
711
-     *                                                 espresso_version())
712
-     * @return int one of the constants on EE_System::req_type_*
713
-     */
714
-    public static function detect_req_type_given_activation_history(
715
-        $activation_history_for_addon,
716
-        $activation_indicator_option_name,
717
-        $version_to_upgrade_to
718
-    ) {
719
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
720
-        if ($activation_history_for_addon) {
721
-            //it exists, so this isn't a completely new install
722
-            //check if this version already in that list of previously installed versions
723
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
724
-                //it a version we haven't seen before
725
-                if ($version_is_higher === 1) {
726
-                    $req_type = EE_System::req_type_upgrade;
727
-                } else {
728
-                    $req_type = EE_System::req_type_downgrade;
729
-                }
730
-                delete_option($activation_indicator_option_name);
731
-            } else {
732
-                // its not an update. maybe a reactivation?
733
-                if (get_option($activation_indicator_option_name, false)) {
734
-                    if ($version_is_higher === -1) {
735
-                        $req_type = EE_System::req_type_downgrade;
736
-                    } elseif ($version_is_higher === 0) {
737
-                        //we've seen this version before, but it's an activation. must be a reactivation
738
-                        $req_type = EE_System::req_type_reactivation;
739
-                    } else {//$version_is_higher === 1
740
-                        $req_type = EE_System::req_type_upgrade;
741
-                    }
742
-                    delete_option($activation_indicator_option_name);
743
-                } else {
744
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
745
-                    if ($version_is_higher === -1) {
746
-                        $req_type = EE_System::req_type_downgrade;
747
-                    } elseif ($version_is_higher === 0) {
748
-                        //we've seen this version before and it's not an activation. its normal request
749
-                        $req_type = EE_System::req_type_normal;
750
-                    } else {//$version_is_higher === 1
751
-                        $req_type = EE_System::req_type_upgrade;
752
-                    }
753
-                }
754
-            }
755
-        } else {
756
-            //brand new install
757
-            $req_type = EE_System::req_type_new_activation;
758
-            delete_option($activation_indicator_option_name);
759
-        }
760
-        return $req_type;
761
-    }
762
-
763
-
764
-
765
-    /**
766
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
767
-     * the $activation_history_for_addon
768
-     *
769
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
770
-     *                                             sometimes containing 'unknown-date'
771
-     * @param string $version_to_upgrade_to        (current version)
772
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
773
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
774
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
775
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
776
-     */
777
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
778
-    {
779
-        //find the most recently-activated version
780
-        $most_recently_active_version =
781
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
782
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
783
-    }
784
-
785
-
786
-
787
-    /**
788
-     * Gets the most recently active version listed in the activation history,
789
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
790
-     *
791
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
792
-     *                                   sometimes containing 'unknown-date'
793
-     * @return string
794
-     */
795
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
796
-    {
797
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
798
-        $most_recently_active_version            = '0.0.0.dev.000';
799
-        if (is_array($activation_history)) {
800
-            foreach ($activation_history as $version => $times_activated) {
801
-                //check there is a record of when this version was activated. Otherwise,
802
-                //mark it as unknown
803
-                if (! $times_activated) {
804
-                    $times_activated = array('unknown-date');
805
-                }
806
-                if (is_string($times_activated)) {
807
-                    $times_activated = array($times_activated);
808
-                }
809
-                foreach ($times_activated as $an_activation) {
810
-                    if ($an_activation !== 'unknown-date'
811
-                        && $an_activation
812
-                           > $most_recently_active_version_activation) {
813
-                        $most_recently_active_version            = $version;
814
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
815
-                            ? '1970-01-01 00:00:00'
816
-                            : $an_activation;
817
-                    }
818
-                }
819
-            }
820
-        }
821
-        return $most_recently_active_version;
822
-    }
823
-
824
-
825
-
826
-    /**
827
-     * This redirects to the about EE page after activation
828
-     *
829
-     * @return void
830
-     */
831
-    public function redirect_to_about_ee()
832
-    {
833
-        $notices = EE_Error::get_notices(false);
834
-        //if current user is an admin and it's not an ajax or rest request
835
-        if (
836
-            ! isset($notices['errors'])
837
-            && $this->request->isAdmin()
838
-            && apply_filters(
839
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
840
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
841
-            )
842
-        ) {
843
-            $query_params = array('page' => 'espresso_about');
844
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
845
-                $query_params['new_activation'] = true;
846
-            }
847
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
848
-                $query_params['reactivation'] = true;
849
-            }
850
-            $url = add_query_arg($query_params, admin_url('admin.php'));
851
-            wp_safe_redirect($url);
852
-            exit();
853
-        }
854
-    }
855
-
856
-
857
-
858
-    /**
859
-     * load_core_configuration
860
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
861
-     * which runs during the WP 'plugins_loaded' action at priority 5
862
-     *
863
-     * @return void
864
-     * @throws ReflectionException
865
-     */
866
-    public function load_core_configuration()
867
-    {
868
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
869
-        $this->loader->getShared('EE_Load_Textdomain');
870
-        //load textdomain
871
-        EE_Load_Textdomain::load_textdomain();
872
-        // load and setup EE_Config and EE_Network_Config
873
-        $config = $this->loader->getShared('EE_Config');
874
-        $this->loader->getShared('EE_Network_Config');
875
-        // setup autoloaders
876
-        // enable logging?
877
-        if ($config->admin->use_full_logging) {
878
-            $this->loader->getShared('EE_Log');
879
-        }
880
-        // check for activation errors
881
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
882
-        if ($activation_errors) {
883
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
884
-            update_option('ee_plugin_activation_errors', false);
885
-        }
886
-        // get model names
887
-        $this->_parse_model_names();
888
-        //load caf stuff a chance to play during the activation process too.
889
-        $this->_maybe_brew_regular();
890
-        // configure custom post type definitions
891
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
892
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
893
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
894
-    }
895
-
896
-
897
-
898
-    /**
899
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
900
-     *
901
-     * @return void
902
-     * @throws ReflectionException
903
-     */
904
-    private function _parse_model_names()
905
-    {
906
-        //get all the files in the EE_MODELS folder that end in .model.php
907
-        $models                 = glob(EE_MODELS . '*.model.php');
908
-        $model_names            = array();
909
-        $non_abstract_db_models = array();
910
-        foreach ($models as $model) {
911
-            // get model classname
912
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
913
-            $short_name      = str_replace('EEM_', '', $classname);
914
-            $reflectionClass = new ReflectionClass($classname);
915
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
916
-                $non_abstract_db_models[ $short_name ] = $classname;
917
-            }
918
-            $model_names[ $short_name ] = $classname;
919
-        }
920
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
921
-        $this->registry->non_abstract_db_models = apply_filters(
922
-            'FHEE__EE_System__parse_implemented_model_names',
923
-            $non_abstract_db_models
924
-        );
925
-    }
926
-
927
-
928
-    /**
929
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
930
-     * that need to be setup before our EE_System launches.
931
-     *
932
-     * @return void
933
-     * @throws DomainException
934
-     * @throws InvalidArgumentException
935
-     * @throws InvalidDataTypeException
936
-     * @throws InvalidInterfaceException
937
-     * @throws InvalidClassException
938
-     * @throws InvalidFilePathException
939
-     */
940
-    private function _maybe_brew_regular()
941
-    {
942
-        /** @var Domain $domain */
943
-        $domain = DomainFactory::getShared(
944
-            new FullyQualifiedName(
945
-                'EventEspresso\core\domain\Domain'
946
-            ),
947
-            array(
948
-                new FilePath(EVENT_ESPRESSO_MAIN_FILE),
949
-                Version::fromString(espresso_version())
950
-            )
951
-        );
952
-        if ($domain->isCaffeinated()) {
953
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
954
-        }
955
-    }
956
-
957
-
958
-
959
-    /**
960
-     * register_shortcodes_modules_and_widgets
961
-     * generate lists of shortcodes and modules, then verify paths and classes
962
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
963
-     * which runs during the WP 'plugins_loaded' action at priority 7
964
-     *
965
-     * @access public
966
-     * @return void
967
-     * @throws Exception
968
-     */
969
-    public function register_shortcodes_modules_and_widgets()
970
-    {
971
-        try {
972
-            // load, register, and add shortcodes the new way
973
-            if ($this->request->isFrontend() || $this->request->isIframe()) {
974
-                $this->loader->getShared(
975
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
976
-                    array(
977
-                        // and the old way, but we'll put it under control of the new system
978
-                        EE_Config::getLegacyShortcodesManager(),
979
-                    )
980
-                );
981
-            }
982
-            if (function_exists('register_block_type')) {
983
-                // or the even newer newer new way
984
-                if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
985
-                    $this->loader->getShared(
986
-                        'EventEspresso\core\services\editor\BlockRegistrationManager'
987
-                    );
988
-                }
989
-                if ($this->request->isAdmin()) {
990
-                    $this->loader->getShared(
991
-                        'EventEspresso\core\services\editor\EspressoGutenbergEditor',
992
-                        array($editor_block_collection, $this->request)
993
-                    );
994
-                }
995
-            }
996
-        } catch (Exception $exception) {
997
-            new ExceptionStackTraceDisplay($exception);
998
-        }
999
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
1000
-        // check for addons using old hook point
1001
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
1002
-            $this->_incompatible_addon_error();
1003
-        }
1004
-    }
1005
-
1006
-
1007
-
1008
-    /**
1009
-     * _incompatible_addon_error
1010
-     *
1011
-     * @access public
1012
-     * @return void
1013
-     */
1014
-    private function _incompatible_addon_error()
1015
-    {
1016
-        // get array of classes hooking into here
1017
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1018
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
1019
-        );
1020
-        if (! empty($class_names)) {
1021
-            $msg = __(
1022
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1023
-                'event_espresso'
1024
-            );
1025
-            $msg .= '<ul>';
1026
-            foreach ($class_names as $class_name) {
1027
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
1028
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1029
-                        $class_name
1030
-                    ) . '</b></li>';
1031
-            }
1032
-            $msg .= '</ul>';
1033
-            $msg .= __(
1034
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1035
-                'event_espresso'
1036
-            );
1037
-            // save list of incompatible addons to wp-options for later use
1038
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1039
-            if (is_admin()) {
1040
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1041
-            }
1042
-        }
1043
-    }
1044
-
1045
-
1046
-
1047
-    /**
1048
-     * brew_espresso
1049
-     * begins the process of setting hooks for initializing EE in the correct order
1050
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1051
-     * which runs during the WP 'plugins_loaded' action at priority 9
1052
-     *
1053
-     * @return void
1054
-     */
1055
-    public function brew_espresso()
1056
-    {
1057
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1058
-        // load some final core systems
1059
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1060
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1061
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1062
-        add_action('init', array($this, 'load_controllers'), 7);
1063
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1064
-        add_action('init', array($this, 'initialize'), 10);
1065
-        add_action('init', array($this, 'initialize_last'), 100);
1066
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1067
-            // pew pew pew
1068
-            $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1069
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1070
-        }
1071
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1072
-    }
1073
-
1074
-
1075
-
1076
-    /**
1077
-     *    set_hooks_for_core
1078
-     *
1079
-     * @access public
1080
-     * @return    void
1081
-     * @throws EE_Error
1082
-     */
1083
-    public function set_hooks_for_core()
1084
-    {
1085
-        $this->_deactivate_incompatible_addons();
1086
-        do_action('AHEE__EE_System__set_hooks_for_core');
1087
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1088
-        //caps need to be initialized on every request so that capability maps are set.
1089
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1090
-        $this->registry->CAP->init_caps();
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1097
-     * deactivates any addons considered incompatible with the current version of EE
1098
-     */
1099
-    private function _deactivate_incompatible_addons()
1100
-    {
1101
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1102
-        if (! empty($incompatible_addons)) {
1103
-            $active_plugins = get_option('active_plugins', array());
1104
-            foreach ($active_plugins as $active_plugin) {
1105
-                foreach ($incompatible_addons as $incompatible_addon) {
1106
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1107
-                        unset($_GET['activate']);
1108
-                        espresso_deactivate_plugin($active_plugin);
1109
-                    }
1110
-                }
1111
-            }
1112
-        }
1113
-    }
1114
-
1115
-
1116
-
1117
-    /**
1118
-     *    perform_activations_upgrades_and_migrations
1119
-     *
1120
-     * @access public
1121
-     * @return    void
1122
-     */
1123
-    public function perform_activations_upgrades_and_migrations()
1124
-    {
1125
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1126
-    }
1127
-
1128
-
1129
-    /**
1130
-     * @return void
1131
-     * @throws DomainException
1132
-     */
1133
-    public function load_CPTs_and_session()
1134
-    {
1135
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1136
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1137
-        $register_custom_taxonomies = $this->loader->getShared(
1138
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1139
-        );
1140
-        $register_custom_taxonomies->registerCustomTaxonomies();
1141
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1142
-        $register_custom_post_types = $this->loader->getShared(
1143
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1144
-        );
1145
-        $register_custom_post_types->registerCustomPostTypes();
1146
-        // register Custom Post Types and Taxonomies
1147
-        $this->loader->getShared('EE_Register_CPTs');
1148
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1149
-    }
1150
-
1151
-
1152
-
1153
-    /**
1154
-     * load_controllers
1155
-     * this is the best place to load any additional controllers that needs access to EE core.
1156
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1157
-     * time
1158
-     *
1159
-     * @access public
1160
-     * @return void
1161
-     */
1162
-    public function load_controllers()
1163
-    {
1164
-        do_action('AHEE__EE_System__load_controllers__start');
1165
-        // let's get it started
1166
-        if (
1167
-            ! $this->maintenance_mode->level()
1168
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1169
-        ) {
1170
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1171
-            $this->loader->getShared('EE_Front_Controller');
1172
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1173
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1174
-            $this->loader->getShared('EE_Admin');
1175
-        }
1176
-        do_action('AHEE__EE_System__load_controllers__complete');
1177
-    }
1178
-
1179
-
1180
-
1181
-    /**
1182
-     * core_loaded_and_ready
1183
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1184
-     *
1185
-     * @access public
1186
-     * @return void
1187
-     */
1188
-    public function core_loaded_and_ready()
1189
-    {
1190
-        if (
1191
-            $this->request->isAdmin()
1192
-            || $this->request->isEeAjax()
1193
-            || $this->request->isFrontend()
1194
-        ) {
1195
-            $this->loader->getShared('EE_Session');
1196
-        }
1197
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1198
-        // load_espresso_template_tags
1199
-        if (
1200
-            is_readable(EE_PUBLIC . 'template_tags.php')
1201
-            && (
1202
-                $this->request->isFrontend()
1203
-                || $this->request->isAdmin()
1204
-                || $this->request->isIframe()
1205
-                || $this->request->isFeed()
1206
-            )
1207
-        ) {
1208
-            require_once EE_PUBLIC . 'template_tags.php';
1209
-        }
1210
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1211
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1212
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1213
-        }
1214
-    }
1215
-
1216
-
1217
-
1218
-    /**
1219
-     * initialize
1220
-     * this is the best place to begin initializing client code
1221
-     *
1222
-     * @access public
1223
-     * @return void
1224
-     */
1225
-    public function initialize()
1226
-    {
1227
-        do_action('AHEE__EE_System__initialize');
1228
-    }
1229
-
1230
-
1231
-
1232
-    /**
1233
-     * initialize_last
1234
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1235
-     * initialize has done so
1236
-     *
1237
-     * @access public
1238
-     * @return void
1239
-     */
1240
-    public function initialize_last()
1241
-    {
1242
-        do_action('AHEE__EE_System__initialize_last');
1243
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1244
-        $rewrite_rules = $this->loader->getShared(
1245
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1246
-        );
1247
-        $rewrite_rules->flushRewriteRules();
1248
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1249
-    }
1250
-
1251
-
1252
-
1253
-    /**
1254
-     * @return void
1255
-     * @throws EE_Error
1256
-     */
1257
-    public function addEspressoToolbar()
1258
-    {
1259
-        $this->loader->getShared(
1260
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1261
-            array($this->registry->CAP)
1262
-        );
1263
-    }
1264
-
1265
-
1266
-
1267
-    /**
1268
-     * do_not_cache
1269
-     * sets no cache headers and defines no cache constants for WP plugins
1270
-     *
1271
-     * @access public
1272
-     * @return void
1273
-     */
1274
-    public static function do_not_cache()
1275
-    {
1276
-        // set no cache constants
1277
-        if (! defined('DONOTCACHEPAGE')) {
1278
-            define('DONOTCACHEPAGE', true);
1279
-        }
1280
-        if (! defined('DONOTCACHCEOBJECT')) {
1281
-            define('DONOTCACHCEOBJECT', true);
1282
-        }
1283
-        if (! defined('DONOTCACHEDB')) {
1284
-            define('DONOTCACHEDB', true);
1285
-        }
1286
-        // add no cache headers
1287
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1288
-        // plus a little extra for nginx and Google Chrome
1289
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1290
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1291
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1292
-    }
1293
-
1294
-
1295
-
1296
-    /**
1297
-     *    extra_nocache_headers
1298
-     *
1299
-     * @access    public
1300
-     * @param $headers
1301
-     * @return    array
1302
-     */
1303
-    public static function extra_nocache_headers($headers)
1304
-    {
1305
-        // for NGINX
1306
-        $headers['X-Accel-Expires'] = 0;
1307
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1308
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1309
-        return $headers;
1310
-    }
1311
-
1312
-
1313
-
1314
-    /**
1315
-     *    nocache_headers
1316
-     *
1317
-     * @access    public
1318
-     * @return    void
1319
-     */
1320
-    public static function nocache_headers()
1321
-    {
1322
-        nocache_headers();
1323
-    }
1324
-
1325
-
1326
-
1327
-    /**
1328
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1329
-     * never returned with the function.
1330
-     *
1331
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1332
-     * @return array
1333
-     */
1334
-    public function remove_pages_from_wp_list_pages($exclude_array)
1335
-    {
1336
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1337
-    }
35
+	/**
36
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
37
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
38
+	 */
39
+	const req_type_normal = 0;
40
+
41
+	/**
42
+	 * Indicates this is a brand new installation of EE so we should install
43
+	 * tables and default data etc
44
+	 */
45
+	const req_type_new_activation = 1;
46
+
47
+	/**
48
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
49
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
50
+	 * and that default data is setup too
51
+	 */
52
+	const req_type_reactivation = 2;
53
+
54
+	/**
55
+	 * indicates that EE has been upgraded since its previous request.
56
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
57
+	 */
58
+	const req_type_upgrade = 3;
59
+
60
+	/**
61
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
62
+	 */
63
+	const req_type_downgrade = 4;
64
+
65
+	/**
66
+	 * @deprecated since version 4.6.0.dev.006
67
+	 * Now whenever a new_activation is detected the request type is still just
68
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
69
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
70
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
71
+	 * (Specifically, when the migration manager indicates migrations are finished
72
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
73
+	 */
74
+	const req_type_activation_but_not_installed = 5;
75
+
76
+	/**
77
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
78
+	 */
79
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
80
+
81
+
82
+	/**
83
+	 * @var EE_System $_instance
84
+	 */
85
+	private static $_instance;
86
+
87
+	/**
88
+	 * @var EE_Registry $registry
89
+	 */
90
+	private $registry;
91
+
92
+	/**
93
+	 * @var LoaderInterface $loader
94
+	 */
95
+	private $loader;
96
+
97
+	/**
98
+	 * @var EE_Capabilities $capabilities
99
+	 */
100
+	private $capabilities;
101
+
102
+	/**
103
+	 * @var RequestInterface $request
104
+	 */
105
+	private $request;
106
+
107
+	/**
108
+	 * @var EE_Maintenance_Mode $maintenance_mode
109
+	 */
110
+	private $maintenance_mode;
111
+
112
+	/**
113
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
114
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
115
+	 *
116
+	 * @var int $_req_type
117
+	 */
118
+	private $_req_type;
119
+
120
+	/**
121
+	 * Whether or not there was a non-micro version change in EE core version during this request
122
+	 *
123
+	 * @var boolean $_major_version_change
124
+	 */
125
+	private $_major_version_change = false;
126
+
127
+	/**
128
+	 * A Context DTO dedicated solely to identifying the current request type.
129
+	 *
130
+	 * @var RequestTypeContextCheckerInterface $request_type
131
+	 */
132
+	private $request_type;
133
+
134
+
135
+
136
+	/**
137
+	 * @singleton method used to instantiate class object
138
+	 * @param EE_Registry|null         $registry
139
+	 * @param LoaderInterface|null     $loader
140
+	 * @param RequestInterface|null          $request
141
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
142
+	 * @return EE_System
143
+	 */
144
+	public static function instance(
145
+		EE_Registry $registry = null,
146
+		LoaderInterface $loader = null,
147
+		RequestInterface $request = null,
148
+		EE_Maintenance_Mode $maintenance_mode = null
149
+	) {
150
+		// check if class object is instantiated
151
+		if (! self::$_instance instanceof EE_System) {
152
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
153
+		}
154
+		return self::$_instance;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * resets the instance and returns it
161
+	 *
162
+	 * @return EE_System
163
+	 */
164
+	public static function reset()
165
+	{
166
+		self::$_instance->_req_type = null;
167
+		//make sure none of the old hooks are left hanging around
168
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
+		//we need to reset the migration manager in order for it to detect DMSs properly
170
+		EE_Data_Migration_Manager::reset();
171
+		self::instance()->detect_activations_or_upgrades();
172
+		self::instance()->perform_activations_upgrades_and_migrations();
173
+		return self::instance();
174
+	}
175
+
176
+
177
+
178
+	/**
179
+	 * sets hooks for running rest of system
180
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
181
+	 * starting EE Addons from any other point may lead to problems
182
+	 *
183
+	 * @param EE_Registry         $registry
184
+	 * @param LoaderInterface     $loader
185
+	 * @param RequestInterface          $request
186
+	 * @param EE_Maintenance_Mode $maintenance_mode
187
+	 */
188
+	private function __construct(
189
+		EE_Registry $registry,
190
+		LoaderInterface $loader,
191
+		RequestInterface $request,
192
+		EE_Maintenance_Mode $maintenance_mode
193
+	) {
194
+		$this->registry         = $registry;
195
+		$this->loader           = $loader;
196
+		$this->request          = $request;
197
+		$this->maintenance_mode = $maintenance_mode;
198
+		do_action('AHEE__EE_System__construct__begin', $this);
199
+		add_action(
200
+			'AHEE__EE_Bootstrap__load_espresso_addons',
201
+			array($this, 'loadCapabilities'),
202
+			5
203
+		);
204
+		add_action(
205
+			'AHEE__EE_Bootstrap__load_espresso_addons',
206
+			array($this, 'loadCommandBus'),
207
+			7
208
+		);
209
+		add_action(
210
+			'AHEE__EE_Bootstrap__load_espresso_addons',
211
+			array($this, 'loadPluginApi'),
212
+			9
213
+		);
214
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
215
+		add_action(
216
+			'AHEE__EE_Bootstrap__load_espresso_addons',
217
+			array($this, 'load_espresso_addons')
218
+		);
219
+		// when an ee addon is activated, we want to call the core hook(s) again
220
+		// because the newly-activated addon didn't get a chance to run at all
221
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
222
+		// detect whether install or upgrade
223
+		add_action(
224
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
225
+			array($this, 'detect_activations_or_upgrades'),
226
+			3
227
+		);
228
+		// load EE_Config, EE_Textdomain, etc
229
+		add_action(
230
+			'AHEE__EE_Bootstrap__load_core_configuration',
231
+			array($this, 'load_core_configuration'),
232
+			5
233
+		);
234
+		// load EE_Config, EE_Textdomain, etc
235
+		add_action(
236
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
237
+			array($this, 'register_shortcodes_modules_and_widgets'),
238
+			7
239
+		);
240
+		// you wanna get going? I wanna get going... let's get going!
241
+		add_action(
242
+			'AHEE__EE_Bootstrap__brew_espresso',
243
+			array($this, 'brew_espresso'),
244
+			9
245
+		);
246
+		//other housekeeping
247
+		//exclude EE critical pages from wp_list_pages
248
+		add_filter(
249
+			'wp_list_pages_excludes',
250
+			array($this, 'remove_pages_from_wp_list_pages'),
251
+			10
252
+		);
253
+		// ALL EE Addons should use the following hook point to attach their initial setup too
254
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
255
+		do_action('AHEE__EE_System__construct__complete', $this);
256
+	}
257
+
258
+
259
+	/**
260
+	 * load and setup EE_Capabilities
261
+	 *
262
+	 * @return void
263
+	 * @throws EE_Error
264
+	 */
265
+	public function loadCapabilities()
266
+	{
267
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
268
+		add_action(
269
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
270
+			function ()
271
+			{
272
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
273
+			}
274
+		);
275
+	}
276
+
277
+
278
+
279
+	/**
280
+	 * create and cache the CommandBus, and also add middleware
281
+	 * The CapChecker middleware requires the use of EE_Capabilities
282
+	 * which is why we need to load the CommandBus after Caps are set up
283
+	 *
284
+	 * @return void
285
+	 * @throws EE_Error
286
+	 */
287
+	public function loadCommandBus()
288
+	{
289
+		$this->loader->getShared(
290
+			'CommandBusInterface',
291
+			array(
292
+				null,
293
+				apply_filters(
294
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
+					array(
296
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
+					)
299
+				),
300
+			)
301
+		);
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @return void
308
+	 * @throws EE_Error
309
+	 */
310
+	public function loadPluginApi()
311
+	{
312
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
313
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
314
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
315
+		$this->loader->getShared('EE_Request_Handler');
316
+	}
317
+
318
+
319
+	/**
320
+	 * @param string $addon_name
321
+	 * @param string $version_constant
322
+	 * @param string $min_version_required
323
+	 * @param string $load_callback
324
+	 * @param string $plugin_file_constant
325
+	 * @return void
326
+	 */
327
+	private function deactivateIncompatibleAddon(
328
+		$addon_name,
329
+		$version_constant,
330
+		$min_version_required,
331
+		$load_callback,
332
+		$plugin_file_constant
333
+	) {
334
+		if (! defined($version_constant)) {
335
+			return;
336
+		}
337
+		$addon_version = constant($version_constant);
338
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
339
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
340
+			if (! function_exists('deactivate_plugins')) {
341
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
342
+			}
343
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
344
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
345
+			EE_Error::add_error(
346
+				sprintf(
347
+					esc_html__(
348
+						'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.',
349
+						'event_espresso'
350
+					),
351
+					$addon_name,
352
+					$min_version_required
353
+				),
354
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
355
+			);
356
+			EE_Error::get_notices(false, true);
357
+		}
358
+	}
359
+
360
+
361
+	/**
362
+	 * load_espresso_addons
363
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
364
+	 * this is hooked into both:
365
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
366
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
367
+	 *    and the WP 'activate_plugin' hook point
368
+	 *
369
+	 * @access public
370
+	 * @return void
371
+	 */
372
+	public function load_espresso_addons()
373
+	{
374
+		$this->deactivateIncompatibleAddon(
375
+			'Wait Lists',
376
+			'EE_WAIT_LISTS_VERSION',
377
+			'1.0.0.beta.074',
378
+			'load_espresso_wait_lists',
379
+			'EE_WAIT_LISTS_PLUGIN_FILE'
380
+		);
381
+		$this->deactivateIncompatibleAddon(
382
+			'Automated Upcoming Event Notifications',
383
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
384
+			'1.0.0.beta.091',
385
+			'load_espresso_automated_upcoming_event_notification',
386
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
387
+		);
388
+		do_action('AHEE__EE_System__load_espresso_addons');
389
+		//if the WP API basic auth plugin isn't already loaded, load it now.
390
+		//We want it for mobile apps. Just include the entire plugin
391
+		//also, don't load the basic auth when a plugin is getting activated, because
392
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
393
+		//and causes a fatal error
394
+		if (
395
+			$this->request->getRequestParam('activate') !== 'true'
396
+			&& ! function_exists('json_basic_auth_handler')
397
+			&& ! function_exists('json_basic_auth_error')
398
+			&& ! in_array(
399
+				$this->request->getRequestParam('action'),
400
+				array('activate', 'activate-selected'),
401
+				true
402
+			)
403
+		) {
404
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
405
+		}
406
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * detect_activations_or_upgrades
413
+	 * Checks for activation or upgrade of core first;
414
+	 * then also checks if any registered addons have been activated or upgraded
415
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
+	 * which runs during the WP 'plugins_loaded' action at priority 3
417
+	 *
418
+	 * @access public
419
+	 * @return void
420
+	 */
421
+	public function detect_activations_or_upgrades()
422
+	{
423
+		//first off: let's make sure to handle core
424
+		$this->detect_if_activation_or_upgrade();
425
+		foreach ($this->registry->addons as $addon) {
426
+			if ($addon instanceof EE_Addon) {
427
+				//detect teh request type for that addon
428
+				$addon->detect_activation_or_upgrade();
429
+			}
430
+		}
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * detect_if_activation_or_upgrade
437
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
438
+	 * and either setting up the DB or setting up maintenance mode etc.
439
+	 *
440
+	 * @access public
441
+	 * @return void
442
+	 */
443
+	public function detect_if_activation_or_upgrade()
444
+	{
445
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
446
+		// check if db has been updated, or if its a brand-new installation
447
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
448
+		$request_type       = $this->detect_req_type($espresso_db_update);
449
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
450
+		switch ($request_type) {
451
+			case EE_System::req_type_new_activation:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
453
+				$this->_handle_core_version_change($espresso_db_update);
454
+				break;
455
+			case EE_System::req_type_reactivation:
456
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
457
+				$this->_handle_core_version_change($espresso_db_update);
458
+				break;
459
+			case EE_System::req_type_upgrade:
460
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
461
+				//migrations may be required now that we've upgraded
462
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
463
+				$this->_handle_core_version_change($espresso_db_update);
464
+				//				echo "done upgrade";die;
465
+				break;
466
+			case EE_System::req_type_downgrade:
467
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
468
+				//its possible migrations are no longer required
469
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
470
+				$this->_handle_core_version_change($espresso_db_update);
471
+				break;
472
+			case EE_System::req_type_normal:
473
+			default:
474
+				break;
475
+		}
476
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * Updates the list of installed versions and sets hooks for
483
+	 * initializing the database later during the request
484
+	 *
485
+	 * @param array $espresso_db_update
486
+	 */
487
+	private function _handle_core_version_change($espresso_db_update)
488
+	{
489
+		$this->update_list_of_installed_versions($espresso_db_update);
490
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
491
+		add_action(
492
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
493
+			array($this, 'initialize_db_if_no_migrations_required')
494
+		);
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
501
+	 * information about what versions of EE have been installed and activated,
502
+	 * NOT necessarily the state of the database
503
+	 *
504
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
505
+	 *                                            If not supplied, fetches it from the options table
506
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
507
+	 */
508
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
509
+	{
510
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
511
+		if (! $espresso_db_update) {
512
+			$espresso_db_update = get_option('espresso_db_update');
513
+		}
514
+		// check that option is an array
515
+		if (! is_array($espresso_db_update)) {
516
+			// if option is FALSE, then it never existed
517
+			if ($espresso_db_update === false) {
518
+				// make $espresso_db_update an array and save option with autoload OFF
519
+				$espresso_db_update = array();
520
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
521
+			} else {
522
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
523
+				$espresso_db_update = array($espresso_db_update => array());
524
+				update_option('espresso_db_update', $espresso_db_update);
525
+			}
526
+		} else {
527
+			$corrected_db_update = array();
528
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
529
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
530
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
531
+					//the key is an int, and the value IS NOT an array
532
+					//so it must be numerically-indexed, where values are versions installed...
533
+					//fix it!
534
+					$version_string                         = $should_be_array;
535
+					$corrected_db_update[ $version_string ] = array('unknown-date');
536
+				} else {
537
+					//ok it checks out
538
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
539
+				}
540
+			}
541
+			$espresso_db_update = $corrected_db_update;
542
+			update_option('espresso_db_update', $espresso_db_update);
543
+		}
544
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
545
+		return $espresso_db_update;
546
+	}
547
+
548
+
549
+
550
+	/**
551
+	 * Does the traditional work of setting up the plugin's database and adding default data.
552
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
553
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
554
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
555
+	 * so that it will be done when migrations are finished
556
+	 *
557
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
558
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
559
+	 *                                       This is a resource-intensive job
560
+	 *                                       so we prefer to only do it when necessary
561
+	 * @return void
562
+	 * @throws EE_Error
563
+	 */
564
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
565
+	{
566
+		$request_type = $this->detect_req_type();
567
+		//only initialize system if we're not in maintenance mode.
568
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
569
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
570
+			$rewrite_rules = $this->loader->getShared(
571
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
572
+			);
573
+			$rewrite_rules->flush();
574
+			if ($verify_schema) {
575
+				EEH_Activation::initialize_db_and_folders();
576
+			}
577
+			EEH_Activation::initialize_db_content();
578
+			EEH_Activation::system_initialization();
579
+			if ($initialize_addons_too) {
580
+				$this->initialize_addons();
581
+			}
582
+		} else {
583
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
584
+		}
585
+		if ($request_type === EE_System::req_type_new_activation
586
+			|| $request_type === EE_System::req_type_reactivation
587
+			|| (
588
+				$request_type === EE_System::req_type_upgrade
589
+				&& $this->is_major_version_change()
590
+			)
591
+		) {
592
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
593
+		}
594
+	}
595
+
596
+
597
+
598
+	/**
599
+	 * Initializes the db for all registered addons
600
+	 *
601
+	 * @throws EE_Error
602
+	 */
603
+	public function initialize_addons()
604
+	{
605
+		//foreach registered addon, make sure its db is up-to-date too
606
+		foreach ($this->registry->addons as $addon) {
607
+			if ($addon instanceof EE_Addon) {
608
+				$addon->initialize_db_if_no_migrations_required();
609
+			}
610
+		}
611
+	}
612
+
613
+
614
+
615
+	/**
616
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
617
+	 *
618
+	 * @param    array  $version_history
619
+	 * @param    string $current_version_to_add version to be added to the version history
620
+	 * @return    boolean success as to whether or not this option was changed
621
+	 */
622
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
623
+	{
624
+		if (! $version_history) {
625
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
626
+		}
627
+		if ($current_version_to_add === null) {
628
+			$current_version_to_add = espresso_version();
629
+		}
630
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
631
+		// re-save
632
+		return update_option('espresso_db_update', $version_history);
633
+	}
634
+
635
+
636
+
637
+	/**
638
+	 * Detects if the current version indicated in the has existed in the list of
639
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
640
+	 *
641
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
642
+	 *                                  If not supplied, fetches it from the options table.
643
+	 *                                  Also, caches its result so later parts of the code can also know whether
644
+	 *                                  there's been an update or not. This way we can add the current version to
645
+	 *                                  espresso_db_update, but still know if this is a new install or not
646
+	 * @return int one of the constants on EE_System::req_type_
647
+	 */
648
+	public function detect_req_type($espresso_db_update = null)
649
+	{
650
+		if ($this->_req_type === null) {
651
+			$espresso_db_update          = ! empty($espresso_db_update)
652
+				? $espresso_db_update
653
+				: $this->fix_espresso_db_upgrade_option();
654
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
655
+				$espresso_db_update,
656
+				'ee_espresso_activation', espresso_version()
657
+			);
658
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
659
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
660
+		}
661
+		return $this->_req_type;
662
+	}
663
+
664
+
665
+
666
+	/**
667
+	 * Returns whether or not there was a non-micro version change (ie, change in either
668
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
669
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
670
+	 *
671
+	 * @param $activation_history
672
+	 * @return bool
673
+	 */
674
+	private function _detect_major_version_change($activation_history)
675
+	{
676
+		$previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
677
+		$previous_version_parts = explode('.', $previous_version);
678
+		$current_version_parts  = explode('.', espresso_version());
679
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
680
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
681
+				   || $previous_version_parts[1] !== $current_version_parts[1]
682
+			   );
683
+	}
684
+
685
+
686
+
687
+	/**
688
+	 * Returns true if either the major or minor version of EE changed during this request.
689
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
690
+	 *
691
+	 * @return bool
692
+	 */
693
+	public function is_major_version_change()
694
+	{
695
+		return $this->_major_version_change;
696
+	}
697
+
698
+
699
+
700
+	/**
701
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
702
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
703
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
704
+	 * just activated to (for core that will always be espresso_version())
705
+	 *
706
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
707
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
708
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
709
+	 *                                                 indicate that this plugin was just activated
710
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
711
+	 *                                                 espresso_version())
712
+	 * @return int one of the constants on EE_System::req_type_*
713
+	 */
714
+	public static function detect_req_type_given_activation_history(
715
+		$activation_history_for_addon,
716
+		$activation_indicator_option_name,
717
+		$version_to_upgrade_to
718
+	) {
719
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
720
+		if ($activation_history_for_addon) {
721
+			//it exists, so this isn't a completely new install
722
+			//check if this version already in that list of previously installed versions
723
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
724
+				//it a version we haven't seen before
725
+				if ($version_is_higher === 1) {
726
+					$req_type = EE_System::req_type_upgrade;
727
+				} else {
728
+					$req_type = EE_System::req_type_downgrade;
729
+				}
730
+				delete_option($activation_indicator_option_name);
731
+			} else {
732
+				// its not an update. maybe a reactivation?
733
+				if (get_option($activation_indicator_option_name, false)) {
734
+					if ($version_is_higher === -1) {
735
+						$req_type = EE_System::req_type_downgrade;
736
+					} elseif ($version_is_higher === 0) {
737
+						//we've seen this version before, but it's an activation. must be a reactivation
738
+						$req_type = EE_System::req_type_reactivation;
739
+					} else {//$version_is_higher === 1
740
+						$req_type = EE_System::req_type_upgrade;
741
+					}
742
+					delete_option($activation_indicator_option_name);
743
+				} else {
744
+					//we've seen this version before and the activation indicate doesn't show it was just activated
745
+					if ($version_is_higher === -1) {
746
+						$req_type = EE_System::req_type_downgrade;
747
+					} elseif ($version_is_higher === 0) {
748
+						//we've seen this version before and it's not an activation. its normal request
749
+						$req_type = EE_System::req_type_normal;
750
+					} else {//$version_is_higher === 1
751
+						$req_type = EE_System::req_type_upgrade;
752
+					}
753
+				}
754
+			}
755
+		} else {
756
+			//brand new install
757
+			$req_type = EE_System::req_type_new_activation;
758
+			delete_option($activation_indicator_option_name);
759
+		}
760
+		return $req_type;
761
+	}
762
+
763
+
764
+
765
+	/**
766
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
767
+	 * the $activation_history_for_addon
768
+	 *
769
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
770
+	 *                                             sometimes containing 'unknown-date'
771
+	 * @param string $version_to_upgrade_to        (current version)
772
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
773
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
774
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
775
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
776
+	 */
777
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
778
+	{
779
+		//find the most recently-activated version
780
+		$most_recently_active_version =
781
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
782
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
783
+	}
784
+
785
+
786
+
787
+	/**
788
+	 * Gets the most recently active version listed in the activation history,
789
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
790
+	 *
791
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
792
+	 *                                   sometimes containing 'unknown-date'
793
+	 * @return string
794
+	 */
795
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
796
+	{
797
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
798
+		$most_recently_active_version            = '0.0.0.dev.000';
799
+		if (is_array($activation_history)) {
800
+			foreach ($activation_history as $version => $times_activated) {
801
+				//check there is a record of when this version was activated. Otherwise,
802
+				//mark it as unknown
803
+				if (! $times_activated) {
804
+					$times_activated = array('unknown-date');
805
+				}
806
+				if (is_string($times_activated)) {
807
+					$times_activated = array($times_activated);
808
+				}
809
+				foreach ($times_activated as $an_activation) {
810
+					if ($an_activation !== 'unknown-date'
811
+						&& $an_activation
812
+						   > $most_recently_active_version_activation) {
813
+						$most_recently_active_version            = $version;
814
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
815
+							? '1970-01-01 00:00:00'
816
+							: $an_activation;
817
+					}
818
+				}
819
+			}
820
+		}
821
+		return $most_recently_active_version;
822
+	}
823
+
824
+
825
+
826
+	/**
827
+	 * This redirects to the about EE page after activation
828
+	 *
829
+	 * @return void
830
+	 */
831
+	public function redirect_to_about_ee()
832
+	{
833
+		$notices = EE_Error::get_notices(false);
834
+		//if current user is an admin and it's not an ajax or rest request
835
+		if (
836
+			! isset($notices['errors'])
837
+			&& $this->request->isAdmin()
838
+			&& apply_filters(
839
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
840
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
841
+			)
842
+		) {
843
+			$query_params = array('page' => 'espresso_about');
844
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
845
+				$query_params['new_activation'] = true;
846
+			}
847
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
848
+				$query_params['reactivation'] = true;
849
+			}
850
+			$url = add_query_arg($query_params, admin_url('admin.php'));
851
+			wp_safe_redirect($url);
852
+			exit();
853
+		}
854
+	}
855
+
856
+
857
+
858
+	/**
859
+	 * load_core_configuration
860
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
861
+	 * which runs during the WP 'plugins_loaded' action at priority 5
862
+	 *
863
+	 * @return void
864
+	 * @throws ReflectionException
865
+	 */
866
+	public function load_core_configuration()
867
+	{
868
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
869
+		$this->loader->getShared('EE_Load_Textdomain');
870
+		//load textdomain
871
+		EE_Load_Textdomain::load_textdomain();
872
+		// load and setup EE_Config and EE_Network_Config
873
+		$config = $this->loader->getShared('EE_Config');
874
+		$this->loader->getShared('EE_Network_Config');
875
+		// setup autoloaders
876
+		// enable logging?
877
+		if ($config->admin->use_full_logging) {
878
+			$this->loader->getShared('EE_Log');
879
+		}
880
+		// check for activation errors
881
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
882
+		if ($activation_errors) {
883
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
884
+			update_option('ee_plugin_activation_errors', false);
885
+		}
886
+		// get model names
887
+		$this->_parse_model_names();
888
+		//load caf stuff a chance to play during the activation process too.
889
+		$this->_maybe_brew_regular();
890
+		// configure custom post type definitions
891
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
892
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
893
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
894
+	}
895
+
896
+
897
+
898
+	/**
899
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
900
+	 *
901
+	 * @return void
902
+	 * @throws ReflectionException
903
+	 */
904
+	private function _parse_model_names()
905
+	{
906
+		//get all the files in the EE_MODELS folder that end in .model.php
907
+		$models                 = glob(EE_MODELS . '*.model.php');
908
+		$model_names            = array();
909
+		$non_abstract_db_models = array();
910
+		foreach ($models as $model) {
911
+			// get model classname
912
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
913
+			$short_name      = str_replace('EEM_', '', $classname);
914
+			$reflectionClass = new ReflectionClass($classname);
915
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
916
+				$non_abstract_db_models[ $short_name ] = $classname;
917
+			}
918
+			$model_names[ $short_name ] = $classname;
919
+		}
920
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
921
+		$this->registry->non_abstract_db_models = apply_filters(
922
+			'FHEE__EE_System__parse_implemented_model_names',
923
+			$non_abstract_db_models
924
+		);
925
+	}
926
+
927
+
928
+	/**
929
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
930
+	 * that need to be setup before our EE_System launches.
931
+	 *
932
+	 * @return void
933
+	 * @throws DomainException
934
+	 * @throws InvalidArgumentException
935
+	 * @throws InvalidDataTypeException
936
+	 * @throws InvalidInterfaceException
937
+	 * @throws InvalidClassException
938
+	 * @throws InvalidFilePathException
939
+	 */
940
+	private function _maybe_brew_regular()
941
+	{
942
+		/** @var Domain $domain */
943
+		$domain = DomainFactory::getShared(
944
+			new FullyQualifiedName(
945
+				'EventEspresso\core\domain\Domain'
946
+			),
947
+			array(
948
+				new FilePath(EVENT_ESPRESSO_MAIN_FILE),
949
+				Version::fromString(espresso_version())
950
+			)
951
+		);
952
+		if ($domain->isCaffeinated()) {
953
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
954
+		}
955
+	}
956
+
957
+
958
+
959
+	/**
960
+	 * register_shortcodes_modules_and_widgets
961
+	 * generate lists of shortcodes and modules, then verify paths and classes
962
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
963
+	 * which runs during the WP 'plugins_loaded' action at priority 7
964
+	 *
965
+	 * @access public
966
+	 * @return void
967
+	 * @throws Exception
968
+	 */
969
+	public function register_shortcodes_modules_and_widgets()
970
+	{
971
+		try {
972
+			// load, register, and add shortcodes the new way
973
+			if ($this->request->isFrontend() || $this->request->isIframe()) {
974
+				$this->loader->getShared(
975
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
976
+					array(
977
+						// and the old way, but we'll put it under control of the new system
978
+						EE_Config::getLegacyShortcodesManager(),
979
+					)
980
+				);
981
+			}
982
+			if (function_exists('register_block_type')) {
983
+				// or the even newer newer new way
984
+				if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
985
+					$this->loader->getShared(
986
+						'EventEspresso\core\services\editor\BlockRegistrationManager'
987
+					);
988
+				}
989
+				if ($this->request->isAdmin()) {
990
+					$this->loader->getShared(
991
+						'EventEspresso\core\services\editor\EspressoGutenbergEditor',
992
+						array($editor_block_collection, $this->request)
993
+					);
994
+				}
995
+			}
996
+		} catch (Exception $exception) {
997
+			new ExceptionStackTraceDisplay($exception);
998
+		}
999
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
1000
+		// check for addons using old hook point
1001
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
1002
+			$this->_incompatible_addon_error();
1003
+		}
1004
+	}
1005
+
1006
+
1007
+
1008
+	/**
1009
+	 * _incompatible_addon_error
1010
+	 *
1011
+	 * @access public
1012
+	 * @return void
1013
+	 */
1014
+	private function _incompatible_addon_error()
1015
+	{
1016
+		// get array of classes hooking into here
1017
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1018
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
1019
+		);
1020
+		if (! empty($class_names)) {
1021
+			$msg = __(
1022
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1023
+				'event_espresso'
1024
+			);
1025
+			$msg .= '<ul>';
1026
+			foreach ($class_names as $class_name) {
1027
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
1028
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1029
+						$class_name
1030
+					) . '</b></li>';
1031
+			}
1032
+			$msg .= '</ul>';
1033
+			$msg .= __(
1034
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1035
+				'event_espresso'
1036
+			);
1037
+			// save list of incompatible addons to wp-options for later use
1038
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1039
+			if (is_admin()) {
1040
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1041
+			}
1042
+		}
1043
+	}
1044
+
1045
+
1046
+
1047
+	/**
1048
+	 * brew_espresso
1049
+	 * begins the process of setting hooks for initializing EE in the correct order
1050
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1051
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1052
+	 *
1053
+	 * @return void
1054
+	 */
1055
+	public function brew_espresso()
1056
+	{
1057
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1058
+		// load some final core systems
1059
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1060
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1061
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1062
+		add_action('init', array($this, 'load_controllers'), 7);
1063
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1064
+		add_action('init', array($this, 'initialize'), 10);
1065
+		add_action('init', array($this, 'initialize_last'), 100);
1066
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1067
+			// pew pew pew
1068
+			$this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1069
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1070
+		}
1071
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1072
+	}
1073
+
1074
+
1075
+
1076
+	/**
1077
+	 *    set_hooks_for_core
1078
+	 *
1079
+	 * @access public
1080
+	 * @return    void
1081
+	 * @throws EE_Error
1082
+	 */
1083
+	public function set_hooks_for_core()
1084
+	{
1085
+		$this->_deactivate_incompatible_addons();
1086
+		do_action('AHEE__EE_System__set_hooks_for_core');
1087
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1088
+		//caps need to be initialized on every request so that capability maps are set.
1089
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1090
+		$this->registry->CAP->init_caps();
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1097
+	 * deactivates any addons considered incompatible with the current version of EE
1098
+	 */
1099
+	private function _deactivate_incompatible_addons()
1100
+	{
1101
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1102
+		if (! empty($incompatible_addons)) {
1103
+			$active_plugins = get_option('active_plugins', array());
1104
+			foreach ($active_plugins as $active_plugin) {
1105
+				foreach ($incompatible_addons as $incompatible_addon) {
1106
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1107
+						unset($_GET['activate']);
1108
+						espresso_deactivate_plugin($active_plugin);
1109
+					}
1110
+				}
1111
+			}
1112
+		}
1113
+	}
1114
+
1115
+
1116
+
1117
+	/**
1118
+	 *    perform_activations_upgrades_and_migrations
1119
+	 *
1120
+	 * @access public
1121
+	 * @return    void
1122
+	 */
1123
+	public function perform_activations_upgrades_and_migrations()
1124
+	{
1125
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1126
+	}
1127
+
1128
+
1129
+	/**
1130
+	 * @return void
1131
+	 * @throws DomainException
1132
+	 */
1133
+	public function load_CPTs_and_session()
1134
+	{
1135
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1136
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1137
+		$register_custom_taxonomies = $this->loader->getShared(
1138
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1139
+		);
1140
+		$register_custom_taxonomies->registerCustomTaxonomies();
1141
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1142
+		$register_custom_post_types = $this->loader->getShared(
1143
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1144
+		);
1145
+		$register_custom_post_types->registerCustomPostTypes();
1146
+		// register Custom Post Types and Taxonomies
1147
+		$this->loader->getShared('EE_Register_CPTs');
1148
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1149
+	}
1150
+
1151
+
1152
+
1153
+	/**
1154
+	 * load_controllers
1155
+	 * this is the best place to load any additional controllers that needs access to EE core.
1156
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1157
+	 * time
1158
+	 *
1159
+	 * @access public
1160
+	 * @return void
1161
+	 */
1162
+	public function load_controllers()
1163
+	{
1164
+		do_action('AHEE__EE_System__load_controllers__start');
1165
+		// let's get it started
1166
+		if (
1167
+			! $this->maintenance_mode->level()
1168
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1169
+		) {
1170
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1171
+			$this->loader->getShared('EE_Front_Controller');
1172
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1173
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1174
+			$this->loader->getShared('EE_Admin');
1175
+		}
1176
+		do_action('AHEE__EE_System__load_controllers__complete');
1177
+	}
1178
+
1179
+
1180
+
1181
+	/**
1182
+	 * core_loaded_and_ready
1183
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1184
+	 *
1185
+	 * @access public
1186
+	 * @return void
1187
+	 */
1188
+	public function core_loaded_and_ready()
1189
+	{
1190
+		if (
1191
+			$this->request->isAdmin()
1192
+			|| $this->request->isEeAjax()
1193
+			|| $this->request->isFrontend()
1194
+		) {
1195
+			$this->loader->getShared('EE_Session');
1196
+		}
1197
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1198
+		// load_espresso_template_tags
1199
+		if (
1200
+			is_readable(EE_PUBLIC . 'template_tags.php')
1201
+			&& (
1202
+				$this->request->isFrontend()
1203
+				|| $this->request->isAdmin()
1204
+				|| $this->request->isIframe()
1205
+				|| $this->request->isFeed()
1206
+			)
1207
+		) {
1208
+			require_once EE_PUBLIC . 'template_tags.php';
1209
+		}
1210
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1211
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1212
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1213
+		}
1214
+	}
1215
+
1216
+
1217
+
1218
+	/**
1219
+	 * initialize
1220
+	 * this is the best place to begin initializing client code
1221
+	 *
1222
+	 * @access public
1223
+	 * @return void
1224
+	 */
1225
+	public function initialize()
1226
+	{
1227
+		do_action('AHEE__EE_System__initialize');
1228
+	}
1229
+
1230
+
1231
+
1232
+	/**
1233
+	 * initialize_last
1234
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1235
+	 * initialize has done so
1236
+	 *
1237
+	 * @access public
1238
+	 * @return void
1239
+	 */
1240
+	public function initialize_last()
1241
+	{
1242
+		do_action('AHEE__EE_System__initialize_last');
1243
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1244
+		$rewrite_rules = $this->loader->getShared(
1245
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1246
+		);
1247
+		$rewrite_rules->flushRewriteRules();
1248
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1249
+	}
1250
+
1251
+
1252
+
1253
+	/**
1254
+	 * @return void
1255
+	 * @throws EE_Error
1256
+	 */
1257
+	public function addEspressoToolbar()
1258
+	{
1259
+		$this->loader->getShared(
1260
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1261
+			array($this->registry->CAP)
1262
+		);
1263
+	}
1264
+
1265
+
1266
+
1267
+	/**
1268
+	 * do_not_cache
1269
+	 * sets no cache headers and defines no cache constants for WP plugins
1270
+	 *
1271
+	 * @access public
1272
+	 * @return void
1273
+	 */
1274
+	public static function do_not_cache()
1275
+	{
1276
+		// set no cache constants
1277
+		if (! defined('DONOTCACHEPAGE')) {
1278
+			define('DONOTCACHEPAGE', true);
1279
+		}
1280
+		if (! defined('DONOTCACHCEOBJECT')) {
1281
+			define('DONOTCACHCEOBJECT', true);
1282
+		}
1283
+		if (! defined('DONOTCACHEDB')) {
1284
+			define('DONOTCACHEDB', true);
1285
+		}
1286
+		// add no cache headers
1287
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1288
+		// plus a little extra for nginx and Google Chrome
1289
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1290
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1291
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1292
+	}
1293
+
1294
+
1295
+
1296
+	/**
1297
+	 *    extra_nocache_headers
1298
+	 *
1299
+	 * @access    public
1300
+	 * @param $headers
1301
+	 * @return    array
1302
+	 */
1303
+	public static function extra_nocache_headers($headers)
1304
+	{
1305
+		// for NGINX
1306
+		$headers['X-Accel-Expires'] = 0;
1307
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1308
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1309
+		return $headers;
1310
+	}
1311
+
1312
+
1313
+
1314
+	/**
1315
+	 *    nocache_headers
1316
+	 *
1317
+	 * @access    public
1318
+	 * @return    void
1319
+	 */
1320
+	public static function nocache_headers()
1321
+	{
1322
+		nocache_headers();
1323
+	}
1324
+
1325
+
1326
+
1327
+	/**
1328
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1329
+	 * never returned with the function.
1330
+	 *
1331
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1332
+	 * @return array
1333
+	 */
1334
+	public function remove_pages_from_wp_list_pages($exclude_array)
1335
+	{
1336
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1337
+	}
1338 1338
 
1339 1339
 
1340 1340
 
Please login to merge, or discard this patch.
modules/ticket_selector/ProcessTicketSelector.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -473,7 +473,7 @@
 block discarded – undo
473 473
      *
474 474
      * @param EE_Ticket $ticket
475 475
      * @param int        $qty
476
-     * @return TRUE on success, FALSE on fail
476
+     * @return boolean on success, FALSE on fail
477 477
      * @throws InvalidArgumentException
478 478
      * @throws InvalidInterfaceException
479 479
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +520 added lines, -520 removed lines patch added patch discarded remove patch
@@ -34,526 +34,526 @@
 block discarded – undo
34 34
 class ProcessTicketSelector
35 35
 {
36 36
 
37
-    /**
38
-     * @var EE_Cart $cart
39
-     */
40
-    private $cart;
41
-
42
-    /**
43
-     * @var EE_Core_Config $core_config
44
-     */
45
-    private $core_config;
46
-
47
-    /**
48
-     * @var Request $request
49
-     */
50
-    private $request;
51
-
52
-    /**
53
-     * @var EE_Session $session
54
-     */
55
-    private $session;
56
-
57
-    /**
58
-     * @var EEM_Ticket $ticket_model
59
-     */
60
-    private $ticket_model;
61
-
62
-    /**
63
-     * @var TicketDatetimeAvailabilityTracker $tracker
64
-     */
65
-    private $tracker;
66
-
67
-
68
-    /**
69
-     * ProcessTicketSelector constructor.
70
-     * NOTE: PLZ use the Loader to instantiate this class if need be
71
-     * so that all dependencies get injected correctly (which will happen automatically)
72
-     * Null values for parameters are only for backwards compatibility but will be removed later on.
73
-     *
74
-     * @param EE_Core_Config                    $core_config
75
-     * @param Request                           $request
76
-     * @param EE_Session                        $session
77
-     * @param EEM_Ticket                        $ticket_model
78
-     * @param TicketDatetimeAvailabilityTracker $tracker
79
-     * @throws InvalidArgumentException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     */
83
-    public function __construct(
84
-        EE_Core_Config $core_config = null,
85
-        Request $request = null,
86
-        EE_Session $session = null,
87
-        EEM_Ticket $ticket_model = null,
88
-        TicketDatetimeAvailabilityTracker $tracker = null
89
-    ) {
90
-        /** @var LoaderInterface $loader */
91
-        $loader             = LoaderFactory::getLoader();
92
-        $this->core_config  = $core_config instanceof EE_Core_Config
93
-            ? $core_config
94
-            : $loader->getShared('EE_Core_Config');
95
-        $this->request      = $request instanceof Request
96
-            ? $request
97
-            : $loader->getShared('EventEspresso\core\services\request\Request');
98
-        $this->session      = $session instanceof EE_Session
99
-            ? $session
100
-            : $loader->getShared('EE_Session');
101
-        $this->ticket_model = $ticket_model instanceof EEM_Ticket
102
-            ? $ticket_model
103
-            : $loader->getShared('EEM_Ticket');
104
-        $this->tracker      = $tracker instanceof TicketDatetimeAvailabilityTracker
105
-            ? $tracker
106
-            : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
107
-    }
108
-
109
-
110
-    /**
111
-     * cancelTicketSelections
112
-     *
113
-     * @return bool
114
-     * @throws EE_Error
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidInterfaceException
117
-     * @throws InvalidDataTypeException
118
-     */
119
-    public function cancelTicketSelections()
120
-    {
121
-        // check nonce
122
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
123
-            return false;
124
-        }
125
-        $this->session->clear_session(__CLASS__, __FUNCTION__);
126
-        if ($this->request->requestParamIsSet('event_id')) {
127
-            EEH_URL::safeRedirectAndExit(
128
-                EEH_Event_View::event_link_url(
129
-                    $this->request->getRequestParam('event_id')
130
-                )
131
-            );
132
-        }
133
-        EEH_URL::safeRedirectAndExit(
134
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
135
-        );
136
-        return true;
137
-    }
138
-
139
-
140
-    /**
141
-     * processTicketSelectorNonce
142
-     *
143
-     * @param  string $nonce_name
144
-     * @param string  $id
145
-     * @return bool
146
-     */
147
-    private function processTicketSelectorNonce($nonce_name, $id = '')
148
-    {
149
-        $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
150
-        if (
151
-            ! $this->request->isAdmin()
152
-            && (
153
-                ! $this->request->is_set($nonce_name_with_id)
154
-                || ! wp_verify_nonce(
155
-                    $this->request->get($nonce_name_with_id),
156
-                    $nonce_name
157
-                )
158
-            )
159
-        ) {
160
-            EE_Error::add_error(
161
-                sprintf(
162
-                    esc_html__(
163
-                        'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
164
-                        'event_espresso'
165
-                    ),
166
-                    '<br/>'
167
-                ),
168
-                __FILE__,
169
-                __FUNCTION__,
170
-                __LINE__
171
-            );
172
-            return false;
173
-        }
174
-        return true;
175
-    }
176
-
177
-
178
-    /**
179
-     * process_ticket_selections
180
-     *
181
-     * @return array|bool
182
-     * @throws EE_Error
183
-     * @throws InvalidArgumentException
184
-     * @throws InvalidDataTypeException
185
-     * @throws InvalidInterfaceException
186
-     */
187
-    public function processTicketSelections()
188
-    {
189
-        do_action('EED_Ticket_Selector__process_ticket_selections__before');
190
-        if($this->request->isBot()) {
191
-            EEH_URL::safeRedirectAndExit(
192
-                apply_filters(
193
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
194
-                    site_url()
195
-                )
196
-            );
197
-        }
198
-        // do we have an event id?
199
-        $id = $this->getEventId();
200
-        // we should really only have 1 registration in the works now
201
-        // (ie, no MER) so unless otherwise requested, clear the session
202
-        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
203
-            $this->session->clear_session(__CLASS__, __FUNCTION__);
204
-        }
205
-        // validate/sanitize/filter data
206
-        $valid = apply_filters(
207
-            'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
208
-            $this->validatePostData($id)
209
-        );
210
-        //check total tickets ordered vs max number of attendees that can register
211
-        if ($valid['total_tickets'] > $valid['max_atndz']) {
212
-            $this->maxAttendeesViolation($valid);
213
-        } else {
214
-            // all data appears to be valid
215
-            if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
216
-                return true;
217
-            }
218
-        }
219
-        // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
220
-        // at this point, just return if registration is being made from admin
221
-        if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
222
-            return false;
223
-        }
224
-        if ($valid['return_url']) {
225
-            EEH_URL::safeRedirectAndExit($valid['return_url']);
226
-        }
227
-        if ($id) {
228
-            EEH_URL::safeRedirectAndExit(get_permalink($id));
229
-        }
230
-        echo EE_Error::get_notices();
231
-        return false;
232
-    }
233
-
234
-
235
-    /**
236
-     * @return int
237
-     */
238
-    private function getEventId()
239
-    {
240
-        // do we have an event id?
241
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
242
-            // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
243
-            EE_Error::add_error(
244
-                sprintf(
245
-                    esc_html__(
246
-                        'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
247
-                        'event_espresso'
248
-                    ),
249
-                    '<br/>'
250
-                ),
251
-                __FILE__,
252
-                __FUNCTION__,
253
-                __LINE__
254
-            );
255
-        }
256
-        //if event id is valid
257
-        return absint($this->request->getRequestParam('tkt-slctr-event-id'));
258
-    }
259
-
260
-
261
-    /**
262
-     * validate_post_data
263
-     *
264
-     * @param int $id
265
-     * @return array|FALSE
266
-     */
267
-    private function validatePostData($id = 0)
268
-    {
269
-        if (! $id) {
270
-            EE_Error::add_error(
271
-                esc_html__('The event id provided was not valid.', 'event_espresso'),
272
-                __FILE__,
273
-                __FUNCTION__,
274
-                __LINE__
275
-            );
276
-            return false;
277
-        }
278
-        // start with an empty array()
279
-        $valid_data = array();
280
-        // grab valid id
281
-        $valid_data['id'] = $id;
282
-        // array of other form names
283
-        $inputs_to_clean = array(
284
-            'event_id'   => 'tkt-slctr-event-id',
285
-            'max_atndz'  => 'tkt-slctr-max-atndz-',
286
-            'rows'       => 'tkt-slctr-rows-',
287
-            'qty'        => 'tkt-slctr-qty-',
288
-            'ticket_id'  => 'tkt-slctr-ticket-id-',
289
-            'return_url' => 'tkt-slctr-return-url-',
290
-        );
291
-        // let's track the total number of tickets ordered.'
292
-        $valid_data['total_tickets'] = 0;
293
-        // cycle through $inputs_to_clean array
294
-        foreach ($inputs_to_clean as $what => $input_to_clean) {
295
-            // check for POST data
296
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
297
-                // grab value
298
-                $input_value = $this->request->getRequestParam($input_to_clean . $id);
299
-                switch ($what) {
300
-                    // integers
301
-                    case 'event_id':
302
-                        $valid_data[ $what ] = absint($input_value);
303
-                        // get event via the event id we put in the form
304
-                        break;
305
-                    case 'rows':
306
-                    case 'max_atndz':
307
-                        $valid_data[ $what ] = absint($input_value);
308
-                        break;
309
-                    // arrays of integers
310
-                    case 'qty':
311
-                        /** @var array $row_qty */
312
-                        $row_qty = $input_value;
313
-                        // if qty is coming from a radio button input, then we need to assemble an array of rows
314
-                        if (! is_array($row_qty)) {
315
-                            /** @var string $row_qty */
316
-                            // get number of rows
317
-                            $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id)
318
-                                ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id))
319
-                                : 1;
320
-                            // explode integers by the dash
321
-                            $row_qty = explode('-', $row_qty);
322
-                            $row     = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
323
-                            $qty     = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
324
-                            $row_qty = array($row => $qty);
325
-                            for ($x = 1; $x <= $rows; $x++) {
326
-                                if (! isset($row_qty[ $x ])) {
327
-                                    $row_qty[ $x ] = 0;
328
-                                }
329
-                            }
330
-                        }
331
-                        ksort($row_qty);
332
-                        // cycle thru values
333
-                        foreach ($row_qty as $qty) {
334
-                            $qty = absint($qty);
335
-                            // sanitize as integers
336
-                            $valid_data[ $what ][]       = $qty;
337
-                            $valid_data['total_tickets'] += $qty;
338
-                        }
339
-                        break;
340
-                    // array of integers
341
-                    case 'ticket_id':
342
-                        // cycle thru values
343
-                        foreach ((array) $input_value as $key => $value) {
344
-                            // allow only integers
345
-                            $valid_data[ $what ][ $key ] = absint($value);
346
-                        }
347
-                        break;
348
-                    case 'return_url' :
349
-                        // grab and sanitize return-url
350
-                        $input_value = esc_url_raw($input_value);
351
-                        // was the request coming from an iframe ? if so, then:
352
-                        if (strpos($input_value, 'event_list=iframe')) {
353
-                            // get anchor fragment
354
-                            $input_value = explode('#', $input_value);
355
-                            $input_value = end($input_value);
356
-                            // use event list url instead, but append anchor
357
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
358
-                        }
359
-                        $valid_data[ $what ] = $input_value;
360
-                        break;
361
-                }    // end switch $what
362
-            }
363
-        }    // end foreach $inputs_to_clean
364
-        return $valid_data;
365
-    }
366
-
367
-
368
-    /**
369
-     * @param array $valid
370
-     */
371
-    private function maxAttendeesViolation(array $valid)
372
-    {
373
-        // ordering too many tickets !!!
374
-        $total_tickets_string = esc_html(
375
-            _n(
376
-                'You have attempted to purchase %s ticket.',
377
-                'You have attempted to purchase %s tickets.',
378
-                $valid['total_tickets'],
379
-                'event_espresso'
380
-            )
381
-        );
382
-        $limit_error_1        = sprintf($total_tickets_string, $valid['total_tickets']);
383
-        // dev only message
384
-        $max_attendees_string = esc_html(
385
-            _n(
386
-                'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
387
-                'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
388
-                $valid['max_atndz'],
389
-                'event_espresso'
390
-            )
391
-        );
392
-        $limit_error_2    = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
393
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
394
-    }
395
-
396
-
397
-    /**
398
-     * @param array $valid
399
-     * @return int|TRUE
400
-     * @throws EE_Error
401
-     * @throws InvalidArgumentException
402
-     * @throws InvalidDataTypeException
403
-     * @throws InvalidInterfaceException
404
-     */
405
-    private function addTicketsToCart(array $valid)
406
-    {
407
-        $tickets_added = 0;
408
-        $tickets_selected = false;
409
-        if($valid['total_tickets'] > 0){
410
-            // load cart using factory because we don't want to do so until actually needed
411
-            $this->cart = CartFactory::getCart();
412
-            // cycle thru the number of data rows sent from the event listing
413
-            for ($x = 0; $x < $valid['rows']; $x++) {
414
-                // does this row actually contain a ticket quantity?
415
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
416
-                    // YES we have a ticket quantity
417
-                    $tickets_selected = true;
418
-                    $valid_ticket     = false;
419
-                    // \EEH_Debug_Tools::printr(
420
-                    //     $valid['ticket_id'][ $x ],
421
-                    //     '$valid[\'ticket_id\'][ $x ]',
422
-                    //     __FILE__, __LINE__
423
-                    // );
424
-                    if (isset($valid['ticket_id'][ $x ])) {
425
-                        // get ticket via the ticket id we put in the form
426
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
427
-                        if ($ticket instanceof EE_Ticket) {
428
-                            $valid_ticket  = true;
429
-                            $tickets_added += $this->addTicketToCart(
430
-                                $ticket,
431
-                                $valid['qty'][ $x ]
432
-                            );
433
-                        }
434
-                    }
435
-                    if ($valid_ticket !== true) {
436
-                        // nothing added to cart retrieved
437
-                        EE_Error::add_error(
438
-                            sprintf(
439
-                                esc_html__(
440
-                                    'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
441
-                                    'event_espresso'
442
-                                ),
443
-                                '<br/>'
444
-                            ),
445
-                            __FILE__, __FUNCTION__, __LINE__
446
-                        );
447
-                    }
448
-                    if (EE_Error::has_error()) {
449
-                        break;
450
-                    }
451
-                }
452
-            }
453
-        }
454
-        do_action(
455
-            'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
456
-            $this->cart,
457
-            $this
458
-        );
459
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
460
-            // no ticket quantities were selected
461
-            EE_Error::add_error(
462
-                esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
463
-                __FILE__, __FUNCTION__, __LINE__
464
-            );
465
-        }
466
-        return $tickets_added;
467
-    }
468
-
469
-
470
-
471
-    /**
472
-     * adds a ticket to the cart
473
-     *
474
-     * @param EE_Ticket $ticket
475
-     * @param int        $qty
476
-     * @return TRUE on success, FALSE on fail
477
-     * @throws InvalidArgumentException
478
-     * @throws InvalidInterfaceException
479
-     * @throws InvalidDataTypeException
480
-     * @throws EE_Error
481
-     */
482
-    private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
483
-    {
484
-        // get the number of spaces left for this datetime ticket
485
-        $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
486
-        // compare available spaces against the number of tickets being purchased
487
-        if ($available_spaces >= $qty) {
488
-            // allow addons to prevent a ticket from being added to cart
489
-            if (
490
-                ! apply_filters(
491
-                    'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
492
-                    true,
493
-                    $ticket,
494
-                    $qty,
495
-                    $available_spaces
496
-                )
497
-            ) {
498
-                return false;
499
-            }
500
-            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
501
-            // add event to cart
502
-            if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
503
-                $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
504
-                return true;
505
-            }
506
-            return false;
507
-        }
508
-        $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
509
-        return false;
510
-    }
511
-
512
-
513
-    /**
514
-     * @param $tickets_added
515
-     * @return bool
516
-     * @throws InvalidInterfaceException
517
-     * @throws InvalidDataTypeException
518
-     * @throws EE_Error
519
-     * @throws InvalidArgumentException
520
-     */
521
-    private function processSuccessfulCart($tickets_added)
522
-    {
523
-        // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
524
-        if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
525
-            // make sure cart is loaded
526
-            if(! $this->cart  instanceof EE_Cart){
527
-                $this->cart = CartFactory::getCart();
528
-            }
529
-            do_action(
530
-                'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
531
-                $this->cart,
532
-                $this
533
-            );
534
-            $this->cart->recalculate_all_cart_totals();
535
-            $this->cart->save_cart(false);
536
-            // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
537
-            // just return TRUE for registrations being made from admin
538
-            if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
539
-                return true;
540
-            }
541
-            EEH_URL::safeRedirectAndExit(
542
-                apply_filters(
543
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
544
-                    $this->core_config->reg_page_url()
545
-                )
546
-            );
547
-        }
548
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
549
-            // nothing added to cart
550
-            EE_Error::add_attention(
551
-                esc_html__('No tickets were added for the event', 'event_espresso'),
552
-                __FILE__, __FUNCTION__, __LINE__
553
-            );
554
-        }
555
-        return false;
556
-    }
37
+	/**
38
+	 * @var EE_Cart $cart
39
+	 */
40
+	private $cart;
41
+
42
+	/**
43
+	 * @var EE_Core_Config $core_config
44
+	 */
45
+	private $core_config;
46
+
47
+	/**
48
+	 * @var Request $request
49
+	 */
50
+	private $request;
51
+
52
+	/**
53
+	 * @var EE_Session $session
54
+	 */
55
+	private $session;
56
+
57
+	/**
58
+	 * @var EEM_Ticket $ticket_model
59
+	 */
60
+	private $ticket_model;
61
+
62
+	/**
63
+	 * @var TicketDatetimeAvailabilityTracker $tracker
64
+	 */
65
+	private $tracker;
66
+
67
+
68
+	/**
69
+	 * ProcessTicketSelector constructor.
70
+	 * NOTE: PLZ use the Loader to instantiate this class if need be
71
+	 * so that all dependencies get injected correctly (which will happen automatically)
72
+	 * Null values for parameters are only for backwards compatibility but will be removed later on.
73
+	 *
74
+	 * @param EE_Core_Config                    $core_config
75
+	 * @param Request                           $request
76
+	 * @param EE_Session                        $session
77
+	 * @param EEM_Ticket                        $ticket_model
78
+	 * @param TicketDatetimeAvailabilityTracker $tracker
79
+	 * @throws InvalidArgumentException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 */
83
+	public function __construct(
84
+		EE_Core_Config $core_config = null,
85
+		Request $request = null,
86
+		EE_Session $session = null,
87
+		EEM_Ticket $ticket_model = null,
88
+		TicketDatetimeAvailabilityTracker $tracker = null
89
+	) {
90
+		/** @var LoaderInterface $loader */
91
+		$loader             = LoaderFactory::getLoader();
92
+		$this->core_config  = $core_config instanceof EE_Core_Config
93
+			? $core_config
94
+			: $loader->getShared('EE_Core_Config');
95
+		$this->request      = $request instanceof Request
96
+			? $request
97
+			: $loader->getShared('EventEspresso\core\services\request\Request');
98
+		$this->session      = $session instanceof EE_Session
99
+			? $session
100
+			: $loader->getShared('EE_Session');
101
+		$this->ticket_model = $ticket_model instanceof EEM_Ticket
102
+			? $ticket_model
103
+			: $loader->getShared('EEM_Ticket');
104
+		$this->tracker      = $tracker instanceof TicketDatetimeAvailabilityTracker
105
+			? $tracker
106
+			: $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
107
+	}
108
+
109
+
110
+	/**
111
+	 * cancelTicketSelections
112
+	 *
113
+	 * @return bool
114
+	 * @throws EE_Error
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidInterfaceException
117
+	 * @throws InvalidDataTypeException
118
+	 */
119
+	public function cancelTicketSelections()
120
+	{
121
+		// check nonce
122
+		if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
123
+			return false;
124
+		}
125
+		$this->session->clear_session(__CLASS__, __FUNCTION__);
126
+		if ($this->request->requestParamIsSet('event_id')) {
127
+			EEH_URL::safeRedirectAndExit(
128
+				EEH_Event_View::event_link_url(
129
+					$this->request->getRequestParam('event_id')
130
+				)
131
+			);
132
+		}
133
+		EEH_URL::safeRedirectAndExit(
134
+			site_url('/' . $this->core_config->event_cpt_slug . '/')
135
+		);
136
+		return true;
137
+	}
138
+
139
+
140
+	/**
141
+	 * processTicketSelectorNonce
142
+	 *
143
+	 * @param  string $nonce_name
144
+	 * @param string  $id
145
+	 * @return bool
146
+	 */
147
+	private function processTicketSelectorNonce($nonce_name, $id = '')
148
+	{
149
+		$nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
150
+		if (
151
+			! $this->request->isAdmin()
152
+			&& (
153
+				! $this->request->is_set($nonce_name_with_id)
154
+				|| ! wp_verify_nonce(
155
+					$this->request->get($nonce_name_with_id),
156
+					$nonce_name
157
+				)
158
+			)
159
+		) {
160
+			EE_Error::add_error(
161
+				sprintf(
162
+					esc_html__(
163
+						'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
164
+						'event_espresso'
165
+					),
166
+					'<br/>'
167
+				),
168
+				__FILE__,
169
+				__FUNCTION__,
170
+				__LINE__
171
+			);
172
+			return false;
173
+		}
174
+		return true;
175
+	}
176
+
177
+
178
+	/**
179
+	 * process_ticket_selections
180
+	 *
181
+	 * @return array|bool
182
+	 * @throws EE_Error
183
+	 * @throws InvalidArgumentException
184
+	 * @throws InvalidDataTypeException
185
+	 * @throws InvalidInterfaceException
186
+	 */
187
+	public function processTicketSelections()
188
+	{
189
+		do_action('EED_Ticket_Selector__process_ticket_selections__before');
190
+		if($this->request->isBot()) {
191
+			EEH_URL::safeRedirectAndExit(
192
+				apply_filters(
193
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
194
+					site_url()
195
+				)
196
+			);
197
+		}
198
+		// do we have an event id?
199
+		$id = $this->getEventId();
200
+		// we should really only have 1 registration in the works now
201
+		// (ie, no MER) so unless otherwise requested, clear the session
202
+		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
203
+			$this->session->clear_session(__CLASS__, __FUNCTION__);
204
+		}
205
+		// validate/sanitize/filter data
206
+		$valid = apply_filters(
207
+			'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
208
+			$this->validatePostData($id)
209
+		);
210
+		//check total tickets ordered vs max number of attendees that can register
211
+		if ($valid['total_tickets'] > $valid['max_atndz']) {
212
+			$this->maxAttendeesViolation($valid);
213
+		} else {
214
+			// all data appears to be valid
215
+			if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
216
+				return true;
217
+			}
218
+		}
219
+		// die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
220
+		// at this point, just return if registration is being made from admin
221
+		if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
222
+			return false;
223
+		}
224
+		if ($valid['return_url']) {
225
+			EEH_URL::safeRedirectAndExit($valid['return_url']);
226
+		}
227
+		if ($id) {
228
+			EEH_URL::safeRedirectAndExit(get_permalink($id));
229
+		}
230
+		echo EE_Error::get_notices();
231
+		return false;
232
+	}
233
+
234
+
235
+	/**
236
+	 * @return int
237
+	 */
238
+	private function getEventId()
239
+	{
240
+		// do we have an event id?
241
+		if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
242
+			// $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
243
+			EE_Error::add_error(
244
+				sprintf(
245
+					esc_html__(
246
+						'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
247
+						'event_espresso'
248
+					),
249
+					'<br/>'
250
+				),
251
+				__FILE__,
252
+				__FUNCTION__,
253
+				__LINE__
254
+			);
255
+		}
256
+		//if event id is valid
257
+		return absint($this->request->getRequestParam('tkt-slctr-event-id'));
258
+	}
259
+
260
+
261
+	/**
262
+	 * validate_post_data
263
+	 *
264
+	 * @param int $id
265
+	 * @return array|FALSE
266
+	 */
267
+	private function validatePostData($id = 0)
268
+	{
269
+		if (! $id) {
270
+			EE_Error::add_error(
271
+				esc_html__('The event id provided was not valid.', 'event_espresso'),
272
+				__FILE__,
273
+				__FUNCTION__,
274
+				__LINE__
275
+			);
276
+			return false;
277
+		}
278
+		// start with an empty array()
279
+		$valid_data = array();
280
+		// grab valid id
281
+		$valid_data['id'] = $id;
282
+		// array of other form names
283
+		$inputs_to_clean = array(
284
+			'event_id'   => 'tkt-slctr-event-id',
285
+			'max_atndz'  => 'tkt-slctr-max-atndz-',
286
+			'rows'       => 'tkt-slctr-rows-',
287
+			'qty'        => 'tkt-slctr-qty-',
288
+			'ticket_id'  => 'tkt-slctr-ticket-id-',
289
+			'return_url' => 'tkt-slctr-return-url-',
290
+		);
291
+		// let's track the total number of tickets ordered.'
292
+		$valid_data['total_tickets'] = 0;
293
+		// cycle through $inputs_to_clean array
294
+		foreach ($inputs_to_clean as $what => $input_to_clean) {
295
+			// check for POST data
296
+			if ($this->request->requestParamIsSet($input_to_clean . $id)) {
297
+				// grab value
298
+				$input_value = $this->request->getRequestParam($input_to_clean . $id);
299
+				switch ($what) {
300
+					// integers
301
+					case 'event_id':
302
+						$valid_data[ $what ] = absint($input_value);
303
+						// get event via the event id we put in the form
304
+						break;
305
+					case 'rows':
306
+					case 'max_atndz':
307
+						$valid_data[ $what ] = absint($input_value);
308
+						break;
309
+					// arrays of integers
310
+					case 'qty':
311
+						/** @var array $row_qty */
312
+						$row_qty = $input_value;
313
+						// if qty is coming from a radio button input, then we need to assemble an array of rows
314
+						if (! is_array($row_qty)) {
315
+							/** @var string $row_qty */
316
+							// get number of rows
317
+							$rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id)
318
+								? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id))
319
+								: 1;
320
+							// explode integers by the dash
321
+							$row_qty = explode('-', $row_qty);
322
+							$row     = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
323
+							$qty     = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
324
+							$row_qty = array($row => $qty);
325
+							for ($x = 1; $x <= $rows; $x++) {
326
+								if (! isset($row_qty[ $x ])) {
327
+									$row_qty[ $x ] = 0;
328
+								}
329
+							}
330
+						}
331
+						ksort($row_qty);
332
+						// cycle thru values
333
+						foreach ($row_qty as $qty) {
334
+							$qty = absint($qty);
335
+							// sanitize as integers
336
+							$valid_data[ $what ][]       = $qty;
337
+							$valid_data['total_tickets'] += $qty;
338
+						}
339
+						break;
340
+					// array of integers
341
+					case 'ticket_id':
342
+						// cycle thru values
343
+						foreach ((array) $input_value as $key => $value) {
344
+							// allow only integers
345
+							$valid_data[ $what ][ $key ] = absint($value);
346
+						}
347
+						break;
348
+					case 'return_url' :
349
+						// grab and sanitize return-url
350
+						$input_value = esc_url_raw($input_value);
351
+						// was the request coming from an iframe ? if so, then:
352
+						if (strpos($input_value, 'event_list=iframe')) {
353
+							// get anchor fragment
354
+							$input_value = explode('#', $input_value);
355
+							$input_value = end($input_value);
356
+							// use event list url instead, but append anchor
357
+							$input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
358
+						}
359
+						$valid_data[ $what ] = $input_value;
360
+						break;
361
+				}    // end switch $what
362
+			}
363
+		}    // end foreach $inputs_to_clean
364
+		return $valid_data;
365
+	}
366
+
367
+
368
+	/**
369
+	 * @param array $valid
370
+	 */
371
+	private function maxAttendeesViolation(array $valid)
372
+	{
373
+		// ordering too many tickets !!!
374
+		$total_tickets_string = esc_html(
375
+			_n(
376
+				'You have attempted to purchase %s ticket.',
377
+				'You have attempted to purchase %s tickets.',
378
+				$valid['total_tickets'],
379
+				'event_espresso'
380
+			)
381
+		);
382
+		$limit_error_1        = sprintf($total_tickets_string, $valid['total_tickets']);
383
+		// dev only message
384
+		$max_attendees_string = esc_html(
385
+			_n(
386
+				'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
387
+				'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
388
+				$valid['max_atndz'],
389
+				'event_espresso'
390
+			)
391
+		);
392
+		$limit_error_2    = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
393
+		EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
394
+	}
395
+
396
+
397
+	/**
398
+	 * @param array $valid
399
+	 * @return int|TRUE
400
+	 * @throws EE_Error
401
+	 * @throws InvalidArgumentException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws InvalidInterfaceException
404
+	 */
405
+	private function addTicketsToCart(array $valid)
406
+	{
407
+		$tickets_added = 0;
408
+		$tickets_selected = false;
409
+		if($valid['total_tickets'] > 0){
410
+			// load cart using factory because we don't want to do so until actually needed
411
+			$this->cart = CartFactory::getCart();
412
+			// cycle thru the number of data rows sent from the event listing
413
+			for ($x = 0; $x < $valid['rows']; $x++) {
414
+				// does this row actually contain a ticket quantity?
415
+				if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
416
+					// YES we have a ticket quantity
417
+					$tickets_selected = true;
418
+					$valid_ticket     = false;
419
+					// \EEH_Debug_Tools::printr(
420
+					//     $valid['ticket_id'][ $x ],
421
+					//     '$valid[\'ticket_id\'][ $x ]',
422
+					//     __FILE__, __LINE__
423
+					// );
424
+					if (isset($valid['ticket_id'][ $x ])) {
425
+						// get ticket via the ticket id we put in the form
426
+						$ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
427
+						if ($ticket instanceof EE_Ticket) {
428
+							$valid_ticket  = true;
429
+							$tickets_added += $this->addTicketToCart(
430
+								$ticket,
431
+								$valid['qty'][ $x ]
432
+							);
433
+						}
434
+					}
435
+					if ($valid_ticket !== true) {
436
+						// nothing added to cart retrieved
437
+						EE_Error::add_error(
438
+							sprintf(
439
+								esc_html__(
440
+									'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
441
+									'event_espresso'
442
+								),
443
+								'<br/>'
444
+							),
445
+							__FILE__, __FUNCTION__, __LINE__
446
+						);
447
+					}
448
+					if (EE_Error::has_error()) {
449
+						break;
450
+					}
451
+				}
452
+			}
453
+		}
454
+		do_action(
455
+			'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
456
+			$this->cart,
457
+			$this
458
+		);
459
+		if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
460
+			// no ticket quantities were selected
461
+			EE_Error::add_error(
462
+				esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
463
+				__FILE__, __FUNCTION__, __LINE__
464
+			);
465
+		}
466
+		return $tickets_added;
467
+	}
468
+
469
+
470
+
471
+	/**
472
+	 * adds a ticket to the cart
473
+	 *
474
+	 * @param EE_Ticket $ticket
475
+	 * @param int        $qty
476
+	 * @return TRUE on success, FALSE on fail
477
+	 * @throws InvalidArgumentException
478
+	 * @throws InvalidInterfaceException
479
+	 * @throws InvalidDataTypeException
480
+	 * @throws EE_Error
481
+	 */
482
+	private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
483
+	{
484
+		// get the number of spaces left for this datetime ticket
485
+		$available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
486
+		// compare available spaces against the number of tickets being purchased
487
+		if ($available_spaces >= $qty) {
488
+			// allow addons to prevent a ticket from being added to cart
489
+			if (
490
+				! apply_filters(
491
+					'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
492
+					true,
493
+					$ticket,
494
+					$qty,
495
+					$available_spaces
496
+				)
497
+			) {
498
+				return false;
499
+			}
500
+			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
501
+			// add event to cart
502
+			if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
503
+				$this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
504
+				return true;
505
+			}
506
+			return false;
507
+		}
508
+		$this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
509
+		return false;
510
+	}
511
+
512
+
513
+	/**
514
+	 * @param $tickets_added
515
+	 * @return bool
516
+	 * @throws InvalidInterfaceException
517
+	 * @throws InvalidDataTypeException
518
+	 * @throws EE_Error
519
+	 * @throws InvalidArgumentException
520
+	 */
521
+	private function processSuccessfulCart($tickets_added)
522
+	{
523
+		// exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
524
+		if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
525
+			// make sure cart is loaded
526
+			if(! $this->cart  instanceof EE_Cart){
527
+				$this->cart = CartFactory::getCart();
528
+			}
529
+			do_action(
530
+				'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
531
+				$this->cart,
532
+				$this
533
+			);
534
+			$this->cart->recalculate_all_cart_totals();
535
+			$this->cart->save_cart(false);
536
+			// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
537
+			// just return TRUE for registrations being made from admin
538
+			if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
539
+				return true;
540
+			}
541
+			EEH_URL::safeRedirectAndExit(
542
+				apply_filters(
543
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
544
+					$this->core_config->reg_page_url()
545
+				)
546
+			);
547
+		}
548
+		if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
549
+			// nothing added to cart
550
+			EE_Error::add_attention(
551
+				esc_html__('No tickets were added for the event', 'event_espresso'),
552
+				__FILE__, __FUNCTION__, __LINE__
553
+			);
554
+		}
555
+		return false;
556
+	}
557 557
 }
558 558
 // End of file ProcessTicketSelector.php
559 559
 // Location: /ProcessTicketSelector.php
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     public function cancelTicketSelections()
120 120
     {
121 121
         // check nonce
122
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122
+        if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
123 123
             return false;
124 124
         }
125 125
         $this->session->clear_session(__CLASS__, __FUNCTION__);
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             );
132 132
         }
133 133
         EEH_URL::safeRedirectAndExit(
134
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
134
+            site_url('/'.$this->core_config->event_cpt_slug.'/')
135 135
         );
136 136
         return true;
137 137
     }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     public function processTicketSelections()
188 188
     {
189 189
         do_action('EED_Ticket_Selector__process_ticket_selections__before');
190
-        if($this->request->isBot()) {
190
+        if ($this->request->isBot()) {
191 191
             EEH_URL::safeRedirectAndExit(
192 192
                 apply_filters(
193 193
                     'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
     private function getEventId()
239 239
     {
240 240
         // do we have an event id?
241
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
241
+        if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
242 242
             // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
243 243
             EE_Error::add_error(
244 244
                 sprintf(
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      */
267 267
     private function validatePostData($id = 0)
268 268
     {
269
-        if (! $id) {
269
+        if ( ! $id) {
270 270
             EE_Error::add_error(
271 271
                 esc_html__('The event id provided was not valid.', 'event_espresso'),
272 272
                 __FILE__,
@@ -293,29 +293,29 @@  discard block
 block discarded – undo
293 293
         // cycle through $inputs_to_clean array
294 294
         foreach ($inputs_to_clean as $what => $input_to_clean) {
295 295
             // check for POST data
296
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
296
+            if ($this->request->requestParamIsSet($input_to_clean.$id)) {
297 297
                 // grab value
298
-                $input_value = $this->request->getRequestParam($input_to_clean . $id);
298
+                $input_value = $this->request->getRequestParam($input_to_clean.$id);
299 299
                 switch ($what) {
300 300
                     // integers
301 301
                     case 'event_id':
302
-                        $valid_data[ $what ] = absint($input_value);
302
+                        $valid_data[$what] = absint($input_value);
303 303
                         // get event via the event id we put in the form
304 304
                         break;
305 305
                     case 'rows':
306 306
                     case 'max_atndz':
307
-                        $valid_data[ $what ] = absint($input_value);
307
+                        $valid_data[$what] = absint($input_value);
308 308
                         break;
309 309
                     // arrays of integers
310 310
                     case 'qty':
311 311
                         /** @var array $row_qty */
312 312
                         $row_qty = $input_value;
313 313
                         // if qty is coming from a radio button input, then we need to assemble an array of rows
314
-                        if (! is_array($row_qty)) {
314
+                        if ( ! is_array($row_qty)) {
315 315
                             /** @var string $row_qty */
316 316
                             // get number of rows
317
-                            $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id)
318
-                                ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id))
317
+                            $rows = $this->request->requestParamIsSet('tkt-slctr-rows-'.$id)
318
+                                ? absint($this->request->getRequestParam('tkt-slctr-rows-'.$id))
319 319
                                 : 1;
320 320
                             // explode integers by the dash
321 321
                             $row_qty = explode('-', $row_qty);
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
                             $qty     = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
324 324
                             $row_qty = array($row => $qty);
325 325
                             for ($x = 1; $x <= $rows; $x++) {
326
-                                if (! isset($row_qty[ $x ])) {
327
-                                    $row_qty[ $x ] = 0;
326
+                                if ( ! isset($row_qty[$x])) {
327
+                                    $row_qty[$x] = 0;
328 328
                                 }
329 329
                             }
330 330
                         }
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
                         foreach ($row_qty as $qty) {
334 334
                             $qty = absint($qty);
335 335
                             // sanitize as integers
336
-                            $valid_data[ $what ][]       = $qty;
336
+                            $valid_data[$what][] = $qty;
337 337
                             $valid_data['total_tickets'] += $qty;
338 338
                         }
339 339
                         break;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
                         // cycle thru values
343 343
                         foreach ((array) $input_value as $key => $value) {
344 344
                             // allow only integers
345
-                            $valid_data[ $what ][ $key ] = absint($value);
345
+                            $valid_data[$what][$key] = absint($value);
346 346
                         }
347 347
                         break;
348 348
                     case 'return_url' :
@@ -354,9 +354,9 @@  discard block
 block discarded – undo
354 354
                             $input_value = explode('#', $input_value);
355 355
                             $input_value = end($input_value);
356 356
                             // use event list url instead, but append anchor
357
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
357
+                            $input_value = EEH_Event_View::event_archive_url().'#'.$input_value;
358 358
                         }
359
-                        $valid_data[ $what ] = $input_value;
359
+                        $valid_data[$what] = $input_value;
360 360
                         break;
361 361
                 }    // end switch $what
362 362
             }
@@ -389,8 +389,8 @@  discard block
 block discarded – undo
389 389
                 'event_espresso'
390 390
             )
391 391
         );
392
-        $limit_error_2    = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
393
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
392
+        $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
393
+        EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__);
394 394
     }
395 395
 
396 396
 
@@ -406,13 +406,13 @@  discard block
 block discarded – undo
406 406
     {
407 407
         $tickets_added = 0;
408 408
         $tickets_selected = false;
409
-        if($valid['total_tickets'] > 0){
409
+        if ($valid['total_tickets'] > 0) {
410 410
             // load cart using factory because we don't want to do so until actually needed
411 411
             $this->cart = CartFactory::getCart();
412 412
             // cycle thru the number of data rows sent from the event listing
413 413
             for ($x = 0; $x < $valid['rows']; $x++) {
414 414
                 // does this row actually contain a ticket quantity?
415
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
415
+                if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
416 416
                     // YES we have a ticket quantity
417 417
                     $tickets_selected = true;
418 418
                     $valid_ticket     = false;
@@ -421,14 +421,14 @@  discard block
 block discarded – undo
421 421
                     //     '$valid[\'ticket_id\'][ $x ]',
422 422
                     //     __FILE__, __LINE__
423 423
                     // );
424
-                    if (isset($valid['ticket_id'][ $x ])) {
424
+                    if (isset($valid['ticket_id'][$x])) {
425 425
                         // get ticket via the ticket id we put in the form
426
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
426
+                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]);
427 427
                         if ($ticket instanceof EE_Ticket) {
428
-                            $valid_ticket  = true;
428
+                            $valid_ticket = true;
429 429
                             $tickets_added += $this->addTicketToCart(
430 430
                                 $ticket,
431
-                                $valid['qty'][ $x ]
431
+                                $valid['qty'][$x]
432 432
                             );
433 433
                         }
434 434
                     }
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
             $this->cart,
457 457
             $this
458 458
         );
459
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
459
+        if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
460 460
             // no ticket quantities were selected
461 461
             EE_Error::add_error(
462 462
                 esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
         // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
524 524
         if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
525 525
             // make sure cart is loaded
526
-            if(! $this->cart  instanceof EE_Cart){
526
+            if ( ! $this->cart  instanceof EE_Cart) {
527 527
                 $this->cart = CartFactory::getCart();
528 528
             }
529 529
             do_action(
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
                 )
546 546
             );
547 547
         }
548
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
548
+        if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
549 549
             // nothing added to cart
550 550
             EE_Error::add_attention(
551 551
                 esc_html__('No tickets were added for the event', 'event_espresso'),
Please login to merge, or discard this patch.
core/EE_Error.core.php 2 patches
Indentation   +1142 added lines, -1142 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
 // if you're a dev and want to receive all errors via email
12 12
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
13 13
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
14
-    set_error_handler(array('EE_Error', 'error_handler'));
15
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
14
+	set_error_handler(array('EE_Error', 'error_handler'));
15
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
16 16
 }
17 17
 
18 18
 
@@ -27,258 +27,258 @@  discard block
 block discarded – undo
27 27
 class EE_Error extends Exception
28 28
 {
29 29
 
30
-    const OPTIONS_KEY_NOTICES = 'ee_notices';
31
-
32
-
33
-    /**
34
-     * name of the file to log exceptions to
35
-     *
36
-     * @var string
37
-     */
38
-    private static $_exception_log_file = 'espresso_error_log.txt';
39
-
40
-    /**
41
-     *    stores details for all exception
42
-     *
43
-     * @var array
44
-     */
45
-    private static $_all_exceptions = array();
46
-
47
-    /**
48
-     *    tracks number of errors
49
-     *
50
-     * @var int
51
-     */
52
-    private static $_error_count = 0;
53
-
54
-    /**
55
-     * @var array $_espresso_notices
56
-     */
57
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
58
-
59
-
60
-
61
-    /**
62
-     * @override default exception handling
63
-     * @param string         $message
64
-     * @param int            $code
65
-     * @param Exception|null $previous
66
-     */
67
-    public function __construct($message, $code = 0, Exception $previous = null)
68
-    {
69
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
70
-            parent::__construct($message, $code);
71
-        } else {
72
-            parent::__construct($message, $code, $previous);
73
-        }
74
-    }
75
-
76
-
77
-    /**
78
-     *    error_handler
79
-     *
80
-     * @param $code
81
-     * @param $message
82
-     * @param $file
83
-     * @param $line
84
-     * @return void
85
-     */
86
-    public static function error_handler($code, $message, $file, $line)
87
-    {
88
-        $type = EE_Error::error_type($code);
89
-        $site = site_url();
90
-        switch ($site) {
91
-            case 'http://ee4.eventespresso.com/' :
92
-            case 'http://ee4decaf.eventespresso.com/' :
93
-            case 'http://ee4hf.eventespresso.com/' :
94
-            case 'http://ee4a.eventespresso.com/' :
95
-            case 'http://ee4ad.eventespresso.com/' :
96
-            case 'http://ee4b.eventespresso.com/' :
97
-            case 'http://ee4bd.eventespresso.com/' :
98
-            case 'http://ee4d.eventespresso.com/' :
99
-            case 'http://ee4dd.eventespresso.com/' :
100
-                $to = '[email protected]';
101
-                break;
102
-            default :
103
-                $to = get_option('admin_email');
104
-        }
105
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
106
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
107
-        if (function_exists('wp_mail')) {
108
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
109
-            wp_mail($to, $subject, $msg);
110
-        }
111
-        echo '<div id="message" class="espresso-notices error"><p>';
112
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
113
-        echo '<br /></p></div>';
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * error_type
120
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
121
-     *
122
-     * @param $code
123
-     * @return string
124
-     */
125
-    public static function error_type($code)
126
-    {
127
-        switch ($code) {
128
-            case E_ERROR: // 1 //
129
-                return 'E_ERROR';
130
-            case E_WARNING: // 2 //
131
-                return 'E_WARNING';
132
-            case E_PARSE: // 4 //
133
-                return 'E_PARSE';
134
-            case E_NOTICE: // 8 //
135
-                return 'E_NOTICE';
136
-            case E_CORE_ERROR: // 16 //
137
-                return 'E_CORE_ERROR';
138
-            case E_CORE_WARNING: // 32 //
139
-                return 'E_CORE_WARNING';
140
-            case E_COMPILE_ERROR: // 64 //
141
-                return 'E_COMPILE_ERROR';
142
-            case E_COMPILE_WARNING: // 128 //
143
-                return 'E_COMPILE_WARNING';
144
-            case E_USER_ERROR: // 256 //
145
-                return 'E_USER_ERROR';
146
-            case E_USER_WARNING: // 512 //
147
-                return 'E_USER_WARNING';
148
-            case E_USER_NOTICE: // 1024 //
149
-                return 'E_USER_NOTICE';
150
-            case E_STRICT: // 2048 //
151
-                return 'E_STRICT';
152
-            case E_RECOVERABLE_ERROR: // 4096 //
153
-                return 'E_RECOVERABLE_ERROR';
154
-            case E_DEPRECATED: // 8192 //
155
-                return 'E_DEPRECATED';
156
-            case E_USER_DEPRECATED: // 16384 //
157
-                return 'E_USER_DEPRECATED';
158
-            case E_ALL: // 16384 //
159
-                return 'E_ALL';
160
-        }
161
-        return '';
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     *    fatal_error_handler
168
-     *
169
-     * @return void
170
-     */
171
-    public static function fatal_error_handler()
172
-    {
173
-        $last_error = error_get_last();
174
-        if ($last_error['type'] === E_ERROR) {
175
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
176
-        }
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * _format_error
183
-     *
184
-     * @param $code
185
-     * @param $message
186
-     * @param $file
187
-     * @param $line
188
-     * @return string
189
-     */
190
-    private static function _format_error($code, $message, $file, $line)
191
-    {
192
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
193
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
194
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
195
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
196
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
197
-        $html .= '</tbody></table>';
198
-        return $html;
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * set_content_type
205
-     *
206
-     * @param $content_type
207
-     * @return string
208
-     */
209
-    public static function set_content_type($content_type)
210
-    {
211
-        return 'text/html';
212
-    }
213
-
214
-
215
-
216
-    /**
217
-     * @return void
218
-     * @throws EE_Error
219
-     * @throws ReflectionException
220
-     */
221
-    public function get_error()
222
-    {
223
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
224
-            throw $this;
225
-        }
226
-        // get separate user and developer messages if they exist
227
-        $msg = explode('||', $this->getMessage());
228
-        $user_msg = $msg[0];
229
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
230
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
231
-        // add details to _all_exceptions array
232
-        $x_time = time();
233
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
234
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
235
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
236
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
237
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
238
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
239
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
240
-        self::$_error_count++;
241
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
242
-        $this->display_errors();
243
-    }
244
-
245
-
246
-    /**
247
-     * @param bool   $check_stored
248
-     * @param string $type_to_check
249
-     * @return bool
250
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
251
-     * @throws \InvalidArgumentException
252
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
253
-     * @throws InvalidInterfaceException
254
-     */
255
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
256
-    {
257
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
258
-                     && ! empty(self::$_espresso_notices[$type_to_check])
259
-            ? true
260
-            : false;
261
-        if ($check_stored && ! $has_error) {
262
-            $notices = EE_Error::getStoredNotices();
263
-            foreach ($notices as $type => $notice) {
264
-                if ($type === $type_to_check && $notice) {
265
-                    return true;
266
-                }
267
-            }
268
-        }
269
-        return $has_error;
270
-    }
271
-
272
-
273
-
274
-    /**
275
-     * @echo string
276
-     * @throws \ReflectionException
277
-     */
278
-    public function display_errors()
279
-    {
280
-        $trace_details = '';
281
-        $output = '
30
+	const OPTIONS_KEY_NOTICES = 'ee_notices';
31
+
32
+
33
+	/**
34
+	 * name of the file to log exceptions to
35
+	 *
36
+	 * @var string
37
+	 */
38
+	private static $_exception_log_file = 'espresso_error_log.txt';
39
+
40
+	/**
41
+	 *    stores details for all exception
42
+	 *
43
+	 * @var array
44
+	 */
45
+	private static $_all_exceptions = array();
46
+
47
+	/**
48
+	 *    tracks number of errors
49
+	 *
50
+	 * @var int
51
+	 */
52
+	private static $_error_count = 0;
53
+
54
+	/**
55
+	 * @var array $_espresso_notices
56
+	 */
57
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
58
+
59
+
60
+
61
+	/**
62
+	 * @override default exception handling
63
+	 * @param string         $message
64
+	 * @param int            $code
65
+	 * @param Exception|null $previous
66
+	 */
67
+	public function __construct($message, $code = 0, Exception $previous = null)
68
+	{
69
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
70
+			parent::__construct($message, $code);
71
+		} else {
72
+			parent::__construct($message, $code, $previous);
73
+		}
74
+	}
75
+
76
+
77
+	/**
78
+	 *    error_handler
79
+	 *
80
+	 * @param $code
81
+	 * @param $message
82
+	 * @param $file
83
+	 * @param $line
84
+	 * @return void
85
+	 */
86
+	public static function error_handler($code, $message, $file, $line)
87
+	{
88
+		$type = EE_Error::error_type($code);
89
+		$site = site_url();
90
+		switch ($site) {
91
+			case 'http://ee4.eventespresso.com/' :
92
+			case 'http://ee4decaf.eventespresso.com/' :
93
+			case 'http://ee4hf.eventespresso.com/' :
94
+			case 'http://ee4a.eventespresso.com/' :
95
+			case 'http://ee4ad.eventespresso.com/' :
96
+			case 'http://ee4b.eventespresso.com/' :
97
+			case 'http://ee4bd.eventespresso.com/' :
98
+			case 'http://ee4d.eventespresso.com/' :
99
+			case 'http://ee4dd.eventespresso.com/' :
100
+				$to = '[email protected]';
101
+				break;
102
+			default :
103
+				$to = get_option('admin_email');
104
+		}
105
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
106
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
107
+		if (function_exists('wp_mail')) {
108
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
109
+			wp_mail($to, $subject, $msg);
110
+		}
111
+		echo '<div id="message" class="espresso-notices error"><p>';
112
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
113
+		echo '<br /></p></div>';
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * error_type
120
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
121
+	 *
122
+	 * @param $code
123
+	 * @return string
124
+	 */
125
+	public static function error_type($code)
126
+	{
127
+		switch ($code) {
128
+			case E_ERROR: // 1 //
129
+				return 'E_ERROR';
130
+			case E_WARNING: // 2 //
131
+				return 'E_WARNING';
132
+			case E_PARSE: // 4 //
133
+				return 'E_PARSE';
134
+			case E_NOTICE: // 8 //
135
+				return 'E_NOTICE';
136
+			case E_CORE_ERROR: // 16 //
137
+				return 'E_CORE_ERROR';
138
+			case E_CORE_WARNING: // 32 //
139
+				return 'E_CORE_WARNING';
140
+			case E_COMPILE_ERROR: // 64 //
141
+				return 'E_COMPILE_ERROR';
142
+			case E_COMPILE_WARNING: // 128 //
143
+				return 'E_COMPILE_WARNING';
144
+			case E_USER_ERROR: // 256 //
145
+				return 'E_USER_ERROR';
146
+			case E_USER_WARNING: // 512 //
147
+				return 'E_USER_WARNING';
148
+			case E_USER_NOTICE: // 1024 //
149
+				return 'E_USER_NOTICE';
150
+			case E_STRICT: // 2048 //
151
+				return 'E_STRICT';
152
+			case E_RECOVERABLE_ERROR: // 4096 //
153
+				return 'E_RECOVERABLE_ERROR';
154
+			case E_DEPRECATED: // 8192 //
155
+				return 'E_DEPRECATED';
156
+			case E_USER_DEPRECATED: // 16384 //
157
+				return 'E_USER_DEPRECATED';
158
+			case E_ALL: // 16384 //
159
+				return 'E_ALL';
160
+		}
161
+		return '';
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 *    fatal_error_handler
168
+	 *
169
+	 * @return void
170
+	 */
171
+	public static function fatal_error_handler()
172
+	{
173
+		$last_error = error_get_last();
174
+		if ($last_error['type'] === E_ERROR) {
175
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
176
+		}
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * _format_error
183
+	 *
184
+	 * @param $code
185
+	 * @param $message
186
+	 * @param $file
187
+	 * @param $line
188
+	 * @return string
189
+	 */
190
+	private static function _format_error($code, $message, $file, $line)
191
+	{
192
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
193
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
194
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
195
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
196
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
197
+		$html .= '</tbody></table>';
198
+		return $html;
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * set_content_type
205
+	 *
206
+	 * @param $content_type
207
+	 * @return string
208
+	 */
209
+	public static function set_content_type($content_type)
210
+	{
211
+		return 'text/html';
212
+	}
213
+
214
+
215
+
216
+	/**
217
+	 * @return void
218
+	 * @throws EE_Error
219
+	 * @throws ReflectionException
220
+	 */
221
+	public function get_error()
222
+	{
223
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
224
+			throw $this;
225
+		}
226
+		// get separate user and developer messages if they exist
227
+		$msg = explode('||', $this->getMessage());
228
+		$user_msg = $msg[0];
229
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
230
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
231
+		// add details to _all_exceptions array
232
+		$x_time = time();
233
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
234
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
235
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
236
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
237
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
238
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
239
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
240
+		self::$_error_count++;
241
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
242
+		$this->display_errors();
243
+	}
244
+
245
+
246
+	/**
247
+	 * @param bool   $check_stored
248
+	 * @param string $type_to_check
249
+	 * @return bool
250
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
251
+	 * @throws \InvalidArgumentException
252
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
253
+	 * @throws InvalidInterfaceException
254
+	 */
255
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
256
+	{
257
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
258
+					 && ! empty(self::$_espresso_notices[$type_to_check])
259
+			? true
260
+			: false;
261
+		if ($check_stored && ! $has_error) {
262
+			$notices = EE_Error::getStoredNotices();
263
+			foreach ($notices as $type => $notice) {
264
+				if ($type === $type_to_check && $notice) {
265
+					return true;
266
+				}
267
+			}
268
+		}
269
+		return $has_error;
270
+	}
271
+
272
+
273
+
274
+	/**
275
+	 * @echo string
276
+	 * @throws \ReflectionException
277
+	 */
278
+	public function display_errors()
279
+	{
280
+		$trace_details = '';
281
+		$output = '
282 282
 <style type="text/css">
283 283
 	#ee-error-message {
284 284
 		max-width:90% !important;
@@ -334,21 +334,21 @@  discard block
 block discarded – undo
334 334
 	}
335 335
 </style>
336 336
 <div id="ee-error-message" class="error">';
337
-        if (! WP_DEBUG) {
338
-            $output .= '
337
+		if (! WP_DEBUG) {
338
+			$output .= '
339 339
 	<p>';
340
-        }
341
-        // cycle thru errors
342
-        foreach (self::$_all_exceptions as $time => $ex) {
343
-            $error_code = '';
344
-            // process trace info
345
-            if (empty($ex['trace'])) {
346
-                $trace_details .= __(
347
-                    'Sorry, but no trace information was available for this exception.',
348
-                    'event_espresso'
349
-                );
350
-            } else {
351
-                $trace_details .= '
340
+		}
341
+		// cycle thru errors
342
+		foreach (self::$_all_exceptions as $time => $ex) {
343
+			$error_code = '';
344
+			// process trace info
345
+			if (empty($ex['trace'])) {
346
+				$trace_details .= __(
347
+					'Sorry, but no trace information was available for this exception.',
348
+					'event_espresso'
349
+				);
350
+			} else {
351
+				$trace_details .= '
352 352
 			<div id="ee-trace-details">
353 353
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
354 354
 				<tr>
@@ -358,43 +358,43 @@  discard block
 block discarded – undo
358 358
 					<th scope="col" align="left">Class</th>
359 359
 					<th scope="col" align="left">Method( arguments )</th>
360 360
 				</tr>';
361
-                $last_on_stack = count($ex['trace']) - 1;
362
-                // reverse array so that stack is in proper chronological order
363
-                $sorted_trace = array_reverse($ex['trace']);
364
-                foreach ($sorted_trace as $nmbr => $trace) {
365
-                    $file = isset($trace['file']) ? $trace['file'] : '';
366
-                    $class = isset($trace['class']) ? $trace['class'] : '';
367
-                    $type = isset($trace['type']) ? $trace['type'] : '';
368
-                    $function = isset($trace['function']) ? $trace['function'] : '';
369
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
370
-                    $line = isset($trace['line']) ? $trace['line'] : '';
371
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
372
-                    if (empty($file) && ! empty($class)) {
373
-                        $a = new ReflectionClass($class);
374
-                        $file = $a->getFileName();
375
-                        if (empty($line) && ! empty($function)) {
376
-                            try {
377
-                                //if $function is a closure, this throws an exception
378
-                                $b = new ReflectionMethod($class, $function);
379
-                                $line = $b->getStartLine();
380
-                            } catch (Exception $closure_exception) {
381
-                                $line = 'unknown';
382
-                            }
383
-                        }
384
-                    }
385
-                    if ($nmbr === $last_on_stack) {
386
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
387
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
388
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
389
-                    }
390
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
391
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
392
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
393
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
394
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
395
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
396
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
397
-                    $trace_details .= '
361
+				$last_on_stack = count($ex['trace']) - 1;
362
+				// reverse array so that stack is in proper chronological order
363
+				$sorted_trace = array_reverse($ex['trace']);
364
+				foreach ($sorted_trace as $nmbr => $trace) {
365
+					$file = isset($trace['file']) ? $trace['file'] : '';
366
+					$class = isset($trace['class']) ? $trace['class'] : '';
367
+					$type = isset($trace['type']) ? $trace['type'] : '';
368
+					$function = isset($trace['function']) ? $trace['function'] : '';
369
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
370
+					$line = isset($trace['line']) ? $trace['line'] : '';
371
+					$zebra = ($nmbr % 2) ? ' odd' : '';
372
+					if (empty($file) && ! empty($class)) {
373
+						$a = new ReflectionClass($class);
374
+						$file = $a->getFileName();
375
+						if (empty($line) && ! empty($function)) {
376
+							try {
377
+								//if $function is a closure, this throws an exception
378
+								$b = new ReflectionMethod($class, $function);
379
+								$line = $b->getStartLine();
380
+							} catch (Exception $closure_exception) {
381
+								$line = 'unknown';
382
+							}
383
+						}
384
+					}
385
+					if ($nmbr === $last_on_stack) {
386
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
387
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
388
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
389
+					}
390
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
391
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
392
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
393
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
394
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
395
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
396
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
397
+					$trace_details .= '
398 398
 					<tr>
399 399
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
400 400
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -402,633 +402,633 @@  discard block
 block discarded – undo
402 402
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
403 403
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
404 404
 					</tr>';
405
-                }
406
-                $trace_details .= '
405
+				}
406
+				$trace_details .= '
407 407
 			 </table>
408 408
 			</div>';
409
-            }
410
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
411
-            // add generic non-identifying messages for non-privileged users
412
-            if (! WP_DEBUG) {
413
-                $output .= '<span class="ee-error-user-msg-spn">'
414
-                           . trim($ex['msg'])
415
-                           . '</span> &nbsp; <sup>'
416
-                           . $ex['code']
417
-                           . '</sup><br />';
418
-            } else {
419
-                // or helpful developer messages if debugging is on
420
-                $output .= '
409
+			}
410
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
411
+			// add generic non-identifying messages for non-privileged users
412
+			if (! WP_DEBUG) {
413
+				$output .= '<span class="ee-error-user-msg-spn">'
414
+						   . trim($ex['msg'])
415
+						   . '</span> &nbsp; <sup>'
416
+						   . $ex['code']
417
+						   . '</sup><br />';
418
+			} else {
419
+				// or helpful developer messages if debugging is on
420
+				$output .= '
421 421
 		<div class="ee-error-dev-msg-dv">
422 422
 			<p class="ee-error-dev-msg-pg">
423 423
 				<strong class="ee-error-dev-msg-str">An '
424
-                           . $ex['name']
425
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
426
-                           . $ex['code']
427
-                           . '</span><br />
424
+						   . $ex['name']
425
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
426
+						   . $ex['code']
427
+						   . '</span><br />
428 428
 				<span class="big-text">"'
429
-                           . trim($ex['msg'])
430
-                           . '"</span><br/>
429
+						   . trim($ex['msg'])
430
+						   . '"</span><br/>
431 431
 				<a id="display-ee-error-trace-'
432
-                           . self::$_error_count
433
-                           . $time
434
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
435
-                           . self::$_error_count
436
-                           . $time
437
-                           . '">
432
+						   . self::$_error_count
433
+						   . $time
434
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
435
+						   . self::$_error_count
436
+						   . $time
437
+						   . '">
438 438
 					'
439
-                           . __('click to view backtrace and class/method details', 'event_espresso')
440
-                           . '
439
+						   . __('click to view backtrace and class/method details', 'event_espresso')
440
+						   . '
441 441
 				</a><br />
442 442
 				<span class="small-text lt-grey-text">'
443
-                           . $ex['file']
444
-                           . ' &nbsp; ( line no: '
445
-                           . $ex['line']
446
-                           . ' )</span>
443
+						   . $ex['file']
444
+						   . ' &nbsp; ( line no: '
445
+						   . $ex['line']
446
+						   . ' )</span>
447 447
 			</p>
448 448
 			<div id="ee-error-trace-'
449
-                           . self::$_error_count
450
-                           . $time
451
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
449
+						   . self::$_error_count
450
+						   . $time
451
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
452 452
 				'
453
-                           . $trace_details;
454
-                if (! empty($class)) {
455
-                    $output .= '
453
+						   . $trace_details;
454
+				if (! empty($class)) {
455
+					$output .= '
456 456
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
457 457
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
458 458
 						<h3>Class Details</h3>';
459
-                    $a = new ReflectionClass($class);
460
-                    $output .= '
459
+					$a = new ReflectionClass($class);
460
+					$output .= '
461 461
 						<pre>' . $a . '</pre>
462 462
 					</div>
463 463
 				</div>';
464
-                }
465
-                $output .= '
464
+				}
465
+				$output .= '
466 466
 			</div>
467 467
 		</div>
468 468
 		<br />';
469
-            }
470
-            $this->write_to_error_log($time, $ex);
471
-        }
472
-        // remove last linebreak
473
-        $output = substr($output, 0, -6);
474
-        if (! WP_DEBUG) {
475
-            $output .= '
469
+			}
470
+			$this->write_to_error_log($time, $ex);
471
+		}
472
+		// remove last linebreak
473
+		$output = substr($output, 0, -6);
474
+		if (! WP_DEBUG) {
475
+			$output .= '
476 476
 	</p>';
477
-        }
478
-        $output .= '
477
+		}
478
+		$output .= '
479 479
 </div>';
480
-        $output .= self::_print_scripts(true);
481
-        if (defined('DOING_AJAX')) {
482
-            echo wp_json_encode(array('error' => $output));
483
-            exit();
484
-        }
485
-        echo $output;
486
-        die();
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     *    generate string from exception trace args
493
-     *
494
-     * @param array $arguments
495
-     * @param bool  $array
496
-     * @return string
497
-     */
498
-    private function _convert_args_to_string($arguments = array(), $array = false)
499
-    {
500
-        $arg_string = '';
501
-        if (! empty($arguments)) {
502
-            $args = array();
503
-            foreach ($arguments as $arg) {
504
-                if (! empty($arg)) {
505
-                    if (is_string($arg)) {
506
-                        $args[] = " '" . $arg . "'";
507
-                    } elseif (is_array($arg)) {
508
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
509
-                    } elseif ($arg === null) {
510
-                        $args[] = ' NULL';
511
-                    } elseif (is_bool($arg)) {
512
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
513
-                    } elseif (is_object($arg)) {
514
-                        $args[] = ' OBJECT ' . get_class($arg);
515
-                    } elseif (is_resource($arg)) {
516
-                        $args[] = get_resource_type($arg);
517
-                    } else {
518
-                        $args[] = $arg;
519
-                    }
520
-                }
521
-            }
522
-            $arg_string = implode(', ', $args);
523
-        }
524
-        if ($array) {
525
-            $arg_string .= ' )';
526
-        }
527
-        return $arg_string;
528
-    }
529
-
530
-
531
-
532
-    /**
533
-     *    add error message
534
-     *
535
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
536
-     *                            separate messages for user || dev
537
-     * @param        string $file the file that the error occurred in - just use __FILE__
538
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
539
-     * @param        string $line the line number where the error occurred - just use __LINE__
540
-     * @return        void
541
-     */
542
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
543
-    {
544
-        self::_add_notice('errors', $msg, $file, $func, $line);
545
-        self::$_error_count++;
546
-    }
547
-
548
-
549
-
550
-    /**
551
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
552
-     * adds an error
553
-     *
554
-     * @param string $msg
555
-     * @param string $file
556
-     * @param string $func
557
-     * @param string $line
558
-     * @throws EE_Error
559
-     */
560
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
561
-    {
562
-        if (WP_DEBUG) {
563
-            throw new EE_Error($msg);
564
-        }
565
-        EE_Error::add_error($msg, $file, $func, $line);
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     *    add success message
572
-     *
573
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
574
-     *                            separate messages for user || dev
575
-     * @param        string $file the file that the error occurred in - just use __FILE__
576
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
577
-     * @param        string $line the line number where the error occurred - just use __LINE__
578
-     * @return        void
579
-     */
580
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
581
-    {
582
-        self::_add_notice('success', $msg, $file, $func, $line);
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     *    add attention message
589
-     *
590
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
591
-     *                            separate messages for user || dev
592
-     * @param        string $file the file that the error occurred in - just use __FILE__
593
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
594
-     * @param        string $line the line number where the error occurred - just use __LINE__
595
-     * @return        void
596
-     */
597
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
598
-    {
599
-        self::_add_notice('attention', $msg, $file, $func, $line);
600
-    }
601
-
602
-
603
-
604
-    /**
605
-     * @param string $type whether the message is for a success or error notification
606
-     * @param string $msg the message to display to users or developers
607
-     *                    - adding a double pipe || (OR) creates separate messages for user || dev
608
-     * @param string $file the file that the error occurred in - just use __FILE__
609
-     * @param string $func the function/method that the error occurred in - just use __FUNCTION__
610
-     * @param string $line the line number where the error occurred - just use __LINE__
611
-     * @return void
612
-     */
613
-    private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
614
-    {
615
-        if (empty($msg)) {
616
-            EE_Error::doing_it_wrong(
617
-                'EE_Error::add_' . $type . '()',
618
-                sprintf(
619
-                    __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
620
-                        'event_espresso'),
621
-                    $type,
622
-                    $file,
623
-                    $line
624
-                ),
625
-                EVENT_ESPRESSO_VERSION
626
-            );
627
-        }
628
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
629
-            EE_Error::doing_it_wrong(
630
-                'EE_Error::add_error()',
631
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
632
-                    'event_espresso'),
633
-                EVENT_ESPRESSO_VERSION
634
-            );
635
-        }
636
-        // get separate user and developer messages if they exist
637
-        $msg      = explode('||', $msg);
638
-        $user_msg = $msg[0];
639
-        $dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
640
-        /**
641
-         * Do an action so other code can be triggered when a notice is created
642
-         *
643
-         * @param string $type     can be 'errors', 'attention', or 'success'
644
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
645
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
646
-         * @param string $file     file where error was generated
647
-         * @param string $func     function where error was generated
648
-         * @param string $line     line where error was generated
649
-         */
650
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
651
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
652
-        // add notice if message exists
653
-        if (! empty($msg)) {
654
-            // get error code
655
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
656
-            if (WP_DEBUG && $type === 'errors') {
657
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
658
-            }
659
-            // add notice. Index by code if it's not blank
660
-            if ($notice_code) {
661
-                self::$_espresso_notices[$type][$notice_code] = $msg;
662
-            } else {
663
-                self::$_espresso_notices[$type][] = $msg;
664
-            }
665
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
666
-        }
667
-    }
668
-
669
-
670
-    /**
671
-     * in some case it may be necessary to overwrite the existing success messages
672
-     *
673
-     * @return        void
674
-     */
675
-    public static function overwrite_success()
676
-    {
677
-        self::$_espresso_notices['success'] = false;
678
-    }
679
-
680
-
681
-
682
-    /**
683
-     * in some case it may be necessary to overwrite the existing attention messages
684
-     *
685
-     * @return void
686
-     */
687
-    public static function overwrite_attention()
688
-    {
689
-        self::$_espresso_notices['attention'] = false;
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     * in some case it may be necessary to overwrite the existing error messages
696
-     *
697
-     * @return void
698
-     */
699
-    public static function overwrite_errors()
700
-    {
701
-        self::$_espresso_notices['errors'] = false;
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     * @return void
708
-     */
709
-    public static function reset_notices()
710
-    {
711
-        self::$_espresso_notices['success']   = false;
712
-        self::$_espresso_notices['attention'] = false;
713
-        self::$_espresso_notices['errors']    = false;
714
-    }
715
-
716
-
717
-
718
-    /**
719
-     * @return int
720
-     */
721
-    public static function has_notices()
722
-    {
723
-        $has_notices = 0;
724
-        // check for success messages
725
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
726
-            ? 3
727
-            : $has_notices;
728
-        // check for attention messages
729
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
730
-            ? 2
731
-            : $has_notices;
732
-        // check for error messages
733
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
734
-            ? 1
735
-            : $has_notices;
736
-        return $has_notices;
737
-    }
738
-
739
-
740
-    /**
741
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
742
-     *
743
-     * @since 4.9.0
744
-     * @return array
745
-     */
746
-    public static function get_vanilla_notices()
747
-    {
748
-        return array(
749
-            'success'   => isset(self::$_espresso_notices['success'])
750
-                ? self::$_espresso_notices['success']
751
-                : array(),
752
-            'attention' => isset(self::$_espresso_notices['attention'])
753
-                ? self::$_espresso_notices['attention']
754
-                : array(),
755
-            'errors'    => isset(self::$_espresso_notices['errors'])
756
-                ? self::$_espresso_notices['errors']
757
-                : array(),
758
-        );
759
-    }
760
-
761
-
762
-    /**
763
-     * @return array
764
-     * @throws InvalidArgumentException
765
-     * @throws InvalidDataTypeException
766
-     * @throws InvalidInterfaceException
767
-     */
768
-    public static function getStoredNotices()
769
-    {
770
-        if ($user_id = get_current_user_id()) {
771
-            // get notices for logged in user
772
-            $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id);
773
-            return is_array($notices) ? $notices : array();
774
-        }
775
-        if (EE_Session::isLoadedAndActive()) {
776
-            // get notices for user currently engaged in a session
777
-            $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES);
778
-            return is_array($session_data) ? $session_data : array();
779
-        }
780
-        // get global notices and hope they apply to the current site visitor
781
-        $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
782
-        return is_array($notices) ? $notices : array();
783
-    }
784
-
785
-
786
-    /**
787
-     * @param array $notices
788
-     * @return bool
789
-     * @throws InvalidArgumentException
790
-     * @throws InvalidDataTypeException
791
-     * @throws InvalidInterfaceException
792
-     */
793
-    public static function storeNotices(array $notices)
794
-    {
795
-        if ($user_id = get_current_user_id()) {
796
-            // store notices for logged in user
797
-            return (bool) update_user_option(
798
-                $user_id,
799
-                EE_Error::OPTIONS_KEY_NOTICES,
800
-                $notices
801
-            );
802
-        }
803
-        if (EE_Session::isLoadedAndActive()) {
804
-            // store notices for user currently engaged in a session
805
-            return EE_Session::instance()->set_session_data(
806
-                array(EE_Error::OPTIONS_KEY_NOTICES => $notices)
807
-            );
808
-        }
809
-        // store global notices and hope they apply to the same site visitor on the next request
810
-        return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices);
811
-    }
812
-
813
-
814
-    /**
815
-     * @return bool|TRUE
816
-     * @throws InvalidArgumentException
817
-     * @throws InvalidDataTypeException
818
-     * @throws InvalidInterfaceException
819
-     */
820
-    public static function clearNotices()
821
-    {
822
-        if ($user_id = get_current_user_id()) {
823
-            // clear notices for logged in user
824
-            return (bool) update_user_option(
825
-                $user_id,
826
-                EE_Error::OPTIONS_KEY_NOTICES,
827
-                array()
828
-            );
829
-        }
830
-        if (EE_Session::isLoadedAndActive()) {
831
-            // clear notices for user currently engaged in a session
832
-            return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES);
833
-        }
834
-        // clear global notices and hope none belonged to some for some other site visitor
835
-        return update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
836
-    }
837
-
838
-
839
-    /**
840
-     * saves notices to the db for retrieval on next request
841
-     *
842
-     * @return void
843
-     * @throws InvalidArgumentException
844
-     * @throws InvalidDataTypeException
845
-     * @throws InvalidInterfaceException
846
-     */
847
-    public static function stashNoticesBeforeRedirect()
848
-    {
849
-        EE_Error::get_notices(false, true);
850
-    }
851
-
852
-
853
-    /**
854
-     * compile all error or success messages into one string
855
-     *
856
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
857
-     * @param boolean $format_output            whether or not to format the messages for display in the WP admin
858
-     * @param boolean $save_to_transient        whether or not to save notices to the db for retrieval on next request
859
-     *                                          - ONLY do this just before redirecting
860
-     * @param boolean $remove_empty             whether or not to unset empty messages
861
-     * @return array
862
-     * @throws InvalidArgumentException
863
-     * @throws InvalidDataTypeException
864
-     * @throws InvalidInterfaceException
865
-     */
866
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
867
-    {
868
-        $success_messages   = '';
869
-        $attention_messages = '';
870
-        $error_messages     = '';
871
-        // either save notices to the db
872
-        if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
873
-            self::$_espresso_notices = array_merge(
874
-                EE_Error::getStoredNotices(),
875
-                self::$_espresso_notices
876
-            );
877
-            EE_Error::storeNotices(self::$_espresso_notices);
878
-            return array();
879
-        }
880
-        $print_scripts = EE_Error::combineExistingAndNewNotices();
881
-        // check for success messages
882
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
883
-            // combine messages
884
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br />');
885
-            $print_scripts    = true;
886
-        }
887
-        // check for attention messages
888
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
889
-            // combine messages
890
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
891
-            $print_scripts      = true;
892
-        }
893
-        // check for error messages
894
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
895
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
896
-                ? __('The following errors have occurred:<br />', 'event_espresso')
897
-                : __('An error has occurred:<br />', 'event_espresso');
898
-            // combine messages
899
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
900
-            $print_scripts  = true;
901
-        }
902
-        if ($format_output) {
903
-            $notices = EE_Error::formatNoticesOutput(
904
-                $success_messages,
905
-                $attention_messages,
906
-                $error_messages
907
-            );
908
-        } else {
909
-            $notices = array(
910
-                'success'   => $success_messages,
911
-                'attention' => $attention_messages,
912
-                'errors'    => $error_messages,
913
-            );
914
-            if ($remove_empty) {
915
-                // remove empty notices
916
-                foreach ($notices as $type => $notice) {
917
-                    if (empty($notice)) {
918
-                        unset($notices[$type]);
919
-                    }
920
-                }
921
-            }
922
-        }
923
-        if ($print_scripts) {
924
-            self::_print_scripts();
925
-        }
926
-        return $notices;
927
-    }
928
-
929
-
930
-    /**
931
-     * @return bool
932
-     * @throws InvalidArgumentException
933
-     * @throws InvalidDataTypeException
934
-     * @throws InvalidInterfaceException
935
-     */
936
-    private static function combineExistingAndNewNotices()
937
-    {
938
-        $print_scripts = false;
939
-        // grab any notices that have been previously saved
940
-        $notices = EE_Error::getStoredNotices();
941
-        if (! empty($notices)) {
942
-            foreach ($notices as $type => $notice) {
943
-                if (is_array($notice) && ! empty($notice)) {
944
-                    // make sure that existing notice type is an array
945
-                    self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
946
-                                                        && ! empty(self::$_espresso_notices[ $type ])
947
-                        ? self::$_espresso_notices[ $type ]
948
-                        : array();
949
-                    // add newly created notices to existing ones
950
-                    self::$_espresso_notices[ $type ] += $notice;
951
-                    $print_scripts = true;
952
-                }
953
-            }
954
-            // now clear any stored notices
955
-            EE_Error::clearNotices();
956
-        }
957
-        return $print_scripts;
958
-    }
959
-
960
-
961
-    /**
962
-     * @param string $success_messages
963
-     * @param string $attention_messages
964
-     * @param string $error_messages
965
-     * @return string
966
-     */
967
-    private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages)
968
-    {
969
-        $notices = '<div id="espresso-notices">';
970
-        $close   = is_admin()
971
-            ? ''
972
-            : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>';
973
-        if ($success_messages !== '') {
974
-            $css_id    = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
975
-            $css_class = is_admin() ? 'updated fade' : 'success fade-away';
976
-            //showMessage( $success_messages );
977
-            $notices .= '<div id="' . $css_id . '" '
978
-                        . 'class="espresso-notices ' . $css_class . '" '
979
-                        . 'style="display:none;">'
980
-                        . '<p>' . $success_messages . '</p>'
981
-                        . $close
982
-                        . '</div>';
983
-        }
984
-        if ($attention_messages !== '') {
985
-            $css_id    = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
986
-            $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
987
-            //showMessage( $error_messages, TRUE );
988
-            $notices .= '<div id="' . $css_id . '" '
989
-                        . 'class="espresso-notices ' . $css_class . '" '
990
-                        . 'style="display:none;">'
991
-                        . '<p>' . $attention_messages . '</p>'
992
-                        . $close
993
-                        . '</div>';
994
-        }
995
-        if ($error_messages !== '') {
996
-            $css_id    = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
997
-            $css_class = is_admin() ? 'error' : 'error fade-away';
998
-            //showMessage( $error_messages, TRUE );
999
-            $notices .= '<div id="' . $css_id . '" '
1000
-                        . 'class="espresso-notices ' . $css_class . '" '
1001
-                        . 'style="display:none;">'
1002
-                        . '<p>' . $error_messages . '</p>'
1003
-                        . $close
1004
-                        . '</div>';
1005
-        }
1006
-        $notices .= '</div>';
1007
-        return $notices;
1008
-    }
1009
-
1010
-
1011
-
1012
-    /**
1013
-     * _print_scripts
1014
-     *
1015
-     * @param    bool $force_print
1016
-     * @return    string
1017
-     */
1018
-    private static function _print_scripts($force_print = false)
1019
-    {
1020
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1021
-            if (wp_script_is('ee_error_js', 'enqueued')) {
1022
-                return '';
1023
-            }
1024
-            if (wp_script_is('ee_error_js', 'registered')) {
1025
-                wp_enqueue_style('espresso_default');
1026
-                wp_enqueue_style('espresso_custom_css');
1027
-                wp_enqueue_script('ee_error_js');
1028
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1029
-            }
1030
-        } else {
1031
-            return '
480
+		$output .= self::_print_scripts(true);
481
+		if (defined('DOING_AJAX')) {
482
+			echo wp_json_encode(array('error' => $output));
483
+			exit();
484
+		}
485
+		echo $output;
486
+		die();
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 *    generate string from exception trace args
493
+	 *
494
+	 * @param array $arguments
495
+	 * @param bool  $array
496
+	 * @return string
497
+	 */
498
+	private function _convert_args_to_string($arguments = array(), $array = false)
499
+	{
500
+		$arg_string = '';
501
+		if (! empty($arguments)) {
502
+			$args = array();
503
+			foreach ($arguments as $arg) {
504
+				if (! empty($arg)) {
505
+					if (is_string($arg)) {
506
+						$args[] = " '" . $arg . "'";
507
+					} elseif (is_array($arg)) {
508
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
509
+					} elseif ($arg === null) {
510
+						$args[] = ' NULL';
511
+					} elseif (is_bool($arg)) {
512
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
513
+					} elseif (is_object($arg)) {
514
+						$args[] = ' OBJECT ' . get_class($arg);
515
+					} elseif (is_resource($arg)) {
516
+						$args[] = get_resource_type($arg);
517
+					} else {
518
+						$args[] = $arg;
519
+					}
520
+				}
521
+			}
522
+			$arg_string = implode(', ', $args);
523
+		}
524
+		if ($array) {
525
+			$arg_string .= ' )';
526
+		}
527
+		return $arg_string;
528
+	}
529
+
530
+
531
+
532
+	/**
533
+	 *    add error message
534
+	 *
535
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
536
+	 *                            separate messages for user || dev
537
+	 * @param        string $file the file that the error occurred in - just use __FILE__
538
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
539
+	 * @param        string $line the line number where the error occurred - just use __LINE__
540
+	 * @return        void
541
+	 */
542
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
543
+	{
544
+		self::_add_notice('errors', $msg, $file, $func, $line);
545
+		self::$_error_count++;
546
+	}
547
+
548
+
549
+
550
+	/**
551
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
552
+	 * adds an error
553
+	 *
554
+	 * @param string $msg
555
+	 * @param string $file
556
+	 * @param string $func
557
+	 * @param string $line
558
+	 * @throws EE_Error
559
+	 */
560
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
561
+	{
562
+		if (WP_DEBUG) {
563
+			throw new EE_Error($msg);
564
+		}
565
+		EE_Error::add_error($msg, $file, $func, $line);
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 *    add success message
572
+	 *
573
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
574
+	 *                            separate messages for user || dev
575
+	 * @param        string $file the file that the error occurred in - just use __FILE__
576
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
577
+	 * @param        string $line the line number where the error occurred - just use __LINE__
578
+	 * @return        void
579
+	 */
580
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
581
+	{
582
+		self::_add_notice('success', $msg, $file, $func, $line);
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 *    add attention message
589
+	 *
590
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
591
+	 *                            separate messages for user || dev
592
+	 * @param        string $file the file that the error occurred in - just use __FILE__
593
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
594
+	 * @param        string $line the line number where the error occurred - just use __LINE__
595
+	 * @return        void
596
+	 */
597
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
598
+	{
599
+		self::_add_notice('attention', $msg, $file, $func, $line);
600
+	}
601
+
602
+
603
+
604
+	/**
605
+	 * @param string $type whether the message is for a success or error notification
606
+	 * @param string $msg the message to display to users or developers
607
+	 *                    - adding a double pipe || (OR) creates separate messages for user || dev
608
+	 * @param string $file the file that the error occurred in - just use __FILE__
609
+	 * @param string $func the function/method that the error occurred in - just use __FUNCTION__
610
+	 * @param string $line the line number where the error occurred - just use __LINE__
611
+	 * @return void
612
+	 */
613
+	private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
614
+	{
615
+		if (empty($msg)) {
616
+			EE_Error::doing_it_wrong(
617
+				'EE_Error::add_' . $type . '()',
618
+				sprintf(
619
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
620
+						'event_espresso'),
621
+					$type,
622
+					$file,
623
+					$line
624
+				),
625
+				EVENT_ESPRESSO_VERSION
626
+			);
627
+		}
628
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
629
+			EE_Error::doing_it_wrong(
630
+				'EE_Error::add_error()',
631
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
632
+					'event_espresso'),
633
+				EVENT_ESPRESSO_VERSION
634
+			);
635
+		}
636
+		// get separate user and developer messages if they exist
637
+		$msg      = explode('||', $msg);
638
+		$user_msg = $msg[0];
639
+		$dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
640
+		/**
641
+		 * Do an action so other code can be triggered when a notice is created
642
+		 *
643
+		 * @param string $type     can be 'errors', 'attention', or 'success'
644
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
645
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
646
+		 * @param string $file     file where error was generated
647
+		 * @param string $func     function where error was generated
648
+		 * @param string $line     line where error was generated
649
+		 */
650
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
651
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
652
+		// add notice if message exists
653
+		if (! empty($msg)) {
654
+			// get error code
655
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
656
+			if (WP_DEBUG && $type === 'errors') {
657
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
658
+			}
659
+			// add notice. Index by code if it's not blank
660
+			if ($notice_code) {
661
+				self::$_espresso_notices[$type][$notice_code] = $msg;
662
+			} else {
663
+				self::$_espresso_notices[$type][] = $msg;
664
+			}
665
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
666
+		}
667
+	}
668
+
669
+
670
+	/**
671
+	 * in some case it may be necessary to overwrite the existing success messages
672
+	 *
673
+	 * @return        void
674
+	 */
675
+	public static function overwrite_success()
676
+	{
677
+		self::$_espresso_notices['success'] = false;
678
+	}
679
+
680
+
681
+
682
+	/**
683
+	 * in some case it may be necessary to overwrite the existing attention messages
684
+	 *
685
+	 * @return void
686
+	 */
687
+	public static function overwrite_attention()
688
+	{
689
+		self::$_espresso_notices['attention'] = false;
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 * in some case it may be necessary to overwrite the existing error messages
696
+	 *
697
+	 * @return void
698
+	 */
699
+	public static function overwrite_errors()
700
+	{
701
+		self::$_espresso_notices['errors'] = false;
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 * @return void
708
+	 */
709
+	public static function reset_notices()
710
+	{
711
+		self::$_espresso_notices['success']   = false;
712
+		self::$_espresso_notices['attention'] = false;
713
+		self::$_espresso_notices['errors']    = false;
714
+	}
715
+
716
+
717
+
718
+	/**
719
+	 * @return int
720
+	 */
721
+	public static function has_notices()
722
+	{
723
+		$has_notices = 0;
724
+		// check for success messages
725
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
726
+			? 3
727
+			: $has_notices;
728
+		// check for attention messages
729
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
730
+			? 2
731
+			: $has_notices;
732
+		// check for error messages
733
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
734
+			? 1
735
+			: $has_notices;
736
+		return $has_notices;
737
+	}
738
+
739
+
740
+	/**
741
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
742
+	 *
743
+	 * @since 4.9.0
744
+	 * @return array
745
+	 */
746
+	public static function get_vanilla_notices()
747
+	{
748
+		return array(
749
+			'success'   => isset(self::$_espresso_notices['success'])
750
+				? self::$_espresso_notices['success']
751
+				: array(),
752
+			'attention' => isset(self::$_espresso_notices['attention'])
753
+				? self::$_espresso_notices['attention']
754
+				: array(),
755
+			'errors'    => isset(self::$_espresso_notices['errors'])
756
+				? self::$_espresso_notices['errors']
757
+				: array(),
758
+		);
759
+	}
760
+
761
+
762
+	/**
763
+	 * @return array
764
+	 * @throws InvalidArgumentException
765
+	 * @throws InvalidDataTypeException
766
+	 * @throws InvalidInterfaceException
767
+	 */
768
+	public static function getStoredNotices()
769
+	{
770
+		if ($user_id = get_current_user_id()) {
771
+			// get notices for logged in user
772
+			$notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id);
773
+			return is_array($notices) ? $notices : array();
774
+		}
775
+		if (EE_Session::isLoadedAndActive()) {
776
+			// get notices for user currently engaged in a session
777
+			$session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES);
778
+			return is_array($session_data) ? $session_data : array();
779
+		}
780
+		// get global notices and hope they apply to the current site visitor
781
+		$notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
782
+		return is_array($notices) ? $notices : array();
783
+	}
784
+
785
+
786
+	/**
787
+	 * @param array $notices
788
+	 * @return bool
789
+	 * @throws InvalidArgumentException
790
+	 * @throws InvalidDataTypeException
791
+	 * @throws InvalidInterfaceException
792
+	 */
793
+	public static function storeNotices(array $notices)
794
+	{
795
+		if ($user_id = get_current_user_id()) {
796
+			// store notices for logged in user
797
+			return (bool) update_user_option(
798
+				$user_id,
799
+				EE_Error::OPTIONS_KEY_NOTICES,
800
+				$notices
801
+			);
802
+		}
803
+		if (EE_Session::isLoadedAndActive()) {
804
+			// store notices for user currently engaged in a session
805
+			return EE_Session::instance()->set_session_data(
806
+				array(EE_Error::OPTIONS_KEY_NOTICES => $notices)
807
+			);
808
+		}
809
+		// store global notices and hope they apply to the same site visitor on the next request
810
+		return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices);
811
+	}
812
+
813
+
814
+	/**
815
+	 * @return bool|TRUE
816
+	 * @throws InvalidArgumentException
817
+	 * @throws InvalidDataTypeException
818
+	 * @throws InvalidInterfaceException
819
+	 */
820
+	public static function clearNotices()
821
+	{
822
+		if ($user_id = get_current_user_id()) {
823
+			// clear notices for logged in user
824
+			return (bool) update_user_option(
825
+				$user_id,
826
+				EE_Error::OPTIONS_KEY_NOTICES,
827
+				array()
828
+			);
829
+		}
830
+		if (EE_Session::isLoadedAndActive()) {
831
+			// clear notices for user currently engaged in a session
832
+			return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES);
833
+		}
834
+		// clear global notices and hope none belonged to some for some other site visitor
835
+		return update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
836
+	}
837
+
838
+
839
+	/**
840
+	 * saves notices to the db for retrieval on next request
841
+	 *
842
+	 * @return void
843
+	 * @throws InvalidArgumentException
844
+	 * @throws InvalidDataTypeException
845
+	 * @throws InvalidInterfaceException
846
+	 */
847
+	public static function stashNoticesBeforeRedirect()
848
+	{
849
+		EE_Error::get_notices(false, true);
850
+	}
851
+
852
+
853
+	/**
854
+	 * compile all error or success messages into one string
855
+	 *
856
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
857
+	 * @param boolean $format_output            whether or not to format the messages for display in the WP admin
858
+	 * @param boolean $save_to_transient        whether or not to save notices to the db for retrieval on next request
859
+	 *                                          - ONLY do this just before redirecting
860
+	 * @param boolean $remove_empty             whether or not to unset empty messages
861
+	 * @return array
862
+	 * @throws InvalidArgumentException
863
+	 * @throws InvalidDataTypeException
864
+	 * @throws InvalidInterfaceException
865
+	 */
866
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
867
+	{
868
+		$success_messages   = '';
869
+		$attention_messages = '';
870
+		$error_messages     = '';
871
+		// either save notices to the db
872
+		if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
873
+			self::$_espresso_notices = array_merge(
874
+				EE_Error::getStoredNotices(),
875
+				self::$_espresso_notices
876
+			);
877
+			EE_Error::storeNotices(self::$_espresso_notices);
878
+			return array();
879
+		}
880
+		$print_scripts = EE_Error::combineExistingAndNewNotices();
881
+		// check for success messages
882
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
883
+			// combine messages
884
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br />');
885
+			$print_scripts    = true;
886
+		}
887
+		// check for attention messages
888
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
889
+			// combine messages
890
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
891
+			$print_scripts      = true;
892
+		}
893
+		// check for error messages
894
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
895
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
896
+				? __('The following errors have occurred:<br />', 'event_espresso')
897
+				: __('An error has occurred:<br />', 'event_espresso');
898
+			// combine messages
899
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
900
+			$print_scripts  = true;
901
+		}
902
+		if ($format_output) {
903
+			$notices = EE_Error::formatNoticesOutput(
904
+				$success_messages,
905
+				$attention_messages,
906
+				$error_messages
907
+			);
908
+		} else {
909
+			$notices = array(
910
+				'success'   => $success_messages,
911
+				'attention' => $attention_messages,
912
+				'errors'    => $error_messages,
913
+			);
914
+			if ($remove_empty) {
915
+				// remove empty notices
916
+				foreach ($notices as $type => $notice) {
917
+					if (empty($notice)) {
918
+						unset($notices[$type]);
919
+					}
920
+				}
921
+			}
922
+		}
923
+		if ($print_scripts) {
924
+			self::_print_scripts();
925
+		}
926
+		return $notices;
927
+	}
928
+
929
+
930
+	/**
931
+	 * @return bool
932
+	 * @throws InvalidArgumentException
933
+	 * @throws InvalidDataTypeException
934
+	 * @throws InvalidInterfaceException
935
+	 */
936
+	private static function combineExistingAndNewNotices()
937
+	{
938
+		$print_scripts = false;
939
+		// grab any notices that have been previously saved
940
+		$notices = EE_Error::getStoredNotices();
941
+		if (! empty($notices)) {
942
+			foreach ($notices as $type => $notice) {
943
+				if (is_array($notice) && ! empty($notice)) {
944
+					// make sure that existing notice type is an array
945
+					self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
946
+														&& ! empty(self::$_espresso_notices[ $type ])
947
+						? self::$_espresso_notices[ $type ]
948
+						: array();
949
+					// add newly created notices to existing ones
950
+					self::$_espresso_notices[ $type ] += $notice;
951
+					$print_scripts = true;
952
+				}
953
+			}
954
+			// now clear any stored notices
955
+			EE_Error::clearNotices();
956
+		}
957
+		return $print_scripts;
958
+	}
959
+
960
+
961
+	/**
962
+	 * @param string $success_messages
963
+	 * @param string $attention_messages
964
+	 * @param string $error_messages
965
+	 * @return string
966
+	 */
967
+	private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages)
968
+	{
969
+		$notices = '<div id="espresso-notices">';
970
+		$close   = is_admin()
971
+			? ''
972
+			: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>';
973
+		if ($success_messages !== '') {
974
+			$css_id    = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
975
+			$css_class = is_admin() ? 'updated fade' : 'success fade-away';
976
+			//showMessage( $success_messages );
977
+			$notices .= '<div id="' . $css_id . '" '
978
+						. 'class="espresso-notices ' . $css_class . '" '
979
+						. 'style="display:none;">'
980
+						. '<p>' . $success_messages . '</p>'
981
+						. $close
982
+						. '</div>';
983
+		}
984
+		if ($attention_messages !== '') {
985
+			$css_id    = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
986
+			$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
987
+			//showMessage( $error_messages, TRUE );
988
+			$notices .= '<div id="' . $css_id . '" '
989
+						. 'class="espresso-notices ' . $css_class . '" '
990
+						. 'style="display:none;">'
991
+						. '<p>' . $attention_messages . '</p>'
992
+						. $close
993
+						. '</div>';
994
+		}
995
+		if ($error_messages !== '') {
996
+			$css_id    = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
997
+			$css_class = is_admin() ? 'error' : 'error fade-away';
998
+			//showMessage( $error_messages, TRUE );
999
+			$notices .= '<div id="' . $css_id . '" '
1000
+						. 'class="espresso-notices ' . $css_class . '" '
1001
+						. 'style="display:none;">'
1002
+						. '<p>' . $error_messages . '</p>'
1003
+						. $close
1004
+						. '</div>';
1005
+		}
1006
+		$notices .= '</div>';
1007
+		return $notices;
1008
+	}
1009
+
1010
+
1011
+
1012
+	/**
1013
+	 * _print_scripts
1014
+	 *
1015
+	 * @param    bool $force_print
1016
+	 * @return    string
1017
+	 */
1018
+	private static function _print_scripts($force_print = false)
1019
+	{
1020
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1021
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1022
+				return '';
1023
+			}
1024
+			if (wp_script_is('ee_error_js', 'registered')) {
1025
+				wp_enqueue_style('espresso_default');
1026
+				wp_enqueue_style('espresso_custom_css');
1027
+				wp_enqueue_script('ee_error_js');
1028
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1029
+			}
1030
+		} else {
1031
+			return '
1032 1032
 <script>
1033 1033
 /* <![CDATA[ */
1034 1034
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -1038,223 +1038,223 @@  discard block
 block discarded – undo
1038 1038
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1039 1039
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1040 1040
 ';
1041
-        }
1042
-        return '';
1043
-    }
1044
-
1045
-
1046
-
1047
-    /**
1048
-     * @return void
1049
-     */
1050
-    public static function enqueue_error_scripts()
1051
-    {
1052
-        self::_print_scripts();
1053
-    }
1054
-
1055
-
1056
-
1057
-    /**
1058
-     * create error code from filepath, function name,
1059
-     * and line number where exception or error was thrown
1060
-     *
1061
-     * @param string $file
1062
-     * @param string $func
1063
-     * @param string $line
1064
-     * @return string
1065
-     */
1066
-    public static function generate_error_code($file = '', $func = '', $line = '')
1067
-    {
1068
-        $file       = explode('.', basename($file));
1069
-        $error_code = ! empty($file[0]) ? $file[0] : '';
1070
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1071
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1072
-        return $error_code;
1073
-    }
1074
-
1075
-
1076
-
1077
-    /**
1078
-     * write exception details to log file
1079
-     * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
1080
-     *
1081
-     * @param int   $time
1082
-     * @param array $ex
1083
-     * @param bool  $clear
1084
-     * @return void
1085
-     */
1086
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1087
-    {
1088
-        if (empty($ex)) {
1089
-            return;
1090
-        }
1091
-        if (! $time) {
1092
-            $time = time();
1093
-        }
1094
-        $exception_log = '----------------------------------------------------------------------------------------'
1095
-                         . PHP_EOL;
1096
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1097
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1098
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1099
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1100
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1101
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1102
-        $exception_log .= $ex['string'] . PHP_EOL;
1103
-        $exception_log .= '----------------------------------------------------------------------------------------'
1104
-                          . PHP_EOL;
1105
-        try {
1106
-            error_log($exception_log);
1107
-        } catch (EE_Error $e) {
1108
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1109
-                'event_espresso'), $e->getMessage()));
1110
-        }
1111
-    }
1112
-
1113
-
1114
-
1115
-    /**
1116
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1117
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1118
-     * but the code execution is done in a manner that could lead to unexpected results
1119
-     * (i.e. running to early, or too late in WP or EE loading process).
1120
-     * A good test for knowing whether to use this method is:
1121
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1122
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1123
-     * 2. If this is loaded before something else, it won't break anything,
1124
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1125
-     *
1126
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1127
-     * @param string $function      The function that was called
1128
-     * @param string $message       A message explaining what has been done incorrectly
1129
-     * @param string $version       The version of Event Espresso where the error was added
1130
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1131
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1132
-     *                              but not have any notices appear until a later version. This allows developers
1133
-     *                              extra time to update their code before notices appear.
1134
-     * @param int    $error_type
1135
-     */
1136
-    public static function doing_it_wrong(
1137
-        $function,
1138
-        $message,
1139
-        $version,
1140
-        $applies_when = '',
1141
-        $error_type = null
1142
-    ) {
1143
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1144
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1145
-        }
1146
-    }
1147
-
1148
-
1149
-
1150
-    /**
1151
-     * Like get_notices, but returns an array of all the notices of the given type.
1152
-     *
1153
-     * @return array {
1154
-     *  @type array $success   all the success messages
1155
-     *  @type array $errors    all the error messages
1156
-     *  @type array $attention all the attention messages
1157
-     * }
1158
-     */
1159
-    public static function get_raw_notices()
1160
-    {
1161
-        return self::$_espresso_notices;
1162
-    }
1163
-
1164
-
1165
-
1166
-    /**
1167
-     * @deprecated 4.9.27
1168
-     * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1169
-     * @param string $pan_message  the message to be stored persistently until dismissed
1170
-     * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1171
-     * @return void
1172
-     * @throws InvalidDataTypeException
1173
-     */
1174
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1175
-    {
1176
-        new PersistentAdminNotice(
1177
-            $pan_name,
1178
-            $pan_message,
1179
-            $force_update
1180
-        );
1181
-        EE_Error::doing_it_wrong(
1182
-            __METHOD__,
1183
-            sprintf(
1184
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1185
-                '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1186
-            ),
1187
-            '4.9.27'
1188
-        );
1189
-    }
1190
-
1191
-
1192
-
1193
-    /**
1194
-     * @deprecated 4.9.27
1195
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1196
-     * @param bool   $purge
1197
-     * @param bool   $return
1198
-     * @throws DomainException
1199
-     * @throws InvalidInterfaceException
1200
-     * @throws InvalidDataTypeException
1201
-     * @throws ServiceNotFoundException
1202
-     * @throws InvalidArgumentException
1203
-     */
1204
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1205
-    {
1206
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1207
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1208
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1209
-        );
1210
-        $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1211
-        EE_Error::doing_it_wrong(
1212
-            __METHOD__,
1213
-            sprintf(
1214
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1215
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1216
-            ),
1217
-            '4.9.27'
1218
-        );
1219
-    }
1220
-
1221
-
1222
-
1223
-    /**
1224
-     * @deprecated 4.9.27
1225
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1226
-     * @param  string $pan_message the message to be stored persistently until dismissed
1227
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
1228
-     */
1229
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1230
-    {
1231
-        EE_Error::doing_it_wrong(
1232
-            __METHOD__,
1233
-            sprintf(
1234
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1235
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1236
-            ),
1237
-            '4.9.27'
1238
-        );
1239
-    }
1240
-
1241
-
1242
-
1243
-    /**
1244
-     * @deprecated 4.9.27
1245
-     * @param string $return_url
1246
-     */
1247
-    public static function get_persistent_admin_notices($return_url = '')
1248
-    {
1249
-        EE_Error::doing_it_wrong(
1250
-            __METHOD__,
1251
-            sprintf(
1252
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1253
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1254
-            ),
1255
-            '4.9.27'
1256
-        );
1257
-    }
1041
+		}
1042
+		return '';
1043
+	}
1044
+
1045
+
1046
+
1047
+	/**
1048
+	 * @return void
1049
+	 */
1050
+	public static function enqueue_error_scripts()
1051
+	{
1052
+		self::_print_scripts();
1053
+	}
1054
+
1055
+
1056
+
1057
+	/**
1058
+	 * create error code from filepath, function name,
1059
+	 * and line number where exception or error was thrown
1060
+	 *
1061
+	 * @param string $file
1062
+	 * @param string $func
1063
+	 * @param string $line
1064
+	 * @return string
1065
+	 */
1066
+	public static function generate_error_code($file = '', $func = '', $line = '')
1067
+	{
1068
+		$file       = explode('.', basename($file));
1069
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1070
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
1071
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
1072
+		return $error_code;
1073
+	}
1074
+
1075
+
1076
+
1077
+	/**
1078
+	 * write exception details to log file
1079
+	 * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
1080
+	 *
1081
+	 * @param int   $time
1082
+	 * @param array $ex
1083
+	 * @param bool  $clear
1084
+	 * @return void
1085
+	 */
1086
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1087
+	{
1088
+		if (empty($ex)) {
1089
+			return;
1090
+		}
1091
+		if (! $time) {
1092
+			$time = time();
1093
+		}
1094
+		$exception_log = '----------------------------------------------------------------------------------------'
1095
+						 . PHP_EOL;
1096
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1097
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1098
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1099
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1100
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1101
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
1102
+		$exception_log .= $ex['string'] . PHP_EOL;
1103
+		$exception_log .= '----------------------------------------------------------------------------------------'
1104
+						  . PHP_EOL;
1105
+		try {
1106
+			error_log($exception_log);
1107
+		} catch (EE_Error $e) {
1108
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1109
+				'event_espresso'), $e->getMessage()));
1110
+		}
1111
+	}
1112
+
1113
+
1114
+
1115
+	/**
1116
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1117
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1118
+	 * but the code execution is done in a manner that could lead to unexpected results
1119
+	 * (i.e. running to early, or too late in WP or EE loading process).
1120
+	 * A good test for knowing whether to use this method is:
1121
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1122
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1123
+	 * 2. If this is loaded before something else, it won't break anything,
1124
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1125
+	 *
1126
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1127
+	 * @param string $function      The function that was called
1128
+	 * @param string $message       A message explaining what has been done incorrectly
1129
+	 * @param string $version       The version of Event Espresso where the error was added
1130
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1131
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1132
+	 *                              but not have any notices appear until a later version. This allows developers
1133
+	 *                              extra time to update their code before notices appear.
1134
+	 * @param int    $error_type
1135
+	 */
1136
+	public static function doing_it_wrong(
1137
+		$function,
1138
+		$message,
1139
+		$version,
1140
+		$applies_when = '',
1141
+		$error_type = null
1142
+	) {
1143
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1144
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1145
+		}
1146
+	}
1147
+
1148
+
1149
+
1150
+	/**
1151
+	 * Like get_notices, but returns an array of all the notices of the given type.
1152
+	 *
1153
+	 * @return array {
1154
+	 *  @type array $success   all the success messages
1155
+	 *  @type array $errors    all the error messages
1156
+	 *  @type array $attention all the attention messages
1157
+	 * }
1158
+	 */
1159
+	public static function get_raw_notices()
1160
+	{
1161
+		return self::$_espresso_notices;
1162
+	}
1163
+
1164
+
1165
+
1166
+	/**
1167
+	 * @deprecated 4.9.27
1168
+	 * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1169
+	 * @param string $pan_message  the message to be stored persistently until dismissed
1170
+	 * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1171
+	 * @return void
1172
+	 * @throws InvalidDataTypeException
1173
+	 */
1174
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1175
+	{
1176
+		new PersistentAdminNotice(
1177
+			$pan_name,
1178
+			$pan_message,
1179
+			$force_update
1180
+		);
1181
+		EE_Error::doing_it_wrong(
1182
+			__METHOD__,
1183
+			sprintf(
1184
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1185
+				'\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1186
+			),
1187
+			'4.9.27'
1188
+		);
1189
+	}
1190
+
1191
+
1192
+
1193
+	/**
1194
+	 * @deprecated 4.9.27
1195
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1196
+	 * @param bool   $purge
1197
+	 * @param bool   $return
1198
+	 * @throws DomainException
1199
+	 * @throws InvalidInterfaceException
1200
+	 * @throws InvalidDataTypeException
1201
+	 * @throws ServiceNotFoundException
1202
+	 * @throws InvalidArgumentException
1203
+	 */
1204
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1205
+	{
1206
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1207
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1208
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1209
+		);
1210
+		$persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1211
+		EE_Error::doing_it_wrong(
1212
+			__METHOD__,
1213
+			sprintf(
1214
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1215
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1216
+			),
1217
+			'4.9.27'
1218
+		);
1219
+	}
1220
+
1221
+
1222
+
1223
+	/**
1224
+	 * @deprecated 4.9.27
1225
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1226
+	 * @param  string $pan_message the message to be stored persistently until dismissed
1227
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
1228
+	 */
1229
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1230
+	{
1231
+		EE_Error::doing_it_wrong(
1232
+			__METHOD__,
1233
+			sprintf(
1234
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1235
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1236
+			),
1237
+			'4.9.27'
1238
+		);
1239
+	}
1240
+
1241
+
1242
+
1243
+	/**
1244
+	 * @deprecated 4.9.27
1245
+	 * @param string $return_url
1246
+	 */
1247
+	public static function get_persistent_admin_notices($return_url = '')
1248
+	{
1249
+		EE_Error::doing_it_wrong(
1250
+			__METHOD__,
1251
+			sprintf(
1252
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1253
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1254
+			),
1255
+			'4.9.27'
1256
+		);
1257
+	}
1258 1258
 
1259 1259
 
1260 1260
 
@@ -1269,27 +1269,27 @@  discard block
 block discarded – undo
1269 1269
  */
1270 1270
 function espresso_error_enqueue_scripts()
1271 1271
 {
1272
-    // js for error handling
1273
-    wp_register_script(
1274
-        'espresso_core',
1275
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1276
-        array('jquery'),
1277
-        EVENT_ESPRESSO_VERSION,
1278
-        false
1279
-    );
1280
-    wp_register_script(
1281
-        'ee_error_js',
1282
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1283
-        array('espresso_core'),
1284
-        EVENT_ESPRESSO_VERSION,
1285
-        false
1286
-    );
1272
+	// js for error handling
1273
+	wp_register_script(
1274
+		'espresso_core',
1275
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1276
+		array('jquery'),
1277
+		EVENT_ESPRESSO_VERSION,
1278
+		false
1279
+	);
1280
+	wp_register_script(
1281
+		'ee_error_js',
1282
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1283
+		array('espresso_core'),
1284
+		EVENT_ESPRESSO_VERSION,
1285
+		false
1286
+	);
1287 1287
 }
1288 1288
 
1289 1289
 if (is_admin()) {
1290
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1290
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1291 1291
 } else {
1292
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1292
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1293 1293
 }
1294 1294
 
1295 1295
 
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
             default :
103 103
                 $to = get_option('admin_email');
104 104
         }
105
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
105
+        $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
106 106
         $msg = EE_Error::_format_error($type, $message, $file, $line);
107 107
         if (function_exists('wp_mail')) {
108 108
             add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
109 109
             wp_mail($to, $subject, $msg);
110 110
         }
111 111
         echo '<div id="message" class="espresso-notices error"><p>';
112
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
112
+        echo $type.': '.$message.'<br />'.$file.' line '.$line;
113 113
         echo '<br /></p></div>';
114 114
     }
115 115
 
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 	}
335 335
 </style>
336 336
 <div id="ee-error-message" class="error">';
337
-        if (! WP_DEBUG) {
337
+        if ( ! WP_DEBUG) {
338 338
             $output .= '
339 339
 	<p>';
340 340
         }
@@ -393,14 +393,14 @@  discard block
 block discarded – undo
393 393
                     $class_dsply = ! empty($class) ? $class : '&nbsp;';
394 394
                     $type_dsply = ! empty($type) ? $type : '&nbsp;';
395 395
                     $function_dsply = ! empty($function) ? $function : '&nbsp;';
396
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
396
+                    $args_dsply = ! empty($args) ? '( '.$args.' )' : '';
397 397
                     $trace_details .= '
398 398
 					<tr>
399
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
400
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
401
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
402
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
403
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
399
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
400
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
401
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
402
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
403
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
404 404
 					</tr>';
405 405
                 }
406 406
                 $trace_details .= '
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
             }
410 410
             $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
411 411
             // add generic non-identifying messages for non-privileged users
412
-            if (! WP_DEBUG) {
412
+            if ( ! WP_DEBUG) {
413 413
                 $output .= '<span class="ee-error-user-msg-spn">'
414 414
                            . trim($ex['msg'])
415 415
                            . '</span> &nbsp; <sup>'
@@ -451,14 +451,14 @@  discard block
 block discarded – undo
451 451
                            . '-dv" class="ee-error-trace-dv" style="display: none;">
452 452
 				'
453 453
                            . $trace_details;
454
-                if (! empty($class)) {
454
+                if ( ! empty($class)) {
455 455
                     $output .= '
456 456
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
457 457
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
458 458
 						<h3>Class Details</h3>';
459 459
                     $a = new ReflectionClass($class);
460 460
                     $output .= '
461
-						<pre>' . $a . '</pre>
461
+						<pre>' . $a.'</pre>
462 462
 					</div>
463 463
 				</div>';
464 464
                 }
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
         }
472 472
         // remove last linebreak
473 473
         $output = substr($output, 0, -6);
474
-        if (! WP_DEBUG) {
474
+        if ( ! WP_DEBUG) {
475 475
             $output .= '
476 476
 	</p>';
477 477
         }
@@ -498,20 +498,20 @@  discard block
 block discarded – undo
498 498
     private function _convert_args_to_string($arguments = array(), $array = false)
499 499
     {
500 500
         $arg_string = '';
501
-        if (! empty($arguments)) {
501
+        if ( ! empty($arguments)) {
502 502
             $args = array();
503 503
             foreach ($arguments as $arg) {
504
-                if (! empty($arg)) {
504
+                if ( ! empty($arg)) {
505 505
                     if (is_string($arg)) {
506
-                        $args[] = " '" . $arg . "'";
506
+                        $args[] = " '".$arg."'";
507 507
                     } elseif (is_array($arg)) {
508
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
508
+                        $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true);
509 509
                     } elseif ($arg === null) {
510 510
                         $args[] = ' NULL';
511 511
                     } elseif (is_bool($arg)) {
512 512
                         $args[] = ($arg) ? ' TRUE' : ' FALSE';
513 513
                     } elseif (is_object($arg)) {
514
-                        $args[] = ' OBJECT ' . get_class($arg);
514
+                        $args[] = ' OBJECT '.get_class($arg);
515 515
                     } elseif (is_resource($arg)) {
516 516
                         $args[] = get_resource_type($arg);
517 517
                     } else {
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
     {
615 615
         if (empty($msg)) {
616 616
             EE_Error::doing_it_wrong(
617
-                'EE_Error::add_' . $type . '()',
617
+                'EE_Error::add_'.$type.'()',
618 618
                 sprintf(
619 619
                     __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
620 620
                         'event_espresso'),
@@ -650,11 +650,11 @@  discard block
 block discarded – undo
650 650
         do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
651 651
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
652 652
         // add notice if message exists
653
-        if (! empty($msg)) {
653
+        if ( ! empty($msg)) {
654 654
             // get error code
655 655
             $notice_code = EE_Error::generate_error_code($file, $func, $line);
656 656
             if (WP_DEBUG && $type === 'errors') {
657
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
657
+                $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
658 658
             }
659 659
             // add notice. Index by code if it's not blank
660 660
             if ($notice_code) {
@@ -882,13 +882,13 @@  discard block
 block discarded – undo
882 882
         if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
883 883
             // combine messages
884 884
             $success_messages .= implode(self::$_espresso_notices['success'], '<br />');
885
-            $print_scripts    = true;
885
+            $print_scripts = true;
886 886
         }
887 887
         // check for attention messages
888 888
         if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
889 889
             // combine messages
890 890
             $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
891
-            $print_scripts      = true;
891
+            $print_scripts = true;
892 892
         }
893 893
         // check for error messages
894 894
         if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
                 : __('An error has occurred:<br />', 'event_espresso');
898 898
             // combine messages
899 899
             $error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
900
-            $print_scripts  = true;
900
+            $print_scripts = true;
901 901
         }
902 902
         if ($format_output) {
903 903
             $notices = EE_Error::formatNoticesOutput(
@@ -938,16 +938,16 @@  discard block
 block discarded – undo
938 938
         $print_scripts = false;
939 939
         // grab any notices that have been previously saved
940 940
         $notices = EE_Error::getStoredNotices();
941
-        if (! empty($notices)) {
941
+        if ( ! empty($notices)) {
942 942
             foreach ($notices as $type => $notice) {
943 943
                 if (is_array($notice) && ! empty($notice)) {
944 944
                     // make sure that existing notice type is an array
945
-                    self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
946
-                                                        && ! empty(self::$_espresso_notices[ $type ])
947
-                        ? self::$_espresso_notices[ $type ]
945
+                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
946
+                                                        && ! empty(self::$_espresso_notices[$type])
947
+                        ? self::$_espresso_notices[$type]
948 948
                         : array();
949 949
                     // add newly created notices to existing ones
950
-                    self::$_espresso_notices[ $type ] += $notice;
950
+                    self::$_espresso_notices[$type] += $notice;
951 951
                     $print_scripts = true;
952 952
                 }
953 953
             }
@@ -974,10 +974,10 @@  discard block
 block discarded – undo
974 974
             $css_id    = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
975 975
             $css_class = is_admin() ? 'updated fade' : 'success fade-away';
976 976
             //showMessage( $success_messages );
977
-            $notices .= '<div id="' . $css_id . '" '
978
-                        . 'class="espresso-notices ' . $css_class . '" '
977
+            $notices .= '<div id="'.$css_id.'" '
978
+                        . 'class="espresso-notices '.$css_class.'" '
979 979
                         . 'style="display:none;">'
980
-                        . '<p>' . $success_messages . '</p>'
980
+                        . '<p>'.$success_messages.'</p>'
981 981
                         . $close
982 982
                         . '</div>';
983 983
         }
@@ -985,10 +985,10 @@  discard block
 block discarded – undo
985 985
             $css_id    = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
986 986
             $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
987 987
             //showMessage( $error_messages, TRUE );
988
-            $notices .= '<div id="' . $css_id . '" '
989
-                        . 'class="espresso-notices ' . $css_class . '" '
988
+            $notices .= '<div id="'.$css_id.'" '
989
+                        . 'class="espresso-notices '.$css_class.'" '
990 990
                         . 'style="display:none;">'
991
-                        . '<p>' . $attention_messages . '</p>'
991
+                        . '<p>'.$attention_messages.'</p>'
992 992
                         . $close
993 993
                         . '</div>';
994 994
         }
@@ -996,10 +996,10 @@  discard block
 block discarded – undo
996 996
             $css_id    = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
997 997
             $css_class = is_admin() ? 'error' : 'error fade-away';
998 998
             //showMessage( $error_messages, TRUE );
999
-            $notices .= '<div id="' . $css_id . '" '
1000
-                        . 'class="espresso-notices ' . $css_class . '" '
999
+            $notices .= '<div id="'.$css_id.'" '
1000
+                        . 'class="espresso-notices '.$css_class.'" '
1001 1001
                         . 'style="display:none;">'
1002
-                        . '<p>' . $error_messages . '</p>'
1002
+                        . '<p>'.$error_messages.'</p>'
1003 1003
                         . $close
1004 1004
                         . '</div>';
1005 1005
         }
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
      */
1018 1018
     private static function _print_scripts($force_print = false)
1019 1019
     {
1020
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1020
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1021 1021
             if (wp_script_is('ee_error_js', 'enqueued')) {
1022 1022
                 return '';
1023 1023
             }
@@ -1031,12 +1031,12 @@  discard block
 block discarded – undo
1031 1031
             return '
1032 1032
 <script>
1033 1033
 /* <![CDATA[ */
1034
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1034
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1035 1035
 /* ]]> */
1036 1036
 </script>
1037
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1038
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1039
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1037
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1038
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1039
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1040 1040
 ';
1041 1041
         }
1042 1042
         return '';
@@ -1067,8 +1067,8 @@  discard block
 block discarded – undo
1067 1067
     {
1068 1068
         $file       = explode('.', basename($file));
1069 1069
         $error_code = ! empty($file[0]) ? $file[0] : '';
1070
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1071
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1070
+        $error_code .= ! empty($func) ? ' - '.$func : '';
1071
+        $error_code .= ! empty($line) ? ' - '.$line : '';
1072 1072
         return $error_code;
1073 1073
     }
1074 1074
 
@@ -1088,18 +1088,18 @@  discard block
 block discarded – undo
1088 1088
         if (empty($ex)) {
1089 1089
             return;
1090 1090
         }
1091
-        if (! $time) {
1091
+        if ( ! $time) {
1092 1092
             $time = time();
1093 1093
         }
1094 1094
         $exception_log = '----------------------------------------------------------------------------------------'
1095 1095
                          . PHP_EOL;
1096
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1097
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1098
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1099
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1100
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1101
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1102
-        $exception_log .= $ex['string'] . PHP_EOL;
1096
+        $exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1097
+        $exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1098
+        $exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1099
+        $exception_log .= 'File: '.$ex['file'].PHP_EOL;
1100
+        $exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1101
+        $exception_log .= 'Stack trace: '.PHP_EOL;
1102
+        $exception_log .= $ex['string'].PHP_EOL;
1103 1103
         $exception_log .= '----------------------------------------------------------------------------------------'
1104 1104
                           . PHP_EOL;
1105 1105
         try {
@@ -1272,14 +1272,14 @@  discard block
 block discarded – undo
1272 1272
     // js for error handling
1273 1273
     wp_register_script(
1274 1274
         'espresso_core',
1275
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1275
+        EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1276 1276
         array('jquery'),
1277 1277
         EVENT_ESPRESSO_VERSION,
1278 1278
         false
1279 1279
     );
1280 1280
     wp_register_script(
1281 1281
         'ee_error_js',
1282
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1282
+        EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1283 1283
         array('espresso_core'),
1284 1284
         EVENT_ESPRESSO_VERSION,
1285 1285
         false
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 2 patches
Indentation   +659 added lines, -659 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,649 +17,649 @@  discard block
 block discarded – undo
17 17
 class EEH_Debug_Tools
18 18
 {
19 19
 
20
-    /**
21
-     *    instance of the EEH_Autoloader object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $_memory_usage_points = array();
32
-
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @access    public
38
-     * @return EEH_Debug_Tools
39
-     */
40
-    public static function instance()
41
-    {
42
-        // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
44
-            self::$_instance = new self();
45
-        }
46
-        return self::$_instance;
47
-    }
48
-
49
-
50
-
51
-    /**
52
-     * private class constructor
53
-     */
54
-    private function __construct()
55
-    {
56
-        // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
59
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
-            // so we've moved it to our test folder so that it is not included with production releases
62
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
-        }
65
-        // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
-        //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
-        // }
68
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
69
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     *    show_db_name
78
-     *
79
-     * @return void
80
-     */
81
-    public static function show_db_name()
82
-    {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
-                 . DB_NAME
86
-                 . '</p>';
87
-        }
88
-        if (EE_DEBUG) {
89
-            Benchmark::displayResults();
90
-        }
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    dump EE_Session object at bottom of page after everything else has happened
97
-     *
98
-     * @return void
99
-     */
100
-    public function espresso_session_footer_dump()
101
-    {
102
-        if (
103
-            (defined('WP_DEBUG') && WP_DEBUG)
104
-            && ! defined('DOING_AJAX')
105
-            && class_exists('Kint')
106
-            && function_exists('wp_get_current_user')
107
-            && current_user_can('update_core')
108
-            && class_exists('EE_Registry')
109
-        ) {
110
-            Kint::dump(EE_Registry::instance()->SSN->id());
111
-            Kint::dump(EE_Registry::instance()->SSN);
112
-            //			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
-            $this->espresso_list_hooked_functions();
114
-            Benchmark::displayResults();
115
-        }
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     *    List All Hooked Functions
122
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
-     *
125
-     * @param string $tag
126
-     * @return void
127
-     */
128
-    public function espresso_list_hooked_functions($tag = '')
129
-    {
130
-        global $wp_filter;
131
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
-        if ($tag) {
133
-            $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
135
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
-                return;
137
-            }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
139
-        } else {
140
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
-            ksort($hook);
142
-        }
143
-        foreach ($hook as $tag_name => $priorities) {
144
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
-            ksort($priorities);
146
-            foreach ($priorities as $priority => $function) {
147
-                echo $priority;
148
-                foreach ($function as $name => $properties) {
149
-                    echo "\t$name<br />";
150
-                }
151
-            }
152
-        }
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     *    registered_filter_callbacks
159
-     *
160
-     * @param string $hook_name
161
-     * @return array
162
-     */
163
-    public static function registered_filter_callbacks($hook_name = '')
164
-    {
165
-        $filters = array();
166
-        global $wp_filter;
167
-        if (isset($wp_filter[$hook_name])) {
168
-            $filters[$hook_name] = array();
169
-            foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
-                $filters[$hook_name][$priority] = array();
171
-                foreach ($callbacks as $callback) {
172
-                    $filters[$hook_name][$priority][] = $callback['function'];
173
-                }
174
-            }
175
-        }
176
-        return $filters;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     *    captures plugin activation errors for debugging
183
-     *
184
-     * @return void
185
-     * @throws EE_Error
186
-     */
187
-    public static function ee_plugin_activation_errors()
188
-    {
189
-        if (WP_DEBUG) {
190
-            $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
-            }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
-            if (class_exists('EEH_File')) {
196
-                try {
197
-                    EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
-                    );
200
-                    EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
-                        $activation_errors
203
-                    );
204
-                } catch (EE_Error $e) {
205
-                    EE_Error::add_error(
206
-                        sprintf(
207
-                            __(
208
-                                'The Event Espresso activation errors file could not be setup because: %s',
209
-                                'event_espresso'
210
-                            ),
211
-                            $e->getMessage()
212
-                        ),
213
-                        __FILE__, __FUNCTION__, __LINE__
214
-                    );
215
-                }
216
-            } else {
217
-                // old school attempt
218
-                file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
-                    $activation_errors
221
-                );
222
-            }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
-            update_option('ee_plugin_activation_errors', $activation_errors);
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
-     * or we want to make sure they use something the right way.
234
-     *
235
-     * @access public
236
-     * @param string $function      The function that was called
237
-     * @param string $message       A message explaining what has been done incorrectly
238
-     * @param string $version       The version of Event Espresso where the error was added
239
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
-     *                              for a deprecated function. This allows deprecation to occur during one version,
241
-     *                              but not have any notices appear until a later version. This allows developers
242
-     *                              extra time to update their code before notices appear.
243
-     * @param int    $error_type
244
-     * @uses   trigger_error()
245
-     */
246
-    public function doing_it_wrong(
247
-        $function,
248
-        $message,
249
-        $version,
250
-        $applies_when = '',
251
-        $error_type = null
252
-    ) {
253
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
-        // because we swapped the parameter order around for the last two params,
256
-        // let's verify that some third party isn't still passing an error type value for the third param
257
-        if (is_int($applies_when)) {
258
-            $error_type = $applies_when;
259
-            $applies_when = espresso_version();
260
-        }
261
-        // if not displaying notices yet, then just leave
262
-        if (version_compare(espresso_version(), $applies_when, '<')) {
263
-            return;
264
-        }
265
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
-        $version = $version === null
267
-            ? ''
268
-            : sprintf(
269
-                __('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
-                $version
271
-            );
272
-        $error_message = sprintf(
273
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
-            $function,
275
-            '<strong>',
276
-            '</strong>',
277
-            $message,
278
-            $version
279
-        );
280
-        // don't trigger error if doing ajax,
281
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
-        if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
284
-                    'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
-                    'event_espresso'
286
-                );
287
-            $error_message .= '<ul><li>';
288
-            $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
-            $error_message .= '</ul>';
290
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
-            //now we set this on the transient so it shows up on the next request.
292
-            EE_Error::get_notices(false, true);
293
-        } else {
294
-            trigger_error($error_message, $error_type);
295
-        }
296
-    }
297
-
298
-
299
-
300
-
301
-    /**
302
-     * Logger helpers
303
-     */
304
-    /**
305
-     * debug
306
-     *
307
-     * @param string $class
308
-     * @param string $func
309
-     * @param string $line
310
-     * @param array  $info
311
-     * @param bool   $display_request
312
-     * @param string $debug_index
313
-     * @param string $debug_key
314
-     * @throws EE_Error
315
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
-     */
317
-    public static function log(
318
-        $class = '',
319
-        $func = '',
320
-        $line = '',
321
-        $info = array(),
322
-        $display_request = false,
323
-        $debug_index = '',
324
-        $debug_key = 'EE_DEBUG_SPCO'
325
-    ) {
326
-        if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
-            $debug_data = get_option($debug_key, array());
329
-            $default_data = array(
330
-                $class => $func . '() : ' . $line,
331
-                'REQ'  => $display_request ? $_REQUEST : '',
332
-            );
333
-            // don't serialize objects
334
-            $info = self::strip_objects($info);
335
-            $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
337
-                $debug_data[$index] = array();
338
-            }
339
-            $debug_data[$index][microtime()] = array_merge($default_data, $info);
340
-            update_option($debug_key, $debug_data);
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * strip_objects
348
-     *
349
-     * @param array $info
350
-     * @return array
351
-     */
352
-    public static function strip_objects($info = array())
353
-    {
354
-        foreach ($info as $key => $value) {
355
-            if (is_array($value)) {
356
-                $info[$key] = self::strip_objects($value);
357
-            } else if (is_object($value)) {
358
-                $object_class = get_class($value);
359
-                $info[$object_class] = array();
360
-                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
-                if (method_exists($value, 'ID')) {
362
-                    $info[$object_class]['ID'] = $value->ID();
363
-                }
364
-                if (method_exists($value, 'status')) {
365
-                    $info[$object_class]['status'] = $value->status();
366
-                } else if (method_exists($value, 'status_ID')) {
367
-                    $info[$object_class]['status'] = $value->status_ID();
368
-                }
369
-                unset($info[$key]);
370
-            }
371
-        }
372
-        return (array)$info;
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * @param mixed      $var
379
-     * @param string     $var_name
380
-     * @param string     $file
381
-     * @param int|string $line
382
-     * @param int        $heading_tag
383
-     * @param bool       $die
384
-     * @param string     $margin
385
-     */
386
-    public static function printv(
387
-        $var,
388
-        $var_name = '',
389
-        $file = '',
390
-        $line = '',
391
-        $heading_tag = 5,
392
-        $die = false,
393
-        $margin = ''
394
-    ) {
395
-        $var_name = ! $var_name ? 'string' : $var_name;
396
-        $var_name = ucwords(str_replace('$', '', $var_name));
397
-        $is_method = method_exists($var_name, $var);
398
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
399
-        $heading_tag = absint($heading_tag);
400
-        $result = $heading_tag < 3 ? "\n" : '';
401
-        $heading_tag = $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
402
-        $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
403
-        $result .= $is_method
404
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
405
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
406
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
407
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
408
-        if ($die) {
409
-            die($result);
410
-        }
411
-        echo $result;
412
-    }
413
-
414
-
415
-    protected static function plainOutput()
416
-    {
417
-        return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX);
418
-    }
419
-
420
-
421
-    /**
422
-     * @param string $var_name
423
-     * @param string $heading_tag
424
-     * @param string $margin
425
-     * @param int    $line
426
-     * @return string
427
-     */
428
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
429
-    {
430
-        if (EEH_Debug_Tools::plainOutput()) {
431
-            $heading = '';
432
-            if($heading_tag === 'h1' || $heading_tag === 'h2') {
433
-                $heading .= "\n";
434
-            }
435
-            $heading .= "\n{$line}) {$var_name}";
436
-            return $heading;
437
-        }
438
-        $margin = "25px 0 0 {$margin}";
439
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
440
-    }
441
-
442
-
443
-
444
-    /**
445
-     * @param string $heading_tag
446
-     * @return string
447
-     */
448
-    protected static function headingX($heading_tag = 'h5')
449
-    {
450
-        if (EEH_Debug_Tools::plainOutput()) {
451
-            return '';
452
-        }
453
-        return '</' . $heading_tag . '>';
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     * @param string $content
460
-     * @return string
461
-     */
462
-    protected static function grey_span($content = '')
463
-    {
464
-        if (EEH_Debug_Tools::plainOutput()) {
465
-            return $content;
466
-        }
467
-        return '<span style="color:#999">' . $content . '</span>';
468
-    }
469
-
470
-
471
-
472
-    /**
473
-     * @param string $file
474
-     * @param int    $line
475
-     * @return string
476
-     */
477
-    protected static function file_and_line($file, $line, $heading_tag)
478
-    {
479
-        if ($file === '' || $line === '') {
480
-            return '';
481
-        }
482
-        $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
483
-        if (EEH_Debug_Tools::plainOutput()) {
484
-            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
485
-                return " ({$file})";
486
-            }
487
-            return '';
488
-        }
489
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
490
-               . $file
491
-               . '<br />line no: '
492
-               . $line
493
-               . '</span>';
494
-    }
495
-
496
-
497
-
498
-    /**
499
-     * @param string $content
500
-     * @return string
501
-     */
502
-    protected static function orange_span($content = '')
503
-    {
504
-        if (EEH_Debug_Tools::plainOutput()) {
505
-            return $content;
506
-        }
507
-        return '<span style="color:#E76700">' . $content . '</span>';
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * @param mixed $var
514
-     * @return string
515
-     */
516
-    protected static function pre_span($var)
517
-    {
518
-        ob_start();
519
-        var_dump($var);
520
-        $var = ob_get_clean();
521
-        if (EEH_Debug_Tools::plainOutput()) {
522
-            return "\n" . $var;
523
-        }
524
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * @param mixed      $var
531
-     * @param string     $var_name
532
-     * @param string     $file
533
-     * @param int|string $line
534
-     * @param int        $heading_tag
535
-     * @param bool       $die
536
-     */
537
-    public static function printr(
538
-        $var,
539
-        $var_name = '',
540
-        $file = '',
541
-        $line = '',
542
-        $heading_tag = 5,
543
-        $die = false
544
-    ) {
545
-        // return;
546
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
547
-        $margin = is_admin() ? ' 180px' : '0';
548
-        //$print_r = false;
549
-        if (is_string($var)) {
550
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
551
-            return;
552
-        }
553
-        if (is_object($var)) {
554
-            $var_name = ! $var_name ? 'object' : $var_name;
555
-            //$print_r = true;
556
-        } else if (is_array($var)) {
557
-            $var_name = ! $var_name ? 'array' : $var_name;
558
-            //$print_r = true;
559
-        } else if (is_numeric($var)) {
560
-            $var_name = ! $var_name ? 'numeric' : $var_name;
561
-        } else if ($var === null) {
562
-            $var_name = ! $var_name ? 'null' : $var_name;
563
-        }
564
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
565
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
566
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
567
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
568
-                EEH_Debug_Tools::pre_span($var)
569
-            );
570
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
571
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
572
-        if ($die) {
573
-            die($result);
574
-        }
575
-        echo $result;
576
-    }
577
-
578
-
579
-
580
-    /******************** deprecated ********************/
581
-
582
-
583
-
584
-    /**
585
-     * @deprecated 4.9.39.rc.034
586
-     */
587
-    public function reset_times()
588
-    {
589
-        Benchmark::resetTimes();
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     * @deprecated 4.9.39.rc.034
596
-     * @param null $timer_name
597
-     */
598
-    public function start_timer($timer_name = null)
599
-    {
600
-        Benchmark::startTimer($timer_name);
601
-    }
602
-
603
-
604
-
605
-    /**
606
-     * @deprecated 4.9.39.rc.034
607
-     * @param string $timer_name
608
-     */
609
-    public function stop_timer($timer_name = '')
610
-    {
611
-        Benchmark::stopTimer($timer_name);
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * @deprecated 4.9.39.rc.034
618
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
619
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
620
-     * @return void
621
-     */
622
-    public function measure_memory($label, $output_now = false)
623
-    {
624
-        Benchmark::measureMemory($label, $output_now);
625
-    }
626
-
627
-
628
-
629
-    /**
630
-     * @deprecated 4.9.39.rc.034
631
-     * @param int $size
632
-     * @return string
633
-     */
634
-    public function convert($size)
635
-    {
636
-        return Benchmark::convert($size);
637
-    }
638
-
639
-
640
-
641
-    /**
642
-     * @deprecated 4.9.39.rc.034
643
-     * @param bool $output_now
644
-     * @return string
645
-     */
646
-    public function show_times($output_now = true)
647
-    {
648
-        return Benchmark::displayResults($output_now);
649
-    }
650
-
651
-
652
-
653
-    /**
654
-     * @deprecated 4.9.39.rc.034
655
-     * @param string $timer_name
656
-     * @param float  $total_time
657
-     * @return string
658
-     */
659
-    public function format_time($timer_name, $total_time)
660
-    {
661
-        return Benchmark::formatTime($timer_name, $total_time);
662
-    }
20
+	/**
21
+	 *    instance of the EEH_Autoloader object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $_memory_usage_points = array();
32
+
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @access    public
38
+	 * @return EEH_Debug_Tools
39
+	 */
40
+	public static function instance()
41
+	{
42
+		// check if class object is instantiated, and instantiated properly
43
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
44
+			self::$_instance = new self();
45
+		}
46
+		return self::$_instance;
47
+	}
48
+
49
+
50
+
51
+	/**
52
+	 * private class constructor
53
+	 */
54
+	private function __construct()
55
+	{
56
+		// load Kint PHP debugging library
57
+		if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
59
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
+			// so we've moved it to our test folder so that it is not included with production releases
62
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
+			require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
+		}
65
+		// if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
+		//add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
+		// }
68
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
69
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 *    show_db_name
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function show_db_name()
82
+	{
83
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
+				 . DB_NAME
86
+				 . '</p>';
87
+		}
88
+		if (EE_DEBUG) {
89
+			Benchmark::displayResults();
90
+		}
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    dump EE_Session object at bottom of page after everything else has happened
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public function espresso_session_footer_dump()
101
+	{
102
+		if (
103
+			(defined('WP_DEBUG') && WP_DEBUG)
104
+			&& ! defined('DOING_AJAX')
105
+			&& class_exists('Kint')
106
+			&& function_exists('wp_get_current_user')
107
+			&& current_user_can('update_core')
108
+			&& class_exists('EE_Registry')
109
+		) {
110
+			Kint::dump(EE_Registry::instance()->SSN->id());
111
+			Kint::dump(EE_Registry::instance()->SSN);
112
+			//			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
+			$this->espresso_list_hooked_functions();
114
+			Benchmark::displayResults();
115
+		}
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 *    List All Hooked Functions
122
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
+	 *
125
+	 * @param string $tag
126
+	 * @return void
127
+	 */
128
+	public function espresso_list_hooked_functions($tag = '')
129
+	{
130
+		global $wp_filter;
131
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
+		if ($tag) {
133
+			$hook[$tag] = $wp_filter[$tag];
134
+			if (! is_array($hook[$tag])) {
135
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
+				return;
137
+			}
138
+			echo '<h5>For Tag: ' . $tag . '</h5>';
139
+		} else {
140
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
+			ksort($hook);
142
+		}
143
+		foreach ($hook as $tag_name => $priorities) {
144
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
+			ksort($priorities);
146
+			foreach ($priorities as $priority => $function) {
147
+				echo $priority;
148
+				foreach ($function as $name => $properties) {
149
+					echo "\t$name<br />";
150
+				}
151
+			}
152
+		}
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 *    registered_filter_callbacks
159
+	 *
160
+	 * @param string $hook_name
161
+	 * @return array
162
+	 */
163
+	public static function registered_filter_callbacks($hook_name = '')
164
+	{
165
+		$filters = array();
166
+		global $wp_filter;
167
+		if (isset($wp_filter[$hook_name])) {
168
+			$filters[$hook_name] = array();
169
+			foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
+				$filters[$hook_name][$priority] = array();
171
+				foreach ($callbacks as $callback) {
172
+					$filters[$hook_name][$priority][] = $callback['function'];
173
+				}
174
+			}
175
+		}
176
+		return $filters;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 *    captures plugin activation errors for debugging
183
+	 *
184
+	 * @return void
185
+	 * @throws EE_Error
186
+	 */
187
+	public static function ee_plugin_activation_errors()
188
+	{
189
+		if (WP_DEBUG) {
190
+			$activation_errors = ob_get_contents();
191
+			if (! empty($activation_errors)) {
192
+				$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
+			}
194
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
+			if (class_exists('EEH_File')) {
196
+				try {
197
+					EEH_File::ensure_file_exists_and_is_writable(
198
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
+					);
200
+					EEH_File::write_to_file(
201
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
+						$activation_errors
203
+					);
204
+				} catch (EE_Error $e) {
205
+					EE_Error::add_error(
206
+						sprintf(
207
+							__(
208
+								'The Event Espresso activation errors file could not be setup because: %s',
209
+								'event_espresso'
210
+							),
211
+							$e->getMessage()
212
+						),
213
+						__FILE__, __FUNCTION__, __LINE__
214
+					);
215
+				}
216
+			} else {
217
+				// old school attempt
218
+				file_put_contents(
219
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
+					$activation_errors
221
+				);
222
+			}
223
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
+			update_option('ee_plugin_activation_errors', $activation_errors);
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
+	 * or we want to make sure they use something the right way.
234
+	 *
235
+	 * @access public
236
+	 * @param string $function      The function that was called
237
+	 * @param string $message       A message explaining what has been done incorrectly
238
+	 * @param string $version       The version of Event Espresso where the error was added
239
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
241
+	 *                              but not have any notices appear until a later version. This allows developers
242
+	 *                              extra time to update their code before notices appear.
243
+	 * @param int    $error_type
244
+	 * @uses   trigger_error()
245
+	 */
246
+	public function doing_it_wrong(
247
+		$function,
248
+		$message,
249
+		$version,
250
+		$applies_when = '',
251
+		$error_type = null
252
+	) {
253
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
+		// because we swapped the parameter order around for the last two params,
256
+		// let's verify that some third party isn't still passing an error type value for the third param
257
+		if (is_int($applies_when)) {
258
+			$error_type = $applies_when;
259
+			$applies_when = espresso_version();
260
+		}
261
+		// if not displaying notices yet, then just leave
262
+		if (version_compare(espresso_version(), $applies_when, '<')) {
263
+			return;
264
+		}
265
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
+		$version = $version === null
267
+			? ''
268
+			: sprintf(
269
+				__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
+				$version
271
+			);
272
+		$error_message = sprintf(
273
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
+			$function,
275
+			'<strong>',
276
+			'</strong>',
277
+			$message,
278
+			$version
279
+		);
280
+		// don't trigger error if doing ajax,
281
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
+		if (defined('DOING_AJAX') && DOING_AJAX) {
283
+			$error_message .= ' ' . esc_html__(
284
+					'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
+					'event_espresso'
286
+				);
287
+			$error_message .= '<ul><li>';
288
+			$error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
+			$error_message .= '</ul>';
290
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
+			//now we set this on the transient so it shows up on the next request.
292
+			EE_Error::get_notices(false, true);
293
+		} else {
294
+			trigger_error($error_message, $error_type);
295
+		}
296
+	}
297
+
298
+
299
+
300
+
301
+	/**
302
+	 * Logger helpers
303
+	 */
304
+	/**
305
+	 * debug
306
+	 *
307
+	 * @param string $class
308
+	 * @param string $func
309
+	 * @param string $line
310
+	 * @param array  $info
311
+	 * @param bool   $display_request
312
+	 * @param string $debug_index
313
+	 * @param string $debug_key
314
+	 * @throws EE_Error
315
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
+	 */
317
+	public static function log(
318
+		$class = '',
319
+		$func = '',
320
+		$line = '',
321
+		$info = array(),
322
+		$display_request = false,
323
+		$debug_index = '',
324
+		$debug_key = 'EE_DEBUG_SPCO'
325
+	) {
326
+		if (WP_DEBUG) {
327
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
+			$debug_data = get_option($debug_key, array());
329
+			$default_data = array(
330
+				$class => $func . '() : ' . $line,
331
+				'REQ'  => $display_request ? $_REQUEST : '',
332
+			);
333
+			// don't serialize objects
334
+			$info = self::strip_objects($info);
335
+			$index = ! empty($debug_index) ? $debug_index : 0;
336
+			if (! isset($debug_data[$index])) {
337
+				$debug_data[$index] = array();
338
+			}
339
+			$debug_data[$index][microtime()] = array_merge($default_data, $info);
340
+			update_option($debug_key, $debug_data);
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * strip_objects
348
+	 *
349
+	 * @param array $info
350
+	 * @return array
351
+	 */
352
+	public static function strip_objects($info = array())
353
+	{
354
+		foreach ($info as $key => $value) {
355
+			if (is_array($value)) {
356
+				$info[$key] = self::strip_objects($value);
357
+			} else if (is_object($value)) {
358
+				$object_class = get_class($value);
359
+				$info[$object_class] = array();
360
+				$info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
+				if (method_exists($value, 'ID')) {
362
+					$info[$object_class]['ID'] = $value->ID();
363
+				}
364
+				if (method_exists($value, 'status')) {
365
+					$info[$object_class]['status'] = $value->status();
366
+				} else if (method_exists($value, 'status_ID')) {
367
+					$info[$object_class]['status'] = $value->status_ID();
368
+				}
369
+				unset($info[$key]);
370
+			}
371
+		}
372
+		return (array)$info;
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * @param mixed      $var
379
+	 * @param string     $var_name
380
+	 * @param string     $file
381
+	 * @param int|string $line
382
+	 * @param int        $heading_tag
383
+	 * @param bool       $die
384
+	 * @param string     $margin
385
+	 */
386
+	public static function printv(
387
+		$var,
388
+		$var_name = '',
389
+		$file = '',
390
+		$line = '',
391
+		$heading_tag = 5,
392
+		$die = false,
393
+		$margin = ''
394
+	) {
395
+		$var_name = ! $var_name ? 'string' : $var_name;
396
+		$var_name = ucwords(str_replace('$', '', $var_name));
397
+		$is_method = method_exists($var_name, $var);
398
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
399
+		$heading_tag = absint($heading_tag);
400
+		$result = $heading_tag < 3 ? "\n" : '';
401
+		$heading_tag = $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
402
+		$result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
403
+		$result .= $is_method
404
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
405
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
406
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
407
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
408
+		if ($die) {
409
+			die($result);
410
+		}
411
+		echo $result;
412
+	}
413
+
414
+
415
+	protected static function plainOutput()
416
+	{
417
+		return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX);
418
+	}
419
+
420
+
421
+	/**
422
+	 * @param string $var_name
423
+	 * @param string $heading_tag
424
+	 * @param string $margin
425
+	 * @param int    $line
426
+	 * @return string
427
+	 */
428
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
429
+	{
430
+		if (EEH_Debug_Tools::plainOutput()) {
431
+			$heading = '';
432
+			if($heading_tag === 'h1' || $heading_tag === 'h2') {
433
+				$heading .= "\n";
434
+			}
435
+			$heading .= "\n{$line}) {$var_name}";
436
+			return $heading;
437
+		}
438
+		$margin = "25px 0 0 {$margin}";
439
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
440
+	}
441
+
442
+
443
+
444
+	/**
445
+	 * @param string $heading_tag
446
+	 * @return string
447
+	 */
448
+	protected static function headingX($heading_tag = 'h5')
449
+	{
450
+		if (EEH_Debug_Tools::plainOutput()) {
451
+			return '';
452
+		}
453
+		return '</' . $heading_tag . '>';
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 * @param string $content
460
+	 * @return string
461
+	 */
462
+	protected static function grey_span($content = '')
463
+	{
464
+		if (EEH_Debug_Tools::plainOutput()) {
465
+			return $content;
466
+		}
467
+		return '<span style="color:#999">' . $content . '</span>';
468
+	}
469
+
470
+
471
+
472
+	/**
473
+	 * @param string $file
474
+	 * @param int    $line
475
+	 * @return string
476
+	 */
477
+	protected static function file_and_line($file, $line, $heading_tag)
478
+	{
479
+		if ($file === '' || $line === '') {
480
+			return '';
481
+		}
482
+		$file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
483
+		if (EEH_Debug_Tools::plainOutput()) {
484
+			if ($heading_tag === 'h1' || $heading_tag === 'h2') {
485
+				return " ({$file})";
486
+			}
487
+			return '';
488
+		}
489
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
490
+			   . $file
491
+			   . '<br />line no: '
492
+			   . $line
493
+			   . '</span>';
494
+	}
495
+
496
+
497
+
498
+	/**
499
+	 * @param string $content
500
+	 * @return string
501
+	 */
502
+	protected static function orange_span($content = '')
503
+	{
504
+		if (EEH_Debug_Tools::plainOutput()) {
505
+			return $content;
506
+		}
507
+		return '<span style="color:#E76700">' . $content . '</span>';
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * @param mixed $var
514
+	 * @return string
515
+	 */
516
+	protected static function pre_span($var)
517
+	{
518
+		ob_start();
519
+		var_dump($var);
520
+		$var = ob_get_clean();
521
+		if (EEH_Debug_Tools::plainOutput()) {
522
+			return "\n" . $var;
523
+		}
524
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * @param mixed      $var
531
+	 * @param string     $var_name
532
+	 * @param string     $file
533
+	 * @param int|string $line
534
+	 * @param int        $heading_tag
535
+	 * @param bool       $die
536
+	 */
537
+	public static function printr(
538
+		$var,
539
+		$var_name = '',
540
+		$file = '',
541
+		$line = '',
542
+		$heading_tag = 5,
543
+		$die = false
544
+	) {
545
+		// return;
546
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
547
+		$margin = is_admin() ? ' 180px' : '0';
548
+		//$print_r = false;
549
+		if (is_string($var)) {
550
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
551
+			return;
552
+		}
553
+		if (is_object($var)) {
554
+			$var_name = ! $var_name ? 'object' : $var_name;
555
+			//$print_r = true;
556
+		} else if (is_array($var)) {
557
+			$var_name = ! $var_name ? 'array' : $var_name;
558
+			//$print_r = true;
559
+		} else if (is_numeric($var)) {
560
+			$var_name = ! $var_name ? 'numeric' : $var_name;
561
+		} else if ($var === null) {
562
+			$var_name = ! $var_name ? 'null' : $var_name;
563
+		}
564
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
565
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
566
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
567
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
568
+				EEH_Debug_Tools::pre_span($var)
569
+			);
570
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
571
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
572
+		if ($die) {
573
+			die($result);
574
+		}
575
+		echo $result;
576
+	}
577
+
578
+
579
+
580
+	/******************** deprecated ********************/
581
+
582
+
583
+
584
+	/**
585
+	 * @deprecated 4.9.39.rc.034
586
+	 */
587
+	public function reset_times()
588
+	{
589
+		Benchmark::resetTimes();
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 * @deprecated 4.9.39.rc.034
596
+	 * @param null $timer_name
597
+	 */
598
+	public function start_timer($timer_name = null)
599
+	{
600
+		Benchmark::startTimer($timer_name);
601
+	}
602
+
603
+
604
+
605
+	/**
606
+	 * @deprecated 4.9.39.rc.034
607
+	 * @param string $timer_name
608
+	 */
609
+	public function stop_timer($timer_name = '')
610
+	{
611
+		Benchmark::stopTimer($timer_name);
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * @deprecated 4.9.39.rc.034
618
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
619
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
620
+	 * @return void
621
+	 */
622
+	public function measure_memory($label, $output_now = false)
623
+	{
624
+		Benchmark::measureMemory($label, $output_now);
625
+	}
626
+
627
+
628
+
629
+	/**
630
+	 * @deprecated 4.9.39.rc.034
631
+	 * @param int $size
632
+	 * @return string
633
+	 */
634
+	public function convert($size)
635
+	{
636
+		return Benchmark::convert($size);
637
+	}
638
+
639
+
640
+
641
+	/**
642
+	 * @deprecated 4.9.39.rc.034
643
+	 * @param bool $output_now
644
+	 * @return string
645
+	 */
646
+	public function show_times($output_now = true)
647
+	{
648
+		return Benchmark::displayResults($output_now);
649
+	}
650
+
651
+
652
+
653
+	/**
654
+	 * @deprecated 4.9.39.rc.034
655
+	 * @param string $timer_name
656
+	 * @param float  $total_time
657
+	 * @return string
658
+	 */
659
+	public function format_time($timer_name, $total_time)
660
+	{
661
+		return Benchmark::formatTime($timer_name, $total_time);
662
+	}
663 663
 
664 664
 
665 665
 
@@ -672,31 +672,31 @@  discard block
 block discarded – undo
672 672
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
673 673
  */
674 674
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
675
-    function dump_wp_query()
676
-    {
677
-        global $wp_query;
678
-        d($wp_query);
679
-    }
675
+	function dump_wp_query()
676
+	{
677
+		global $wp_query;
678
+		d($wp_query);
679
+	}
680 680
 }
681 681
 /**
682 682
  * borrowed from Kint Debugger
683 683
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
684 684
  */
685 685
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
686
-    function dump_wp()
687
-    {
688
-        global $wp;
689
-        d($wp);
690
-    }
686
+	function dump_wp()
687
+	{
688
+		global $wp;
689
+		d($wp);
690
+	}
691 691
 }
692 692
 /**
693 693
  * borrowed from Kint Debugger
694 694
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
695 695
  */
696 696
 if (class_exists('Kint') && ! function_exists('dump_post')) {
697
-    function dump_post()
698
-    {
699
-        global $post;
700
-        d($post);
701
-    }
697
+	function dump_post()
698
+	{
699
+		global $post;
700
+		d($post);
701
+	}
702 702
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public static function instance()
41 41
     {
42 42
         // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
43
+        if ( ! self::$_instance instanceof EEH_Debug_Tools) {
44 44
             self::$_instance = new self();
45 45
         }
46 46
         return self::$_instance;
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
     private function __construct()
55 55
     {
56 56
         // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
57
+        if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) {
58 58
             // despite EE4 having a check for an existing copy of the Kint debugging class,
59 59
             // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60 60
             // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61 61
             // so we've moved it to our test folder so that it is not included with production releases
62 62
             // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
63
+            require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php');
64 64
         }
65 65
         // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66 66
         //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public static function show_db_name()
82 82
     {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
83
+        if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84 84
             echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85 85
                  . DB_NAME
86 86
                  . '</p>';
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
         echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132 132
         if ($tag) {
133 133
             $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
134
+            if ( ! is_array($hook[$tag])) {
135 135
                 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136 136
                 return;
137 137
             }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
138
+            echo '<h5>For Tag: '.$tag.'</h5>';
139 139
         } else {
140 140
             $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141 141
             ksort($hook);
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
     {
189 189
         if (WP_DEBUG) {
190 190
             $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
+            if ( ! empty($activation_errors)) {
192
+                $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
193 193
             }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
194
+            espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
195 195
             if (class_exists('EEH_File')) {
196 196
                 try {
197 197
                     EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
198
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'
199 199
                     );
200 200
                     EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
201
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
202 202
                         $activation_errors
203 203
                     );
204 204
                 } catch (EE_Error $e) {
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
             } else {
217 217
                 // old school attempt
218 218
                 file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
219
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
220 220
                     $activation_errors
221 221
                 );
222 222
             }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
223
+            $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
224 224
             update_option('ee_plugin_activation_errors', $activation_errors);
225 225
         }
226 226
     }
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         // don't trigger error if doing ajax,
281 281
         // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282 282
         if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
283
+            $error_message .= ' '.esc_html__(
284 284
                     'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285 285
                     'event_espresso'
286 286
                 );
@@ -324,16 +324,16 @@  discard block
 block discarded – undo
324 324
         $debug_key = 'EE_DEBUG_SPCO'
325 325
     ) {
326 326
         if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
327
+            $debug_key = $debug_key.'_'.EE_Session::instance()->id();
328 328
             $debug_data = get_option($debug_key, array());
329 329
             $default_data = array(
330
-                $class => $func . '() : ' . $line,
330
+                $class => $func.'() : '.$line,
331 331
                 'REQ'  => $display_request ? $_REQUEST : '',
332 332
             );
333 333
             // don't serialize objects
334 334
             $info = self::strip_objects($info);
335 335
             $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
336
+            if ( ! isset($debug_data[$index])) {
337 337
                 $debug_data[$index] = array();
338 338
             }
339 339
             $debug_data[$index][microtime()] = array_merge($default_data, $info);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                 unset($info[$key]);
370 370
             }
371 371
         }
372
-        return (array)$info;
372
+        return (array) $info;
373 373
     }
374 374
 
375 375
 
@@ -401,8 +401,8 @@  discard block
 block discarded – undo
401 401
         $heading_tag = $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
402 402
         $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
403 403
         $result .= $is_method
404
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
405
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
+            ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()')
405
+            : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var);
406 406
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
407 407
         $result .= EEH_Debug_Tools::headingX($heading_tag);
408 408
         if ($die) {
@@ -429,14 +429,14 @@  discard block
 block discarded – undo
429 429
     {
430 430
         if (EEH_Debug_Tools::plainOutput()) {
431 431
             $heading = '';
432
-            if($heading_tag === 'h1' || $heading_tag === 'h2') {
432
+            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
433 433
                 $heading .= "\n";
434 434
             }
435 435
             $heading .= "\n{$line}) {$var_name}";
436 436
             return $heading;
437 437
         }
438 438
         $margin = "25px 0 0 {$margin}";
439
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
439
+        return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>';
440 440
     }
441 441
 
442 442
 
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
         if (EEH_Debug_Tools::plainOutput()) {
451 451
             return '';
452 452
         }
453
-        return '</' . $heading_tag . '>';
453
+        return '</'.$heading_tag.'>';
454 454
     }
455 455
 
456 456
 
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
         if (EEH_Debug_Tools::plainOutput()) {
465 465
             return $content;
466 466
         }
467
-        return '<span style="color:#999">' . $content . '</span>';
467
+        return '<span style="color:#999">'.$content.'</span>';
468 468
     }
469 469
 
470 470
 
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
         if (EEH_Debug_Tools::plainOutput()) {
505 505
             return $content;
506 506
         }
507
-        return '<span style="color:#E76700">' . $content . '</span>';
507
+        return '<span style="color:#E76700">'.$content.'</span>';
508 508
     }
509 509
 
510 510
 
@@ -519,9 +519,9 @@  discard block
 block discarded – undo
519 519
         var_dump($var);
520 520
         $var = ob_get_clean();
521 521
         if (EEH_Debug_Tools::plainOutput()) {
522
-            return "\n" . $var;
522
+            return "\n".$var;
523 523
         }
524
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
524
+        return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>';
525 525
     }
526 526
 
527 527
 
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
         $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
565 565
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
566 566
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
567
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
567
+        $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span(
568 568
                 EEH_Debug_Tools::pre_span($var)
569 569
             );
570 570
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
Please login to merge, or discard this patch.
core/EE_Addon.core.php 1 patch
Indentation   +821 added lines, -821 removed lines patch added patch discarded remove patch
@@ -21,793 +21,793 @@  discard block
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * prefix to be added onto an addon's plugin slug to make a wp option name
26
-     * which will be used to store the plugin's activation history
27
-     */
28
-    const ee_addon_version_history_option_prefix = 'ee_version_history_';
29
-
30
-    /**
31
-     * @var $_version
32
-     * @type string
33
-     */
34
-    protected $_version = '';
35
-
36
-    /**
37
-     * @var $_min_core_version
38
-     * @type string
39
-     */
40
-    protected $_min_core_version = '';
41
-
42
-    /**
43
-     * derived from plugin 'main_file_path using plugin_basename()
44
-     *
45
-     * @type string $_plugin_basename
46
-     */
47
-    protected $_plugin_basename = '';
48
-
49
-    /**
50
-     * A non-internationalized name to identify this addon for use in URLs, etc
51
-     *
52
-     * @type string $_plugin_slug
53
-     */
54
-    protected $_plugin_slug = '';
55
-
56
-    /**
57
-     * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
58
-     *
59
-     * @type string _addon_name
60
-     */
61
-    protected $_addon_name = '';
62
-
63
-    /**
64
-     * one of the EE_System::req_type_* constants
65
-     *
66
-     * @type int $_req_type
67
-     */
68
-    protected $_req_type;
69
-
70
-    /**
71
-     * page slug to be used when generating the "Settings" link on the WP plugin page
72
-     *
73
-     * @type string $_plugin_action_slug
74
-     */
75
-    protected $_plugin_action_slug = '';
76
-
77
-    /**
78
-     * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
79
-     * that can be used for adding upgrading/marketing info
80
-     *
81
-     * @type array $_plugins_page_row
82
-     */
83
-    protected $_plugins_page_row = array();
84
-
85
-
86
-
87
-    /**
88
-     *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
89
-     *
90
-     * @type string
91
-     */
92
-    protected $_main_plugin_file;
93
-
94
-
95
-    /**
96
-     * @var EE_Dependency_Map $dependency_map
97
-     */
98
-    private $dependency_map;
99
-
100
-
101
-    /**
102
-     * @var DomainInterface $domain
103
-     */
104
-    private $domain;
105
-
106
-
107
-    /**
108
-     * @param EE_Dependency_Map $dependency_map [optional]
109
-     * @param DomainInterface   $domain         [optional]
110
-     */
111
-    public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
112
-    {
113
-        if($dependency_map instanceof EE_Dependency_Map) {
114
-            $this->setDependencyMap($dependency_map);
115
-        }
116
-        if ($domain instanceof DomainInterface) {
117
-            $this->setDomain($domain);
118
-        }
119
-        add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
120
-    }
121
-
122
-
123
-    /**
124
-     * @param EE_Dependency_Map $dependency_map
125
-     */
126
-    public function setDependencyMap($dependency_map)
127
-    {
128
-        $this->dependency_map = $dependency_map;
129
-    }
130
-
131
-
132
-    /**
133
-     * @return EE_Dependency_Map
134
-     */
135
-    public function dependencyMap()
136
-    {
137
-        return $this->dependency_map;
138
-    }
139
-
140
-
141
-    /**
142
-     * @param DomainInterface $domain
143
-     */
144
-    public function setDomain(DomainInterface $domain)
145
-    {
146
-        $this->domain = $domain;
147
-    }
148
-
149
-    /**
150
-     * @return DomainInterface
151
-     */
152
-    public function domain()
153
-    {
154
-        return $this->domain;
155
-    }
156
-
157
-
158
-    /**
159
-     * @param mixed $version
160
-     */
161
-    public function set_version($version = null)
162
-    {
163
-        $this->_version = $version;
164
-    }
165
-
166
-
167
-    /**
168
-     * get__version
169
-     *
170
-     * @return string
171
-     */
172
-    public function version()
173
-    {
174
-        return $this->_version;
175
-    }
176
-
177
-
178
-    /**
179
-     * @param mixed $min_core_version
180
-     */
181
-    public function set_min_core_version($min_core_version = null)
182
-    {
183
-        $this->_min_core_version = $min_core_version;
184
-    }
185
-
186
-
187
-    /**
188
-     * get__min_core_version
189
-     *
190
-     * @return string
191
-     */
192
-    public function min_core_version()
193
-    {
194
-        return $this->_min_core_version;
195
-    }
196
-
197
-
198
-    /**
199
-     * Sets addon_name
200
-     *
201
-     * @param string $addon_name
202
-     * @return boolean
203
-     */
204
-    public function set_name($addon_name)
205
-    {
206
-        return $this->_addon_name = $addon_name;
207
-    }
208
-
209
-
210
-    /**
211
-     * Gets addon_name
212
-     *
213
-     * @return string
214
-     */
215
-    public function name()
216
-    {
217
-        return $this->_addon_name;
218
-    }
219
-
220
-
221
-    /**
222
-     * @return string
223
-     */
224
-    public function plugin_basename()
225
-    {
226
-
227
-        return $this->_plugin_basename;
228
-    }
229
-
230
-
231
-    /**
232
-     * @param string $plugin_basename
233
-     */
234
-    public function set_plugin_basename($plugin_basename)
235
-    {
236
-
237
-        $this->_plugin_basename = $plugin_basename;
238
-    }
239
-
240
-
241
-    /**
242
-     * @return string
243
-     */
244
-    public function plugin_slug()
245
-    {
246
-
247
-        return $this->_plugin_slug;
248
-    }
249
-
250
-
251
-    /**
252
-     * @param string $plugin_slug
253
-     */
254
-    public function set_plugin_slug($plugin_slug)
255
-    {
256
-
257
-        $this->_plugin_slug = $plugin_slug;
258
-    }
259
-
260
-
261
-    /**
262
-     * @return string
263
-     */
264
-    public function plugin_action_slug()
265
-    {
266
-
267
-        return $this->_plugin_action_slug;
268
-    }
269
-
270
-
271
-    /**
272
-     * @param string $plugin_action_slug
273
-     */
274
-    public function set_plugin_action_slug($plugin_action_slug)
275
-    {
276
-
277
-        $this->_plugin_action_slug = $plugin_action_slug;
278
-    }
279
-
280
-
281
-    /**
282
-     * @return array
283
-     */
284
-    public function get_plugins_page_row()
285
-    {
286
-
287
-        return $this->_plugins_page_row;
288
-    }
289
-
290
-
291
-    /**
292
-     * @param array $plugins_page_row
293
-     */
294
-    public function set_plugins_page_row($plugins_page_row = array())
295
-    {
296
-        // sigh.... check for example content that I stupidly merged to master and remove it if found
297
-        if (! is_array($plugins_page_row)
298
-            && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
299
-        ) {
300
-            $plugins_page_row = array();
301
-        }
302
-        $this->_plugins_page_row = (array) $plugins_page_row;
303
-    }
304
-
305
-
306
-    /**
307
-     * Called when EE core detects this addon has been activated for the first time.
308
-     * If the site isn't in maintenance mode, should setup the addon's database
309
-     *
310
-     * @return void
311
-     */
312
-    public function new_install()
313
-    {
314
-        $classname = get_class($this);
315
-        do_action("AHEE__{$classname}__new_install");
316
-        do_action('AHEE__EE_Addon__new_install', $this);
317
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
318
-        add_action(
319
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
320
-            array($this, 'initialize_db_if_no_migrations_required')
321
-        );
322
-    }
323
-
324
-
325
-    /**
326
-     * Called when EE core detects this addon has been reactivated. When this happens,
327
-     * it's good to just check that your data is still intact
328
-     *
329
-     * @return void
330
-     */
331
-    public function reactivation()
332
-    {
333
-        $classname = get_class($this);
334
-        do_action("AHEE__{$classname}__reactivation");
335
-        do_action('AHEE__EE_Addon__reactivation', $this);
336
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
337
-        add_action(
338
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
339
-            array($this, 'initialize_db_if_no_migrations_required')
340
-        );
341
-    }
342
-
343
-
344
-    /**
345
-     * Called when the registered deactivation hook for this addon fires.
346
-     * @throws EE_Error
347
-     */
348
-    public function deactivation()
349
-    {
350
-        $classname = get_class($this);
351
-        do_action("AHEE__{$classname}__deactivation");
352
-        do_action('AHEE__EE_Addon__deactivation', $this);
353
-        //check if the site no longer needs to be in maintenance mode
354
-        EE_Register_Addon::deregister($this->name());
355
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
356
-    }
357
-
358
-
359
-    /**
360
-     * Takes care of double-checking that we're not in maintenance mode, and then
361
-     * initializing this addon's necessary initial data. This is called by default on new activations
362
-     * and reactivations.
363
-     *
364
-     * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
365
-     *                               This is a resource-intensive job so we prefer to only do it when necessary
366
-     * @return void
367
-     * @throws \EE_Error
368
-     * @throws InvalidInterfaceException
369
-     * @throws InvalidDataTypeException
370
-     * @throws InvalidArgumentException
371
-     */
372
-    public function initialize_db_if_no_migrations_required($verify_schema = true)
373
-    {
374
-        if ($verify_schema === '') {
375
-            //wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
376
-            //(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
377
-            //calls them with an argument of an empty string (ie ""), which evaluates to false
378
-            //so we need to treat the empty string as if nothing had been passed, and should instead use the default
379
-            $verify_schema = true;
380
-        }
381
-        if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
382
-            if ($verify_schema) {
383
-                $this->initialize_db();
384
-            }
385
-            $this->initialize_default_data();
386
-            //@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
387
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to(
388
-                array(
389
-                    'slug'    => $this->name(),
390
-                    'version' => $this->version(),
391
-                )
392
-            );
393
-            /* make sure core's data is a-ok
24
+	/**
25
+	 * prefix to be added onto an addon's plugin slug to make a wp option name
26
+	 * which will be used to store the plugin's activation history
27
+	 */
28
+	const ee_addon_version_history_option_prefix = 'ee_version_history_';
29
+
30
+	/**
31
+	 * @var $_version
32
+	 * @type string
33
+	 */
34
+	protected $_version = '';
35
+
36
+	/**
37
+	 * @var $_min_core_version
38
+	 * @type string
39
+	 */
40
+	protected $_min_core_version = '';
41
+
42
+	/**
43
+	 * derived from plugin 'main_file_path using plugin_basename()
44
+	 *
45
+	 * @type string $_plugin_basename
46
+	 */
47
+	protected $_plugin_basename = '';
48
+
49
+	/**
50
+	 * A non-internationalized name to identify this addon for use in URLs, etc
51
+	 *
52
+	 * @type string $_plugin_slug
53
+	 */
54
+	protected $_plugin_slug = '';
55
+
56
+	/**
57
+	 * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
58
+	 *
59
+	 * @type string _addon_name
60
+	 */
61
+	protected $_addon_name = '';
62
+
63
+	/**
64
+	 * one of the EE_System::req_type_* constants
65
+	 *
66
+	 * @type int $_req_type
67
+	 */
68
+	protected $_req_type;
69
+
70
+	/**
71
+	 * page slug to be used when generating the "Settings" link on the WP plugin page
72
+	 *
73
+	 * @type string $_plugin_action_slug
74
+	 */
75
+	protected $_plugin_action_slug = '';
76
+
77
+	/**
78
+	 * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
79
+	 * that can be used for adding upgrading/marketing info
80
+	 *
81
+	 * @type array $_plugins_page_row
82
+	 */
83
+	protected $_plugins_page_row = array();
84
+
85
+
86
+
87
+	/**
88
+	 *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
89
+	 *
90
+	 * @type string
91
+	 */
92
+	protected $_main_plugin_file;
93
+
94
+
95
+	/**
96
+	 * @var EE_Dependency_Map $dependency_map
97
+	 */
98
+	private $dependency_map;
99
+
100
+
101
+	/**
102
+	 * @var DomainInterface $domain
103
+	 */
104
+	private $domain;
105
+
106
+
107
+	/**
108
+	 * @param EE_Dependency_Map $dependency_map [optional]
109
+	 * @param DomainInterface   $domain         [optional]
110
+	 */
111
+	public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null)
112
+	{
113
+		if($dependency_map instanceof EE_Dependency_Map) {
114
+			$this->setDependencyMap($dependency_map);
115
+		}
116
+		if ($domain instanceof DomainInterface) {
117
+			$this->setDomain($domain);
118
+		}
119
+		add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
120
+	}
121
+
122
+
123
+	/**
124
+	 * @param EE_Dependency_Map $dependency_map
125
+	 */
126
+	public function setDependencyMap($dependency_map)
127
+	{
128
+		$this->dependency_map = $dependency_map;
129
+	}
130
+
131
+
132
+	/**
133
+	 * @return EE_Dependency_Map
134
+	 */
135
+	public function dependencyMap()
136
+	{
137
+		return $this->dependency_map;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param DomainInterface $domain
143
+	 */
144
+	public function setDomain(DomainInterface $domain)
145
+	{
146
+		$this->domain = $domain;
147
+	}
148
+
149
+	/**
150
+	 * @return DomainInterface
151
+	 */
152
+	public function domain()
153
+	{
154
+		return $this->domain;
155
+	}
156
+
157
+
158
+	/**
159
+	 * @param mixed $version
160
+	 */
161
+	public function set_version($version = null)
162
+	{
163
+		$this->_version = $version;
164
+	}
165
+
166
+
167
+	/**
168
+	 * get__version
169
+	 *
170
+	 * @return string
171
+	 */
172
+	public function version()
173
+	{
174
+		return $this->_version;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @param mixed $min_core_version
180
+	 */
181
+	public function set_min_core_version($min_core_version = null)
182
+	{
183
+		$this->_min_core_version = $min_core_version;
184
+	}
185
+
186
+
187
+	/**
188
+	 * get__min_core_version
189
+	 *
190
+	 * @return string
191
+	 */
192
+	public function min_core_version()
193
+	{
194
+		return $this->_min_core_version;
195
+	}
196
+
197
+
198
+	/**
199
+	 * Sets addon_name
200
+	 *
201
+	 * @param string $addon_name
202
+	 * @return boolean
203
+	 */
204
+	public function set_name($addon_name)
205
+	{
206
+		return $this->_addon_name = $addon_name;
207
+	}
208
+
209
+
210
+	/**
211
+	 * Gets addon_name
212
+	 *
213
+	 * @return string
214
+	 */
215
+	public function name()
216
+	{
217
+		return $this->_addon_name;
218
+	}
219
+
220
+
221
+	/**
222
+	 * @return string
223
+	 */
224
+	public function plugin_basename()
225
+	{
226
+
227
+		return $this->_plugin_basename;
228
+	}
229
+
230
+
231
+	/**
232
+	 * @param string $plugin_basename
233
+	 */
234
+	public function set_plugin_basename($plugin_basename)
235
+	{
236
+
237
+		$this->_plugin_basename = $plugin_basename;
238
+	}
239
+
240
+
241
+	/**
242
+	 * @return string
243
+	 */
244
+	public function plugin_slug()
245
+	{
246
+
247
+		return $this->_plugin_slug;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @param string $plugin_slug
253
+	 */
254
+	public function set_plugin_slug($plugin_slug)
255
+	{
256
+
257
+		$this->_plugin_slug = $plugin_slug;
258
+	}
259
+
260
+
261
+	/**
262
+	 * @return string
263
+	 */
264
+	public function plugin_action_slug()
265
+	{
266
+
267
+		return $this->_plugin_action_slug;
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param string $plugin_action_slug
273
+	 */
274
+	public function set_plugin_action_slug($plugin_action_slug)
275
+	{
276
+
277
+		$this->_plugin_action_slug = $plugin_action_slug;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @return array
283
+	 */
284
+	public function get_plugins_page_row()
285
+	{
286
+
287
+		return $this->_plugins_page_row;
288
+	}
289
+
290
+
291
+	/**
292
+	 * @param array $plugins_page_row
293
+	 */
294
+	public function set_plugins_page_row($plugins_page_row = array())
295
+	{
296
+		// sigh.... check for example content that I stupidly merged to master and remove it if found
297
+		if (! is_array($plugins_page_row)
298
+			&& strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
299
+		) {
300
+			$plugins_page_row = array();
301
+		}
302
+		$this->_plugins_page_row = (array) $plugins_page_row;
303
+	}
304
+
305
+
306
+	/**
307
+	 * Called when EE core detects this addon has been activated for the first time.
308
+	 * If the site isn't in maintenance mode, should setup the addon's database
309
+	 *
310
+	 * @return void
311
+	 */
312
+	public function new_install()
313
+	{
314
+		$classname = get_class($this);
315
+		do_action("AHEE__{$classname}__new_install");
316
+		do_action('AHEE__EE_Addon__new_install', $this);
317
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
318
+		add_action(
319
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
320
+			array($this, 'initialize_db_if_no_migrations_required')
321
+		);
322
+	}
323
+
324
+
325
+	/**
326
+	 * Called when EE core detects this addon has been reactivated. When this happens,
327
+	 * it's good to just check that your data is still intact
328
+	 *
329
+	 * @return void
330
+	 */
331
+	public function reactivation()
332
+	{
333
+		$classname = get_class($this);
334
+		do_action("AHEE__{$classname}__reactivation");
335
+		do_action('AHEE__EE_Addon__reactivation', $this);
336
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
337
+		add_action(
338
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
339
+			array($this, 'initialize_db_if_no_migrations_required')
340
+		);
341
+	}
342
+
343
+
344
+	/**
345
+	 * Called when the registered deactivation hook for this addon fires.
346
+	 * @throws EE_Error
347
+	 */
348
+	public function deactivation()
349
+	{
350
+		$classname = get_class($this);
351
+		do_action("AHEE__{$classname}__deactivation");
352
+		do_action('AHEE__EE_Addon__deactivation', $this);
353
+		//check if the site no longer needs to be in maintenance mode
354
+		EE_Register_Addon::deregister($this->name());
355
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
356
+	}
357
+
358
+
359
+	/**
360
+	 * Takes care of double-checking that we're not in maintenance mode, and then
361
+	 * initializing this addon's necessary initial data. This is called by default on new activations
362
+	 * and reactivations.
363
+	 *
364
+	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
365
+	 *                               This is a resource-intensive job so we prefer to only do it when necessary
366
+	 * @return void
367
+	 * @throws \EE_Error
368
+	 * @throws InvalidInterfaceException
369
+	 * @throws InvalidDataTypeException
370
+	 * @throws InvalidArgumentException
371
+	 */
372
+	public function initialize_db_if_no_migrations_required($verify_schema = true)
373
+	{
374
+		if ($verify_schema === '') {
375
+			//wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
376
+			//(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
377
+			//calls them with an argument of an empty string (ie ""), which evaluates to false
378
+			//so we need to treat the empty string as if nothing had been passed, and should instead use the default
379
+			$verify_schema = true;
380
+		}
381
+		if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
382
+			if ($verify_schema) {
383
+				$this->initialize_db();
384
+			}
385
+			$this->initialize_default_data();
386
+			//@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
387
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to(
388
+				array(
389
+					'slug'    => $this->name(),
390
+					'version' => $this->version(),
391
+				)
392
+			);
393
+			/* make sure core's data is a-ok
394 394
              * (at the time of writing, we especially want to verify all the caps are present
395 395
              * because payment method type capabilities are added dynamically, and it's
396 396
              * possible this addon added a payment method. But it's also possible
397 397
              * other data needs to be verified)
398 398
              */
399
-            EEH_Activation::initialize_db_content();
400
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
401
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
402
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
403
-            );
404
-            $rewrite_rules->flushRewriteRules();
405
-            //in case there are lots of addons being activated at once, let's force garbage collection
406
-            //to help avoid memory limit errors
407
-            //EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
408
-            gc_collect_cycles();
409
-        } else {
410
-            //ask the data migration manager to init this addon's data
411
-            //when migrations are finished because we can't do it now
412
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
413
-        }
414
-    }
415
-
416
-
417
-    /**
418
-     * Used to setup this addon's database tables, but not necessarily any default
419
-     * data in them. The default is to actually use the most up-to-date data migration script
420
-     * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
421
-     * methods to setup the db.
422
-     */
423
-    public function initialize_db()
424
-    {
425
-        //find the migration script that sets the database to be compatible with the code
426
-        $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
427
-        if ($current_dms_name) {
428
-            $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
429
-            $current_data_migration_script->set_migrating(false);
430
-            $current_data_migration_script->schema_changes_before_migration();
431
-            $current_data_migration_script->schema_changes_after_migration();
432
-            if ($current_data_migration_script->get_errors()) {
433
-                foreach ($current_data_migration_script->get_errors() as $error) {
434
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
435
-                }
436
-            }
437
-        }
438
-        //if not DMS was found that should be ok. This addon just doesn't require any database changes
439
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to(
440
-            array(
441
-                'slug'    => $this->name(),
442
-                'version' => $this->version(),
443
-            )
444
-        );
445
-    }
446
-
447
-
448
-    /**
449
-     * If you want to setup default data for the addon, override this method, and call
450
-     * parent::initialize_default_data() from within it. This is normally called
451
-     * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
452
-     * and should verify default data is present (but this is also called
453
-     * on reactivations and just after migrations, so please verify you actually want
454
-     * to ADD default data, because it may already be present).
455
-     * However, please call this parent (currently it just fires a hook which other
456
-     * addons may be depending on)
457
-     */
458
-    public function initialize_default_data()
459
-    {
460
-        /**
461
-         * Called when an addon is ensuring its default data is set (possibly called
462
-         * on a reactivation, so first check for the absence of other data before setting
463
-         * default data)
464
-         *
465
-         * @param EE_Addon $addon the addon that called this
466
-         */
467
-        do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
468
-        //override to insert default data. It is safe to use the models here
469
-        //because the site should not be in maintenance mode
470
-    }
471
-
472
-
473
-    /**
474
-     * EE Core detected that this addon has been upgraded. We should check if there
475
-     * are any new migration scripts, and if so put the site into maintenance mode until
476
-     * they're ran
477
-     *
478
-     * @return void
479
-     */
480
-    public function upgrade()
481
-    {
482
-        $classname = get_class($this);
483
-        do_action("AHEE__{$classname}__upgrade");
484
-        do_action('AHEE__EE_Addon__upgrade', $this);
485
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
486
-        //also it's possible there is new default data that needs to be added
487
-        add_action(
488
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
489
-            array($this, 'initialize_db_if_no_migrations_required')
490
-        );
491
-    }
492
-
493
-
494
-    /**
495
-     * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
496
-     */
497
-    public function downgrade()
498
-    {
499
-        $classname = get_class($this);
500
-        do_action("AHEE__{$classname}__downgrade");
501
-        do_action('AHEE__EE_Addon__downgrade', $this);
502
-        //it's possible there's old default data that needs to be double-checked
503
-        add_action(
504
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
505
-            array($this, 'initialize_db_if_no_migrations_required')
506
-        );
507
-    }
508
-
509
-
510
-    /**
511
-     * set_db_update_option_name
512
-     * Until we do something better, we'll just check for migration scripts upon
513
-     * plugin activation only. In the future, we'll want to do it on plugin updates too
514
-     *
515
-     * @return bool
516
-     */
517
-    public function set_db_update_option_name()
518
-    {
519
-        EE_Error::doing_it_wrong(
520
-            __FUNCTION__,
521
-            esc_html__(
522
-                'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
523
-                'event_espresso'
524
-            ),
525
-            '4.3.0.alpha.016'
526
-        );
527
-        //let's just handle this on the next request, ok? right now we're just not really ready
528
-        return $this->set_activation_indicator_option();
529
-    }
530
-
531
-
532
-    /**
533
-     * Returns the name of the activation indicator option
534
-     * (an option which is set temporarily to indicate that this addon was just activated)
535
-     *
536
-     * @deprecated since version 4.3.0.alpha.016
537
-     * @return string
538
-     */
539
-    public function get_db_update_option_name()
540
-    {
541
-        EE_Error::doing_it_wrong(
542
-            __FUNCTION__,
543
-            esc_html__(
544
-                'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
545
-                'event_espresso'
546
-            ),
547
-            '4.3.0.alpha.016'
548
-        );
549
-        return $this->get_activation_indicator_option_name();
550
-    }
551
-
552
-
553
-    /**
554
-     * When the addon is activated, this should be called to set a wordpress option that
555
-     * indicates it was activated. This is especially useful for detecting reactivations.
556
-     *
557
-     * @return bool
558
-     */
559
-    public function set_activation_indicator_option()
560
-    {
561
-        // let's just handle this on the next request, ok? right now we're just not really ready
562
-        return update_option($this->get_activation_indicator_option_name(), true);
563
-    }
564
-
565
-
566
-    /**
567
-     * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
568
-     *
569
-     * @return string
570
-     */
571
-    public function get_activation_indicator_option_name()
572
-    {
573
-        return 'ee_activation_' . $this->name();
574
-    }
575
-
576
-
577
-    /**
578
-     * Used by EE_System to set the request type of this addon. Should not be used by addon developers
579
-     *
580
-     * @param int $req_type
581
-     */
582
-    public function set_req_type($req_type)
583
-    {
584
-        $this->_req_type = $req_type;
585
-    }
586
-
587
-
588
-    /**
589
-     * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
590
-     * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
591
-     * EE_System when it is checking for new install or upgrades of addons
592
-     */
593
-    public function detect_req_type()
594
-    {
595
-        if (! $this->_req_type) {
596
-            $this->detect_activation_or_upgrade();
597
-        }
598
-        return $this->_req_type;
599
-    }
600
-
601
-
602
-    /**
603
-     * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
604
-     * Should only be called once per request
605
-     *
606
-     * @return void
607
-     */
608
-    public function detect_activation_or_upgrade()
609
-    {
610
-        $activation_history_for_addon = $this->get_activation_history();
399
+			EEH_Activation::initialize_db_content();
400
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
401
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
402
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
403
+			);
404
+			$rewrite_rules->flushRewriteRules();
405
+			//in case there are lots of addons being activated at once, let's force garbage collection
406
+			//to help avoid memory limit errors
407
+			//EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
408
+			gc_collect_cycles();
409
+		} else {
410
+			//ask the data migration manager to init this addon's data
411
+			//when migrations are finished because we can't do it now
412
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
413
+		}
414
+	}
415
+
416
+
417
+	/**
418
+	 * Used to setup this addon's database tables, but not necessarily any default
419
+	 * data in them. The default is to actually use the most up-to-date data migration script
420
+	 * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
421
+	 * methods to setup the db.
422
+	 */
423
+	public function initialize_db()
424
+	{
425
+		//find the migration script that sets the database to be compatible with the code
426
+		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
427
+		if ($current_dms_name) {
428
+			$current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
429
+			$current_data_migration_script->set_migrating(false);
430
+			$current_data_migration_script->schema_changes_before_migration();
431
+			$current_data_migration_script->schema_changes_after_migration();
432
+			if ($current_data_migration_script->get_errors()) {
433
+				foreach ($current_data_migration_script->get_errors() as $error) {
434
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
435
+				}
436
+			}
437
+		}
438
+		//if not DMS was found that should be ok. This addon just doesn't require any database changes
439
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to(
440
+			array(
441
+				'slug'    => $this->name(),
442
+				'version' => $this->version(),
443
+			)
444
+		);
445
+	}
446
+
447
+
448
+	/**
449
+	 * If you want to setup default data for the addon, override this method, and call
450
+	 * parent::initialize_default_data() from within it. This is normally called
451
+	 * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
452
+	 * and should verify default data is present (but this is also called
453
+	 * on reactivations and just after migrations, so please verify you actually want
454
+	 * to ADD default data, because it may already be present).
455
+	 * However, please call this parent (currently it just fires a hook which other
456
+	 * addons may be depending on)
457
+	 */
458
+	public function initialize_default_data()
459
+	{
460
+		/**
461
+		 * Called when an addon is ensuring its default data is set (possibly called
462
+		 * on a reactivation, so first check for the absence of other data before setting
463
+		 * default data)
464
+		 *
465
+		 * @param EE_Addon $addon the addon that called this
466
+		 */
467
+		do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
468
+		//override to insert default data. It is safe to use the models here
469
+		//because the site should not be in maintenance mode
470
+	}
471
+
472
+
473
+	/**
474
+	 * EE Core detected that this addon has been upgraded. We should check if there
475
+	 * are any new migration scripts, and if so put the site into maintenance mode until
476
+	 * they're ran
477
+	 *
478
+	 * @return void
479
+	 */
480
+	public function upgrade()
481
+	{
482
+		$classname = get_class($this);
483
+		do_action("AHEE__{$classname}__upgrade");
484
+		do_action('AHEE__EE_Addon__upgrade', $this);
485
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
486
+		//also it's possible there is new default data that needs to be added
487
+		add_action(
488
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
489
+			array($this, 'initialize_db_if_no_migrations_required')
490
+		);
491
+	}
492
+
493
+
494
+	/**
495
+	 * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
496
+	 */
497
+	public function downgrade()
498
+	{
499
+		$classname = get_class($this);
500
+		do_action("AHEE__{$classname}__downgrade");
501
+		do_action('AHEE__EE_Addon__downgrade', $this);
502
+		//it's possible there's old default data that needs to be double-checked
503
+		add_action(
504
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
505
+			array($this, 'initialize_db_if_no_migrations_required')
506
+		);
507
+	}
508
+
509
+
510
+	/**
511
+	 * set_db_update_option_name
512
+	 * Until we do something better, we'll just check for migration scripts upon
513
+	 * plugin activation only. In the future, we'll want to do it on plugin updates too
514
+	 *
515
+	 * @return bool
516
+	 */
517
+	public function set_db_update_option_name()
518
+	{
519
+		EE_Error::doing_it_wrong(
520
+			__FUNCTION__,
521
+			esc_html__(
522
+				'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
523
+				'event_espresso'
524
+			),
525
+			'4.3.0.alpha.016'
526
+		);
527
+		//let's just handle this on the next request, ok? right now we're just not really ready
528
+		return $this->set_activation_indicator_option();
529
+	}
530
+
531
+
532
+	/**
533
+	 * Returns the name of the activation indicator option
534
+	 * (an option which is set temporarily to indicate that this addon was just activated)
535
+	 *
536
+	 * @deprecated since version 4.3.0.alpha.016
537
+	 * @return string
538
+	 */
539
+	public function get_db_update_option_name()
540
+	{
541
+		EE_Error::doing_it_wrong(
542
+			__FUNCTION__,
543
+			esc_html__(
544
+				'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
545
+				'event_espresso'
546
+			),
547
+			'4.3.0.alpha.016'
548
+		);
549
+		return $this->get_activation_indicator_option_name();
550
+	}
551
+
552
+
553
+	/**
554
+	 * When the addon is activated, this should be called to set a wordpress option that
555
+	 * indicates it was activated. This is especially useful for detecting reactivations.
556
+	 *
557
+	 * @return bool
558
+	 */
559
+	public function set_activation_indicator_option()
560
+	{
561
+		// let's just handle this on the next request, ok? right now we're just not really ready
562
+		return update_option($this->get_activation_indicator_option_name(), true);
563
+	}
564
+
565
+
566
+	/**
567
+	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
568
+	 *
569
+	 * @return string
570
+	 */
571
+	public function get_activation_indicator_option_name()
572
+	{
573
+		return 'ee_activation_' . $this->name();
574
+	}
575
+
576
+
577
+	/**
578
+	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
579
+	 *
580
+	 * @param int $req_type
581
+	 */
582
+	public function set_req_type($req_type)
583
+	{
584
+		$this->_req_type = $req_type;
585
+	}
586
+
587
+
588
+	/**
589
+	 * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
590
+	 * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
591
+	 * EE_System when it is checking for new install or upgrades of addons
592
+	 */
593
+	public function detect_req_type()
594
+	{
595
+		if (! $this->_req_type) {
596
+			$this->detect_activation_or_upgrade();
597
+		}
598
+		return $this->_req_type;
599
+	}
600
+
601
+
602
+	/**
603
+	 * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
604
+	 * Should only be called once per request
605
+	 *
606
+	 * @return void
607
+	 */
608
+	public function detect_activation_or_upgrade()
609
+	{
610
+		$activation_history_for_addon = $this->get_activation_history();
611 611
 //		d($activation_history_for_addon);
612
-        $request_type = EE_System::detect_req_type_given_activation_history(
613
-            $activation_history_for_addon,
614
-            $this->get_activation_indicator_option_name(),
615
-            $this->version()
616
-        );
617
-        $this->set_req_type($request_type);
618
-        $classname = get_class($this);
619
-        switch ($request_type) {
620
-            case EE_System::req_type_new_activation:
621
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
622
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
623
-                $this->new_install();
624
-                $this->update_list_of_installed_versions($activation_history_for_addon);
625
-                break;
626
-            case EE_System::req_type_reactivation:
627
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
628
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
629
-                $this->reactivation();
630
-                $this->update_list_of_installed_versions($activation_history_for_addon);
631
-                break;
632
-            case EE_System::req_type_upgrade:
633
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
634
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
635
-                $this->upgrade();
636
-                $this->update_list_of_installed_versions($activation_history_for_addon);
637
-                break;
638
-            case EE_System::req_type_downgrade:
639
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
640
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
641
-                $this->downgrade();
642
-                $this->update_list_of_installed_versions($activation_history_for_addon);
643
-                break;
644
-            case EE_System::req_type_normal:
645
-            default:
612
+		$request_type = EE_System::detect_req_type_given_activation_history(
613
+			$activation_history_for_addon,
614
+			$this->get_activation_indicator_option_name(),
615
+			$this->version()
616
+		);
617
+		$this->set_req_type($request_type);
618
+		$classname = get_class($this);
619
+		switch ($request_type) {
620
+			case EE_System::req_type_new_activation:
621
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
622
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
623
+				$this->new_install();
624
+				$this->update_list_of_installed_versions($activation_history_for_addon);
625
+				break;
626
+			case EE_System::req_type_reactivation:
627
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
628
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
629
+				$this->reactivation();
630
+				$this->update_list_of_installed_versions($activation_history_for_addon);
631
+				break;
632
+			case EE_System::req_type_upgrade:
633
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
634
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
635
+				$this->upgrade();
636
+				$this->update_list_of_installed_versions($activation_history_for_addon);
637
+				break;
638
+			case EE_System::req_type_downgrade:
639
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
640
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
641
+				$this->downgrade();
642
+				$this->update_list_of_installed_versions($activation_history_for_addon);
643
+				break;
644
+			case EE_System::req_type_normal:
645
+			default:
646 646
 //				$this->_maybe_redirect_to_ee_about();
647
-                break;
648
-        }
649
-
650
-        do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
651
-    }
652
-
653
-    /**
654
-     * Updates the version history for this addon
655
-     *
656
-     * @param array  $version_history
657
-     * @param string $current_version_to_add
658
-     * @return boolean success
659
-     */
660
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
661
-    {
662
-        if (! $version_history) {
663
-            $version_history = $this->get_activation_history();
664
-        }
665
-        if ($current_version_to_add === null) {
666
-            $current_version_to_add = $this->version();
667
-        }
668
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
669
-        // resave
647
+				break;
648
+		}
649
+
650
+		do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
651
+	}
652
+
653
+	/**
654
+	 * Updates the version history for this addon
655
+	 *
656
+	 * @param array  $version_history
657
+	 * @param string $current_version_to_add
658
+	 * @return boolean success
659
+	 */
660
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
661
+	{
662
+		if (! $version_history) {
663
+			$version_history = $this->get_activation_history();
664
+		}
665
+		if ($current_version_to_add === null) {
666
+			$current_version_to_add = $this->version();
667
+		}
668
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
669
+		// resave
670 670
 //		echo "updating list of installed versions:".$this->get_activation_history_option_name();d($version_history);
671
-        return update_option($this->get_activation_history_option_name(), $version_history);
672
-    }
673
-
674
-    /**
675
-     * Gets the name of the wp option that stores the activation history
676
-     * of this addon
677
-     *
678
-     * @return string
679
-     */
680
-    public function get_activation_history_option_name()
681
-    {
682
-        return self::ee_addon_version_history_option_prefix . $this->name();
683
-    }
684
-
685
-
686
-    /**
687
-     * Gets the wp option which stores the activation history for this addon
688
-     *
689
-     * @return array
690
-     */
691
-    public function get_activation_history()
692
-    {
693
-        return get_option($this->get_activation_history_option_name(), null);
694
-    }
695
-
696
-
697
-    /**
698
-     * @param string $config_section
699
-     */
700
-    public function set_config_section($config_section = '')
701
-    {
702
-        $this->_config_section = ! empty($config_section) ? $config_section : 'addons';
703
-    }
704
-
705
-    /**
706
-     * Sets the filepath to the main plugin file
707
-     *
708
-     * @param string $filepath
709
-     */
710
-    public function set_main_plugin_file($filepath)
711
-    {
712
-        $this->_main_plugin_file = $filepath;
713
-    }
714
-
715
-    /**
716
-     * gets the filepath to teh main file
717
-     *
718
-     * @return string
719
-     */
720
-    public function get_main_plugin_file()
721
-    {
722
-        return $this->_main_plugin_file;
723
-    }
724
-
725
-    /**
726
-     * Gets the filename (no path) of the main file (the main file loaded
727
-     * by WP)
728
-     *
729
-     * @return string
730
-     */
731
-    public function get_main_plugin_file_basename()
732
-    {
733
-        return plugin_basename($this->get_main_plugin_file());
734
-    }
735
-
736
-    /**
737
-     * Gets the folder name which contains the main plugin file
738
-     *
739
-     * @return string
740
-     */
741
-    public function get_main_plugin_file_dirname()
742
-    {
743
-        return dirname($this->get_main_plugin_file());
744
-    }
745
-
746
-
747
-    /**
748
-     * sets hooks used in the admin
749
-     *
750
-     * @return void
751
-     */
752
-    public function admin_init()
753
-    {
754
-        // is admin and not in M-Mode ?
755
-        if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
756
-            add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
757
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
758
-        }
759
-    }
760
-
761
-
762
-    /**
763
-     * plugin_actions
764
-     * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
765
-     *
766
-     * @param $links
767
-     * @param $file
768
-     * @return array
769
-     */
770
-    public function plugin_action_links($links, $file)
771
-    {
772
-        if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
773
-            // before other links
774
-            array_unshift(
775
-                $links,
776
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
777
-                . esc_html__('Settings', 'event_espresso')
778
-                . '</a>'
779
-            );
780
-        }
781
-        return $links;
782
-    }
783
-
784
-
785
-    /**
786
-     * after_plugin_row
787
-     * Add additional content to the plugins page plugin row
788
-     * Inserts another row
789
-     *
790
-     * @param $plugin_file
791
-     * @param $plugin_data
792
-     * @param $status
793
-     * @return void
794
-     */
795
-    public function after_plugin_row($plugin_file, $plugin_data, $status)
796
-    {
797
-        $after_plugin_row = '';
798
-        $plugins_page_row = $this->get_plugins_page_row();
799
-        if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
800
-            $class            = $status ? 'active' : 'inactive';
801
-            $link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
802
-            $link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
803
-            $description      = isset($plugins_page_row['description'])
804
-                ? $plugins_page_row['description']
805
-                : '';
806
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
807
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
808
-                $after_plugin_row .= '<th class="check-column" scope="row"></th>';
809
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
810
-                $after_plugin_row .= '<style>
671
+		return update_option($this->get_activation_history_option_name(), $version_history);
672
+	}
673
+
674
+	/**
675
+	 * Gets the name of the wp option that stores the activation history
676
+	 * of this addon
677
+	 *
678
+	 * @return string
679
+	 */
680
+	public function get_activation_history_option_name()
681
+	{
682
+		return self::ee_addon_version_history_option_prefix . $this->name();
683
+	}
684
+
685
+
686
+	/**
687
+	 * Gets the wp option which stores the activation history for this addon
688
+	 *
689
+	 * @return array
690
+	 */
691
+	public function get_activation_history()
692
+	{
693
+		return get_option($this->get_activation_history_option_name(), null);
694
+	}
695
+
696
+
697
+	/**
698
+	 * @param string $config_section
699
+	 */
700
+	public function set_config_section($config_section = '')
701
+	{
702
+		$this->_config_section = ! empty($config_section) ? $config_section : 'addons';
703
+	}
704
+
705
+	/**
706
+	 * Sets the filepath to the main plugin file
707
+	 *
708
+	 * @param string $filepath
709
+	 */
710
+	public function set_main_plugin_file($filepath)
711
+	{
712
+		$this->_main_plugin_file = $filepath;
713
+	}
714
+
715
+	/**
716
+	 * gets the filepath to teh main file
717
+	 *
718
+	 * @return string
719
+	 */
720
+	public function get_main_plugin_file()
721
+	{
722
+		return $this->_main_plugin_file;
723
+	}
724
+
725
+	/**
726
+	 * Gets the filename (no path) of the main file (the main file loaded
727
+	 * by WP)
728
+	 *
729
+	 * @return string
730
+	 */
731
+	public function get_main_plugin_file_basename()
732
+	{
733
+		return plugin_basename($this->get_main_plugin_file());
734
+	}
735
+
736
+	/**
737
+	 * Gets the folder name which contains the main plugin file
738
+	 *
739
+	 * @return string
740
+	 */
741
+	public function get_main_plugin_file_dirname()
742
+	{
743
+		return dirname($this->get_main_plugin_file());
744
+	}
745
+
746
+
747
+	/**
748
+	 * sets hooks used in the admin
749
+	 *
750
+	 * @return void
751
+	 */
752
+	public function admin_init()
753
+	{
754
+		// is admin and not in M-Mode ?
755
+		if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
756
+			add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
757
+			add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
758
+		}
759
+	}
760
+
761
+
762
+	/**
763
+	 * plugin_actions
764
+	 * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
765
+	 *
766
+	 * @param $links
767
+	 * @param $file
768
+	 * @return array
769
+	 */
770
+	public function plugin_action_links($links, $file)
771
+	{
772
+		if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
773
+			// before other links
774
+			array_unshift(
775
+				$links,
776
+				'<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
777
+				. esc_html__('Settings', 'event_espresso')
778
+				. '</a>'
779
+			);
780
+		}
781
+		return $links;
782
+	}
783
+
784
+
785
+	/**
786
+	 * after_plugin_row
787
+	 * Add additional content to the plugins page plugin row
788
+	 * Inserts another row
789
+	 *
790
+	 * @param $plugin_file
791
+	 * @param $plugin_data
792
+	 * @param $status
793
+	 * @return void
794
+	 */
795
+	public function after_plugin_row($plugin_file, $plugin_data, $status)
796
+	{
797
+		$after_plugin_row = '';
798
+		$plugins_page_row = $this->get_plugins_page_row();
799
+		if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
800
+			$class            = $status ? 'active' : 'inactive';
801
+			$link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
802
+			$link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
803
+			$description      = isset($plugins_page_row['description'])
804
+				? $plugins_page_row['description']
805
+				: '';
806
+			if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
807
+				$after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
808
+				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
809
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
810
+				$after_plugin_row .= '<style>
811 811
 .ee-button,
812 812
 .ee-button:active,
813 813
 .ee-button:visited {
@@ -844,49 +844,49 @@  discard block
 block discarded – undo
844 844
 }
845 845
 .ee-button:active { top:0; }
846 846
 </style>';
847
-                $after_plugin_row .= '
847
+				$after_plugin_row .= '
848 848
 <p class="ee-addon-upsell-info-dv">
849 849
 	<a class="ee-button" href="' . $link_url . '">'
850
-                . $link_text
851
-                . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
852
-                . '</a>
850
+				. $link_text
851
+				. ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
852
+				. '</a>
853 853
 </p>';
854
-                $after_plugin_row .= '</td>';
855
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
856
-                $after_plugin_row .= $description;
857
-                $after_plugin_row .= '</td>';
858
-                $after_plugin_row .= '</tr>';
859
-            } else {
860
-                $after_plugin_row .= $description;
861
-            }
862
-        }
863
-
864
-        echo $after_plugin_row;
865
-    }
866
-
867
-
868
-    /**
869
-     * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
870
-     * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
871
-     * for back compat reasons.
872
-     *
873
-     * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
874
-     *
875
-     * It is recommended, if client code is `de-registering` an add-on, then do it on the
876
-     * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
877
-     * callback does not get run/set in that request.
878
-     *
879
-     * Also, keep in mind that if a registered add-on happens to be deactivated via
880
-     * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
881
-     * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
882
-     * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
883
-     * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
884
-     * to call `parent::deactivation`.
885
-     *
886
-     * @since 4.9.26
887
-     */
888
-    public function after_registration()
889
-    {
890
-        // cricket chirp... cricket chirp...
891
-    }
854
+				$after_plugin_row .= '</td>';
855
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
856
+				$after_plugin_row .= $description;
857
+				$after_plugin_row .= '</td>';
858
+				$after_plugin_row .= '</tr>';
859
+			} else {
860
+				$after_plugin_row .= $description;
861
+			}
862
+		}
863
+
864
+		echo $after_plugin_row;
865
+	}
866
+
867
+
868
+	/**
869
+	 * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
870
+	 * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
871
+	 * for back compat reasons.
872
+	 *
873
+	 * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
874
+	 *
875
+	 * It is recommended, if client code is `de-registering` an add-on, then do it on the
876
+	 * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
877
+	 * callback does not get run/set in that request.
878
+	 *
879
+	 * Also, keep in mind that if a registered add-on happens to be deactivated via
880
+	 * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
881
+	 * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
882
+	 * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
883
+	 * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
884
+	 * to call `parent::deactivation`.
885
+	 *
886
+	 * @since 4.9.26
887
+	 */
888
+	public function after_registration()
889
+	{
890
+		// cricket chirp... cricket chirp...
891
+	}
892 892
 }
Please login to merge, or discard this patch.
core/CPTs/EE_Register_CPTs.core.php 2 patches
Indentation   +314 added lines, -314 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\services\loaders\LoaderFactory;
9 9
 
10 10
 if (! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -25,303 +25,303 @@  discard block
 block discarded – undo
25 25
 {
26 26
 
27 27
 
28
-    /**
29
-     * instantiated at init priority 5
30
-     *
31
-     * @deprecated $VID:$
32
-     */
33
-    public function __construct()
34
-    {
35
-        do_action('AHEE__EE_Register_CPTs__construct_end', $this);
36
-    }
37
-
38
-
39
-    /**
40
-     * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
41
-     *
42
-     * @deprecated $VID:$
43
-     * @return void
44
-     * @throws InvalidInterfaceException
45
-     * @throws InvalidDataTypeException
46
-     * @throws InvalidArgumentException
47
-     */
48
-    public static function maybe_flush_rewrite_rules()
49
-    {
50
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
51
-        $rewrite_rules = LoaderFactory::getLoader()->getShared(
52
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
53
-        );
54
-        $rewrite_rules->flushRewriteRules();
55
-    }
56
-
57
-
58
-    /**
59
-     * @return CustomTaxonomyDefinitions
60
-     * @throws InvalidArgumentException
61
-     * @throws InvalidDataTypeException
62
-     * @throws InvalidInterfaceException
63
-     */
64
-    public static function getTaxonomyDefinitions()
65
-    {
66
-        return LoaderFactory::getLoader()->getShared(
67
-            'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
68
-        );
69
-    }
70
-
71
-
72
-    /**
73
-     * @deprecated $VID:$
74
-     * @param string $description The description content.
75
-     * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
76
-     * @return string
77
-     * @throws InvalidArgumentException
78
-     * @throws InvalidDataTypeException
79
-     * @throws InvalidInterfaceException
80
-     */
81
-    public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
82
-    {
83
-        $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
84
-        return $taxonomies->filterCustomTermDescription($description, $taxonomy);
85
-    }
86
-
87
-
88
-    /**
89
-     * @deprecated $VID:$
90
-     * @return array
91
-     * @throws InvalidArgumentException
92
-     * @throws InvalidDataTypeException
93
-     * @throws InvalidInterfaceException
94
-     */
95
-    public static function get_taxonomies()
96
-    {
97
-        $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
98
-        return $taxonomies->getCustomTaxonomyDefinitions();
99
-    }
100
-
101
-
102
-    /**
103
-     * @return CustomPostTypeDefinitions
104
-     * @throws InvalidArgumentException
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     */
108
-    public static function getCustomPostTypeDefinitions()
109
-    {
110
-        return LoaderFactory::getLoader()->getShared(
111
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
112
-        );
113
-    }
114
-
115
-
116
-    /**
117
-     * @deprecated $VID:$
118
-     * @return array
119
-     * @throws InvalidArgumentException
120
-     * @throws InvalidDataTypeException
121
-     * @throws InvalidInterfaceException
122
-     */
123
-    public static function get_CPTs()
124
-    {
125
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
126
-        return $custom_post_types->getDefinitions();
127
-    }
128
-
129
-
130
-    /**
131
-     * @deprecated $VID:$
132
-     * @return array
133
-     * @throws InvalidArgumentException
134
-     * @throws InvalidDataTypeException
135
-     * @throws InvalidInterfaceException
136
-     */
137
-    public static function get_private_CPTs()
138
-    {
139
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
140
-        return $custom_post_types->getPrivateCustomPostTypes();
141
-    }
142
-
143
-
144
-    /**
145
-     * @deprecated $VID:$
146
-     * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
147
-     *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
148
-     *                                            model names for cpts registered in EE.
149
-     * @return array           Empty array if no matching model names for the given slug or an array of model
150
-     *                                            names indexed by post type slug.
151
-     * @throws InvalidArgumentException
152
-     * @throws InvalidDataTypeException
153
-     * @throws InvalidInterfaceException
154
-     */
155
-    public static function get_cpt_model_names($post_type_slug = '')
156
-    {
157
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
158
-        return $custom_post_types->getCustomPostTypeModelNames($post_type_slug);
159
-    }
160
-
161
-
162
-    /**
163
-     * @deprecated $VID:$
164
-     * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
165
-     *                               the cpt matching the given slug.  Otherwise all cpt models will be
166
-     *                               instantiated (if possible).
167
-     * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
168
-     *                               EEM models indexed by post slug.
169
-     * @throws InvalidArgumentException
170
-     * @throws InvalidDataTypeException
171
-     * @throws InvalidInterfaceException
172
-     */
173
-    public static function instantiate_cpt_models($post_type_slug = '')
174
-    {
175
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
176
-        return $custom_post_types->getCustomPostTypeModels($post_type_slug);
177
-    }
178
-
179
-
180
-    /**
181
-     * @deprecated $VID:$
182
-     * @param string $taxonomy_name , eg 'books'
183
-     * @param string $singular_name internationalized singular name
184
-     * @param string $plural_name   internationalized plural name
185
-     * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
186
-     * @throws InvalidArgumentException
187
-     * @throws InvalidDataTypeException
188
-     * @throws InvalidInterfaceException
189
-     * @throws DomainException
190
-     */
191
-    public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
192
-    {
193
-        /** @var \EventEspresso\core\domain\services\custom_post_types\registerCustomTaxonomies $taxonomies */
194
-        $taxonomies = LoaderFactory::getLoader()->getShared(
195
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
196
-        );
197
-        $taxonomies->registerCustomTaxonomy(
198
-            $taxonomy_name,
199
-            $singular_name,
200
-            $plural_name,
201
-            $override_args
202
-        );
203
-    }
204
-
205
-
206
-    /**
207
-     * @deprecated $VID:$
208
-     * @param string $post_type     the actual post type name
209
-     *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
210
-     *                              cpt Also any models must use this slug as well)
211
-     * @param string $singular_name a pre-internationalized string for the singular name of the objects
212
-     * @param string $plural_name   a pre-internalized string for the plural name of the objects
213
-     * @param array  $override_args exactly like $args as described in
214
-     *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
215
-     *                              set in this function will be overridden by whatever you set in $override_args
216
-     * @param string $singular_slug
217
-     * @param string $plural_slug
218
-     * @return void , but registers the custom post type
219
-     * @throws InvalidArgumentException
220
-     * @throws InvalidDataTypeException
221
-     * @throws InvalidInterfaceException
222
-     * @throws DomainException
223
-     */
224
-    public function register_CPT(
225
-        $post_type,
226
-        $singular_name,
227
-        $plural_name,
228
-        $override_args = array(),
229
-        $singular_slug = '',
230
-        $plural_slug = ''
231
-    ) {
232
-        /** @var \EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
233
-        $register_custom_post_types = LoaderFactory::getLoader()->getShared(
234
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
235
-        );
236
-        $register_custom_post_types->registerCustomPostType(
237
-            $post_type,
238
-            $singular_name,
239
-            $plural_name,
240
-            $singular_slug,
241
-            $plural_slug,
242
-            $override_args
243
-        );
244
-    }
245
-
246
-
247
-    /**
248
-     * @return RegisterCustomTaxonomyTerms
249
-     * @throws InvalidArgumentException
250
-     * @throws InvalidDataTypeException
251
-     * @throws InvalidInterfaceException
252
-     */
253
-    public static function getRegisterCustomTaxonomyTerms()
254
-    {
255
-        return LoaderFactory::getLoader()->getShared(
256
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
257
-        );
258
-    }
259
-
260
-
261
-    /**
262
-     * @deprecated $VID:$
263
-     * @throws InvalidArgumentException
264
-     * @throws InvalidDataTypeException
265
-     * @throws InvalidInterfaceException
266
-     */
267
-    public function set_must_use_event_types()
268
-    {
269
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
270
-        $register_custom_taxonomy_terms->setMustUseEventTypes();
271
-    }
272
-
273
-
274
-    /**
275
-     * @deprecated $VID:$
276
-     * @param string $taxonomy     The name of the taxonomy
277
-     * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
278
-     *                             description as the elements in the array
279
-     * @return void
280
-     * @throws InvalidArgumentException
281
-     * @throws InvalidDataTypeException
282
-     * @throws InvalidInterfaceException
283
-     */
284
-    public function set_must_use_terms($taxonomy, $term_details)
285
-    {
286
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
287
-        $register_custom_taxonomy_terms->setMustUseTerms($taxonomy, $term_details);
288
-    }
289
-
290
-
291
-    /**
292
-     * @deprecated $VID:$
293
-     * @param string $taxonomy  The taxonomy we're using for the default term
294
-     * @param string $term_slug The slug of the term that will be the default.
295
-     * @param array  $cpt_slugs An array of custom post types we want the default assigned to
296
-     * @throws InvalidArgumentException
297
-     * @throws InvalidDataTypeException
298
-     * @throws InvalidInterfaceException
299
-     */
300
-    public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
301
-    {
302
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
303
-        $register_custom_taxonomy_terms->registerCustomTaxonomyTerm(
304
-            $taxonomy,
305
-            $term_slug,
306
-            $cpt_slugs
307
-        );
308
-    }
309
-
310
-
311
-    /**
312
-     * @deprecated $VID:$
313
-     * @param  int     $post_id ID of CPT being saved
314
-     * @param  WP_Post $post    Post object
315
-     * @return void
316
-     * @throws InvalidArgumentException
317
-     * @throws InvalidDataTypeException
318
-     * @throws InvalidInterfaceException
319
-     */
320
-    public function save_default_term($post_id, $post)
321
-    {
322
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
323
-        $register_custom_taxonomy_terms->saveDefaultTerm($post_id, $post);
324
-    }
28
+	/**
29
+	 * instantiated at init priority 5
30
+	 *
31
+	 * @deprecated $VID:$
32
+	 */
33
+	public function __construct()
34
+	{
35
+		do_action('AHEE__EE_Register_CPTs__construct_end', $this);
36
+	}
37
+
38
+
39
+	/**
40
+	 * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
41
+	 *
42
+	 * @deprecated $VID:$
43
+	 * @return void
44
+	 * @throws InvalidInterfaceException
45
+	 * @throws InvalidDataTypeException
46
+	 * @throws InvalidArgumentException
47
+	 */
48
+	public static function maybe_flush_rewrite_rules()
49
+	{
50
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
51
+		$rewrite_rules = LoaderFactory::getLoader()->getShared(
52
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
53
+		);
54
+		$rewrite_rules->flushRewriteRules();
55
+	}
56
+
57
+
58
+	/**
59
+	 * @return CustomTaxonomyDefinitions
60
+	 * @throws InvalidArgumentException
61
+	 * @throws InvalidDataTypeException
62
+	 * @throws InvalidInterfaceException
63
+	 */
64
+	public static function getTaxonomyDefinitions()
65
+	{
66
+		return LoaderFactory::getLoader()->getShared(
67
+			'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
68
+		);
69
+	}
70
+
71
+
72
+	/**
73
+	 * @deprecated $VID:$
74
+	 * @param string $description The description content.
75
+	 * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
76
+	 * @return string
77
+	 * @throws InvalidArgumentException
78
+	 * @throws InvalidDataTypeException
79
+	 * @throws InvalidInterfaceException
80
+	 */
81
+	public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
82
+	{
83
+		$taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
84
+		return $taxonomies->filterCustomTermDescription($description, $taxonomy);
85
+	}
86
+
87
+
88
+	/**
89
+	 * @deprecated $VID:$
90
+	 * @return array
91
+	 * @throws InvalidArgumentException
92
+	 * @throws InvalidDataTypeException
93
+	 * @throws InvalidInterfaceException
94
+	 */
95
+	public static function get_taxonomies()
96
+	{
97
+		$taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
98
+		return $taxonomies->getCustomTaxonomyDefinitions();
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return CustomPostTypeDefinitions
104
+	 * @throws InvalidArgumentException
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 */
108
+	public static function getCustomPostTypeDefinitions()
109
+	{
110
+		return LoaderFactory::getLoader()->getShared(
111
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
112
+		);
113
+	}
114
+
115
+
116
+	/**
117
+	 * @deprecated $VID:$
118
+	 * @return array
119
+	 * @throws InvalidArgumentException
120
+	 * @throws InvalidDataTypeException
121
+	 * @throws InvalidInterfaceException
122
+	 */
123
+	public static function get_CPTs()
124
+	{
125
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
126
+		return $custom_post_types->getDefinitions();
127
+	}
128
+
129
+
130
+	/**
131
+	 * @deprecated $VID:$
132
+	 * @return array
133
+	 * @throws InvalidArgumentException
134
+	 * @throws InvalidDataTypeException
135
+	 * @throws InvalidInterfaceException
136
+	 */
137
+	public static function get_private_CPTs()
138
+	{
139
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
140
+		return $custom_post_types->getPrivateCustomPostTypes();
141
+	}
142
+
143
+
144
+	/**
145
+	 * @deprecated $VID:$
146
+	 * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
147
+	 *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
148
+	 *                                            model names for cpts registered in EE.
149
+	 * @return array           Empty array if no matching model names for the given slug or an array of model
150
+	 *                                            names indexed by post type slug.
151
+	 * @throws InvalidArgumentException
152
+	 * @throws InvalidDataTypeException
153
+	 * @throws InvalidInterfaceException
154
+	 */
155
+	public static function get_cpt_model_names($post_type_slug = '')
156
+	{
157
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
158
+		return $custom_post_types->getCustomPostTypeModelNames($post_type_slug);
159
+	}
160
+
161
+
162
+	/**
163
+	 * @deprecated $VID:$
164
+	 * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
165
+	 *                               the cpt matching the given slug.  Otherwise all cpt models will be
166
+	 *                               instantiated (if possible).
167
+	 * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
168
+	 *                               EEM models indexed by post slug.
169
+	 * @throws InvalidArgumentException
170
+	 * @throws InvalidDataTypeException
171
+	 * @throws InvalidInterfaceException
172
+	 */
173
+	public static function instantiate_cpt_models($post_type_slug = '')
174
+	{
175
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
176
+		return $custom_post_types->getCustomPostTypeModels($post_type_slug);
177
+	}
178
+
179
+
180
+	/**
181
+	 * @deprecated $VID:$
182
+	 * @param string $taxonomy_name , eg 'books'
183
+	 * @param string $singular_name internationalized singular name
184
+	 * @param string $plural_name   internationalized plural name
185
+	 * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
186
+	 * @throws InvalidArgumentException
187
+	 * @throws InvalidDataTypeException
188
+	 * @throws InvalidInterfaceException
189
+	 * @throws DomainException
190
+	 */
191
+	public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
192
+	{
193
+		/** @var \EventEspresso\core\domain\services\custom_post_types\registerCustomTaxonomies $taxonomies */
194
+		$taxonomies = LoaderFactory::getLoader()->getShared(
195
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
196
+		);
197
+		$taxonomies->registerCustomTaxonomy(
198
+			$taxonomy_name,
199
+			$singular_name,
200
+			$plural_name,
201
+			$override_args
202
+		);
203
+	}
204
+
205
+
206
+	/**
207
+	 * @deprecated $VID:$
208
+	 * @param string $post_type     the actual post type name
209
+	 *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
210
+	 *                              cpt Also any models must use this slug as well)
211
+	 * @param string $singular_name a pre-internationalized string for the singular name of the objects
212
+	 * @param string $plural_name   a pre-internalized string for the plural name of the objects
213
+	 * @param array  $override_args exactly like $args as described in
214
+	 *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
215
+	 *                              set in this function will be overridden by whatever you set in $override_args
216
+	 * @param string $singular_slug
217
+	 * @param string $plural_slug
218
+	 * @return void , but registers the custom post type
219
+	 * @throws InvalidArgumentException
220
+	 * @throws InvalidDataTypeException
221
+	 * @throws InvalidInterfaceException
222
+	 * @throws DomainException
223
+	 */
224
+	public function register_CPT(
225
+		$post_type,
226
+		$singular_name,
227
+		$plural_name,
228
+		$override_args = array(),
229
+		$singular_slug = '',
230
+		$plural_slug = ''
231
+	) {
232
+		/** @var \EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
233
+		$register_custom_post_types = LoaderFactory::getLoader()->getShared(
234
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
235
+		);
236
+		$register_custom_post_types->registerCustomPostType(
237
+			$post_type,
238
+			$singular_name,
239
+			$plural_name,
240
+			$singular_slug,
241
+			$plural_slug,
242
+			$override_args
243
+		);
244
+	}
245
+
246
+
247
+	/**
248
+	 * @return RegisterCustomTaxonomyTerms
249
+	 * @throws InvalidArgumentException
250
+	 * @throws InvalidDataTypeException
251
+	 * @throws InvalidInterfaceException
252
+	 */
253
+	public static function getRegisterCustomTaxonomyTerms()
254
+	{
255
+		return LoaderFactory::getLoader()->getShared(
256
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
257
+		);
258
+	}
259
+
260
+
261
+	/**
262
+	 * @deprecated $VID:$
263
+	 * @throws InvalidArgumentException
264
+	 * @throws InvalidDataTypeException
265
+	 * @throws InvalidInterfaceException
266
+	 */
267
+	public function set_must_use_event_types()
268
+	{
269
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
270
+		$register_custom_taxonomy_terms->setMustUseEventTypes();
271
+	}
272
+
273
+
274
+	/**
275
+	 * @deprecated $VID:$
276
+	 * @param string $taxonomy     The name of the taxonomy
277
+	 * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
278
+	 *                             description as the elements in the array
279
+	 * @return void
280
+	 * @throws InvalidArgumentException
281
+	 * @throws InvalidDataTypeException
282
+	 * @throws InvalidInterfaceException
283
+	 */
284
+	public function set_must_use_terms($taxonomy, $term_details)
285
+	{
286
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
287
+		$register_custom_taxonomy_terms->setMustUseTerms($taxonomy, $term_details);
288
+	}
289
+
290
+
291
+	/**
292
+	 * @deprecated $VID:$
293
+	 * @param string $taxonomy  The taxonomy we're using for the default term
294
+	 * @param string $term_slug The slug of the term that will be the default.
295
+	 * @param array  $cpt_slugs An array of custom post types we want the default assigned to
296
+	 * @throws InvalidArgumentException
297
+	 * @throws InvalidDataTypeException
298
+	 * @throws InvalidInterfaceException
299
+	 */
300
+	public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
301
+	{
302
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
303
+		$register_custom_taxonomy_terms->registerCustomTaxonomyTerm(
304
+			$taxonomy,
305
+			$term_slug,
306
+			$cpt_slugs
307
+		);
308
+	}
309
+
310
+
311
+	/**
312
+	 * @deprecated $VID:$
313
+	 * @param  int     $post_id ID of CPT being saved
314
+	 * @param  WP_Post $post    Post object
315
+	 * @return void
316
+	 * @throws InvalidArgumentException
317
+	 * @throws InvalidDataTypeException
318
+	 * @throws InvalidInterfaceException
319
+	 */
320
+	public function save_default_term($post_id, $post)
321
+	{
322
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
323
+		$register_custom_taxonomy_terms->saveDefaultTerm($post_id, $post);
324
+	}
325 325
 }
326 326
 
327 327
 
@@ -335,24 +335,24 @@  discard block
 block discarded – undo
335 335
 class EE_Default_Term
336 336
 {
337 337
 
338
-    //props holding the items
339
-    public $taxonomy  = '';
338
+	//props holding the items
339
+	public $taxonomy  = '';
340 340
 
341
-    public $cpt_slugs = array();
341
+	public $cpt_slugs = array();
342 342
 
343
-    public $term_slug = '';
343
+	public $term_slug = '';
344 344
 
345 345
 
346
-    /**
347
-     * @deprecated $VID:$
348
-     * @param string $taxonomy The taxonomy the default term belongs to
349
-     * @param string $term_slug The slug of the term that will be the default.
350
-     * @param array  $cpt_slugs The custom post type the default term gets saved with
351
-     */
352
-    public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
353
-    {
354
-        $this->taxonomy  = $taxonomy;
355
-        $this->cpt_slugs = (array) $cpt_slugs;
356
-        $this->term_slug = $term_slug;
357
-    }
346
+	/**
347
+	 * @deprecated $VID:$
348
+	 * @param string $taxonomy The taxonomy the default term belongs to
349
+	 * @param string $term_slug The slug of the term that will be the default.
350
+	 * @param array  $cpt_slugs The custom post type the default term gets saved with
351
+	 */
352
+	public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
353
+	{
354
+		$this->taxonomy  = $taxonomy;
355
+		$this->cpt_slugs = (array) $cpt_slugs;
356
+		$this->term_slug = $term_slug;
357
+	}
358 358
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
 use EventEspresso\core\exceptions\InvalidInterfaceException;
8 8
 use EventEspresso\core\services\loaders\LoaderFactory;
9 9
 
10
-if (! defined('EVENT_ESPRESSO_VERSION')) {
10
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11 11
     exit('No direct script access allowed');
12 12
 }
13 13
 
Please login to merge, or discard this patch.
core/domain/services/custom_post_types/RewriteRules.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -17,30 +17,30 @@
 block discarded – undo
17 17
 class RewriteRules
18 18
 {
19 19
 
20
-    const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules';
21
-
22
-
23
-    /**
24
-     * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
25
-     *
26
-     * @return void
27
-     */
28
-    public function flush()
29
-    {
30
-        update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true);
31
-    }
32
-
33
-
34
-    /**
35
-     * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
36
-     *
37
-     * @return void
38
-     */
39
-    public function flushRewriteRules()
40
-    {
41
-        if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) {
42
-            flush_rewrite_rules();
43
-            update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false);
44
-        }
45
-    }
20
+	const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules';
21
+
22
+
23
+	/**
24
+	 * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
25
+	 *
26
+	 * @return void
27
+	 */
28
+	public function flush()
29
+	{
30
+		update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true);
31
+	}
32
+
33
+
34
+	/**
35
+	 * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
36
+	 *
37
+	 * @return void
38
+	 */
39
+	public function flushRewriteRules()
40
+	{
41
+		if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) {
42
+			flush_rewrite_rules();
43
+			update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false);
44
+		}
45
+	}
46 46
 }
Please login to merge, or discard this patch.
core/domain/services/custom_post_types/RegisterCustomTaxonomyTerms.php 2 patches
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -20,176 +20,176 @@
 block discarded – undo
20 20
 class RegisterCustomTaxonomyTerms
21 21
 {
22 22
 
23
-    /**
24
-     * @var array[] $custom_taxonomy_terms
25
-     */
26
-    public $custom_taxonomy_terms = array();
27
-
28
-
29
-    /**
30
-     * RegisterCustomTaxonomyTerms constructor.
31
-     */
32
-    public function __construct()
33
-    {
34
-        // hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts
35
-        // IF they don't have a term for that taxonomy set.
36
-        add_action('save_post', array($this, 'save_default_term'), 100, 2);
37
-    }
38
-
39
-
40
-    public function registerCustomTaxonomyTerms()
41
-    {
42
-        // setup default terms in any of our taxonomies (but only if we're in admin).
43
-        // Why not added via register_activation_hook?
44
-        // Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies
45
-        // (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin.
46
-        // Keep in mind that this will READ these terms if they are deleted by the user.  Hence MUST use terms.
47
-        // if ( is_admin() ) {
48
-        // 	$this->set_must_use_event_types();
49
-        // }
50
-        //set default terms
51
-        $this->registerCustomTaxonomyTerm(
52
-            'espresso_event_type',
53
-            'single-event',
54
-            array('espresso_events')
55
-        );
56
-    }
57
-
58
-
59
-    /**
60
-     * Allows us to set what the default will be for terms when a cpt is PUBLISHED.
61
-     *
62
-     * @param string $taxonomy  The taxonomy we're using for the default term
63
-     * @param string $term_slug The slug of the term that will be the default.
64
-     * @param array  $cpt_slugs An array of custom post types we want the default assigned to
65
-     */
66
-    public function registerCustomTaxonomyTerm($taxonomy, $term_slug, array $cpt_slugs = array())
67
-    {
68
-        $this->custom_taxonomy_terms[][ $term_slug ] = new CustomTaxonomyTerm(
69
-            $taxonomy,
70
-            $term_slug,
71
-            $cpt_slugs
72
-        );
73
-    }
74
-
75
-
76
-    /**
77
-     * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property
78
-     *
79
-     * @param  int    $post_id ID of CPT being saved
80
-     * @param  WP_Post $post    Post object
81
-     * @return void
82
-     */
83
-    public function saveDefaultTerm($post_id, WP_Post $post)
84
-    {
85
-        if (empty($this->custom_taxonomy_terms)) {
86
-            return;
87
-        } //no default terms set so lets just exit.
88
-        foreach ($this->custom_taxonomy_terms as $custom_taxonomy_terms) {
89
-            foreach ($custom_taxonomy_terms as $custom_taxonomy_term) {
90
-                if (
91
-                    $post->post_status === 'publish'
92
-                    && in_array($post->post_type, $custom_taxonomy_term->cpt_slugs, true)
93
-                ) {
94
-                    //note some error proofing going on here to save unnecessary db queries
95
-                    $taxonomies = get_object_taxonomies($post->post_type);
96
-                    foreach ($taxonomies as $taxonomy) {
97
-                        $terms = wp_get_post_terms($post_id, $taxonomy);
98
-                        if (empty($terms) && $taxonomy === $custom_taxonomy_term->taxonomy) {
99
-                            wp_set_object_terms(
100
-                                $post_id,
101
-                                array($custom_taxonomy_term->term_slug),
102
-                                $taxonomy
103
-                            );
104
-                        }
105
-                    }
106
-                }
107
-            }
108
-        }
109
-    }
110
-
111
-
112
-    /**
113
-     * @return void
114
-     */
115
-    public function setMustUseEventTypes()
116
-    {
117
-        $term_details = array(
118
-            //Attendee's register for the first date-time only
119
-            'single-event'    => array(
120
-                'term' => esc_html__('Single Event', 'event_espresso'),
121
-                'desc' => esc_html__(
122
-                    'A single event that spans one or more consecutive days.',
123
-                    'event_espresso'
124
-                ),
125
-            ),
126
-            //example: a party or two-day long workshop
127
-            //Attendee's can register for any of the date-times
128
-            'multi-event'     => array(
129
-                'term' => esc_html__('Multi Event', 'event_espresso'),
130
-                'desc' => esc_html__(
131
-                    'Multiple, separate, but related events that occur on consecutive days.',
132
-                    'event_espresso'
133
-                ),
134
-            ),
135
-            //example: a three day music festival or week long conference
136
-            //Attendee's register for the first date-time only
137
-            'event-series'    => array(
138
-                'term' => esc_html__('Event Series', 'event_espresso'),
139
-                'desc' => esc_html__(
140
-                    ' Multiple events that occur over multiple non-consecutive days.',
141
-                    'event_espresso'
142
-                ),
143
-            ),
144
-            //example: an 8 week introduction to basket weaving course
145
-            //Attendee's can register for any of the date-times.
146
-            'recurring-event' => array(
147
-                'term' => esc_html__('Recurring Event', 'event_espresso'),
148
-                'desc' => esc_html__(
149
-                    'Multiple events that occur over multiple non-consecutive days.',
150
-                    'event_espresso'
151
-                ),
152
-            ),
153
-            //example: a yoga class
154
-            'ongoing'         => array(
155
-                'term' => esc_html__('Ongoing Event', 'event_espresso'),
156
-                'desc' => esc_html__(
157
-                    'An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event',
158
-                    'event_espresso'
159
-                ),
160
-            )
161
-            //example: access to a museum
162
-            //'walk-in' => array( esc_html__('Walk In', 'event_espresso'), esc_html__('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ),
163
-            //'reservation' => array( esc_html__('Reservation', 'event_espresso'), esc_html__('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
164
-            // 'multiple-session' => array( esc_html__('Multiple Session', 'event_espresso'), esc_html__('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
165
-            //'appointment' => array( esc_html__('Appointments', 'event_espresso'), esc_html__('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') )
166
-        );
167
-        $this->setMustUseTerms('espresso_event_type', $term_details);
168
-    }
169
-
170
-
171
-    /**
172
-     * wrapper method for handling the setting up of initial terms in the db (if they don't already exist).
173
-     * Note this should ONLY be used for terms that always must be present.  Be aware that if an initial term is
174
-     * deleted then it WILL be recreated.
175
-     *
176
-     * @param string $taxonomy     The name of the taxonomy
177
-     * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
178
-     *                             description as the elements in the array
179
-     * @return void
180
-     */
181
-    public function setMustUseTerms($taxonomy, $term_details)
182
-    {
183
-        $term_details = (array) $term_details;
184
-        foreach ($term_details as $slug => $details) {
185
-            if (isset($details['term'], $details['desc']) && ! term_exists($slug, $taxonomy)) {
186
-                $insert_arr = array(
187
-                    'slug'        => $slug,
188
-                    'description' => $details['desc'],
189
-                );
190
-                wp_insert_term($details['term'], $taxonomy, $insert_arr);
191
-            }
192
-        }
193
-    }
23
+	/**
24
+	 * @var array[] $custom_taxonomy_terms
25
+	 */
26
+	public $custom_taxonomy_terms = array();
27
+
28
+
29
+	/**
30
+	 * RegisterCustomTaxonomyTerms constructor.
31
+	 */
32
+	public function __construct()
33
+	{
34
+		// hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts
35
+		// IF they don't have a term for that taxonomy set.
36
+		add_action('save_post', array($this, 'save_default_term'), 100, 2);
37
+	}
38
+
39
+
40
+	public function registerCustomTaxonomyTerms()
41
+	{
42
+		// setup default terms in any of our taxonomies (but only if we're in admin).
43
+		// Why not added via register_activation_hook?
44
+		// Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies
45
+		// (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin.
46
+		// Keep in mind that this will READ these terms if they are deleted by the user.  Hence MUST use terms.
47
+		// if ( is_admin() ) {
48
+		// 	$this->set_must_use_event_types();
49
+		// }
50
+		//set default terms
51
+		$this->registerCustomTaxonomyTerm(
52
+			'espresso_event_type',
53
+			'single-event',
54
+			array('espresso_events')
55
+		);
56
+	}
57
+
58
+
59
+	/**
60
+	 * Allows us to set what the default will be for terms when a cpt is PUBLISHED.
61
+	 *
62
+	 * @param string $taxonomy  The taxonomy we're using for the default term
63
+	 * @param string $term_slug The slug of the term that will be the default.
64
+	 * @param array  $cpt_slugs An array of custom post types we want the default assigned to
65
+	 */
66
+	public function registerCustomTaxonomyTerm($taxonomy, $term_slug, array $cpt_slugs = array())
67
+	{
68
+		$this->custom_taxonomy_terms[][ $term_slug ] = new CustomTaxonomyTerm(
69
+			$taxonomy,
70
+			$term_slug,
71
+			$cpt_slugs
72
+		);
73
+	}
74
+
75
+
76
+	/**
77
+	 * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property
78
+	 *
79
+	 * @param  int    $post_id ID of CPT being saved
80
+	 * @param  WP_Post $post    Post object
81
+	 * @return void
82
+	 */
83
+	public function saveDefaultTerm($post_id, WP_Post $post)
84
+	{
85
+		if (empty($this->custom_taxonomy_terms)) {
86
+			return;
87
+		} //no default terms set so lets just exit.
88
+		foreach ($this->custom_taxonomy_terms as $custom_taxonomy_terms) {
89
+			foreach ($custom_taxonomy_terms as $custom_taxonomy_term) {
90
+				if (
91
+					$post->post_status === 'publish'
92
+					&& in_array($post->post_type, $custom_taxonomy_term->cpt_slugs, true)
93
+				) {
94
+					//note some error proofing going on here to save unnecessary db queries
95
+					$taxonomies = get_object_taxonomies($post->post_type);
96
+					foreach ($taxonomies as $taxonomy) {
97
+						$terms = wp_get_post_terms($post_id, $taxonomy);
98
+						if (empty($terms) && $taxonomy === $custom_taxonomy_term->taxonomy) {
99
+							wp_set_object_terms(
100
+								$post_id,
101
+								array($custom_taxonomy_term->term_slug),
102
+								$taxonomy
103
+							);
104
+						}
105
+					}
106
+				}
107
+			}
108
+		}
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return void
114
+	 */
115
+	public function setMustUseEventTypes()
116
+	{
117
+		$term_details = array(
118
+			//Attendee's register for the first date-time only
119
+			'single-event'    => array(
120
+				'term' => esc_html__('Single Event', 'event_espresso'),
121
+				'desc' => esc_html__(
122
+					'A single event that spans one or more consecutive days.',
123
+					'event_espresso'
124
+				),
125
+			),
126
+			//example: a party or two-day long workshop
127
+			//Attendee's can register for any of the date-times
128
+			'multi-event'     => array(
129
+				'term' => esc_html__('Multi Event', 'event_espresso'),
130
+				'desc' => esc_html__(
131
+					'Multiple, separate, but related events that occur on consecutive days.',
132
+					'event_espresso'
133
+				),
134
+			),
135
+			//example: a three day music festival or week long conference
136
+			//Attendee's register for the first date-time only
137
+			'event-series'    => array(
138
+				'term' => esc_html__('Event Series', 'event_espresso'),
139
+				'desc' => esc_html__(
140
+					' Multiple events that occur over multiple non-consecutive days.',
141
+					'event_espresso'
142
+				),
143
+			),
144
+			//example: an 8 week introduction to basket weaving course
145
+			//Attendee's can register for any of the date-times.
146
+			'recurring-event' => array(
147
+				'term' => esc_html__('Recurring Event', 'event_espresso'),
148
+				'desc' => esc_html__(
149
+					'Multiple events that occur over multiple non-consecutive days.',
150
+					'event_espresso'
151
+				),
152
+			),
153
+			//example: a yoga class
154
+			'ongoing'         => array(
155
+				'term' => esc_html__('Ongoing Event', 'event_espresso'),
156
+				'desc' => esc_html__(
157
+					'An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event',
158
+					'event_espresso'
159
+				),
160
+			)
161
+			//example: access to a museum
162
+			//'walk-in' => array( esc_html__('Walk In', 'event_espresso'), esc_html__('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ),
163
+			//'reservation' => array( esc_html__('Reservation', 'event_espresso'), esc_html__('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
164
+			// 'multiple-session' => array( esc_html__('Multiple Session', 'event_espresso'), esc_html__('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
165
+			//'appointment' => array( esc_html__('Appointments', 'event_espresso'), esc_html__('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') )
166
+		);
167
+		$this->setMustUseTerms('espresso_event_type', $term_details);
168
+	}
169
+
170
+
171
+	/**
172
+	 * wrapper method for handling the setting up of initial terms in the db (if they don't already exist).
173
+	 * Note this should ONLY be used for terms that always must be present.  Be aware that if an initial term is
174
+	 * deleted then it WILL be recreated.
175
+	 *
176
+	 * @param string $taxonomy     The name of the taxonomy
177
+	 * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
178
+	 *                             description as the elements in the array
179
+	 * @return void
180
+	 */
181
+	public function setMustUseTerms($taxonomy, $term_details)
182
+	{
183
+		$term_details = (array) $term_details;
184
+		foreach ($term_details as $slug => $details) {
185
+			if (isset($details['term'], $details['desc']) && ! term_exists($slug, $taxonomy)) {
186
+				$insert_arr = array(
187
+					'slug'        => $slug,
188
+					'description' => $details['desc'],
189
+				);
190
+				wp_insert_term($details['term'], $taxonomy, $insert_arr);
191
+			}
192
+		}
193
+	}
194 194
 
195 195
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
      */
66 66
     public function registerCustomTaxonomyTerm($taxonomy, $term_slug, array $cpt_slugs = array())
67 67
     {
68
-        $this->custom_taxonomy_terms[][ $term_slug ] = new CustomTaxonomyTerm(
68
+        $this->custom_taxonomy_terms[][$term_slug] = new CustomTaxonomyTerm(
69 69
             $taxonomy,
70 70
             $term_slug,
71 71
             $cpt_slugs
Please login to merge, or discard this patch.